Skip to content

Removes Manual Nearby Update Methods #1271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 7 additions & 23 deletions app/src/main/java/fr/free/nrw/commons/nearby/NearbyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
private NearbyMapFragment nearbyMapFragment;
private static final String TAG_RETAINED_FRAGMENT = "RetainedFragment";

@BindView(R.id.swipe_container) SwipeRefreshLayout swipeLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -81,13 +80,6 @@ protected void onCreate(Bundle savedInstanceState) {

initBottomSheetBehaviour();
initDrawer();
swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
lockNearbyView(false);
refreshView(true);
}
});
}

private void resumeFragment() {
Expand Down Expand Up @@ -142,10 +134,6 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.action_refresh:
lockNearbyView(false);
refreshView(true);
return true;
case R.id.action_display_list:
bottomSheetBehaviorForDetails.setState(BottomSheetBehavior.STATE_HIDDEN);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
Expand All @@ -166,7 +154,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
switch (requestCode) {
case LOCATION_REQUEST: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
refreshView(false);
refreshView();
} else {
//If permission not granted, go to page that says Nearby Places cannot be displayed
hideProgressBar();
Expand Down Expand Up @@ -221,7 +209,7 @@ private void checkGps() {
private void checkLocationPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (locationManager.isLocationPermissionGranted()) {
refreshView(false);
refreshView();
} else {
// Should we show an explanation?
if (locationManager.isPermissionExplanationRequired(this)) {
Expand All @@ -247,7 +235,7 @@ private void checkLocationPermission() {
}
}
} else {
refreshView(false);
refreshView();
}
}

Expand All @@ -256,7 +244,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
Timber.d("User is back from Settings page");
refreshView(false);
refreshView();
}
}

Expand Down Expand Up @@ -306,18 +294,15 @@ public void onPause() {
/**
* This method should be the single point to load/refresh nearby places
*
* @param isHardRefresh Should display a toast if the location hasn't changed
*/
private void refreshView(boolean isHardRefresh) {
private void refreshView() {
if (lockNearbyView) {
return;
}
locationManager.registerLocationManager();
LatLng lastLocation = locationManager.getLastLocation();
if (curLatLang != null && curLatLang.equals(lastLocation)) { //refresh view only if location has changed
if (isHardRefresh) {
ViewUtil.showLongToast(this, R.string.nearby_location_has_not_changed);
}

return;
}
curLatLang = lastLocation;
Expand Down Expand Up @@ -357,7 +342,6 @@ private void populatePlaces(List<Place> placeList) {
setListFragment();

hideProgressBar();
swipeLayout.setRefreshing(false);
}

private void lockNearbyView(boolean lock) {
Expand Down Expand Up @@ -403,7 +387,7 @@ private void setListFragment() {

@Override
public void onLocationChanged(LatLng latLng) {
refreshView(false);
refreshView();
}

public void prepareViewsForSheetPosition(int bottomSheetState) {
Expand Down
23 changes: 10 additions & 13 deletions app/src/main/res/layout/activity_nearby.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,16 @@
android:layout_below="@id/toolbar"
android:gravity="center_vertical"
android:orientation="horizontal">
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>

<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_list"
Expand Down
8 changes: 0 additions & 8 deletions app/src/main/res/menu/menu_nearby.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,4 @@
app:showAsAction="ifRoom"
/>

<item
android:id="@+id/action_refresh"
android:title="@string/refresh_button"
android:icon="@drawable/ic_refresh_white_24dp"
android:orderInCategory="1"
app:showAsAction="ifRoom"
/>

</menu>