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

139 lines
4.4 KiB
Java
Raw Normal View History

2016-08-17 11:00:55 +00:00
package com.topjohnwu.magisk;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
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
}
}
private class ModulesAdapter extends ArrayAdapter<Module> {
public ModulesAdapter(Context context, int resource, List<Module> modules) {
super(context, resource, modules);
2016-08-17 11:00:55 +00:00
}
@SuppressLint("SetTextI18n")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder vh;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.row, null);
vh = new ViewHolder();
vh.name = (TextView) convertView.findViewById(R.id.name);
vh.version = (TextView) convertView.findViewById(R.id.version);
vh.versionCode = (TextView) convertView.findViewById(R.id.versionCode);
vh.description = (TextView) convertView.findViewById(R.id.description);
vh.cache = (TextView) convertView.findViewById(R.id.cache);
convertView.setTag(vh);
} else {
vh = (ViewHolder) convertView.getTag();
}
Module module = getItem(position);
vh.name.setText("name= " + module.getName());
vh.version.setText("version= " + module.getVersion());
vh.versionCode.setText("versioncode= " + module.getVersionCode());
vh.description.setText("description= " + module.getDescription());
vh.cache.setText("is from cache= " + module.isCache());
return convertView;
}
private class ViewHolder {
public TextView name;
public TextView version;
public TextView versionCode;
public TextView description;
public TextView cache;
}
}
}