Skip to content

[Enhacement] Save app state: category name (fixes part of issue #4965) #5092

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import android.content.Intent;
import android.graphics.BitmapFactory;
import android.location.Location;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
Expand All @@ -20,6 +21,7 @@
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
Expand All @@ -29,6 +31,10 @@
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.mapbox.android.core.location.LocationEngine;
import com.mapbox.android.core.location.LocationEngineCallback;
import com.mapbox.android.core.location.LocationEngineResult;
import com.mapbox.android.core.permissions.PermissionsListener;
import com.mapbox.android.core.permissions.PermissionsManager;
import com.mapbox.geojson.Point;
import com.mapbox.mapboxsdk.camera.CameraPosition;
Expand All @@ -53,6 +59,7 @@
import fr.free.nrw.commons.Utils;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.theme.BaseActivity;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Named;
import org.jetbrains.annotations.NotNull;
Expand All @@ -62,7 +69,8 @@
* Helps to pick location and return the result with an intent
*/
public class LocationPickerActivity extends BaseActivity implements OnMapReadyCallback,
OnCameraMoveStartedListener, OnCameraIdleListener, Observer<CameraPosition> {
OnCameraMoveStartedListener, OnCameraIdleListener, Observer<CameraPosition>,
PermissionsListener {

/**
* DROPPED_MARKER_LAYER_ID : id for layer
Expand All @@ -72,6 +80,10 @@ public class LocationPickerActivity extends BaseActivity implements OnMapReadyCa
* cameraPosition : position of picker
*/
private CameraPosition cameraPosition;
/**
* deviceLocation : position of device
*/
private Location deviceLocation;
/**
* markerImage : picker image
*/
Expand All @@ -84,6 +96,10 @@ public class LocationPickerActivity extends BaseActivity implements OnMapReadyCa
* mapView : view of the map
*/
private MapView mapView;
/**
* permissionsManager : permissions of the location
*/
private PermissionsManager permissionsManager;
/**
* tvAttribution : credit
*/
Expand All @@ -104,6 +120,10 @@ public class LocationPickerActivity extends BaseActivity implements OnMapReadyCa
* placeSelectedButton : fab for selecting location
*/
FloatingActionButton placeSelectedButton;
/**
* centerDeviceLocationButton : fab for center the camera to device's location
*/
FloatingActionButton centerDeviceLocationButton;
/**
* droppedMarkerLayer : Layer for static screen
*/
Expand Down Expand Up @@ -152,11 +172,13 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) {
bindViews();
addBackButtonListener();
addPlaceSelectedButton();
addCenterDeviceLocationButton();
addCredits();
getToolbarUI();

if ("UploadActivity".equals(activity)) {
placeSelectedButton.setVisibility(View.GONE);
centerDeviceLocationButton.setVisibility(View.GONE);
modifyLocationButton.setVisibility(View.VISIBLE);
showInMapButton.setVisibility(View.VISIBLE);
largeToolbarText.setText(getResources().getString(R.string.image_location));
Expand Down Expand Up @@ -267,6 +289,7 @@ private void onStyleLoaded(final Style style) {
*/
private void onClickModifyLocation() {
placeSelectedButton.setVisibility(View.VISIBLE);
centerDeviceLocationButton.setVisibility(View.VISIBLE);
modifyLocationButton.setVisibility(View.GONE);
showInMapButton.setVisibility(View.GONE);
droppedMarkerLayer.setProperties(visibility(NONE));
Expand Down Expand Up @@ -334,11 +357,27 @@ private void enableLocationComponent(@NonNull final Style loadedMapStyle) {
locationComponent.setLocationComponentEnabled(true);

// Set the component's camera mode
locationComponent.setCameraMode(CameraMode.NONE);
locationComponent.setCameraMode(CameraMode.TRACKING);

// Set the component's render mode
locationComponent.setRenderMode(RenderMode.NORMAL);

locationComponent.getLocationEngine().getLastLocation(
new LocationEngineCallback<LocationEngineResult>() {
@Override
public void onSuccess(LocationEngineResult result) {
deviceLocation = result.getLastLocation();
}

@Override
public void onFailure(@NonNull Exception exception) {

}
});

} else {
permissionsManager = new PermissionsManager(this);
permissionsManager.requestLocationPermissions(this);
}
}

Expand Down Expand Up @@ -406,6 +445,22 @@ void placeSelected() {
finish();
}

/**
* Center the camera to current device's location
*/
private void addCenterDeviceLocationButton() {
centerDeviceLocationButton = findViewById(R.id.current_location_button);
enableLocationComponent(mapboxMap.getStyle());
centerDeviceLocationButton.setOnClickListener(view -> centerCameraPosition());
}

/**
* Center the camera to current device's location
*/
void centerCameraPosition(){
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(deviceLocation.getLatitude(), deviceLocation.getLongitude()),13.0));
}

@Override
protected void onStart() {
super.onStart();
Expand Down Expand Up @@ -447,4 +502,26 @@ public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}

@Override
public void onExplanationNeeded(List<String> permissionsToExplain) {
Toast.makeText(this, "Permission required to get current location", Toast.LENGTH_SHORT).show();
}

@Override
public void onPermissionResult(boolean granted) {
if (granted){
enableLocationComponent(mapboxMap.getStyle());
} else {
Toast.makeText(this, "Permission not granted!", Toast.LENGTH_SHORT).show();
finish();
}
}

@Override
public void onRequestPermissionsResult(final int requestCode, @NonNull final String[] permissions,
@NonNull final int[] grantResults) {
permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import static fr.free.nrw.commons.category.CategoryClientKt.CATEGORY_PREFIX;

import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
Expand Down Expand Up @@ -65,8 +67,23 @@ protected void onCreate(Bundle savedInstanceState) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setTabs();
setPageTitle();

if (null != savedInstanceState) {
categoryName = savedInstanceState.getString("categoryName");
}
}

/**
* Save categoryName
* @param outState
*/
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString("categoryName", categoryName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment including example values, especially with multiple selected categories. Thanks!

}


/**
* This activity contains 3 tabs and a viewpager. This method is used to set the titles of tab,
* Set the fragments according to the tab selected in the viewPager.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ protected void onBecameVisible() {

@Override
public void goToNextScreen() {
callback.onNextButtonClicked(callback.getIndexInViewFlipper(this));
callback.onNextButtonClicked(callback.getIndexInViewFlipper(this)+1);
}

@Override
public void goToPreviousScreen() {
callback.onPreviousButtonClicked(callback.getIndexInViewFlipper(this));
callback.onPreviousButtonClicked(callback.getIndexInViewFlipper(this)-1);
}

@Override
Expand Down Expand Up @@ -319,7 +319,7 @@ public void onPreviousButtonClicked() {
updateDepicts();
goBackToPreviousScreen();
} else {
callback.onPreviousButtonClicked(callback.getIndexInViewFlipper(this));
callback.onPreviousButtonClicked(callback.getIndexInViewFlipper(this)-1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,12 @@ public void onDestroy() {

@OnClick(R.id.btn_previous)
public void onPreviousButtonClicked() {
callback.onPreviousButtonClicked(callback.getIndexInViewFlipper(this));
callback.onPreviousButtonClicked(callback.getIndexInViewFlipper(this)-1);
}

@OnClick(R.id.btn_submit)
public void onSubmitButtonClicked() {
callback.onNextButtonClicked(callback.getIndexInViewFlipper(this));
callback.onNextButtonClicked(callback.getIndexInViewFlipper(this)+1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,12 @@ private void showInfoAlert(int titleStringID, int messageStringId) {

@OnClick(R.id.btn_next)
public void onNextButtonClicked() {
presenter.verifyImageQuality(callback.getIndexInViewFlipper(this));
presenter.verifyImageQuality(callback.getIndexInViewFlipper(this)+1);
}

@OnClick(R.id.btn_previous)
public void onPreviousButtonClicked() {
callback.onPreviousButtonClicked(callback.getIndexInViewFlipper(this));
callback.onPreviousButtonClicked(callback.getIndexInViewFlipper(this)-1);
}

@OnClick(R.id.btn_add_description)
Expand Down Expand Up @@ -320,7 +320,7 @@ public void showProgress(boolean shouldShow) {

@Override
public void onImageValidationSuccess() {
callback.onNextButtonClicked(callback.getIndexInViewFlipper(this));
callback.onNextButtonClicked(callback.getIndexInViewFlipper(this)+1);
}

/**
Expand Down
18 changes: 17 additions & 1 deletion app/src/main/res/layout/bottom_container_location_picker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/ic_check_black_24dp" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/current_location_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_marginStart="336dp"
android:layout_marginBottom="656dp"
android:contentDescription="@string/select_location_location_picker"
android:tint="@color/achievement_background_dark"
app:backgroundTint="@color/white"
app:elevation="3dp"
app:layout_anchorGravity="top|end"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/ic_my_location_black_24dp" />

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_attribution"
android:layout_width="wrap_content"
Expand Down Expand Up @@ -64,12 +80,12 @@
android:id="@+id/show_in_map"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="@string/show_in_map_app"
android:textAlignment="center"
android:textColor="@color/primaryColor"
android:textSize="14sp"
android:visibility="gone"
android:layout_margin="5dp"
app:layout_constraintBottom_toBottomOf="@id/map_bottom_layout"
app:layout_constraintEnd_toEndOf="@id/map_bottom_layout"
app:layout_constraintStart_toStartOf="@+id/guideline3"
Expand Down