diff --git a/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt index 68b0e14e1..46d52cbdc 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt @@ -273,6 +273,12 @@ class ConversationsListActivity : adapter!!.addListener(this) prepareViews() + if (shouldShowIgnoreBatteryOptimizationHint()) { + showIgnoreBatteryOptimizationHint() + } else { + binding.chatListBatteryOptimizationIgnoredHint.visibility = View.GONE + } + showShareToScreen = hasActivityActionSendIntent() if (!eventBus.isRegistered(this)) { @@ -1453,32 +1459,8 @@ class ConversationsListActivity : } REQUEST_POST_NOTIFICATIONS_PERMISSION -> { - // whenever user allowed notifications, also check to ignore battery optimization if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - if (!PowerManagerUtils().isIgnoringBatteryOptimizations() && - ClosedInterfaceImpl().isGooglePlayServicesAvailable - ) { - val dialogText = String.format( - context.resources.getString(R.string.nc_ignore_battery_optimization_dialog_text), - context.resources.getString(R.string.nc_app_name) - ) - - val dialogBuilder = MaterialAlertDialogBuilder(this) - .setTitle(R.string.nc_ignore_battery_optimization_dialog_title) - .setMessage(dialogText) - .setPositiveButton(R.string.nc_ok) { _, _ -> - startActivity( - Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS) - ) - } - .setNegativeButton(R.string.nc_common_dismiss, null) - viewThemeUtils.dialog.colorMaterialAlertDialogBackground(this, dialogBuilder) - val dialog = dialogBuilder.show() - viewThemeUtils.platform.colorTextButtons( - dialog.getButton(AlertDialog.BUTTON_POSITIVE), - dialog.getButton(AlertDialog.BUTTON_NEGATIVE) - ) - } + Log.d(TAG, "Notification permission was granted") } else { Log.d( TAG, @@ -1490,6 +1472,41 @@ class ConversationsListActivity : } } + @SuppressLint("StringFormatInvalid") + private fun showIgnoreBatteryOptimizationHint() { + binding.chatListBatteryOptimizationIgnoredHint.visibility = View.VISIBLE + + val dialogText = String.format( + context.resources.getString(R.string.nc_ignore_battery_optimization_dialog_text), + context.resources.getString(R.string.nc_app_name) + ) + + val dialogBuilder = MaterialAlertDialogBuilder(this) + .setTitle(R.string.nc_ignore_battery_optimization_dialog_title) + .setMessage(dialogText) + .setPositiveButton(R.string.nc_ok) { _, _ -> + startActivity( + Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS) + ) + } + .setNegativeButton(R.string.nc_common_dismiss, null) + viewThemeUtils.dialog.colorMaterialAlertDialogBackground(this, dialogBuilder) + + binding.chatListBatteryOptimizationIgnoredHint.setOnClickListener { + val dialog = dialogBuilder.show() + viewThemeUtils.platform.colorTextButtons( + dialog.getButton(AlertDialog.BUTTON_POSITIVE), + dialog.getButton(AlertDialog.BUTTON_NEGATIVE) + ) + } + } + + private fun shouldShowIgnoreBatteryOptimizationHint() : Boolean { + return !PowerManagerUtils().isIgnoringBatteryOptimizations() && + ClosedInterfaceImpl().isGooglePlayServicesAvailable && + appPreferences.getShowIgnoreBatteryOptimizationHint() + } + private fun openConversation(textToPaste: String? = "") { if (CallActivity.active && selectedConversation!!.token != ApplicationWideCurrentRoomHolder.getInstance().currentRoomToken diff --git a/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt b/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt index 72a7e9795..493bcae75 100644 --- a/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt @@ -662,6 +662,7 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu private fun themeSwitchPreferences() { binding.run { listOf( + settingsShowIgnoreBatteryOptimizationHintSwitch, settingsScreenLockSwitch, settingsScreenSecuritySwitch, settingsIncognitoKeyboardSwitch, @@ -857,6 +858,19 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu } private fun setupCheckables() { + binding.settingsShowIgnoreBatteryOptimizationHintSwitch.isChecked = + appPreferences.showIgnoreBatteryOptimizationHint + + if (ClosedInterfaceImpl().isGooglePlayServicesAvailable) { + binding.settingsShowIgnoreBatteryOptimizationHint.setOnClickListener { + val isChecked = binding.settingsShowIgnoreBatteryOptimizationHintSwitch.isChecked + binding.settingsShowIgnoreBatteryOptimizationHintSwitch.isChecked = !isChecked + appPreferences.setShowIgnoreBatteryOptimizationHint(!isChecked) + } + } else { + binding.settingsShowIgnoreBatteryOptimizationHint.visibility = View.GONE + } + binding.settingsScreenSecuritySwitch.isChecked = appPreferences.isScreenSecured binding.settingsIncognitoKeyboardSwitch.isChecked = appPreferences.isKeyboardIncognito diff --git a/app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferences.java b/app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferences.java index 606614a72..b779337ed 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferences.java +++ b/app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferences.java @@ -178,6 +178,9 @@ public interface AppPreferences { void deleteAllMessageQueuesFor(String userId); + boolean getShowIgnoreBatteryOptimizationHint(); + + void setShowIgnoreBatteryOptimizationHint(boolean showIgnoreBatteryOptimizationHint); void clear(); } diff --git a/app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferencesImpl.kt b/app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferencesImpl.kt index c3e2fcc48..6a913ea19 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferencesImpl.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/preferences/AppPreferencesImpl.kt @@ -544,6 +544,19 @@ class AppPreferencesImpl(val context: Context) : AppPreferences { } } + override fun getShowIgnoreBatteryOptimizationHint(): Boolean { + return runBlocking { async { + readBoolean(SHOW_IGNORE_BATTERY_OPTIMIZATION_HINT, true).first() + } }.getCompleted() + } + + override fun setShowIgnoreBatteryOptimizationHint(showIgnoreBatteryOptimizationHint: Boolean) = + runBlocking { + async { + writeBoolean(SHOW_IGNORE_BATTERY_OPTIMIZATION_HINT, showIgnoreBatteryOptimizationHint) + } + } + override fun clear() {} private suspend fun writeString(key: String, value: String) = @@ -628,6 +641,7 @@ class AppPreferencesImpl(val context: Context) : AppPreferences { const val PHONE_BOOK_INTEGRATION_LAST_RUN = "phone_book_integration_last_run" const val TYPING_STATUS = "typing_status" const val MESSAGE_QUEUE = "@message_queue" + const val SHOW_IGNORE_BATTERY_OPTIMIZATION_HINT = "show_ignore_battery_optimization_hint" private fun String.convertStringToArray(): Array { var varString = this val floatList = mutableListOf() diff --git a/app/src/main/res/layout/activity_conversations.xml b/app/src/main/res/layout/activity_conversations.xml index bdf5880e1..0c71bb4ba 100644 --- a/app/src/main/res/layout/activity_conversations.xml +++ b/app/src/main/res/layout/activity_conversations.xml @@ -37,6 +37,18 @@ android:visibility="gone" tools:visibility="visible" /> + + + + + + + + + + + + + + #99000000 #EF3B02 #DBE2E9 + #FF9800 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ca4c364cf..01f10ccdf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -181,6 +181,8 @@ How to translate with transifex: Ignore battery optimization Battery optimization is not ignored. This should be changed to make sure that notifications work in the background! Please click OK and select \"All apps\" -> %1$s -> Do not optimize + Show battery optimization hint + When the battery optimization is not ignored, show a hint Meta information Generation of system report