mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Code cleanup
This commit is contained in:
parent
148c891580
commit
cff4086bb3
6 changed files with 21 additions and 77 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<Place> loadAttractionsFromLocationToPlaces(
|
||||
public static List<Place> loadAttractionsFromLocationToPlaces(
|
||||
LatLng curLatLng,
|
||||
List<Place> placeList) {
|
||||
placeList = placeList.subList(0, Math.min(placeList.size(), MAX_RESULTS));
|
||||
|
|
@ -223,7 +226,7 @@ public class NearbyController {
|
|||
public class NearbyPlacesInfo {
|
||||
public List<Place> 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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<List<Place>>() {
|
||||
}.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<Place>) 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<Place> placeList) {
|
||||
try {
|
||||
adapterFactory.updateAdapterData(placeList, (RVRendererAdapter<Place>) 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<Place> placeList) {
|
||||
Timber.d("Update list fragment");
|
||||
adapterFactory.updateAdapterData(placeList, (RVRendererAdapter<Place>) recyclerView.getAdapter());
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Place> 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue