From 87568b6590a7fcb7ca69d8011ac64a6fb683626e Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Fri, 15 Jan 2021 06:45:07 +0530 Subject: [PATCH] Fix the crash that occurs on navigating back to the main fragment. --- .../newpipe/fragments/MainFragment.java | 5 --- .../schabi/newpipe/local/feed/FeedFragment.kt | 8 ++-- .../subscription/SubscriptionFragment.kt | 8 ++-- .../subscription/dialog/FeedGroupDialog.kt | 37 ++++++++++++------- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java index 9487fa385..4765e6265 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -117,11 +117,6 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte public void onDestroy() { super.onDestroy(); tabsManager.unsetSavedTabsListener(); - } - - @Override - public void onDestroyView() { - super.onDestroyView(); if (binding != null) { binding.pager.setAdapter(null); binding = null; diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt index f767f8f22..6df15c8b2 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt @@ -251,7 +251,7 @@ class FeedFragment : BaseListFragment() { } feedBinding.loadingProgressBar.isIndeterminate = isIndeterminate || - (progressState.maxProgress > 0 && progressState.currentProgress == 0) + (progressState.maxProgress > 0 && progressState.currentProgress == 0) feedBinding.loadingProgressBar.progress = progressState.currentProgress feedBinding.loadingProgressBar.max = progressState.maxProgress @@ -269,8 +269,10 @@ class FeedFragment : BaseListFragment() { val loadedCount = loadedState.notLoadedCount > 0 feedBinding.refreshSubtitleText.isVisible = loadedCount if (loadedCount) { - feedBinding.refreshSubtitleText.text = getString(R.string.feed_subscription_not_loaded_count, - loadedState.notLoadedCount) + feedBinding.refreshSubtitleText.text = getString( + R.string.feed_subscription_not_loaded_count, + loadedState.notLoadedCount + ) } if (loadedState.itemsErrors.isNotEmpty()) { diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt index c745ae39e..c4454186e 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt @@ -311,10 +311,10 @@ class SubscriptionFragment : BaseStateFragment() { dialogTitleBinding.itemAdditionalDetails.visibility = View.GONE AlertDialog.Builder(requireContext()) - .setCustomTitle(dialogTitleBinding.root) - .setItems(commands, actions) - .create() - .show() + .setCustomTitle(dialogTitleBinding.root) + .setItems(commands, actions) + .create() + .show() } private fun deleteChannel(selectedItem: ChannelInfoItem) { diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt index 8260f0fb9..7c7ebdea9 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt @@ -368,7 +368,8 @@ class FeedGroupDialog : DialogFragment(), BackPressable { val selectedCount = this.selectedSubscriptions.size val selectedCountText = resources.getQuantityString( R.plurals.feed_group_dialog_selection_count, - selectedCount, selectedCount) + selectedCount, selectedCount + ) feedGroupCreateBinding.selectedSubscriptionCountView.text = selectedCountText feedGroupCreateBinding.subscriptionsHeaderInfo.text = selectedCountText } @@ -423,10 +424,12 @@ class FeedGroupDialog : DialogFragment(), BackPressable { feedGroupCreateBinding.separator.onlyVisibleIn(SubscriptionsPickerScreen, IconPickerScreen) feedGroupCreateBinding.cancelButton.onlyVisibleIn(InitialScreen, DeleteScreen) - feedGroupCreateBinding.confirmButton.setText(when { - currentScreen == InitialScreen && groupId == NO_GROUP_SELECTED -> R.string.create - else -> android.R.string.ok - }) + feedGroupCreateBinding.confirmButton.setText( + when { + currentScreen == InitialScreen && groupId == NO_GROUP_SELECTED -> R.string.create + else -> android.R.string.ok + } + ) feedGroupCreateBinding.deleteButton.isGone = currentScreen != InitialScreen || groupId == NO_GROUP_SELECTED @@ -471,27 +474,35 @@ class FeedGroupDialog : DialogFragment(), BackPressable { private fun showKeyboardSearch() { if (searchLayoutBinding.toolbarSearchEditText.requestFocus()) { - inputMethodManager.showSoftInput(searchLayoutBinding.toolbarSearchEditText, - InputMethodManager.SHOW_IMPLICIT) + inputMethodManager.showSoftInput( + searchLayoutBinding.toolbarSearchEditText, + InputMethodManager.SHOW_IMPLICIT + ) } } private fun hideKeyboardSearch() { - inputMethodManager.hideSoftInputFromWindow(searchLayoutBinding.toolbarSearchEditText.windowToken, - InputMethodManager.RESULT_UNCHANGED_SHOWN) + inputMethodManager.hideSoftInputFromWindow( + searchLayoutBinding.toolbarSearchEditText.windowToken, + InputMethodManager.RESULT_UNCHANGED_SHOWN + ) searchLayoutBinding.toolbarSearchEditText.clearFocus() } private fun showKeyboard() { if (feedGroupCreateBinding.groupNameInput.requestFocus()) { - inputMethodManager.showSoftInput(feedGroupCreateBinding.groupNameInput, - InputMethodManager.SHOW_IMPLICIT) + inputMethodManager.showSoftInput( + feedGroupCreateBinding.groupNameInput, + InputMethodManager.SHOW_IMPLICIT + ) } } private fun hideKeyboard() { - inputMethodManager.hideSoftInputFromWindow(feedGroupCreateBinding.groupNameInput.windowToken, - InputMethodManager.RESULT_UNCHANGED_SHOWN) + inputMethodManager.hideSoftInputFromWindow( + feedGroupCreateBinding.groupNameInput.windowToken, + InputMethodManager.RESULT_UNCHANGED_SHOWN + ) feedGroupCreateBinding.groupNameInput.clearFocus() }