Bring module fragment up to same level as repo fragment

This commit is contained in:
d8ahazard 2016-09-12 16:47:32 -05:00
parent 62dd8f35c0
commit 3d4b4e04c5
7 changed files with 237 additions and 89 deletions

View File

@ -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);

View File

@ -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<Module> {
@Override
public int compare(Module o1, Module o2) {
return o1.getName().compareTo(o2.getName());
}
}
}

View File

@ -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; }

View File

@ -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<String> magisk = getModList(MAGISK_PATH);
Log.d("Magisk", "Utils: Reload called, loading modules from" + (doReload ? " the internet " : " cache"));
List<String> 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<Void, Void, Void> {
@ -479,6 +482,8 @@ public class Utils {
return null;
}
}
public static class FlashZIP extends AsyncTask<Void, Void, Boolean> {
@ -544,4 +549,6 @@ public class Utils {
void onItemClick(View view, int position);
}
}

View File

@ -1,112 +1,184 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
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">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:orientation="horizontal"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="8dp">
<LinearLayout
android:layout_width="0dip"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="4dip"
android:layout_marginRight="4dip"
android:layout_weight="1"
android:orientation="vertical">
android:layout_gravity="center_vertical">
<TextView
android:id="@+id/title"
android:layout_width="300dip"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="0dp"
android:singleLine="false"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textIsSelectable="false"/>
android:textIsSelectable="false" />
<TextView
android:id="@+id/version_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@id/title"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/tertiary_text_dark"
android:textIsSelectable="false"
android:textStyle="bold|italic" />
<TextView
android:id="@+id/description"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@id/title"
android:layout_alignParentEnd="true"
android:orientation="horizontal">
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:gravity="center"
android:padding="3dp"
android:src="@drawable/ic_menu_overflow_material"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:focusable="false"
android:gravity="center"
android:padding="3dp"
android:src="@drawable/ic_delete"
tools:ignore="ContentDescription" />
</LinearLayout>
<!--<ImageView-->
<!--android:id="@+id/update"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:focusable="false"-->
<!--android:gravity="right"-->
<!--android:background="@drawable/ic_file_download_black"-->
<!--android:layout_marginEnd="10dp"-->
<!--android:layout_gravity="right"-->
<!--android:layout_alignBaseline="@id/title"-->
<!--android:layout_alignParentEnd="true"-->
<!--/>-->
<TextView
android:id="@+id/description"
android:layout_width="300dip"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@id/version_name"
android:layout_gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textIsSelectable="false"/>
android:textIsSelectable="false" />
<TextView
android:id="@+id/warning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/description"
android:layout_gravity="center_vertical"
android:text="@string/remove_file_created"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/red500"
android:visibility="gone"/>
<LinearLayout
android:visibility="gone" />
<LinearLayout
android:id="@+id/expand_layout"
android:minHeight="100dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:layout_alignParentStart="true"
android:layout_below="@id/description"
android:minHeight="100dp"
android:orientation="vertical"
<TextView
android:id="@+id/author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/tertiary_text_dark"
android:textIsSelectable="false"
android:textStyle="bold|italic" />
</LinearLayout>
>
</LinearLayout>
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:focusable="false"
android:gravity="center"
android:padding="3dp"
android:src="@drawable/ic_menu_overflow_material"
tools:ignore="ContentDescription"/>
<TextView
android:id="@+id/author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/tertiary_text_dark"
android:textIsSelectable="false"
android:textStyle="bold|italic" />
<ImageView
android:id="@+id/delete"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:focusable="false"
android:gravity="center"
android:padding="3dp"
android:src="@drawable/ic_delete"
tools:ignore="ContentDescription"/>
</LinearLayout>
<TextView
android:id="@+id/updateStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textIsSelectable="false"
android:layout_gravity="center_horizontal" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="50dip"
android:layout_gravity="center"
android:layout_marginBottom="0dip"
android:orientation="horizontal">
<ImageView
android:id="@+id/changeLog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:background="@drawable/ic_changelog" />
<ImageView
android:id="@+id/authorLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:background="@drawable/ic_author" />
<ImageView
android:id="@+id/supportLink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:background="@drawable/ic_support" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>

View File

@ -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" />

View File

@ -42,7 +42,7 @@
<!--Module Fragment-->
<string name="cache_modules">Cache modules</string>
<string name="no_modules_found">No modules found</string>
<string name="module_update_available">An update is available</string>
<string name="module_update_available">An update is available!</string>
<string name="module_up_to_date">Module is up-to-date</string>
<string name="module_installed">Module is installed</string>
<string name="module_not_installed">Module is not installed</string>