Skip to content

Commit

Permalink
BandReader1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
v_zhaoyutia committed Sep 26, 2023
1 parent 11972ae commit b19341f
Show file tree
Hide file tree
Showing 19 changed files with 42 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
.externalNativeBuild
.cxx
local.properties
/.idea/
Binary file modified app/release/app-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:icon="@mipmap/logo"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:roundIcon="@mipmap/logo"
android:supportsRtl="true"
android:theme="@style/Theme.bandReader"
tools:targetApi="31">
Expand Down
42 changes: 38 additions & 4 deletions app/src/main/java/com/example/bandReader/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.widget.Toast
import androidx.activity.OnBackPressedDispatcher
import androidx.activity.addCallback
import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
Expand Down Expand Up @@ -92,6 +94,7 @@ import com.nareshchocha.filepickerlibrary.utilities.appConst.Const
import com.permissionx.guolindev.PermissionX
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -110,6 +113,7 @@ class MainActivity : AppCompatActivity() {
private val uri: MutableStateFlow<Uri> = MutableStateFlow(Uri.EMPTY)
private lateinit var bluetoothManager: BluetoothManager
private lateinit var bluetoothAdapter: BluetoothAdapter
private var countDown = 0L

private val pickFileLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
Expand All @@ -136,7 +140,7 @@ class MainActivity : AppCompatActivity() {
initBlue()

lifecycleScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED){
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
mainViewModel.restartFlow.collect {
if (it) {
restart()
Expand All @@ -148,6 +152,12 @@ class MainActivity : AppCompatActivity() {
setContent {
BandReaderTheme(darkTheme = true) {
navController = rememberNavController()
(navController as NavHostController).setLifecycleOwner(this@MainActivity)
val onBackPressedDispatcher = OnBackPressedDispatcher()
onBackPressedDispatcher.addCallback(owner = this@MainActivity, enabled = true){
Toast.makeText(this@MainActivity, "navhost back", Toast.LENGTH_SHORT).show()
}
(navController as NavHostController).setOnBackPressedDispatcher(onBackPressedDispatcher)
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier
Expand Down Expand Up @@ -255,7 +265,7 @@ class MainActivity : AppCompatActivity() {
).show()
if (mainViewModel.grantedErrFlow.value) {
restart()
}else{
} else {
lifecycleScope.launch {
mainViewModel.getConnectedDevice()
delay(1000)
Expand Down Expand Up @@ -289,7 +299,8 @@ class MainActivity : AppCompatActivity() {
}
}
}
fun restart(){

fun restart() {
Handler(Looper.getMainLooper()).postDelayed({
val launchIntent =
packageManager.getLaunchIntentForPackage(application.packageName)
Expand All @@ -298,6 +309,27 @@ class MainActivity : AppCompatActivity() {
}, 1000)
}

override fun onBackPressed() {
// super.onBackPressed()
if (navController.currentBackStackEntry?.destination?.route.equals("home")){
if (countDown !== 0L){
android.os.Process.killProcess(android.os.Process.myPid())
System.exit(0)
}else{
Toast.makeText(this@MainActivity, "再次返回退出", Toast.LENGTH_SHORT).show()
countDown = 2000L
lifecycleScope.launch {
delay(2000)
countDown = 0
}
}
}else{
navController.popBackStack()

}

}

@OptIn(ExperimentalFoundationApi::class)
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@Composable
Expand Down Expand Up @@ -527,7 +559,9 @@ class MainActivity : AppCompatActivity() {
Text(
text = syncState.value.str,
textAlign = TextAlign.Center,
modifier = Modifier.width(Dp((14*5).sp.value)).padding(bottom = 3.dp)
modifier = Modifier
.width(Dp((14 * 5).sp.value))
.padding(bottom = 3.dp)
)
},
)
Expand Down
Binary file added app/src/main/res/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 0 additions & 6 deletions app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml

This file was deleted.

6 changes: 0 additions & 6 deletions app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml

This file was deleted.

Binary file removed app/src/main/res/mipmap-hdpi/ic_launcher.webp
Binary file not shown.
Binary file removed app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
Binary file not shown.
Binary file removed app/src/main/res/mipmap-mdpi/ic_launcher.webp
Binary file not shown.
Binary file removed app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xhdpi/ic_launcher.webp
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
Binary file not shown.
Binary file not shown.
Binary file removed app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
Binary file not shown.
Binary file not shown.
Binary file added app/src/main/res/mipmap-xxxhdpi/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="app_name">bandReader</string>
<string name="app_name">BandReader</string>
</resources>

0 comments on commit b19341f

Please sign in to comment.