Skip to content
This repository was archived by the owner on Jul 16, 2024. It is now read-only.

File tree

7 files changed

+40
-8
lines changed

7 files changed

+40
-8
lines changed

app/build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ android {
2121
dataBinding = true
2222
resValues = true
2323
}
24-
lint.abortOnError = true
24+
lint {
25+
abortOnError = true
26+
warningsAsErrors = true
27+
}
2528
val releaseSigning = signingConfigs.create("release") {
2629
keyAlias = getSignProperty("keyAlias")
2730
keyPassword = getSignProperty("keyPassword")

base/src/main/kotlin/io/goooler/demoapp/base/core/BaseFragment.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ abstract class BaseFragment : Fragment(), IFragment {
1010
super.onCreate(savedInstanceState)
1111
activity?.onBackPressedDispatcher?.addCallback(this) {
1212
isEnabled = onBackPressed()
13+
@Suppress("DEPRECATION")
1314
if (!isEnabled) activity?.onBackPressed()
1415
isEnabled = true
1516
}

base/src/main/kotlin/io/goooler/demoapp/base/core/BaseService.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package io.goooler.demoapp.base.core
22

33
import android.app.Notification
44
import android.app.NotificationManager
5+
import android.app.Service
6+
import android.os.Build
57
import androidx.annotation.DrawableRes
68
import androidx.annotation.IntRange
79
import androidx.core.app.NotificationChannelCompat
@@ -48,7 +50,12 @@ abstract class BaseService : LifecycleService() {
4850
}
4951

5052
override fun onDestroy() {
51-
stopForeground(true)
53+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
54+
stopForeground(Service.STOP_FOREGROUND_REMOVE)
55+
} else {
56+
@Suppress("DEPRECATION")
57+
stopForeground(true)
58+
}
5259
super.onDestroy()
5360
}
5461
}

base/src/main/kotlin/io/goooler/demoapp/base/util/BaseExtensions.kt

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,19 @@ inline val isMainThread: Boolean get() = Looper.getMainLooper() == Looper.myLoop
8383
fun <T : Any> unsafeLazy(initializer: () -> T): Lazy<T> =
8484
lazy(LazyThreadSafetyMode.NONE, initializer)
8585

86-
fun <T : Parcelable> T.deepCopy(): T? {
86+
inline fun <reified T : Parcelable> T.deepCopy(): T? {
8787
var parcel: Parcel? = null
8888
return try {
8989
parcel = Parcel.obtain().also {
9090
it.writeParcelable(this, 0)
9191
it.setDataPosition(0)
9292
}
93-
parcel.readParcelable(this::class.java.classLoader)
93+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
94+
parcel.readParcelable(this::class.java.classLoader, T::class.java)
95+
} else {
96+
@Suppress("DEPRECATION")
97+
parcel.readParcelable(this::class.java.classLoader)
98+
}
9499
} finally {
95100
parcel?.recycle()
96101
}
@@ -362,13 +367,26 @@ fun Intent.getStringExtra(name: String, defaultValue: String): String =
362367
fun Intent.getCharSequenceExtra(name: String, defaultValue: CharSequence): CharSequence =
363368
getCharSequenceExtra(name) ?: defaultValue
364369

365-
inline fun <reified T : Parcelable> Intent.getParcelableExtra(name: String, defaultValue: T): T =
366-
getParcelableExtra(name) ?: defaultValue
370+
inline fun <reified T : Parcelable> Intent.getParcelableExtra(name: String, defaultValue: T): T {
371+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
372+
getParcelableExtra(name, T::class.java)
373+
} else {
374+
@Suppress("DEPRECATION")
375+
getParcelableExtra(name)
376+
} ?: defaultValue
377+
}
367378

368379
inline fun <reified T : Serializable> Intent.getSerializableExtra(
369380
name: String,
370381
defaultValue: T,
371-
): T = (getSerializableExtra(name) ?: defaultValue) as T
382+
): T {
383+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
384+
getSerializableExtra(name, T::class.java)
385+
} else {
386+
@Suppress("DEPRECATION")
387+
getSerializableExtra(name) as T
388+
} ?: defaultValue
389+
}
372390

373391
// ---------------------Fragment-------------------------------//
374392

@@ -526,6 +544,7 @@ fun Context.setMusicMute(mute: Boolean = true) {
526544
val direction = if (mute) AudioManager.ADJUST_UNMUTE else AudioManager.ADJUST_MUTE
527545
it.adjustStreamVolume(AudioManager.STREAM_MUSIC, direction, 0)
528546
} else {
547+
@Suppress("DEPRECATION")
529548
it.setStreamMute(AudioManager.STREAM_MUSIC, mute)
530549
}
531550
}

biz/login/src/main/kotlin/io/goooler/demoapp/login/ui/SplashActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class SplashActivity : BaseActivity() {
1818
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
1919
finish()
2020
} else {
21+
@Suppress("DEPRECATION")
2122
super.onBackPressed()
2223
}
2324
}

biz/main/src/main/kotlin/io/goooler/demoapp/main/vm/MainSrlViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class MainSrlViewModel : BaseViewModel() {
7171
finishRefreshAndLoadMore(false)
7272
repository.getRepoListFromApi("goooler", page)
7373
.map { bean ->
74-
MainCommonVhModel.Repo(bean.owner?.avatarUrl, bean.name, bean.fullName)
74+
MainCommonVhModel.Repo(bean.owner.avatarUrl, bean.name, bean.fullName)
7575
}.let {
7676
_listData += it
7777
if (page == 1 && it.isEmpty()) {

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ allprojects {
3535

3636
tasks.withType<KotlinCompile> {
3737
kotlinOptions {
38+
allWarningsAsErrors = true
3839
jvmTarget = JavaVersion.VERSION_11.toString()
3940
}
4041
}

0 commit comments

Comments
 (0)