More cleanup, add native filepicker
Code cleanup, add filepicker lib to avoid issues with stock file apps.
This commit is contained in:
parent
c2a188f7fe
commit
041531e96d
@ -14,6 +14,7 @@ android {
|
||||
enabled true
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
@ -24,13 +25,18 @@ android {
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
maven {
|
||||
url "http://dl.bintray.com/lukaville/maven"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(include: ['*.jar'], dir: 'libs')
|
||||
compile 'com.android.support:recyclerview-v7:24.2.0'
|
||||
compile 'com.android.support:cardview-v7:24.2.0'
|
||||
compile 'com.android.support:design:24.2.0'
|
||||
|
||||
compile 'com.nbsp:library:1.1'
|
||||
compile 'com.jakewharton:butterknife:8.4.0'
|
||||
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import android.widget.Toast;
|
||||
|
||||
import com.topjohnwu.magisk.module.Repo;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
import com.topjohnwu.magisk.utils.WebWindow;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@ -76,6 +77,9 @@ public abstract class BaseRepoFragment extends Fragment {
|
||||
private View viewMain;
|
||||
private Context context;
|
||||
private boolean mIsInstalled, mCanUpdate;
|
||||
private Repo repo;
|
||||
private ViewHolder mHolder;
|
||||
private int mPosition;
|
||||
|
||||
public ReposAdapter(List<Repo> list) {
|
||||
this.mList = list;
|
||||
@ -96,42 +100,47 @@ public abstract class BaseRepoFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(final ViewHolder holder, int position) {
|
||||
final Repo repo = mList.get(position);
|
||||
repo = mList.get(position);
|
||||
mHolder = holder;
|
||||
SetupViewElements();
|
||||
|
||||
Log.d("Magisk", "ReposAdapter: Trying set up bindview from list pos " + position + " out of a total of " + mList.size() + " and " + repo.getId());
|
||||
if (repo.getId() != null) {
|
||||
TextView authorView = holder.author;
|
||||
holder.title.setText(repo.getName());
|
||||
holder.versionName.setText(repo.getmVersion());
|
||||
holder.description.setText(repo.getDescription());
|
||||
String authorString = getResources().getString(R.string.author) + " " + repo.getmAuthor();
|
||||
holder.author.setText(authorString);
|
||||
if ((repo.getmLogUrl() != null) && (repo.getmLogUrl().equals(""))) {
|
||||
holder.log.setText(repo.getmLogUrl());
|
||||
Linkify.addLinks(holder.log, Linkify.WEB_URLS);
|
||||
} else {
|
||||
holder.log.setVisibility(View.GONE);
|
||||
}
|
||||
holder.installedStatus.setText(repo.isInstalled() ? getResources().getString(R.string.module_installed) : getResources().getString(R.string.module_not_installed));
|
||||
if (mExpandedList.get(position)) {
|
||||
holder.expandLayout.setVisibility(View.VISIBLE);
|
||||
|
||||
private void SetupViewElements() {
|
||||
mPosition = mHolder.getAdapterPosition();
|
||||
if (repo.getId() != null) {
|
||||
TextView authorView = mHolder.author;
|
||||
mHolder.title.setText(repo.getName());
|
||||
mHolder.versionName.setText(repo.getmVersion());
|
||||
mHolder.description.setText(repo.getDescription());
|
||||
String authorString = getResources().getString(R.string.author) + " " + repo.getmAuthor();
|
||||
mHolder.author.setText(authorString);
|
||||
if ((repo.getmLogUrl() != null) && (repo.getmLogUrl().equals(""))) {
|
||||
mHolder.log.setText(repo.getmLogUrl());
|
||||
Linkify.addLinks(mHolder.log, Linkify.WEB_URLS);
|
||||
} else {
|
||||
holder.expandLayout.setVisibility(View.GONE);
|
||||
mHolder.log.setVisibility(View.GONE);
|
||||
}
|
||||
mHolder.installedStatus.setText(repo.isInstalled() ? getResources().getString(R.string.module_installed) : getResources().getString(R.string.module_not_installed));
|
||||
if (mExpandedList.get(mPosition)) {
|
||||
mHolder.expandLayout.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mHolder.expandLayout.setVisibility(View.GONE);
|
||||
}
|
||||
if (repo.isInstalled()) {
|
||||
holder.installedStatus.setTextColor(Color.parseColor("#14AD00"));
|
||||
holder.updateStatus.setText(repo.canUpdate() ? getResources().getString(R.string.module_update_available) : getResources().getString(R.string.module_up_to_date));
|
||||
mHolder.installedStatus.setTextColor(Color.parseColor("#14AD00"));
|
||||
mHolder.updateStatus.setText(repo.canUpdate() ? getResources().getString(R.string.module_update_available) : getResources().getString(R.string.module_up_to_date));
|
||||
}
|
||||
Log.d("Magisk", "ReposAdapter: Setting up info " + repo.getId() + " and " + repo.getDescription() + " and " + repo.getmVersion());
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
updateImage.setImageResource(R.drawable.ic_system_update_alt_black);
|
||||
mCanUpdate = prefs.getBoolean("repo-isInstalled_" + repo.getId(), false);
|
||||
updateImage.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
View.OnClickListener oCl = view -> {
|
||||
if (view == updateImage) {
|
||||
if (!mIsInstalled | mCanUpdate) {
|
||||
|
||||
Utils.DownloadReceiver reciever = new Utils.DownloadReceiver() {
|
||||
Utils.DownloadReceiver receiver = new Utils.DownloadReceiver() {
|
||||
@Override
|
||||
public void task(File file) {
|
||||
Log.d("Magisk", "Task firing");
|
||||
@ -139,12 +148,17 @@ public abstract class BaseRepoFragment extends Fragment {
|
||||
}
|
||||
};
|
||||
String filename = repo.getId().replace(" ", "") + ".zip";
|
||||
Utils.downloadAndReceive(context, reciever, repo.getmZipUrl(), filename);
|
||||
Utils.downloadAndReceive(context, receiver, repo.getmZipUrl(), filename);
|
||||
} else {
|
||||
Toast.makeText(context, repo.getId() + " is already installed.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else if (view == mHolder.log) {
|
||||
new WebWindow("Changelog",repo.getmLogUrl(),getActivity());
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
updateImage.setOnClickListener(oCl);
|
||||
mHolder.log.setOnClickListener(oCl);
|
||||
if (prefs.contains("repo-isInstalled_" + repo.getId())) {
|
||||
mIsInstalled = prefs.getBoolean("repo-isInstalled_" + repo.getId(), false);
|
||||
// if (mIsInstalled) {
|
||||
@ -155,11 +169,8 @@ public abstract class BaseRepoFragment extends Fragment {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mList.size();
|
||||
|
@ -25,17 +25,13 @@ import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.topjohnwu.magisk.utils.Shell;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
@ -14,7 +14,6 @@ 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.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
@ -23,14 +22,17 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.nbsp.materialfilepicker.MaterialFilePicker;
|
||||
import com.nbsp.materialfilepicker.ui.FilePickerActivity;
|
||||
import com.topjohnwu.magisk.module.Module;
|
||||
import com.topjohnwu.magisk.module.Repo;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
@ -42,11 +44,16 @@ public class ModulesFragment extends Fragment {
|
||||
public static List<Repo> listModulesDownload = new ArrayList<>();
|
||||
private static final int FILE_SELECT_CODE = 0;
|
||||
private int viewPagePosition;
|
||||
private static final int RESULT_OK = 1;
|
||||
|
||||
@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;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@ -54,46 +61,56 @@ public class ModulesFragment extends Fragment {
|
||||
View view = inflater.inflate(R.layout.modules_fragment, container, false);
|
||||
|
||||
ButterKnife.bind(this, view);
|
||||
new Utils.LoadModules(getActivity(),false).execute();
|
||||
new Utils.LoadModules(getActivity(), false).execute();
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
new updateUI().execute();
|
||||
setHasOptionsMenu(true);
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
|
||||
fabio.setOnClickListener(view -> {
|
||||
openFilePicker();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void openFilePicker() {
|
||||
new MaterialFilePicker()
|
||||
.withSupportFragment(this)
|
||||
.withFilter(Pattern.compile(".*\\.zip$"))
|
||||
.withRequestCode(FILE_SELECT_CODE)
|
||||
.withHiddenFiles(true)
|
||||
.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
switch (requestCode) {
|
||||
case FILE_SELECT_CODE:
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
Log.d("Magisk","WelcomeActivity: Got an OK result" + resultCode);
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
String path = data.getStringExtra(FilePickerActivity.RESULT_FILE_PATH);
|
||||
Log.d("Magisk","ModuleFragment: Got an OK result " + path);
|
||||
if (path != null) {
|
||||
Log.d("Path: ", path);
|
||||
Toast.makeText(getActivity(), "Picked file: " + path, Toast.LENGTH_LONG).show();
|
||||
// Get the Uri of the selected file
|
||||
Uri uri = data.getData();
|
||||
String path = uri.getPath();
|
||||
String filePath = data.getStringExtra(FilePickerActivity.RESULT_FILE_PATH);
|
||||
|
||||
Uri uri = Uri.parse(filePath);
|
||||
|
||||
path = uri.getPath();
|
||||
Log.d("Magisk","ModuleFragment: Got an OK result " + filePath + " and " + uri.toString() + " and " + path);
|
||||
|
||||
String fileName = uri.getLastPathSegment();
|
||||
new Utils.FlashZIP(getActivity(), fileName, path).execute();
|
||||
|
||||
}
|
||||
break;
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
@ -107,7 +124,7 @@ public class ModulesFragment extends Fragment {
|
||||
viewPager.setAdapter(new TabsAdapter(getChildFragmentManager()));
|
||||
tabLayout.setupWithViewPager(viewPager);
|
||||
viewPager.setCurrentItem(viewPagePosition);
|
||||
new Utils.LoadModules(getActivity(),true).execute();
|
||||
new Utils.LoadModules(getActivity(), true).execute();
|
||||
new updateUI().execute();
|
||||
break;
|
||||
}
|
||||
@ -115,8 +132,8 @@ public class ModulesFragment extends Fragment {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
void selectPage(int pageIndex){
|
||||
tabLayout.setScrollPosition(pageIndex,0f,true);
|
||||
void selectPage(int pageIndex) {
|
||||
tabLayout.setScrollPosition(pageIndex, 0f, true);
|
||||
viewPager.setCurrentItem(pageIndex);
|
||||
}
|
||||
|
||||
@ -137,6 +154,7 @@ public class ModulesFragment extends Fragment {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class DownloadModuleFragment extends BaseRepoFragment {
|
||||
|
||||
@Override
|
||||
@ -146,7 +164,6 @@ public class ModulesFragment extends Fragment {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private class updateUI extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
@Override
|
||||
@ -169,7 +186,7 @@ public class ModulesFragment extends Fragment {
|
||||
private class TabsAdapter extends FragmentPagerAdapter {
|
||||
|
||||
String[] tabTitles = new String[]{
|
||||
getString(R.string.modules), getString(R.string.cache_modules) ,"Download"
|
||||
getString(R.string.modules), getString(R.string.cache_modules), "Download"
|
||||
};
|
||||
|
||||
public TabsAdapter(FragmentManager fm) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.topjohnwu.magisk;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
|
@ -7,8 +7,6 @@ import android.util.Log;
|
||||
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class Module {
|
||||
|
||||
private String mRemoveFile;
|
||||
@ -203,6 +201,6 @@ public class Module {
|
||||
|
||||
public boolean isOnline() {return mIsOnline; }
|
||||
|
||||
public boolean isUpdateAvailable() { return mUpdateAvailable; };
|
||||
public boolean isUpdateAvailable() { return mUpdateAvailable; }
|
||||
|
||||
}
|
@ -102,7 +102,7 @@ public class Repo {
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putString("repo_" + mId, manifestString);
|
||||
editor.putBoolean("hasCachedRepos", true);
|
||||
editor.putString("updated_" + mId, this.lastUpdate.toString());
|
||||
editor.putString("updated_" + mId, this.lastUpdate);
|
||||
Log.d("Magisk", "Storing Preferences: " + manifestString);
|
||||
editor.apply();
|
||||
}
|
||||
|
@ -1,8 +1,5 @@
|
||||
package com.topjohnwu.magisk.utils;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.topjohnwu.magisk.utils;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
@ -8,14 +8,11 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Environment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
@ -30,7 +27,6 @@ import com.topjohnwu.magisk.module.Module;
|
||||
import com.topjohnwu.magisk.module.RepoHelper;
|
||||
import com.topjohnwu.magisk.module.Repo;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
33
app/src/main/java/com/topjohnwu/magisk/utils/WebWindow.java
Normal file
33
app/src/main/java/com/topjohnwu/magisk/utils/WebWindow.java
Normal file
@ -0,0 +1,33 @@
|
||||
package com.topjohnwu.magisk.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.webkit.WebResourceRequest;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
|
||||
|
||||
public class WebWindow {
|
||||
|
||||
public WebWindow(String title, String url, Context context) {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(context);
|
||||
alert.setTitle(title);
|
||||
|
||||
WebView wv = new WebView(context);
|
||||
wv.loadUrl(url);
|
||||
wv.setWebViewClient(new WebViewClient() {
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
||||
view.loadUrl(url);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
alert.setView(wv);
|
||||
alert.setNegativeButton("Close", (dialog, id) -> {
|
||||
dialog.dismiss();
|
||||
});
|
||||
alert.show();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user