mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Change nearby design, first create views then register listeners
This commit is contained in:
parent
297eb67dae
commit
cdd62290ac
5 changed files with 153 additions and 30 deletions
|
|
@ -1,8 +1,10 @@
|
||||||
package fr.free.nrw.commons.nearby.mvp.contract;
|
package fr.free.nrw.commons.nearby.mvp.contract;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
|
import com.mapbox.mapboxsdk.maps.MapView;
|
||||||
|
|
||||||
import fr.free.nrw.commons.nearby.Place;
|
import fr.free.nrw.commons.nearby.Place;
|
||||||
|
|
||||||
|
|
@ -21,7 +23,7 @@ public interface NearbyMapContract {
|
||||||
void updateMapMarkers();
|
void updateMapMarkers();
|
||||||
void updateMapToTrackPosition();
|
void updateMapToTrackPosition();
|
||||||
void setListeners();
|
void setListeners();
|
||||||
void setupMapView();
|
MapView setupMapView(Bundle savedInstanceState);
|
||||||
void addCurrentLocationMarker();
|
void addCurrentLocationMarker();
|
||||||
void setSearchThisAreaButtonVisibility(boolean visible);
|
void setSearchThisAreaButtonVisibility(boolean visible);
|
||||||
boolean isCurrentLocationMarkerVisible();
|
boolean isCurrentLocationMarkerVisible();
|
||||||
|
|
@ -38,6 +40,7 @@ public interface NearbyMapContract {
|
||||||
void animateFABs(boolean isFabOpen);
|
void animateFABs(boolean isFabOpen);
|
||||||
void closeFabs ( boolean isFabOpen);
|
void closeFabs ( boolean isFabOpen);
|
||||||
void updateMarker(boolean isBookmarked, Place place);
|
void updateMarker(boolean isBookmarked, Place place);
|
||||||
|
void setViewsAreReady(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UserActions extends NearbyElementContract.UserActions {
|
interface UserActions extends NearbyElementContract.UserActions {
|
||||||
|
|
|
||||||
|
|
@ -23,4 +23,8 @@ public interface NearbyParentFragmentContract {
|
||||||
void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType);
|
void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType);
|
||||||
void lockNearby(boolean isNearbyLocked);
|
void lockNearby(boolean isNearbyLocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ViewsAreReadyCallback {
|
||||||
|
void nearbyFragmentAndMapViewReady();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,114 @@
|
||||||
package fr.free.nrw.commons.nearby.mvp.fragments;
|
package fr.free.nrw.commons.nearby.mvp.fragments;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.view.animation.Animation;
|
||||||
|
import android.view.animation.AnimationUtils;
|
||||||
|
|
||||||
|
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
|
import com.mapbox.mapboxsdk.Mapbox;
|
||||||
|
import com.mapbox.mapboxsdk.maps.MapView;
|
||||||
|
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import fr.free.nrw.commons.R;
|
||||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||||
|
import fr.free.nrw.commons.nearby.NearbyFragment;
|
||||||
import fr.free.nrw.commons.nearby.Place;
|
import fr.free.nrw.commons.nearby.Place;
|
||||||
import fr.free.nrw.commons.nearby.mvp.contract.NearbyMapContract;
|
import fr.free.nrw.commons.nearby.mvp.contract.NearbyMapContract;
|
||||||
|
import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract;
|
||||||
|
import timber.log.Timber;
|
||||||
|
|
||||||
public class NearbyMapFragment extends CommonsDaggerSupportFragment implements NearbyMapContract.View {
|
public class NearbyMapFragment extends CommonsDaggerSupportFragment implements NearbyMapContract.View {
|
||||||
|
@BindView(R.id.bottom_sheet)
|
||||||
|
View bottomSheetList;
|
||||||
|
|
||||||
|
@BindView(R.id.bottom_sheet_details)
|
||||||
|
View bottomSheetDetails;
|
||||||
|
|
||||||
|
MapView mapView;
|
||||||
|
public NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback;
|
||||||
|
|
||||||
|
private BottomSheetBehavior bottomSheetListBehavior;
|
||||||
|
private BottomSheetBehavior bottomSheetDetailsBehavior;
|
||||||
|
private Animation rotate_backward;
|
||||||
|
private Animation fab_close;
|
||||||
|
private Animation fab_open;
|
||||||
|
private Animation rotate_forward;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
Timber.d("Nearby map fragment created");
|
||||||
|
Mapbox.getInstance(getActivity(),
|
||||||
|
getString(R.string.mapbox_commons_app_token));
|
||||||
|
Mapbox.getTelemetry().setUserTelemetryRequestState(false);
|
||||||
|
setRetainInstance(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
Timber.d("onCreateView called");
|
||||||
|
this.mapView = setupMapView(savedInstanceState);
|
||||||
|
setHasOptionsMenu(false);
|
||||||
|
initViews();
|
||||||
|
return mapView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initViews() {
|
||||||
|
Timber.d("init views called");
|
||||||
|
View view = ((NearbyFragment)getParentFragment()).view;
|
||||||
|
ButterKnife.bind(this, view);
|
||||||
|
bottomSheetListBehavior = BottomSheetBehavior.from(bottomSheetList);
|
||||||
|
bottomSheetDetailsBehavior = BottomSheetBehavior.from(bottomSheetDetails);
|
||||||
|
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
||||||
|
bottomSheetDetails.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
fab_open = AnimationUtils.loadAnimation(getParentFragment().getActivity(), R.anim.fab_open);
|
||||||
|
fab_close = AnimationUtils.loadAnimation(getParentFragment().getActivity(), R.anim.fab_close);
|
||||||
|
rotate_forward = AnimationUtils.loadAnimation(getParentFragment().getActivity(), R.anim.rotate_forward);
|
||||||
|
rotate_backward = AnimationUtils.loadAnimation(getParentFragment().getActivity(), R.anim.rotate_backward);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
this.getView().setFocusableInTouchMode(true);
|
||||||
|
this.getView().requestFocus();
|
||||||
|
this.getView().setOnKeyListener((v, keyCode, event) -> {
|
||||||
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
|
if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior
|
||||||
|
.STATE_EXPANDED) {
|
||||||
|
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
||||||
|
return true;
|
||||||
|
} else if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior
|
||||||
|
.STATE_COLLAPSED) {
|
||||||
|
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
||||||
|
mapView.getMapAsync(MapboxMap::deselectMarkers);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
viewsAreReadyCallback.nearbyFragmentAndMapViewReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MapView setupMapView(Bundle savedInstanceState) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showSearchThisAreaButton() {
|
public void showSearchThisAreaButton() {
|
||||||
|
|
||||||
|
|
@ -19,11 +119,6 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initViews() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateMapMarkers() {
|
public void updateMapMarkers() {
|
||||||
|
|
||||||
|
|
@ -39,11 +134,6 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setupMapView() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCurrentLocationMarker() {
|
public void addCurrentLocationMarker() {
|
||||||
|
|
||||||
|
|
@ -124,6 +214,11 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setViewsAreReady(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback) {
|
||||||
|
this.viewsAreReadyCallback = viewsAreReadyCallback;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showPlaces() {
|
public void showPlaces() {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,6 @@ import fr.free.nrw.commons.location.LatLng;
|
||||||
import fr.free.nrw.commons.location.LocationServiceManager;
|
import fr.free.nrw.commons.location.LocationServiceManager;
|
||||||
import fr.free.nrw.commons.location.LocationUpdateListener;
|
import fr.free.nrw.commons.location.LocationUpdateListener;
|
||||||
import fr.free.nrw.commons.nearby.NearbyController;
|
import fr.free.nrw.commons.nearby.NearbyController;
|
||||||
import fr.free.nrw.commons.nearby.NearbyListFragment;
|
|
||||||
import fr.free.nrw.commons.nearby.NearbyMapFragment;
|
|
||||||
import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract;
|
import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract;
|
||||||
import fr.free.nrw.commons.nearby.mvp.presenter.NearbyParentFragmentPresenter;
|
import fr.free.nrw.commons.nearby.mvp.presenter.NearbyParentFragmentPresenter;
|
||||||
import fr.free.nrw.commons.utils.NetworkUtils;
|
import fr.free.nrw.commons.utils.NetworkUtils;
|
||||||
|
|
@ -68,8 +66,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
|
|
||||||
private NearbyParentFragmentContract.UserActions userActions;
|
private NearbyParentFragmentContract.UserActions userActions;
|
||||||
|
|
||||||
private fr.free.nrw.commons.nearby.NearbyMapFragment nearbyMapFragment;
|
private NearbyMapFragment nearbyMapFragment;
|
||||||
private fr.free.nrw.commons.nearby.NearbyListFragment nearbyListFragment;
|
private NearbyListFragment nearbyListFragment;
|
||||||
private static final String TAG_RETAINED_MAP_FRAGMENT = NearbyMapFragment.class.getSimpleName();
|
private static final String TAG_RETAINED_MAP_FRAGMENT = NearbyMapFragment.class.getSimpleName();
|
||||||
private static final String TAG_RETAINED_LIST_FRAGMENT = NearbyListFragment.class.getSimpleName();
|
private static final String TAG_RETAINED_LIST_FRAGMENT = NearbyListFragment.class.getSimpleName();
|
||||||
private NearbyParentFragmentPresenter nearbyParentFragmentPresenter;
|
private NearbyParentFragmentPresenter nearbyParentFragmentPresenter;
|
||||||
|
|
@ -78,7 +76,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setRetainInstance(true);
|
setRetainInstance(true);
|
||||||
nearbyParentFragmentPresenter = new NearbyParentFragmentPresenter(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
@ -93,6 +90,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
resumeFragment();
|
resumeFragment();
|
||||||
|
nearbyParentFragmentPresenter = new NearbyParentFragmentPresenter(this, nearbyMapFragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,8 @@ import static fr.free.nrw.commons.location.LocationServiceManager.LocationChange
|
||||||
public class NearbyParentFragmentPresenter
|
public class NearbyParentFragmentPresenter
|
||||||
implements NearbyParentFragmentContract.UserActions,
|
implements NearbyParentFragmentContract.UserActions,
|
||||||
WikidataEditListener.WikidataP18EditListener,
|
WikidataEditListener.WikidataP18EditListener,
|
||||||
LocationUpdateListener {
|
LocationUpdateListener,
|
||||||
|
NearbyParentFragmentContract.ViewsAreReadyCallback{
|
||||||
@Inject
|
@Inject
|
||||||
LocationServiceManager locationManager;
|
LocationServiceManager locationManager;
|
||||||
|
|
||||||
|
|
@ -26,10 +27,14 @@ public class NearbyParentFragmentPresenter
|
||||||
private boolean isNearbyLocked;
|
private boolean isNearbyLocked;
|
||||||
private LatLng curLatLng;
|
private LatLng curLatLng;
|
||||||
|
|
||||||
|
boolean nearbyViewsAreReady;
|
||||||
|
boolean onTabSelected;
|
||||||
|
|
||||||
public NearbyParentFragmentPresenter(NearbyParentFragmentContract.View nearbyParentFragmentView,
|
public NearbyParentFragmentPresenter(NearbyParentFragmentContract.View nearbyParentFragmentView,
|
||||||
NearbyMapContract.View nearbyMapFragmentView) {
|
NearbyMapContract.View nearbyMapFragmentView) {
|
||||||
this.nearbyParentFragmentView = nearbyParentFragmentView;
|
this.nearbyParentFragmentView = nearbyParentFragmentView;
|
||||||
this.nearbyMapFragmentView = nearbyMapFragmentView;
|
this.nearbyMapFragmentView = nearbyMapFragmentView;
|
||||||
|
nearbyMapFragmentView.setViewsAreReady(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -37,9 +42,28 @@ public class NearbyParentFragmentPresenter
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* -To initialize nearby operations both views should be ready and tab is selected.
|
||||||
|
* Initializes nearby operations if nearby views are ready
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onTabSelected() {
|
public void onTabSelected() {
|
||||||
initializeNearbyOperations();
|
onTabSelected = true;
|
||||||
|
if (nearbyViewsAreReady) {
|
||||||
|
initializeNearbyOperations();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* -To initialize nearby operations both views should be ready and tab is selected.
|
||||||
|
* Initializes nearby operations if tab selected, otherwise just sets nearby views are ready
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void nearbyFragmentAndMapViewReady() {
|
||||||
|
nearbyViewsAreReady = true;
|
||||||
|
if (onTabSelected) {
|
||||||
|
initializeNearbyOperations();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -48,10 +72,8 @@ public class NearbyParentFragmentPresenter
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void initializeNearbyOperations() {
|
public void initializeNearbyOperations() {
|
||||||
locationManager.addLocationListener(this);
|
locationManager.addLocationListener(this);
|
||||||
nearbyParentFragmentView.registerLocationUpdates(locationManager);
|
nearbyParentFragmentView.registerLocationUpdates(locationManager);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -102,17 +124,17 @@ public class NearbyParentFragmentPresenter
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Significant changed - Markers and current location will be updated together
|
||||||
|
* Slightly changed - Only current position marker will be updated
|
||||||
|
*/
|
||||||
if (locationChangeType.equals(LOCATION_SIGNIFICANTLY_CHANGED)
|
if (locationChangeType.equals(LOCATION_SIGNIFICANTLY_CHANGED)
|
||||||
|| locationChangeType.equals(MAP_UPDATED)) {
|
|| locationChangeType.equals(MAP_UPDATED)) {
|
||||||
|
nearbyMapFragmentView.updateMapMarkers();
|
||||||
|
nearbyMapFragmentView.updateMapToTrackPosition();
|
||||||
|
} else {
|
||||||
|
nearbyMapFragmentView.updateMapToTrackPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -134,4 +156,5 @@ public class NearbyParentFragmentPresenter
|
||||||
public void onLocationChangedMedium(LatLng latLng) {
|
public void onLocationChangedMedium(LatLng latLng) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue