Fixed clearing cache crashing due to operations on main thread

This commit is contained in:
Viktor De Pasquale 2019-05-24 12:28:16 +02:00
parent aaabd836e4
commit f0a734fdab
2 changed files with 5 additions and 2 deletions

View File

@ -12,6 +12,7 @@ import com.topjohnwu.magisk.utils.Utils
import com.topjohnwu.magisk.utils.toSingle
import com.topjohnwu.magisk.utils.writeToFile
import com.topjohnwu.magisk.utils.writeToString
import io.reactivex.Completable
import io.reactivex.Single
class ModuleRepository(
@ -59,7 +60,7 @@ class ModuleRepository(
.fetchModuleInstaller()
.map { it.writeToFile(context, FILE_MODULE_INSTALLER_SH) }
fun deleteAllCached() = repoDao.deleteAll()
fun deleteAllCached() = Completable.fromCallable { repoDao.deleteAll() }
private fun fetchProperties(module: String, lastChanged: Long) = apiRaw

View File

@ -110,7 +110,9 @@ public final class SettingsFragment extends BasePreferenceFragment {
Preference clear = findPreference("clear");
clear.setOnPreferenceClickListener(pref -> {
getPrefs().edit().remove(Config.Key.ETAG_KEY).apply();
getModuleRepo().deleteAllCached();
getModuleRepo().deleteAllCached().subscribeOn(Schedulers.io()).subscribe(() -> {
}, throwable -> {
});
Utils.toast(R.string.repo_cache_cleared, Toast.LENGTH_SHORT);
return true;
});