android: notice about background service (#481)

* android: notice about background service

* update alert text
This commit is contained in:
Evgeny Poberezkin
2022-03-30 12:33:31 +01:00
committed by GitHub
parent 1b7cee9fcf
commit 8574674c2d
10 changed files with 68 additions and 14 deletions

View File

@@ -40,7 +40,6 @@ class MainActivity: ComponentActivity() {
super.onCreate(savedInstanceState)
// testJson()
processIntent(intent, vm.chatModel)
// vm.app.initiateBackgroundWork()
setContent {
SimpleXTheme {
Surface(

View File

@@ -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()
}
}
}

View File

@@ -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"
}
}

View File

@@ -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.*

View File

@@ -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))

View File

@@ -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

View File

@@ -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

View File

@@ -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))

View File

@@ -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

View File

@@ -1,6 +1,6 @@
buildscript {
ext {
compose_version = '1.1.0'
compose_version = '1.1.1'
}
repositories {
google()