mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Try to use SupportMapFragment instead, still no success...
This commit is contained in:
parent
0ec470bfd1
commit
f3694e3647
3 changed files with 248 additions and 11 deletions
|
|
@ -0,0 +1,198 @@
|
|||
package fr.free.nrw.commons.nearby.mvp.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
|
||||
import com.mapbox.mapboxsdk.maps.SupportMapFragment;
|
||||
import com.mapbox.mapboxsdk.utils.MapFragmentUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
import fr.free.nrw.commons.nearby.NearbyBaseMarker;
|
||||
import fr.free.nrw.commons.nearby.Place;
|
||||
import fr.free.nrw.commons.nearby.mvp.contract.NearbyMapContract;
|
||||
import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class NearbyMapFragment2 extends SupportMapFragment implements NearbyMapContract.View {
|
||||
public NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
Log.d("deneme2","on attach");
|
||||
((NearbyParentFragment)getParentFragment()).childMapFragmentAttached();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a MapFragment instance
|
||||
*
|
||||
* @param mapboxMapOptions The configuration options to be used.
|
||||
* @return MapFragment created.
|
||||
*/
|
||||
@NonNull
|
||||
public static NearbyMapFragment2 newInstance(@Nullable MapboxMapOptions mapboxMapOptions) {
|
||||
Log.d("deneme2","on NearbyMapFragment2 newInstance");
|
||||
NearbyMapFragment2 mapFragment = new NearbyMapFragment2();
|
||||
mapFragment.setArguments(MapFragmentUtils.createFragmentArgs(mapboxMapOptions));
|
||||
return mapFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showSearchThisAreaButton() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showInformationBottomSheet() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initViews() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMapMarkers(LatLng latLng, List<Place> placeList) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMapToTrackPosition(LatLng curLatLng) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setListeners() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapView setupMapView(Bundle savedInstanceState) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCurrentLocationMarker(LatLng curLatLng) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSearchThisAreaButtonVisibility(boolean visible) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCurrentLocationMarkerVisible() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNearbyMarkersToMapBoxMap(List<NearbyBaseMarker> baseMarkerOptions) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareViewsForSheetPosition() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideFABs() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showFABs() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAnchorToBigFABs(FloatingActionButton floatingActionButton, int anchorID) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAnchorFromFABs(FloatingActionButton fab) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAnchorToSmallFABs(FloatingActionButton floatingActionButton, int anchorID) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void passInfoToSheet(Place place) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateBookmarkButtonImage(Place place) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openWebView(Uri link) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void animateFABs(boolean isFabOpen) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeFabs(boolean isFabOpen) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMarker(boolean isBookmarked, Place place) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public LatLng getCameraTarget() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapboxMap getMapboxMap() {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Means that views are set in presenter to reference variables
|
||||
* @param viewsAreReadyCallback
|
||||
*/
|
||||
@Override
|
||||
public void viewsAreAssignedToPresenter(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback) {
|
||||
Log.d("deneme2","on viewsAreAssignedToPresenter");
|
||||
|
||||
Timber.d("Views are set");
|
||||
this.viewsAreReadyCallback = viewsAreReadyCallback;
|
||||
this.viewsAreReadyCallback.nearbyFragmentsAreReady();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showPlaces() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,13 @@ import android.widget.ProgressBar;
|
|||
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.gson.Gson;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.constants.Style;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.SupportMapFragment;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
|
@ -91,9 +98,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
|
||||
private NearbyParentFragmentContract.UserActions userActions;
|
||||
|
||||
private NearbyMapFragment nearbyMapFragment;
|
||||
private NearbyMapFragment2 nearbyMapFragment;
|
||||
private NearbyListFragment nearbyListFragment;
|
||||
private static final String TAG_RETAINED_MAP_FRAGMENT = NearbyMapFragment.class.getSimpleName();
|
||||
private static final String TAG_RETAINED_MAP_FRAGMENT = NearbyMapFragment2.class.getSimpleName();
|
||||
private static final String TAG_RETAINED_LIST_FRAGMENT = NearbyListFragment.class.getSimpleName();
|
||||
public NearbyParentFragmentPresenter nearbyParentFragmentPresenter;
|
||||
|
||||
|
|
@ -113,6 +120,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setRetainInstance(true);
|
||||
Mapbox.getInstance(getActivity(),
|
||||
getString(R.string.mapbox_commons_app_token));
|
||||
Mapbox.getTelemetry().setUserTelemetryRequestState(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -230,8 +240,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
/**
|
||||
* Returns the map fragment added to child fragment manager previously, if exists.
|
||||
*/
|
||||
private NearbyMapFragment getMapFragment() {
|
||||
NearbyMapFragment existingFragment = (NearbyMapFragment) getChildFragmentManager()
|
||||
private NearbyMapFragment2 getMapFragment() {
|
||||
NearbyMapFragment2 existingFragment = (NearbyMapFragment2) getChildFragmentManager()
|
||||
.findFragmentByTag(TAG_RETAINED_MAP_FRAGMENT);
|
||||
if (existingFragment == null) {
|
||||
existingFragment = setMapFragment();
|
||||
|
|
@ -239,11 +249,32 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
return existingFragment;
|
||||
}
|
||||
|
||||
private NearbyMapFragment setMapFragment() {
|
||||
private NearbyMapFragment2 setMapFragment() {
|
||||
FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
|
||||
NearbyMapFragment nearbyMapFragment = new NearbyMapFragment();
|
||||
// Build mapboxMap
|
||||
MapboxMapOptions options = new MapboxMapOptions();
|
||||
options.camera(new CameraPosition.Builder()
|
||||
.target(new com.mapbox.mapboxsdk.geometry.LatLng(-52.6885, -70.1395))
|
||||
.zoom(9)
|
||||
.build());
|
||||
|
||||
// Create map fragment
|
||||
NearbyMapFragment2 nearbyMapFragment = NearbyMapFragment2.newInstance(options);
|
||||
|
||||
//NearbyMapFragment2 nearbyMapFragment = new NearbyMapFragment2();
|
||||
fragmentTransaction.replace(R.id.container, nearbyMapFragment, TAG_RETAINED_MAP_FRAGMENT);
|
||||
fragmentTransaction.commitAllowingStateLoss();
|
||||
|
||||
nearbyMapFragment.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
Log.d("deneme2","onMapReady");
|
||||
nearbyMapFragment.viewsAreReadyCallback.nearbyMapViewReady();
|
||||
}
|
||||
});
|
||||
if (nearbyMapFragment.getMapboxMap()!=null){
|
||||
|
||||
}
|
||||
return nearbyMapFragment;
|
||||
}
|
||||
|
||||
|
|
@ -289,6 +320,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
nearbyMapFragment = getMapFragment();
|
||||
nearbyListFragment = getListFragment();
|
||||
addNetworkBroadcastReceiver();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -98,20 +98,20 @@ public class NearbyParentFragmentPresenter
|
|||
public void initializeNearbyOperations() {
|
||||
Timber.d("initializing nearby operations started");
|
||||
// Add location listener to be notified about location changes
|
||||
locationServiceManager.addLocationListener(this);
|
||||
//locationServiceManager.addLocationListener(this);
|
||||
nearbyParentFragmentView.checkPermissionsAndPerformAction(this::performNearbyOperationsIfPermissionGiven);
|
||||
|
||||
}
|
||||
|
||||
public void performNearbyOperationsIfPermissionGiven() {
|
||||
Timber.d("performNearbyOperationsIfPermissionGiven");
|
||||
nearbyParentFragmentView.registerLocationUpdates(locationServiceManager);
|
||||
//nearbyParentFragmentView.registerLocationUpdates(locationServiceManager);
|
||||
// Nearby buttons should be active, they should be inactive only during update
|
||||
lockNearby(false);
|
||||
//lockNearby(false);
|
||||
// This will start a consequence to check GPS depending on different API
|
||||
//nearbyParentFragmentView.checkGps(locationServiceManager);
|
||||
// We will know when we went offline and online again
|
||||
nearbyParentFragmentView.addNetworkBroadcastReceiver();
|
||||
//nearbyParentFragmentView.addNetworkBroadcastReceiver();
|
||||
//nearbyMapFragmentView.setupMapView(null);
|
||||
nearbyOperationsInitialized();
|
||||
}
|
||||
|
|
@ -129,6 +129,7 @@ public class NearbyParentFragmentPresenter
|
|||
}
|
||||
|
||||
public void nearbyOperationsInitialized() {
|
||||
Log.d("deneme2","nearbyOperationsinitialized");
|
||||
nearbyOperationsInitialized = true;
|
||||
if (nearbyMapViewReady) {
|
||||
initializeMapOperations();
|
||||
|
|
@ -136,6 +137,11 @@ public class NearbyParentFragmentPresenter
|
|||
}
|
||||
|
||||
public void initializeMapOperations() {
|
||||
Log.d("deneme2","initializeMapOperations");
|
||||
|
||||
lockNearby(false);
|
||||
nearbyParentFragmentView.addNetworkBroadcastReceiver();
|
||||
|
||||
Timber.d("Nearby map view is created and ready");
|
||||
updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED, null);
|
||||
// TODO: document this prpoblem, if updateMapAndList is not called at checkGPS then this method never called, setup map view never ends
|
||||
|
|
@ -157,8 +163,8 @@ public class NearbyParentFragmentPresenter
|
|||
locationServiceManager.removeLocationListener(this);
|
||||
Timber.d("Nearby locked");
|
||||
} else {
|
||||
nearbyParentFragmentView.registerLocationUpdates(locationServiceManager);
|
||||
locationServiceManager.addLocationListener(this);
|
||||
nearbyParentFragmentView.registerLocationUpdates(locationServiceManager);
|
||||
Timber.d("Nearby unlocked");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue