Converted classmap to kotlin
This commit is contained in:
parent
92789c3113
commit
eb169cb133
@ -1,31 +0,0 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import com.topjohnwu.magisk.model.download.DownloadModuleService;
|
||||
import com.topjohnwu.magisk.model.receiver.GeneralReceiver;
|
||||
import com.topjohnwu.magisk.model.update.UpdateCheckService;
|
||||
import com.topjohnwu.magisk.ui.MainActivity;
|
||||
import com.topjohnwu.magisk.ui.SplashActivity;
|
||||
import com.topjohnwu.magisk.ui.flash.FlashActivity;
|
||||
import com.topjohnwu.magisk.ui.surequest.SuRequestActivity;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ClassMap {
|
||||
private static Map<Class, Class> classMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
classMap.put(App.class, a.e.class);
|
||||
classMap.put(MainActivity.class, a.b.class);
|
||||
classMap.put(SplashActivity.class, a.c.class);
|
||||
classMap.put(FlashActivity.class, a.f.class);
|
||||
classMap.put(UpdateCheckService.class, a.g.class);
|
||||
classMap.put(GeneralReceiver.class, a.h.class);
|
||||
classMap.put(DownloadModuleService.class, a.j.class);
|
||||
classMap.put(SuRequestActivity.class, a.m.class);
|
||||
}
|
||||
|
||||
public static <T> Class<T> get(Class c) {
|
||||
return classMap.get(c);
|
||||
}
|
||||
}
|
27
app/src/main/java/com/topjohnwu/magisk/ClassMap.kt
Normal file
27
app/src/main/java/com/topjohnwu/magisk/ClassMap.kt
Normal file
@ -0,0 +1,27 @@
|
||||
package com.topjohnwu.magisk
|
||||
|
||||
import com.topjohnwu.magisk.model.download.DownloadModuleService
|
||||
import com.topjohnwu.magisk.model.receiver.GeneralReceiver
|
||||
import com.topjohnwu.magisk.model.update.UpdateCheckService
|
||||
import com.topjohnwu.magisk.ui.MainActivity
|
||||
import com.topjohnwu.magisk.ui.SplashActivity
|
||||
import com.topjohnwu.magisk.ui.flash.FlashActivity
|
||||
import com.topjohnwu.magisk.ui.surequest.SuRequestActivity
|
||||
|
||||
object ClassMap {
|
||||
private val map = mapOf(
|
||||
App::class.java to a.e::class.java,
|
||||
MainActivity::class.java to a.b::class.java,
|
||||
SplashActivity::class.java to a.c::class.java,
|
||||
FlashActivity::class.java to a.f::class.java,
|
||||
UpdateCheckService::class.java to a.g::class.java,
|
||||
GeneralReceiver::class.java to a.h::class.java,
|
||||
DownloadModuleService::class.java to a.j::class.java,
|
||||
SuRequestActivity::class.java to a.m::class.java
|
||||
)
|
||||
|
||||
@JvmStatic
|
||||
operator fun get(c: Class<*>): Class<*>? {
|
||||
return map.getOrElse(c) { null } //as? Class<T>
|
||||
}
|
||||
}
|
@ -41,7 +41,7 @@ open class GeneralReceiver : BroadcastReceiver() {
|
||||
}
|
||||
when (action) {
|
||||
SuRequestActivity.REQUEST -> {
|
||||
val i = Intent(context, ClassMap.get<Any>(SuRequestActivity::class.java))
|
||||
val i = Intent(context, ClassMap[SuRequestActivity::class.java])
|
||||
.setAction(action)
|
||||
.putExtra("socket", intent.getStringExtra("socket"))
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
|
@ -48,7 +48,7 @@ open class MainActivity : MagiskActivity<MainViewModel, ActivityMainBinding>() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
if (!SplashActivity.DONE) {
|
||||
startActivity(Intent(this, ClassMap.get<Any>(SplashActivity::class.java)))
|
||||
startActivity(Intent(this, ClassMap[SplashActivity::class.java]))
|
||||
finish()
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ open class SplashActivity : AppCompatActivity() {
|
||||
//UpdateRepos().exec()
|
||||
}
|
||||
|
||||
val intent = Intent(this, ClassMap.get<Any>(MainActivity::class.java))
|
||||
val intent = Intent(this, ClassMap[MainActivity::class.java])
|
||||
intent.putExtra(Const.Key.OPEN_SECTION, getIntent().getStringExtra(Const.Key.OPEN_SECTION))
|
||||
DONE = true
|
||||
startActivity(intent)
|
||||
|
@ -28,7 +28,7 @@ class ModulesFragment : MagiskFragment<ModuleViewModel, FragmentModulesBinding>(
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (requestCode == Const.ID.FETCH_ZIP && resultCode == Activity.RESULT_OK && data != null) {
|
||||
// Get the URI of the selected file
|
||||
val intent = Intent(activity, ClassMap.get<Any>(FlashActivity::class.java))
|
||||
val intent = Intent(activity, ClassMap[FlashActivity::class.java])
|
||||
intent.setData(data.data).putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_ZIP)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ class ReposFragment : MagiskFragment<ModuleViewModel, FragmentReposBinding>(),
|
||||
|
||||
fun download(install: Boolean) {
|
||||
context.runWithExternalRW {
|
||||
val intent = Intent(activity, ClassMap.get<Any>(DownloadModuleService::class.java))
|
||||
val intent = Intent(activity, ClassMap[DownloadModuleService::class.java])
|
||||
.putExtra("repo", item).putExtra("install", install)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
context.startForegroundService(intent) //hmm, service starts itself in foreground, this seems unnecessary
|
||||
|
@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import androidx.annotation.WorkerThread;
|
||||
import androidx.work.Constraints;
|
||||
import androidx.work.ExistingPeriodicWorkPolicy;
|
||||
import androidx.work.ListenableWorker;
|
||||
import androidx.work.NetworkType;
|
||||
import androidx.work.PeriodicWorkRequest;
|
||||
import androidx.work.WorkManager;
|
||||
@ -110,13 +111,15 @@ public class Utils {
|
||||
return BuildConfig.VERSION_NAME.contains("-");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void scheduleUpdateCheck() {
|
||||
if (Config.get(Config.Key.CHECK_UPDATES)) {
|
||||
Constraints constraints = new Constraints.Builder()
|
||||
.setRequiredNetworkType(NetworkType.CONNECTED)
|
||||
.build();
|
||||
Class<? extends ListenableWorker> service = (Class<? extends ListenableWorker>) ClassMap.get(UpdateCheckService.class);
|
||||
PeriodicWorkRequest request = new PeriodicWorkRequest
|
||||
.Builder(ClassMap.get(UpdateCheckService.class), 12, TimeUnit.HOURS)
|
||||
.Builder(service, 12, TimeUnit.HOURS)
|
||||
.setConstraints(constraints)
|
||||
.build();
|
||||
WorkManager.getInstance().enqueueUniquePeriodicWork(
|
||||
|
Loading…
Reference in New Issue
Block a user