From 2b6f2de1395a053bb49e711dc0c929f3c60acb09 Mon Sep 17 00:00:00 2001 From: mentalinc Date: Sat, 14 Oct 2023 06:22:15 +1300 Subject: [PATCH 1/6] Adding Back button preference This is to add a preference to restore the behaviour of the app before this commit: https://github.com/nextcloud/news-android/commit/28ea07e2c5251af6e336d29d5de31115eb0b3872 Signed-off-by: mentalinc --- .../NewsReaderListActivity.java | 17 ++++++++++++++++- .../owncloudnewsreader/SettingsActivity.java | 1 + .../owncloudnewsreader/SettingsFragment.java | 2 ++ .../src/main/res/values/strings.xml | 1 + .../src/main/res/xml/pref_general.xml | 6 ++++++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java index 8d3b49dd3..7fdb34d28 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java @@ -862,7 +862,22 @@ public boolean onMenuItemActionCollapse(MenuItem item) { @Override public void onBackPressed() { if (!handlePodcastBackPressed()) { - super.onBackPressed(); + + //Add in check for preference to determine if closes app or opens drawer + Boolean backAction = mPrefs.getBoolean(SettingsActivity.CB_PREF_BACK_OPENS_DRAWER,false); + //if (backAction) { //change this line to the preference test - or add into an AND in the below iff + if (backAction) { //change this line to the preference test - or add into an AND in the below iff + if (binding.drawerLayout != null) { + if (binding.drawerLayout.isDrawerOpen(GravityCompat.START)) + super.onBackPressed(); + else + binding.drawerLayout.openDrawer(GravityCompat.START); + } else { + super.onBackPressed(); + } + }else { + super.onBackPressed(); + } } } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/SettingsActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/SettingsActivity.java index 0664b66a5..6bb39072b 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/SettingsActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/SettingsActivity.java @@ -70,6 +70,7 @@ public class SettingsActivity extends AppCompatActivity { public static final String CB_MARK_AS_READ_WHILE_SCROLLING_STRING = "cb_MarkAsReadWhileScrolling"; public static final String CB_SHOW_FAST_ACTIONS = "cb_ShowFastActions"; + public static final String CB_PREF_BACK_OPENS_DRAWER = "cb_prefBackButtonOpensDrawer"; public static final String CB_DISABLE_HOSTNAME_VERIFICATION_STRING = "cb_DisableHostnameVerification"; public static final String CB_SKIP_DETAILVIEW_AND_OPEN_BROWSER_DIRECTLY_STRING = "cb_openInBrowserDirectly"; diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/SettingsFragment.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/SettingsFragment.java index fecc72c2f..3402a7e1a 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/SettingsFragment.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/SettingsFragment.java @@ -26,6 +26,7 @@ import static de.luhmer.owncloudnewsreader.SettingsActivity.SP_SWIPE_LEFT_ACTION; import static de.luhmer.owncloudnewsreader.SettingsActivity.SP_SWIPE_RIGHT_ACTION; import static de.luhmer.owncloudnewsreader.SettingsActivity.SYNC_INTERVAL_IN_MINUTES_STRING_DEPRECATED; +import static de.luhmer.owncloudnewsreader.SettingsActivity.CB_PREF_BACK_OPENS_DRAWER; import android.accounts.Account; import android.accounts.AccountManager; @@ -239,6 +240,7 @@ private void bindGeneralPreferences(DialogPreference.TargetFragment prefFrag) bindPreferenceBooleanToValue(prefFrag.findPreference(CB_MARK_AS_READ_WHILE_SCROLLING_STRING)); bindPreferenceBooleanToValue(prefFrag.findPreference(CB_SHOW_FAST_ACTIONS)); bindPreferenceBooleanToValue(prefFrag.findPreference(CB_SKIP_DETAILVIEW_AND_OPEN_BROWSER_DIRECTLY_STRING)); + bindPreferenceBooleanToValue(prefFrag.findPreference(CB_PREF_BACK_OPENS_DRAWER)); bindPreferenceSummaryToValue(prefFrag.findPreference(SP_SORT_ORDER)); bindPreferenceSummaryToValue(prefFrag.findPreference(SP_SEARCH_IN)); bindPreferenceSummaryToValue(prefFrag.findPreference(SP_SWIPE_RIGHT_ACTION)); diff --git a/News-Android-App/src/main/res/values/strings.xml b/News-Android-App/src/main/res/values/strings.xml index a768bac92..f180a0252 100644 --- a/News-Android-App/src/main/res/values/strings.xml +++ b/News-Android-App/src/main/res/values/strings.xml @@ -211,6 +211,7 @@ Mark as read while scrolling Activate fast access functions Skip detailed view and open article in the browser + Back button opens drawer Accept Unknown Certificate? diff --git a/News-Android-App/src/main/res/xml/pref_general.xml b/News-Android-App/src/main/res/xml/pref_general.xml index 68320503e..4721102f5 100644 --- a/News-Android-App/src/main/res/xml/pref_general.xml +++ b/News-Android-App/src/main/res/xml/pref_general.xml @@ -90,6 +90,12 @@ android:title="@string/pref_title_OpenInBrowserDirectly" app:iconSpaceReserved="false"/> + + + Date: Sun, 15 Oct 2023 19:54:14 +1300 Subject: [PATCH 2/6] Start migration to getOnBackPressedDispatcher and restore back button The back button now works as it prior to the change, there is a setting to configure if you want the back button to open the feeds list or to just exit (default) Signed-off-by: mentalinc --- .../NewsDetailActivity.java | 1 + .../NewsReaderListActivity.java | 45 ++++++++++++++++--- .../src/main/res/xml/pref_general.xml | 1 - 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java index 310b3023f..d07648a4e 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java @@ -427,6 +427,7 @@ public void updateActionBarIcons() { @Override public void onBackPressed() { + Log.v(TAG,"NewsDetailActivity onBackPressed() Called"); if (!handlePodcastBackPressed()) super.onBackPressed(); } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java index 7fdb34d28..959e4c863 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java @@ -48,6 +48,8 @@ import android.widget.SearchView; import android.widget.Toast; +import androidx.activity.OnBackPressedCallback; +import androidx.activity.OnBackPressedDispatcher; import androidx.annotation.NonNull; import androidx.annotation.VisibleForTesting; import androidx.appcompat.app.ActionBarDrawerToggle; @@ -209,6 +211,33 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + //trying to get back button working again + OnBackPressedDispatcher dispatcher = getOnBackPressedDispatcher(); + getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) { + @Override + public void handleOnBackPressed() { + Log.d(TAG, "NewsReaderListActivity handleOnBackPressed() called"); + if (!handlePodcastBackPressed()) { + + //Add in check for preference to determine if closes app or opens drawer + if (mPrefs.getBoolean(SettingsActivity.CB_PREF_BACK_OPENS_DRAWER, false)) { //change this line to the preference test - or add into an AND in the below iff + + if (binding.drawerLayout != null) { + if (binding.drawerLayout.isDrawerOpen(GravityCompat.START)) + setEnabled(false); + else + binding.drawerLayout.openDrawer(GravityCompat.START); + } else { + setEnabled(false); + } + } else { + setEnabled(false); + } + } + } + }); + binding = ActivityNewsreaderBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); @@ -859,28 +888,30 @@ public boolean onMenuItemActionCollapse(MenuItem item) { return true; } + // remove this method overide as no longer works when using the new android predictive back gestures + // cleanup once confirmed new approach is working as expected +/* @Override public void onBackPressed() { + Log.e(TAG,"NewsReaderListActivity onBackPressed() Called"); if (!handlePodcastBackPressed()) { //Add in check for preference to determine if closes app or opens drawer - Boolean backAction = mPrefs.getBoolean(SettingsActivity.CB_PREF_BACK_OPENS_DRAWER,false); - //if (backAction) { //change this line to the preference test - or add into an AND in the below iff - if (backAction) { //change this line to the preference test - or add into an AND in the below iff + if (mPrefs.getBoolean(SettingsActivity.CB_PREF_BACK_OPENS_DRAWER,false)) { //change this line to the preference test - or add into an AND in the below iff if (binding.drawerLayout != null) { if (binding.drawerLayout.isDrawerOpen(GravityCompat.START)) - super.onBackPressed(); - else + //super.onBackPressed(); + //else binding.drawerLayout.openDrawer(GravityCompat.START); } else { - super.onBackPressed(); + //super.onBackPressed(); } }else { super.onBackPressed(); } } } - +*/ public static final int RESULT_SETTINGS = 15642; private void syncMenuItemUnreadOnly() { diff --git a/News-Android-App/src/main/res/xml/pref_general.xml b/News-Android-App/src/main/res/xml/pref_general.xml index 4721102f5..0cb145f24 100644 --- a/News-Android-App/src/main/res/xml/pref_general.xml +++ b/News-Android-App/src/main/res/xml/pref_general.xml @@ -95,7 +95,6 @@ android:title="@string/pref_title_BackButtonOpensDrawer" app:iconSpaceReserved="false" /> - Date: Sat, 28 Oct 2023 11:26:38 +0200 Subject: [PATCH 3/6] refactor back-pressed logic Signed-off-by: David Luhmer --- .../NewsReaderListActivity.java | 227 +++++++++--------- 1 file changed, 110 insertions(+), 117 deletions(-) diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java index 959e4c863..f46d5365d 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java @@ -49,7 +49,6 @@ import android.widget.Toast; import androidx.activity.OnBackPressedCallback; -import androidx.activity.OnBackPressedDispatcher; import androidx.annotation.NonNull; import androidx.annotation.VisibleForTesting; import androidx.appcompat.app.ActionBarDrawerToggle; @@ -79,6 +78,7 @@ import com.nextcloud.android.sso.exceptions.TokenMismatchException; import com.nextcloud.android.sso.helper.SingleAccountHelper; import com.nextcloud.android.sso.ui.UiExceptionManager; +import com.sothree.slidinguppanel.SlidingUpPanelLayout; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; @@ -140,7 +140,7 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements public static final String ITEM_ID = "ITEM_ID"; public static final String TITLE = "TITLE"; - public static HashSet stayUnreadItems = new HashSet<>(); + public static HashSet stayUnreadItems = new HashSet<>(); private MenuItem menuItemOnlyUnread; private MenuItem menuItemDownloadMoreItems; @@ -149,6 +149,26 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements @VisibleForTesting(otherwise = PROTECTED) public ActivityNewsreaderBinding binding; + OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(true) { + // we need to handle two cases: + // - The user has the "Open Sidebar on Backpress" option enabled + // - the callback need to be set because we want to close the podcast pane on back navigation (in case it's open) + // - set callback will be enabled/disabled based on whether the podcast pane is open/closed + // - The user has the "Open Sidebar on Backpress" option disabled + // - the callback needs to check first if the podcast is open - if so - close it and on + // the next back navigation open the sidebar - and then close the app + // - once the podcast pane is open - the callback will be disabled + // - the event listener (onDrawerClosed) will enable the back pressed callback again + @Override + public void handleOnBackPressed() { + Log.d(TAG, "handleOnBackPressed() 1"); + if (!handlePodcastBackPressed()) { + Log.d(TAG, "handleOnBackPressed() 2"); + binding.drawerLayout.openDrawer(GravityCompat.START); + setEnabled(false); + } + } + }; //private ServiceConnection mConnection = null; @@ -197,6 +217,80 @@ public void onPostCreate(Bundle savedInstanceState) { private boolean isUserLoggedIn() { return (mPrefs.getString(SettingsActivity.EDT_OWNCLOUDROOTPATH_STRING, null) != null); } + private boolean mBackOpensDrawer = false; + + @Override + protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { + restoreInstanceState(savedInstanceState); + super.onRestoreInstanceState(savedInstanceState); + } + + @Override + protected void onSaveInstanceState(@NonNull Bundle outState) { + saveInstanceState(outState); + super.onSaveInstanceState(outState); + } + + private void saveInstanceState(Bundle outState) { + NewsReaderDetailFragment ndf = getNewsReaderDetailFragment(); + if (ndf != null) { + outState.putLong(OPTIONAL_FOLDER_ID, ndf.getIdFolder()); + outState.putBoolean(IS_FOLDER_BOOLEAN, ndf.getIdFeed() == null); + outState.putLong(ID_FEED_STRING, ndf.getIdFeed() != null ? ndf.getIdFeed() : ndf.getIdFolder()); + + NewsListRecyclerAdapter adapter = (NewsListRecyclerAdapter) ndf.getRecyclerView().getAdapter(); + if (adapter != null) { + outState.putInt(LIST_ADAPTER_TOTAL_COUNT, adapter.getTotalItemCount()); + outState.putInt(LIST_ADAPTER_PAGE_COUNT, adapter.getCachedPages()); + } + } + if (mSearchView != null) { + mSearchString = mSearchView.getQuery().toString(); + outState.putString(SEARCH_KEY, mSearchString); + } + } + + private void restoreInstanceState(Bundle savedInstanceState) { + if (savedInstanceState.containsKey(ID_FEED_STRING) && + savedInstanceState.containsKey(IS_FOLDER_BOOLEAN) && + savedInstanceState.containsKey(OPTIONAL_FOLDER_ID)) { + + NewsListRecyclerAdapter adapter = new NewsListRecyclerAdapter(this, getNewsReaderDetailFragment().binding.list, this, mPostDelayHandler, mPrefs); + + adapter.setTotalItemCount(savedInstanceState.getInt(LIST_ADAPTER_TOTAL_COUNT)); + adapter.setCachedPages(savedInstanceState.getInt(LIST_ADAPTER_PAGE_COUNT)); + + getNewsReaderDetailFragment() + .getRecyclerView() + .setAdapter(adapter); + + updateDetailFragment(savedInstanceState.getLong(ID_FEED_STRING), + savedInstanceState.getBoolean(IS_FOLDER_BOOLEAN), + savedInstanceState.getLong(OPTIONAL_FOLDER_ID), + false); + } + mSearchString = savedInstanceState.getString(SEARCH_KEY, null); + } + + @Override + public void onConfigurationChanged(@NonNull Configuration newConfig) { + super.onConfigurationChanged(newConfig); + if (drawerToggle != null) { + drawerToggle.onConfigurationChanged(newConfig); + } + } + SlidingUpPanelLayout.PanelSlideListener panelSlideListener = new SlidingUpPanelLayout.PanelSlideListener() { + @Override + public void onPanelSlide(View panel, float slideOffset) { + } + + @Override + public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) { + boolean panelIsOpen = newState.equals(SlidingUpPanelLayout.PanelState.EXPANDED); + // in case the podcast panel is open, we need to close it first (intercept back presses) + onBackPressedCallback.setEnabled(panelIsOpen || mBackOpensDrawer); + } + }; @Override protected void onCreate(Bundle savedInstanceState) { @@ -211,33 +305,6 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - - //trying to get back button working again - OnBackPressedDispatcher dispatcher = getOnBackPressedDispatcher(); - getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) { - @Override - public void handleOnBackPressed() { - Log.d(TAG, "NewsReaderListActivity handleOnBackPressed() called"); - if (!handlePodcastBackPressed()) { - - //Add in check for preference to determine if closes app or opens drawer - if (mPrefs.getBoolean(SettingsActivity.CB_PREF_BACK_OPENS_DRAWER, false)) { //change this line to the preference test - or add into an AND in the below iff - - if (binding.drawerLayout != null) { - if (binding.drawerLayout.isDrawerOpen(GravityCompat.START)) - setEnabled(false); - else - binding.drawerLayout.openDrawer(GravityCompat.START); - } else { - setEnabled(false); - } - } else { - setEnabled(false); - } - } - } - }); - binding = ActivityNewsreaderBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); @@ -272,6 +339,7 @@ public void handleOnBackPressed() { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); + onBackPressedCallback.setEnabled(mBackOpensDrawer); syncState(); } @@ -281,6 +349,9 @@ public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); reloadCountNumbersOfSlidingPaneAdapter(); + // -> handleOnBackPressed() will disable it + // onBackPressedCallback.setEnabled(false); + syncState(); } }; @@ -295,77 +366,19 @@ public void onDrawerOpened(View drawerView) { drawerToggle.syncState(); } + getPodcastSlidingUpPanelLayout().addPanelSlideListener(panelSlideListener); + getOnBackPressedDispatcher().addCallback(this, onBackPressedCallback); + //AppRater.app_launched(this); //AppRater.rateNow(this); - if (savedInstanceState == null) { //When the app starts (no orientation change) + if (savedInstanceState == null) { // When the app starts (no orientation change) updateDetailFragment(SubscriptionExpandableListAdapter.SPECIAL_FOLDERS.ALL_UNREAD_ITEMS.getValue(), true, null, true); } showChangelogIfNecessary(); } - @Override - protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { - restoreInstanceState(savedInstanceState); - super.onRestoreInstanceState(savedInstanceState); - } - - @Override - protected void onSaveInstanceState(@NonNull Bundle outState) { - saveInstanceState(outState); - super.onSaveInstanceState(outState); - } - - private void saveInstanceState(Bundle outState) { - NewsReaderDetailFragment ndf = getNewsReaderDetailFragment(); - if (ndf != null) { - outState.putLong(OPTIONAL_FOLDER_ID, ndf.getIdFolder()); - outState.putBoolean(IS_FOLDER_BOOLEAN, ndf.getIdFeed() == null); - outState.putLong(ID_FEED_STRING, ndf.getIdFeed() != null ? ndf.getIdFeed() : ndf.getIdFolder()); - - NewsListRecyclerAdapter adapter = (NewsListRecyclerAdapter) ndf.getRecyclerView().getAdapter(); - if (adapter != null) { - outState.putInt(LIST_ADAPTER_TOTAL_COUNT, adapter.getTotalItemCount()); - outState.putInt(LIST_ADAPTER_PAGE_COUNT, adapter.getCachedPages()); - } - } - if (mSearchView != null) { - mSearchString = mSearchView.getQuery().toString(); - outState.putString(SEARCH_KEY, mSearchString); - } - } - - private void restoreInstanceState(Bundle savedInstanceState) { - if (savedInstanceState.containsKey(ID_FEED_STRING) && - savedInstanceState.containsKey(IS_FOLDER_BOOLEAN) && - savedInstanceState.containsKey(OPTIONAL_FOLDER_ID)) { - - NewsListRecyclerAdapter adapter = new NewsListRecyclerAdapter(this, getNewsReaderDetailFragment().binding.list, this, mPostDelayHandler, mPrefs); - - adapter.setTotalItemCount(savedInstanceState.getInt(LIST_ADAPTER_TOTAL_COUNT)); - adapter.setCachedPages(savedInstanceState.getInt(LIST_ADAPTER_PAGE_COUNT)); - - getNewsReaderDetailFragment() - .getRecyclerView() - .setAdapter(adapter); - - updateDetailFragment(savedInstanceState.getLong(ID_FEED_STRING), - savedInstanceState.getBoolean(IS_FOLDER_BOOLEAN), - savedInstanceState.getLong(OPTIONAL_FOLDER_ID), - false); - } - mSearchString = savedInstanceState.getString(SEARCH_KEY, null); - } - - @Override - public void onConfigurationChanged(@NonNull Configuration newConfig) { - super.onConfigurationChanged(newConfig); - if (drawerToggle != null) { - drawerToggle.onConfigurationChanged(newConfig); - } - } - void showChangelogIfNecessary() { // on first app start with new version - always show the changelog int currentVersionCode = BuildConfig.VERSION_CODE; @@ -566,12 +579,16 @@ private boolean syncFinishedHandler() { @Override protected void onResume() { + mBackOpensDrawer = mPrefs.getBoolean(SettingsActivity.CB_PREF_BACK_OPENS_DRAWER, false); + onBackPressedCallback.setEnabled(mBackOpensDrawer); + NewsReaderListFragment newsReaderListFragment = getSlidingListFragment(); if (newsReaderListFragment != null) { - newsReaderListFragment.reloadAdapter(); + newsReaderListFragment.reloadAdapter(); newsReaderListFragment.bindUserInfoToUI(); } - invalidateOptionsMenu(); + + invalidateOptionsMenu(); super.onResume(); } @@ -888,30 +905,6 @@ public boolean onMenuItemActionCollapse(MenuItem item) { return true; } - // remove this method overide as no longer works when using the new android predictive back gestures - // cleanup once confirmed new approach is working as expected -/* - @Override - public void onBackPressed() { - Log.e(TAG,"NewsReaderListActivity onBackPressed() Called"); - if (!handlePodcastBackPressed()) { - - //Add in check for preference to determine if closes app or opens drawer - if (mPrefs.getBoolean(SettingsActivity.CB_PREF_BACK_OPENS_DRAWER,false)) { //change this line to the preference test - or add into an AND in the below iff - if (binding.drawerLayout != null) { - if (binding.drawerLayout.isDrawerOpen(GravityCompat.START)) - //super.onBackPressed(); - //else - binding.drawerLayout.openDrawer(GravityCompat.START); - } else { - //super.onBackPressed(); - } - }else { - super.onBackPressed(); - } - } - } -*/ public static final int RESULT_SETTINGS = 15642; private void syncMenuItemUnreadOnly() { From 238e1da14fbd8dc7bd8ec390d4b5b4797b702d02 Mon Sep 17 00:00:00 2001 From: David Luhmer Date: Sat, 28 Oct 2023 11:33:47 +0200 Subject: [PATCH 4/6] cleanup Signed-off-by: David Luhmer --- .../NewsDetailActivity.java | 1 - .../NewsReaderListActivity.java | 41 ++++++++++--------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java index d07648a4e..310b3023f 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java @@ -427,7 +427,6 @@ public void updateActionBarIcons() { @Override public void onBackPressed() { - Log.v(TAG,"NewsDetailActivity onBackPressed() Called"); if (!handlePodcastBackPressed()) super.onBackPressed(); } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java index f46d5365d..35cb98b67 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java @@ -149,26 +149,6 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements @VisibleForTesting(otherwise = PROTECTED) public ActivityNewsreaderBinding binding; - OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(true) { - // we need to handle two cases: - // - The user has the "Open Sidebar on Backpress" option enabled - // - the callback need to be set because we want to close the podcast pane on back navigation (in case it's open) - // - set callback will be enabled/disabled based on whether the podcast pane is open/closed - // - The user has the "Open Sidebar on Backpress" option disabled - // - the callback needs to check first if the podcast is open - if so - close it and on - // the next back navigation open the sidebar - and then close the app - // - once the podcast pane is open - the callback will be disabled - // - the event listener (onDrawerClosed) will enable the back pressed callback again - @Override - public void handleOnBackPressed() { - Log.d(TAG, "handleOnBackPressed() 1"); - if (!handlePodcastBackPressed()) { - Log.d(TAG, "handleOnBackPressed() 2"); - binding.drawerLayout.openDrawer(GravityCompat.START); - setEnabled(false); - } - } - }; //private ServiceConnection mConnection = null; @@ -292,6 +272,27 @@ public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState prev } }; + OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(true) { + // we need to handle two cases: + // - The user has the "Open Sidebar on Backpress" option enabled + // - the callback need to be set because we want to close the podcast pane on back navigation (in case it's open) + // - set callback will be enabled/disabled based on whether the podcast pane is open/closed + // - The user has the "Open Sidebar on Backpress" option disabled + // - the callback needs to check first if the podcast is open - if so - close it and on + // the next back navigation open the sidebar - and then close the app + // - once the podcast pane is open - the callback will be disabled + // - the event listener (onDrawerClosed) will enable the back pressed callback again + @Override + public void handleOnBackPressed() { + Log.d(TAG, "handleOnBackPressed() 1"); + if (!handlePodcastBackPressed()) { + Log.d(TAG, "handleOnBackPressed() 2"); + binding.drawerLayout.openDrawer(GravityCompat.START); + setEnabled(false); + } + } + }; + @Override protected void onCreate(Bundle savedInstanceState) { ((NewsReaderApplication) getApplication()).getAppComponent().injectActivity(this); From 17fcd832848d6678bc41c89f772077ef8182cc1e Mon Sep 17 00:00:00 2001 From: David Luhmer Date: Sat, 28 Oct 2023 11:34:42 +0200 Subject: [PATCH 5/6] cleanup Signed-off-by: David Luhmer --- .../de/luhmer/owncloudnewsreader/NewsReaderListActivity.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java index 35cb98b67..eb091be67 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java @@ -150,6 +150,8 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements @VisibleForTesting(otherwise = PROTECTED) public ActivityNewsreaderBinding binding; + private boolean mBackOpensDrawer = false; + //private ServiceConnection mConnection = null; private ActionBarDrawerToggle drawerToggle; @@ -197,7 +199,6 @@ public void onPostCreate(Bundle savedInstanceState) { private boolean isUserLoggedIn() { return (mPrefs.getString(SettingsActivity.EDT_OWNCLOUDROOTPATH_STRING, null) != null); } - private boolean mBackOpensDrawer = false; @Override protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { From b84318bd6c267793011a5d3b0187b09968967797 Mon Sep 17 00:00:00 2001 From: David Luhmer Date: Sat, 28 Oct 2023 11:36:07 +0200 Subject: [PATCH 6/6] move code around Signed-off-by: David Luhmer --- .../NewsReaderListActivity.java | 121 +++++++++--------- 1 file changed, 61 insertions(+), 60 deletions(-) diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java index eb091be67..320a91de8 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java @@ -200,66 +200,6 @@ private boolean isUserLoggedIn() { return (mPrefs.getString(SettingsActivity.EDT_OWNCLOUDROOTPATH_STRING, null) != null); } - @Override - protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { - restoreInstanceState(savedInstanceState); - super.onRestoreInstanceState(savedInstanceState); - } - - @Override - protected void onSaveInstanceState(@NonNull Bundle outState) { - saveInstanceState(outState); - super.onSaveInstanceState(outState); - } - - private void saveInstanceState(Bundle outState) { - NewsReaderDetailFragment ndf = getNewsReaderDetailFragment(); - if (ndf != null) { - outState.putLong(OPTIONAL_FOLDER_ID, ndf.getIdFolder()); - outState.putBoolean(IS_FOLDER_BOOLEAN, ndf.getIdFeed() == null); - outState.putLong(ID_FEED_STRING, ndf.getIdFeed() != null ? ndf.getIdFeed() : ndf.getIdFolder()); - - NewsListRecyclerAdapter adapter = (NewsListRecyclerAdapter) ndf.getRecyclerView().getAdapter(); - if (adapter != null) { - outState.putInt(LIST_ADAPTER_TOTAL_COUNT, adapter.getTotalItemCount()); - outState.putInt(LIST_ADAPTER_PAGE_COUNT, adapter.getCachedPages()); - } - } - if (mSearchView != null) { - mSearchString = mSearchView.getQuery().toString(); - outState.putString(SEARCH_KEY, mSearchString); - } - } - - private void restoreInstanceState(Bundle savedInstanceState) { - if (savedInstanceState.containsKey(ID_FEED_STRING) && - savedInstanceState.containsKey(IS_FOLDER_BOOLEAN) && - savedInstanceState.containsKey(OPTIONAL_FOLDER_ID)) { - - NewsListRecyclerAdapter adapter = new NewsListRecyclerAdapter(this, getNewsReaderDetailFragment().binding.list, this, mPostDelayHandler, mPrefs); - - adapter.setTotalItemCount(savedInstanceState.getInt(LIST_ADAPTER_TOTAL_COUNT)); - adapter.setCachedPages(savedInstanceState.getInt(LIST_ADAPTER_PAGE_COUNT)); - - getNewsReaderDetailFragment() - .getRecyclerView() - .setAdapter(adapter); - - updateDetailFragment(savedInstanceState.getLong(ID_FEED_STRING), - savedInstanceState.getBoolean(IS_FOLDER_BOOLEAN), - savedInstanceState.getLong(OPTIONAL_FOLDER_ID), - false); - } - mSearchString = savedInstanceState.getString(SEARCH_KEY, null); - } - - @Override - public void onConfigurationChanged(@NonNull Configuration newConfig) { - super.onConfigurationChanged(newConfig); - if (drawerToggle != null) { - drawerToggle.onConfigurationChanged(newConfig); - } - } SlidingUpPanelLayout.PanelSlideListener panelSlideListener = new SlidingUpPanelLayout.PanelSlideListener() { @Override public void onPanelSlide(View panel, float slideOffset) { @@ -381,6 +321,67 @@ public void onDrawerOpened(View drawerView) { showChangelogIfNecessary(); } + @Override + protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { + restoreInstanceState(savedInstanceState); + super.onRestoreInstanceState(savedInstanceState); + } + + @Override + protected void onSaveInstanceState(@NonNull Bundle outState) { + saveInstanceState(outState); + super.onSaveInstanceState(outState); + } + + private void saveInstanceState(Bundle outState) { + NewsReaderDetailFragment ndf = getNewsReaderDetailFragment(); + if (ndf != null) { + outState.putLong(OPTIONAL_FOLDER_ID, ndf.getIdFolder()); + outState.putBoolean(IS_FOLDER_BOOLEAN, ndf.getIdFeed() == null); + outState.putLong(ID_FEED_STRING, ndf.getIdFeed() != null ? ndf.getIdFeed() : ndf.getIdFolder()); + + NewsListRecyclerAdapter adapter = (NewsListRecyclerAdapter) ndf.getRecyclerView().getAdapter(); + if (adapter != null) { + outState.putInt(LIST_ADAPTER_TOTAL_COUNT, adapter.getTotalItemCount()); + outState.putInt(LIST_ADAPTER_PAGE_COUNT, adapter.getCachedPages()); + } + } + if (mSearchView != null) { + mSearchString = mSearchView.getQuery().toString(); + outState.putString(SEARCH_KEY, mSearchString); + } + } + + private void restoreInstanceState(Bundle savedInstanceState) { + if (savedInstanceState.containsKey(ID_FEED_STRING) && + savedInstanceState.containsKey(IS_FOLDER_BOOLEAN) && + savedInstanceState.containsKey(OPTIONAL_FOLDER_ID)) { + + NewsListRecyclerAdapter adapter = new NewsListRecyclerAdapter(this, getNewsReaderDetailFragment().binding.list, this, mPostDelayHandler, mPrefs); + + adapter.setTotalItemCount(savedInstanceState.getInt(LIST_ADAPTER_TOTAL_COUNT)); + adapter.setCachedPages(savedInstanceState.getInt(LIST_ADAPTER_PAGE_COUNT)); + + getNewsReaderDetailFragment() + .getRecyclerView() + .setAdapter(adapter); + + updateDetailFragment(savedInstanceState.getLong(ID_FEED_STRING), + savedInstanceState.getBoolean(IS_FOLDER_BOOLEAN), + savedInstanceState.getLong(OPTIONAL_FOLDER_ID), + false); + } + mSearchString = savedInstanceState.getString(SEARCH_KEY, null); + } + + @Override + public void onConfigurationChanged(@NonNull Configuration newConfig) { + super.onConfigurationChanged(newConfig); + if (drawerToggle != null) { + drawerToggle.onConfigurationChanged(newConfig); + } + } + void showChangelogIfNecessary() { // on first app start with new version - always show the changelog int currentVersionCode = BuildConfig.VERSION_CODE;