Removed events from modules / replaced with retrofit/rx

This commit is contained in:
Viktor De Pasquale
2019-05-07 15:41:56 +02:00
parent 10e903c9fc
commit 7c755a3991
17 changed files with 116 additions and 223 deletions
@@ -36,9 +36,18 @@ public abstract class BaseModule implements Comparable<BaseModule>, Parcelable {
mVersionCode = p.readInt();
}
protected BaseModule(MagiskModule m) {
mId = m.getId();
mName = m.getName();
mVersion = m.getVersion();
mAuthor = m.getAuthor();
mDescription = m.getDescription();
mVersionCode = Integer.parseInt(m.getVersionCode());
}
@Override
public int compareTo(@NonNull BaseModule module) {
return this.getName().toLowerCase().compareTo(module.getName().toLowerCase());
return getName().toLowerCase().compareTo(module.getName().toLowerCase());
}
@Override
@@ -71,7 +80,9 @@ public abstract class BaseModule implements Comparable<BaseModule>, Parcelable {
return values;
}
protected void parseProps(List<String> props) { parseProps(props.toArray(new String[0])); }
protected void parseProps(List<String> props) {
parseProps(props.toArray(new String[0]));
}
protected void parseProps(String[] props) throws NumberFormatException {
for (String line : props) {
@@ -3,10 +3,14 @@ package com.topjohnwu.magisk.model.entity
import com.squareup.moshi.Json
import com.topjohnwu.magisk.utils.timeFormatStandard
import com.topjohnwu.magisk.utils.toTime
import timber.log.Timber
data class GithubRepo(
@Json(name = "name") val name: String,
@Json(name = "updated_at") val updatedAt: String
) {
val updatedAtMillis by lazy { updatedAt.toTime(timeFormatStandard) }
val updatedAtMillis by lazy {
updatedAt.toTime(timeFormatStandard)
.apply { Timber.i("$name updated @ $this ($updatedAt)") }
}
}
@@ -19,6 +19,7 @@ interface MagiskModule : Parcelable {
val author: String
val version: String
val versionCode: String
val description: String
}
@Entity(tableName = "repos")
@@ -30,6 +31,7 @@ data class Repository(
override val author: String,
override val version: String,
override val versionCode: String,
override val description: String,
val lastUpdate: Long
) : MagiskModule
@@ -40,6 +42,7 @@ data class Module(
override val author: String,
override val version: String,
override val versionCode: String,
override val description: String,
val path: String
) : MagiskModule
@@ -57,6 +60,7 @@ fun Map<String, String>.toModule(path: String): Module {
author = get("author").orEmpty(),
version = get("version").orEmpty(),
versionCode = get("versionCode").orEmpty(),
description = get("description").orEmpty(),
path = path
)
}
@@ -77,5 +81,6 @@ fun Map<String, String>.toRepository(lastUpdate: Long) = Repository(
author = get("author").orEmpty(),
version = get("version").orEmpty(),
versionCode = get("versionCode").orEmpty(),
description = get("description").orEmpty(),
lastUpdate = lastUpdate
)
@@ -29,6 +29,11 @@ public class Repo extends BaseModule {
mLastUpdate = new Date(p.readLong());
}
public Repo(Repository repo) {
super(repo);
mLastUpdate = new Date(repo.getLastUpdate());
}
public static final Parcelable.Creator<Repo> CREATOR = new Parcelable.Creator<Repo>() {
@Override
@@ -49,7 +54,7 @@ public class Repo extends BaseModule {
}
public void update() throws IllegalRepoException {
String props[] = Utils.dlString(getPropUrl()).split("\\n");
String[] props = Utils.dlString(getPropUrl()).split("\\n");
try {
parseProps(props);
} catch (NumberFormatException e) {
@@ -8,6 +8,7 @@ import com.skoumal.teanity.util.KObservableField
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.model.entity.OldModule
import com.topjohnwu.magisk.model.entity.Repo
import com.topjohnwu.magisk.model.entity.Repository
import com.topjohnwu.magisk.utils.get
import com.topjohnwu.magisk.utils.toggle
@@ -55,6 +56,8 @@ class ModuleRvItem(val item: OldModule) : ComparableRvItem<ModuleRvItem>() {
class RepoRvItem(val item: Repo) : ComparableRvItem<RepoRvItem>() {
constructor(repo: Repository) : this(Repo(repo))
override val layoutRes: Int = R.layout.item_repo
override fun contentSameAs(other: RepoRvItem): Boolean = item.version == other.item.version
@@ -1,33 +0,0 @@
package com.topjohnwu.magisk.model.update;
import androidx.annotation.NonNull;
import androidx.work.ListenableWorker;
import com.topjohnwu.magisk.App;
import com.topjohnwu.magisk.BuildConfig;
import com.topjohnwu.magisk.Config;
import com.topjohnwu.magisk.model.worker.DelegateWorker;
import com.topjohnwu.magisk.tasks.CheckUpdates;
import com.topjohnwu.magisk.view.Notifications;
import com.topjohnwu.superuser.Shell;
public class UpdateCheckService extends DelegateWorker {
@NonNull
@Override
public ListenableWorker.Result doWork() {
if (App.foreground() == null) {
Shell.getShell();
CheckUpdates.check(this::onCheckDone);
}
return ListenableWorker.Result.success();
}
private void onCheckDone() {
if (BuildConfig.VERSION_CODE < Config.remoteManagerVersionCode) {
Notifications.managerUpdate();
} else if (Config.magiskVersionCode < Config.remoteMagiskVersionCode) {
Notifications.magiskUpdate();
}
}
}
@@ -0,0 +1,31 @@
package com.topjohnwu.magisk.model.update
import androidx.work.ListenableWorker
import com.topjohnwu.magisk.BuildConfig
import com.topjohnwu.magisk.Config
import com.topjohnwu.magisk.data.repository.MagiskRepository
import com.topjohnwu.magisk.model.entity.MagiskConfig
import com.topjohnwu.magisk.model.worker.DelegateWorker
import com.topjohnwu.magisk.utils.inject
import com.topjohnwu.magisk.view.Notifications
class UpdateCheckService : DelegateWorker() {
private val magiskRepo: MagiskRepository by inject()
override fun doWork(): ListenableWorker.Result {
val config = runCatching { magiskRepo.fetchConfig().blockingGet() }
config.getOrNull()?.let { checkUpdates(it) }
return when {
config.isFailure -> ListenableWorker.Result.failure()
else -> ListenableWorker.Result.success()
}
}
private fun checkUpdates(config: MagiskConfig) {
when {
BuildConfig.VERSION_CODE < config.app.versionCode.toIntOrNull() ?: -1 -> Notifications.managerUpdate()
Config.magiskVersionCode < config.magisk.versionCode.toIntOrNull() ?: -1 -> Notifications.magiskUpdate()
}
}
}