2016-08-22 21:18:28 +00:00
|
|
|
package com.topjohnwu.magisk;
|
2016-08-17 11:00:55 +00:00
|
|
|
|
2016-08-31 21:49:35 +00:00
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Intent;
|
2016-09-02 18:18:37 +00:00
|
|
|
import android.content.SharedPreferences;
|
2016-08-31 21:49:35 +00:00
|
|
|
import android.net.Uri;
|
2016-08-17 11:00:55 +00:00
|
|
|
import android.os.AsyncTask;
|
|
|
|
import android.os.Bundle;
|
2016-09-02 18:18:37 +00:00
|
|
|
import android.preference.PreferenceManager;
|
2016-08-21 13:29:42 +00:00
|
|
|
import android.support.annotation.Nullable;
|
2016-08-31 21:49:35 +00:00
|
|
|
import android.support.design.widget.FloatingActionButton;
|
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-09-06 21:54:08 +00:00
|
|
|
import android.support.v4.widget.SwipeRefreshLayout;
|
2016-09-01 21:58:26 +00:00
|
|
|
import android.util.Log;
|
2016-08-21 13:29:42 +00:00
|
|
|
import android.view.LayoutInflater;
|
2016-08-27 19:52:03 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
2016-08-25 10:40:00 +00:00
|
|
|
import android.view.MenuItem;
|
2016-08-21 13:29:42 +00:00
|
|
|
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
|
|
|
|
2016-08-22 21:18:28 +00:00
|
|
|
import com.topjohnwu.magisk.module.Module;
|
2016-09-02 13:32:34 +00:00
|
|
|
import com.topjohnwu.magisk.module.Repo;
|
2016-08-24 21:58:15 +00:00
|
|
|
import com.topjohnwu.magisk.utils.Utils;
|
2016-08-17 11:00:55 +00:00
|
|
|
|
2016-08-31 21:49:35 +00:00
|
|
|
import java.io.File;
|
2016-08-25 10:40:00 +00:00
|
|
|
import java.util.ArrayList;
|
2016-08-17 11:00:55 +00:00
|
|
|
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
|
|
|
|
2016-08-28 22:35:07 +00:00
|
|
|
public static List<Module> listModules = new ArrayList<>();
|
|
|
|
public static List<Module> listModulesCache = new ArrayList<>();
|
2016-09-02 13:32:34 +00:00
|
|
|
public static List<Repo> listModulesDownload = new ArrayList<>();
|
2016-08-31 21:49:35 +00:00
|
|
|
private static final int FILE_SELECT_CODE = 0;
|
2016-09-06 21:54:08 +00:00
|
|
|
private TabsAdapter ta;
|
2016-08-31 21:49:35 +00:00
|
|
|
private File input;
|
2016-09-06 21:54:08 +00:00
|
|
|
private SwipeRefreshLayout mSwipeRefreshLayout;
|
2016-08-17 11:00:55 +00:00
|
|
|
|
2016-08-21 14:42:50 +00:00
|
|
|
@BindView(R.id.progressBar) ProgressBar progressBar;
|
2016-08-31 21:49:35 +00:00
|
|
|
@BindView(R.id.fab) FloatingActionButton fabio;
|
2016-08-21 14:42:50 +00:00
|
|
|
@BindView(R.id.pager) ViewPager viewPager;
|
|
|
|
@BindView(R.id.tab_layout) TabLayout tabLayout;
|
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);
|
2016-09-06 21:54:08 +00:00
|
|
|
|
2016-08-21 14:08:45 +00:00
|
|
|
ButterKnife.bind(this, view);
|
2016-09-02 18:18:37 +00:00
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
|
|
|
if (prefs.contains("hasCachedRepos")) {
|
|
|
|
new Utils.LoadModules(getActivity(), false).execute();
|
|
|
|
} else {
|
|
|
|
new Utils.LoadModules(getActivity(), true).execute();
|
|
|
|
}
|
2016-09-06 21:54:08 +00:00
|
|
|
|
2016-08-25 10:08:07 +00:00
|
|
|
new updateUI().execute();
|
2016-08-23 16:28:27 +00:00
|
|
|
setHasOptionsMenu(true);
|
2016-08-21 14:08:45 +00:00
|
|
|
return view;
|
2016-08-17 11:00:55 +00:00
|
|
|
}
|
|
|
|
|
2016-09-06 21:54:08 +00:00
|
|
|
public void updateThisShit() {
|
|
|
|
new Utils.LoadModules(getActivity(), true).execute();
|
|
|
|
new updateUI().execute();
|
|
|
|
setHasOptionsMenu(true);
|
|
|
|
}
|
|
|
|
|
2016-08-27 19:52:03 +00:00
|
|
|
@Override
|
|
|
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
|
super.onCreateOptionsMenu(menu, inflater);
|
|
|
|
inflater.inflate(R.menu.menu_module, menu);
|
2016-08-31 21:49:35 +00:00
|
|
|
fabio.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
|
|
|
Intent intent = new Intent();
|
|
|
|
intent.setType("*/zip");
|
|
|
|
intent.setAction(Intent.ACTION_GET_CONTENT);
|
|
|
|
startActivityForResult(intent,FILE_SELECT_CODE);
|
|
|
|
}
|
2016-09-01 15:42:26 +00:00
|
|
|
|
|
|
|
|
2016-08-31 21:49:35 +00:00
|
|
|
});
|
2016-09-01 21:58:26 +00:00
|
|
|
|
2016-08-27 19:52:03 +00:00
|
|
|
}
|
|
|
|
|
2016-09-06 21:54:08 +00:00
|
|
|
|
|
|
|
|
2016-08-31 21:49:35 +00:00
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
switch (requestCode) {
|
|
|
|
case FILE_SELECT_CODE:
|
|
|
|
if (resultCode == Activity.RESULT_OK) {
|
|
|
|
// Get the Uri of the selected file
|
|
|
|
Uri uri = data.getData();
|
|
|
|
String path = uri.getPath();
|
|
|
|
String fileName = uri.getLastPathSegment();
|
|
|
|
new Utils.FlashZIP(getActivity(), fileName, path).execute();
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}}
|
|
|
|
|
2016-08-23 16:28:27 +00:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.force_reload:
|
2016-08-27 19:52:03 +00:00
|
|
|
listModules.clear();
|
|
|
|
listModulesCache.clear();
|
2016-09-01 21:58:26 +00:00
|
|
|
listModulesDownload.clear();
|
2016-08-27 19:52:03 +00:00
|
|
|
progressBar.setVisibility(View.VISIBLE);
|
2016-09-06 21:54:08 +00:00
|
|
|
ta = new TabsAdapter(getChildFragmentManager());
|
|
|
|
viewPager.setAdapter(ta);
|
2016-08-27 19:52:03 +00:00
|
|
|
tabLayout.setupWithViewPager(viewPager);
|
2016-09-06 21:54:08 +00:00
|
|
|
new Utils.LoadModules(getActivity(),true).execute();
|
2016-08-25 10:08:07 +00:00
|
|
|
new updateUI().execute();
|
2016-08-23 16:28:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
2016-09-06 21:54:08 +00:00
|
|
|
public void redrawLayout() {
|
|
|
|
listModules.clear();
|
|
|
|
listModulesCache.clear();
|
|
|
|
listModulesDownload.clear();
|
|
|
|
progressBar.setVisibility(View.VISIBLE);
|
|
|
|
ta = new TabsAdapter(getChildFragmentManager());
|
|
|
|
viewPager.setAdapter(ta);
|
|
|
|
tabLayout.setupWithViewPager(viewPager);
|
|
|
|
new Utils.LoadModules(getActivity(),false).execute();
|
|
|
|
new updateUI().execute();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-22 21:18:28 +00:00
|
|
|
public static class NormalModuleFragment extends BaseModuleFragment {
|
2016-08-21 14:42:50 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<Module> listModules() {
|
2016-08-25 10:08:07 +00:00
|
|
|
return listModules;
|
2016-08-21 14:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class CacheModuleFragment extends BaseModuleFragment {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<Module> listModules() {
|
2016-08-25 10:08:07 +00:00
|
|
|
return listModulesCache;
|
2016-08-21 14:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2016-09-02 13:32:34 +00:00
|
|
|
public static class DownloadModuleFragment extends BaseRepoFragment {
|
2016-09-01 21:58:26 +00:00
|
|
|
|
|
|
|
@Override
|
2016-09-02 13:32:34 +00:00
|
|
|
protected List<Repo> listRepos() {
|
2016-09-01 21:58:26 +00:00
|
|
|
return listModulesDownload;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-21 14:42:50 +00:00
|
|
|
|
2016-09-06 21:54:08 +00:00
|
|
|
public class updateUI extends AsyncTask<Void, Void, Void> {
|
2016-08-17 11:00:55 +00:00
|
|
|
|
|
|
|
@Override
|
2016-08-22 21:18:28 +00:00
|
|
|
protected Void doInBackground(Void... voids) {
|
|
|
|
return null;
|
2016-08-17 11:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-08-22 21:18:28 +00:00
|
|
|
protected void onPostExecute(Void v) {
|
|
|
|
super.onPostExecute(v);
|
2016-08-17 11:00:55 +00:00
|
|
|
|
2016-08-21 14:08:45 +00:00
|
|
|
progressBar.setVisibility(View.GONE);
|
2016-09-06 21:54:08 +00:00
|
|
|
ta = new TabsAdapter(getChildFragmentManager());
|
|
|
|
viewPager.setAdapter(ta);
|
2016-08-23 16:28:27 +00:00
|
|
|
tabLayout.setupWithViewPager(viewPager);
|
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[]{
|
2016-09-01 21:58:26 +00:00
|
|
|
getString(R.string.modules), getString(R.string.cache_modules) ,"Download"
|
2016-08-21 14:42:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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) {
|
2016-08-22 21:18:28 +00:00
|
|
|
return new NormalModuleFragment();
|
2016-09-01 21:58:26 +00:00
|
|
|
} else if (position == 1) {
|
2016-08-21 14:42:50 +00:00
|
|
|
return new CacheModuleFragment();
|
2016-09-01 21:58:26 +00:00
|
|
|
} else {
|
|
|
|
return new DownloadModuleFragment();
|
2016-08-21 14:42:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-01 21:58:26 +00:00
|
|
|
|
2016-08-17 11:00:55 +00:00
|
|
|
}
|