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.module.Module;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.WebWindow;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -132,7 +133,36 @@ public abstract class BaseModuleFragment extends Fragment {
holder.title.setText(module.getName()); holder.title.setText(module.getName());
holder.versionName.setText(module.getVersion()); holder.versionName.setText(module.getVersion());
holder.description.setText(module.getDescription()); 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.setChecked(module.isEnabled());
holder.checkBox.setOnCheckedChangeListener((compoundButton, b) -> chboxListener.onItemClick(compoundButton, holder.getAdapterPosition())); 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.version_name) TextView versionName;
@BindView(R.id.description) TextView description; @BindView(R.id.description) TextView description;
@BindView(R.id.warning) TextView warning; @BindView(R.id.warning) TextView warning;
@BindView(R.id.checkbox) CheckBox checkBox; @BindView(R.id.checkbox) CheckBox checkBox;
@BindView(R.id.delete) @BindView(R.id.author) TextView author;
ImageView delete; @BindView(R.id.updateStatus) TextView updateStatus;
@BindView(R.id.expand_layout) @BindView(R.id.delete) ImageView delete;
LinearLayout expandLayout; @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 ValueAnimator mAnimator;
private int mMeasuredHeight; private int mMeasuredHeight;
@ -188,6 +219,7 @@ public abstract class BaseModuleFragment extends Fragment {
DisplayMetrics dimension = new DisplayMetrics(); DisplayMetrics dimension = new DisplayMetrics();
windowmanager.getDefaultDisplay().getMetrics(dimension); windowmanager.getDefaultDisplay().getMetrics(dimension);
final int mHeight = dimension.heightPixels; final int mHeight = dimension.heightPixels;
expandLayout.getViewTreeObserver().addOnPreDrawListener( expandLayout.getViewTreeObserver().addOnPreDrawListener(
new ViewTreeObserver.OnPreDrawListener() { new ViewTreeObserver.OnPreDrawListener() {
@ -195,7 +227,6 @@ public abstract class BaseModuleFragment extends Fragment {
public boolean onPreDraw() { public boolean onPreDraw() {
expandLayout.getViewTreeObserver().removeOnPreDrawListener(this); expandLayout.getViewTreeObserver().removeOnPreDrawListener(this);
expandLayout.setVisibility(View.GONE); expandLayout.setVisibility(View.GONE);
final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
final int heightSpec = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED); final int heightSpec = View.MeasureSpec.makeMeasureSpec(0,View.MeasureSpec.UNSPECIFIED);
expandLayout.measure(widthSpec, heightSpec); expandLayout.measure(widthSpec, heightSpec);

View File

@ -31,6 +31,8 @@ import com.topjohnwu.magisk.module.Repo;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -123,6 +125,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(listModulesCache,new CustomComparator());
new updateUI().execute(); new updateUI().execute();
break; 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 mName = null;
private String mVersion = "(No version provided)"; private String mVersion = "(No version provided)";
private String mDescription = "(No description provided)"; private String mDescription = "(No description provided)";
private String mUrl,mSupportUrl,mDonateUrl,mZipUrl,mBaseUrl,mManifestUrl,mAuthor; private String mUrl,mSupportUrl,mDonateUrl,mZipUrl,mBaseUrl,mManifestUrl,mAuthor,mLogUrl;
private boolean mEnable, mRemove,mUpdateAvailable,mIsOnline; private boolean mEnable, mRemove,mUpdateAvailable,mIsOnline,mIsCacheModule;
private String mId; private String mId;
@ -43,40 +43,46 @@ public class Module {
this.mVersionCode = Integer.valueOf(props[1]); this.mVersionCode = Integer.valueOf(props[1]);
break; break;
case "name": case "name":
this.mName = value; this.mName = props[1];
break; break;
case "author": case "author":
this.mAuthor = value; this.mAuthor = props[1];
break; break;
case "id": case "id":
this.mId = value; this.mId = props[1];
break; break;
case "version": case "version":
this.mVersion = value; this.mVersion = props[1];
break; break;
case "description": case "description":
this.mDescription = value; this.mDescription = props[1];
break; break;
case "donate": case "donate":
this.mDonateUrl = value; this.mDonateUrl = props[1];
break;
case "cacheModule":
this.mIsCacheModule = Boolean.valueOf(props[1]);
break; break;
case "support": case "support":
this.mSupportUrl = value; this.mSupportUrl = props[1];
break; break;
case "donateUrl": case "donateUrl":
this.mDonateUrl = value; this.mDonateUrl = props[1];
break; break;
case "zipUrl": case "zipUrl":
this.mZipUrl = value; this.mZipUrl = props[1];
break; break;
case "baseUrl": case "baseUrl":
this.mBaseUrl = value; this.mBaseUrl = props[1];
break; break;
case "manifestUrl": case "manifestUrl":
this.mManifestUrl = value; this.mManifestUrl = props[1];
break;
case "logUrl":
this.mLogUrl = props[1];
break; break;
default: default:
Log.d("Magisk", "Module: Manifest string not recognized: " + props[0]); Log.d("Magisk", "Manifest string not recognized: " + props[0]);
break; break;
} }
@ -106,6 +112,7 @@ public class Module {
mIsOnline = true; mIsOnline = true;
} else mIsOnline = false; } else mIsOnline = false;
} }
if (idEntry[0].equals("versionCode")) { if (idEntry[0].equals("versionCode")) {
if (idEntry.length != 2) { if (idEntry.length != 2) {
continue; continue;
@ -171,6 +178,14 @@ public class Module {
return mVersion; return mVersion;
} }
public String getAuthor() {
return mAuthor;
}
public String getId() {return mId; }
public String getChangeLog() {return mLogUrl; }
public String getDescription() { public String getDescription() {
return mDescription; return mDescription;
} }
@ -199,6 +214,18 @@ public class Module {
return mRemove; return mRemove;
} }
public String getmDonateUrl() {
return mDonateUrl;
}
public String getmManifestUrl() {
return mManifestUrl;
}
public String getmSupportUrl() {
return mSupportUrl;
}
public boolean isOnline() {return mIsOnline; } public boolean isOnline() {return mIsOnline; }
public boolean isUpdateAvailable() { return mUpdateAvailable; } public boolean isUpdateAvailable() { return mUpdateAvailable; }

View File

@ -41,6 +41,8 @@ import java.net.URL;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException; import java.security.spec.InvalidKeySpecException;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import javax.crypto.BadPaddingException; import javax.crypto.BadPaddingException;
@ -439,12 +441,12 @@ public class Utils {
List<String> magisk = getModList(MAGISK_PATH); List<String> magisk = getModList(MAGISK_PATH);
Log.d("Magisk", "Utils: Reload called, loading modules from" + (doReload ? " the internet " : " cache")); Log.d("Magisk", "Utils: Reload called, loading modules from" + (doReload ? " the internet " : " cache"));
List<String> magiskCache = getModList(MAGISK_CACHE_PATH); List<String> magiskCache = getModList(MAGISK_CACHE_PATH);
RepoHelper mr = new RepoHelper();
for (String mod : magisk) { for (String mod : magisk) {
Log.d("Magisk", "Utils: Adding module from string " + mod); Log.d("Magisk", "Utils: Adding module from string " + mod);
ModulesFragment.listModules.add(new Module(mod, mContext)); ModulesFragment.listModules.add(new Module(mod, mContext));
} }
for (String mod : magiskCache) { for (String mod : magiskCache) {
Log.d("Magisk", "Utils: Adding cache module from string " + mod); Log.d("Magisk", "Utils: Adding cache module from string " + mod);
ModulesFragment.listModulesCache.add(new Module(mod, mContext)); ModulesFragment.listModulesCache.add(new Module(mod, mContext));
@ -452,6 +454,7 @@ public class Utils {
return null; return null;
} }
} }
public static class LoadRepos extends AsyncTask<Void, Void, Void> { public static class LoadRepos extends AsyncTask<Void, Void, Void> {
@ -479,6 +482,8 @@ public class Utils {
return null; return null;
} }
} }
public static class FlashZIP extends AsyncTask<Void, Void, Boolean> { public static class FlashZIP extends AsyncTask<Void, Void, Boolean> {
@ -544,4 +549,6 @@ public class Utils {
void onItemClick(View view, int position); void onItemClick(View view, int position);
} }
} }

View File

@ -13,31 +13,26 @@
android:minHeight="?android:attr/listPreferredItemHeight" android:minHeight="?android:attr/listPreferredItemHeight"
card_view:cardCornerRadius="2dp" card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp"> card_view:cardElevation="2dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:minHeight="?android:attr/listPreferredItemHeight" android:orientation="vertical"
android:orientation="horizontal"
android:padding="8dp"> android:padding="8dp">
<LinearLayout
android:layout_width="0dip" <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical">
android:layout_marginLeft="4dip"
android:layout_marginRight="4dip"
android:layout_weight="1"
android:orientation="vertical">
<TextView <TextView
android:id="@+id/title" android:id="@+id/title"
android:layout_width="300dip"
android:layout_height="wrap_content" 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:singleLine="false"
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:textIsSelectable="false" /> android:textIsSelectable="false" />
@ -46,50 +41,25 @@
android:id="@+id/version_name" android:id="@+id/version_name"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="@id/title"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@android:color/tertiary_text_dark" android:textColor="@android:color/tertiary_text_dark"
android:textIsSelectable="false" android:textIsSelectable="false"
android:textStyle="bold|italic" /> android:textStyle="bold|italic" />
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textIsSelectable="false"/>
<TextView
android:id="@+id/warning"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/remove_file_created"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/red500"
android:visibility="gone"/>
<LinearLayout <LinearLayout
android:id="@+id/expand_layout"
android:minHeight="100dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/author"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" android:layout_alignBaseline="@id/title"
android:textColor="@android:color/tertiary_text_dark" android:layout_alignParentEnd="true"
android:textIsSelectable="false" android:orientation="horizontal">
android:textStyle="bold|italic" />
</LinearLayout>
</LinearLayout>
<CheckBox <CheckBox
android:id="@+id/checkbox" android:id="@+id/checkbox"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:focusable="false" android:focusable="false"
android:gravity="center" android:gravity="center"
android:padding="3dp" android:padding="3dp"
@ -99,14 +69,116 @@
<ImageView <ImageView
android:id="@+id/delete" android:id="@+id/delete"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:focusable="false" android:focusable="false"
android:gravity="center" android:gravity="center"
android:padding="3dp" android:padding="3dp"
android:src="@drawable/ic_delete" android:src="@drawable/ic_delete"
tools:ignore="ContentDescription" /> tools:ignore="ContentDescription" />
</LinearLayout> </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" />
<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:id="@+id/expand_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
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" />
<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> </LinearLayout>

View File

@ -111,6 +111,7 @@
android:id="@+id/updateStatus" android:id="@+id/updateStatus"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceSmall" android:textAppearance="?android:attr/textAppearanceSmall"
android:textIsSelectable="false" android:textIsSelectable="false"
android:layout_marginBottom="20dip" /> android:layout_marginBottom="20dip" />

View File

@ -42,7 +42,7 @@
<!--Module Fragment--> <!--Module Fragment-->
<string name="cache_modules">Cache modules</string> <string name="cache_modules">Cache modules</string>
<string name="no_modules_found">No modules found</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_up_to_date">Module is up-to-date</string>
<string name="module_installed">Module is installed</string> <string name="module_installed">Module is installed</string>
<string name="module_not_installed">Module is not installed</string> <string name="module_not_installed">Module is not installed</string>