mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Implement back button with presenter
This commit is contained in:
parent
c1403c1e22
commit
9007ae5cd4
5 changed files with 65 additions and 16 deletions
|
|
@ -4,7 +4,6 @@ import android.annotation.SuppressLint;
|
|||
import android.app.AlertDialog;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
|
|
@ -268,14 +267,7 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
|
|||
} else if (getSupportFragmentManager().findFragmentByTag(nearbyFragmentTag) != null && !isContributionsFragmentVisible) {
|
||||
// Means that nearby fragment is visible (not contributions fragment)
|
||||
NearbyTestLayersFragment nearbyFragment = (NearbyTestLayersFragment) contributionsActivityPagerAdapter.getItem(1);
|
||||
|
||||
if(nearbyFragment.isBottomSheetExpanded()) {
|
||||
// Back should first hide the bottom sheet if it is expanded
|
||||
nearbyFragment.listOptionMenuItemClicked();
|
||||
} else {
|
||||
// Otherwise go back to contributions fragment
|
||||
viewPager.setCurrentItem(0);
|
||||
}
|
||||
nearbyFragment.nearbyParentFragmentPresenter.backButtonClicked();
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ import fr.free.nrw.commons.R;
|
|||
import fr.free.nrw.commons.Utils;
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
|
||||
import fr.free.nrw.commons.contributions.ContributionController;
|
||||
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.location.LocationServiceManager;
|
||||
|
|
@ -418,10 +419,19 @@ public class NearbyTestLayersFragment extends CommonsDaggerSupportFragment imple
|
|||
getActivity().registerReceiver(broadcastReceiver, intentFilter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide or expand bottom sheet according to states of all sheets
|
||||
*/
|
||||
@Override
|
||||
public void listOptionMenuItemClicked() {
|
||||
|
||||
if(bottomSheetListBehavior.getState()== BottomSheetBehavior.STATE_COLLAPSED || bottomSheetListBehavior.getState()==BottomSheetBehavior.STATE_HIDDEN){
|
||||
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
||||
bottomSheetListBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
|
||||
}else if(bottomSheetListBehavior.getState()==BottomSheetBehavior.STATE_EXPANDED){
|
||||
bottomSheetListBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void populatePlaces(fr.free.nrw.commons.location.LatLng curlatLng, fr.free.nrw.commons.location.LatLng searchLatLng) {
|
||||
|
|
@ -478,11 +488,21 @@ public class NearbyTestLayersFragment extends CommonsDaggerSupportFragment imple
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isBottomSheetExpanded() {
|
||||
return false;
|
||||
public boolean isListBottomSheetExpanded() {
|
||||
return bottomSheetListBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED;
|
||||
}
|
||||
|
||||
public boolean isDetailsBottomSheetVisible() {
|
||||
return !(bottomSheetDetailsBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN);
|
||||
}
|
||||
|
||||
public void setBottomSheetDetailsSmaller() {
|
||||
if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
||||
} else {
|
||||
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -508,6 +528,11 @@ public class NearbyTestLayersFragment extends CommonsDaggerSupportFragment imple
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTabItemContributions() {
|
||||
((MainActivity)getActivity()).viewPager.setCurrentItem(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkPermissionsAndPerformAction(Runnable runnable) {
|
||||
Log.d("denemeTest","checkPermissionsAndPerformAction is called");
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public interface NearbyParentFragmentContract {
|
|||
void addNetworkBroadcastReceiver();
|
||||
void listOptionMenuItemClicked();
|
||||
void populatePlaces(LatLng curlatLng, LatLng searchLatLng);
|
||||
boolean isBottomSheetExpanded();
|
||||
boolean isListBottomSheetExpanded();
|
||||
|
||||
void checkPermissionsAndPerformAction(Runnable runnable);
|
||||
void resumeFragment();
|
||||
|
|
@ -36,6 +36,9 @@ public interface NearbyParentFragmentContract {
|
|||
void addSearchThisAreaButtonAction();
|
||||
void setSearchThisAreaButtonVisibility(boolean isVisible);
|
||||
void setProgressBarVisibility(boolean isVisible);
|
||||
void setTabItemContributions();
|
||||
boolean isDetailsBottomSheetVisible();
|
||||
void setBottomSheetDetailsSmaller();
|
||||
}
|
||||
|
||||
interface UserActions {
|
||||
|
|
@ -45,6 +48,7 @@ public interface NearbyParentFragmentContract {
|
|||
void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType, LatLng cameraTarget);
|
||||
void lockUnlockNearby(boolean isNearbyLocked);
|
||||
void setActionListeners(JsonKvStore applicationKvStore);
|
||||
void backButtonClicked();
|
||||
|
||||
MapboxMap.OnCameraMoveListener onCameraMove(MapboxMap mapboxMap);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -189,6 +189,21 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTabItemContributions() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDetailsBottomSheetVisible() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBottomSheetDetailsSmaller() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
|
|
@ -458,7 +473,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isBottomSheetExpanded() {
|
||||
public boolean isListBottomSheetExpanded() {
|
||||
return bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -180,6 +180,19 @@ public class NearbyParentFragmentPresenter
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void backButtonClicked() {
|
||||
if(nearbyParentFragmentView.isListBottomSheetExpanded()) {
|
||||
// Back should first hide the bottom sheet if it is expanded
|
||||
nearbyParentFragmentView.listOptionMenuItemClicked();
|
||||
} else if (nearbyParentFragmentView.isDetailsBottomSheetVisible()) {
|
||||
nearbyParentFragmentView.setBottomSheetDetailsSmaller();
|
||||
} else {
|
||||
// Otherwise go back to contributions fragment
|
||||
nearbyParentFragmentView.setTabItemContributions();
|
||||
}
|
||||
}
|
||||
|
||||
public void markerUnselected() {
|
||||
nearbyParentFragmentView.hideBottomSheet();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue