Skip to content

Commit caaadbf

Browse files
* Refactor Nearby to alig lifecycle methods
1 parent 349e51f commit caaadbf

14 files changed

+677
-1048
lines changed

app/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ dependencies {
3636
implementation 'fr.avianey.com.viewpagerindicator:library:2.4.1.1@aar'
3737
implementation 'com.github.chrisbanes:PhotoView:2.0.0'
3838
implementation 'com.github.pedrovgs:renderers:3.3.3'
39-
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:7.2.0'
39+
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:8.6.1'
4040
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v7:0.7.0'
4141
implementation 'com.github.deano2390:MaterialShowcaseView:1.2.0'
4242
implementation 'com.dinuscxj:circleprogressbar:1.1.1'
@@ -95,6 +95,7 @@ dependencies {
9595

9696
//swipe_layout
9797
implementation 'com.daimajia.swipelayout:library:1.2.0@aar'
98+
implementation 'com.squareup.retrofit2:retrofit:2.7.1'
9899
}
99100

100101
android {

app/src/main/java/fr/free/nrw/commons/CommonsApplication.java

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.facebook.drawee.backends.pipeline.Fresco;
1616
import com.facebook.imagepipeline.core.ImagePipeline;
1717
import com.facebook.imagepipeline.core.ImagePipelineConfig;
18+
import com.mapbox.mapboxsdk.Mapbox;
1819
import com.squareup.leakcanary.LeakCanary;
1920
import com.squareup.leakcanary.RefWatcher;
2021

@@ -123,6 +124,7 @@ public void onCreate() {
123124

124125
INSTANCE = this;
125126
ACRA.init(this);
127+
Mapbox.getInstance(this, getString(R.string.mapbox_commons_app_token));
126128

127129
ApplicationlessInjection
128130
.getInstance(this)

app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import fr.free.nrw.commons.location.LocationServiceManager;
3131
import fr.free.nrw.commons.nearby.NearbyNotificationCardView;
3232
import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment;
33-
import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter;
3433
import fr.free.nrw.commons.notification.Notification;
3534
import fr.free.nrw.commons.notification.NotificationActivity;
3635
import fr.free.nrw.commons.notification.NotificationController;
@@ -72,6 +71,7 @@ public class MainActivity extends NavigationBaseActivity implements FragmentMana
7271

7372
private MenuItem notificationsMenuItem;
7473
private TextView notificationCount;
74+
private NearbyParentFragment nearbyParentFragment;
7575

7676
public void onCreate(Bundle savedInstanceState) {
7777
super.onCreate(savedInstanceState);
@@ -181,8 +181,6 @@ public void onPageSelected(int position) {
181181
tabLayout.getTabAt(NEARBY_TAB_POSITION).select();
182182
isContributionsFragmentVisible = false;
183183
updateMenuItem();
184-
// Do all permission and GPS related tasks on tab selected, not on create
185-
NearbyParentFragmentPresenter.getInstance().onTabSelected();
186184
break;
187185
default:
188186
tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select();
@@ -258,7 +256,9 @@ public void onBackPressed() {
258256
}
259257
} else if (getSupportFragmentManager().findFragmentByTag(nearbyFragmentTag) != null && !isContributionsFragmentVisible) {
260258
// Means that nearby fragment is visible (not contributions fragment)
261-
NearbyParentFragmentPresenter.getInstance().backButtonClicked();
259+
if (null != nearbyParentFragment) {
260+
nearbyParentFragment.backButtonClicked();
261+
}
262262
} else {
263263
super.onBackPressed();
264264
}
@@ -373,12 +373,13 @@ public Fragment getItem(int position) {
373373
}
374374

375375
case 1:
376-
NearbyParentFragment retainedNearbyFragment = getNearbyFragment(1);
377-
if (retainedNearbyFragment != null) {
378-
return retainedNearbyFragment;
376+
nearbyParentFragment = getNearbyFragment(1);
377+
if (nearbyParentFragment != null) {
378+
return nearbyParentFragment;
379379
} else {
380380
// If we reach here, retainedNearbyFragment is null
381-
return new NearbyParentFragment();
381+
nearbyParentFragment=new NearbyParentFragment();
382+
return nearbyParentFragment;
382383
}
383384
default:
384385
return null;

app/src/main/java/fr/free/nrw/commons/di/FragmentBuilderModule.java

-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import fr.free.nrw.commons.media.MediaDetailFragment;
1515
import fr.free.nrw.commons.media.MediaDetailPagerFragment;
1616
import fr.free.nrw.commons.nearby.fragments.NearbyListFragment;
17-
import fr.free.nrw.commons.nearby.fragments.NearbyMapFragment;
1817
import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment;
1918
import fr.free.nrw.commons.review.ReviewImageFragment;
2019
import fr.free.nrw.commons.settings.SettingsFragment;
@@ -59,9 +58,6 @@ public abstract class FragmentBuilderModule {
5958
@ContributesAndroidInjector
6059
abstract ContributionsFragment bindContributionsFragment();
6160

62-
@ContributesAndroidInjector
63-
abstract NearbyMapFragment bindNearbyMapFragment();
64-
6561
@ContributesAndroidInjector
6662
abstract NearbyParentFragment bindNearbyParentFragment();
6763

app/src/main/java/fr/free/nrw/commons/nearby/CheckBoxTriStates.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import androidx.annotation.Nullable;
1010
import androidx.appcompat.widget.AppCompatCheckBox;
1111

12+
import java.util.List;
13+
1214
import fr.free.nrw.commons.R;
1315
import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter;
1416

@@ -25,6 +27,16 @@ public class CheckBoxTriStates extends AppCompatCheckBox {
2527

2628
private int state;
2729

30+
private Callback callback;
31+
32+
public interface Callback{
33+
void filterByMarkerType(@Nullable List<Label> selectedLabels, int state, boolean b, boolean b1);
34+
}
35+
36+
public void setCallback(Callback callback) {
37+
this.callback = callback;
38+
}
39+
2840
/**
2941
* This is the listener set to the super class which is going to be evoke each
3042
* time the check state has changed.
@@ -87,7 +99,7 @@ public void setState(int state) {
8799
}
88100

89101
if (NearbyController.currentLocation != null) {
90-
NearbyParentFragmentPresenter.getInstance().filterByMarkerType(null, state, false, true);
102+
callback.filterByMarkerType(null, state, false, true);
91103
}
92104
updateBtn();
93105
}

app/src/main/java/fr/free/nrw/commons/nearby/NearbyFilterSearchRecyclerViewAdapter.java

+15-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,14 @@ public class NearbyFilterSearchRecyclerViewAdapter
3535

3636
private int state;
3737

38+
private Callback callback;
39+
3840
RecyclerView.SmoothScroller smoothScroller;
3941

42+
public void setCallback(Callback callback) {
43+
this.callback = callback;
44+
}
45+
4046
public NearbyFilterSearchRecyclerViewAdapter(Context context, ArrayList<Label> labels, RecyclerView recyclerView) {
4147
this.context = context;
4248
this.labels = labels;
@@ -79,15 +85,15 @@ public void onBindViewHolder(@NonNull RecyclerViewHolder holder, int position) {
7985

8086
holder.placeTypeLayout.setBackgroundColor(label.isSelected() ? ContextCompat.getColor(context, R.color.divider_grey) : Color.WHITE);
8187
holder.placeTypeLayout.setOnClickListener(view -> {
82-
NearbyParentFragmentPresenter.getInstance().setCheckboxUnknown();
88+
callback.setCheckboxUnknown();
8389
if (label.isSelected()) {
8490
selectedLabels.remove(label);
8591
} else {
8692
selectedLabels.add(label);
8793
}
8894
label.setSelected(!label.isSelected());
8995
holder.placeTypeLayout.setBackgroundColor(label.isSelected() ? ContextCompat.getColor(context, R.color.divider_grey) : Color.WHITE);
90-
NearbyParentFragmentPresenter.getInstance().filterByMarkerType(selectedLabels, 0, false, false);
96+
callback.filterByMarkerType(selectedLabels, 0, false, false);
9197
});
9298
}
9399

@@ -166,4 +172,11 @@ public void setRecyclerViewAdapterNeutral() {
166172
state = CheckBoxTriStates.UNKNOWN;
167173
}
168174

175+
public interface Callback{
176+
177+
void setCheckboxUnknown();
178+
179+
void filterByMarkerType(ArrayList<Label> selectedLabels, int i, boolean b, boolean b1);
180+
}
181+
169182
}

app/src/main/java/fr/free/nrw/commons/nearby/PlaceRenderer.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@
3333
import fr.free.nrw.commons.contributions.ContributionController;
3434
import fr.free.nrw.commons.di.ApplicationlessInjection;
3535
import fr.free.nrw.commons.kvstore.JsonKvStore;
36-
import fr.free.nrw.commons.nearby.fragments.NearbyMapFragment;
3736
import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment;
3837
import timber.log.Timber;
3938

40-
import static fr.free.nrw.commons.nearby.fragments.NearbyParentFragment.TAG_RETAINED_MAP_FRAGMENT;
4139
import static fr.free.nrw.commons.theme.NavigationBaseActivity.startActivityWithFlags;
4240
import static fr.free.nrw.commons.wikidata.WikidataConstants.PLACE_OBJECT;
4341

@@ -193,8 +191,7 @@ protected void hookListeners(View view) {
193191
onBookmarkClick.onClick();
194192
}
195193
else {
196-
((NearbyMapFragment)(fragment.getParentFragment()).getChildFragmentManager().
197-
findFragmentByTag(TAG_RETAINED_MAP_FRAGMENT)).
194+
((NearbyParentFragment) (fragment.getParentFragment())).
198195
updateMarker(isBookmarked, place, null);
199196
}
200197
}

app/src/main/java/fr/free/nrw/commons/nearby/contract/NearbyMapContract.java

-36
This file was deleted.

app/src/main/java/fr/free/nrw/commons/nearby/contract/NearbyParentFragmentContract.java

+37-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package fr.free.nrw.commons.nearby.contract;
22

3+
import android.content.Context;
4+
35
import com.mapbox.mapboxsdk.annotations.Marker;
46
import com.mapbox.mapboxsdk.maps.MapboxMap;
57

@@ -9,16 +11,17 @@
911
import fr.free.nrw.commons.location.LatLng;
1012
import fr.free.nrw.commons.location.LocationServiceManager;
1113
import fr.free.nrw.commons.nearby.Label;
14+
import fr.free.nrw.commons.nearby.NearbyBaseMarker;
1215
import fr.free.nrw.commons.nearby.Place;
16+
import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter;
1317

1418
public interface NearbyParentFragmentContract {
1519

1620
interface View {
1721
void registerLocationUpdates(LocationServiceManager locationServiceManager);
1822
boolean isNetworkConnectionEstablished();
19-
void addNetworkBroadcastReceiver();
2023
void listOptionMenuItemClicked();
21-
void populatePlaces(LatLng curlatLng, LatLng searchLatLng);
24+
void populatePlaces(LatLng curlatLng);
2225
boolean isListBottomSheetExpanded();
2326
void checkPermissionsAndPerformAction(Runnable runnable);
2427
void displayLoginSkippedWarning();
@@ -29,7 +32,7 @@ interface View {
2932
void hideBottomSheet();
3033
void hideBottomDetailsSheet();
3134
void displayBottomSheetWithInfo(Marker marker);
32-
void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener);
35+
void addOnCameraMoveListener();
3336
void addSearchThisAreaButtonAction();
3437
void setSearchThisAreaButtonVisibility(boolean isVisible);
3538
void setProgressBarVisibility(boolean isVisible);
@@ -44,26 +47,49 @@ interface View {
4447
void setFilterState();
4548
void disableFABRecenter();
4649
void enableFABRecenter();
50+
void addCurrentLocationMarker(LatLng curLatLng);
51+
52+
void updateMapToTrackPosition(LatLng curLatLng);
53+
54+
Context getContext();
55+
56+
void updateMapMarkers(List<NearbyBaseMarker> nearbyBaseMarkers, Marker selectedMarker);
57+
58+
void filterOutAllMarkers();
59+
60+
void displayAllMarkers();
61+
62+
void filterMarkersByLabels(List<Label> selectedLabels, boolean existsSelected, boolean needPhotoSelected, boolean filterForPlaceState, boolean filterForAllNoneType);
63+
64+
LatLng getCameraTarget();
65+
66+
void centerMapToPlace(Place placeToCenter);
67+
68+
void updateListFragment(List<Place> placeList);
69+
70+
LatLng getLastLocation();
4771
}
4872

4973
interface NearbyListView {
5074
void updateListFragment(List<Place> placeList);
5175
}
5276

5377
interface UserActions {
54-
void onTabSelected();
55-
void checkForPermission();
56-
void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType, LatLng cameraTarget);
78+
void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType);
5779
void lockUnlockNearby(boolean isNearbyLocked);
80+
81+
void attachView(View view);
82+
83+
void detachView();
84+
5885
void setActionListeners(JsonKvStore applicationKvStore);
5986
void backButtonClicked();
60-
MapboxMap.OnCameraMoveListener onCameraMove(MapboxMap mapboxMap);
87+
void onCameraMove(com.mapbox.mapboxsdk.geometry.LatLng latLng);
6188
void filterByMarkerType(List<Label> selectedLabels, int state, boolean filterForPlaceState, boolean filterForAllNoneType);
89+
90+
void updateMapMarkersToController(List<NearbyBaseMarker> nearbyBaseMarkers);
91+
6292
void searchViewGainedFocus();
6393
void setCheckboxUnknown();
6494
}
65-
66-
interface ViewsAreReadyCallback {
67-
void nearbyFragmentsAreReady();
68-
}
6995
}

app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyListFragment.java

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public class NearbyListFragment extends CommonsDaggerSupportFragment implements
4444
@Override
4545
public void onCreate(Bundle savedInstanceState) {
4646
super.onCreate(savedInstanceState);
47-
setRetainInstance(true);
4847
}
4948

5049
@Override

0 commit comments

Comments
 (0)