Work on file picker - WIP
This commit is contained in:
parent
46abbfe224
commit
6a90340b14
@ -26,9 +26,7 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
repositories {
|
repositories {
|
||||||
maven {
|
|
||||||
url "http://dl.bintray.com/lukaville/maven"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@ -36,7 +34,7 @@ dependencies {
|
|||||||
compile 'com.android.support:recyclerview-v7:24.2.0'
|
compile 'com.android.support:recyclerview-v7:24.2.0'
|
||||||
compile 'com.android.support:cardview-v7:24.2.0'
|
compile 'com.android.support:cardview-v7:24.2.0'
|
||||||
compile 'com.android.support:design:24.2.0'
|
compile 'com.android.support:design:24.2.0'
|
||||||
compile 'com.nbsp:library:1.1'
|
|
||||||
compile 'com.jakewharton:butterknife:8.4.0'
|
compile 'com.jakewharton:butterknife:8.4.0'
|
||||||
|
compile 'com.github.angads25:filepicker:1.0.6'
|
||||||
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
|
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
|
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
|
||||||
<activity
|
<activity
|
||||||
android:name=".WelcomeActivity"
|
android:name=".WelcomeActivity"
|
||||||
|
android:exported="true"
|
||||||
android:configChanges="orientation|screenSize">
|
android:configChanges="orientation|screenSize">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
@ -23,9 +24,11 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".AboutActivity"
|
android:name=".AboutActivity"
|
||||||
android:theme="@style/AppTheme.Transparent"/>
|
android:theme="@style/AppTheme.Transparent"/>
|
||||||
|
|
||||||
<provider
|
<provider
|
||||||
android:name="android.support.v4.content.FileProvider"
|
android:name="android.support.v4.content.FileProvider"
|
||||||
android:authorities="com.topjohnwu.magisk.provider"
|
android:authorities="com.topjohnwu.magisk.provider"
|
||||||
@ -35,6 +38,7 @@
|
|||||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
android:resource="@xml/file_paths" />
|
android:resource="@xml/file_paths" />
|
||||||
</provider>
|
</provider>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
@ -167,9 +167,6 @@ public abstract class BaseModuleFragment extends Fragment {
|
|||||||
String logUrl = module.getmLogUrl();
|
String logUrl = module.getmLogUrl();
|
||||||
String supportUrl = module.getmSupportUrl();
|
String supportUrl = module.getmSupportUrl();
|
||||||
String donateUrl = module.getmDonateUrl();
|
String donateUrl = module.getmDonateUrl();
|
||||||
if (supportUrl != null && !supportUrl.isEmpty()) holder.supportLink.setBackgroundColor(Color.GRAY);
|
|
||||||
if (logUrl != null && !logUrl.isEmpty()) holder.changeLog.setBackgroundColor(Color.GRAY);
|
|
||||||
if (donateUrl != null && !donateUrl.isEmpty()) holder.authorLink.setBackgroundColor(Color.GRAY);
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
if (prefs.contains("ignoreUpdateAlerts")) {
|
if (prefs.contains("ignoreUpdateAlerts")) {
|
||||||
ignoreAlertUpdate = prefs.getBoolean("ignoreUpdateAlerts", false);
|
ignoreAlertUpdate = prefs.getBoolean("ignoreUpdateAlerts", false);
|
||||||
|
@ -2,40 +2,46 @@ package com.topjohnwu.magisk;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.os.Environment;
|
||||||
|
import android.provider.DocumentsContract;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.design.widget.TabLayout;
|
import android.support.design.widget.TabLayout;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.support.v4.app.FragmentPagerAdapter;
|
import android.support.v4.app.FragmentPagerAdapter;
|
||||||
|
import android.support.v4.provider.DocumentFile;
|
||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.nbsp.materialfilepicker.MaterialFilePicker;
|
|
||||||
import com.nbsp.materialfilepicker.ui.FilePickerActivity;
|
import com.github.angads25.filepicker.controller.DialogSelectionListener;
|
||||||
|
import com.github.angads25.filepicker.model.DialogConfigs;
|
||||||
|
import com.github.angads25.filepicker.model.DialogProperties;
|
||||||
|
import com.github.angads25.filepicker.view.FilePickerDialog;
|
||||||
import com.topjohnwu.magisk.module.Module;
|
import com.topjohnwu.magisk.module.Module;
|
||||||
import com.topjohnwu.magisk.module.Repo;
|
|
||||||
import com.topjohnwu.magisk.module.RepoHelper;
|
import com.topjohnwu.magisk.module.RepoHelper;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
import com.topjohnwu.magisk.utils.lib;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
@ -44,9 +50,7 @@ public class ModulesFragment extends Fragment {
|
|||||||
|
|
||||||
public static List<Module> listModules = new ArrayList<>();
|
public static List<Module> listModules = new ArrayList<>();
|
||||||
public static List<Module> listModulesCache = new ArrayList<>();
|
public static List<Module> listModulesCache = new ArrayList<>();
|
||||||
private static final int FILE_SELECT_CODE = 0;
|
|
||||||
private int viewPagePosition;
|
private int viewPagePosition;
|
||||||
private static final int RESULT_OK = 1;
|
|
||||||
|
|
||||||
@BindView(R.id.progressBar)
|
@BindView(R.id.progressBar)
|
||||||
ProgressBar progressBar;
|
ProgressBar progressBar;
|
||||||
@ -57,6 +61,7 @@ public class ModulesFragment extends Fragment {
|
|||||||
@BindView(R.id.tab_layout)
|
@BindView(R.id.tab_layout)
|
||||||
TabLayout tabLayout;
|
TabLayout tabLayout;
|
||||||
private RepoHelper.TaskDelegate mTaskDelegate;
|
private RepoHelper.TaskDelegate mTaskDelegate;
|
||||||
|
private static final int RQS_OPEN_DOCUMENT_TREE = 2;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
@ -64,61 +69,67 @@ public class ModulesFragment extends Fragment {
|
|||||||
View view = inflater.inflate(R.layout.modules_fragment, container, false);
|
View view = inflater.inflate(R.layout.modules_fragment, container, false);
|
||||||
|
|
||||||
ButterKnife.bind(this, view);
|
ButterKnife.bind(this, view);
|
||||||
|
String[] extensions = new String[1];
|
||||||
|
extensions[0] = "zip";
|
||||||
|
fabio.setOnClickListener(v -> {
|
||||||
|
Intent fileintent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||||
|
fileintent.setType("application/zip");
|
||||||
|
startActivityForResult(fileintent, RQS_OPEN_DOCUMENT_TREE);
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
new Utils.LoadModules(getActivity(), false).execute();
|
new Utils.LoadModules(getActivity(), false).execute();
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
|
||||||
mTaskDelegate = result -> {
|
mTaskDelegate = result -> {
|
||||||
if (result.equals("OK")) {
|
if (result.equals("OK")) {
|
||||||
Log.d("Magisk","ModulesFragment: We dun got the result, hur hur.");
|
Log.d("Magisk", "ModulesFragment: We dun got the result, hur hur.");
|
||||||
RefreshUI();
|
RefreshUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
new updateUI().execute();
|
new updateUI().execute();
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean isExternalStorageDocument(Uri uri) {
|
||||||
|
return "com.android.externalstorage.documents".equals(uri.getAuthority());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
String file = "";
|
||||||
|
if(resultCode == Activity.RESULT_OK && requestCode == RQS_OPEN_DOCUMENT_TREE){
|
||||||
|
if (isExternalStorageDocument(data.getData())) {
|
||||||
|
final String docId = DocumentsContract.getDocumentId(data.getData());
|
||||||
|
final String[] split = docId.split(":");
|
||||||
|
final String type = split[0];
|
||||||
|
|
||||||
|
if ("primary".equalsIgnoreCase(type)) {
|
||||||
|
file = Environment.getExternalStorageDirectory() + "/" + split[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO handle non-primary volumes
|
||||||
|
}
|
||||||
|
String shit = data.getDataString();
|
||||||
|
|
||||||
|
Log.d("Magisk","ModulesFragment: Got a result, " + shit + " and " + data.getData().getAuthority() + " and " + file);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
super.onCreateOptionsMenu(menu, inflater);
|
super.onCreateOptionsMenu(menu, inflater);
|
||||||
inflater.inflate(R.menu.menu_module, menu);
|
inflater.inflate(R.menu.menu_module, menu);
|
||||||
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) {
|
|
||||||
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
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RefreshUI() {
|
private void RefreshUI() {
|
||||||
viewPagePosition = tabLayout.getSelectedTabPosition();
|
viewPagePosition = tabLayout.getSelectedTabPosition();
|
||||||
@ -129,8 +140,8 @@ public class ModulesFragment extends Fragment {
|
|||||||
tabLayout.setupWithViewPager(viewPager);
|
tabLayout.setupWithViewPager(viewPager);
|
||||||
viewPager.setCurrentItem(viewPagePosition);
|
viewPager.setCurrentItem(viewPagePosition);
|
||||||
new Utils.LoadModules(getActivity(), true).execute();
|
new Utils.LoadModules(getActivity(), true).execute();
|
||||||
Collections.sort(listModules,new CustomComparator());
|
Collections.sort(listModules, new CustomComparator());
|
||||||
Collections.sort(listModulesCache,new CustomComparator());
|
Collections.sort(listModulesCache, new CustomComparator());
|
||||||
new updateUI().execute();
|
new updateUI().execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,6 +221,7 @@ public class ModulesFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CustomComparator implements Comparator<Module> {
|
public class CustomComparator implements Comparator<Module> {
|
||||||
@Override
|
@Override
|
||||||
public int compare(Module o1, Module o2) {
|
public int compare(Module o1, Module o2) {
|
||||||
|
@ -18,6 +18,7 @@ import org.json.JSONObject;
|
|||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -43,6 +44,9 @@ public class RepoHelper {
|
|||||||
if (!prefs.contains("hasCachedRepos") | refresh) {
|
if (!prefs.contains("hasCachedRepos") | refresh) {
|
||||||
Log.d(TAG, "RepoHelper: Building from web");
|
Log.d(TAG, "RepoHelper: Building from web");
|
||||||
new BuildFromWeb(delegate).execute();
|
new BuildFromWeb(delegate).execute();
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
|
||||||
|
String date = format.format(Calendar.getInstance().getTime());
|
||||||
|
prefs.edit().putString("last_update",date).apply();
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "RepoHelper: Building from cache");
|
Log.d(TAG, "RepoHelper: Building from cache");
|
||||||
BuildFromCache();
|
BuildFromCache();
|
||||||
|
Loading…
Reference in New Issue
Block a user