From 7abab1ba261e1fa1381d93417dc0957133b69559 Mon Sep 17 00:00:00 2001 From: HeinrichWesson Date: Fri, 30 Oct 2020 09:42:29 +0200 Subject: [PATCH 01/18] CHANGE Remove language action icon from toolbar and add a language change bar to the App Bar. --- .../listbooks/ListBooksContract.java | 2 + .../listbooks/ListBooksFragment.java | 24 +++++++-- .../listbooks/ListBooksPresenter.java | 9 ++-- .../res/drawable-v21/language_selector.xml | 12 +++++ .../main/res/drawable/ic_arrow_down_24.xml | 9 ++++ .../res/drawable/ic_public_black_24dp.xml | 9 ---- .../main/res/drawable/language_selector.xml | 6 +++ .../main/res/layout/fragment_list_books.xml | 51 ++++++++++++------- app/src/main/res/layout/list_item_book.xml | 2 +- app/src/main/res/menu/menu_main.xml | 16 ++---- app/src/main/res/values/strings.xml | 1 + 11 files changed, 95 insertions(+), 46 deletions(-) create mode 100644 app/src/main/res/drawable-v21/language_selector.xml create mode 100644 app/src/main/res/drawable/ic_arrow_down_24.xml delete mode 100644 app/src/main/res/drawable/ic_public_black_24dp.xml create mode 100644 app/src/main/res/drawable/language_selector.xml diff --git a/app/src/main/java/org/bookdash/android/presentation/listbooks/ListBooksContract.java b/app/src/main/java/org/bookdash/android/presentation/listbooks/ListBooksContract.java index e1738f9f..063eb093 100644 --- a/app/src/main/java/org/bookdash/android/presentation/listbooks/ListBooksContract.java +++ b/app/src/main/java/org/bookdash/android/presentation/listbooks/ListBooksContract.java @@ -24,6 +24,8 @@ interface View extends MvpView { void showLanguagePopover(String[] languages, int selected); void startSearchActivity(); + + void onSelectedLanguageChanged(String selectedLanguage); } interface Presenter extends MvpPresenter{ diff --git a/app/src/main/java/org/bookdash/android/presentation/listbooks/ListBooksFragment.java b/app/src/main/java/org/bookdash/android/presentation/listbooks/ListBooksFragment.java index 4d4ed375..35d8f603 100644 --- a/app/src/main/java/org/bookdash/android/presentation/listbooks/ListBooksFragment.java +++ b/app/src/main/java/org/bookdash/android/presentation/listbooks/ListBooksFragment.java @@ -51,6 +51,8 @@ public class ListBooksFragment extends Fragment implements ListBooksContract.Vie private CircularProgressBar circularProgressBar; private LinearLayout linearLayoutErrorScreen; private TextView textViewErrorMessage; + private LinearLayout linearLayoutContainerLanguage; + private TextView textViewCurrentLanguage; private NavDrawerInterface navDrawerInterface; private BookAdapter bookAdapter; private View.OnClickListener bookClickListener = new View.OnClickListener() { @@ -117,6 +119,8 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { linearLayoutErrorScreen = view.findViewById(R.id.linear_layout_error); buttonRetry = view.findViewById(R.id.button_retry); textViewErrorMessage = view.findViewById(R.id.text_view_error_screen); + linearLayoutContainerLanguage = view.findViewById(R.id.container_language); + textViewCurrentLanguage = view.findViewById(R.id.text_current_language); recyclerViewBooks = view.findViewById(R.id.recycler_view_books); recyclerViewBooks.setLayoutManager( new GridLayoutManager(getActivity(), getContext().getResources().getInteger(R.integer.book_span))); @@ -127,6 +131,12 @@ public void onClick(View v) { listBooksPresenter.loadBooksForLanguagePreference(); } }); + linearLayoutContainerLanguage.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + listBooksPresenter.clickOpenLanguagePopover(); + } + }); Toolbar toolbar = view.findViewById(R.id.toolbar); if (navDrawerInterface != null) { navDrawerInterface.setToolbar(toolbar); @@ -164,10 +174,6 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { @Override public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == R.id.action_language_choice) { - listBooksPresenter.clickOpenLanguagePopover(); - return true; - } if (item.getItemId() == R.id.action_search_books) { listBooksPresenter.openSearchScreen(); return true; @@ -275,5 +281,13 @@ public void startSearchActivity() { SearchActivity.start(getActivity()); } - + @Override + public void onSelectedLanguageChanged(final String selectedLanguage) { + runUiThread(new Runnable() { + @Override + public void run() { + textViewCurrentLanguage.setText(selectedLanguage); + } + }); + } } diff --git a/app/src/main/java/org/bookdash/android/presentation/listbooks/ListBooksPresenter.java b/app/src/main/java/org/bookdash/android/presentation/listbooks/ListBooksPresenter.java index 028ab358..ac52bf95 100644 --- a/app/src/main/java/org/bookdash/android/presentation/listbooks/ListBooksPresenter.java +++ b/app/src/main/java/org/bookdash/android/presentation/listbooks/ListBooksPresenter.java @@ -78,11 +78,12 @@ public void onError(final Throwable e) { @Override public void onNext(final Boolean aBoolean) { - analytics.trackLanguageChange(languages.get(indexOfLanguage).getLanguageName()); - loadBooksForLanguage(languages.get(indexOfLanguage)); + FireLanguage selectedLanguage = languages.get(indexOfLanguage); + analytics.trackLanguageChange(selectedLanguage.getLanguageName()); + getView().onSelectedLanguageChanged(selectedLanguage.getLanguageName()); + loadBooksForLanguage(selectedLanguage); } })); - } @Override @@ -104,6 +105,7 @@ public void onError(final Throwable e) { @Override public void onNext(final FireLanguage fireLanguage) { analytics.setUserLanguage(fireLanguage.getLanguageName()); + getView().onSelectedLanguageChanged(fireLanguage.getLanguageName()); loadBooksForLanguage(fireLanguage); } })); @@ -113,6 +115,7 @@ public void onNext(final FireLanguage fireLanguage) { @Override public void clickOpenLanguagePopover() { if (languages == null) { + getView().showSnackBarError(R.string.error_loading_languages_try_again); return; } addSubscription(settingsRepository.getLanguagePreference().observeOn(ioScheduler).subscribeOn(mainScheduler) diff --git a/app/src/main/res/drawable-v21/language_selector.xml b/app/src/main/res/drawable-v21/language_selector.xml new file mode 100644 index 00000000..e798f1e6 --- /dev/null +++ b/app/src/main/res/drawable-v21/language_selector.xml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_arrow_down_24.xml b/app/src/main/res/drawable/ic_arrow_down_24.xml new file mode 100644 index 00000000..fba0a470 --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_down_24.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_public_black_24dp.xml b/app/src/main/res/drawable/ic_public_black_24dp.xml deleted file mode 100644 index 60e024f5..00000000 --- a/app/src/main/res/drawable/ic_public_black_24dp.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/language_selector.xml b/app/src/main/res/drawable/language_selector.xml new file mode 100644 index 00000000..c127c330 --- /dev/null +++ b/app/src/main/res/drawable/language_selector.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_list_books.xml b/app/src/main/res/layout/fragment_list_books.xml index 3b029089..c6e21037 100644 --- a/app/src/main/res/layout/fragment_list_books.xml +++ b/app/src/main/res/layout/fragment_list_books.xml @@ -1,5 +1,4 @@ - + android:src="@drawable/appbackground" /> - + app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> + + + + + app:cpb_sweep_speed="1.0" /> @@ -69,7 +88,7 @@ android:layout_width="150dp" android:layout_height="150dp" android:layout_gravity="center_horizontal" - android:src="@drawable/lb_ic_sad_cloud"/> + android:src="@drawable/lb_ic_sad_cloud" /> + android:text="@string/error_loading_books" />