Merge pull request #1712 from yashk2000/patch-2

#1058 Revamp the menu of the History Activity
This commit is contained in:
Seán Mac Gillicuddy 2020-01-30 16:37:06 +00:00 committed by GitHub
commit 51e90dd9c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 34 deletions

View File

@ -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();

View File

@ -1,11 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<include layout="@layout/layout_standard_app_bar" />
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:background="@color/black"
tools:showIn="@layout/activity_help">
<include layout="@layout/layout_toolbar" />
<Switch
android:id="@+id/history_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
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" />
</com.google.android.material.appbar.AppBarLayout>
<TextView
android:id="@+id/no_history"

View File

@ -12,14 +12,9 @@
app:showAsAction="always|collapseActionView"
tools:ignore="AlwaysShowAction" />
<item
android:id="@+id/menu_history_toggle"
android:checkable="true"
android:title="@string/history_from_current_book"
app:showAsAction="never" />
<item
android:id="@+id/menu_history_clear"
android:icon="@drawable/ic_delete_white_24dp"
android:title="@string/pref_clear_all_history_title"
app:showAsAction="never" />
app:showAsAction="ifRoom" />
</menu>

View File

@ -5,6 +5,8 @@
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="dimen_small_padding">4dp</dimen>
<dimen name="dimen_medium_padding">8dp</dimen>
<dimen name="switch_padding_bottom">6dp</dimen>
<dimen name="switch_padding">15dp</dimen>
<dimen name="abc_dropdownitem_text_padding_left">8dip</dimen>
<dimen name="abc_dropdownitem_text_padding_right">8dip</dimen>
<dimen name="kiwix_search_widget_layout_id_height">50dp</dimen>

View File

@ -202,7 +202,7 @@
<string name="send_feedback">Send feedback</string>
<string name="expand">Expand</string>
<string name="history">History</string>
<string name="history_from_current_book">History from current book</string>
<string name="history_from_current_book">View History From All Books</string>
<string name="search_history">Search history</string>
<string name="selected_items">%1$d selected</string>
<string-array name="description_help_2">