mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Makes sure that initialize nearby operations method is called just after all views and fragments are ready and attached
This commit is contained in:
parent
f4321d0541
commit
771a9ecda3
5 changed files with 50 additions and 18 deletions
|
|
@ -5,6 +5,7 @@ import android.app.AlertDialog;
|
|||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
|
|
@ -407,6 +408,7 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
|
|||
}
|
||||
|
||||
case 1:
|
||||
Log.d("deneme","case 1");
|
||||
NearbyParentFragment retainedNearbyFragment = getNearbyFragment(1);
|
||||
if (retainedNearbyFragment != null) {
|
||||
return retainedNearbyFragment;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import fr.free.nrw.commons.explore.recentsearches.RecentSearchesFragment;
|
|||
import fr.free.nrw.commons.media.MediaDetailFragment;
|
||||
import fr.free.nrw.commons.media.MediaDetailPagerFragment;
|
||||
import fr.free.nrw.commons.nearby.NearbyListFragment;
|
||||
import fr.free.nrw.commons.nearby.NearbyMapFragment;
|
||||
import fr.free.nrw.commons.nearby.mvp.fragments.NearbyMapFragment;
|
||||
import fr.free.nrw.commons.nearby.mvp.fragments.NearbyParentFragment;
|
||||
import fr.free.nrw.commons.review.ReviewImageFragment;
|
||||
import fr.free.nrw.commons.settings.SettingsFragment;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ 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 android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
|
@ -22,7 +23,6 @@ import butterknife.BindView;
|
|||
import butterknife.ButterKnife;
|
||||
import fr.free.nrw.commons.R;
|
||||
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.mvp.contract.NearbyMapContract;
|
||||
import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract;
|
||||
|
|
@ -68,7 +68,7 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
|||
@Override
|
||||
public void initViews() {
|
||||
Timber.d("init views called");
|
||||
View view = ((NearbyFragment)getParentFragment()).view;
|
||||
View view = ((NearbyParentFragment)getParentFragment()).view;
|
||||
ButterKnife.bind(this, view);
|
||||
bottomSheetListBehavior = BottomSheetBehavior.from(bottomSheetList);
|
||||
bottomSheetDetailsBehavior = BottomSheetBehavior.from(bottomSheetDetails);
|
||||
|
|
@ -223,7 +223,9 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
|||
|
||||
@Override
|
||||
public void setViewsAreReady(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback) {
|
||||
Log.d("deneme","setViewsAreReady");
|
||||
this.viewsAreReadyCallback = viewsAreReadyCallback;
|
||||
this.viewsAreReadyCallback.nearbyFragmentAndMapViewReady();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import fr.free.nrw.commons.R;
|
||||
|
|
@ -70,6 +71,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
WikidataEditListener wikidataEditListener;
|
||||
@Inject
|
||||
Gson gson;
|
||||
@Inject
|
||||
LocationServiceManager locationManager;
|
||||
|
||||
private NearbyParentFragmentContract.UserActions userActions;
|
||||
|
||||
|
|
@ -95,6 +98,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setRetainInstance(true);
|
||||
Log.d("deneme","onCreate");
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
@ -103,6 +108,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
View view = inflater.inflate(R.layout.fragment_nearby, container, false);
|
||||
ButterKnife.bind(this, view);
|
||||
this.view = view;
|
||||
Log.d("deneme","onCreateView");
|
||||
return view;
|
||||
}
|
||||
|
||||
|
|
@ -118,7 +124,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
* it is attached.
|
||||
*/
|
||||
public void childMapFragmentAttached() {
|
||||
nearbyParentFragmentPresenter = new NearbyParentFragmentPresenter(this, nearbyMapFragment);
|
||||
Log.d("deneme","childMapFragmentAttached");
|
||||
nearbyParentFragmentPresenter = new NearbyParentFragmentPresenter
|
||||
(this, nearbyMapFragment, locationManager);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -138,6 +146,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
* Resume fragments if they exists
|
||||
*/
|
||||
private void resumeFragment() {
|
||||
Log.d("deneme","resumeFragment");
|
||||
// Find the retained fragment on activity restarts
|
||||
nearbyMapFragment = getMapFragment();
|
||||
nearbyListFragment = getListFragment();
|
||||
|
|
@ -147,7 +156,20 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
* Returns the map fragment added to child fragment manager previously, if exists.
|
||||
*/
|
||||
private NearbyMapFragment getMapFragment() {
|
||||
return (NearbyMapFragment) getChildFragmentManager().findFragmentByTag(TAG_RETAINED_MAP_FRAGMENT);
|
||||
NearbyMapFragment existingFragment = (NearbyMapFragment) getChildFragmentManager()
|
||||
.findFragmentByTag(TAG_RETAINED_MAP_FRAGMENT);
|
||||
if (existingFragment == null) {
|
||||
existingFragment = setMapFragment();
|
||||
}
|
||||
return existingFragment;
|
||||
}
|
||||
|
||||
private NearbyMapFragment setMapFragment() {
|
||||
FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
|
||||
NearbyMapFragment nearbyMapFragment = new NearbyMapFragment();
|
||||
fragmentTransaction.replace(R.id.container, nearbyMapFragment, TAG_RETAINED_MAP_FRAGMENT);
|
||||
fragmentTransaction.commitAllowingStateLoss();
|
||||
return nearbyMapFragment;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package fr.free.nrw.commons.nearby.mvp.presenter;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import android.util.Log;
|
||||
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
import fr.free.nrw.commons.location.LocationServiceManager;
|
||||
|
|
@ -18,8 +18,7 @@ public class NearbyParentFragmentPresenter
|
|||
WikidataEditListener.WikidataP18EditListener,
|
||||
LocationUpdateListener,
|
||||
NearbyParentFragmentContract.ViewsAreReadyCallback{
|
||||
@Inject
|
||||
LocationServiceManager locationManager;
|
||||
|
||||
|
||||
private NearbyParentFragmentContract.View nearbyParentFragmentView;
|
||||
private NearbyMapContract.View nearbyMapFragmentView;
|
||||
|
|
@ -29,11 +28,15 @@ public class NearbyParentFragmentPresenter
|
|||
boolean nearbyViewsAreReady;
|
||||
boolean onTabSelected;
|
||||
|
||||
private LocationServiceManager locationServiceManager;
|
||||
|
||||
public NearbyParentFragmentPresenter(NearbyParentFragmentContract.View nearbyParentFragmentView,
|
||||
NearbyMapContract.View nearbyMapFragmentView) {
|
||||
NearbyMapContract.View nearbyMapFragmentView,
|
||||
LocationServiceManager locationServiceManager) {
|
||||
this.nearbyParentFragmentView = nearbyParentFragmentView;
|
||||
this.nearbyMapFragmentView = nearbyMapFragmentView;
|
||||
nearbyMapFragmentView.setViewsAreReady(this);
|
||||
this.locationServiceManager = locationServiceManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -47,6 +50,7 @@ public class NearbyParentFragmentPresenter
|
|||
*/
|
||||
@Override
|
||||
public void onTabSelected() {
|
||||
Log.d("deneme","onTabSelected");
|
||||
onTabSelected = true;
|
||||
if (nearbyViewsAreReady) {
|
||||
initializeNearbyOperations();
|
||||
|
|
@ -59,6 +63,7 @@ public class NearbyParentFragmentPresenter
|
|||
*/
|
||||
@Override
|
||||
public void nearbyFragmentAndMapViewReady() {
|
||||
Log.d("deneme","nearbyFragmentAndMapViewReady");
|
||||
nearbyViewsAreReady = true;
|
||||
if (onTabSelected) {
|
||||
initializeNearbyOperations();
|
||||
|
|
@ -71,12 +76,13 @@ public class NearbyParentFragmentPresenter
|
|||
*/
|
||||
@Override
|
||||
public void initializeNearbyOperations() {
|
||||
locationManager.addLocationListener(this);
|
||||
nearbyParentFragmentView.registerLocationUpdates(locationManager);
|
||||
Log.d("deneme","initializeNearbyOperations");
|
||||
locationServiceManager.addLocationListener(this);
|
||||
nearbyParentFragmentView.registerLocationUpdates(locationServiceManager);
|
||||
// Nearby buttons should be active, they should be deactive only during update
|
||||
lockNearby(false);
|
||||
//This will start a consequence to check GPS depending on different API
|
||||
nearbyParentFragmentView.checkGps(locationManager);
|
||||
nearbyParentFragmentView.checkGps(locationServiceManager);
|
||||
//We will know when we went offline and online again
|
||||
nearbyParentFragmentView.addNetworkBroadcastReceiver();
|
||||
}
|
||||
|
|
@ -90,11 +96,11 @@ public class NearbyParentFragmentPresenter
|
|||
public void lockNearby(boolean isNearbyLocked) {
|
||||
this.isNearbyLocked = isNearbyLocked;
|
||||
if (isNearbyLocked) {
|
||||
locationManager.unregisterLocationManager();
|
||||
locationManager.removeLocationListener(this);
|
||||
locationServiceManager.unregisterLocationManager();
|
||||
locationServiceManager.removeLocationListener(this);
|
||||
} else {
|
||||
nearbyParentFragmentView.registerLocationUpdates(locationManager);
|
||||
locationManager.addLocationListener(this);
|
||||
nearbyParentFragmentView.registerLocationUpdates(locationServiceManager);
|
||||
locationServiceManager.addLocationListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -115,8 +121,8 @@ public class NearbyParentFragmentPresenter
|
|||
return;
|
||||
}
|
||||
|
||||
//nearbyParentFragmentView.registerLocationUpdates(locationManager);
|
||||
LatLng lastLocation = locationManager.getLastLocation();
|
||||
//nearbyParentFragmentView.registerLocationUpdates(locationServiceManager);
|
||||
LatLng lastLocation = locationServiceManager.getLastLocation();
|
||||
|
||||
if (curLatLng != null) {
|
||||
// TODO figure out what is happening here about orientation change
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue