Skip to content

Commit

Permalink
Merge pull request #668 from SUPLA/develop
Browse files Browse the repository at this point in the history
v24.11
  • Loading branch information
przemyslawzygmunt authored Nov 12, 2024
2 parents 0e07c7a + 63f5262 commit 6c0076c
Show file tree
Hide file tree
Showing 324 changed files with 10,348 additions and 2,425 deletions.
Binary file not shown.
7 changes: 3 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ android {
minSdk = libs.versions.minSdk.get().toInt()
targetSdk = libs.versions.targetSdk.get().toInt()
multiDexEnabled = true
versionCode = 255
versionName = "24.10.05"
versionCode = 259
versionName = "24.11"

ndk {
moduleName = "suplaclient"
Expand Down Expand Up @@ -168,11 +168,10 @@ dependencies {
implementation(libs.kotlin.stdlib)
implementation(libs.kotlinx.serialization)
implementation(libs.jsoup)
implementation(libs.coil)

coreLibraryDesugaring(libs.android.tools.desugar)

annotationProcessor(libs.androidx.room.compiler)

kapt(libs.hilt.kapt)
kapt(libs.hilt.worker.kapt)
ksp(libs.androidx.room.compiler)
Expand Down
17 changes: 4 additions & 13 deletions app/src/main/java/org/supla/android/ChannelDetailIC.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,9 @@ public void onDetailShow() {
getChannelBase().getFunc(),
icSpinnerMaster,
icSpinnerSlave,
new Runnable() {
@Override
public void run() {
masterLastSelectedIdx = icSpinnerMaster.getSelectedItemPosition();
updateSlaveSpinnerItems();
}
() -> {
masterLastSelectedIdx = icSpinnerMaster.getSelectedItemPosition();
updateSlaveSpinnerItems();
});

icSpinnerMaster.setOnItemSelectedListener(this);
Expand All @@ -244,13 +241,7 @@ public void run() {
new TimerTask() {
@Override
public void run() {
final Runnable r =
new Runnable() {
public void run() {
runDownloadTask();
}
};

final Runnable r = () -> runDownloadTask();
mHandler.post(r);
}
},
Expand Down
11 changes: 0 additions & 11 deletions app/src/main/java/org/supla/android/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ of the License, or (at your option) any later version.
import android.os.Build;
import android.preference.PreferenceManager;
import android.provider.Settings;
import org.supla.android.data.model.general.NightModeSetting;
import org.supla.android.data.source.runtime.appsettings.TemperatureUnit;

public class Preferences {
Expand All @@ -43,7 +42,6 @@ public class Preferences {
private static final String pref_show_bottom_label = "pref_show_bottom_label";
private static final String pref_show_bottom_menu = "pref_show_bottom_menu";
private static final String pref_show_opening_percent = "pref_show_opening_percent";
private static final String pref_night_mode = "pref_night_mode";

private static final String pref_chart_type = "pref_ct%d_prof%d_%d";

Expand Down Expand Up @@ -258,15 +256,6 @@ public void setShouldShowNewGestureInfo() {
_prefs.edit().putBoolean(pref_should_show_new_gesture_info, true).apply();
}

public NightModeSetting getNightMode() {
return NightModeSetting.Companion.from(
_prefs.getInt(pref_night_mode, NightModeSetting.UNSET.getValue()));
}

public void setNightMode(NightModeSetting setting) {
_prefs.edit().putInt(pref_night_mode, setting.getValue()).apply();
}

public void registerChangeListener(OnSharedPreferenceChangeListener listener) {
_prefs.registerOnSharedPreferenceChangeListener(listener);
}
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/org/supla/android/SuplaApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ of the License, or (at your option) any later version.
import org.supla.android.core.networking.suplaclient.workers.InitializationWorker;
import org.supla.android.core.notifications.NotificationsHelper;
import org.supla.android.core.observers.AppLifecycleObserver;
import org.supla.android.core.storage.ApplicationPreferences;
import org.supla.android.data.ValuesFormatter;
import org.supla.android.data.model.general.NightModeSetting;
import org.supla.android.db.DbHelper;
Expand Down Expand Up @@ -97,6 +98,7 @@ public class SuplaApp extends MultiDexApplication
@Inject Preferences preferences;
@Inject UiModeManager modeManager;
@Inject SuplaClientNetworkCallback suplaClientNetworkCallback;
@Inject ApplicationPreferences applicationPreferences;

public SuplaApp() {
SuplaClientMessageHandler.getGlobalInstance().registerMessageListener(this);
Expand Down Expand Up @@ -292,12 +294,12 @@ public void cleanupToken() {
}

private void setupNightMode() {
NightModeSetting nightModeSetting = preferences.getNightMode();
NightModeSetting nightModeSetting = applicationPreferences.getNightMode();
if (VERSION.SDK_INT < VERSION_CODES.S) {
AppCompatDelegate.setDefaultNightMode(nightModeSetting.appCompatDelegateValue());
}
if (nightModeSetting == NightModeSetting.UNSET) {
preferences.setNightMode(NightModeSetting.NEVER);
applicationPreferences.setNightMode(NightModeSetting.NEVER);
if (VERSION.SDK_INT >= VERSION_CODES.S) {
// If unset, expected is that the app will start without night mode.
modeManager.setApplicationNightMode(nightModeSetting.modeManagerValue());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.supla.android.core.infrastructure
/*
Copyright (C) AC SOFTWARE SP. Z O.O.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

import android.content.Context
import org.supla.android.core.shared.file
import org.supla.core.shared.infrastructure.storage.CacheFileAccess
import java.io.File

class CacheFileAccessProxy(
val applicationContext: Context
) : CacheFileAccess {
override fun fileExists(file: CacheFileAccess.File): Boolean =
file.file(applicationContext.cacheDir).exists()

override fun dirExists(name: String): Boolean =
with(File(applicationContext.cacheDir, name)) {
isDirectory && exists()
}

override fun mkdir(name: String): Boolean =
File(applicationContext.cacheDir, name).mkdir()

override fun delete(file: CacheFileAccess.File): Boolean =
file.file(applicationContext.cacheDir).delete()

override fun writeBytes(file: CacheFileAccess.File, bytes: ByteArray) {
file.file(applicationContext.cacheDir).writeBytes(bytes)
}

override fun readBytes(file: CacheFileAccess.File): ByteArray =
file.file(applicationContext.cacheDir).readBytes()
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

import org.supla.android.extensions.toHex
import org.supla.core.shared.extensions.toHex
import java.security.MessageDigest
import java.security.NoSuchAlgorithmException
import javax.inject.Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class NotificationsHelper @Inject constructor(
}

fun showNotification(context: Context, title: String, text: String, profileName: String?) {
if (VERSION.SDK_INT >= VERSION_CODES.N && !notificationManager.areNotificationsEnabled()) {
if (!notificationManager.areNotificationsEnabled()) {
return
}
// Channel is removed when user revoke notification permission and we don't know
Expand All @@ -153,28 +153,21 @@ class NotificationsHelper @Inject constructor(
val intent = Intent(context, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}
val flag = if (VERSION.SDK_INT >= VERSION_CODES.M) FLAG_IMMUTABLE else 0

return NotificationCompat.Builder(context, channel)
.setSmallIcon(R.drawable.logo)
.setContentTitle(title)
.setContentText(text)
.setColor(ResourcesCompat.getColor(context.resources, R.color.primary, null))
.setContentIntent(PendingIntent.getActivity(context, 0, intent, flag))
.setContentIntent(PendingIntent.getActivity(context, 0, intent, FLAG_IMMUTABLE))
.setAutoCancel(true)
.setStyle(NotificationCompat.BigTextStyle().bigText(text))
.build()
}

companion object {
fun areNotificationsEnabled(notificationManager: NotificationManager): Boolean {
return if (VERSION.SDK_INT >= VERSION_CODES.N) {
notificationManager.areNotificationsEnabled()
} else {
true
}
return notificationManager.areNotificationsEnabled()
}
}
}

private const val ONE_DAY_MILLIS = 24 * 60 * 60 * 1000
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.supla.android.core.shared
/*
Copyright (C) AC SOFTWARE SP. Z O.O.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

import org.supla.core.shared.infrastructure.storage.CacheFileAccess
import java.io.File

fun CacheFileAccess.File.file(cacheDir: File): File {
directory?.let {
return File(File(cacheDir, it), name)
}

return File(cacheDir, name)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.supla.android.usecases.channel
package org.supla.android.core.shared
/*
Copyright (C) AC SOFTWARE SP. Z O.O.
Expand All @@ -19,28 +19,17 @@ package org.supla.android.usecases.channel

import android.content.Context
import org.supla.android.core.ui.StringProvider
import org.supla.android.data.model.general.ChannelBase
import javax.inject.Inject
import javax.inject.Singleton
import org.supla.core.shared.infrastructure.LocalizedString

@Singleton
class GetChannelCaptionUseCase @Inject constructor(
private val getChannelDefaultCaptionUseCase: GetChannelDefaultCaptionUseCase
) {

operator fun invoke(channelEntity: ChannelBase): StringProvider {
if (channelEntity.caption.trim().isEmpty()) {
return getChannelDefaultCaptionUseCase(channelEntity.function)
} else {
return { channelEntity.caption }
}
}

operator fun invoke(channelEntity: ChannelBase, context: Context): String {
return if (channelEntity.caption.trim().isEmpty()) {
getChannelDefaultCaptionUseCase(channelEntity.function)(context)
} else {
channelEntity.caption
}
operator fun LocalizedString.invoke(context: Context): String {
return when (this) {
is LocalizedString.Constant -> text
LocalizedString.Empty -> ""
is LocalizedString.WithId -> context.getString(id.resourceId)
is LocalizedString.WithResourceIntStringInt -> context.getString(id, arg1, arg2(context), arg3)
is LocalizedString.WithResource -> context.getString(id)
is LocalizedString.WithIdIntStringInt -> context.getString(id.resourceId, arg1, arg2(context), arg3)
}
}

fun LocalizedString.provider(): StringProvider = { context -> invoke(context) }
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package org.supla.android.core.shared
/*
Copyright (C) AC SOFTWARE SP. Z O.O.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

import org.supla.android.R
import org.supla.core.shared.infrastructure.LocalizedStringId

val LocalizedStringId.resourceId: Int
get() = when (this) {
LocalizedStringId.GENERAL_TURN_ON -> R.string.channel_btn_on
LocalizedStringId.GENERAL_TURN_OFF -> R.string.channel_btn_off
LocalizedStringId.GENERAL_OPEN -> R.string.channel_btn_open
LocalizedStringId.GENERAL_CLOSE -> R.string.channel_btn_close
LocalizedStringId.GENERAL_SHUT -> R.string.channel_btn_shut
LocalizedStringId.GENERAL_REVEAL -> R.string.channel_btn_reveal
LocalizedStringId.GENERAL_COLLAPSE -> R.string.channel_btn_collapse
LocalizedStringId.GENERAL_EXPAND -> R.string.channel_btn_expand

LocalizedStringId.CHANNEL_CAPTION_OPEN_SENSOR_GATEWAY -> R.string.channel_caption_gatewayopeningsensor
LocalizedStringId.CHANNEL_CAPTION_CONTROLLING_THE_GATEWAY_LOCK -> R.string.channel_caption_gateway
LocalizedStringId.CHANNEL_CAPTION_OPEN_SENSOR_GATE -> R.string.channel_caption_gateopeningsensor
LocalizedStringId.CHANNEL_CAPTION_CONTROLLING_THE_GATE -> R.string.channel_caption_gate
LocalizedStringId.CHANNEL_CAPTION_OPEN_SENSOR_GARAGE_DOOR -> R.string.channel_caption_garagedooropeningsensor
LocalizedStringId.CHANNEL_CAPTION_CONTROLLING_THE_GARAGE_DOOR -> R.string.channel_caption_garagedoor
LocalizedStringId.CHANNEL_CAPTION_OPEN_SENSOR_DOOR -> R.string.channel_caption_dooropeningsensor
LocalizedStringId.CHANNEL_CAPTION_CONTROLLING_THE_DOOR_LOCK -> R.string.channel_caption_door
LocalizedStringId.CHANNEL_CAPTION_OPEN_SENSOR_ROLLER_SHUTTER -> R.string.channel_caption_rsopeningsensor
LocalizedStringId.CHANNEL_CAPTION_OPEN_SENSOR_ROOF_WINDOW -> R.string.channel_caption_roofwindowopeningsensor
LocalizedStringId.CHANNEL_CAPTION_CONTROLLING_THE_ROLLER_SHUTTER -> R.string.channel_caption_rollershutter
LocalizedStringId.CHANNEL_CAPTION_CONTROLLING_THE_ROOF_WINDOW -> R.string.channel_caption_roofwindow
LocalizedStringId.CHANNEL_CAPTION_CONTROLLING_THE_FACADE_BLIND -> R.string.channel_caption_facade_blinds
LocalizedStringId.CHANNEL_CAPTION_POWER_SWITCH -> R.string.channel_caption_powerswith
LocalizedStringId.CHANNEL_CAPTION_LIGHTSWITCH -> R.string.channel_caption_lightswith
LocalizedStringId.CHANNEL_CAPTION_THERMOMETER -> R.string.channel_caption_thermometer
LocalizedStringId.CHANNEL_CAPTION_HUMIDITY -> R.string.channel_caption_humidity
LocalizedStringId.CHANNEL_CAPTION_HUMIDITY_AND_TEMPERATURE -> R.string.channel_caption_humidityandtemperature
LocalizedStringId.CHANNEL_CAPTION_WIND_SENSOR -> R.string.channel_caption_windsensor
LocalizedStringId.CHANNEL_CAPTION_PRESSURE_SENSOR -> R.string.channel_caption_pressuresensor
LocalizedStringId.CHANNEL_CAPTION_RAIN_SENSOR -> R.string.channel_caption_rainsensor
LocalizedStringId.CHANNEL_CAPTION_WEIGHT_SENSOR -> R.string.channel_caption_weightsensor
LocalizedStringId.CHANNEL_CAPTION_NO_LIQUID_SENSOR -> R.string.channel_caption_noliquidsensor
LocalizedStringId.CHANNEL_CAPTION_DIMMER -> R.string.channel_caption_dimmer
LocalizedStringId.CHANNEL_CAPTION_RGB_LIGHTING -> R.string.channel_caption_rgblighting
LocalizedStringId.CHANNEL_CAPTION_DIMMER_AND_RGB_LIGHTING -> R.string.channel_caption_dimmerandrgblighting
LocalizedStringId.CHANNEL_CAPTION_DEPTH_SENSOR -> R.string.channel_caption_depthsensor
LocalizedStringId.CHANNEL_CAPTION_DISTANCE_SENSOR -> R.string.channel_caption_distancesensor
LocalizedStringId.CHANNEL_CAPTION_OPENING_SENSOR_WINDOW -> R.string.channel_caption_windowopeningsensor
LocalizedStringId.CHANNEL_CAPTION_HOTEL_CARD_SENSOR -> R.string.channel_caption_hotelcard
LocalizedStringId.CHANNEL_CAPTION_ALARM_ARMAMENT_SENSOR -> R.string.channel_caption_alarm_armament
LocalizedStringId.CHANNEL_CAPTION_MAIL_SENSOR -> R.string.channel_caption_mailsensor
LocalizedStringId.CHANNEL_CAPTION_STAIRCASE_TIMER -> R.string.channel_caption_staircasetimer
LocalizedStringId.CHANNEL_CAPTION_IC_GAS_METER -> R.string.channel_caption_gasmeter
LocalizedStringId.CHANNEL_CAPTION_IC_WATER_METER -> R.string.channel_caption_watermeter
LocalizedStringId.CHANNEL_CAPTION_IC_HEAT_METER -> R.string.channel_caption_heatmeter
LocalizedStringId.CHANNEL_CAPTION_THERMOSTAT_HEATPOL_HOMEPLUS -> R.string.channel_caption_thermostat_hp_homeplus
LocalizedStringId.CHANNEL_CAPTION_VALVE -> R.string.channel_caption_valve
LocalizedStringId.CHANNEL_CAPTION_GENERAL_PURPOSE_MEASUREMENT -> R.string.channel_caption_general_purpose_measurement
LocalizedStringId.CHANNEL_CAPTION_GENERAL_PURPOSE_METER -> R.string.channel_caption_general_purpose_meter
LocalizedStringId.CHANNEL_CAPTION_THERMOSTAT -> R.string.channel_caption_thermostat
LocalizedStringId.CHANNEL_CAPTION_ELECTRICITY_METER -> R.string.channel_caption_electricitymeter
LocalizedStringId.CHANNEL_CAPTION_DIGIGLASS -> R.string.channel_caption_digiglass
LocalizedStringId.CHANNEL_CAPTION_TERRACE_AWNING -> R.string.channel_caption_terrace_awning
LocalizedStringId.CHANNEL_CAPTION_PROJECTOR_SCREEN -> R.string.channel_caption_projector_screen
LocalizedStringId.CHANNEL_CAPTION_CURTAIN -> R.string.channel_caption_curtain
LocalizedStringId.CHANNEL_CAPTION_VERTICAL_BLIND -> R.string.channel_caption_vertical_blinds
LocalizedStringId.CHANNEL_CAPTION_ROLLER_GARAGE_DOOR -> R.string.channel_caption_roller_garage_door
LocalizedStringId.CHANNEL_CAPTION_PUMP_SWITCH -> R.string.channel_caption_pump_switch
LocalizedStringId.CHANNEL_CAPTION_HEAT_OR_COLD_SOURCE_SWITCH -> R.string.channel_caption_heat_or_cold_sourc_switch
LocalizedStringId.CHANNEL_CAPTION_UNKNOWN -> R.string.channel_not_supported

LocalizedStringId.CHANNEL_BATTERY_LEVEL -> R.string.channel_battery_level

LocalizedStringId.MOTOR_PROBLEM -> R.string.motor_problem
LocalizedStringId.CALIBRATION_LOST -> R.string.calibration_lost
LocalizedStringId.CALIBRATION_FAILED -> R.string.calibration_failed

LocalizedStringId.THERMOSTAT_THERMOMETER_ERROR -> R.string.thermostat_thermometer_error
LocalizedStringId.THERMOSTAT_BATTER_COVER_OPEN -> R.string.thermostat_battery_cover_open
LocalizedStringId.THERMOSTAT_CLOCK_ERROR -> R.string.thermostat_clock_error
}
Loading

0 comments on commit 6c0076c

Please sign in to comment.