Updated deprecation statements and moved components init after attaching base context

This needed to be done in order to get the Koin working as it requires injection before calling onCreate
This commit is contained in:
Viktor De Pasquale 2019-04-27 11:27:42 +02:00
parent 52eb059515
commit a9b00dd537
5 changed files with 29 additions and 23 deletions

View File

@ -11,12 +11,12 @@ import android.os.Build
import android.os.Bundle
import androidx.appcompat.app.AppCompatDelegate
import androidx.multidex.MultiDex
import androidx.preference.PreferenceManager
import com.topjohnwu.magisk.data.database.MagiskDB
import com.topjohnwu.magisk.data.database.RepoDatabaseHelper
import com.topjohnwu.magisk.di.koinModules
import com.topjohnwu.magisk.utils.LocaleManager
import com.topjohnwu.magisk.utils.RootUtils
import com.topjohnwu.magisk.utils.inject
import com.topjohnwu.net.Networking
import com.topjohnwu.superuser.Shell
import org.koin.android.ext.android.inject
@ -27,36 +27,31 @@ import java.util.concurrent.ThreadPoolExecutor
open class App : Application(), Application.ActivityLifecycleCallbacks {
// Global resources
lateinit var protectedContext: Context
val prefs: SharedPreferences
get() = PreferenceManager.getDefaultSharedPreferences(
protectedContext
)
val DB: MagiskDB by lazy { MagiskDB(protectedContext) }
@Deprecated("Use dependency injection")
val prefs: SharedPreferences by inject()
@Deprecated("Use dependency injection")
val DB: MagiskDB by inject()
@Deprecated("Use dependency injection")
val repoDB: RepoDatabaseHelper by inject()
@Volatile
private var foreground: Activity? = null
override fun onCreate() {
super.onCreate()
override fun attachBaseContext(base: Context) {
super.attachBaseContext(base)
MultiDex.install(base)
Timber.plant(Timber.DebugTree())
startKoin {
androidContext(this@App)
modules(koinModules)
}
Timber.plant(Timber.DebugTree())
}
override fun attachBaseContext(base: Context) {
super.attachBaseContext(base)
MultiDex.install(base)
protectedContext = baseContext
self = this
deContext = base
registerActivityLifecycleCallbacks(this)
if (Build.VERSION.SDK_INT >= 24) {
protectedContext = base.createDeviceProtectedStorageContext()
@ -64,6 +59,8 @@ open class App : Application(), Application.ActivityLifecycleCallbacks {
deContext.moveSharedPreferencesFrom(base, base.defaultPrefsName)
}
registerActivityLifecycleCallbacks(this)
Networking.init(base)
LocaleManager.setLocale(this)
}
@ -99,19 +96,17 @@ open class App : Application(), Application.ActivityLifecycleCallbacks {
companion object {
//fixme this should be at least weak reference, me no likey
@SuppressLint("StaticFieldLeak")
@Deprecated("Use dependency injection")
@JvmStatic
lateinit var self: App
//fixme this should be at least weak reference, me no likey
@SuppressLint("StaticFieldLeak")
@Deprecated("Use dependency injection")
@Deprecated("Use dependency injection; replace with protectedContext")
@JvmStatic
lateinit var deContext: Context
//fixme me no likey
@Deprecated("Use Rx or similar")
@JvmField
var THREAD_POOL: ThreadPoolExecutor
@ -124,11 +119,11 @@ open class App : Application(), Application.ActivityLifecycleCallbacks {
THREAD_POOL = AsyncTask.THREAD_POOL_EXECUTOR as ThreadPoolExecutor
}
//fixme me no likey
@Deprecated("")
@JvmStatic
fun foreground(): Activity? {
return self.foreground
val app: App by inject()
return app.foreground
}
}
}

View File

@ -1,6 +1,7 @@
package com.topjohnwu.magisk.di
import android.content.Context
import androidx.preference.PreferenceManager
import com.skoumal.teanity.rxbus.RxBus
import com.topjohnwu.magisk.App
import org.koin.dsl.module
@ -15,4 +16,5 @@ val applicationModule = module {
get<App>().protectedContext
.getSharedPreferences("su_timeout", 0)
}
single { PreferenceManager.getDefaultSharedPreferences(get<App>().protectedContext) }
}

View File

@ -1,11 +1,12 @@
package com.topjohnwu.magisk.di
import com.topjohnwu.magisk.App
import com.topjohnwu.magisk.data.database.MagiskDB
import com.topjohnwu.magisk.data.database.RepoDatabaseHelper
import org.koin.dsl.module
val databaseModule = module {
single { get<App>().DB }
single { MagiskDB(get<App>().protectedContext) }
single { RepoDatabaseHelper(get()) }
}

View File

@ -26,6 +26,10 @@ import androidx.collection.SparseArrayCompat;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
/**
* @deprecated This class is not to be used. It is marked for deletion.
*/
@Deprecated
public abstract class BaseActivity extends AppCompatActivity implements Event.AutoListener, IBaseLeanback {
static int[] EMPTY_INT_ARRAY = new int[0];

View File

@ -8,6 +8,10 @@ import com.topjohnwu.magisk.utils.Event;
import androidx.fragment.app.Fragment;
import butterknife.Unbinder;
/**
* @deprecated This class is not to be used. It is marked for deletion.
*/
@Deprecated
public abstract class BaseFragment extends Fragment implements Event.AutoListener {
public App app = App.self;