Show uploaded images in the context menu immediately after upload

This commit is contained in:
Vitaliy 2021-02-03 14:04:36 +02:00
parent d6b1f24b55
commit d63e21668f
3 changed files with 49 additions and 31 deletions

View file

@ -19,9 +19,9 @@ import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem;
import net.osmand.plus.mapcontextmenu.UploadPhotosAsyncTask.UploadPhotosListener;
import net.osmand.plus.mapcontextmenu.UploadPhotosAsyncTask.UploadPhotosProgressListener;
public class UploadPhotoProgressBottomSheet extends MenuBottomSheetDialogFragment implements UploadPhotosListener {
public class UploadPhotoProgressBottomSheet extends MenuBottomSheetDialogFragment implements UploadPhotosProgressListener {
public static final String TAG = UploadPhotoProgressBottomSheet.class.getSimpleName();
@ -103,7 +103,7 @@ public class UploadPhotoProgressBottomSheet extends MenuBottomSheetDialogFragmen
return uploadingFinished ? R.string.shared_string_close : R.string.shared_string_cancel;
}
public static UploadPhotosListener showInstance(@NonNull FragmentManager fragmentManager, int maxProgress, OnDismissListener listener) {
public static UploadPhotosProgressListener showInstance(@NonNull FragmentManager fragmentManager, int maxProgress, OnDismissListener listener) {
UploadPhotoProgressBottomSheet fragment = new UploadPhotoProgressBottomSheet();
fragment.setRetainInstance(true);
fragment.setMaxProgress(maxProgress);

View file

@ -36,6 +36,7 @@ import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.data.Amenity;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
@ -51,6 +52,7 @@ import net.osmand.plus.activities.ActivityResultListener;
import net.osmand.plus.activities.ActivityResultListener.OnActivityResultListener;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.mapcontextmenu.UploadPhotosAsyncTask.UploadPhotosListener;
import net.osmand.plus.mapcontextmenu.builders.cards.AbstractCard;
import net.osmand.plus.mapcontextmenu.builders.cards.CardsRowBuilder;
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
@ -75,6 +77,10 @@ import net.osmand.plus.widgets.tools.ClickableSpanTouchListener;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@ -85,8 +91,9 @@ import java.util.Set;
import static net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.GetImageCardsListener;
public class MenuBuilder {
public class MenuBuilder implements UploadPhotosListener {
private static final Log LOG = PlatformUtil.getLog(MenuBuilder.class);
private static final int PICK_IMAGE = 1231;
public static final float SHADOW_HEIGHT_TOP_DP = 17f;
public static final int TITLE_LIMIT = 60;
@ -168,6 +175,25 @@ public class MenuBuilder {
}
}
@Override
public void uploadPhotosSuccess(final String response) {
app.runInUIThread(new Runnable() {
@Override
public void run() {
if (AndroidUtils.isActivityNotDestroyed(mapActivity)) {
try {
ImageCard imageCard = ImageCard.createCardOpr(mapActivity, new JSONObject(response));
if (imageCard != null) {
addImageCard(imageCard);
}
} catch (JSONException e) {
LOG.error(e);
}
}
}
});
}
public interface CollapseExpandListener {
void onCollapseExpand(boolean collapsed);
}
@ -490,7 +516,7 @@ public class MenuBuilder {
}
}
}
execute(new UploadPhotosAsyncTask(mapActivity, imagesUri, getLatLon(), placeId, getAdditionalCardParams(), imageCardListener));
execute(new UploadPhotosAsyncTask(mapActivity, imagesUri, placeId, MenuBuilder.this));
}
}
}));

View file

@ -13,14 +13,11 @@ import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
import net.osmand.osm.io.NetworkUtils;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.UploadPhotoProgressBottomSheet;
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask;
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.GetImageCardsListener;
import net.osmand.plus.openplacereviews.OPRConstants;
import net.osmand.plus.openplacereviews.OprStartFragment;
import net.osmand.plus.osmedit.opr.OpenDBAPI;
@ -36,7 +33,6 @@ import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
@ -47,22 +43,17 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
private final OsmandApplication app;
private final WeakReference<MapActivity> activityRef;
private final OpenDBAPI openDBAPI = new OpenDBAPI();
private final LatLon latLon;
private final List<Uri> data;
private final String[] placeId;
private final Map<String, String> params;
private final GetImageCardsListener imageCardListener;
private UploadPhotosListener listener;
private final UploadPhotosListener listener;
private UploadPhotosProgressListener progressListener;
public UploadPhotosAsyncTask(MapActivity activity, List<Uri> data, LatLon latLon, String[] placeId,
Map<String, String> params, GetImageCardsListener imageCardListener) {
public UploadPhotosAsyncTask(MapActivity activity, List<Uri> data, String[] placeId, UploadPhotosListener listener) {
app = (OsmandApplication) activity.getApplicationContext();
activityRef = new WeakReference<>(activity);
this.data = data;
this.latLon = latLon;
this.params = params;
this.placeId = placeId;
this.imageCardListener = imageCardListener;
this.listener = listener;
}
@Override
@ -70,7 +61,7 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
FragmentActivity activity = activityRef.get();
if (AndroidUtils.isActivityNotDestroyed(activity)) {
FragmentManager manager = activity.getSupportFragmentManager();
listener = UploadPhotoProgressBottomSheet.showInstance(manager, data.size(), new OnDismissListener() {
progressListener = UploadPhotoProgressBottomSheet.showInstance(manager, data.size(), new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
cancel(false);
@ -81,8 +72,8 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
@Override
protected void onProgressUpdate(Integer... values) {
if (listener != null) {
listener.uploadPhotosProgressUpdate(values[0]);
if (progressListener != null) {
progressListener.uploadPhotosProgressUpdate(values[0]);
}
}
@ -103,8 +94,8 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
@Override
protected void onPostExecute(Void aVoid) {
if (listener != null) {
listener.uploadPhotosFinished();
if (progressListener != null) {
progressListener.uploadPhotosFinished();
}
}
@ -156,13 +147,9 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
checkTokenAndShowScreen();
} else {
success = true;
String str = app.getString(R.string.successfully_uploaded_pattern, 1, 1);
app.showToastMessage(str);
//refresh the image
MapActivity activity = activityRef.get();
if (activity != null) {
MenuBuilder.execute(new GetImageCardsTask(activity, latLon, params, imageCardListener));
if (listener != null) {
listener.uploadPhotosSuccess(response);
}
}
} else {
@ -215,12 +202,17 @@ public class UploadPhotosAsyncTask extends AsyncTask<Void, Integer, Void> {
return os.toByteArray();
}
public interface UploadPhotosListener {
public interface UploadPhotosProgressListener {
void uploadPhotosProgressUpdate(int progress);
void uploadPhotosFinished();
}
public interface UploadPhotosListener {
void uploadPhotosSuccess(String response);
}
}