Skip to content

Commit 05e9830

Browse files
* Fixes commons-app#3303 * Refactor Nearby to alig lifecycle methods * Pass updated place list to listfragment * Added default zoom rate to mapbox * Removed NearbyListFragmet and added the ui login to handle the same in NearbyParentFragment * More code refactor * Make BottomSheetList hideable * onFragmentHide, hide the bottom sheets * BigFix, Fragmet visibility, register/un-register camera move based on fragments lifecycke * More code refactor * Let the ExecutorUtil have non-ui thread * Add Location Marker on non-ui thread (the non-ui stuffs) * BugFixes * Removed configchanges "orientation" from MainActivity in Manifest (That was messing with the fragment lifecycle) * Some null checks * Initialise lastknown location in onMapReady * UI Fixes * Adjusted UI to support dark and no-dark themes both (in nearby) * Do not update map on Location Slightly changed * Fix failing test case, let TestCommonsApplication extend Application instead of CommonsApplication * start map view when nearby is visible * start the map when NearbyFragmet is visible * More bugfixes * Added DUMMY view for NearbyPresenter's onDetach State * Added a wrapper frame layout parent for MapView to preven it from drawing above other views * More bugfixes (Fixes commons-app#3287) * Gray out the un-selected markers from the nearby filter list * BugFix, search this area should search the nearby places for the current camera position * More BugFixes * Handle null primitives with proxy * Current location marker flow via permission flow * onCameraMove should have null-check on NearbyController.latestSearchLocation instead of currentLocation * Search for places around last focus location * Handle location updates * If the user is browsing the map, donot update the map with current location
1 parent a6d2523 commit 05e9830

25 files changed

+909
-1248
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'
@@ -102,6 +102,7 @@ dependencies {
102102

103103
//swipe_layout
104104
implementation 'com.daimajia.swipelayout:library:1.2.0@aar'
105+
implementation 'com.squareup.retrofit2:retrofit:2.7.1'
105106
}
106107

