From 3d4b4e04c5c3dfea87cca9a6aa308429ae39e7d4 Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Mon, 12 Sep 2016 16:47:32 -0500 Subject: [PATCH] Bring module fragment up to same level as repo fragment --- .../topjohnwu/magisk/BaseModuleFragment.java | 45 +++- .../com/topjohnwu/magisk/ModulesFragment.java | 10 + .../com/topjohnwu/magisk/module/Module.java | 55 +++-- .../com/topjohnwu/magisk/utils/Utils.java | 9 +- app/src/main/res/layout/list_item_module.xml | 202 ++++++++++++------ app/src/main/res/layout/list_item_repo.xml | 3 +- app/src/main/res/values/strings.xml | 2 +- 7 files changed, 237 insertions(+), 89 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/BaseModuleFragment.java b/app/src/main/java/com/topjohnwu/magisk/BaseModuleFragment.java index c51e59f0a..2787f4f75 100644 --- a/app/src/main/java/com/topjohnwu/magisk/BaseModuleFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/BaseModuleFragment.java @@ -25,6 +25,7 @@ import android.widget.TextView; import com.topjohnwu.magisk.module.Module; import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Utils; +import com.topjohnwu.magisk.utils.WebWindow; import java.util.ArrayList; import java.util.List; @@ -132,7 +133,36 @@ public abstract class BaseModuleFragment extends Fragment { holder.title.setText(module.getName()); holder.versionName.setText(module.getVersion()); holder.description.setText(module.getDescription()); + holder.author.setText(module.getAuthor()); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + if (prefs.contains("repo-canUpdate_" + module.getId())) { + if (prefs.getBoolean("repo-canUpdate_" + module.getId(),false)) { + holder.updateStatus.setText(R.string.module_update_available); + holder.updateStatus.setVisibility(View.VISIBLE); + } else { + holder.updateStatus.setVisibility(View.GONE); + } + } + + View.OnClickListener oCl = new View.OnClickListener() { + @Override + public void onClick(View view) { + if (view.getId() == holder.changeLog.getId()) { + new WebWindow("Changelog",module.getChangeLog(),context); + } + if (view.getId() == holder.authorLink.getId()) { + new WebWindow("Donate",module.getmDonateUrl(),context); + } + if (view.getId() == holder.supportLink.getId()) { + new WebWindow("Support",module.getmSupportUrl(),context); + } + } + }; + + holder.authorLink.setOnClickListener(oCl); + holder.changeLog.setOnClickListener(oCl); + holder.supportLink.setOnClickListener(oCl); holder.checkBox.setChecked(module.isEnabled()); holder.checkBox.setOnCheckedChangeListener((compoundButton, b) -> chboxListener.onItemClick(compoundButton, holder.getAdapterPosition())); @@ -170,14 +200,15 @@ public abstract class BaseModuleFragment extends Fragment { @BindView(R.id.version_name) TextView versionName; @BindView(R.id.description) TextView description; - @BindView(R.id.warning) TextView warning; - @BindView(R.id.checkbox) CheckBox checkBox; - @BindView(R.id.delete) - ImageView delete; - @BindView(R.id.expand_layout) - LinearLayout expandLayout; + @BindView(R.id.author) TextView author; + @BindView(R.id.updateStatus) TextView updateStatus; + @BindView(R.id.delete) ImageView delete; + @BindView(R.id.changeLog) ImageView changeLog; + @BindView(R.id.authorLink) ImageView authorLink; + @BindView(R.id.supportLink) ImageView supportLink; + @BindView(R.id.expand_layout) LinearLayout expandLayout; private ValueAnimator mAnimator; private int mMeasuredHeight; @@ -188,6 +219,7 @@ public abstract class BaseModuleFragment extends Fragment { DisplayMetrics dimension = new DisplayMetrics(); windowmanager.getDefaultDisplay().getMetrics(dimension); final int mHeight = dimension.heightPixels; + expandLayout.getViewTreeObserver().addOnPreDrawListener( new ViewTreeObserver.OnPreDrawListener() { @@ -195,7 +227,6 @@ public abstract class BaseModuleFragment extends Fragment { public boolean onPreDraw() { expandLayout.getViewTreeObserver().removeOnPreDrawListener(this); expandLayout.setVisibility(View.GONE); - final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); final int heightSpec = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED); expandLayout.measure(widthSpec, heightSpec); diff --git a/app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java b/app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java index e3d915ea3..c3f64ee6a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java @@ -31,6 +31,8 @@ import com.topjohnwu.magisk.module.Repo; import com.topjohnwu.magisk.utils.Utils; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.regex.Pattern; @@ -123,6 +125,8 @@ public class ModulesFragment extends Fragment { 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; } @@ -202,5 +206,11 @@ public class ModulesFragment extends Fragment { } } } + public class CustomComparator implements Comparator { + @Override + public int compare(Module o1, Module o2) { + return o1.getName().compareTo(o2.getName()); + } + } } diff --git a/app/src/main/java/com/topjohnwu/magisk/module/Module.java b/app/src/main/java/com/topjohnwu/magisk/module/Module.java index 43ebc3cc4..09dce957b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/module/Module.java +++ b/app/src/main/java/com/topjohnwu/magisk/module/Module.java @@ -15,8 +15,8 @@ public class Module { private String mName = null; private String mVersion = "(No version provided)"; private String mDescription = "(No description provided)"; - private String mUrl,mSupportUrl,mDonateUrl,mZipUrl,mBaseUrl,mManifestUrl,mAuthor; - private boolean mEnable, mRemove,mUpdateAvailable,mIsOnline; + private String mUrl,mSupportUrl,mDonateUrl,mZipUrl,mBaseUrl,mManifestUrl,mAuthor,mLogUrl; + private boolean mEnable, mRemove,mUpdateAvailable,mIsOnline,mIsCacheModule; private String mId; @@ -43,40 +43,46 @@ public class Module { this.mVersionCode = Integer.valueOf(props[1]); break; case "name": - this.mName = value; + this.mName = props[1]; break; case "author": - this.mAuthor = value; + this.mAuthor = props[1]; break; case "id": - this.mId = value; + this.mId = props[1]; break; case "version": - this.mVersion = value; + this.mVersion = props[1]; break; case "description": - this.mDescription = value; + this.mDescription = props[1]; break; case "donate": - this.mDonateUrl = value; + this.mDonateUrl = props[1]; + break; + case "cacheModule": + this.mIsCacheModule = Boolean.valueOf(props[1]); break; case "support": - this.mSupportUrl = value; + this.mSupportUrl = props[1]; break; case "donateUrl": - this.mDonateUrl = value; + this.mDonateUrl = props[1]; break; case "zipUrl": - this.mZipUrl = value; + this.mZipUrl = props[1]; break; case "baseUrl": - this.mBaseUrl = value; + this.mBaseUrl = props[1]; break; case "manifestUrl": - this.mManifestUrl = value; + this.mManifestUrl = props[1]; + break; + case "logUrl": + this.mLogUrl = props[1]; break; default: - Log.d("Magisk", "Module: Manifest string not recognized: " + props[0]); + Log.d("Magisk", "Manifest string not recognized: " + props[0]); break; } @@ -106,6 +112,7 @@ public class Module { mIsOnline = true; } else mIsOnline = false; } + if (idEntry[0].equals("versionCode")) { if (idEntry.length != 2) { continue; @@ -171,6 +178,14 @@ public class Module { return mVersion; } + public String getAuthor() { + return mAuthor; + } + + public String getId() {return mId; } + + public String getChangeLog() {return mLogUrl; } + public String getDescription() { return mDescription; } @@ -199,6 +214,18 @@ public class Module { return mRemove; } + public String getmDonateUrl() { + return mDonateUrl; + } + + public String getmManifestUrl() { + return mManifestUrl; + } + + public String getmSupportUrl() { + return mSupportUrl; + } + public boolean isOnline() {return mIsOnline; } public boolean isUpdateAvailable() { return mUpdateAvailable; } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java index a98f26635..52b74550f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -41,6 +41,8 @@ import java.net.URL; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.spec.InvalidKeySpecException; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import javax.crypto.BadPaddingException; @@ -439,12 +441,12 @@ public class Utils { List magisk = getModList(MAGISK_PATH); Log.d("Magisk", "Utils: Reload called, loading modules from" + (doReload ? " the internet " : " cache")); List magiskCache = getModList(MAGISK_CACHE_PATH); - RepoHelper mr = new RepoHelper(); for (String mod : magisk) { Log.d("Magisk", "Utils: Adding module from string " + mod); ModulesFragment.listModules.add(new Module(mod, mContext)); } + for (String mod : magiskCache) { Log.d("Magisk", "Utils: Adding cache module from string " + mod); ModulesFragment.listModulesCache.add(new Module(mod, mContext)); @@ -452,6 +454,7 @@ public class Utils { return null; } + } public static class LoadRepos extends AsyncTask { @@ -479,6 +482,8 @@ public class Utils { return null; } + + } public static class FlashZIP extends AsyncTask { @@ -544,4 +549,6 @@ public class Utils { void onItemClick(View view, int position); } + + } diff --git a/app/src/main/res/layout/list_item_module.xml b/app/src/main/res/layout/list_item_module.xml index 00ce343c2..72c6951d5 100644 --- a/app/src/main/res/layout/list_item_module.xml +++ b/app/src/main/res/layout/list_item_module.xml @@ -1,112 +1,184 @@ - + xmlns:card_view="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:layout_marginBottom="3dip" + android:layout_marginLeft="8dip" + android:layout_marginRight="8dip" + android:layout_marginTop="3dip" + android:background="?android:attr/selectableItemBackground" + android:minHeight="?android:attr/listPreferredItemHeight" + card_view:cardCornerRadius="2dp" + card_view:cardElevation="2dp"> - + android:layout_gravity="center_vertical"> + android:textIsSelectable="false" /> - + + + + + + + + + + + + + + + + + + + + + + android:textIsSelectable="false" /> - + + + android:layout_alignParentStart="true" + android:layout_below="@id/description" + android:minHeight="100dp" + android:orientation="vertical" - - + > - - + - - + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/list_item_repo.xml b/app/src/main/res/layout/list_item_repo.xml index 7a863268d..39e09fae6 100644 --- a/app/src/main/res/layout/list_item_repo.xml +++ b/app/src/main/res/layout/list_item_repo.xml @@ -71,7 +71,7 @@ android:id="@+id/description" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_gravity="center_vertical" + android:layout_gravity="center_vertical" android:textAppearance="?android:attr/textAppearanceSmall" android:textIsSelectable="false" android:layout_alignParentStart="true" @@ -111,6 +111,7 @@ android:id="@+id/updateStatus" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_gravity="center_horizontal" android:textAppearance="?android:attr/textAppearanceSmall" android:textIsSelectable="false" android:layout_marginBottom="20dip" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 631912cbd..1f072f42a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -42,7 +42,7 @@ Cache modules No modules found - An update is available + An update is available! Module is up-to-date Module is installed Module is not installed