From a2e887024f09d433e7f89a3e314bbed93ee8d0f0 Mon Sep 17 00:00:00 2001 From: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com> Date: Sat, 7 Jan 2023 17:24:28 +0300 Subject: [PATCH] android: Fixed compatibility with API 29 (#1674) --- .../src/main/java/chat/simplex/app/SimplexApp.kt | 2 +- .../java/chat/simplex/app/views/TerminalView.kt | 2 +- .../java/chat/simplex/app/views/chat/SendMsgView.kt | 13 +++++++++---- .../chat/simplex/app/views/chat/item/CIMetaView.kt | 2 +- .../app/views/chatlist/ShareListNavLinkView.kt | 2 +- 5 files changed, 13 insertions(+), 8 deletions(-) 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 d45dc24550..85cbd94ced 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 @@ -39,7 +39,7 @@ class SimplexApp: Application(), LifecycleEventObserver { var isAppOnForeground: Boolean = false fun initChatController(useKey: String? = null, startChat: Boolean = true) { - val dbKey = useKey ?: DatabaseUtils.useDatabaseKey() ?: "" + val dbKey = useKey ?: DatabaseUtils.useDatabaseKey() val dbAbsolutePathPrefix = getFilesDirectory(SimplexApp.context) val migrated: Array = chatMigrateInit(dbAbsolutePathPrefix, dbKey) val res: DBMigrationResult = kotlin.runCatching { 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 c1fdc7d105..acfb205d38 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 @@ -138,7 +138,7 @@ fun TerminalLayout( SendMsgView( composeState = composeState, showVoiceRecordIcon = false, - recState = mutableStateOf(RecordingState.NotStarted), + recState = remember { mutableStateOf(RecordingState.NotStarted) }, isDirectChat = false, liveMessageAlertShown = SharedPreference(get = { false }, set = {}), needToAllowVoiceToContact = false, diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/chat/SendMsgView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/chat/SendMsgView.kt index 439601ef79..1bf9b70383 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/chat/SendMsgView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/chat/SendMsgView.kt @@ -6,8 +6,10 @@ import android.app.Activity import android.content.Context import android.content.pm.ActivityInfo import android.content.res.Configuration +import android.os.Build import android.text.InputType import android.view.ViewGroup +import android.view.WindowManager import android.view.inputmethod.* import android.widget.EditText import androidx.compose.animation.core.* @@ -35,6 +37,7 @@ import androidx.compose.ui.text.font.FontStyle import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.* import androidx.compose.ui.viewinterop.AndroidView +import androidx.core.content.ContextCompat.getSystemService import androidx.core.graphics.drawable.DrawableCompat import androidx.core.view.inputmethod.EditorInfoCompat import androidx.core.view.inputmethod.InputConnectionCompat @@ -323,7 +326,9 @@ private fun LockToCurrentOrientationUntilDispose() { val context = LocalContext.current DisposableEffect(Unit) { val activity = context as Activity - activity.requestedOrientation = when (activity.display?.rotation) { + val manager = context.getSystemService(Activity.WINDOW_SERVICE) as WindowManager + val rotation = if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) manager.defaultDisplay.rotation else activity.display?.rotation + activity.requestedOrientation = when (rotation) { android.view.Surface.ROTATION_90 -> ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE android.view.Surface.ROTATION_180 -> ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT android.view.Surface.ROTATION_270 -> ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE @@ -519,7 +524,7 @@ fun PreviewSendMsgView() { SendMsgView( composeState = remember { mutableStateOf(ComposeState(useLinkPreviews = true)) }, showVoiceRecordIcon = false, - recState = mutableStateOf(RecordingState.NotStarted), + recState = remember { mutableStateOf(RecordingState.NotStarted) }, isDirectChat = true, liveMessageAlertShown = SharedPreference(get = { true }, set = { }), needToAllowVoiceToContact = false, @@ -547,7 +552,7 @@ fun PreviewSendMsgViewEditing() { SendMsgView( composeState = remember { mutableStateOf(composeStateEditing) }, showVoiceRecordIcon = false, - recState = mutableStateOf(RecordingState.NotStarted), + recState = remember { mutableStateOf(RecordingState.NotStarted) }, isDirectChat = true, liveMessageAlertShown = SharedPreference(get = { true }, set = { }), needToAllowVoiceToContact = false, @@ -575,7 +580,7 @@ fun PreviewSendMsgViewInProgress() { SendMsgView( composeState = remember { mutableStateOf(composeStateInProgress) }, showVoiceRecordIcon = false, - recState = mutableStateOf(RecordingState.NotStarted), + recState = remember { mutableStateOf(RecordingState.NotStarted) }, isDirectChat = true, liveMessageAlertShown = SharedPreference(get = { true }, set = { }), needToAllowVoiceToContact = false, diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/chat/item/CIMetaView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/chat/item/CIMetaView.kt index 7a341ad7c6..c8ff1c6aa7 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/chat/item/CIMetaView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/chat/item/CIMetaView.kt @@ -68,7 +68,7 @@ fun reserveSpaceForMeta(meta: CIMeta, chatTTL: Int?): String { if (meta.itemEdited) res += iconSpace if (meta.itemTimed != null) { res += iconSpace - val ttl = meta.itemTimed?.ttl + val ttl = meta.itemTimed.ttl if (ttl != chatTTL) { res += TimedMessagesPreference.shortTtlText(ttl) } diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/chatlist/ShareListNavLinkView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/chatlist/ShareListNavLinkView.kt index e9a007b1ce..5156144854 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/chatlist/ShareListNavLinkView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/chatlist/ShareListNavLinkView.kt @@ -29,7 +29,7 @@ fun ShareListNavLinkView(chat: Chat, chatModel: ChatModel) { click = { groupChatAction(chat.chatInfo.groupInfo, chatModel) }, stopped ) - is ChatInfo.ContactRequest, is ChatInfo.ContactConnection -> {} + is ChatInfo.ContactRequest, is ChatInfo.ContactConnection, is ChatInfo.InvalidJSON -> {} } }