diff --git a/apps/android/app/src/main/java/chat/simplex/app/MainActivity.kt b/apps/android/app/src/main/java/chat/simplex/app/MainActivity.kt index c4b44eff13..b32b2bb276 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/MainActivity.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/MainActivity.kt @@ -40,7 +40,6 @@ class MainActivity: ComponentActivity() { super.onCreate(savedInstanceState) // testJson() processIntent(intent, vm.chatModel) -// vm.app.initiateBackgroundWork() setContent { SimpleXTheme { Surface( diff --git a/apps/android/app/src/main/java/chat/simplex/app/SimplexApp.kt b/apps/android/app/src/main/java/chat/simplex/app/SimplexApp.kt index 14012c5ef7..5506c72daf 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/SimplexApp.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/SimplexApp.kt @@ -1,8 +1,6 @@ package chat.simplex.app import android.app.Application -import android.content.Context -import android.content.SharedPreferences import android.net.LocalServerSocket import android.util.Log import androidx.lifecycle.* @@ -49,6 +47,7 @@ class SimplexApp: Application(), LifecycleEventObserver { if (user != null) { chatController.startChat(user) SimplexService.start(applicationContext) + chatController.showBackgroundServiceNotice() } } } diff --git a/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt b/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt index 96a622c99c..e6ee092ff3 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/model/SimpleXAPI.kt @@ -5,7 +5,15 @@ import android.app.ActivityManager.RunningAppProcessInfo import android.content.Context import android.content.SharedPreferences import android.util.Log +import androidx.compose.foundation.layout.* +import androidx.compose.material.* +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.Bolt import androidx.compose.runtime.mutableStateOf +import androidx.compose.ui.Modifier +import androidx.compose.ui.text.* +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp import chat.simplex.app.* import chat.simplex.app.views.helpers.AlertManager import chat.simplex.app.views.helpers.withApi @@ -368,6 +376,51 @@ open class ChatController(private val ctrl: ChatCtrl, private val ntfManager: Nt chatModel.updateNetworkStatus(contact, Chat.NetworkStatus.Error(err)) } + fun showBackgroundServiceNotice() { + if (!getBackgroundServiceNoticeShown()) { + AlertManager.shared.showAlert { + AlertDialog( + onDismissRequest = AlertManager.shared::hideAlert, + title = { + Row { + Icon( + Icons.Outlined.Bolt, + contentDescription = "Instant notifications", + ) + Text("Private instant notifications!", fontWeight = FontWeight.Bold) + } + }, + text = { + Column { + Text( + buildAnnotatedString { + append("To preserve your privacy instead of push notifications the app has a ") + withStyle(SpanStyle(fontWeight = FontWeight.Medium)) { + append("SimpleX background service") + } + append(" – it uses only a few percents of battery a day.") + }, + Modifier.padding(bottom = 8.dp) + ) + Text( + buildAnnotatedString { + withStyle(SpanStyle(fontWeight = FontWeight.Medium)) { + append("It can be disabled via settings") + } + append(" – notification would still be shown while the app is running.") + } + ) + } + }, + confirmButton = { + Button(onClick = AlertManager.shared::hideAlert) { Text("Ok") } + } + ) + } + setBackgroundServiceNoticeShown() + } + } + fun getAutoRestartWorkerVersion(): Int = sharedPreferences.getInt(SHARED_PREFS_AUTO_RESTART_WORKER_VERSION, 0) fun setAutoRestartWorkerVersion(version: Int) = @@ -382,10 +435,18 @@ open class ChatController(private val ctrl: ChatCtrl, private val ntfManager: Nt .putBoolean(SHARED_PREFS_RUN_SERVICE_IN_BACKGROUND, runService) .apply() + fun getBackgroundServiceNoticeShown(): Boolean = sharedPreferences.getBoolean(SHARED_PREFS_SERVICE_NOTICE_SHOWN, false) + + fun setBackgroundServiceNoticeShown() = + sharedPreferences.edit() + .putBoolean(SHARED_PREFS_SERVICE_NOTICE_SHOWN, true) + .apply() + companion object { private const val SHARED_PREFS_ID = "chat.simplex.app.SIMPLEX_APP_PREFS" private const val SHARED_PREFS_AUTO_RESTART_WORKER_VERSION = "AutoRestartWorkerVersion" private const val SHARED_PREFS_RUN_SERVICE_IN_BACKGROUND = "RunServiceInBackground" + private const val SHARED_PREFS_SERVICE_NOTICE_SHOWN = "BackgroundServiceNoticeShown" } } diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/TerminalView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/TerminalView.kt index 3ce907afc7..98b828c42e 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/TerminalView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/TerminalView.kt @@ -1,6 +1,5 @@ package chat.simplex.app.views -import android.annotation.SuppressLint import android.content.res.Configuration import androidx.activity.compose.BackHandler import androidx.compose.foundation.* diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/WelcomeView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/WelcomeView.kt index b39cc64b8c..996b0bd2e1 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/WelcomeView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/WelcomeView.kt @@ -153,6 +153,7 @@ fun CreateProfilePanel(chatModel: ChatModel) { ) chatModel.controller.startChat(user) SimplexService.start(chatModel.controller.appContext) + chatModel.controller.showBackgroundServiceNotice() } }, enabled = (displayName.isNotEmpty() && isValidDisplayName(displayName)) diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/chat/ComposeView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/chat/ComposeView.kt index 790b34924d..3cea4b1f52 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/chat/ComposeView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/chat/ComposeView.kt @@ -1,7 +1,8 @@ package chat.simplex.app.views.chat import androidx.compose.foundation.layout.Column -import androidx.compose.runtime.* +import androidx.compose.runtime.Composable +import androidx.compose.runtime.MutableState import chat.simplex.app.model.ChatItem // TODO ComposeState diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/chat/item/ChatItemView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/chat/item/ChatItemView.kt index dd61b3515f..bf36647140 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/chat/item/ChatItemView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/chat/item/ChatItemView.kt @@ -5,7 +5,6 @@ import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.layout.* import androidx.compose.material.* import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.Edit import androidx.compose.material.icons.outlined.* import androidx.compose.runtime.* import androidx.compose.ui.Alignment diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/SettingsView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/SettingsView.kt index 086a90f222..aa476561c0 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/SettingsView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/SettingsView.kt @@ -154,10 +154,10 @@ fun SettingsLayout( SettingsSectionView() { Icon( Icons.Outlined.Bolt, - contentDescription = "Instant notifications", + contentDescription = "Private notifications", ) Spacer(Modifier.padding(horizontal = 4.dp)) - Text("Instant notifications", Modifier + Text("Private notifications", Modifier .padding(end = 24.dp) .fillMaxWidth() .weight(1F)) diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/UserProfileView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/UserProfileView.kt index f72e512bca..46ddaffe89 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/UserProfileView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/usersettings/UserProfileView.kt @@ -1,12 +1,8 @@ package chat.simplex.app.views.usersettings import android.content.res.Configuration -import android.widget.ScrollView import androidx.compose.foundation.* -import androidx.compose.foundation.gestures.Orientation -import androidx.compose.foundation.gestures.scrollable import androidx.compose.foundation.layout.* -import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.BasicTextField @@ -26,7 +22,6 @@ import androidx.compose.ui.unit.dp import chat.simplex.app.model.ChatModel import chat.simplex.app.model.Profile import chat.simplex.app.ui.theme.SimpleXTheme -import chat.simplex.app.views.chat.CIListState import chat.simplex.app.views.helpers.* import chat.simplex.app.views.newchat.ModalView import com.google.accompanist.insets.ProvideWindowInsets diff --git a/apps/android/build.gradle b/apps/android/build.gradle index af369aaf9a..ad0b119f62 100644 --- a/apps/android/build.gradle +++ b/apps/android/build.gradle @@ -1,6 +1,6 @@ buildscript { ext { - compose_version = '1.1.0' + compose_version = '1.1.1' } repositories { google()