mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
fix :Back Pressed Event not work in Explore tab when user not login (#4404)
* fix :Back Pressed Event not work in Explore tab * minor changes
This commit is contained in:
parent
6df35e21a9
commit
2a2d2879a9
3 changed files with 31 additions and 18 deletions
|
|
@ -281,7 +281,11 @@ public class MainActivity extends BaseActivity
|
|||
}
|
||||
} else if (exploreFragment != null && activeFragment == ActiveFragment.EXPLORE) {
|
||||
// Means that explore fragment is visible
|
||||
exploreFragment.onBackPressed();
|
||||
if (!exploreFragment.onBackPressed()) {
|
||||
if (applicationKvStore.getBoolean("login_skipped")) {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
} else if (bookmarkFragment != null && activeFragment == ActiveFragment.BOOKMARK) {
|
||||
// Means that bookmark fragment is visible
|
||||
bookmarkFragment.onBackPressed();
|
||||
|
|
|
|||
|
|
@ -17,10 +17,13 @@ import fr.free.nrw.commons.R;
|
|||
import fr.free.nrw.commons.ViewPagerAdapter;
|
||||
import fr.free.nrw.commons.contributions.MainActivity;
|
||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.theme.BaseActivity;
|
||||
import fr.free.nrw.commons.utils.ActivityUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
public class ExploreFragment extends CommonsDaggerSupportFragment {
|
||||
|
||||
|
|
@ -35,6 +38,9 @@ public class ExploreFragment extends CommonsDaggerSupportFragment {
|
|||
ViewPagerAdapter viewPagerAdapter;
|
||||
private ExploreListRootFragment featuredRootFragment;
|
||||
private ExploreListRootFragment mobileRootFragment;
|
||||
@Inject
|
||||
@Named("default_preferences")
|
||||
public JsonKvStore applicationKvStore;
|
||||
|
||||
public void setScroll(boolean canScroll){
|
||||
viewPager.setCanScroll(canScroll);
|
||||
|
|
@ -95,20 +101,21 @@ public class ExploreFragment extends CommonsDaggerSupportFragment {
|
|||
viewPagerAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void onBackPressed() {
|
||||
public boolean onBackPressed() {
|
||||
if (tabLayout.getSelectedTabPosition() == 0) {
|
||||
if(featuredRootFragment.backPressed()){
|
||||
// Event is handled by the Fragment we need not do anything.
|
||||
return;
|
||||
if (featuredRootFragment.backPressed()) {
|
||||
((BaseActivity) getActivity()).getSupportActionBar()
|
||||
.setDisplayHomeAsUpEnabled(false);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if(mobileRootFragment.backPressed()){
|
||||
// Event is handled by the Fragment we need not do anything.
|
||||
return;
|
||||
if (mobileRootFragment.backPressed()) {
|
||||
((BaseActivity) getActivity()).getSupportActionBar()
|
||||
.setDisplayHomeAsUpEnabled(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Event is not handled by the fragment ( i.e performed back action ) therefore change action bar.
|
||||
((BaseActivity)getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package fr.free.nrw.commons.explore;
|
|||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
|
@ -182,20 +181,23 @@ public class ExploreListRootFragment extends CommonsDaggerSupportFragment implem
|
|||
* @return
|
||||
*/
|
||||
public boolean backPressed() {
|
||||
if (null!=mediaDetails && mediaDetails.isVisible()) {
|
||||
if (null != mediaDetails && mediaDetails.isVisible()) {
|
||||
// todo add get list fragment
|
||||
if(mediaDetails.backButtonClicked()) {
|
||||
if (mediaDetails.backButtonClicked()) {
|
||||
// MediaDetails handled the event no further action required.
|
||||
return true;
|
||||
} else {
|
||||
((ExploreFragment) getParentFragment()).tabLayout.setVisibility(View.VISIBLE);
|
||||
removeFragment(mediaDetails);
|
||||
((ExploreFragment) getParentFragment()).setScroll(true);
|
||||
setFragment(listFragment, mediaDetails);
|
||||
((MainActivity) getActivity()).showTabs();
|
||||
return true;
|
||||
}
|
||||
((ExploreFragment)getParentFragment()).tabLayout.setVisibility(View.VISIBLE);
|
||||
removeFragment(mediaDetails);
|
||||
((ExploreFragment) getParentFragment()).setScroll(true);
|
||||
setFragment(listFragment, mediaDetails);
|
||||
} else {
|
||||
((MainActivity) getActivity()).setSelectedItemId(NavTab.CONTRIBUTIONS.code());
|
||||
}
|
||||
((MainActivity)getActivity()).showTabs();
|
||||
((MainActivity) getActivity()).showTabs();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue