Small fixes in send gpx task

This commit is contained in:
Vitaliy 2020-11-11 16:48:43 +02:00
parent 5380837e63
commit ec8e778b6a
3 changed files with 48 additions and 36 deletions

View file

@ -3,7 +3,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:osmand="http://schemas.android.com/apk/res-auto" xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
@ -27,7 +27,6 @@
android:textSize="@dimen/default_list_text_size" android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_medium" /> osmand:typeface="@string/font_roboto_medium" />
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/message_label" android:id="@+id/message_label"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -42,6 +41,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:imeOptions="actionDone" /> android:imeOptions="actionDone" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
@ -60,7 +60,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:imeOptions="actionDone" android:imeOptions="actionDone"
android:text="osmand"/> android:text="osmand" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
</LinearLayout> </LinearLayout>
@ -101,8 +102,9 @@
android:paddingBottom="@dimen/context_menu_first_line_top_margin" android:paddingBottom="@dimen/context_menu_first_line_top_margin"
android:textColor="?android:textColorSecondary" android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size" android:textSize="@dimen/default_desc_text_size"
tools:text="@string/gpx_visibility_txt" osmand:typeface="@string/font_roboto_medium"
osmand:typeface="@string/font_roboto_medium" /> tools:text="@string/gpx_visibility_txt" />
</LinearLayout> </LinearLayout>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
@ -195,5 +197,5 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -1,29 +1,36 @@
package net.osmand.plus.osmedit; package net.osmand.plus.osmedit;
import java.io.File; import android.app.Activity;
import android.os.AsyncTask;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import net.osmand.AndroidUtils;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo; import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo;
import net.osmand.plus.osmedit.OsmEditingPlugin.UploadVisibility; import net.osmand.plus.osmedit.OsmEditingPlugin.UploadVisibility;
import android.app.Activity;
import android.os.AsyncTask; import java.io.File;
import android.widget.Toast; import java.lang.ref.WeakReference;
public class UploadGPXFilesTask extends AsyncTask<GpxInfo, String, String> { public class UploadGPXFilesTask extends AsyncTask<GpxInfo, String, String> {
private final OsmandApplication app;
private final WeakReference<Activity> activityRef;
private final String visibility; private final String visibility;
private final String description; private final String description;
private final String tagstring; private final String tagstring;
private Activity la;
public UploadGPXFilesTask(Activity la, public UploadGPXFilesTask(@NonNull Activity activity, String description, String tagsString,
String description, String tagstring, UploadVisibility visibility) { @Nullable UploadVisibility visibility) {
this.la = la; app = (OsmandApplication) activity.getApplication();
this.activityRef = new WeakReference<>(activity);
this.description = description; this.description = description;
this.tagstring = tagstring; this.tagstring = tagsString;
this.visibility = visibility != null ? visibility.asURLparam() : UploadVisibility.PRIVATE.asURLparam(); this.visibility = visibility != null ? visibility.asURLparam() : UploadVisibility.PRIVATE.asURLparam();
} }
@Override @Override
@ -32,10 +39,9 @@ public class UploadGPXFilesTask extends AsyncTask<GpxInfo, String, String> {
int total = 0; int total = 0;
for (GpxInfo info : params) { for (GpxInfo info : params) {
if (!isCancelled() && info.file != null) { if (!isCancelled() && info.file != null) {
String warning = null;
File file = info.file; File file = info.file;
warning = new OpenstreetmapRemoteUtil((OsmandApplication) la.getApplication()).uploadGPXFile(tagstring, description, visibility, OpenstreetmapRemoteUtil remoteUtil = new OpenstreetmapRemoteUtil(app);
file); String warning = remoteUtil.uploadGPXFile(tagstring, description, visibility, file);
total++; total++;
if (warning == null) { if (warning == null) {
count++; count++;
@ -44,7 +50,7 @@ public class UploadGPXFilesTask extends AsyncTask<GpxInfo, String, String> {
} }
} }
} }
return la.getString(R.string.local_index_items_uploaded, count, total); return app.getString(R.string.local_index_items_uploaded, count, total);
} }
@Override @Override
@ -57,19 +63,24 @@ public class UploadGPXFilesTask extends AsyncTask<GpxInfo, String, String> {
} }
b.append(values[i]); b.append(values[i]);
} }
Toast.makeText(la, b.toString(), Toast.LENGTH_LONG).show(); app.showToastMessage(b.toString());
} }
} }
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
la.setProgressBarIndeterminateVisibility(true); Activity activity = activityRef.get();
if (AndroidUtils.isActivityNotDestroyed(activity)) {
activity.setProgressBarIndeterminateVisibility(true);
}
} }
@Override @Override
protected void onPostExecute(String result) { protected void onPostExecute(String result) {
la.setProgressBarIndeterminateVisibility(false); Activity activity = activityRef.get();
Toast.makeText(la, result, Toast.LENGTH_LONG).show(); if (AndroidUtils.isActivityNotDestroyed(activity)) {
activity.setProgressBarIndeterminateVisibility(false);
}
app.showToastMessage(result);
} }
} }

