mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 05:13:53 +01:00
Use a singleton to access the presenter, instead of passing it to a variable inside fragment
This commit is contained in:
parent
d0310b35b7
commit
2d64f4ba5e
3 changed files with 27 additions and 6 deletions
|
|
@ -33,6 +33,7 @@ import fr.free.nrw.commons.auth.SessionManager;
|
||||||
import fr.free.nrw.commons.location.LocationServiceManager;
|
import fr.free.nrw.commons.location.LocationServiceManager;
|
||||||
import fr.free.nrw.commons.nearby.NearbyNotificationCardView;
|
import fr.free.nrw.commons.nearby.NearbyNotificationCardView;
|
||||||
import fr.free.nrw.commons.nearby.mvp.fragments.NearbyParentFragment;
|
import fr.free.nrw.commons.nearby.mvp.fragments.NearbyParentFragment;
|
||||||
|
import fr.free.nrw.commons.nearby.mvp.presenter.NearbyParentFragmentPresenter;
|
||||||
import fr.free.nrw.commons.notification.Notification;
|
import fr.free.nrw.commons.notification.Notification;
|
||||||
import fr.free.nrw.commons.notification.NotificationActivity;
|
import fr.free.nrw.commons.notification.NotificationActivity;
|
||||||
import fr.free.nrw.commons.notification.NotificationController;
|
import fr.free.nrw.commons.notification.NotificationController;
|
||||||
|
|
@ -172,7 +173,7 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
|
||||||
isContributionsFragmentVisible = false;
|
isContributionsFragmentVisible = false;
|
||||||
updateMenuItem();
|
updateMenuItem();
|
||||||
// Do all permission and GPS related tasks on tab selected, not on create
|
// Do all permission and GPS related tasks on tab selected, not on create
|
||||||
((NearbyParentFragment)contributionsActivityPagerAdapter.getItem(1)).nearbyParentFragmentPresenter.onTabSelected();
|
NearbyParentFragmentPresenter.getInstance().onTabSelected();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select();
|
tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select();
|
||||||
|
|
@ -254,7 +255,7 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
|
||||||
} else if (getSupportFragmentManager().findFragmentByTag(nearbyFragmentTag) != null && !isContributionsFragmentVisible) {
|
} else if (getSupportFragmentManager().findFragmentByTag(nearbyFragmentTag) != null && !isContributionsFragmentVisible) {
|
||||||
// Means that nearby fragment is visible (not contributions fragment)
|
// Means that nearby fragment is visible (not contributions fragment)
|
||||||
NearbyParentFragment nearbyFragment = (NearbyParentFragment) contributionsActivityPagerAdapter.getItem(1);
|
NearbyParentFragment nearbyFragment = (NearbyParentFragment) contributionsActivityPagerAdapter.getItem(1);
|
||||||
nearbyFragment.nearbyParentFragmentPresenter.backButtonClicked();
|
NearbyParentFragmentPresenter.getInstance().backButtonClicked();
|
||||||
} else {
|
} else {
|
||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
private boolean isNetworkErrorOccurred = false;
|
private boolean isNetworkErrorOccurred = false;
|
||||||
private Snackbar snackbar;
|
private Snackbar snackbar;
|
||||||
private View view;
|
private View view;
|
||||||
public NearbyParentFragmentPresenter nearbyParentFragmentPresenter;
|
private NearbyParentFragmentPresenter nearbyParentFragmentPresenter;
|
||||||
private boolean isDarkTheme;
|
private boolean isDarkTheme;
|
||||||
private boolean isFABsExpanded;
|
private boolean isFABsExpanded;
|
||||||
private Marker selectedMarker;
|
private Marker selectedMarker;
|
||||||
|
|
@ -355,7 +355,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
*/
|
*/
|
||||||
private void childMapFragmentAttached() {
|
private void childMapFragmentAttached() {
|
||||||
Timber.d("Child map fragment attached");
|
Timber.d("Child map fragment attached");
|
||||||
nearbyParentFragmentPresenter = new NearbyParentFragmentPresenter
|
nearbyParentFragmentPresenter = NearbyParentFragmentPresenter.getInstance
|
||||||
(nearbyListFragment,this, nearbyMapFragment, locationManager);
|
(nearbyListFragment,this, nearbyMapFragment, locationManager);
|
||||||
nearbyParentFragmentPresenter.nearbyFragmentsAreReady();
|
nearbyParentFragmentPresenter.nearbyFragmentsAreReady();
|
||||||
initViews();
|
initViews();
|
||||||
|
|
|
||||||
|
|
@ -45,10 +45,11 @@ public class NearbyParentFragmentPresenter
|
||||||
private boolean isPortraitMode;
|
private boolean isPortraitMode;
|
||||||
private boolean placesLoadedOnce;
|
private boolean placesLoadedOnce;
|
||||||
|
|
||||||
|
|
||||||
private LocationServiceManager locationServiceManager;
|
private LocationServiceManager locationServiceManager;
|
||||||
|
|
||||||
public NearbyParentFragmentPresenter(NearbyParentFragmentContract.NearbyListView nearbyListFragmentView,
|
public static NearbyParentFragmentPresenter presenterInstance;
|
||||||
|
|
||||||
|
private NearbyParentFragmentPresenter(NearbyParentFragmentContract.NearbyListView nearbyListFragmentView,
|
||||||
NearbyParentFragmentContract.View nearbyParentFragmentView,
|
NearbyParentFragmentContract.View nearbyParentFragmentView,
|
||||||
NearbyMapContract.View nearbyMapFragmentView,
|
NearbyMapContract.View nearbyMapFragmentView,
|
||||||
LocationServiceManager locationServiceManager) {
|
LocationServiceManager locationServiceManager) {
|
||||||
|
|
@ -59,6 +60,25 @@ public class NearbyParentFragmentPresenter
|
||||||
this.locationServiceManager = locationServiceManager;
|
this.locationServiceManager = locationServiceManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static method to create instance of Singleton class
|
||||||
|
public static NearbyParentFragmentPresenter getInstance(NearbyParentFragmentContract.NearbyListView nearbyListFragmentView,
|
||||||
|
NearbyParentFragmentContract.View nearbyParentFragmentView,
|
||||||
|
NearbyMapContract.View nearbyMapFragmentView,
|
||||||
|
LocationServiceManager locationServiceManager) {
|
||||||
|
if (presenterInstance == null) {
|
||||||
|
presenterInstance = new NearbyParentFragmentPresenter(nearbyListFragmentView,
|
||||||
|
nearbyParentFragmentView,
|
||||||
|
nearbyMapFragmentView,
|
||||||
|
locationServiceManager);
|
||||||
|
}
|
||||||
|
return presenterInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We call this method when we are sure presenterInstance is not null
|
||||||
|
public static NearbyParentFragmentPresenter getInstance() {
|
||||||
|
return presenterInstance;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Note: To initialize nearby operations both views should be ready and tab is selected.
|
* Note: To initialize nearby operations both views should be ready and tab is selected.
|
||||||
* Initializes nearby operations if nearby views are ready
|
* Initializes nearby operations if nearby views are ready
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue