This commit is contained in:
misaochan 2018-04-23 21:51:23 +10:00
commit 4c78ebf58b
8 changed files with 80 additions and 23 deletions

View file

@ -1,5 +1,11 @@
# Wikimedia Commons for Android
## v2.7.1
- Fixed UI and permission issues with Nearby
- Fixed issue with My Recent Uploads being empty
- Fixed blank category issue when uploading directly from Nearby
- Various crash fixes
## v2.7.0
- New Nearby Places UI with direct uploads (and associated category suggestions)
- Added two-factor authentication login

View file

@ -82,8 +82,8 @@ android {
defaultConfig {
applicationId 'fr.free.nrw.commons'
versionCode 83
versionName '2.7.0'
versionCode 84
versionName '2.7.1'
setProperty("archivesBaseName", "app-commons-v$versionName-" + getBranchName())
minSdkVersion project.minSdkVersion

View file

@ -19,7 +19,6 @@ import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatDelegate;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
@ -28,7 +27,6 @@ import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.io.IOException;
@ -160,7 +158,10 @@ public class LoginActivity extends AccountAuthenticatorActivity {
WelcomeActivity.startYourself(this);
prefs.edit().putBoolean("firstrun", false).apply();
}
if (sessionManager.getCurrentAccount() != null) {
if (sessionManager.getCurrentAccount() != null
&& sessionManager.isUserLoggedIn()
&& sessionManager.getCachedAuthCookie() != null) {
startMainActivity();
}
}

View file

@ -61,13 +61,11 @@ public class SessionManager {
}
public String getAuthCookie() {
boolean isLoggedIn = sharedPreferences.getBoolean("isUserLoggedIn", false);
if (!isLoggedIn) {
if (!isUserLoggedIn()) {
Timber.e("User is not logged in");
return null;
} else {
String authCookie = sharedPreferences.getString("getAuthCookie", null);
String authCookie = getCachedAuthCookie();
if (authCookie == null) {
Timber.e("Auth cookie is null even after login");
}
@ -75,6 +73,14 @@ public class SessionManager {
}
}
public String getCachedAuthCookie() {
return sharedPreferences.getString("getAuthCookie", null);
}
public boolean isUserLoggedIn() {
return sharedPreferences.getBoolean("isUserLoggedIn", false);
}
public Completable clearAllAccounts() {
AccountManager accountManager = AccountManager.get(context);
Account[] allAccounts = accountManager.getAccountsByType(ACCOUNT_TYPE);

View file

@ -79,6 +79,23 @@ public class LocationServiceManager implements LocationListener {
Manifest.permission.ACCESS_FINE_LOCATION);
}
/**
* Gets the last known location in cases where there wasn't time to register a listener
* (e.g. when Location permission just granted)
* @return last known LatLng
*/
public LatLng getLKL() {
if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
Location lastKL = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (lastKL == null) {
lastKL = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
return LatLng.from(lastKL);
} else {
return null;
}
}
public LatLng getLastLocation() {
if (lastLocation == null) {
return null;
@ -249,6 +266,7 @@ public class LocationServiceManager implements LocationListener {
public enum LocationChangeType{
LOCATION_SIGNIFICANTLY_CHANGED, //Went out of borders of nearby markers
LOCATION_SLIGHTLY_CHANGED, //User might be walking or driving
LOCATION_NOT_CHANGED
LOCATION_NOT_CHANGED,
PERMISSION_JUST_GRANTED
}
}

View file

@ -75,6 +75,7 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
private final String NETWORK_INTENT_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
private BroadcastReceiver broadcastReceiver;
private LatLng lastKnownLocation;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -158,7 +159,11 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
switch (requestCode) {
case LOCATION_REQUEST: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
refreshView(LocationServiceManager.LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED);
Timber.d("Location permission granted, refreshing view");
//Still need to check if GPS is enabled
checkGps();
lastKnownLocation = locationManager.getLKL();
refreshView(LocationServiceManager.LocationChangeType.PERMISSION_JUST_GRANTED);
} else {
//If permission not granted, go to page that says Nearby Places cannot be displayed
hideProgressBar();
@ -347,21 +352,33 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
}
curLatLng = lastLocation;
if (locationChangeType.equals(LocationServiceManager.LocationChangeType.PERMISSION_JUST_GRANTED)) {
curLatLng = lastKnownLocation;
}
if (curLatLng == null) {
Timber.d("Skipping update of nearby places as location is unavailable");
return;
}
if (locationChangeType
.equals(LocationServiceManager.LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED)) {
if (locationChangeType.equals(LocationServiceManager.LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED)
|| locationChangeType.equals(LocationServiceManager.LocationChangeType.PERMISSION_JUST_GRANTED)) {
progressBar.setVisibility(View.VISIBLE);
//TODO: This hack inserts curLatLng before populatePlaces is called (see #1440). Ideally a proper fix should be found
Gson gson = new GsonBuilder()
.registerTypeAdapter(Uri.class, new UriSerializer())
.create();
String gsonCurLatLng = gson.toJson(curLatLang);
bundle.clear();
bundle.putString("CurLatLng", gsonCurLatLng);
placesDisposable = Observable.fromCallable(() -> nearbyController
.loadAttractionsFromLocation(curLatLng))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::populatePlaces);
} else if (locationChangeType
.equals(LocationServiceManager.LocationChangeType.LOCATION_SLIGHTLY_CHANGED)) {
} else if (locationChangeType.equals(LocationServiceManager.LocationChangeType.LOCATION_SLIGHTLY_CHANGED)) {
Gson gson = new GsonBuilder()
.registerTypeAdapter(Uri.class, new UriSerializer())
.create();
@ -384,14 +401,14 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
if (placeList.size() == 0) {
ViewUtil.showSnackbar(findViewById(R.id.container), R.string.no_nearby);
}
bundle.clear();
bundle.putString("PlaceList", gsonPlaceList);
bundle.putString("CurLatLng", gsonCurLatLng);
//bundle.putString("CurLatLng", gsonCurLatLng);
bundle.putString("BoundaryCoord", gsonBoundaryCoordinates);
// First time to init fragments
if (nearbyMapFragment == null) {
Timber.d("Init map fragment for the first time");
lockNearbyView(true);
setMapFragment();
setListFragment();
@ -399,6 +416,7 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
lockNearbyView(false);
} else {
// There are fragments, just update the map and list
Timber.d("Map fragment already exists, just update the map and list");
updateMapFragment(false);
updateListFragment();
}

View file

@ -82,8 +82,11 @@ public class NearbyListFragment extends DaggerFragment {
}
public void updateNearbyListSignificantly() {
adapterFactory.updateAdapterData(getPlaceListFromBundle(bundleForUpdates),
(RVRendererAdapter<Place>) recyclerView.getAdapter());
try {
adapterFactory.updateAdapterData(getPlaceListFromBundle(bundleForUpdates), (RVRendererAdapter<Place>) recyclerView.getAdapter());
} catch (NullPointerException e) {
Timber.e("Null pointer exception from calling recyclerView.getAdapter()");
}
}
private List<Place> getPlaceListFromBundle(Bundle bundle) {

View file

@ -126,6 +126,7 @@ public class NearbyMapFragment extends DaggerFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Timber.d("Nearby map fragment created");
controller = new ContributionController(this);
directUpload = new DirectUpload(this, controller);
@ -151,9 +152,11 @@ public class NearbyMapFragment extends DaggerFragment {
getActivity());
boundaryCoordinates = gson.fromJson(gsonBoundaryCoordinates, gsonBoundaryCoordinatesType);
}
Mapbox.getInstance(getActivity(),
getString(R.string.mapbox_commons_app_token));
MapboxTelemetry.getInstance().setTelemetryEnabled(false);
if (curLatLng != null) {
Mapbox.getInstance(getActivity(),
getString(R.string.mapbox_commons_app_token));
MapboxTelemetry.getInstance().setTelemetryEnabled(false);
}
setRetainInstance(true);
}
@ -161,7 +164,9 @@ public class NearbyMapFragment extends DaggerFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Timber.d("onCreateView called");
if (curLatLng != null) {
Timber.d("curLatLng found, setting up map view...");
setupMapView(savedInstanceState);
}