From b60b3dc3e27bbc63435d40161a79f18586d8b297 Mon Sep 17 00:00:00 2001 From: neslihanturan Date: Tue, 26 Jan 2021 18:04:10 +0300 Subject: [PATCH] Cherrypick for hotfix3.1 (#4205) * Fixes #4159 On Explore Tab, All Available Options on toolbar in media detail view are only targeting the first media in the list. Fixes #4159 On Explore Tab, All Available Options on toolbar in media detail view are only targeting the first media in the list. * fixed bug: App crashes on viewing review in Review Fragment #4132 (#4146) * fixed bug:app crashes on viewing review in Review Fragment #4135 * Fixed the issue with back button in contribution tab. (#4177) Co-authored-by: Pratham2305 * Fixed the issue with back navigation button on toolbar in explore tab. (#4175) * Fix (#4148) Issues on theme change * fixed themeChange crashes * fixed comments * Overlooked the title bar Co-authored-by: Pratham Pahariya <54663429+Pratham2305@users.noreply.github.com> Co-authored-by: Shabir Ahmad <56585337+shabar-shab@users.noreply.github.com> Co-authored-by: Pratham2305 Co-authored-by: Aditya-Srivastav <54016427+4D17Y4@users.noreply.github.com> --- .../bookmarks/BookmarkListRootFragment.java | 8 +++- .../contributions/ContributionsFragment.java | 46 +++++++++++++++---- .../commons/contributions/MainActivity.java | 22 ++++++--- .../explore/ExploreListRootFragment.java | 11 ++++- .../commons/review/ReviewImageFragment.java | 2 +- 5 files changed, 70 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/bookmarks/BookmarkListRootFragment.java b/app/src/main/java/fr/free/nrw/commons/bookmarks/BookmarkListRootFragment.java index fc4a26aa6..3ee03218a 100644 --- a/app/src/main/java/fr/free/nrw/commons/bookmarks/BookmarkListRootFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/bookmarks/BookmarkListRootFragment.java @@ -38,6 +38,10 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple @BindView(R.id.explore_container) FrameLayout container; + public BookmarkListRootFragment(){ + //empty constructor necessary otherwise crashes on recreate + } + public BookmarkListRootFragment(Bundle bundle, BookmarksPagerAdapter bookmarksPagerAdapter) { String title = bundle.getString("categoryName"); int order = bundle.getInt("order"); @@ -65,7 +69,9 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple @Override public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - setFragment(listFragment, mediaDetails); + if(savedInstanceState==null) { + setFragment(listFragment, mediaDetails); + } } public void setFragment(Fragment fragment, Fragment otherFragment) { diff --git a/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java b/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java index 3e248e93c..144724a99 100644 --- a/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/contributions/ContributionsFragment.java @@ -286,13 +286,13 @@ public class ContributionsFragment nearbyNotificationCardView.setVisibility(View.GONE); } } - showFragment(contributionsListFragment, CONTRIBUTION_LIST_FRAGMENT_TAG); + showFragment(contributionsListFragment, CONTRIBUTION_LIST_FRAGMENT_TAG, mediaDetailPagerFragment); } private void showMediaDetailPagerFragment() { // hide nearby card view on media detail is visible setupViewForMediaDetails(); - showFragment(mediaDetailPagerFragment, MEDIA_DETAIL_PAGER_FRAGMENT_TAG); + showFragment(mediaDetailPagerFragment, MEDIA_DETAIL_PAGER_FRAGMENT_TAG, contributionsListFragment); } private void setupViewForMediaDetails() { @@ -329,7 +329,7 @@ public class ContributionsFragment showContributionsListFragment(); } - showFragment(contributionsListFragment, CONTRIBUTION_LIST_FRAGMENT_TAG); + showFragment(contributionsListFragment, CONTRIBUTION_LIST_FRAGMENT_TAG, mediaDetailPagerFragment); } /** @@ -337,15 +337,44 @@ public class ContributionsFragment * * @param fragment * @param tag + * @param otherFragment */ - private void showFragment(Fragment fragment, String tag) { + private void showFragment(Fragment fragment, String tag, Fragment otherFragment) { FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); - transaction.replace(R.id.root_frame, fragment, tag); - transaction.addToBackStack(CONTRIBUTION_LIST_FRAGMENT_TAG); - transaction.commit(); + if (fragment.isAdded() && otherFragment != null) { + transaction.hide(otherFragment); + transaction.show(fragment); + transaction.addToBackStack(CONTRIBUTION_LIST_FRAGMENT_TAG); + transaction.commit(); + getChildFragmentManager().executePendingTransactions(); + } else if (fragment.isAdded() && otherFragment == null) { + transaction.show(fragment); + transaction.addToBackStack(CONTRIBUTION_LIST_FRAGMENT_TAG); + transaction.commit(); + getChildFragmentManager().executePendingTransactions(); + }else if (!fragment.isAdded() && otherFragment != null ) { + transaction.hide(otherFragment); + transaction.add(R.id.root_frame, fragment, tag); + transaction.addToBackStack(CONTRIBUTION_LIST_FRAGMENT_TAG); + transaction.commit(); + getChildFragmentManager().executePendingTransactions(); + } else if (!fragment.isAdded()) { + transaction.replace(R.id.root_frame, fragment, tag); + transaction.addToBackStack(CONTRIBUTION_LIST_FRAGMENT_TAG); + transaction.commit(); + getChildFragmentManager().executePendingTransactions(); + } + } + + public void removeFragment(Fragment fragment) { + getChildFragmentManager() + .beginTransaction() + .remove(fragment) + .commit(); getChildFragmentManager().executePendingTransactions(); } + public Intent getUploadServiceIntent(){ Intent intent = new Intent(getActivity(), UploadService.class); intent.setAction(UploadService.ACTION_START_SERVICE); @@ -620,7 +649,8 @@ public class ContributionsFragment } else { nearbyNotificationCardView.setVisibility(View.GONE); } - getChildFragmentManager().popBackStack(); + removeFragment(mediaDetailPagerFragment); + showFragment(contributionsListFragment, CONTRIBUTION_LIST_FRAGMENT_TAG, mediaDetailPagerFragment); ((BaseActivity)getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false); ((MainActivity)getActivity()).showTabs(); fetchCampaigns(); diff --git a/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java b/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java index 86e6eef77..24c2a1b16 100644 --- a/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java @@ -110,11 +110,18 @@ public class MainActivity extends BaseActivity setContentView(R.layout.main); ButterKnife.bind(this); setSupportActionBar(toolbar); + toolbar.setNavigationOnClickListener(view -> { + onSupportNavigateUp(); + }); if (applicationKvStore.getBoolean("login_skipped") == true) { setTitle(getString(R.string.explore_tab_title_mobile)); setUpLoggedOutPager(); } else { - setTitle(getString(R.string.contributions_fragment)); + if(savedInstanceState == null){ + //starting a fresh fragment. + setTitle(getString(R.string.contributions_fragment)); + loadFragment(ContributionsFragment.newInstance(),false); + } setUpPager(); initMain(); } @@ -125,30 +132,31 @@ public class MainActivity extends BaseActivity } private void setUpPager() { - loadFragment(ContributionsFragment.newInstance()); tabLayout.setOnNavigationItemSelectedListener(item -> { if (!item.getTitle().equals("More")) { // do not change title for more fragment setTitle(item.getTitle()); } Fragment fragment = NavTab.of(item.getOrder()).newInstance(); - return loadFragment(fragment); + return loadFragment(fragment,true); }); } private void setUpLoggedOutPager() { - loadFragment(ExploreFragment.newInstance()); + loadFragment(ExploreFragment.newInstance(),false); tabLayout.setOnNavigationItemSelectedListener(item -> { if (!item.getTitle().equals("More")) { // do not change title for more fragment setTitle(item.getTitle()); } Fragment fragment = NavTabLoggedOut.of(item.getOrder()).newInstance(); - return loadFragment(fragment); + return loadFragment(fragment,true); }); } - private boolean loadFragment(Fragment fragment) { + private boolean loadFragment(Fragment fragment,boolean showBottom ) { + //showBottom so that we do not show the bottom tray again when constructing + //from the saved instance state. if (fragment instanceof ContributionsFragment) { if (activeFragment == ActiveFragment.CONTRIBUTIONS) { // Do nothing if same tab return true; @@ -173,7 +181,7 @@ public class MainActivity extends BaseActivity } bookmarkFragment = (BookmarkFragment) fragment; activeFragment = ActiveFragment.BOOKMARK; - } else if (fragment == null) { + } else if (fragment == null && showBottom) { if (applicationKvStore.getBoolean("login_skipped") == true) { // If logged out, more sheet is different MoreBottomSheetLoggedOutFragment bottomSheet = new MoreBottomSheetLoggedOutFragment(); bottomSheet.show(getSupportFragmentManager(), diff --git a/app/src/main/java/fr/free/nrw/commons/explore/ExploreListRootFragment.java b/app/src/main/java/fr/free/nrw/commons/explore/ExploreListRootFragment.java index 0a3f43a3b..19d9effc7 100644 --- a/app/src/main/java/fr/free/nrw/commons/explore/ExploreListRootFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/explore/ExploreListRootFragment.java @@ -34,6 +34,10 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem @BindView(R.id.explore_container) FrameLayout container; + public ExploreListRootFragment(){ + //empty constructor necessary otherwise crashes on recreate + } + public ExploreListRootFragment(Bundle bundle) { String title = bundle.getString("categoryName"); listFragment = new CategoriesMediaFragment(); @@ -55,7 +59,9 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem @Override public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - setFragment(listFragment, mediaDetails); + if(savedInstanceState == null) { + setFragment(listFragment, mediaDetails); + } } public void setFragment(Fragment fragment, Fragment otherFragment) { @@ -110,7 +116,8 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem Log.d("deneme8","on media clicked"); container.setVisibility(View.VISIBLE); ((ExploreFragment)getParentFragment()).tabLayout.setVisibility(View.GONE); - mediaDetails = new MediaDetailPagerFragment(false, true, position); + mediaDetails = new MediaDetailPagerFragment(false, true); + mediaDetails.showImage(position); setFragment(mediaDetails, listFragment); } diff --git a/app/src/main/java/fr/free/nrw/commons/review/ReviewImageFragment.java b/app/src/main/java/fr/free/nrw/commons/review/ReviewImageFragment.java index f82ebd43a..0a828e079 100644 --- a/app/src/main/java/fr/free/nrw/commons/review/ReviewImageFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/review/ReviewImageFragment.java @@ -115,7 +115,7 @@ public class ReviewImageFragment extends CommonsDaggerSupportFragment { //Get existing user name if it is already saved using savedInstanceState else get from reviewController if (savedInstanceState == null) { - if (getReviewActivity().reviewController != null) { + if (getReviewActivity().reviewController.firstRevision != null) { user = getReviewActivity().reviewController.firstRevision.getUser(); } } else {