Press back to hide EditSourceCompose. Double back to quit app - Android
This commit is contained in:
parent
b82fc6a048
commit
1f4c0d4829
4 changed files with 36 additions and 3 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
package mg.dot.feufaro
|
package mg.dot.feufaro
|
||||||
|
|
||||||
|
import SharedScreenModel
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.app.ComponentCaller
|
import android.app.ComponentCaller
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
|
@ -10,7 +11,9 @@ import android.os.Environment
|
||||||
import android.util.Base64
|
import android.util.Base64
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
|
import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
|
@ -22,11 +25,14 @@ import androidx.core.view.WindowCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import androidx.core.view.WindowInsetsControllerCompat
|
import androidx.core.view.WindowInsetsControllerCompat
|
||||||
import mg.dot.feufaro.ui.LocalFullscreenController
|
import mg.dot.feufaro.ui.LocalFullscreenController
|
||||||
|
import org.koin.android.ext.android.inject
|
||||||
import org.koin.androidx.compose.KoinAndroidContext
|
import org.koin.androidx.compose.KoinAndroidContext
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.zip.GZIPInputStream
|
import java.util.zip.GZIPInputStream
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
|
private val sharedScreenModel: SharedScreenModel by inject()
|
||||||
|
private var lastBackTime = 0L
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
ActivityCompat.requestPermissions(
|
ActivityCompat.requestPermissions(
|
||||||
this,
|
this,
|
||||||
|
|
@ -43,6 +49,27 @@ class MainActivity : ComponentActivity() {
|
||||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||||
intent?.let { handleDeepLinkIntent(it) }
|
intent?.let { handleDeepLinkIntent(it) }
|
||||||
|
|
||||||
|
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
|
||||||
|
override fun handleOnBackPressed() {
|
||||||
|
if (sharedScreenModel.sourceModeState.value) {
|
||||||
|
sharedScreenModel.toggleSourceMode()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val currentTime = System.currentTimeMillis()
|
||||||
|
if (currentTime - lastBackTime < 2000) {
|
||||||
|
finish()
|
||||||
|
} else {
|
||||||
|
lastBackTime = currentTime
|
||||||
|
Toast.makeText(
|
||||||
|
this@MainActivity,
|
||||||
|
"Appuyez à nouveau pour quitter",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
KoinAndroidContext {
|
KoinAndroidContext {
|
||||||
|
|
@ -65,7 +92,6 @@ class MainActivity : ComponentActivity() {
|
||||||
windowInsetsController.show(WindowInsetsCompat.Type.statusBars())
|
windowInsetsController.show(WindowInsetsCompat.Type.statusBars())
|
||||||
windowInsetsController.systemBarsBehavior =
|
windowInsetsController.systemBarsBehavior =
|
||||||
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||||
window.statusBarColor = android.graphics.Color.TRANSPARENT
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
window.attributes.layoutInDisplayCutoutMode =
|
window.attributes.layoutInDisplayCutoutMode =
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<background android:drawable="@mipmap/ic_launcher_background"/>
|
<background android:drawable="@drawable/ic_launcher_background"/>
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
||||||
</adaptive-icon>
|
</adaptive-icon>
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<background android:drawable="@mipmap/ic_launcher_background"/>
|
<background android:drawable="@drawable/ic_launcher_background"/>
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
||||||
</adaptive-icon>
|
</adaptive-icon>
|
||||||
|
|
@ -44,6 +44,8 @@ import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.*
|
import androidx.compose.ui.unit.*
|
||||||
import androidx.compose.ui.window.Popup
|
import androidx.compose.ui.window.Popup
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
|
import cafe.adriel.voyager.core.annotation.InternalVoyagerApi
|
||||||
|
import cafe.adriel.voyager.navigator.internal.BackHandler
|
||||||
import feufaro.composeapp.generated.resources.Emmentaler
|
import feufaro.composeapp.generated.resources.Emmentaler
|
||||||
import feufaro.composeapp.generated.resources.PTSerif_Bold
|
import feufaro.composeapp.generated.resources.PTSerif_Bold
|
||||||
import feufaro.composeapp.generated.resources.PT_Serif_Bold_Italic
|
import feufaro.composeapp.generated.resources.PT_Serif_Bold_Italic
|
||||||
|
|
@ -1421,12 +1423,17 @@ private suspend fun expandInclusions(
|
||||||
return result.toString().trimEnd()
|
return result.toString().trimEnd()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(InternalVoyagerApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun EditSourceCompose(
|
fun EditSourceCompose(
|
||||||
sharedScreenModel: SharedScreenModel,
|
sharedScreenModel: SharedScreenModel,
|
||||||
solfaScreenModel: SolfaScreenModel
|
solfaScreenModel: SolfaScreenModel
|
||||||
) {
|
) {
|
||||||
var isEditorVisible = sharedScreenModel.sourceModeState.value
|
var isEditorVisible = sharedScreenModel.sourceModeState.value
|
||||||
|
BackHandler(enabled = isEditorVisible) {
|
||||||
|
sharedScreenModel.toggleSourceMode()
|
||||||
|
}
|
||||||
|
|
||||||
var sourcePath = sharedScreenModel.activeFilePath.value
|
var sourcePath = sharedScreenModel.activeFilePath.value
|
||||||
var sourceContent = sharedScreenModel.fileContent.value ?: ""
|
var sourceContent = sharedScreenModel.fileContent.value ?: ""
|
||||||
var sourceTitle = sharedScreenModel.songTitle.value
|
var sourceTitle = sharedScreenModel.songTitle.value
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue