2016-08-20 15:26:49 +00:00
|
|
|
package com.topjohnwu.magisk.ui;
|
2016-08-17 11:00:55 +00:00
|
|
|
|
|
|
|
import android.os.AsyncTask;
|
|
|
|
import android.os.Bundle;
|
2016-08-21 13:29:42 +00:00
|
|
|
import android.support.annotation.Nullable;
|
2016-08-21 14:42:50 +00:00
|
|
|
import android.support.design.widget.TabLayout;
|
|
|
|
import android.support.v4.app.Fragment;
|
|
|
|
import android.support.v4.app.FragmentManager;
|
|
|
|
import android.support.v4.app.FragmentPagerAdapter;
|
|
|
|
import android.support.v4.view.ViewPager;
|
2016-08-21 13:29:42 +00:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2016-08-21 14:08:45 +00:00
|
|
|
import android.widget.ProgressBar;
|
2016-08-20 15:26:49 +00:00
|
|
|
|
|
|
|
import com.topjohnwu.magisk.R;
|
|
|
|
import com.topjohnwu.magisk.model.Module;
|
2016-08-21 13:29:42 +00:00
|
|
|
import com.topjohnwu.magisk.ui.utils.Utils;
|
2016-08-17 11:00:55 +00:00
|
|
|
|
|
|
|
import java.io.File;
|
2016-08-21 13:29:42 +00:00
|
|
|
import java.io.FileFilter;
|
2016-08-17 11:00:55 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2016-08-21 13:29:42 +00:00
|
|
|
import butterknife.BindView;
|
|
|
|
import butterknife.ButterKnife;
|
|
|
|
|
2016-08-21 15:21:37 +00:00
|
|
|
public class ModulesFragment extends Fragment {
|
2016-08-17 11:00:55 +00:00
|
|
|
|
|
|
|
private static final String MAGISK_PATH = "/magisk";
|
|
|
|
private static final String MAGISK_CACHE_PATH = "/cache/magisk";
|
|
|
|
|
2016-08-21 14:42:50 +00:00
|
|
|
private static List<Module> listModulesNoCache = new ArrayList<>();
|
|
|
|
private static List<Module> listModulesCache = new ArrayList<>();
|
2016-08-17 11:00:55 +00:00
|
|
|
|
2016-08-21 14:42:50 +00:00
|
|
|
@BindView(R.id.progressBar) ProgressBar progressBar;
|
|
|
|
@BindView(R.id.pager) ViewPager viewPager;
|
|
|
|
@BindView(R.id.tab_layout) TabLayout tabLayout;
|
2016-08-21 14:08:45 +00:00
|
|
|
|
2016-08-21 14:42:50 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2016-08-21 14:08:45 +00:00
|
|
|
|
2016-08-21 14:42:50 +00:00
|
|
|
listModulesCache.clear();
|
|
|
|
listModulesNoCache.clear();
|
|
|
|
}
|
2016-08-21 14:08:45 +00:00
|
|
|
|
2016-08-21 13:29:42 +00:00
|
|
|
@Nullable
|
2016-08-17 11:00:55 +00:00
|
|
|
@Override
|
2016-08-21 13:29:42 +00:00
|
|
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
2016-08-21 14:08:45 +00:00
|
|
|
View view = inflater.inflate(R.layout.modules_fragment, container, false);
|
|
|
|
ButterKnife.bind(this, view);
|
2016-08-17 11:00:55 +00:00
|
|
|
|
2016-08-21 14:42:50 +00:00
|
|
|
viewPager.setAdapter(new TabsAdapter(getChildFragmentManager()));
|
|
|
|
tabLayout.setupWithViewPager(viewPager);
|
|
|
|
|
2016-08-17 11:00:55 +00:00
|
|
|
new CheckFolders().execute();
|
2016-08-21 13:29:42 +00:00
|
|
|
|
2016-08-21 14:08:45 +00:00
|
|
|
return view;
|
2016-08-17 11:00:55 +00:00
|
|
|
}
|
|
|
|
|
2016-08-21 14:42:50 +00:00
|
|
|
public static class NoCacheModuleFragment extends BaseModuleFragment {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<Module> listModules() {
|
|
|
|
return listModulesNoCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class CacheModuleFragment extends BaseModuleFragment {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<Module> listModules() {
|
|
|
|
return listModulesCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-17 11:00:55 +00:00
|
|
|
private class CheckFolders extends AsyncTask<Void, Integer, Boolean> {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Boolean doInBackground(Void... voids) {
|
2016-08-21 13:29:42 +00:00
|
|
|
File[] magisk = new File(MAGISK_PATH).listFiles(new FileFilter() {
|
|
|
|
@Override
|
|
|
|
public boolean accept(File file) {
|
|
|
|
return file.isDirectory();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-08-22 17:44:34 +00:00
|
|
|
Utils.su("chmod 755 /cache");
|
2016-08-21 13:29:42 +00:00
|
|
|
|
|
|
|
File[] magiskCache = new File(MAGISK_CACHE_PATH).listFiles(new FileFilter() {
|
|
|
|
@Override
|
|
|
|
public boolean accept(File file) {
|
|
|
|
return file.isDirectory();
|
|
|
|
}
|
|
|
|
});
|
2016-08-17 11:00:55 +00:00
|
|
|
|
|
|
|
if (magisk != null) {
|
|
|
|
for (File mod : magisk) {
|
2016-08-18 09:27:26 +00:00
|
|
|
Module m = new Module(mod);
|
|
|
|
if (m.isValid()) {
|
2016-08-21 14:42:50 +00:00
|
|
|
try {
|
|
|
|
m.parse();
|
|
|
|
listModulesNoCache.add(m);
|
|
|
|
} catch (Exception ignored) {
|
|
|
|
}
|
2016-08-18 09:27:26 +00:00
|
|
|
}
|
2016-08-17 11:00:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (magiskCache != null) {
|
|
|
|
for (File mod : magiskCache) {
|
2016-08-18 09:27:26 +00:00
|
|
|
Module m = new Module(mod);
|
|
|
|
if (m.isValid()) {
|
2016-08-21 14:42:50 +00:00
|
|
|
try {
|
|
|
|
m.parse();
|
|
|
|
listModulesCache.add(m);
|
|
|
|
} catch (Exception ignored) {
|
|
|
|
}
|
2016-08-18 09:27:26 +00:00
|
|
|
}
|
2016-08-17 11:00:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-08-18 09:27:26 +00:00
|
|
|
protected void onPostExecute(Boolean result) {
|
|
|
|
super.onPostExecute(result);
|
2016-08-17 11:00:55 +00:00
|
|
|
|
2016-08-21 14:08:45 +00:00
|
|
|
progressBar.setVisibility(View.GONE);
|
2016-08-17 11:00:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-21 14:42:50 +00:00
|
|
|
private class TabsAdapter extends FragmentPagerAdapter {
|
|
|
|
|
|
|
|
String[] tabTitles = new String[]{
|
|
|
|
"_no_cache", "_cache"
|
|
|
|
// TODO stringify
|
|
|
|
};
|
|
|
|
|
|
|
|
public TabsAdapter(FragmentManager fm) {
|
|
|
|
super(fm);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCount() {
|
|
|
|
return tabTitles.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getPageTitle(int position) {
|
|
|
|
return tabTitles[position];
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Fragment getItem(int position) {
|
|
|
|
if (position == 0) {
|
|
|
|
return new NoCacheModuleFragment();
|
|
|
|
} else {
|
|
|
|
return new CacheModuleFragment();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-17 11:00:55 +00:00
|
|
|
}
|