PackageViewModel 增加重试功能
This commit is contained in:
@ -772,6 +772,7 @@ public class MainActivity extends BaseActivity {
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEventMainThread(EBNetworkState busNetworkState) {
|
||||
if (busNetworkState.isNetworkConnected()) {
|
||||
mPackageViewModel.checkData();
|
||||
checkRetryDownload();
|
||||
if (Config.getSettings() == null) {
|
||||
getGhzsSettings();
|
||||
|
||||
@ -64,10 +64,10 @@ object PackageRepository {
|
||||
|
||||
val list = PackageUtils.getAllPackageName(mApplication)
|
||||
|
||||
filterPackers(list)
|
||||
|
||||
uploadAppList()
|
||||
|
||||
filterPackers(list)
|
||||
|
||||
loadInstalledGameDigestAndNotifyData(list)
|
||||
loadGhzsUpdate()
|
||||
}
|
||||
@ -115,17 +115,23 @@ object PackageRepository {
|
||||
* 忽略非合法数据
|
||||
*/
|
||||
private fun filterPackers(list: MutableList<String>) {
|
||||
// 忽略特定的包
|
||||
list.remove(Constants.XPOSED_INSTALLER_PACKAGE_NAME)
|
||||
|
||||
// 忽略非助手收录的包 todo 必须先获取接口数据 否则无法此次操作失败(bug)
|
||||
// 忽略非助手收录的包
|
||||
val localList = ArrayList<String>()
|
||||
val filterManager = FilterManager(mApplication)
|
||||
for (pkgName in list) {
|
||||
if (filterManager.isFilter(pkgName)) {
|
||||
localList.add(pkgName)
|
||||
if (filterManager.isInitOver) {
|
||||
for (pkgName in list) {
|
||||
if (filterManager.isFilter(pkgName)) {
|
||||
localList.add(pkgName)
|
||||
}
|
||||
}
|
||||
if (localList.isNotEmpty()) {
|
||||
list.clear()
|
||||
list.addAll(localList)
|
||||
}
|
||||
}
|
||||
|
||||
// 忽略特定的包
|
||||
list.remove(Constants.XPOSED_INSTALLER_PACKAGE_NAME)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,7 +143,7 @@ object PackageRepository {
|
||||
private fun loadInstalledGameDigestAndNotifyData(list: ArrayList<String>) {
|
||||
var isNotifyUpdate = false
|
||||
val latch = ObservableUtil.latch(list.size, {
|
||||
if (isNotifyUpdate) notifyGameUpdateData()
|
||||
if (isNotifyUpdate || gameUpdateLiveData.value == null) notifyGameUpdateData()
|
||||
notifyGameInstallData()
|
||||
}, Any())
|
||||
|
||||
|
||||
@ -12,17 +12,17 @@ import com.halo.assistant.HaloApp
|
||||
|
||||
|
||||
class PackageViewModel(application: Application,
|
||||
private val repository: PackageRepository) : AndroidViewModel(application) {
|
||||
private val mRepository: PackageRepository) : AndroidViewModel(application) {
|
||||
init {
|
||||
|
||||
}
|
||||
|
||||
fun getGameUpdateLiveData(): MutableLiveData<List<GameUpdateEntity>> {
|
||||
return repository.gameUpdateLiveData
|
||||
return mRepository.gameUpdateLiveData
|
||||
}
|
||||
|
||||
fun getGameInstalledLiveData(): MutableLiveData<List<GameInstall>> {
|
||||
return repository.gameInstalledLiveData
|
||||
return mRepository.gameInstalledLiveData
|
||||
}
|
||||
|
||||
/**
|
||||
@ -30,7 +30,7 @@ class PackageViewModel(application: Application,
|
||||
* 只在收到安装广播时调用,不建议手动调用
|
||||
*/
|
||||
fun addInstalledGame(pkgName: String?) {
|
||||
if (!TextUtils.isEmpty(pkgName)) repository.installedGame(pkgName!!)
|
||||
if (!TextUtils.isEmpty(pkgName)) mRepository.installedGame(pkgName!!)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,15 +38,17 @@ class PackageViewModel(application: Application,
|
||||
* 只在收到卸载广播时调用,不建议手动调用
|
||||
*/
|
||||
fun addUninstalledGame(pkgName: String?) {
|
||||
if (!TextUtils.isEmpty(pkgName)) repository.uninstalledGame(pkgName!!)
|
||||
if (!TextUtils.isEmpty(pkgName)) mRepository.uninstalledGame(pkgName!!)
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查数据(查看数据是否初始化完成,未完成则重新加载)
|
||||
* 网络状态变更时调用
|
||||
*/
|
||||
fun checkInstallData() {
|
||||
|
||||
fun checkData() {
|
||||
if (mRepository.gameInstalled.size == 0) {
|
||||
mRepository.initData()
|
||||
}
|
||||
}
|
||||
|
||||
class Factory : ViewModelProvider.NewInstanceFactory() {
|
||||
|
||||
@ -23,14 +23,24 @@ import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
public class FilterManager {
|
||||
|
||||
private final static String FILTER_INIT_OVER_KEY = "filterInitOver";
|
||||
private SharedPreferences mPreferences;
|
||||
private FilterDao mFilterDao;
|
||||
private Context mContext;
|
||||
|
||||
public FilterManager(Context context) {
|
||||
mContext = context;
|
||||
mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
mFilterDao = new FilterDao(context);
|
||||
}
|
||||
|
||||
public Boolean isInitOver() {
|
||||
if (mPreferences.getBoolean(FILTER_INIT_OVER_KEY, false)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void deleteFilters(List<PackageInfo> list) {
|
||||
mFilterDao.deleteAll(list);
|
||||
}
|
||||
@ -100,6 +110,8 @@ public class FilterManager {
|
||||
}
|
||||
if (response.size() == 5000) {
|
||||
getFilterFromServer(skip + 5000);
|
||||
} else if (!isInitOver()) {
|
||||
mPreferences.edit().putBoolean(FILTER_INIT_OVER_KEY, true).apply();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user