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