diff --git a/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java b/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java index 25b14f8cc..a698a2d83 100644 --- a/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java @@ -47,13 +47,15 @@ import static android.content.ContentResolver.requestSync; public class MainActivity extends AuthenticatedActivity implements FragmentManager.OnBackStackChangedListener { - @Inject - SessionManager sessionManager; - @Inject ContributionController controller; @BindView(R.id.tab_layout) TabLayout tabLayout; @BindView(R.id.pager) public UnswipableViewPager viewPager; + + @Inject + SessionManager sessionManager; + @Inject + ContributionController controller; @Inject public LocationServiceManager locationManager; @Inject @@ -72,8 +74,6 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag public boolean isContributionsFragmentVisible = true; // False means nearby fragment is visible private Menu menu; - private boolean onOrientationChanged = false; - private MenuItem notificationsMenuItem; private TextView notificationCount; @@ -84,16 +84,6 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag requestAuthToken(); initDrawer(); setTitle(getString(R.string.navigation_item_home)); // Should I create a new string variable with another name instead? - - - if (savedInstanceState != null ) { - onOrientationChanged = true; // Will be used in nearby fragment to determine significant update of map - - //If nearby map was visible, call on Tab Selected to call all nearby operations - /*if (savedInstanceState.getInt("viewPagerCurrentItem") == 1) { - ((NearbyFragment)contributionsActivityPagerAdapter.getItem(1)).onTabSelected(onOrientationChanged); - }*/ - } } @Override @@ -160,9 +150,7 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag * tab won't change and vice versa. So we have to notify each of them. */ private void setTabAndViewPagerSynchronisation() { - //viewPager.canScrollHorizontally(false); viewPager.setFocusableInTouchMode(true); - viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { @@ -177,7 +165,6 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select(); isContributionsFragmentVisible = true; updateMenuItem(); - break; case NEARBY_TAB_POSITION: Timber.d("Nearby tab selected"); @@ -324,12 +311,12 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag // Display notifications menu item menu.findItem(R.id.notifications).setVisible(true); menu.findItem(R.id.list_sheet).setVisible(false); - Timber.d("Contributions activity notifications menu item is visible"); + Timber.d("Contributions fragment notifications menu item is visible"); } else { // Display bottom list menu item menu.findItem(R.id.notifications).setVisible(false); menu.findItem(R.id.list_sheet).setVisible(true); - Timber.d("Contributions activity list sheet menu item is visible"); + Timber.d("Nearby fragment list sheet menu item is visible"); } } } @@ -353,8 +340,6 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag public class ContributionsActivityPagerAdapter extends FragmentPagerAdapter { FragmentManager fragmentManager; - private boolean isContributionsListFragment = true; // to know what to put in first tab, Contributions of Media Details - public ContributionsActivityPagerAdapter(FragmentManager fragmentManager) { super(fragmentManager); diff --git a/app/src/main/java/fr/free/nrw/commons/di/FragmentBuilderModule.java b/app/src/main/java/fr/free/nrw/commons/di/FragmentBuilderModule.java index bca5a73e1..fb6ac0eaf 100644 --- a/app/src/main/java/fr/free/nrw/commons/di/FragmentBuilderModule.java +++ b/app/src/main/java/fr/free/nrw/commons/di/FragmentBuilderModule.java @@ -13,7 +13,7 @@ import fr.free.nrw.commons.explore.images.SearchImageFragment; import fr.free.nrw.commons.explore.recentsearches.RecentSearchesFragment; import fr.free.nrw.commons.media.MediaDetailFragment; import fr.free.nrw.commons.media.MediaDetailPagerFragment; -import fr.free.nrw.commons.nearby.NearbyListFragment; +import fr.free.nrw.commons.nearby.mvp.fragments.NearbyListFragment; import fr.free.nrw.commons.nearby.mvp.fragments.NearbyMapFragment; import fr.free.nrw.commons.nearby.mvp.fragments.NearbyParentFragment; import fr.free.nrw.commons.review.ReviewImageFragment; @@ -60,7 +60,7 @@ public abstract class FragmentBuilderModule { abstract ContributionsFragment bindContributionsFragment(); @ContributesAndroidInjector - abstract NearbyMapFragment bindSupportMapFragment(); + abstract NearbyMapFragment bindNearbyMapFragment(); @ContributesAndroidInjector abstract NearbyParentFragment bindNearbyParentFragment(); diff --git a/app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java b/app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java index f88001d7c..396cd410c 100644 --- a/app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java +++ b/app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java @@ -6,8 +6,6 @@ import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; -import android.util.Log; - import java.util.HashSet; import java.util.List; import java.util.Set; diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java index ba738aefa..3bd38546a 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyController.java @@ -98,10 +98,13 @@ public class NearbyController { nearbyPlacesInfo.placeList = places; nearbyPlacesInfo.boundaryCoordinates = boundaryCoordinates; + // Returning closes result means we use the controller for nearby card. So no need to set search this area flags if (!returnClosestResult) { + // To remember latest search either around user or any point on map latestSearchLocation = searchLatLng; latestSearchRadius = nearbyPlaces.radius*1000; // to meter + // Our radius searched around us, will be used to understand when user search their own location, we will follow them if (checkingAroundCurrentLocation) { currentLocationSearchRadius = nearbyPlaces.radius*1000; // to meter currentLocation = curLatLng; @@ -123,7 +126,7 @@ public class NearbyController { * @param placeList list of nearby places in Place data type * @return Place list that holds nearby places */ - static List loadAttractionsFromLocationToPlaces( + public static List loadAttractionsFromLocationToPlaces( LatLng curLatLng, List placeList) { placeList = placeList.subList(0, Math.min(placeList.size(), MAX_RESULTS)); @@ -223,7 +226,7 @@ public class NearbyController { public class NearbyPlacesInfo { public List placeList; // List of nearby places public LatLng[] boundaryCoordinates; // Corners of nearby area - public LatLng curLatLng; // current location when this places are populated - public LatLng searchLatLng; //search location for finding this places + public LatLng curLatLng; // Current location when this places are populated + public LatLng searchLatLng; // Search location for finding this places } } diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyListFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyListFragment.java similarity index 70% rename from app/src/main/java/fr/free/nrw/commons/nearby/NearbyListFragment.java rename to app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyListFragment.java index 8e67dcbff..05f0604b4 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyListFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyListFragment.java @@ -1,4 +1,4 @@ -package fr.free.nrw.commons.nearby; +package fr.free.nrw.commons.nearby.mvp.fragments; import android.content.Context; import android.os.Bundle; @@ -22,11 +22,13 @@ import fr.free.nrw.commons.R; import fr.free.nrw.commons.contributions.ContributionController; import fr.free.nrw.commons.di.CommonsDaggerSupportFragment; import fr.free.nrw.commons.location.LatLng; +import fr.free.nrw.commons.nearby.NearbyAdapterFactory; +import fr.free.nrw.commons.nearby.NearbyController; +import fr.free.nrw.commons.nearby.Place; import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract; import timber.log.Timber; public class NearbyListFragment extends CommonsDaggerSupportFragment implements NearbyParentFragmentContract.ListView { - private Bundle bundleForUpdates; // Carry information from activity about changed nearby places and current location private static final Type LIST_TYPE = new TypeToken>() { }.getType(); @@ -70,30 +72,6 @@ public class NearbyListFragment extends CommonsDaggerSupportFragment implements recyclerView.setAdapter(adapterFactory.create(getPlaceListFromBundle(bundle))); } - /** - * Updates nearby list elements all together - */ - public void updateNearbyListSignificantly() { - try { - adapterFactory.updateAdapterData(getPlaceListFromBundle(bundleForUpdates), (RVRendererAdapter) recyclerView.getAdapter()); - } catch (NullPointerException e) { - Timber.e("Null pointer exception from calling recyclerView.getAdapter()"); - } - } - - /** - * While nearby updates for current location held with bundle, automatically, custom updates are - * done by calling this method, triggered by search this are button input from user. - * @param placeList List of nearby places to be added list fragment - */ - public void updateNearbyListSignificantlyForCustomLocation(List placeList) { - try { - adapterFactory.updateAdapterData(placeList, (RVRendererAdapter) recyclerView.getAdapter()); - } catch (NullPointerException e) { - Timber.e("Null pointer exception from calling recyclerView.getAdapter()"); - } - } - /** * When user moved too much, we need to update nearby list too. This operation is made by passing * a bundle from NearbyFragment to NearbyListFragment and NearbyMapFragment. This method extracts @@ -117,16 +95,9 @@ public class NearbyListFragment extends CommonsDaggerSupportFragment implements return placeList; } - /** - * Sets bundles for updates in map. Ie. user is moved too much so we need to update nearby markers. - * @param bundleForUpdates includes new calculated nearby places. - */ - public void setBundleForUpdates(Bundle bundleForUpdates) { - this.bundleForUpdates = bundleForUpdates; - } - @Override public void updateListFragment(List placeList) { + Timber.d("Update list fragment"); adapterFactory.updateAdapterData(placeList, (RVRendererAdapter) recyclerView.getAdapter()); } } diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java index 53a26c752..b30e62724 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java @@ -42,8 +42,6 @@ import com.mapbox.mapboxsdk.maps.MapboxMapOptions; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import com.mapbox.mapboxsdk.maps.Style; -import java.util.List; - import javax.inject.Inject; import javax.inject.Named; @@ -58,7 +56,6 @@ import fr.free.nrw.commons.di.CommonsDaggerSupportFragment; import fr.free.nrw.commons.kvstore.JsonKvStore; import fr.free.nrw.commons.location.LocationServiceManager; import fr.free.nrw.commons.nearby.NearbyController; -import fr.free.nrw.commons.nearby.NearbyListFragment; import fr.free.nrw.commons.nearby.NearbyMarker; import fr.free.nrw.commons.nearby.Place; import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract; @@ -205,7 +202,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment NearbyMapFragment nearbyMapFragment; - private fr.free.nrw.commons.nearby.NearbyListFragment nearbyListFragment; + private NearbyListFragment nearbyListFragment; public static final String TAG_RETAINED_MAP_FRAGMENT = NearbyMapFragment.class.getSimpleName(); public static final String TAG_RETAINED_LIST_FRAGMENT = NearbyListFragment.class.getSimpleName(); @@ -446,16 +443,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment } } - - /** - * Updates nearby list for custom location, will be used with search this area method. When you - * want to search for a place where you are not at. - * @param placeList List of places around your manually chosen target location from map. - */ - private void updateListFragmentForCustomLocation(List placeList) { - nearbyListFragment.updateNearbyListSignificantlyForCustomLocation(placeList); - } - /** * Thanks to this method we make sure NearbyMapFragment is ready and attached. So that we can * prevent NPE caused by null child fragment. This method is called from child fragment when