1515import android .support .design .widget .BottomSheetBehavior ;
1616import android .support .v4 .app .FragmentTransaction ;
1717import android .support .v7 .app .AlertDialog ;
18-
19- import android .text .TextUtils ;
2018import android .view .Menu ;
2119import android .view .MenuInflater ;
2220import android .view .MenuItem ;
2321import android .view .View ;
2422import android .widget .LinearLayout ;
2523import android .widget .ProgressBar ;
2624
27- import android .widget .Toast ;
2825import com .google .gson .Gson ;
2926import com .google .gson .GsonBuilder ;
3027
31- import io .reactivex .functions .Consumer ;
32- import java .io .IOException ;
33- import java .net .ConnectException ;
34- import java .net .UnknownHostException ;
3528import java .util .List ;
3629
3730import javax .inject .Inject ;
4235import fr .free .nrw .commons .R ;
4336import fr .free .nrw .commons .location .LatLng ;
4437import fr .free .nrw .commons .location .LocationServiceManager ;
38+ import fr .free .nrw .commons .location .LocationServiceManager .LocationChangeType ;
4539import fr .free .nrw .commons .location .LocationUpdateListener ;
4640import fr .free .nrw .commons .theme .NavigationBaseActivity ;
4741import fr .free .nrw .commons .utils .NetworkUtils ;
4842import fr .free .nrw .commons .utils .UriSerializer ;
4943import fr .free .nrw .commons .utils .ViewUtil ;
44+ import fr .free .nrw .commons .wikidata .WikidataEditListener ;
5045import io .reactivex .Observable ;
5146import io .reactivex .android .schedulers .AndroidSchedulers ;
5247import io .reactivex .disposables .Disposable ;
5550import uk .co .deanwild .materialshowcaseview .IShowcaseListener ;
5651import uk .co .deanwild .materialshowcaseview .MaterialShowcaseView ;
5752
53+ import static fr .free .nrw .commons .location .LocationServiceManager .LocationChangeType .*;
54+ import static fr .free .nrw .commons .location .LocationServiceManager .LocationChangeType .MAP_UPDATED ;
55+
5856
59- public class NearbyActivity extends NavigationBaseActivity implements LocationUpdateListener {
57+ public class NearbyActivity extends NavigationBaseActivity implements LocationUpdateListener ,
58+ WikidataEditListener .WikidataP18EditListener {
6059
6160 private static final int LOCATION_REQUEST = 1 ;
6261
@@ -76,6 +75,8 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
7675 LocationServiceManager locationManager ;
7776 @ Inject
7877 NearbyController nearbyController ;
78+ @ Inject WikidataEditListener wikidataEditListener ;
79+
7980 @ Inject
8081 @ Named ("application_preferences" ) SharedPreferences applicationPrefs ;
8182 private LatLng curLatLng ;
@@ -110,6 +111,7 @@ protected void onCreate(Bundle savedInstanceState) {
110111
111112 initBottomSheetBehaviour ();
112113 initDrawer ();
114+ wikidataEditListener .setAuthenticationStateListener (this );
113115 }
114116
115117 private void resumeFragment () {
@@ -219,7 +221,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
219221 //Still need to check if GPS is enabled
220222 checkGps ();
221223 lastKnownLocation = locationManager .getLKL ();
222- refreshView (LocationServiceManager . LocationChangeType . PERMISSION_JUST_GRANTED );
224+ refreshView (PERMISSION_JUST_GRANTED );
223225 } else {
224226 //If permission not granted, go to page that says Nearby Places cannot be displayed
225227 hideProgressBar ();
@@ -279,7 +281,7 @@ private void checkGps() {
279281 private void checkLocationPermission () {
280282 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
281283 if (locationManager .isLocationPermissionGranted ()) {
282- refreshView (LocationServiceManager . LocationChangeType . LOCATION_SIGNIFICANTLY_CHANGED );
284+ refreshView (LOCATION_SIGNIFICANTLY_CHANGED );
283285 } else {
284286 // Should we show an explanation?
285287 if (locationManager .isPermissionExplanationRequired (this )) {
@@ -305,7 +307,7 @@ private void checkLocationPermission() {
305307 }
306308 }
307309 } else {
308- refreshView (LocationServiceManager . LocationChangeType . LOCATION_SIGNIFICANTLY_CHANGED );
310+ refreshView (LOCATION_SIGNIFICANTLY_CHANGED );
309311 }
310312 }
311313
@@ -314,7 +316,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
314316 super .onActivityResult (requestCode , resultCode , data );
315317 if (requestCode == 1 ) {
316318 Timber .d ("User is back from Settings page" );
317- refreshView (LocationServiceManager . LocationChangeType . LOCATION_SIGNIFICANTLY_CHANGED );
319+ refreshView (LOCATION_SIGNIFICANTLY_CHANGED );
318320 }
319321 }
320322
@@ -341,7 +343,7 @@ protected void onDestroy() {
341343 @ Override
342344 protected void onResume () {
343345 super .onResume ();
344- lockNearbyView = true ;
346+ lockNearbyView = false ;
345347 checkGps ();
346348 addNetworkBroadcastReceiver ();
347349 }
@@ -373,8 +375,7 @@ private void addNetworkBroadcastReceiver() {
373375 @ Override
374376 public void onReceive (Context context , Intent intent ) {
375377 if (NetworkUtils .isInternetConnectionEstablished (NearbyActivity .this )) {
376- refreshView (LocationServiceManager
377- .LocationChangeType .LOCATION_SIGNIFICANTLY_CHANGED );
378+ refreshView (LOCATION_SIGNIFICANTLY_CHANGED );
378379 } else {
379380 ViewUtil .showLongToast (NearbyActivity .this , getString (R .string .no_internet ));
380381 }
@@ -390,7 +391,7 @@ public void onReceive(Context context, Intent intent) {
390391 *
391392 * @param locationChangeType defines if location shanged significantly or slightly
392393 */
393- private void refreshView (LocationServiceManager . LocationChangeType locationChangeType ) {
394+ private void refreshView (LocationChangeType locationChangeType ) {
394395 if (lockNearbyView ) {
395396 return ;
396397 }
@@ -403,12 +404,13 @@ private void refreshView(LocationServiceManager.LocationChangeType locationChang
403404 locationManager .registerLocationManager ();
404405 LatLng lastLocation = locationManager .getLastLocation ();
405406
406- if (curLatLng != null && curLatLng .equals (lastLocation )) { //refresh view only if location has changed
407+ if (curLatLng != null && curLatLng .equals (lastLocation )
408+ && !locationChangeType .equals (MAP_UPDATED )) { //refresh view only if location has changed
407409 return ;
408410 }
409411 curLatLng = lastLocation ;
410412
411- if (locationChangeType .equals (LocationServiceManager . LocationChangeType . PERMISSION_JUST_GRANTED )) {
413+ if (locationChangeType .equals (PERMISSION_JUST_GRANTED )) {
412414 curLatLng = lastKnownLocation ;
413415 }
414416
@@ -417,8 +419,9 @@ private void refreshView(LocationServiceManager.LocationChangeType locationChang
417419 return ;
418420 }
419421
420- if (locationChangeType .equals (LocationServiceManager .LocationChangeType .LOCATION_SIGNIFICANTLY_CHANGED )
421- || locationChangeType .equals (LocationServiceManager .LocationChangeType .PERMISSION_JUST_GRANTED )) {
422+ if (locationChangeType .equals (LOCATION_SIGNIFICANTLY_CHANGED )
423+ || locationChangeType .equals (PERMISSION_JUST_GRANTED )
424+ || locationChangeType .equals (MAP_UPDATED )) {
422425 progressBar .setVisibility (View .VISIBLE );
423426
424427 //TODO: This hack inserts curLatLng before populatePlaces is called (see #1440). Ideally a proper fix should be found
@@ -440,7 +443,7 @@ private void refreshView(LocationServiceManager.LocationChangeType locationChang
440443 progressBar .setVisibility (View .GONE );
441444 });
442445 } else if (locationChangeType
443- .equals (LocationServiceManager . LocationChangeType . LOCATION_SLIGHTLY_CHANGED )) {
446+ .equals (LOCATION_SLIGHTLY_CHANGED )) {
444447 Gson gson = new GsonBuilder ()
445448 .registerTypeAdapter (Uri .class , new UriSerializer ())
446449 .create ();
@@ -652,12 +655,12 @@ private void setListFragment() {
652655
653656 @ Override
654657 public void onLocationChangedSignificantly (LatLng latLng ) {
655- refreshView (LocationServiceManager . LocationChangeType . LOCATION_SIGNIFICANTLY_CHANGED );
658+ refreshView (LOCATION_SIGNIFICANTLY_CHANGED );
656659 }
657660
658661 @ Override
659662 public void onLocationChangedSlightly (LatLng latLng ) {
660- refreshView (LocationServiceManager . LocationChangeType . LOCATION_SLIGHTLY_CHANGED );
663+ refreshView (LOCATION_SLIGHTLY_CHANGED );
661664 }
662665
663666 public void prepareViewsForSheetPosition (int bottomSheetState ) {
@@ -667,4 +670,9 @@ public void prepareViewsForSheetPosition(int bottomSheetState) {
667670 private void showErrorMessage (String message ) {
668671 ViewUtil .showLongToast (NearbyActivity .this , message );
669672 }
673+
674+ @ Override
675+ public void onWikidataEditSuccessful () {
676+ refreshView (MAP_UPDATED );
677+ }
670678}
0 commit comments