Skip to content

Commit 95097d0

Browse files
committed
Wear: enhance main activity
1 parent 6972230 commit 95097d0

6 files changed

Lines changed: 133 additions & 3 deletions

File tree

wearable/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ android {
2525
}
2626
}
2727
// namespace is used by R and BuildConfig classes
28-
namespace = "com.madness.collision.wearable"
28+
namespace = "io.cliuff.boundo.wear"
2929
compileSdk = 36
3030
defaultConfig {
3131
// below: manifest placeholders

wearable/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<uses-feature android:name="android.hardware.type.watch" />
2222

2323
<application
24-
android:name=".main.MainApplication"
24+
android:name=".MainApplication"
2525
android:allowBackup="true"
2626
android:icon="@mipmap/ic_launcher"
2727
android:roundIcon="@mipmap/ic_launcher_round"
@@ -30,7 +30,7 @@
3030
android:theme="@style/StartingAppTheme"
3131
tools:ignore="GoogleAppIndexingWarning">
3232
<activity
33-
android:name="io.cliuff.boundo.wear.MainActivity"
33+
android:name=".MainActivity"
3434
android:taskAffinity=".main"
3535
android:exported="true"
3636
android:enabled="true">

wearable/src/main/kotlin/io/cliuff/boundo/wear/MainActivity.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,37 @@ package io.cliuff.boundo.wear
1919
import android.os.Bundle
2020
import androidx.activity.ComponentActivity
2121
import androidx.activity.compose.setContent
22+
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
23+
import androidx.lifecycle.lifecycleScope
24+
import io.cliuff.boundo.wear.conf.MiscMain
25+
import io.cliuff.boundo.wear.ui.list.AppList
2226
import io.cliuff.boundo.wear.ui.theme.MetaAppTheme
27+
import kotlinx.coroutines.Dispatchers
28+
import kotlinx.coroutines.Job
29+
import kotlinx.coroutines.launch
2330

2431
class MainActivity : ComponentActivity() {
32+
private var appInitJob: Job? = null
33+
2534
override fun onCreate(savedInstanceState: Bundle?) {
35+
// handle splash screen transition
36+
installSplashScreen()
37+
2638
super.onCreate(savedInstanceState)
39+
applyAppInit()
40+
2741
setContent {
2842
MetaAppTheme {
43+
AppList()
2944
}
3045
}
3146
}
47+
48+
private fun applyAppInit() {
49+
appInitJob?.cancel()
50+
appInitJob = lifecycleScope.launch(Dispatchers.Default) {
51+
val prefs = getSharedPreferences("PrefSettings", MODE_PRIVATE)
52+
MiscMain.applyAppVersionUpgrade(applicationContext, prefs)
53+
}
54+
}
3255
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2025 Clifford Liu
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.cliuff.boundo.wear
18+
19+
import android.app.Application
20+
import coil3.SingletonImageLoader
21+
import io.cliuff.boundo.conf.CoilInitializer
22+
23+
class MainApplication : Application(),
24+
SingletonImageLoader.Factory by CoilInitializer
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2025 Clifford Liu
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.cliuff.boundo.wear.conf
18+
19+
import android.content.Context
20+
import android.content.SharedPreferences
21+
import androidx.core.content.edit
22+
23+
interface SelfUpdater {
24+
val maxVersion: Int
25+
fun apply(oldVersion: Int, prefSettings: SharedPreferences)
26+
}
27+
28+
internal object MiscMain {
29+
private const val APPLICATION_V = "v" // int
30+
31+
fun applyAppVersionUpgrade(context: Context, prefSettings: SharedPreferences) {
32+
val verDefault = -1
33+
val verOri = prefSettings.getInt(APPLICATION_V, verDefault)
34+
val updaters = listOf(SelfUpdater25())
35+
val ver = updaters.last().maxVersion
36+
// below: update registered version
37+
prefSettings.edit { putInt(APPLICATION_V, ver) }
38+
// below: app gone through update process
39+
if (verOri == ver) return
40+
// below: app in update process to the newest
41+
updaters.forEach { updater ->
42+
if (verOri in 0..<updater.maxVersion) updater.apply(verOri, prefSettings)
43+
}
44+
}
45+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2025 Clifford Liu
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.cliuff.boundo.wear.conf
18+
19+
import android.content.SharedPreferences
20+
import androidx.core.content.edit
21+
22+
class SelfUpdater25 : SelfUpdater {
23+
override val maxVersion: Int = 25082000
24+
25+
override fun apply(oldVersion: Int, prefSettings: SharedPreferences) {
26+
// check illegal version code
27+
if (oldVersion < 0) return
28+
// use ifs instead of when to implement fallthrough
29+
if (oldVersion < 25082000) {
30+
prefSettings.edit {
31+
remove("AVSweet")
32+
remove("AVIncludeDisabled")
33+
remove("SDKCheckSortSpinnerSelection1")
34+
remove("SDKCheckDisplaySpinnerSelection")
35+
}
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)