From 98f21c908270ca64440aec273cedc17c84d21483 Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Wed, 29 Jan 2020 18:25:22 +0530 Subject: [PATCH 1/7] #1058 Revamp the menu of the History Activity --- .../core/history/HistoryActivity.java | 59 +++++++++++-------- core/src/main/res/layout/activity_history.xml | 18 +++++- core/src/main/res/menu/menu_history.xml | 6 -- core/src/main/res/values/dimens.xml | 1 + core/src/main/res/values/strings.xml | 2 +- 5 files changed, 53 insertions(+), 33 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/history/HistoryActivity.java b/core/src/main/java/org/kiwix/kiwixmobile/core/history/HistoryActivity.java index 65e050245..8fa97c8c9 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/history/HistoryActivity.java +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/history/HistoryActivity.java @@ -26,7 +26,9 @@ import android.provider.Settings; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.widget.CompoundButton; import android.widget.ImageView; +import android.widget.Switch; import android.widget.TextView; import android.widget.Toast; import androidx.appcompat.app.ActionBar; @@ -74,6 +76,8 @@ public class HistoryActivity extends BaseActivity implements HistoryContract.Vie RecyclerView recyclerView; @BindView(R2.id.no_history) TextView noHistory; + @BindView(R2.id.history_switch) + Switch historySwitch; private boolean refreshAdapter = true; private HistoryAdapter historyAdapter; private LinearLayoutManager layoutManager; @@ -148,6 +152,15 @@ public class HistoryActivity extends BaseActivity implements HistoryContract.Vie recyclerView.setAdapter(historyAdapter); layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager(); recyclerView.setLayoutManager(layoutManager); + + historySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + sharedPreferenceUtil.setShowHistoryCurrentBook(!isChecked); + presenter.loadHistory(sharedPreferenceUtil.getShowHistoryCurrentBook()); + } + }); + + historySwitch.setChecked(!sharedPreferenceUtil.getShowHistoryCurrentBook()); } private void setupHistoryAdapter() { @@ -186,30 +199,31 @@ public class HistoryActivity extends BaseActivity implements HistoryContract.Vie @Override public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.menu_history, menu); - MenuItem toggle = menu.findItem(R.id.menu_history_toggle); - toggle.setChecked(sharedPreferenceUtil.getShowHistoryCurrentBook()); - SearchView search = (SearchView) menu.findItem(R.id.menu_history_search).getActionView(); - search.setQueryHint(getString(R.string.search_history)); - search.setOnQueryTextListener(new SearchView.OnQueryTextListener() { - @Override - public boolean onQueryTextSubmit(String query) { - return false; - } + if (!historyList.isEmpty()) { + getMenuInflater().inflate(R.menu.menu_history, menu); - @Override - public boolean onQueryTextChange(String newText) { - historyList.clear(); - historyList.addAll(fullHistory); - if ("".equals(newText)) { - historyAdapter.notifyDataSetChanged(); + SearchView search = (SearchView) menu.findItem(R.id.menu_history_search).getActionView(); + search.setQueryHint(getString(R.string.search_history)); + search.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + @Override + public boolean onQueryTextSubmit(String query) { + return false; + } + + @Override + public boolean onQueryTextChange(String newText) { + historyList.clear(); + historyList.addAll(fullHistory); + if ("".equals(newText)) { + historyAdapter.notifyDataSetChanged(); + return true; + } + presenter.filterHistory(historyList, newText); return true; } - presenter.filterHistory(historyList, newText); - return true; - } - }); + }); + } return true; } @@ -219,11 +233,6 @@ public class HistoryActivity extends BaseActivity implements HistoryContract.Vie if (itemId == android.R.id.home) { onBackPressed(); return true; - } else if (itemId == R.id.menu_history_toggle) { - item.setChecked(!item.isChecked()); - sharedPreferenceUtil.setShowHistoryCurrentBook(item.isChecked()); - presenter.loadHistory(sharedPreferenceUtil.getShowHistoryCurrentBook()); - return true; } else if (itemId == R.id.menu_history_clear) { presenter.deleteHistory(new ArrayList<>(fullHistory)); fullHistory.clear(); diff --git a/core/src/main/res/layout/activity_history.xml b/core/src/main/res/layout/activity_history.xml index 2014327f1..a20e95466 100644 --- a/core/src/main/res/layout/activity_history.xml +++ b/core/src/main/res/layout/activity_history.xml @@ -5,7 +5,23 @@ android:layout_height="match_parent" android:fitsSystemWindows="true"> - + + + + + + + - - 16dp 4dp 8dp + 15dp 8dip 8dip 50dp diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index da4cc7881..6078ac834 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -202,7 +202,7 @@ Send feedback Expand History - History from current book + View History From All Books Search history %1$d selected From 95a999ea790eb49d47e32d55ef0a9db6182af4df Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Wed, 29 Jan 2020 21:31:36 +0530 Subject: [PATCH 2/7] #1058 Revamp the menu of the History Activity --- core/src/main/res/layout/activity_history.xml | 3 +++ core/src/main/res/values/dimens.xml | 1 + 2 files changed, 4 insertions(+) diff --git a/core/src/main/res/layout/activity_history.xml b/core/src/main/res/layout/activity_history.xml index a20e95466..2032ee07c 100644 --- a/core/src/main/res/layout/activity_history.xml +++ b/core/src/main/res/layout/activity_history.xml @@ -10,6 +10,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_constraintTop_toTopOf="parent" + android:background="@color/black" tools:showIn="@layout/activity_help"> @@ -19,6 +20,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/history_from_current_book" + android:paddingStart="@dimen/switch_text_padding" + android:textColor="@android:color/white" android:switchPadding="@dimen/switch_padding"/> diff --git a/core/src/main/res/values/dimens.xml b/core/src/main/res/values/dimens.xml index 4e3abd9ab..a74d5dd13 100644 --- a/core/src/main/res/values/dimens.xml +++ b/core/src/main/res/values/dimens.xml @@ -6,6 +6,7 @@ 4dp 8dp 15dp + 20dp 8dip 8dip 50dp From 766bfb6d4d18ded35097cbec659d10424b172716 Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Thu, 30 Jan 2020 21:14:13 +0530 Subject: [PATCH 3/7] #1058 Revamp the menu of the History Activity --- core/src/main/res/layout/activity_history.xml | 10 ++++++---- core/src/main/res/values/dimens.xml | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/src/main/res/layout/activity_history.xml b/core/src/main/res/layout/activity_history.xml index 2032ee07c..a60822137 100644 --- a/core/src/main/res/layout/activity_history.xml +++ b/core/src/main/res/layout/activity_history.xml @@ -1,11 +1,12 @@ - + app:theme="@style/ThemeOverlay.MaterialComponents.Dark" /> diff --git a/core/src/main/res/values/dimens.xml b/core/src/main/res/values/dimens.xml index a74d5dd13..041123492 100644 --- a/core/src/main/res/values/dimens.xml +++ b/core/src/main/res/values/dimens.xml @@ -5,6 +5,7 @@ 16dp 4dp 8dp + 10dp 15dp 20dp 8dip From 6e1eca5d9d51584a408823872a1f39449dc909cf Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Thu, 30 Jan 2020 21:17:13 +0530 Subject: [PATCH 4/7] #1058 Revamp the menu of the History Activity --- core/src/main/res/values/dimens.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/res/values/dimens.xml b/core/src/main/res/values/dimens.xml index 041123492..b2b55684a 100644 --- a/core/src/main/res/values/dimens.xml +++ b/core/src/main/res/values/dimens.xml @@ -5,7 +5,7 @@ 16dp 4dp 8dp - 10dp + 6dp 15dp 20dp 8dip From 79bfcd4338e56e4cb60662b2b0f8bfc975e71602 Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Thu, 30 Jan 2020 21:23:28 +0530 Subject: [PATCH 5/7] #1058 Revamp the menu of the History Activity --- core/src/main/res/layout/activity_history.xml | 6 +++--- core/src/main/res/values/dimens.xml | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/core/src/main/res/layout/activity_history.xml b/core/src/main/res/layout/activity_history.xml index a60822137..ef31f1b7d 100644 --- a/core/src/main/res/layout/activity_history.xml +++ b/core/src/main/res/layout/activity_history.xml @@ -18,12 +18,12 @@ diff --git a/core/src/main/res/values/dimens.xml b/core/src/main/res/values/dimens.xml index b2b55684a..25ac86021 100644 --- a/core/src/main/res/values/dimens.xml +++ b/core/src/main/res/values/dimens.xml @@ -7,7 +7,6 @@ 8dp 6dp 15dp - 20dp 8dip 8dip 50dp From 0eed7233de30d8dc160c7bc324469a78f192d068 Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Thu, 30 Jan 2020 21:39:41 +0530 Subject: [PATCH 6/7] #1058 Revamp the menu of the History Activity --- core/src/main/res/layout/activity_history.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/res/layout/activity_history.xml b/core/src/main/res/layout/activity_history.xml index ef31f1b7d..1b15679cb 100644 --- a/core/src/main/res/layout/activity_history.xml +++ b/core/src/main/res/layout/activity_history.xml @@ -24,6 +24,7 @@ android:paddingBottom="@dimen/switch_padding_bottom" android:switchPadding="@dimen/switch_padding" android:text="@string/history_from_current_book" + android:textAppearance="@style/TextAppearance.KiwixTheme.Body2" app:theme="@style/ThemeOverlay.MaterialComponents.Dark" /> From 084835ed5e0bce2e9d5b17dd476da4501642d6ae Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Thu, 30 Jan 2020 21:50:05 +0530 Subject: [PATCH 7/7] #1058 Revamp the menu of the History Activity --- core/src/main/res/menu/menu_history.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/res/menu/menu_history.xml b/core/src/main/res/menu/menu_history.xml index b79733794..dc1705554 100644 --- a/core/src/main/res/menu/menu_history.xml +++ b/core/src/main/res/menu/menu_history.xml @@ -14,6 +14,7 @@ + app:showAsAction="ifRoom" />