Skip to content

Commit 784ee8b

Browse files
neslihanturandomdomegg
authored andcommitted
Fix commons-app#1828: Add missing Javadocs and tidy up code in nearby package (commons-app#2133)
* Add Javadocs * Remove unused variables, methods, fragments, imports, classes
1 parent 5a58454 commit 784ee8b

9 files changed

+122
-158
lines changed

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

-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import fr.free.nrw.commons.nearby.NearbyFragment;
1717
import fr.free.nrw.commons.nearby.NearbyListFragment;
1818
import fr.free.nrw.commons.nearby.NearbyMapFragment;
19-
import fr.free.nrw.commons.nearby.NoPermissionsFragment;
2019
import fr.free.nrw.commons.settings.SettingsFragment;
2120

2221
@Module
@@ -38,9 +37,6 @@ public abstract class FragmentBuilderModule {
3837
@ContributesAndroidInjector
3938
abstract NearbyMapFragment bindNearbyMapFragment();
4039

41-
@ContributesAndroidInjector
42-
abstract NoPermissionsFragment bindNoPermissionsFragment();
43-
4440
@ContributesAndroidInjector
4541
abstract SettingsFragment bindSettingsFragment();
4642

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import android.content.res.Resources;
66
import android.graphics.Bitmap;
77
import android.support.graphics.drawable.VectorDrawableCompat;
8-
import android.util.Log;
98

109
import com.mapbox.mapboxsdk.annotations.IconFactory;
1110

@@ -179,6 +178,9 @@ public static List<NearbyBaseMarker> loadAttractionsFromLocationToBaseMarkerOpti
179178
return baseMarkerOptions;
180179
}
181180

