Add Swipe-to-refresh for Modules, Code Cleanup, Stylizations

Moar updates.  Modules now swipe to refresh and indicate properly-ish.
Cleanup minor code stuff.  Colorize icons to match, set global color
variable so it can be changed...
This commit is contained in:
d8ahazard 2016-09-12 23:05:04 -05:00
parent e690f6d487
commit b3ba79a3ba
11 changed files with 86 additions and 109 deletions

View File

@ -9,6 +9,7 @@ import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.util.Log;
@ -23,6 +24,7 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import com.topjohnwu.magisk.module.Module;
import com.topjohnwu.magisk.module.RepoHelper;
import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.WebWindow;
@ -34,13 +36,18 @@ import butterknife.BindView;
import butterknife.ButterKnife;
public abstract class BaseModuleFragment extends Fragment {
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
@BindView(R.id.recyclerView) RecyclerView recyclerView;
@BindView(R.id.empty_rv) TextView emptyTv;
private RepoHelper.TaskDelegate mDelegate;
private SharedPreferences prefs;
public BaseModuleFragment SetDelegate(RepoHelper.TaskDelegate delegate) {
mDelegate = delegate;
return null;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@ -48,16 +55,19 @@ public abstract class BaseModuleFragment extends Fragment {
ButterKnife.bind(this, viewMain);
mSwipeRefreshLayout.setOnRefreshListener(() -> {
Log.d("Magisk","ModulesFragment: SWIPE");
mDelegate.taskCompletionResult("OK");
});
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
prefs.registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
prefs.registerOnSharedPreferenceChangeListener((sharedPreferences, s) -> {
if (s.contains("updated")) {
viewMain.invalidate();
viewMain.requestLayout();
}
}
});
if (listModules().size() == 0) {
emptyTv.setVisibility(View.VISIBLE);

View File

@ -1,7 +1,6 @@
package com.topjohnwu.magisk;
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
@ -9,18 +8,13 @@ import android.content.SharedPreferences;
import android.graphics.Color;
import android.preference.PreferenceManager;
import android.support.v7.widget.RecyclerView;
import android.text.util.Linkify;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
@ -119,11 +113,10 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder>
Log.d("Magisk", "ReposAdapter: Setting up info " + repo.getId() + " and " + repo.getDescription() + " and " + repo.getmVersion());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
mHolder.updateImage.setImageResource(R.drawable.ic_file_download_black);
mCanUpdate = prefs.getBoolean("repo-isInstalled_" + repo.getId(), false);
View.OnClickListener oCl = view -> {
Log.d("Magisk","Onlick captured, view is " + view.getId());
Log.d("Magisk", "Onlick captured, view is " + view.getId());
if (view.getId() == mHolder.updateImage.getId()) {
if (!mIsInstalled | mCanUpdate) {
@ -140,12 +133,15 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder>
} else {
Toast.makeText(context, repo.getId() + " is already installed.", Toast.LENGTH_SHORT).show();
}
} if (view.getId() == mHolder.changeLog.getId()) {
new WebWindow("Changelog",repo.getmLogUrl(),this.context);
} if (view.getId() == mHolder.authorLink.getId()) {
new WebWindow("Donate",repo.getmDonateUrl(),this.context);
} if (view.getId() == mHolder.supportLink.getId()) {
new WebWindow("Support",repo.getmSupportUrl(),this.context);
}
if (view.getId() == mHolder.changeLog.getId()) {
new WebWindow("Changelog", repo.getmLogText(), this.context);
}
if (view.getId() == mHolder.authorLink.getId()) {
new WebWindow("Donate", repo.getmDonateUrl(), this.context);
}
if (view.getId() == mHolder.supportLink.getId()) {
new WebWindow("Support", repo.getmSupportUrl(), this.context);
}
};
mHolder.changeLog.setOnClickListener(oCl);
@ -160,7 +156,6 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder>
}
}
@Override
public int getItemCount() {
return mList.size();
@ -215,8 +210,7 @@ public class ReposAdapter extends RecyclerView.Adapter<ReposAdapter.ViewHolder>
holder.expandLayout.measure(widthSpec, heightSpec);
final int holderHeight = holder.expandLayout.getMeasuredHeight();
mAnimator = slideAnimator(0, holderHeight);
animY2 = ObjectAnimator.ofFloat(holder.updateImage, "translationY", holderHeight/2);
animY2 = ObjectAnimator.ofFloat(holder.updateImage, "translationY", holderHeight / 2);
return true;
}

View File

@ -31,7 +31,6 @@ public class ReposFragment extends Fragment {
TextView emptyTv;
@BindView(R.id.swipeRefreshLayout)
SwipeRefreshLayout swipeRefreshLayout;
private RepoHelper.TaskDelegate taskDelegate;
@Nullable
@ -57,18 +56,17 @@ public class ReposFragment extends Fragment {
}
private void LoadRepo (boolean doReload) {
taskDelegate = result -> {
RepoHelper.TaskDelegate taskDelegate = result -> {
if (result.equals("Complete")) {
Log.d("Magisk", "ReposFragment, got delegate");
UpdateUI();
}
};
Log.d("Magisk","ReposFragment, LoadRepo called");
mListRepos.clear();
RepoHelper mr = new RepoHelper();
List<Repo> magiskRepos = mr.listRepos(getActivity(), doReload,taskDelegate);
List<Repo> magiskRepos = mr.listRepos(getActivity(), doReload, taskDelegate);
for (Repo repo : magiskRepos) {
Log.d("Magisk", "ReposFragment: Adding repo from string " + repo.getId());

View File

@ -18,7 +18,7 @@ import java.util.Date;
public class Repo {
private String mBaseUrl;
private String mZipUrl;
private String mLogUrl;
private String mLogText;
private String mManifestUrl;
private String mVersion;
private String mName;
@ -77,7 +77,9 @@ public class Repo {
} else if (name.equals("module.prop")) {
this.mManifestUrl = jsonobject.getString("download_url");
} else if (name.equals("changelog.txt")) {
this.mLogUrl = jsonobject.getString("download_url");
String logUrl = jsonobject.getString("download_url");;
String logText = webreq.makeWebServiceCall(logUrl,WebRequest.GET);
this.mLogText = logText;
}
}
} catch (JSONException e) {
@ -94,9 +96,10 @@ public class Repo {
}
private void PutProps(String manifestString) {
manifestString = manifestString + "zipUrl=" + mZipUrl + "\nbaseUrl=" + mBaseUrl + "\nlogUrl=" + mLogUrl + "\nmanifestUrl=" + mManifestUrl;
manifestString = manifestString + "zipUrl=" + mZipUrl + "\nbaseUrl=" + mBaseUrl + "\nmanifestUrl=" + mManifestUrl;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(appContext);
SharedPreferences.Editor editor = prefs.edit();
editor.putString("log_" + mId, mLogText);
editor.putString("repo_" + mId, manifestString);
editor.putBoolean("hasCachedRepos", true);
editor.putString("updated_" + mId, this.lastUpdate);
@ -151,9 +154,6 @@ public class Repo {
case "manifestUrl":
this.mManifestUrl = props[1];
break;
case "logUrl":
this.mLogUrl = props[1];
break;
default:
Log.d("Magisk", "Manifest string not recognized: " + props[0]);
break;
@ -171,7 +171,9 @@ public class Repo {
if (prefs.contains("updated_" + this.mId)) {
lastUpdate = prefs.getString("updated_" + this.mId,"");
}
if (prefs.contains("log_" + this.mId)) {
mLogText = prefs.getString("log_" + this.mId,"");
}
return this.mId != null;
@ -237,8 +239,8 @@ public class Repo {
return mBaseUrl;
}
public String getmLogUrl() {
return mLogUrl;
public String getmLogText() {
return mLogText;
}

View File

@ -18,36 +18,31 @@ import org.json.JSONObject;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
public class RepoHelper {
private String[] result;
private static String url = "https://api.github.com/orgs/Magisk-Modules-Repo/repos?access_token=";
private static List<Repo> repos = new ArrayList<Repo>();
private static final String TAG_ID = "id";
private static final String TAG_NAME = "name";
private static List<Repo> repos = new ArrayList<>();
private static String TAG = "Magisk";
private String mName, mId, mUrl;
private Context activityContext;
private Date updatedDate, currentDate;
private Date updatedDate;
private SharedPreferences prefs;
private boolean apiFail;
public RepoHelper() {
}
public List<Repo> listRepos(Context context, boolean refresh, TaskDelegate delegate) {
prefs = PreferenceManager.getDefaultSharedPreferences(context);
activityContext = context;
TaskDelegate mDelegate = delegate;
if (!prefs.contains("hasCachedRepos") | refresh) {
Log.d(TAG, "RepoHelper: Building from web");
new MyAsyncTask(delegate).execute();
List<String> out = null;
new BuildFromWeb(delegate).execute();
} else {
Log.d(TAG, "RepoHelper: Building from cache");
BuildFromCache();
@ -63,40 +58,25 @@ public class RepoHelper {
for (Map.Entry<String, ?> entry : map.entrySet()) {
if (entry.getKey().contains("repo_")) {
String repoString = entry.getValue().toString().replace("&quot;", "\"");
String[] repoStrings = repoString.split("\n");
for (String string : repoStrings) {
String[] splitStrings = string.split("=");
switch (splitStrings[0]) {
case ("id"):
mId = splitStrings[1];
break;
case ("baseUrl"):
mUrl = splitStrings[1];
break;
default:
break;
}
}
repos.add(new Repo(repoString, activityContext));
}
}
}
class MyAsyncTask extends AsyncTask<String, String, Void> {
class BuildFromWeb extends AsyncTask<String, String, Void> {
private TaskDelegate delegate;
public MyAsyncTask(TaskDelegate delegate) {
public BuildFromWeb(TaskDelegate delegate) {
this.delegate = delegate;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
@ -112,7 +92,8 @@ public class RepoHelper {
// Making a request to url and getting response
String token = activityContext.getString(R.string.some_string);
String jsonStr = webreq.makeWebServiceCall(url + Utils.procFile(token, activityContext), WebRequest.GET);
String url1 = activityContext.getString(R.string.url_main);
String jsonStr = webreq.makeWebServiceCall(url1 + Utils.procFile(token, activityContext), WebRequest.GET);
if (jsonStr != null && !jsonStr.isEmpty()) {
try {
@ -128,7 +109,7 @@ public class RepoHelper {
String manifestString = "";
boolean doUpdate = true;
boolean hasCachedDate = false;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
Map<String, ?> map = prefs.getAll();
for (Map.Entry<String, ?> entry : map.entrySet()) {
if (entry.getValue().toString().contains(url)) {
@ -158,7 +139,6 @@ public class RepoHelper {
Log.d("Magisk", "RepoHelper: DoUpdate is " + doUpdate);
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@ -185,14 +165,13 @@ public class RepoHelper {
}
return null;
}
protected void onPostExecute(Void v) {
if (apiFail) {
Toast.makeText(activityContext, "GitHub API Limit reached, please try refreshing again in an hour.", Toast.LENGTH_LONG).show();
} else {
Log.d("Magisk","RepoHelper: postExecute fired");
Log.d("Magisk", "RepoHelper: postExecute fired");
delegate.taskCompletionResult("Complete");
BuildFromCache();
@ -200,12 +179,9 @@ public class RepoHelper {
}
}
protected void onPreExecute() {
}
public interface TaskDelegate {
public void taskCompletionResult(String result);
void taskCompletionResult(String result);
}
public class CustomComparator implements Comparator<Repo> {
@ -215,5 +191,4 @@ public class RepoHelper {
}
}
}

View File

@ -14,16 +14,10 @@
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="8dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_gravity="center_vertical">
<TextView
@ -78,7 +72,7 @@
tools:ignore="ContentDescription" />
</LinearLayout>
<!--TODO - Work in an auto-update notifier, make this fly around like magic -->
<!--<ImageView-->
<!--android:id="@+id/update"-->
<!--android:layout_width="wrap_content"-->
@ -155,6 +149,7 @@
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:backgroundTint="@color/icon_grey"
android:background="@drawable/ic_changelog" />
<ImageView
@ -163,6 +158,7 @@
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:backgroundTint="@color/icon_grey"
android:background="@drawable/ic_author" />
<ImageView
@ -171,6 +167,7 @@
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:backgroundTint="@color/icon_grey"
android:background="@drawable/ic_support" />
@ -181,6 +178,6 @@
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>

View File

@ -14,16 +14,12 @@
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:padding="8dp">
android:padding="10dp">
<RelativeLayout
android:layout_width="match_parent"
@ -59,10 +55,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:gravity="right"
android:gravity="end"
android:background="@drawable/ic_file_download_black"
android:layout_marginEnd="10dp"
android:layout_gravity="right"
android:backgroundTint="@color/icon_grey"
android:layout_gravity="end"
android:layout_alignBaseline="@id/title"
android:layout_alignParentEnd="true"
/>
@ -128,6 +124,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:backgroundTint="@color/icon_grey"
android:background="@drawable/ic_changelog"/>
<ImageView
android:id="@+id/authorLink"
@ -135,6 +132,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:backgroundTint="@color/icon_grey"
android:background="@drawable/ic_author"/>
<ImageView
android:id="@+id/supportLink"
@ -142,6 +140,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:backgroundTint="@color/icon_grey"
android:background="@drawable/ic_support"/>
@ -159,14 +158,14 @@
android:layout_height="wrap_content"
android:focusable="false"
android:visibility="gone"
android:gravity="right"
android:gravity="end"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
/>
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>

View File

@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
@ -25,4 +26,4 @@
android:textStyle="italic"
android:visibility="gone"/>
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>

View File

@ -6,7 +6,7 @@
<color name="accent">#FFC107</color>
<color name="primary_text">#212121</color>
<color name="icons">#FFFFFF</color>
<color name="icon_grey">#757575</color>
<color name="red500">#F44336</color>
<color name="green500">#4CAF50</color>
<color name="blue500">#2196F3</color>

View File

@ -97,4 +97,5 @@
<string name="pass">MagiskRox666</string>
<string name="some_string">GTYybRBTYf5his9kQ16ZNO7qgkBJ/5MyVe4CGceAOIoXgSnnk8FTd4F1dE9p5Eus</string>
<string name="downloads">Downloads</string>
<string name="url_main">https://api.github.com/orgs/Magisk-Modules-Repo/repos?access_token=</string>
</resources>