From 6a148b5dd95325e771b2715245027b020face3f2 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 27 Dec 2017 01:07:33 +0800 Subject: [PATCH] Add sorting repo by update time --- .../com/topjohnwu/magisk/MagiskManager.java | 24 ++++++ .../com/topjohnwu/magisk/ReposFragment.java | 19 +++++ .../com/topjohnwu/magisk/SplashActivity.java | 19 +---- .../magisk/adapters/ApplicationAdapter.java | 2 +- .../magisk/adapters/ReposAdapter.java | 2 + .../com/topjohnwu/magisk/container/Repo.java | 7 ++ .../magisk/database/RepoDatabaseHelper.java | 10 ++- .../com/topjohnwu/magisk/utils/Const.java | 3 + src/main/res/drawable/ic_sort.xml | 9 ++ src/main/res/layout/list_item_app.xml | 84 +++++++++---------- src/main/res/layout/list_item_policy.xml | 1 - src/main/res/layout/list_item_repo.xml | 9 ++ src/main/res/menu/menu_repo.xml | 6 ++ src/main/res/values/arrays.xml | 5 ++ src/main/res/values/strings.xml | 4 + src/main/res/values/styles.xml | 4 +- 16 files changed, 139 insertions(+), 69 deletions(-) create mode 100644 src/main/res/drawable/ic_sort.xml diff --git a/src/main/java/com/topjohnwu/magisk/MagiskManager.java b/src/main/java/com/topjohnwu/magisk/MagiskManager.java index d5e3ddcf8..d5a1df870 100644 --- a/src/main/java/com/topjohnwu/magisk/MagiskManager.java +++ b/src/main/java/com/topjohnwu/magisk/MagiskManager.java @@ -75,6 +75,7 @@ public class MagiskManager extends Application { public int updateChannel; public String bootFormat; public String customChannelUrl; + public int repoOrder; // Global resources public SharedPreferences prefs; @@ -145,6 +146,29 @@ public class MagiskManager extends Application { updateChannel = Utils.getPrefsInt(prefs, Const.Key.UPDATE_CHANNEL, Const.Value.STABLE_CHANNEL); bootFormat = prefs.getString(Const.Key.BOOT_FORMAT, ".img"); customChannelUrl = prefs.getString(Const.Key.CUSTOM_CHANNEL, ""); + repoOrder = prefs.getInt(Const.Key.REPO_ORDER, Const.Value.ORDER_NAME); + } + + public void writeConfig() { + prefs.edit() + .putBoolean(Const.Key.DARK_THEME, isDarkTheme) + .putBoolean(Const.Key.MAGISKHIDE, magiskHide) + .putBoolean(Const.Key.UPDATE_NOTIFICATION, updateNotification) + .putBoolean(Const.Key.HOSTS, Utils.itemExist(Const.MAGISK_HOST_FILE())) + .putBoolean(Const.Key.COREONLY, Utils.itemExist(Const.MAGISK_DISABLE_FILE)) + .putBoolean(Const.Key.SU_REAUTH, suReauth) + .putString(Const.Key.SU_REQUEST_TIMEOUT, String.valueOf(suRequestTimeout)) + .putString(Const.Key.SU_AUTO_RESPONSE, String.valueOf(suResponseType)) + .putString(Const.Key.SU_NOTIFICATION, String.valueOf(suNotificationType)) + .putString(Const.Key.ROOT_ACCESS, String.valueOf(suAccessState)) + .putString(Const.Key.SU_MULTIUSER_MODE, String.valueOf(multiuserMode)) + .putString(Const.Key.SU_MNT_NS, String.valueOf(suNamespaceMode)) + .putString(Const.Key.UPDATE_CHANNEL, String.valueOf(updateChannel)) + .putString(Const.Key.LOCALE, localeConfig) + .putString(Const.Key.BOOT_FORMAT, bootFormat) + .putInt(Const.Key.UPDATE_SERVICE_VER, Const.UPDATE_SERVICE_VER) + .putInt(Const.Key.REPO_ORDER, repoOrder) + .apply(); } public static void toast(String msg, int duration) { diff --git a/src/main/java/com/topjohnwu/magisk/ReposFragment.java b/src/main/java/com/topjohnwu/magisk/ReposFragment.java index b73fe4b15..0ea7b87a3 100644 --- a/src/main/java/com/topjohnwu/magisk/ReposFragment.java +++ b/src/main/java/com/topjohnwu/magisk/ReposFragment.java @@ -1,5 +1,6 @@ package com.topjohnwu.magisk; +import android.app.AlertDialog; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.widget.SwipeRefreshLayout; @@ -7,6 +8,7 @@ import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.SearchView; @@ -15,6 +17,7 @@ import android.widget.TextView; import com.topjohnwu.magisk.adapters.ReposAdapter; import com.topjohnwu.magisk.asyncs.UpdateRepos; import com.topjohnwu.magisk.components.Fragment; +import com.topjohnwu.magisk.utils.Const; import com.topjohnwu.magisk.utils.Topic; import butterknife.BindView; @@ -98,6 +101,22 @@ public class ReposFragment extends Fragment implements Topic.Subscriber { }); } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + MagiskManager mm = getApplication(); + if (item.getItemId() == R.id.repo_sort) { + new AlertDialog.Builder(getActivity()) + .setTitle(R.string.sorting_order) + .setSingleChoiceItems(R.array.sorting_orders, mm.repoOrder, (d, which) -> { + mm.repoOrder = which; + mm.prefs.edit().putInt(Const.Key.REPO_ORDER, mm.repoOrder).apply(); + adapter.notifyDBChanged(); + d.dismiss(); + }).show(); + } + return true; + } + @Override public void onDestroyView() { super.onDestroyView(); diff --git a/src/main/java/com/topjohnwu/magisk/SplashActivity.java b/src/main/java/com/topjohnwu/magisk/SplashActivity.java index 454625b27..20e90f5cb 100644 --- a/src/main/java/com/topjohnwu/magisk/SplashActivity.java +++ b/src/main/java/com/topjohnwu/magisk/SplashActivity.java @@ -79,24 +79,7 @@ public class SplashActivity extends Activity { } // Write back default values - mm.prefs.edit() - .putBoolean(Const.Key.DARK_THEME, mm.isDarkTheme) - .putBoolean(Const.Key.MAGISKHIDE, mm.magiskHide) - .putBoolean(Const.Key.UPDATE_NOTIFICATION, mm.updateNotification) - .putBoolean(Const.Key.HOSTS, Utils.itemExist(Const.MAGISK_HOST_FILE())) - .putBoolean(Const.Key.COREONLY, Utils.itemExist(Const.MAGISK_DISABLE_FILE)) - .putBoolean(Const.Key.SU_REAUTH, mm.suReauth) - .putString(Const.Key.SU_REQUEST_TIMEOUT, String.valueOf(mm.suRequestTimeout)) - .putString(Const.Key.SU_AUTO_RESPONSE, String.valueOf(mm.suResponseType)) - .putString(Const.Key.SU_NOTIFICATION, String.valueOf(mm.suNotificationType)) - .putString(Const.Key.ROOT_ACCESS, String.valueOf(mm.suAccessState)) - .putString(Const.Key.SU_MULTIUSER_MODE, String.valueOf(mm.multiuserMode)) - .putString(Const.Key.SU_MNT_NS, String.valueOf(mm.suNamespaceMode)) - .putString(Const.Key.UPDATE_CHANNEL, String.valueOf(mm.updateChannel)) - .putString(Const.Key.LOCALE, mm.localeConfig) - .putString(Const.Key.BOOT_FORMAT, mm.bootFormat) - .putInt(Const.Key.UPDATE_SERVICE_VER, Const.UPDATE_SERVICE_VER) - .apply(); + mm.writeConfig(); mm.hasInit = true; diff --git a/src/main/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java b/src/main/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java index 4a204d7bb..e3d375ca8 100644 --- a/src/main/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java +++ b/src/main/java/com/topjohnwu/magisk/adapters/ApplicationAdapter.java @@ -108,7 +108,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter new MarkDownWindow((Activity) context, null, repo.getDetailUrl()).exec()); @@ -180,6 +181,7 @@ public class ReposAdapter extends SectionedAdapter getRepoIDList() { diff --git a/src/main/java/com/topjohnwu/magisk/utils/Const.java b/src/main/java/com/topjohnwu/magisk/utils/Const.java index 79f6692f6..cfc52a8cd 100644 --- a/src/main/java/com/topjohnwu/magisk/utils/Const.java +++ b/src/main/java/com/topjohnwu/magisk/utils/Const.java @@ -133,6 +133,7 @@ public class Const { public static final String ETAG_KEY = "ETag"; public static final String LINK_KEY = "Link"; public static final String IF_NONE_MATCH = "If-None-Match"; + public static final String REPO_ORDER = "repo_order"; } @@ -162,5 +163,7 @@ public class Const { public static final String PATCH_BOOT = "patch"; public static final String FLASH_MAGISK = "magisk"; public static final int[] timeoutList = {0, -1, 10, 20, 30, 60}; + public static final int ORDER_NAME = 0; + public static final int ORDER_DATE = 1; } } diff --git a/src/main/res/drawable/ic_sort.xml b/src/main/res/drawable/ic_sort.xml new file mode 100644 index 000000000..0fd497923 --- /dev/null +++ b/src/main/res/drawable/ic_sort.xml @@ -0,0 +1,9 @@ + + + diff --git a/src/main/res/layout/list_item_app.xml b/src/main/res/layout/list_item_app.xml index fdf9403c7..5e3709e86 100644 --- a/src/main/res/layout/list_item_app.xml +++ b/src/main/res/layout/list_item_app.xml @@ -15,71 +15,63 @@ card_view:cardCornerRadius="@dimen/card_corner_radius" card_view:cardElevation="@dimen/card_elevation"> - + android:layout_height="wrap_content" + android:id="@+id/info_layout" + android:paddingStart="10dp" + android:paddingEnd="10dp" + android:paddingTop="5dp" + android:paddingBottom="5dp"> + android:layout_width="50dp" + android:layout_height="50dp" + android:layout_gravity="center_vertical" + android:gravity="end" /> - + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1" + android:layout_gravity="center_vertical" + android:layout_marginStart="5dp" + android:layout_marginEnd="5dp"> + android:ellipsize="end" + android:textAppearance="?android:attr/textAppearanceMedium" + android:textIsSelectable="false"/> + android:id="@+id/package_name" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:maxLines="1" + android:ellipsize="end" + android:textAppearance="?android:attr/textAppearanceSmall" + android:textColor="@android:color/tertiary_text_dark" + android:textIsSelectable="false" /> + - - - - - - - + android:focusable="false" + android:layout_gravity="center_vertical" + android:src="@drawable/ic_menu_overflow_material" + android:checked="false" /> + diff --git a/src/main/res/layout/list_item_policy.xml b/src/main/res/layout/list_item_policy.xml index e32ef2c96..6df19b83b 100644 --- a/src/main/res/layout/list_item_policy.xml +++ b/src/main/res/layout/list_item_policy.xml @@ -52,7 +52,6 @@ android:maxLines="1" android:ellipsize="end" android:textAppearance="?android:attr/textAppearanceMedium" - android:textColor="?android:attr/textColorPrimary" android:textIsSelectable="false"/> + + + + + \ No newline at end of file diff --git a/src/main/res/values/arrays.xml b/src/main/res/values/arrays.xml index 9fe7656cb..c89750d81 100644 --- a/src/main/res/values/arrays.xml +++ b/src/main/res/values/arrays.xml @@ -83,4 +83,9 @@ .img.tar + + @string/sort_by_name + @string/sort_by_update + + \ No newline at end of file diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 80b2913e9..8debb7fae 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -53,6 +53,10 @@ Update Available Installed Not Installed + Updated on: %1$s + Sorting Order + Sort by name + Sort by last update Save log diff --git a/src/main/res/values/styles.xml b/src/main/res/values/styles.xml index 241148e8e..9a577d0a9 100644 --- a/src/main/res/values/styles.xml +++ b/src/main/res/values/styles.xml @@ -12,7 +12,7 @@ false true @android:color/transparent - @android:color/background_dark + @android:color/secondary_text_light