View file

@ -3,7 +3,6 @@ package net.osmand.plus.osmedit.dialogs;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
@ -21,6 +20,7 @@ import com.google.android.material.textfield.TextInputEditText;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.UiUtilities.DialogButtonType;
import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter; import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter;
@ -35,7 +35,6 @@ import net.osmand.util.Algorithms;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment { public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
@ -53,15 +52,15 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
@Override @Override
public void createMenuItems(Bundle savedInstanceState) { public void createMenuItems(Bundle savedInstanceState) {
LayoutInflater themedInflater = UiUtilities.getInflater(requireContext(), nightMode);
View sendOsmPoiView = themedInflater.inflate(R.layout.send_gpx_fragment, null);
messageField = sendOsmPoiView.findViewById(R.id.message_field);
tagsField = sendOsmPoiView.findViewById(R.id.tags_field);
OsmandApplication app = requiredMyApplication(); OsmandApplication app = requiredMyApplication();
OsmandSettings settings = app.getSettings(); OsmandSettings settings = app.getSettings();
LayoutInflater themedInflater = UiUtilities.getInflater(app, nightMode);
View sendOsmPoiView = themedInflater.inflate(R.layout.send_gpx_fragment, null);
tagsField = sendOsmPoiView.findViewById(R.id.tags_field);
messageField = sendOsmPoiView.findViewById(R.id.message_field);
TextView accountName = sendOsmPoiView.findViewById(R.id.user_name); TextView accountName = sendOsmPoiView.findViewById(R.id.user_name);
if (!Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get())) { if (!Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get())) {
accountName.setText(settings.USER_DISPLAY_NAME.get()); accountName.setText(settings.USER_DISPLAY_NAME.get());
@ -107,12 +106,11 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
.setCustomView(sendOsmPoiView) .setCustomView(sendOsmPoiView)
.create(); .create();
items.add(titleItem); items.add(titleItem);
setRetainInstance(true);
} }
@Override @Override
protected UiUtilities.DialogButtonType getRightBottomButtonType() { protected DialogButtonType getRightBottomButtonType() {
return (UiUtilities.DialogButtonType.PRIMARY); return DialogButtonType.PRIMARY;
} }
@Override @Override
@ -140,6 +138,7 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
SendGpxBottomSheetFragment fragment = new SendGpxBottomSheetFragment(); SendGpxBottomSheetFragment fragment = new SendGpxBottomSheetFragment();
fragment.setTargetFragment(targetFragment, 0); fragment.setTargetFragment(targetFragment, 0);
fragment.setGpxInfos(info); fragment.setGpxInfos(info);
fragment.setRetainInstance(true);
fragment.show(fragmentManager, TAG); fragment.show(fragmentManager, TAG);
} }
} }