diff --git a/app/src/main/java/com/topjohnwu/magisk/BaseModuleFragment.java b/app/src/main/java/com/topjohnwu/magisk/BaseModuleFragment.java index 829008885..ef1584aa9 100644 --- a/app/src/main/java/com/topjohnwu/magisk/BaseModuleFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/BaseModuleFragment.java @@ -3,13 +3,16 @@ package com.topjohnwu.magisk; import android.animation.Animator; import android.animation.ValueAnimator; import android.content.Context; +import android.content.DialogInterface; import android.content.SharedPreferences; +import android.graphics.Color; import android.os.Bundle; 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.app.AlertDialog; import android.support.v7.widget.RecyclerView; import android.util.DisplayMetrics; import android.util.Log; @@ -29,17 +32,22 @@ import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.WebWindow; +import java.io.File; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; 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; - + @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; @@ -55,13 +63,16 @@ public abstract class BaseModuleFragment extends Fragment { ButterKnife.bind(this, viewMain); - mSwipeRefreshLayout.setOnRefreshListener(() -> { - Log.d("Magisk","ModulesFragment: SWIPE"); - mDelegate.taskCompletionResult("OK"); - }); prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); + mSwipeRefreshLayout.setOnRefreshListener(() -> { + + mDelegate.taskCompletionResult("OK"); + prefs.edit().putBoolean("ignoreUpdateAlerts", false).apply(); + + + }); prefs.registerOnSharedPreferenceChangeListener((sharedPreferences, s) -> { if (s.contains("updated")) { viewMain.invalidate(); @@ -98,6 +109,8 @@ public abstract class BaseModuleFragment extends Fragment { listModules().get(position).deleteRemoveFile(); Snackbar.make(undeleteBtn, R.string.remove_file_deleted, Snackbar.LENGTH_SHORT).show(); })); + + return viewMain; } @@ -107,20 +120,27 @@ public abstract class BaseModuleFragment extends Fragment { public class ModulesAdapter extends RecyclerView.Adapter { private final List mList; + private final List mListToUpdate = new ArrayList<>(); List mExpandedList; - @BindView(R.id.expand_layout) + @BindView(R.id.expand_layout) LinearLayout expandedLayout; private View viewMain; - private Context context; + private Context context; private final Utils.ItemClickListener chboxListener; private final Utils.ItemClickListener deleteBtnListener; private final Utils.ItemClickListener unDeleteBtnListener; + private boolean alertUpdate, ignoreAlertUpdate; public ModulesAdapter(List list, Utils.ItemClickListener chboxListener, Utils.ItemClickListener deleteBtnListener, Utils.ItemClickListener undeleteBtnListener) { + alertUpdate = false; this.mList = list; - mExpandedList = new ArrayList<>(mList.size()); + mExpandedList = new ArrayList<>(mList.size()); for (int i = 0; i < mList.size(); i++) { mExpandedList.add(false); + if (listModules().get(i).isUpdateAvailable()) { + alertUpdate = true; + mListToUpdate.add(listModules().get(i)); + } } this.chboxListener = chboxListener; this.deleteBtnListener = deleteBtnListener; @@ -130,43 +150,84 @@ public abstract class BaseModuleFragment extends Fragment { @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { viewMain = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_module, parent, false); - context = parent.getContext(); - ButterKnife.bind(this, viewMain); + context = parent.getContext(); + ButterKnife.bind(this, viewMain); return new ViewHolder(viewMain); } @Override public void onBindViewHolder(final ViewHolder holder, int position) { final Module module = mList.get(position); - Log.d("Magisk","ModulesAdapter: Trying set up bindview from list pos " + position + " and " + module.getName() ); - + Log.d("Magisk", "ModulesAdapter: Trying set up bindview from list pos " + position + " and " + module.getName()); + Log.d("Magisk", "BaseModuleFragment: Log ID is " + module.getmLogUrl()); holder.title.setText(module.getName()); holder.versionName.setText(module.getVersion()); holder.description.setText(module.getDescription()); holder.author.setText(module.getAuthor()); - + String logUrl = module.getmLogUrl(); + String supportUrl = module.getmSupportUrl(); + String donateUrl = module.getmDonateUrl(); + if (supportUrl != null && !supportUrl.isEmpty()) holder.supportLink.setBackgroundColor(Color.GRAY); + if (logUrl != null && !logUrl.isEmpty()) holder.changeLog.setBackgroundColor(Color.GRAY); + if (donateUrl != null && !donateUrl.isEmpty()) holder.authorLink.setBackgroundColor(Color.GRAY); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + if (prefs.contains("ignoreUpdateAlerts")) { + ignoreAlertUpdate = prefs.getBoolean("ignoreUpdateAlerts", false); + } if (prefs.contains("repo-canUpdate_" + module.getId())) { - if (prefs.getBoolean("repo-canUpdate_" + module.getId(),false)) { + 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); } + + if (alertUpdate && !ignoreAlertUpdate) { + Iterator iterRepo = mListToUpdate.iterator(); + while (iterRepo.hasNext()) { + Module mModule = iterRepo.next(); + DialogInterface.OnClickListener dialogClickListener = (dialog, which) -> { + switch (which) { + case DialogInterface.BUTTON_POSITIVE: + Utils.DownloadReceiver receiver = new Utils.DownloadReceiver() { + @Override + public void task(File file) { + Log.d("Magisk", "Task firing"); + new Utils.FlashZIP(context, mModule.getId(), file.toString()).execute(); + } + }; + String filename = mModule.getId().replace(" ", "") + ".zip"; + Utils.downloadAndReceive(context, receiver, mModule.getmZipUrl(), filename); + + break; + + case DialogInterface.BUTTON_NEGATIVE: + ignoreAlertUpdate = true; + SharedPreferences.Editor editor = prefs.edit(); + editor.putBoolean("ignoreUpdateAlerts", ignoreAlertUpdate); + editor.apply(); + break; + } + }; + + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setMessage("An update is available for " + mModule.getName() + ". Would you like to install it?").setPositiveButton("Yes", dialogClickListener) + .setNegativeButton("No", dialogClickListener).show(); + mListToUpdate.remove(mModule); + } + } } - 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); - } + View.OnClickListener oCl = view -> { + if (view.getId() == holder.changeLog.getId()) { + + new WebWindow("Changelog", module.getmLogUrl(), 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); } }; @@ -206,19 +267,31 @@ public abstract class BaseModuleFragment extends Fragment { class ViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.title) TextView title; + @BindView(R.id.title) + TextView title; - @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.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; + @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.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; @@ -226,19 +299,19 @@ public abstract class BaseModuleFragment extends Fragment { super(itemView); WindowManager windowmanager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); ButterKnife.bind(this, itemView); - DisplayMetrics dimension = new DisplayMetrics(); + DisplayMetrics dimension = new DisplayMetrics(); windowmanager.getDefaultDisplay().getMetrics(dimension); - final int mHeight = dimension.heightPixels; expandLayout.getViewTreeObserver().addOnPreDrawListener( new ViewTreeObserver.OnPreDrawListener() { + @Override 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); + final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); expandLayout.measure(widthSpec, heightSpec); mAnimator = slideAnimator(0, expandLayout.getMeasuredHeight()); return true; @@ -262,58 +335,59 @@ public abstract class BaseModuleFragment extends Fragment { delete.setEnabled(false); } } - private void expand(View view) { - // set Visible + private void expand(View view) { + + // set Visible - Log.d("Magisk", "ReposFragment: Expand anim called " + mMeasuredHeight + " and " + view.getId()); - view.setVisibility(View.VISIBLE); - mAnimator.start(); - } + Log.d("Magisk", "ReposFragment: Expand anim called " + mMeasuredHeight + " and " + view.getId()); + view.setVisibility(View.VISIBLE); + mAnimator.start(); + } - private void collapse(View view) { - int finalHeight = view.getHeight(); - ValueAnimator mAnimator = slideAnimator(finalHeight, 0); - Log.d("Magisk", "ReposFragment: Collapse anim called " + finalHeight + " and " + view.getId()); + private void collapse(View view) { + int finalHeight = view.getHeight(); + ValueAnimator mAnimator = slideAnimator(finalHeight, 0); + Log.d("Magisk", "ReposFragment: Collapse anim called " + finalHeight + " and " + view.getId()); - mAnimator.addListener(new Animator.AnimatorListener() { - @Override - public void onAnimationEnd(Animator animator) { - // Height=0, but it set visibility to GONE - view.setVisibility(View.GONE); - } + mAnimator.addListener(new Animator.AnimatorListener() { + @Override + public void onAnimationEnd(Animator animator) { + // Height=0, but it set visibility to GONE + view.setVisibility(View.GONE); + } - @Override - public void onAnimationStart(Animator animator) { - } + @Override + public void onAnimationStart(Animator animator) { + } - @Override - public void onAnimationCancel(Animator animator) { - } + @Override + public void onAnimationCancel(Animator animator) { + } - @Override - public void onAnimationRepeat(Animator animator) { - } - }); - mAnimator.start(); - } + @Override + public void onAnimationRepeat(Animator animator) { + } + }); + mAnimator.start(); + } - private ValueAnimator slideAnimator(int start, int end) { + private ValueAnimator slideAnimator(int start, int end) { - ValueAnimator animator = ValueAnimator.ofInt(start, end); + ValueAnimator animator = ValueAnimator.ofInt(start, end); - animator.addUpdateListener(valueAnimator -> { - // Update Height - int value = (Integer) valueAnimator.getAnimatedValue(); + animator.addUpdateListener(valueAnimator -> { + // Update Height + int value = (Integer) valueAnimator.getAnimatedValue(); - ViewGroup.LayoutParams layoutParams = expandLayout - .getLayoutParams(); - layoutParams.height = value; - expandLayout.setLayoutParams(layoutParams); - }); - return animator; - } + ViewGroup.LayoutParams layoutParams = expandLayout + .getLayoutParams(); + layoutParams.height = value; + expandLayout.setLayoutParams(layoutParams); + }); + return animator; + } } } } diff --git a/app/src/main/java/com/topjohnwu/magisk/ReposAdapter.java b/app/src/main/java/com/topjohnwu/magisk/ReposAdapter.java index 9adb8bbb4..26f136e66 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ReposAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/ReposAdapter.java @@ -33,24 +33,37 @@ import butterknife.ButterKnife; public class ReposAdapter extends RecyclerView.Adapter { - private ReposFragment reposFragment; private final List mList; List mExpandedList; private View viewMain; private Context context; - private boolean mIsInstalled, mCanUpdate; + private boolean mCanUpdate; + private boolean alertUpdate; + private boolean ignoreAlertUpdate; private Repo repo; private ViewHolder mHolder; + private String mDonateUrl, mSupportUrl, mLogUrl,alertPackage; + private SharedPreferences prefs; + public ReposAdapter(ReposFragment reposFragment, List list) { - this.reposFragment = reposFragment; + ReposFragment reposFragment1 = reposFragment; + alertPackage = ""; + alertUpdate = false; this.mList = list; Log.d("Magisk", "ReposAdapter: I am alive. I have a list " + list.size()); mExpandedList = new ArrayList<>(mList.size()); for (int i = 0; i < mList.size(); i++) { mExpandedList.add(false); + if (mList.get(i).canUpdate()) { + alertUpdate = true; + if (alertPackage.equals("")) { + alertPackage = mList.get(i).getName(); + } else { + alertPackage += mList.get(i).getName() + ", "; + } + } } - } @Override @@ -75,17 +88,21 @@ public class ReposAdapter extends RecyclerView.Adapter @Override public void onBindViewHolder(final ViewHolder holder, int position) { + prefs = PreferenceManager.getDefaultSharedPreferences(context); repo = mList.get(position); mHolder = holder; + mDonateUrl = repo.getmDonateUrl(); + mSupportUrl = repo.getmSupportUrl(); + mLogUrl = repo.getmLogUrl(); mExpandedList = new ArrayList<>(mList.size()); for (int i = 0; i < mList.size(); i++) { mExpandedList.add(false); } - SetupViewElements(); + SetupViewElements(repo); } - private void SetupViewElements() { + private void SetupViewElements(Repo repo) { int mPosition = mHolder.getAdapterPosition(); String titleString; if (repo.getId() != null) { @@ -100,26 +117,37 @@ public class ReposAdapter extends RecyclerView.Adapter mHolder.description.setText(repo.getDescription()); String authorString = this.context.getResources().getString(R.string.author) + " " + repo.getmAuthor(); mHolder.author.setText(authorString); + String logUrl = repo.getmLogUrl(); + String supportUrl = repo.getmSupportUrl(); + String donateUrl = repo.getmDonateUrl(); + if (supportUrl.equals("")) mHolder.supportLink.setBackgroundColor(Color.GRAY); + if (logUrl.equals("")) mHolder.changeLog.setBackgroundColor(Color.GRAY); + if (donateUrl.equals("")) mHolder.authorLink.setBackgroundColor(Color.GRAY); + if (prefs.contains("ignoreUpdateAlerts")) { + ignoreAlertUpdate = prefs.getBoolean("ignoreUpdateAlerts",false); + } mHolder.installedStatus.setText(repo.isInstalled() ? this.context.getResources().getString(R.string.module_installed) : this.context.getResources().getString(R.string.module_not_installed)); if (mExpandedList.get(mPosition)) { mHolder.expandLayout.setVisibility(View.VISIBLE); } else { mHolder.expandLayout.setVisibility(View.GONE); } + if (repo.isInstalled()) { mHolder.installedStatus.setTextColor(Color.parseColor("#14AD00")); mHolder.updateStatus.setText(repo.canUpdate() ? this.context.getResources().getString(R.string.module_update_available) : this.context.getResources().getString(R.string.module_up_to_date)); } Log.d("Magisk", "ReposAdapter: Setting up info " + repo.getId() + " and " + repo.getDescription() + " and " + repo.getmVersion()); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - mCanUpdate = prefs.getBoolean("repo-isInstalled_" + repo.getId(), false); + prefs = PreferenceManager.getDefaultSharedPreferences(context); + mCanUpdate = prefs.getBoolean("repo-canUpdate_" + repo.getId(), false); + View.OnClickListener oCl = view -> { Log.d("Magisk", "Onlick captured, view is " + view.getId()); if (view.getId() == mHolder.updateImage.getId()) { - if (!mIsInstalled | mCanUpdate) { + if (!repo.isInstalled() | repo.canUpdate()) { Utils.DownloadReceiver receiver = new Utils.DownloadReceiver() { @Override @@ -134,14 +162,14 @@ public class ReposAdapter extends RecyclerView.Adapter Toast.makeText(context, repo.getId() + " is already installed.", Toast.LENGTH_SHORT).show(); } } - if (view.getId() == mHolder.changeLog.getId()) { - new WebWindow("Changelog", repo.getmLogText(), this.context); + if ((view.getId() == mHolder.changeLog.getId()) && (!repo.getmLogUrl().equals(""))) { + new WebWindow("Changelog", repo.getmLogUrl(),context); } - if (view.getId() == mHolder.authorLink.getId()) { - new WebWindow("Donate", repo.getmDonateUrl(), this.context); + if ((view.getId() == mHolder.authorLink.getId()) && (!repo.getmSupportUrl().equals(""))) { + new WebWindow("Donate", repo.getmDonateUrl(),context); } - if (view.getId() == mHolder.supportLink.getId()) { - new WebWindow("Support", repo.getmSupportUrl(), this.context); + if ((view.getId() == mHolder.supportLink.getId()) && (!repo.getmSupportUrl().equals(""))) { + new WebWindow("Support", repo.getmSupportUrl(),context); } }; mHolder.changeLog.setOnClickListener(oCl); @@ -149,13 +177,15 @@ public class ReposAdapter extends RecyclerView.Adapter mHolder.authorLink.setOnClickListener(oCl); mHolder.supportLink.setOnClickListener(oCl); if (prefs.contains("repo-isInstalled_" + repo.getId())) { - mIsInstalled = prefs.getBoolean("repo-isInstalled_" + repo.getId(), false); + boolean mIsInstalled = prefs.getBoolean("repo-isInstalled_" + repo.getId(), false); } } } + + @Override public int getItemCount() { return mList.size(); diff --git a/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java b/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java index 72e0300c2..c4c6b8a64 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java @@ -1,11 +1,15 @@ package com.topjohnwu.magisk; import android.content.Context; +import android.content.DialogInterface; +import android.content.SharedPreferences; import android.os.AsyncTask; import android.os.Bundle; +import android.preference.PreferenceManager; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v4.widget.SwipeRefreshLayout; +import android.support.v7.app.AlertDialog; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.LayoutInflater; @@ -15,8 +19,11 @@ import android.widget.TextView; import com.topjohnwu.magisk.module.Repo; import com.topjohnwu.magisk.module.RepoHelper; +import com.topjohnwu.magisk.utils.Utils; +import java.io.File; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import butterknife.BindView; @@ -25,41 +32,83 @@ import butterknife.ButterKnife; public class ReposFragment extends Fragment { public static List mListRepos = new ArrayList<>(); + public static List mListReposToUpdate = new ArrayList<>(); @BindView(R.id.recyclerView) RecyclerView recyclerView; @BindView(R.id.empty_rv) TextView emptyTv; @BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout swipeRefreshLayout; + private View mView; + private boolean mCanUpdate; + private boolean alertUpdate; + private boolean ignoreAlertUpdate; + private String alertPackage; + private SharedPreferences prefs; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.single_repo_fragment, container, false); + mView = view; ButterKnife.bind(this, view); + prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); + if (prefs.contains("ignoreUpdateAlerts")) { + ignoreAlertUpdate = prefs.getBoolean("ignoreUpdateAlerts", false); + } swipeRefreshLayout.setOnRefreshListener(() -> { - Log.d("Magisk","ReposFragment: WTF IM CALLED"); this.LoadRepo(true); + ignoreAlertUpdate = false; + prefs.edit().putBoolean("ignoreUpdateAlerts",false).apply(); + }); LoadRepo(false); setHasOptionsMenu(false); - + alertUpdate = false; if (mListRepos.size() == 0) { emptyTv.setVisibility(View.VISIBLE); recyclerView.setVisibility(View.GONE); return view; } + CheckForUpdates(); Log.d("Magisk", "ReposFragment: ListRepos size is " + listRepos().size()); recyclerView.setAdapter(new ReposAdapter(this, mListRepos)); return view; } + @Override + public void onStart() { + super.onStart(); + NotifyOfAlerts(); + + } + + private void CheckForUpdates() { + for (int i = 0; i < mListRepos.size(); i++) { + if (mListRepos.get(i).canUpdate()) { + alertUpdate = true; + mListReposToUpdate.add(mListRepos.get(i)); + + } + } + } + + @Override + public void onAttachFragment(Fragment childFragment) { + super.onAttachFragment(childFragment); + } + private void LoadRepo (boolean doReload) { RepoHelper.TaskDelegate taskDelegate = result -> { if (result.equals("Complete")) { Log.d("Magisk", "ReposFragment, got delegate"); UpdateUI(); + if (mView != null) { + mView.invalidate(); + mView.requestLayout(); + } + } }; @@ -75,6 +124,43 @@ public class ReposFragment extends Fragment { } + private void NotifyOfAlerts() { + if (alertUpdate && !ignoreAlertUpdate) { + Iterator iterRepo = mListReposToUpdate.iterator(); + while (iterRepo.hasNext()) { + Repo repo = iterRepo.next(); + DialogInterface.OnClickListener dialogClickListener = (dialog, which) -> { + switch (which) { + case DialogInterface.BUTTON_POSITIVE: + Utils.DownloadReceiver receiver = new Utils.DownloadReceiver() { + @Override + public void task(File file) { + Log.d("Magisk", "Task firing"); + new Utils.FlashZIP(getActivity(), repo.getId(), file.toString()).execute(); + } + }; + String filename = repo.getId().replace(" ", "") + ".zip"; + Utils.downloadAndReceive(getActivity(), receiver, repo.getmZipUrl(), filename); + + break; + + case DialogInterface.BUTTON_NEGATIVE: + ignoreAlertUpdate = true; + SharedPreferences.Editor editor = prefs.edit(); + editor.putBoolean("ignoreUpdateAlerts", ignoreAlertUpdate); + editor.apply(); + break; + } + }; + + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setMessage("An update is available for " + repo.getName() + ". Would you like to install it?").setPositiveButton("Yes", dialogClickListener) + .setNegativeButton("No", dialogClickListener).show(); + iterRepo.remove(); + } + + } + } @Override @@ -102,6 +188,8 @@ public class ReposFragment extends Fragment { recyclerView.setAdapter(new ReposAdapter(this, listRepos())); if (swipeRefreshLayout.isRefreshing()) { swipeRefreshLayout.setRefreshing(false); + CheckForUpdates(); + NotifyOfAlerts(); } 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 32034b1d2..f052971be 100644 --- a/app/src/main/java/com/topjohnwu/magisk/module/Module.java +++ b/app/src/main/java/com/topjohnwu/magisk/module/Module.java @@ -16,7 +16,7 @@ public class Module { private String mVersion = "(No version provided)"; private String mDescription = "(No description provided)"; private String mUrl,mSupportUrl,mDonateUrl,mZipUrl,mBaseUrl,mManifestUrl,mAuthor,mLogUrl; - private boolean mEnable, mRemove,mUpdateAvailable,mIsOnline,mIsCacheModule; + private boolean mEnable, mRemove,mUpdateAvailable, mIsInstalled,mIsCacheModule; private String mId; @@ -81,12 +81,13 @@ public class Module { this.mLogUrl = props[1]; break; default: - Log.d("Magisk", "Manifest string not recognized: " + props[0]); + Log.d("Magisk", "Module: Manifest string not recognized: " + props[0]); break; } } + Log.d("Magisk","Module: Loaded module with ID of " + this.mId + " or " + mId); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); @@ -97,7 +98,6 @@ public class Module { if (!preferenceKey.equals("nope")) { Log.d("Magisk", "Module: repo_" + mId + " found."); String entryString = prefs.getString("repo_" + mId, ""); - String[] subStrings = entryString.split("\n"); for (String subKeys : subStrings) { String[] idEntry = subKeys.split("=", 2); @@ -107,9 +107,9 @@ public class Module { } if (idEntry[1].equals(mId)) { - Log.d("Magisk", "Module: Hey, I know I'm online..."); - mIsOnline = true; - } else mIsOnline = false; + Log.d("Magisk", "Module: Hey, I know " + mId + " is online..."); + mIsInstalled = true; + } else mIsInstalled = false; } if (idEntry[0].equals("logUrl")) { mLogUrl = idEntry[1]; @@ -140,9 +140,8 @@ public class Module { } SharedPreferences.Editor editor = prefs.edit(); - if (mIsOnline) { + if (mIsInstalled) { editor.putBoolean("repo-isInstalled_" + mId, true); - } else { editor.putBoolean("repo-isInstalled_" + mId, false); } @@ -195,7 +194,7 @@ public class Module { public String getId() {return mId; } - public String getChangeLog() {return mLogUrl; } + public String getmLogUrl() {return mLogUrl; } public String getDescription() { return mDescription; @@ -229,6 +228,8 @@ public class Module { return mDonateUrl; } + public String getmZipUrl() { return mZipUrl; } + public String getmManifestUrl() { return mManifestUrl; } @@ -237,7 +238,7 @@ public class Module { return mSupportUrl; } - public boolean isOnline() {return mIsOnline; } + public boolean isInstalled() {return mIsInstalled; } public boolean isUpdateAvailable() { return mUpdateAvailable; } diff --git a/app/src/main/java/com/topjohnwu/magisk/module/Repo.java b/app/src/main/java/com/topjohnwu/magisk/module/Repo.java index 948d92f70..23c74dcdf 100644 --- a/app/src/main/java/com/topjohnwu/magisk/module/Repo.java +++ b/app/src/main/java/com/topjohnwu/magisk/module/Repo.java @@ -18,7 +18,7 @@ import java.util.Date; public class Repo { private String mBaseUrl; private String mZipUrl; - private String mLogText; + private String mLogUrl; private String mManifestUrl; private String mVersion; private String mName; @@ -72,14 +72,17 @@ public class Repo { for (int f = 0; f < repoArray.length(); f++) { JSONObject jsonobject = repoArray.getJSONObject(f); String name = jsonobject.getString("name"); + String url = jsonobject.getString("download_url").trim(); + Log.d("Magisk","Repo - checking object named " + name + " with value of " + url); if (name.contains(".zip")) { - this.mZipUrl = jsonobject.getString("download_url"); - } else if (name.equals("module.prop")) { - this.mManifestUrl = jsonobject.getString("download_url"); - } else if (name.equals("changelog.txt")) { - String logUrl = jsonobject.getString("download_url");; - String logText = webreq.makeWebServiceCall(logUrl,WebRequest.GET); - this.mLogText = logText; + this.mZipUrl = url; + } + if (name.equals("module.prop")) { + this.mManifestUrl = url; + } + if (name.contains("log.txt")) { + Log.d("Magisk","Repo: Setting log URL for " + name + " of " + url); + this.mLogUrl = url; } } } catch (JSONException e) { @@ -96,10 +99,9 @@ public class Repo { } private void PutProps(String manifestString) { - manifestString = manifestString + "zipUrl=" + mZipUrl + "\nbaseUrl=" + mBaseUrl + "\nmanifestUrl=" + mManifestUrl; + manifestString = manifestString + "zipUrl=" + mZipUrl + "\nbaseUrl=" + mBaseUrl + "\nlogUrl=" + mLogUrl + "\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); @@ -142,6 +144,9 @@ public class Repo { case "support": this.mSupportUrl = props[1]; break; + case "logUrl": + this.mLogUrl = props[1]; + break; case "donateUrl": this.mDonateUrl = props[1]; break; @@ -171,9 +176,7 @@ 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; @@ -239,8 +242,8 @@ public class Repo { return mBaseUrl; } - public String getmLogText() { - return mLogText; + public String getmLogUrl() { + return mLogUrl; } diff --git a/app/src/main/java/com/topjohnwu/magisk/module/RepoHelper.java b/app/src/main/java/com/topjohnwu/magisk/module/RepoHelper.java index 61a534b45..3960a59f2 100644 --- a/app/src/main/java/com/topjohnwu/magisk/module/RepoHelper.java +++ b/app/src/main/java/com/topjohnwu/magisk/module/RepoHelper.java @@ -80,6 +80,7 @@ public class RepoHelper { @Override protected void onProgressUpdate(String... values) { super.onProgressUpdate(values); + prefs.edit().putBoolean("ignoreUpdateAlerts", false).apply(); Toast.makeText(activityContext, "Refreshing online modules", Toast.LENGTH_SHORT).show(); }