Update ClassMap

This commit is contained in:
topjohnwu 2019-06-08 15:34:15 -07:00
parent e799918ab6
commit 2f320c7239
2 changed files with 3 additions and 6 deletions

View File

@ -21,7 +21,7 @@ object ClassMap {
)
@JvmStatic
operator fun get(c: Class<*>): Class<*>? {
return map.getOrElse(c) { null } //as? Class<T>
operator fun <T : Class<*>>get(c: Class<*>): T {
return map.getOrElse(c) { throw IllegalArgumentException() } as T
}
}

View File

@ -111,17 +111,14 @@ 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)
//ensures that notification doesn't pop up every time user starts the app
.setRequiresDeviceIdle(true)
.build();
Class<? extends ListenableWorker> service = (Class<? extends ListenableWorker>) ClassMap.get(UpdateCheckService.class);
PeriodicWorkRequest request = new PeriodicWorkRequest
.Builder(service, 12, TimeUnit.HOURS)
.Builder(ClassMap.get(UpdateCheckService.class), 12, TimeUnit.HOURS)
.setConstraints(constraints)
.build();
WorkManager.getInstance().enqueueUniquePeriodicWork(