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