107108
android {

app/src/main/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
android:name=".contributions.MainActivity"
7979
android:icon="@mipmap/ic_launcher"
8080
android:label="@string/app_name"
81-
android:configChanges="orientation|screenSize|keyboard" />
81+
android:configChanges="screenSize|keyboard" />
8282
<activity
8383
android:name=".settings.SettingsActivity"
8484
android:label="@string/title_activity_settings" />

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

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.facebook.imagepipeline.producers.FetchState;
2020
import com.facebook.imagepipeline.producers.NetworkFetcher;
2121
import com.facebook.imagepipeline.producers.ProducerContext;
22+
import com.mapbox.mapboxsdk.Mapbox;
2223
import com.squareup.leakcanary.LeakCanary;
2324
import com.squareup.leakcanary.RefWatcher;
2425

@@ -134,6 +135,7 @@ public void onCreate() {
134135

135136
INSTANCE = this;
136137
ACRA.init(this);
138+
Mapbox.getInstance(this, getString(R.string.mapbox_commons_app_token));
137139

138140
ApplicationlessInjection
139141
.getInstance(this)

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import fr.free.nrw.commons.location.LocationServiceManager;
3636
import fr.free.nrw.commons.nearby.NearbyNotificationCardView;
3737
import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment;
38-
import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter;
3938
import fr.free.nrw.commons.notification.Notification;
4039
import fr.free.nrw.commons.notification.NotificationActivity;
4140
import fr.free.nrw.commons.notification.NotificationController;
@@ -78,6 +77,7 @@ public class MainActivity extends NavigationBaseActivity implements FragmentMana
7877

7978
private MenuItem notificationsMenuItem;
8079
private TextView notificationCount;
80+
private NearbyParentFragment nearbyParentFragment;
8181

8282
public void onCreate(Bundle savedInstanceState) {
8383
super.onCreate(savedInstanceState);
@@ -188,8 +188,6 @@ public void onPageSelected(int position) {
188188
tabLayout.getTabAt(NEARBY_TAB_POSITION).select();
189189
isContributionsFragmentVisible = false;
190190
updateMenuItem();
191-
// Do all permission and GPS related tasks on tab selected, not on create
192-
NearbyParentFragmentPresenter.getInstance().onTabSelected();
193191
break;
194192
default:
195193
tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select();
@@ -265,7 +263,9 @@ public void onBackPressed() {
265263
}
266264
} else if (getSupportFragmentManager().findFragmentByTag(nearbyFragmentTag) != null && !isContributionsFragmentVisible) {
267265
// Means that nearby fragment is visible (not contributions fragment)
268-
NearbyParentFragmentPresenter.getInstance().backButtonClicked();
266+
if (null != nearbyParentFragment) {
267+
nearbyParentFragment.backButtonClicked();
268+
}
269269
} else {
270270
super.onBackPressed();
271271
}
@@ -380,12 +380,13 @@ public Fragment getItem(int position) {
380380
}
381381

382382
case 1:
383-
NearbyParentFragment retainedNearbyFragment = getNearbyFragment(1);
384-
if (retainedNearbyFragment != null) {
385-
return retainedNearbyFragment;
383+
nearbyParentFragment = getNearbyFragment(1);
384+
if (nearbyParentFragment != null) {
385+
return nearbyParentFragment;
386386
} else {
387387
// If we reach here, retainedNearbyFragment is null
388-
return new NearbyParentFragment();
388+
nearbyParentFragment=new NearbyParentFragment();
389+
return nearbyParentFragment;
389390
}
390391
default:
391392
return null;

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

-8
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import fr.free.nrw.commons.explore.recentsearches.RecentSearchesFragment;
1414
import fr.free.nrw.commons.media.MediaDetailFragment;
1515
import fr.free.nrw.commons.media.MediaDetailPagerFragment;
16-
import fr.free.nrw.commons.nearby.fragments.NearbyListFragment;
17-
import fr.free.nrw.commons.nearby.fragments.NearbyMapFragment;
1816
import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment;
1917
import fr.free.nrw.commons.review.ReviewImageFragment;
2018
import fr.free.nrw.commons.settings.SettingsFragment;
@@ -40,9 +38,6 @@ public abstract class FragmentBuilderModule {
4038
@ContributesAndroidInjector
4139
abstract MediaDetailPagerFragment bindMediaDetailPagerFragment();
4240

43-
@ContributesAndroidInjector
44-
abstract NearbyListFragment bindNearbyListFragment();
45-
4641
@ContributesAndroidInjector
4742
abstract SettingsFragment bindSettingsFragment();
4843

@@ -64,9 +59,6 @@ public abstract class FragmentBuilderModule {
6459
@ContributesAndroidInjector
6560
abstract ContributionsFragment bindContributionsFragment();
6661

67-
@ContributesAndroidInjector
68-
abstract NearbyMapFragment bindNearbyMapFragment();
69-
7062
@ContributesAndroidInjector
7163
abstract NearbyParentFragment bindNearbyParentFragment();
7264

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/NearbyAdapterFactory.java

-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ public class NearbyAdapterFactory {
1717
private Fragment fragment;
1818
private ContributionController controller;
1919

20-
NearbyAdapterFactory(){
21-
22-
}
23-
2420
public NearbyAdapterFactory(Fragment fragment, ContributionController controller) {
2521
this.fragment = fragment;
2622
this.controller = controller;

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

+17-8
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,24 @@ public class NearbyFilterSearchRecyclerViewAdapter
2727

2828
private final LayoutInflater inflater;
2929
private Context context;
30-
private RecyclerView recyclerView;
3130
private ArrayList<Label> labels;
3231
private ArrayList<Label> displayedLabels;
3332
public ArrayList<Label> selectedLabels = new ArrayList<>();
3433

3534
private int state;
3635

36+
private Callback callback;
37+
3738
RecyclerView.SmoothScroller smoothScroller;
3839

40+
public void setCallback(Callback callback) {
41+
this.callback = callback;
42+
}
43+
3944
public NearbyFilterSearchRecyclerViewAdapter(Context context, ArrayList<Label> labels, RecyclerView recyclerView) {
4045
this.context = context;
4146
this.labels = labels;
4247
this.displayedLabels = labels;
43-
this.recyclerView = recyclerView;
4448
smoothScroller = new
4549
LinearSmoothScroller(context) {
4650
@Override protected int getVerticalSnapPreference() {
@@ -66,7 +70,7 @@ public RecyclerViewHolder(View view) {
6670
@NonNull
6771
@Override
6872
public RecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
69-
View itemView = inflater.inflate(R.layout.nearby_search_list_item, parent, false);
73+
View itemView = inflater.inflate(callback.isDarkTheme()?R.layout.nearby_search_list_item_dark:R.layout.nearby_search_list_item, parent, false);
7074
return new RecyclerViewHolder(itemView);
7175
}
7276

@@ -76,17 +80,17 @@ public void onBindViewHolder(@NonNull RecyclerViewHolder holder, int position) {
7680
holder.placeTypeIcon.setImageResource(label.getIcon());
7781
holder.placeTypeLabel.setText(label.toString());
7882

79-
holder.placeTypeLayout.setBackgroundColor(label.isSelected() ? ContextCompat.getColor(context, R.color.divider_grey) : Color.WHITE);
83+
holder.placeTypeLayout.setBackgroundColor(label.isSelected() ? ContextCompat.getColor(context, R.color.divider_grey) : callback.isDarkTheme()?Color.BLACK:Color.WHITE);
8084
holder.placeTypeLayout.setOnClickListener(view -> {
81-
NearbyParentFragmentPresenter.getInstance().setCheckboxUnknown();
85+
callback.setCheckboxUnknown();
8286
if (label.isSelected()) {
8387
selectedLabels.remove(label);
8488
} else {
8589
selectedLabels.add(label);
8690
}
8791
label.setSelected(!label.isSelected());
8892
holder.placeTypeLayout.setBackgroundColor(label.isSelected() ? ContextCompat.getColor(context, R.color.divider_grey) : Color.WHITE);
89-
NearbyParentFragmentPresenter.getInstance().filterByMarkerType(selectedLabels, 0, false, false);
93+
callback.filterByMarkerType(selectedLabels, 0, false, false);
9094
});
9195
}
9296

@@ -161,8 +165,13 @@ public void setRecyclerViewAdapterAllSelected() {
161165
notifyDataSetChanged();
162166
}
163167

164-
public void setRecyclerViewAdapterNeutral() {
165-
state = CheckBoxTriStates.UNKNOWN;
168+
public interface Callback{
169+
170+
void setCheckboxUnknown();
171+
172+
void filterByMarkerType(ArrayList<Label> selectedLabels, int i, boolean b, boolean b1);
173+
174+
boolean isDarkTheme();
166175
}
167176

168177
}

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

+2-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@
3434
import fr.free.nrw.commons.contributions.ContributionController;
3535
import fr.free.nrw.commons.di.ApplicationlessInjection;
3636
import fr.free.nrw.commons.kvstore.JsonKvStore;
37-
import fr.free.nrw.commons.nearby.fragments.NearbyMapFragment;
3837
import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment;
3938
import timber.log.Timber;
4039

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

@@ -121,7 +119,7 @@ protected void hookListeners(View view) {
121119
}
122120
}
123121
if (onBookmarkClick == null) {
124-
((NearbyParentFragment) fragment.getParentFragment()).centerMapToPlace(place);
122+
((NearbyParentFragment) fragment).centerMapToPlace(place);
125123
}
126124
};
127125
view.setOnClickListener(listener);
@@ -194,8 +192,7 @@ protected void hookListeners(View view) {
194192
onBookmarkClick.onClick();
195193
}
196194
else {
197-
((NearbyMapFragment)(fragment.getParentFragment()).getChildFragmentManager().
198-
findFragmentByTag(TAG_RETAINED_MAP_FRAGMENT)).
195+
((NearbyParentFragment) (fragment.getParentFragment())).
199196
updateMarker(isBookmarked, place, null);
200197
}
201198
}

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

-36
This file was deleted.

0 commit comments

Comments
 (0)