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

View file

@ -1,29 +1,36 @@
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.R;
import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo;
import net.osmand.plus.osmedit.OsmEditingPlugin.UploadVisibility;
import android.app.Activity;
import android.os.AsyncTask;
import android.widget.Toast;
import java.io.File;
import java.lang.ref.WeakReference;
public class UploadGPXFilesTask extends AsyncTask<GpxInfo, String, String> {
private final OsmandApplication app;
private final WeakReference<Activity> activityRef;
private final String visibility;
private final String description;
private final String tagstring;
private Activity la;
public UploadGPXFilesTask(Activity la,
String description, String tagstring, UploadVisibility visibility) {
this.la = la;
public UploadGPXFilesTask(@NonNull Activity activity, String description, String tagsString,
@Nullable UploadVisibility visibility) {
app = (OsmandApplication) activity.getApplication();
this.activityRef = new WeakReference<>(activity);
this.description = description;
this.tagstring = tagstring;
this.tagstring = tagsString;
this.visibility = visibility != null ? visibility.asURLparam() : UploadVisibility.PRIVATE.asURLparam();
}
@Override
@ -32,10 +39,9 @@ public class UploadGPXFilesTask extends AsyncTask<GpxInfo, String, String> {
int total = 0;
for (GpxInfo info : params) {
if (!isCancelled() && info.file != null) {
String warning = null;
File file = info.file;
warning = new OpenstreetmapRemoteUtil((OsmandApplication) la.getApplication()).uploadGPXFile(tagstring, description, visibility,
file);
OpenstreetmapRemoteUtil remoteUtil = new OpenstreetmapRemoteUtil(app);
String warning = remoteUtil.uploadGPXFile(tagstring, description, visibility, file);
total++;
if (warning == null) {
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
@ -57,19 +63,24 @@ public class UploadGPXFilesTask extends AsyncTask<GpxInfo, String, String> {
}
b.append(values[i]);
}
Toast.makeText(la, b.toString(), Toast.LENGTH_LONG).show();
app.showToastMessage(b.toString());
}
}
@Override
protected void onPreExecute() {
la.setProgressBarIndeterminateVisibility(true);
Activity activity = activityRef.get();
if (AndroidUtils.isActivityNotDestroyed(activity)) {
activity.setProgressBarIndeterminateVisibility(true);
}
}
@Override
protected void onPostExecute(String result) {
la.setProgressBarIndeterminateVisibility(false);
Toast.makeText(la, result, Toast.LENGTH_LONG).show();
Activity activity = activityRef.get();
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.Bundle;
import android.text.Editable;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
@ -21,6 +20,7 @@ import com.google.android.material.textfield.TextInputEditText;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.UiUtilities.DialogButtonType;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter;
@ -35,7 +35,6 @@ import net.osmand.util.Algorithms;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
@ -53,15 +52,15 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
@Override
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();
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);
if (!Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get())) {
accountName.setText(settings.USER_DISPLAY_NAME.get());
@ -107,12 +106,11 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
.setCustomView(sendOsmPoiView)
.create();
items.add(titleItem);
setRetainInstance(true);
}
@Override
protected UiUtilities.DialogButtonType getRightBottomButtonType() {
return (UiUtilities.DialogButtonType.PRIMARY);
protected DialogButtonType getRightBottomButtonType() {
return DialogButtonType.PRIMARY;
}
@Override
@ -140,6 +138,7 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
SendGpxBottomSheetFragment fragment = new SendGpxBottomSheetFragment();
fragment.setTargetFragment(targetFragment, 0);
fragment.setGpxInfos(info);
fragment.setRetainInstance(true);
fragment.show(fragmentManager, TAG);
}
}