Magisk/app/src/main/java/com/topjohnwu/magisk/ui/ModulesActivity.java

91 lines
2.5 KiB
Java
Raw Normal View History

2016-08-20 15:26:49 +00:00
package com.topjohnwu.magisk.ui;
2016-08-17 11:00:55 +00:00
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ListView;
2016-08-20 15:26:49 +00:00
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.model.Module;
import com.topjohnwu.magisk.rv.ModulesAdapter;
2016-08-17 11:00:55 +00:00
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class ModulesActivity extends Activity {
private static final String MAGISK_PATH = "/magisk";
private static final String MAGISK_CACHE_PATH = "/cache/magisk";
private List<Module> listModules = new ArrayList<>();
private ListView mListView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_modules);
mListView = (ListView) findViewById(android.R.id.list);
new CheckFolders().execute();
}
private class CheckFolders extends AsyncTask<Void, Integer, Boolean> {
private ProgressDialog progress;
@Override
protected void onPreExecute() {
super.onPreExecute();
progress = ProgressDialog.show(ModulesActivity.this, null, getString(R.string.loading), true, false);
}
@Override
protected Boolean doInBackground(Void... voids) {
File[] magisk = new File(MAGISK_PATH).listFiles(File::isDirectory);
File[] magiskCache = new File(MAGISK_CACHE_PATH).listFiles(File::isDirectory);
if (magisk != null) {
for (File mod : magisk) {
Module m = new Module(mod);
if (m.isValid()) {
listModules.add(m);
}
2016-08-17 11:00:55 +00:00
}
}
if (magiskCache != null) {
for (File mod : magiskCache) {
Module m = new Module(mod);
if (m.isValid()) {
listModules.add(m);
}
2016-08-17 11:00:55 +00:00
}
}
//noinspection Convert2streamapi
for (Module module : listModules) {
try {
2016-08-17 11:00:55 +00:00
module.parse();
} catch (Exception ignored) {
}
}
return true;
}
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
2016-08-17 11:00:55 +00:00
progress.dismiss();
mListView.setAdapter(new ModulesAdapter(ModulesActivity.this, R.layout.row, listModules));
2016-08-17 11:00:55 +00:00
}
}
}