181+
/**
182+
* We pass this variable as a group of placeList and boundaryCoordinates
183+
*/
182184
public class NearbyPlacesInfo {
183185
public List<Place> placeList; // List of nearby places
184186
public LatLng[] boundaryCoordinates; // Corners of nearby area

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

+43-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import android.support.design.widget.Snackbar;
1515
import android.support.v4.app.FragmentTransaction;
1616
import android.support.v7.app.AlertDialog;
17-
import android.util.Log;
1817
import android.view.LayoutInflater;
1918
import android.view.View;
2019
import android.view.ViewGroup;
@@ -211,6 +210,10 @@ public void onSlide(View bottomSheet, float slideOffset) {
211210
bottomSheetBehaviorForDetails.setState(BottomSheetBehavior.STATE_HIDDEN);
212211
}
213212

213+
/**
214+
* Sets camera position, zoom level according to sheet positions
215+
* @param bottomSheetState expanded, collapsed or hidden
216+
*/
214217
public void prepareViewsForSheetPosition(int bottomSheetState) {
215218
// TODO
216219
}
@@ -243,7 +246,7 @@ public void onWikidataEditSuccessful() {
243246
/**
244247
* This method should be the single point to load/refresh nearby places
245248
*
246-
* @param locationChangeType defines if location shanged significantly or slightly
249+
* @param locationChangeType defines if location changed significantly or slightly
247250
*/
248251
public void refreshView(LocationServiceManager.LocationChangeType locationChangeType) {
249252
Timber.d("Refreshing nearby places");
@@ -359,7 +362,6 @@ public void refreshViewForCustomLocation(LatLng customLatLng, boolean refreshFor
359362
* @param nearbyPlacesInfo This variable has place list information and distances.
360363
*/
361364
private void populatePlacesFromCustomLocation(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) {
362-
//NearbyMapFragment nearbyMapFragment = getMapFragment();
363365
if (nearbyMapFragment != null) {
364366
nearbyMapFragment.searchThisAreaButtonProgressBar.setVisibility(View.GONE);
365367
}
@@ -374,6 +376,11 @@ private void populatePlacesFromCustomLocation(NearbyController.NearbyPlacesInfo
374376
}
375377
}
376378

379+
/**
380+
* Turns nearby place lists and boundary coordinates into gson and update map and list fragments
381+
* accordingly
382+
* @param nearbyPlacesInfo a variable holds both nearby place list and boundary coordinates
383+
*/
377384
private void populatePlaces(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) {
378385
Timber.d("Populating nearby places");
379386
List<Place> placeList = nearbyPlacesInfo.placeList;
@@ -390,7 +397,6 @@ private void populatePlaces(NearbyController.NearbyPlacesInfo nearbyPlacesInfo)
390397
}
391398

392399
bundle.putString("PlaceList", gsonPlaceList);
393-
//bundle.putString("CurLatLng", gsonCurLatLng);
394400
bundle.putString("BoundaryCoord", gsonBoundaryCoordinates);
395401

396402
// First time to init fragments
@@ -412,7 +418,7 @@ private void populatePlaces(NearbyController.NearbyPlacesInfo nearbyPlacesInfo)
412418
/**
413419
* Lock nearby view updates while updating map or list. Because we don't want new update calls
414420
* when we already updating for old location update.
415-
* @param lock
421+
* @param lock true if we should lock nearby map
416422
*/
417423
private void lockNearbyView(boolean lock) {
418424
if (lock) {
@@ -426,6 +432,18 @@ private void lockNearbyView(boolean lock) {
426432
}
427433
}
428434

435+
/**
436+
* Updates map fragment,
437+
* For slight update: camera follows users location
438+
* For significant update: nearby markers are removed and new markers added again
439+
* Slight updates stop if user is checking another area of map
440+
*
441+
* @param updateViaButton search this area button is clicked
442+
* @param isSlightUpdate Means no need to update markers, just follow user location with camera
443+
* @param customLatLng Will be used for updates for other locations than users current location.
444+
* Ie. when we use search this area feature
445+
* @param nearbyPlacesInfo Includes nearby places list and boundary coordinates
446+
*/
429447
private void updateMapFragment(boolean updateViaButton, boolean isSlightUpdate, @Nullable LatLng customLatLng, @Nullable NearbyController.NearbyPlacesInfo nearbyPlacesInfo) {
430448

431449
if (nearbyMapFragment.searchThisAreaModeOn) {
@@ -499,6 +517,10 @@ private void updateMapFragment(boolean updateViaButton, boolean isSlightUpdate,
499517
}
500518
}
501519

520+
/**
521+
* Updates already existing list fragment with bundle includes nearby places and boundary
522+
* coordinates
523+
*/
502524
private void updateListFragment() {
503525
nearbyListFragment.setBundleForUpdates(bundle);
504526
nearbyListFragment.updateNearbyListSignificantly();
@@ -537,6 +559,9 @@ private void setListFragment() {
537559
fragmentTransaction.commitAllowingStateLoss();
538560
}
539561

562+
/**
563+
* Hides progress bar
564+
*/
540565
private void hideProgressBar() {
541566
if (progressBar != null) {
542567
progressBar.setVisibility(View.GONE);
@@ -576,12 +601,18 @@ private void registerLocationUpdates() {
576601
}
577602
}
578603

604+
/**
605+
* Requests location permission if activity is not null
606+
*/
579607
private void requestLocationPermissions() {
580608
if (!getActivity().isFinishing()) {
581609
locationManager.requestPermissions(getActivity());
582610
}
583611
}
584612

613+
/**
614+
* Will warn user if location is denied
615+
*/
585616
private void showLocationPermissionDeniedErrorDialog() {
586617
new AlertDialog.Builder(getActivity())
587618
.setMessage(R.string.nearby_needs_permissions)
@@ -671,6 +702,9 @@ private void showErrorMessage(String message) {
671702
ViewUtil.showLongToast(getActivity(), message);
672703
}
673704

705+
/**
706+
* Adds network broadcast receiver to recognize connection established
707+
*/
674708
private void addNetworkBroadcastReceiver() {
675709
if (!FragmentUtils.isFragmentUIActive(this)) {
676710
return;
@@ -708,6 +742,10 @@ public void onResume() {
708742
resumeFragment();
709743
}
710744

745+
/**
746+
* Perform nearby operations on nearby tab selected
747+
* @param onOrientationChanged pass orientation changed info to fragment
748+
*/
711749
public void onTabSelected(boolean onOrientationChanged) {
712750
Timber.d("On nearby tab selected");
713751
this.onOrientationChanged = onOrientationChanged;

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

+15-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
9292
recyclerView.setAdapter(adapterFactory.create(getPlaceListFromBundle(bundle)));
9393
}
9494

95+
/**
96+
* Updates nearby list elements all together
97+
*/
9598
public void updateNearbyListSignificantly() {
9699
try {
97100
adapterFactory.updateAdapterData(getPlaceListFromBundle(bundleForUpdates), (RVRendererAdapter<Place>) recyclerView.getAdapter());
@@ -103,7 +106,7 @@ public void updateNearbyListSignificantly() {
103106
/**
104107
* While nearby updates for current location held with bundle, automatically, custom updates are
105108
* done by calling this methods, triddered by search this are button input from user.
106-
* @param placeList
109+
* @param placeList List of nearby places to be added list fragment
107110
*/
108111
public void updateNearbyListSignificantlyForCustomLocation(List<Place> placeList) {
109112
try {
@@ -113,6 +116,13 @@ public void updateNearbyListSignificantlyForCustomLocation(List<Place> placeList
113116
}
114117
}
115118

119+
/**
120+
* When user moved too much, we need to update nearby list too. This operation is made by passing
121+
* a bundle from NearbyFragment to NearbyListFragment and NearbyMapFragment. This method extracts
122+
* place list from bundle to a list variable.
123+
* @param bundle Bundle passed from NearbyFragment on users significant moving
124+
* @return List of new nearby places
125+
*/
116126
private List<Place> getPlaceListFromBundle(Bundle bundle) {
117127
List<Place> placeList = Collections.emptyList();
118128

@@ -176,6 +186,10 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
176186
}
177187
}
178188

189+
/**
190+
* Sets bundles for updates in map. Ie. user is moved too much so we need to update nearby markers.
191+
* @param bundleForUpdates includes new calculated nearby places.
192+
*/
179193
public void setBundleForUpdates(Bundle bundleForUpdates) {
180194
this.bundleForUpdates = bundleForUpdates;
181195
}

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

+25-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import android.support.design.widget.CoordinatorLayout;
1616
import android.support.design.widget.FloatingActionButton;
1717
import android.support.v7.app.AlertDialog;
18-
import android.util.Log;
1918
import android.view.Gravity;
2019
import android.view.KeyEvent;
2120
import android.view.LayoutInflater;
@@ -62,7 +61,7 @@
6261
import fr.free.nrw.commons.auth.LoginActivity;
6362
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
6463
import fr.free.nrw.commons.contributions.ContributionController;
65-
import fr.free.nrw.commons.location.LocationServiceManager;
64+
6665
import fr.free.nrw.commons.utils.LocationUtils;
6766
import fr.free.nrw.commons.utils.PlaceUtils;
6867
import fr.free.nrw.commons.utils.UriDeserializer;
@@ -130,7 +129,6 @@ public class NearbyMapFragment extends DaggerFragment {
130129
private final double CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT = 0.06;
131130
private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.04;
132131

133-
private boolean isMapReady;
134132
public boolean searchThisAreaModeOn = false;
135133

136134
private Bundle bundleForUpdtes;// Carry information from activity about changed nearby places and current location
@@ -361,7 +359,10 @@ private void updateMapToTrackPosition() {
361359
}
362360
}
363361
}
364-
362+
363+
/**
364+
* Initialize all views. TODO: Use bind view instead.
365+
*/
365366
private void initViews() {
366367
Timber.d("initViews called");
367368
bottomSheetList = ((NearbyFragment)getParentFragment()).view.findViewById(R.id.bottom_sheet);
@@ -406,6 +407,9 @@ private void initViews() {
406407

407408
}
408409

410+
/**
411+
* Sets click listeners of FABs, and 2 bottom sheets
412+
*/
409413
private void setListeners() {
410414
fabPlus.setOnClickListener(view -> {
411415
if (applicationPrefs.getBoolean("login_skipped", false)) {
@@ -512,6 +516,10 @@ public void onSlide(@NonNull View bottomSheet, float slideOffset) {
512516
}
513517
}
514518

519+
/**
520+
* Sets up map view of first time it created, it passes MapBoxMap options and style assets.
521+
* @param savedInstanceState bundle coming from Nearby Fragment
522+
*/
515523
private void setupMapView(Bundle savedInstanceState) {
516524
Timber.d("setupMapView called");
517525
MapboxMapOptions options = new MapboxMapOptions()
@@ -541,6 +549,10 @@ public void onMapReady(MapboxMap mapboxMap) {
541549
}
542550
}
543551

552+
/**
553+
* Adds map movement listener to understand swiping with fingers. So that we can display search
554+
* this area button to search nearby places for other locations
555+
*/
544556
private void addMapMovementListeners() {
545557

546558
mapboxMap.addOnCameraMoveListener(new MapboxMap.OnCameraMoveListener() {
@@ -793,9 +805,7 @@ private void showFAB() {
793805
addAnchorToSmallFABs(fabGallery, ((NearbyFragment)getParentFragment()).view.findViewById(R.id.empty_view).getId());
794806

795807
addAnchorToSmallFABs(fabCamera, ((NearbyFragment)getParentFragment()).view.findViewById(R.id.empty_view1).getId());
796-
797-
isMapReady = true;
798-
}
808+
}
799809

800810

801811
/*
@@ -946,6 +956,10 @@ private void openWebView(Uri link) {
946956
Utils.handleWebUrl(getContext(), link);
947957
}
948958

959+
/**
960+
* Starts animation of fab plus (turning on opening) and other FABs
961+
* @param isFabOpen state of FAB buttons, open when clicked on fab button, closed on other click
962+
*/
949963
private void animateFAB(boolean isFabOpen) {
950964
this.isFabOpen = !isFabOpen;
951965
if (fabPlus.isShown()){
@@ -966,6 +980,10 @@ private void animateFAB(boolean isFabOpen) {
966980
}
967981
}
968982

983+
/**
984+
* Hides camera and gallery FABs, turn back plus FAB
985+
* @param isFabOpen
986+
*/
969987
private void closeFabs ( boolean isFabOpen){
970988
if (isFabOpen) {
971989
fabPlus.startAnimation(rotate_backward);

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

-18
This file was deleted.

0 commit comments

Comments
 (0)