Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Refactor Nearby to alig lifecycle methods
  • Loading branch information
ashishkumar468 committed Jan 12, 2020
1 parent 349e51f commit caaadbf
Show file tree
Hide file tree
Showing 14 changed files with 677 additions and 1,048 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies {
implementation 'fr.avianey.com.viewpagerindicator:library:2.4.1.1@aar'
implementation 'com.github.chrisbanes:PhotoView:2.0.0'
implementation 'com.github.pedrovgs:renderers:3.3.3'
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:7.2.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:8.6.1'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v7:0.7.0'
implementation 'com.github.deano2390:MaterialShowcaseView:1.2.0'
implementation 'com.dinuscxj:circleprogressbar:1.1.1'
Expand Down Expand Up @@ -95,6 +95,7 @@ dependencies {

//swipe_layout
implementation 'com.daimajia.swipelayout:library:1.2.0@aar'
implementation 'com.squareup.retrofit2:retrofit:2.7.1'
}

android {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/CommonsApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.imagepipeline.core.ImagePipeline;
import com.facebook.imagepipeline.core.ImagePipelineConfig;
import com.mapbox.mapboxsdk.Mapbox;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;

Expand Down Expand Up @@ -123,6 +124,7 @@ public void onCreate() {

INSTANCE = this;
ACRA.init(this);
Mapbox.getInstance(this, getString(R.string.mapbox_commons_app_token));

ApplicationlessInjection
.getInstance(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import fr.free.nrw.commons.location.LocationServiceManager;
import fr.free.nrw.commons.nearby.NearbyNotificationCardView;
import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment;
import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter;
import fr.free.nrw.commons.notification.Notification;
import fr.free.nrw.commons.notification.NotificationActivity;
import fr.free.nrw.commons.notification.NotificationController;
Expand Down Expand Up @@ -72,6 +71,7 @@ public class MainActivity extends NavigationBaseActivity implements FragmentMana

private MenuItem notificationsMenuItem;
private TextView notificationCount;
private NearbyParentFragment nearbyParentFragment;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -181,8 +181,6 @@ public void onPageSelected(int position) {
tabLayout.getTabAt(NEARBY_TAB_POSITION).select();
isContributionsFragmentVisible = false;
updateMenuItem();
// Do all permission and GPS related tasks on tab selected, not on create
NearbyParentFragmentPresenter.getInstance().onTabSelected();
break;
default:
tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select();
Expand Down Expand Up @@ -258,7 +256,9 @@ public void onBackPressed() {
}
} else if (getSupportFragmentManager().findFragmentByTag(nearbyFragmentTag) != null && !isContributionsFragmentVisible) {
// Means that nearby fragment is visible (not contributions fragment)
NearbyParentFragmentPresenter.getInstance().backButtonClicked();
if (null != nearbyParentFragment) {
nearbyParentFragment.backButtonClicked();
}
} else {
super.onBackPressed();
}
Expand Down Expand Up @@ -373,12 +373,13 @@ public Fragment getItem(int position) {
}

case 1:
NearbyParentFragment retainedNearbyFragment = getNearbyFragment(1);
if (retainedNearbyFragment != null) {
return retainedNearbyFragment;
nearbyParentFragment = getNearbyFragment(1);
if (nearbyParentFragment != null) {
return nearbyParentFragment;
} else {
// If we reach here, retainedNearbyFragment is null
return new NearbyParentFragment();
nearbyParentFragment=new NearbyParentFragment();
return nearbyParentFragment;
}
default:
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import fr.free.nrw.commons.media.MediaDetailFragment;
import fr.free.nrw.commons.media.MediaDetailPagerFragment;
import fr.free.nrw.commons.nearby.fragments.NearbyListFragment;
import fr.free.nrw.commons.nearby.fragments.NearbyMapFragment;
import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment;
import fr.free.nrw.commons.review.ReviewImageFragment;
import fr.free.nrw.commons.settings.SettingsFragment;
Expand Down Expand Up @@ -59,9 +58,6 @@ public abstract class FragmentBuilderModule {
@ContributesAndroidInjector
abstract ContributionsFragment bindContributionsFragment();

@ContributesAndroidInjector
abstract NearbyMapFragment bindNearbyMapFragment();

@ContributesAndroidInjector
abstract NearbyParentFragment bindNearbyParentFragment();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatCheckBox;

import java.util.List;

import fr.free.nrw.commons.R;
import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter;

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

private int state;

private Callback callback;

public interface Callback{
void filterByMarkerType(@Nullable List<Label> selectedLabels, int state, boolean b, boolean b1);
}

public void setCallback(Callback callback) {
this.callback = callback;
}

/**
* This is the listener set to the super class which is going to be evoke each
* time the check state has changed.
Expand Down Expand Up @@ -87,7 +99,7 @@ public void setState(int state) {
}

if (NearbyController.currentLocation != null) {
NearbyParentFragmentPresenter.getInstance().filterByMarkerType(null, state, false, true);
callback.filterByMarkerType(null, state, false, true);
}
updateBtn();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ public class NearbyFilterSearchRecyclerViewAdapter

private int state;

private Callback callback;

RecyclerView.SmoothScroller smoothScroller;

public void setCallback(Callback callback) {
this.callback = callback;
}

public NearbyFilterSearchRecyclerViewAdapter(Context context, ArrayList<Label> labels, RecyclerView recyclerView) {
this.context = context;
this.labels = labels;
Expand Down Expand Up @@ -79,15 +85,15 @@ public void onBindViewHolder(@NonNull RecyclerViewHolder holder, int position) {

holder.placeTypeLayout.setBackgroundColor(label.isSelected() ? ContextCompat.getColor(context, R.color.divider_grey) : Color.WHITE);
holder.placeTypeLayout.setOnClickListener(view -> {
NearbyParentFragmentPresenter.getInstance().setCheckboxUnknown();
callback.setCheckboxUnknown();
if (label.isSelected()) {
selectedLabels.remove(label);
} else {
selectedLabels.add(label);
}
label.setSelected(!label.isSelected());
holder.placeTypeLayout.setBackgroundColor(label.isSelected() ? ContextCompat.getColor(context, R.color.divider_grey) : Color.WHITE);
NearbyParentFragmentPresenter.getInstance().filterByMarkerType(selectedLabels, 0, false, false);
callback.filterByMarkerType(selectedLabels, 0, false, false);
});
}

Expand Down Expand Up @@ -166,4 +172,11 @@ public void setRecyclerViewAdapterNeutral() {
state = CheckBoxTriStates.UNKNOWN;
}

public interface Callback{

void setCheckboxUnknown();

void filterByMarkerType(ArrayList<Label> selectedLabels, int i, boolean b, boolean b1);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@
import fr.free.nrw.commons.contributions.ContributionController;
import fr.free.nrw.commons.di.ApplicationlessInjection;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.nearby.fragments.NearbyMapFragment;
import fr.free.nrw.commons.nearby.fragments.NearbyParentFragment;
import timber.log.Timber;

import static fr.free.nrw.commons.nearby.fragments.NearbyParentFragment.TAG_RETAINED_MAP_FRAGMENT;
import static fr.free.nrw.commons.theme.NavigationBaseActivity.startActivityWithFlags;
import static fr.free.nrw.commons.wikidata.WikidataConstants.PLACE_OBJECT;

Expand Down Expand Up @@ -193,8 +191,7 @@ protected void hookListeners(View view) {
onBookmarkClick.onClick();
}
else {
((NearbyMapFragment)(fragment.getParentFragment()).getChildFragmentManager().
findFragmentByTag(TAG_RETAINED_MAP_FRAGMENT)).
((NearbyParentFragment) (fragment.getParentFragment())).
updateMarker(isBookmarked, place, null);
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fr.free.nrw.commons.nearby.contract;

import android.content.Context;

import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.maps.MapboxMap;

Expand All @@ -9,16 +11,17 @@
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.location.LocationServiceManager;
import fr.free.nrw.commons.nearby.Label;
import fr.free.nrw.commons.nearby.NearbyBaseMarker;
import fr.free.nrw.commons.nearby.Place;
import fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter;

public interface NearbyParentFragmentContract {

interface View {
void registerLocationUpdates(LocationServiceManager locationServiceManager);
boolean isNetworkConnectionEstablished();
void addNetworkBroadcastReceiver();
void listOptionMenuItemClicked();
void populatePlaces(LatLng curlatLng, LatLng searchLatLng);
void populatePlaces(LatLng curlatLng);
boolean isListBottomSheetExpanded();
void checkPermissionsAndPerformAction(Runnable runnable);
void displayLoginSkippedWarning();
Expand All @@ -29,7 +32,7 @@ interface View {
void hideBottomSheet();
void hideBottomDetailsSheet();
void displayBottomSheetWithInfo(Marker marker);
void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener);
void addOnCameraMoveListener();
void addSearchThisAreaButtonAction();
void setSearchThisAreaButtonVisibility(boolean isVisible);
void setProgressBarVisibility(boolean isVisible);
Expand All @@ -44,26 +47,49 @@ interface View {
void setFilterState();
void disableFABRecenter();
void enableFABRecenter();
void addCurrentLocationMarker(LatLng curLatLng);

void updateMapToTrackPosition(LatLng curLatLng);

Context getContext();

void updateMapMarkers(List<NearbyBaseMarker> nearbyBaseMarkers, Marker selectedMarker);

void filterOutAllMarkers();

void displayAllMarkers();

void filterMarkersByLabels(List<Label> selectedLabels, boolean existsSelected, boolean needPhotoSelected, boolean filterForPlaceState, boolean filterForAllNoneType);

LatLng getCameraTarget();

void centerMapToPlace(Place placeToCenter);

void updateListFragment(List<Place> placeList);

LatLng getLastLocation();
}

interface NearbyListView {
void updateListFragment(List<Place> placeList);
}

interface UserActions {
void onTabSelected();
void checkForPermission();
void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType, LatLng cameraTarget);
void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType);
void lockUnlockNearby(boolean isNearbyLocked);

void attachView(View view);

void detachView();

void setActionListeners(JsonKvStore applicationKvStore);
void backButtonClicked();
MapboxMap.OnCameraMoveListener onCameraMove(MapboxMap mapboxMap);
void onCameraMove(com.mapbox.mapboxsdk.geometry.LatLng latLng);
void filterByMarkerType(List<Label> selectedLabels, int state, boolean filterForPlaceState, boolean filterForAllNoneType);

void updateMapMarkersToController(List<NearbyBaseMarker> nearbyBaseMarkers);

void searchViewGainedFocus();
void setCheckboxUnknown();
}

interface ViewsAreReadyCallback {
void nearbyFragmentsAreReady();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public class NearbyListFragment extends CommonsDaggerSupportFragment implements
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
}

@Override
Expand Down

0 comments on commit caaadbf

Please sign in to comment.