Fix ActivityTracker
Koin does not support nullable types
This commit is contained in:
parent
7d93ca5c73
commit
9784353223
app/src/main/java/com/topjohnwu/magisk
@ -13,6 +13,7 @@ import androidx.work.impl.WorkDatabase
|
||||
import androidx.work.impl.WorkDatabase_Impl
|
||||
import com.topjohnwu.magisk.data.database.RepoDatabase
|
||||
import com.topjohnwu.magisk.data.database.RepoDatabase_Impl
|
||||
import com.topjohnwu.magisk.di.ActivityTracker
|
||||
import com.topjohnwu.magisk.di.koinModules
|
||||
import com.topjohnwu.magisk.extensions.get
|
||||
import com.topjohnwu.magisk.utils.LocaleManager
|
||||
@ -26,7 +27,7 @@ import java.util.concurrent.ThreadPoolExecutor
|
||||
|
||||
open class App : Application() {
|
||||
|
||||
lateinit var protectedContext: Context
|
||||
lateinit var deContext: Context
|
||||
|
||||
override fun attachBaseContext(base: Context) {
|
||||
super.attachBaseContext(base)
|
||||
@ -39,15 +40,15 @@ open class App : Application() {
|
||||
modules(koinModules)
|
||||
}
|
||||
|
||||
protectedContext = baseContext
|
||||
deContext = base
|
||||
self = this
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
protectedContext = base.createDeviceProtectedStorageContext()
|
||||
protectedContext.moveSharedPreferencesFrom(base, base.defaultPrefsName)
|
||||
deContext = base.createDeviceProtectedStorageContext()
|
||||
deContext.moveSharedPreferencesFrom(base, defaultPrefsName)
|
||||
}
|
||||
|
||||
registerActivityLifecycleCallbacks(get())
|
||||
registerActivityLifecycleCallbacks(get<ActivityTracker>())
|
||||
|
||||
Networking.init(base)
|
||||
LocaleManager.setLocale(this)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.topjohnwu.magisk.di
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
@ -14,15 +15,16 @@ val applicationModule = module {
|
||||
factory { get<Context>().resources }
|
||||
factory { get<Context>() as App }
|
||||
factory { get<Context>().packageManager }
|
||||
factory(Protected) { get<App>().protectedContext }
|
||||
factory(Protected) { get<App>().deContext }
|
||||
single(SUTimeout) { get<Context>(Protected).getSharedPreferences("su_timeout", 0) }
|
||||
single { PreferenceManager.getDefaultSharedPreferences(get<Context>(Protected)) }
|
||||
single { ActivityTracker() as Application.ActivityLifecycleCallbacks }
|
||||
factory { (get<Application.ActivityLifecycleCallbacks>() as ActivityTracker).foreground }
|
||||
single { ActivityTracker() }
|
||||
factory { get<ActivityTracker>().foreground ?: NullActivity }
|
||||
}
|
||||
|
||||
private class ActivityTracker : Application.ActivityLifecycleCallbacks {
|
||||
class ActivityTracker : Application.ActivityLifecycleCallbacks {
|
||||
|
||||
@Volatile
|
||||
var foreground: Activity? = null
|
||||
|
||||
override fun onActivityCreated(activity: Activity, bundle: Bundle?) {}
|
||||
@ -45,3 +47,6 @@ private class ActivityTracker : Application.ActivityLifecycleCallbacks {
|
||||
|
||||
override fun onActivityDestroyed(activity: Activity) {}
|
||||
}
|
||||
|
||||
@SuppressLint("Registered")
|
||||
object NullActivity : Activity()
|
||||
|
@ -7,6 +7,7 @@ import com.skoumal.teanity.extensions.subscribeK
|
||||
import com.topjohnwu.magisk.Config
|
||||
import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.data.network.GithubRawServices
|
||||
import com.topjohnwu.magisk.di.NullActivity
|
||||
import com.topjohnwu.magisk.extensions.firstMap
|
||||
import com.topjohnwu.magisk.extensions.get
|
||||
import com.topjohnwu.magisk.extensions.writeTo
|
||||
@ -56,7 +57,7 @@ abstract class RemoteFileService : NotificationService() {
|
||||
}
|
||||
}) {
|
||||
val newId = finishNotify(it, subject)
|
||||
get<Activity?>()?.run {
|
||||
if (get<Activity>() !is NullActivity) {
|
||||
onFinished(it, subject, newId)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user