mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Merge pull request #898 from mashawan/master
Implement List or map: remember last used #649
This commit is contained in:
commit
d6873cfad4
4 changed files with 66 additions and 21 deletions
|
|
@ -2,14 +2,15 @@ package fr.free.nrw.commons.nearby;
|
|||
|
||||
import android.Manifest;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.location.LocationManager;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
|
@ -43,28 +44,46 @@ public class NearbyActivity extends NavigationBaseActivity {
|
|||
|
||||
@BindView(R.id.progressBar)
|
||||
ProgressBar progressBar;
|
||||
private boolean isMapViewActive = false;
|
||||
private static final int LOCATION_REQUEST = 1;
|
||||
private static final String MAP_LAST_USED_PREFERENCE = "mapLastUsed";
|
||||
|
||||
private LocationServiceManager locationManager;
|
||||
private LatLng curLatLang;
|
||||
private Bundle bundle;
|
||||
private NearbyAsyncTask nearbyAsyncTask;
|
||||
private SharedPreferences sharedPreferences;
|
||||
private NearbyActivityMode viewMode;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
setContentView(R.layout.activity_nearby);
|
||||
ButterKnife.bind(this);
|
||||
checkLocationPermission();
|
||||
bundle = new Bundle();
|
||||
initDrawer();
|
||||
initViewState();
|
||||
}
|
||||
|
||||
private void initViewState() {
|
||||
if (sharedPreferences.getBoolean(MAP_LAST_USED_PREFERENCE, false)) {
|
||||
viewMode = NearbyActivityMode.MAP;
|
||||
} else {
|
||||
viewMode = NearbyActivityMode.LIST;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.menu_nearby, menu);
|
||||
|
||||
if (viewMode.isMap()) {
|
||||
MenuItem item = menu.findItem(R.id.action_toggle_view);
|
||||
item.setIcon(viewMode.getIcon());
|
||||
}
|
||||
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
|
|
@ -75,13 +94,10 @@ public class NearbyActivity extends NavigationBaseActivity {
|
|||
case R.id.action_refresh:
|
||||
refreshView();
|
||||
return true;
|
||||
case R.id.action_map:
|
||||
showMapView();
|
||||
if (isMapViewActive) {
|
||||
item.setIcon(R.drawable.ic_list_white_24dp);
|
||||
} else {
|
||||
item.setIcon(R.drawable.ic_map_white_24dp);
|
||||
}
|
||||
case R.id.action_toggle_view:
|
||||
viewMode = viewMode.toggle();
|
||||
item.setIcon(viewMode.getIcon());
|
||||
toggleView();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
|
@ -214,20 +230,16 @@ public class NearbyActivity extends NavigationBaseActivity {
|
|||
}
|
||||
}
|
||||
|
||||
private void showMapView() {
|
||||
private void toggleView() {
|
||||
if (nearbyAsyncTask != null) {
|
||||
if (!isMapViewActive) {
|
||||
isMapViewActive = true;
|
||||
if (nearbyAsyncTask.getStatus() == AsyncTask.Status.FINISHED) {
|
||||
if (nearbyAsyncTask.getStatus() == AsyncTask.Status.FINISHED) {
|
||||
if (viewMode.isMap()) {
|
||||
setMapFragment();
|
||||
}
|
||||
|
||||
} else {
|
||||
isMapViewActive = false;
|
||||
if (nearbyAsyncTask.getStatus() == AsyncTask.Status.FINISHED) {
|
||||
} else {
|
||||
setListFragment();
|
||||
}
|
||||
}
|
||||
sharedPreferences.edit().putBoolean(MAP_LAST_USED_PREFERENCE, viewMode.isMap()).apply();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -303,7 +315,7 @@ public class NearbyActivity extends NavigationBaseActivity {
|
|||
bundle.putString("CurLatLng", gsonCurLatLng);
|
||||
|
||||
// Begin the transaction
|
||||
if (isMapViewActive) {
|
||||
if (viewMode.isMap()) {
|
||||
setMapFragment();
|
||||
} else {
|
||||
setListFragment();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
package fr.free.nrw.commons.nearby;
|
||||
|
||||
import android.support.annotation.DrawableRes;
|
||||
|
||||
import fr.free.nrw.commons.R;
|
||||
|
||||
enum NearbyActivityMode {
|
||||
MAP(R.drawable.ic_list_white_24dp),
|
||||
LIST(R.drawable.ic_map_white_24dp);
|
||||
|
||||
@DrawableRes
|
||||
private final int icon;
|
||||
|
||||
NearbyActivityMode(int icon) {
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
public int getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public NearbyActivityMode toggle() {
|
||||
return isMap() ? LIST : MAP;
|
||||
}
|
||||
|
||||
public boolean isMap() {
|
||||
return MAP.equals(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_map"
|
||||
android:id="@+id/action_toggle_view"
|
||||
android:title="@string/refresh_button"
|
||||
android:icon="@drawable/ic_map_white_24dp"
|
||||
android:orderInCategory="1"
|
||||
|
|
|
|||
|
|
@ -54,7 +54,10 @@
|
|||
<string name="gps_disabled">आपके डिवाइस में जीपीएस अक्षम है। क्या आप इसे सक्षम करना चाहेंगे?</string>
|
||||
<string name="enable_gps">जीपीएस सक्षम करें</string>
|
||||
<string name="contributions_subtitle_zero">अभी तक कोई अपलोड नहीं</string>
|
||||
<string name="contributions_subtitle" formatted="false">{{PLURAL | शून्य = @ स्ट्रिंग / योगदान_उपशीर्षक_शुन्य | एक =% d अपलोड |% d अपलोड्स}}</string>
|
||||
<plurals name="contributions_subtitle">
|
||||
<item quantity="one">%d अपलोड</item>
|
||||
<item quantity="other">%d अपलोड्स</item>
|
||||
</plurals>
|
||||
<plurals name="starting_multiple_uploads">
|
||||
<item quantity="one">%d अपलोड शुरू</item>
|
||||
<item quantity="other">%d अपलोड शुरू</item>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue