mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-11-03 16:23:54 +01:00
Merge branch 'master' into dependency-injection
This commit is contained in:
commit
f134d23ecb
111 changed files with 1230 additions and 364 deletions
|
|
@ -10,6 +10,7 @@ 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;
|
||||
|
|
@ -49,26 +50,45 @@ public class NearbyActivity extends NavigationBaseActivity {
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -79,13 +99,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);
|
||||
|
|
@ -163,15 +180,30 @@ public class NearbyActivity extends NavigationBaseActivity {
|
|||
if (progressBar != null) {
|
||||
progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
Fragment noPermissionsFragment = new NoPermissionsFragment();
|
||||
fragmentTransaction.replace(R.id.container, noPermissionsFragment);
|
||||
fragmentTransaction.commit();
|
||||
|
||||
showLocationPermissionDeniedErrorDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void showLocationPermissionDeniedErrorDialog() {
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(R.string.nearby_needs_permissions)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(R.string.give_permission, (dialog, which) -> {
|
||||
//will ask for the location permission again
|
||||
checkLocationPermission();
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, (dialog, which) -> {
|
||||
//dismiss dialog and finish activity
|
||||
dialog.cancel();
|
||||
finish();
|
||||
})
|
||||
.create()
|
||||
.show();
|
||||
}
|
||||
|
||||
private void checkGps() {
|
||||
LocationManager manager = (LocationManager) getSystemService(LOCATION_SERVICE);
|
||||
if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
|
||||
|
|
@ -203,20 +235,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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -292,7 +320,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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue