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:
parent
52eb059515
commit
a9b00dd537
@ -11,12 +11,12 @@ import android.os.Build
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import androidx.multidex.MultiDex
|
import androidx.multidex.MultiDex
|
||||||
import androidx.preference.PreferenceManager
|
|
||||||
import com.topjohnwu.magisk.data.database.MagiskDB
|
import com.topjohnwu.magisk.data.database.MagiskDB
|
||||||
import com.topjohnwu.magisk.data.database.RepoDatabaseHelper
|
import com.topjohnwu.magisk.data.database.RepoDatabaseHelper
|
||||||
import com.topjohnwu.magisk.di.koinModules
|
import com.topjohnwu.magisk.di.koinModules
|
||||||
import com.topjohnwu.magisk.utils.LocaleManager
|
import com.topjohnwu.magisk.utils.LocaleManager
|
||||||
import com.topjohnwu.magisk.utils.RootUtils
|
import com.topjohnwu.magisk.utils.RootUtils
|
||||||
|
import com.topjohnwu.magisk.utils.inject
|
||||||
import com.topjohnwu.net.Networking
|
import com.topjohnwu.net.Networking
|
||||||
import com.topjohnwu.superuser.Shell
|
import com.topjohnwu.superuser.Shell
|
||||||
import org.koin.android.ext.android.inject
|
import org.koin.android.ext.android.inject
|
||||||
@ -27,36 +27,31 @@ import java.util.concurrent.ThreadPoolExecutor
|
|||||||
|
|
||||||
open class App : Application(), Application.ActivityLifecycleCallbacks {
|
open class App : Application(), Application.ActivityLifecycleCallbacks {
|
||||||
|
|
||||||
// Global resources
|
|
||||||
lateinit var protectedContext: Context
|
lateinit var protectedContext: Context
|
||||||
val prefs: SharedPreferences
|
|
||||||
get() = PreferenceManager.getDefaultSharedPreferences(
|
@Deprecated("Use dependency injection")
|
||||||
protectedContext
|
val prefs: SharedPreferences by inject()
|
||||||
)
|
@Deprecated("Use dependency injection")
|
||||||
val DB: MagiskDB by lazy { MagiskDB(protectedContext) }
|
val DB: MagiskDB by inject()
|
||||||
@Deprecated("Use dependency injection")
|
@Deprecated("Use dependency injection")
|
||||||
val repoDB: RepoDatabaseHelper by inject()
|
val repoDB: RepoDatabaseHelper by inject()
|
||||||
|
|
||||||
@Volatile
|
@Volatile
|
||||||
private var foreground: Activity? = null
|
private var foreground: Activity? = null
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun attachBaseContext(base: Context) {
|
||||||
super.onCreate()
|
super.attachBaseContext(base)
|
||||||
|
MultiDex.install(base)
|
||||||
|
Timber.plant(Timber.DebugTree())
|
||||||
|
|
||||||
startKoin {
|
startKoin {
|
||||||
androidContext(this@App)
|
androidContext(this@App)
|
||||||
modules(koinModules)
|
modules(koinModules)
|
||||||
}
|
}
|
||||||
|
|
||||||
Timber.plant(Timber.DebugTree())
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun attachBaseContext(base: Context) {
|
|
||||||
super.attachBaseContext(base)
|
|
||||||
MultiDex.install(base)
|
|
||||||
protectedContext = baseContext
|
protectedContext = baseContext
|
||||||
self = this
|
self = this
|
||||||
deContext = base
|
deContext = base
|
||||||
registerActivityLifecycleCallbacks(this)
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= 24) {
|
if (Build.VERSION.SDK_INT >= 24) {
|
||||||
protectedContext = base.createDeviceProtectedStorageContext()
|
protectedContext = base.createDeviceProtectedStorageContext()
|
||||||
@ -64,6 +59,8 @@ open class App : Application(), Application.ActivityLifecycleCallbacks {
|
|||||||
deContext.moveSharedPreferencesFrom(base, base.defaultPrefsName)
|
deContext.moveSharedPreferencesFrom(base, base.defaultPrefsName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registerActivityLifecycleCallbacks(this)
|
||||||
|
|
||||||
Networking.init(base)
|
Networking.init(base)
|
||||||
LocaleManager.setLocale(this)
|
LocaleManager.setLocale(this)
|
||||||
}
|
}
|
||||||
@ -99,19 +96,17 @@ open class App : Application(), Application.ActivityLifecycleCallbacks {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
//fixme this should be at least weak reference, me no likey
|
|
||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
@Deprecated("Use dependency injection")
|
@Deprecated("Use dependency injection")
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
lateinit var self: App
|
lateinit var self: App
|
||||||
|
|
||||||
//fixme this should be at least weak reference, me no likey
|
|
||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
@Deprecated("Use dependency injection")
|
@Deprecated("Use dependency injection; replace with protectedContext")
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
lateinit var deContext: Context
|
lateinit var deContext: Context
|
||||||
|
|
||||||
//fixme me no likey
|
@Deprecated("Use Rx or similar")
|
||||||
@JvmField
|
@JvmField
|
||||||
var THREAD_POOL: ThreadPoolExecutor
|
var THREAD_POOL: ThreadPoolExecutor
|
||||||
|
|
||||||
@ -124,11 +119,11 @@ open class App : Application(), Application.ActivityLifecycleCallbacks {
|
|||||||
THREAD_POOL = AsyncTask.THREAD_POOL_EXECUTOR as ThreadPoolExecutor
|
THREAD_POOL = AsyncTask.THREAD_POOL_EXECUTOR as ThreadPoolExecutor
|
||||||
}
|
}
|
||||||
|
|
||||||
//fixme me no likey
|
|
||||||
@Deprecated("")
|
@Deprecated("")
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun foreground(): Activity? {
|
fun foreground(): Activity? {
|
||||||
return self.foreground
|
val app: App by inject()
|
||||||
|
return app.foreground
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.topjohnwu.magisk.di
|
package com.topjohnwu.magisk.di
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import androidx.preference.PreferenceManager
|
||||||
import com.skoumal.teanity.rxbus.RxBus
|
import com.skoumal.teanity.rxbus.RxBus
|
||||||
import com.topjohnwu.magisk.App
|
import com.topjohnwu.magisk.App
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
@ -15,4 +16,5 @@ val applicationModule = module {
|
|||||||
get<App>().protectedContext
|
get<App>().protectedContext
|
||||||
.getSharedPreferences("su_timeout", 0)
|
.getSharedPreferences("su_timeout", 0)
|
||||||
}
|
}
|
||||||
|
single { PreferenceManager.getDefaultSharedPreferences(get<App>().protectedContext) }
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package com.topjohnwu.magisk.di
|
package com.topjohnwu.magisk.di
|
||||||
|
|
||||||
import com.topjohnwu.magisk.App
|
import com.topjohnwu.magisk.App
|
||||||
|
import com.topjohnwu.magisk.data.database.MagiskDB
|
||||||
import com.topjohnwu.magisk.data.database.RepoDatabaseHelper
|
import com.topjohnwu.magisk.data.database.RepoDatabaseHelper
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
|
|
||||||
|
|
||||||
val databaseModule = module {
|
val databaseModule = module {
|
||||||
single { get<App>().DB }
|
single { MagiskDB(get<App>().protectedContext) }
|
||||||
single { RepoDatabaseHelper(get()) }
|
single { RepoDatabaseHelper(get()) }
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,10 @@ import androidx.collection.SparseArrayCompat;
|
|||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
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 {
|
public abstract class BaseActivity extends AppCompatActivity implements Event.AutoListener, IBaseLeanback {
|
||||||
|
|
||||||
static int[] EMPTY_INT_ARRAY = new int[0];
|
static int[] EMPTY_INT_ARRAY = new int[0];
|
||||||
|
@ -8,6 +8,10 @@ import com.topjohnwu.magisk.utils.Event;
|
|||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import butterknife.Unbinder;
|
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 abstract class BaseFragment extends Fragment implements Event.AutoListener {
|
||||||
|
|
||||||
public App app = App.self;
|
public App app = App.self;
|
||||||
|
Loading…
Reference in New Issue
Block a user