mirror of
https://github.com/topjohnwu/Magisk.git
synced 2026-01-13 05:17:37 -08:00
Merge remote-tracking branch 'refs/remotes/origin/digitalhigh_autodownload' into digitalhigh_automount
Yeeeeaaaaaaaaaahhhhhhhhhh baby!
This commit is contained in:
@@ -2,9 +2,12 @@ package com.topjohnwu.magisk;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.design.widget.TabLayout;
|
||||
@@ -12,98 +15,121 @@ import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.ipaulpro.afilechooser.FileInfo;
|
||||
import com.ipaulpro.afilechooser.utils.FileUtils;
|
||||
import com.topjohnwu.magisk.module.Module;
|
||||
import com.topjohnwu.magisk.utils.Shell;
|
||||
import com.topjohnwu.magisk.module.RepoHelper;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class ModulesFragment extends Fragment {
|
||||
|
||||
private static final int FETCH_ZIP_CODE = 2;
|
||||
public static List<Module> listModules = new ArrayList<>();
|
||||
public static List<Module> listModulesCache = new ArrayList<>();
|
||||
private static final int FILE_SELECT_CODE = 0;
|
||||
private File input;
|
||||
|
||||
@BindView(R.id.progressBar) ProgressBar progressBar;
|
||||
@BindView(R.id.fab) FloatingActionButton fabio;
|
||||
@BindView(R.id.pager) ViewPager viewPager;
|
||||
@BindView(R.id.tab_layout) TabLayout tabLayout;
|
||||
@BindView(R.id.progressBar)
|
||||
ProgressBar progressBar;
|
||||
@BindView(R.id.fab)
|
||||
FloatingActionButton fabio;
|
||||
@BindView(R.id.pager)
|
||||
ViewPager viewPager;
|
||||
@BindView(R.id.tab_layout)
|
||||
TabLayout tabLayout;
|
||||
private int viewPagePosition;
|
||||
private RepoHelper.TaskDelegate mTaskDelegate;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.modules_fragment, container, false);
|
||||
|
||||
ButterKnife.bind(this, view);
|
||||
fabio.setOnClickListener(v -> {
|
||||
Intent getContentIntent = FileUtils.createGetContentIntent(null);
|
||||
getContentIntent.setType("application/zip");
|
||||
Intent fileIntent = Intent.createChooser(getContentIntent, "Select a file");
|
||||
|
||||
startActivityForResult(fileIntent, FETCH_ZIP_CODE);
|
||||
|
||||
});
|
||||
|
||||
new Utils.LoadModules(getActivity(), false).execute();
|
||||
mTaskDelegate = result -> {
|
||||
if (result.equals("OK")) {
|
||||
RefreshUI();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
new updateUI().execute();
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (data != null) {
|
||||
// Get the URI of the selected file
|
||||
final Uri uri = data.getData();
|
||||
Log.i("Magisk", "ModulesFragment: Uri = " + uri.toString() + " or ");
|
||||
new Utils.FlashZIP(getActivity(),uri).execute();
|
||||
try {
|
||||
// Get the file path from the URI
|
||||
FileInfo fileInfo = FileUtils.getFileInfo(getActivity(), uri);
|
||||
Toast.makeText(getActivity(),
|
||||
"File Selected: " + fileInfo.getDisplayName() + " size: " + fileInfo.getSize(), Toast.LENGTH_LONG).show();
|
||||
|
||||
if (!fileInfo.isExternal()) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("FileSelectorTestAc...", "File select error", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
inflater.inflate(R.menu.menu_module, menu);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
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();
|
||||
private void RefreshUI() {
|
||||
viewPagePosition = tabLayout.getSelectedTabPosition();
|
||||
listModules.clear();
|
||||
listModulesCache.clear();
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
viewPager.setAdapter(new TabsAdapter(getChildFragmentManager()));
|
||||
tabLayout.setupWithViewPager(viewPager);
|
||||
viewPager.setCurrentItem(viewPagePosition);
|
||||
new Utils.LoadModules(getActivity(), true).execute();
|
||||
Collections.sort(listModules, new CustomComparator());
|
||||
Collections.sort(listModulesCache, new CustomComparator());
|
||||
new updateUI().execute();
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
}}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.force_reload:
|
||||
listModules.clear();
|
||||
listModulesCache.clear();
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
viewPager.setAdapter(new TabsAdapter(getChildFragmentManager()));
|
||||
tabLayout.setupWithViewPager(viewPager);
|
||||
new Utils.LoadModules(getContext()).execute();
|
||||
new updateUI().execute();
|
||||
break;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
void selectPage(int pageIndex) {
|
||||
tabLayout.setScrollPosition(pageIndex, 0f, true);
|
||||
viewPager.setCurrentItem(pageIndex);
|
||||
}
|
||||
|
||||
public static class NormalModuleFragment extends BaseModuleFragment {
|
||||
@@ -134,11 +160,11 @@ public class ModulesFragment extends Fragment {
|
||||
@Override
|
||||
protected void onPostExecute(Void v) {
|
||||
super.onPostExecute(v);
|
||||
|
||||
progressBar.setVisibility(View.GONE);
|
||||
|
||||
viewPager.setAdapter(new TabsAdapter(getChildFragmentManager()));
|
||||
tabLayout.setupWithViewPager(viewPager);
|
||||
selectPage(viewPagePosition);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,10 +191,22 @@ public class ModulesFragment extends Fragment {
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
if (position == 0) {
|
||||
return new NormalModuleFragment();
|
||||
NormalModuleFragment nmf = new NormalModuleFragment();
|
||||
nmf.SetDelegate(mTaskDelegate);
|
||||
return nmf;
|
||||
} else {
|
||||
return new CacheModuleFragment();
|
||||
CacheModuleFragment cmf = new CacheModuleFragment();
|
||||
cmf.SetDelegate(mTaskDelegate);
|
||||
return cmf;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class CustomComparator implements Comparator<Module> {
|
||||
@Override
|
||||
public int compare(Module o1, Module o2) {
|
||||
return o1.getName().compareTo(o2.getName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user