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 <Pratham2305@users.noreply.github.com>

* 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 <Pratham2305@users.noreply.github.com>
Co-authored-by: Aditya-Srivastav <54016427+4D17Y4@users.noreply.github.com>
This commit is contained in:
neslihanturan 2021-01-26 18:04:10 +03:00 committed by GitHub
parent 78dd5f6494
commit b60b3dc3e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 19 deletions

View file

@ -38,6 +38,10 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
@BindView(R.id.explore_container) @BindView(R.id.explore_container)
FrameLayout container; FrameLayout container;
public BookmarkListRootFragment(){
//empty constructor necessary otherwise crashes on recreate
}
public BookmarkListRootFragment(Bundle bundle, BookmarksPagerAdapter bookmarksPagerAdapter) { public BookmarkListRootFragment(Bundle bundle, BookmarksPagerAdapter bookmarksPagerAdapter) {
String title = bundle.getString("categoryName"); String title = bundle.getString("categoryName");
int order = bundle.getInt("order"); int order = bundle.getInt("order");
@ -65,7 +69,9 @@ public class BookmarkListRootFragment extends CommonsDaggerSupportFragment imple
@Override @Override
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
setFragment(listFragment, mediaDetails); if(savedInstanceState==null) {
setFragment(listFragment, mediaDetails);
}
} }
public void setFragment(Fragment fragment, Fragment otherFragment) { public void setFragment(Fragment fragment, Fragment otherFragment) {

View file

@ -286,13 +286,13 @@ public class ContributionsFragment
nearbyNotificationCardView.setVisibility(View.GONE); nearbyNotificationCardView.setVisibility(View.GONE);
} }
} }
showFragment(contributionsListFragment, CONTRIBUTION_LIST_FRAGMENT_TAG); showFragment(contributionsListFragment, CONTRIBUTION_LIST_FRAGMENT_TAG, mediaDetailPagerFragment);
} }
private void showMediaDetailPagerFragment() { private void showMediaDetailPagerFragment() {
// hide nearby card view on media detail is visible // hide nearby card view on media detail is visible
setupViewForMediaDetails(); setupViewForMediaDetails();
showFragment(mediaDetailPagerFragment, MEDIA_DETAIL_PAGER_FRAGMENT_TAG); showFragment(mediaDetailPagerFragment, MEDIA_DETAIL_PAGER_FRAGMENT_TAG, contributionsListFragment);
} }
private void setupViewForMediaDetails() { private void setupViewForMediaDetails() {
@ -329,7 +329,7 @@ public class ContributionsFragment
showContributionsListFragment(); showContributionsListFragment();
} }
showFragment(contributionsListFragment, CONTRIBUTION_LIST_FRAGMENT_TAG); showFragment(contributionsListFragment, CONTRIBUTION_LIST_FRAGMENT_TAG, mediaDetailPagerFragment);
} }
/** /**
@ -337,15 +337,44 @@ public class ContributionsFragment
* *
* @param fragment * @param fragment
* @param tag * @param tag
* @param otherFragment
*/ */
private void showFragment(Fragment fragment, String tag) { private void showFragment(Fragment fragment, String tag, Fragment otherFragment) {
FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.replace(R.id.root_frame, fragment, tag); if (fragment.isAdded() && otherFragment != null) {
transaction.addToBackStack(CONTRIBUTION_LIST_FRAGMENT_TAG); transaction.hide(otherFragment);
transaction.commit(); 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(); getChildFragmentManager().executePendingTransactions();
} }
public Intent getUploadServiceIntent(){ public Intent getUploadServiceIntent(){
Intent intent = new Intent(getActivity(), UploadService.class); Intent intent = new Intent(getActivity(), UploadService.class);
intent.setAction(UploadService.ACTION_START_SERVICE); intent.setAction(UploadService.ACTION_START_SERVICE);
@ -620,7 +649,8 @@ public class ContributionsFragment
} else { } else {
nearbyNotificationCardView.setVisibility(View.GONE); nearbyNotificationCardView.setVisibility(View.GONE);
} }
getChildFragmentManager().popBackStack(); removeFragment(mediaDetailPagerFragment);
showFragment(contributionsListFragment, CONTRIBUTION_LIST_FRAGMENT_TAG, mediaDetailPagerFragment);
((BaseActivity)getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false); ((BaseActivity)getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
((MainActivity)getActivity()).showTabs(); ((MainActivity)getActivity()).showTabs();
fetchCampaigns(); fetchCampaigns();

View file

@ -110,11 +110,18 @@ public class MainActivity extends BaseActivity
setContentView(R.layout.main); setContentView(R.layout.main);
ButterKnife.bind(this); ButterKnife.bind(this);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
toolbar.setNavigationOnClickListener(view -> {
onSupportNavigateUp();
});
if (applicationKvStore.getBoolean("login_skipped") == true) { if (applicationKvStore.getBoolean("login_skipped") == true) {
setTitle(getString(R.string.explore_tab_title_mobile)); setTitle(getString(R.string.explore_tab_title_mobile));
setUpLoggedOutPager(); setUpLoggedOutPager();
} else { } 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(); setUpPager();
initMain(); initMain();
} }
@ -125,30 +132,31 @@ public class MainActivity extends BaseActivity
} }
private void setUpPager() { private void setUpPager() {
loadFragment(ContributionsFragment.newInstance());
tabLayout.setOnNavigationItemSelectedListener(item -> { tabLayout.setOnNavigationItemSelectedListener(item -> {
if (!item.getTitle().equals("More")) { if (!item.getTitle().equals("More")) {
// do not change title for more fragment // do not change title for more fragment
setTitle(item.getTitle()); setTitle(item.getTitle());
} }
Fragment fragment = NavTab.of(item.getOrder()).newInstance(); Fragment fragment = NavTab.of(item.getOrder()).newInstance();
return loadFragment(fragment); return loadFragment(fragment,true);
}); });
} }
private void setUpLoggedOutPager() { private void setUpLoggedOutPager() {
loadFragment(ExploreFragment.newInstance()); loadFragment(ExploreFragment.newInstance(),false);
tabLayout.setOnNavigationItemSelectedListener(item -> { tabLayout.setOnNavigationItemSelectedListener(item -> {
if (!item.getTitle().equals("More")) { if (!item.getTitle().equals("More")) {
// do not change title for more fragment // do not change title for more fragment
setTitle(item.getTitle()); setTitle(item.getTitle());
} }
Fragment fragment = NavTabLoggedOut.of(item.getOrder()).newInstance(); 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 (fragment instanceof ContributionsFragment) {
if (activeFragment == ActiveFragment.CONTRIBUTIONS) { // Do nothing if same tab if (activeFragment == ActiveFragment.CONTRIBUTIONS) { // Do nothing if same tab
return true; return true;
@ -173,7 +181,7 @@ public class MainActivity extends BaseActivity
} }
bookmarkFragment = (BookmarkFragment) fragment; bookmarkFragment = (BookmarkFragment) fragment;
activeFragment = ActiveFragment.BOOKMARK; 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 if (applicationKvStore.getBoolean("login_skipped") == true) { // If logged out, more sheet is different
MoreBottomSheetLoggedOutFragment bottomSheet = new MoreBottomSheetLoggedOutFragment(); MoreBottomSheetLoggedOutFragment bottomSheet = new MoreBottomSheetLoggedOutFragment();
bottomSheet.show(getSupportFragmentManager(), bottomSheet.show(getSupportFragmentManager(),

View file

@ -34,6 +34,10 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem
@BindView(R.id.explore_container) @BindView(R.id.explore_container)
FrameLayout container; FrameLayout container;
public ExploreListRootFragment(){
//empty constructor necessary otherwise crashes on recreate
}
public ExploreListRootFragment(Bundle bundle) { public ExploreListRootFragment(Bundle bundle) {
String title = bundle.getString("categoryName"); String title = bundle.getString("categoryName");
listFragment = new CategoriesMediaFragment(); listFragment = new CategoriesMediaFragment();
@ -55,7 +59,9 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem
@Override @Override
public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
setFragment(listFragment, mediaDetails); if(savedInstanceState == null) {
setFragment(listFragment, mediaDetails);
}
} }
public void setFragment(Fragment fragment, Fragment otherFragment) { public void setFragment(Fragment fragment, Fragment otherFragment) {
@ -110,7 +116,8 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem
Log.d("deneme8","on media clicked"); Log.d("deneme8","on media clicked");
container.setVisibility(View.VISIBLE); container.setVisibility(View.VISIBLE);
((ExploreFragment)getParentFragment()).tabLayout.setVisibility(View.GONE); ((ExploreFragment)getParentFragment()).tabLayout.setVisibility(View.GONE);
mediaDetails = new MediaDetailPagerFragment(false, true, position); mediaDetails = new MediaDetailPagerFragment(false, true);
mediaDetails.showImage(position);
setFragment(mediaDetails, listFragment); setFragment(mediaDetails, listFragment);
} }

View file

@ -115,7 +115,7 @@ public class ReviewImageFragment extends CommonsDaggerSupportFragment {
//Get existing user name if it is already saved using savedInstanceState else get from reviewController //Get existing user name if it is already saved using savedInstanceState else get from reviewController
if (savedInstanceState == null) { if (savedInstanceState == null) {
if (getReviewActivity().reviewController != null) { if (getReviewActivity().reviewController.firstRevision != null) {
user = getReviewActivity().reviewController.firstRevision.getUser(); user = getReviewActivity().reviewController.firstRevision.getUser();
} }
} else { } else {