Refactor: enum, unnecessary method, delete unnecessary files, screen rotate support, null fix, strinf name fix

This commit is contained in:
androiddevkkotlin 2020-11-11 12:20:22 +02:00
parent c80a358b45
commit a6f65b066f
7 changed files with 44 additions and 153 deletions

View file

@ -59,7 +59,8 @@
android:id="@+id/tags_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone" />
android:imeOptions="actionDone"
android:text="osmand"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
@ -98,9 +99,9 @@
android:paddingTop="@dimen/context_menu_first_line_top_margin"
android:paddingRight="@dimen/content_padding"
android:paddingBottom="@dimen/context_menu_first_line_top_margin"
android:text="@string/gpx_visibility_txt"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
tools:text="@string/gpx_visibility_txt"
osmand:typeface="@string/font_roboto_medium" />
</LinearLayout>

View file

@ -1,76 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TextView
android:id="@+id/DescriptionTextTop"
android:textSize="@dimen/default_list_text_size_large"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:gravity="center_horizontal"
android:text="@string/send_files_to_osm"
android:layout_marginStart="5dp" />
<TableRow android:layout_width="fill_parent">
<TextView
android:id="@+id/TextView"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="@string/shared_string_description"
android:layout_marginStart="5dp" />
<EditText
android:id="@+id/memory_size"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:minLines="3"
android:text=""
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp" />
</TableRow>
<TableRow android:layout_width="fill_parent">
<TextView
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="@string/gpx_tags_txt"
android:layout_marginStart="5dp" />
<EditText
android:id="@+id/TagsText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="osmand"
android:layout_marginEnd="5dp"
android:layout_marginStart="5dp" />
</TableRow>
<TableRow android:layout_width="fill_parent">
<TextView
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="@string/gpx_visibility_txt"
android:layout_marginStart="5dp" />
<Spinner
android:id="@+id/Visibility"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginEnd="5dp"
android:layout_marginStart="5dp" />
</TableRow>
</TableLayout>

View file

@ -11,10 +11,10 @@
Thx - Hardy
-->
<string name="trackable_visibility">Trackable means that the trace will not show up in any public listings but trackpoints from it will still be available through the public GPS API with timestamps. Other users will only be able to download processed trackpoints from your trace which can\'t be associated with you directly.</string>
<string name="identifiable_visibility">Identifiable means that the trace will be shown publicly in Your GPS traces and in public GPS trace listings, i.e. other users will be able to download the raw trace and associate it with your username. Data served via the trackpoints API will reference your original trace page. Timestamps of the trace points are available through the public GPS API.</string>
<string name="private_visibility">Private means that the trace will not show up in any public listings, but trackpoints from it will still be available through the public GPS API without timestamps but will not be chronologically ordered.</string>
<string name="public_visibility">Public means that the trace will be shown publicly in Your GPS traces and in public GPS trace listings. Data served via the API does not reference your trace page. Timestamps of the trace points are not available through the public GPS API, and the points are not chronologically ordered. However, other users are still able to download the raw trace from the public trace list and any timestamps contained within.</string>
<string name="gpx_upload_trackable_visibility_descr">Trackable means that the trace will not show up in any public listings but trackpoints from it will still be available through the public GPS API with timestamps. Other users will only be able to download processed trackpoints from your trace which can\'t be associated with you directly.</string>
<string name="gpx_upload_identifiable_visibility_descr">Identifiable means that the trace will be shown publicly in Your GPS traces and in public GPS trace listings, i.e. other users will be able to download the raw trace and associate it with your username. Data served via the trackpoints API will reference your original trace page. Timestamps of the trace points are available through the public GPS API.</string>
<string name="gpx_upload_private_visibility_descr">Private means that the trace will not show up in any public listings, but trackpoints from it will still be available through the public GPS API without timestamps but will not be chronologically ordered.</string>
<string name="gpx_upload_public_visibility_descr">Public means that the trace will be shown publicly in Your GPS traces and in public GPS trace listings. Data served via the API does not reference your trace page. Timestamps of the trace points are not available through the public GPS API, and the points are not chronologically ordered. However, other users are still able to download the raw trace from the public trace list and any timestamps contained within.</string>
<string name="enter_text_separated">Enter tags separated by comma.</string>
<string name="send_files_to_openstreetmap">Send GPX file to OpenStreetMap</string>
<string name="subscription_on_hold_title">OsmAnd Live subscription is on hold</string>

View file

@ -1,38 +0,0 @@
package net.osmand.plus.activities;
import net.osmand.plus.activities.EnumAdapter.IEnumWithResource;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class EnumAdapter<T extends IEnumWithResource>
extends ArrayAdapter<T>
{
public EnumAdapter(Context context, int textViewResourceId, T[] enums)
{
super(context, textViewResourceId, enums);
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
TextView textView = (TextView) super.getDropDownView(position, convertView, parent);
T item = getItem(position);
textView.setText(item.stringResource());
return textView;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView textView = (TextView) super.getView(position, convertView, parent);
T item = getItem(position);
textView.setText(item.stringResource());
return textView;
}
public static interface IEnumWithResource {
int stringResource();
}
}

View file

@ -30,7 +30,6 @@ import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.EnumAdapter.IEnumWithResource;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TabActivity;
import net.osmand.plus.dashboard.DashboardOnMap.DashboardType;
@ -433,16 +432,19 @@ public class OsmEditingPlugin extends OsmandPlugin {
}
}
public enum UploadVisibility implements IEnumWithResource {
Public(R.string.gpxup_public, R.string.public_visibility),
Identifiable(R.string.gpxup_identifiable, R.string.identifiable_visibility),
Trackable(R.string.gpxup_trackable, R.string.trackable_visibility),
Private(R.string.gpxup_private, R.string.private_visibility);
private final int resourceId;
public enum UploadVisibility {
PUBLIC(R.string.gpxup_public, R.string.gpx_upload_public_visibility_descr),
IDENTIFIABLE(R.string.gpxup_identifiable, R.string.gpx_upload_identifiable_visibility_descr),
TRACKABLE(R.string.gpxup_trackable, R.string.gpx_upload_trackable_visibility_descr),
PRIVATE(R.string.gpxup_private, R.string.gpx_upload_private_visibility_descr);
@StringRes
private final int titleId;
@StringRes
private final int descriptionId;
UploadVisibility(int resourceId,int descriptionId ) {
this.resourceId = resourceId;
UploadVisibility(int titleId, int descriptionId) {
this.titleId = titleId;
this.descriptionId = descriptionId;
}
@ -450,9 +452,9 @@ public class OsmEditingPlugin extends OsmandPlugin {
return name().toLowerCase();
}
@Override
public int stringResource() {
return resourceId;
@StringRes
public int getTitleId() {
return titleId;
}
@StringRes

View file

@ -22,7 +22,7 @@ public class UploadGPXFilesTask extends AsyncTask<GpxInfo, String, String> {
this.la = la;
this.description = description;
this.tagstring = tagstring;
this.visibility = visibility != null ? visibility.asURLparam() : UploadVisibility.Private.asURLparam();
this.visibility = visibility != null ? visibility.asURLparam() : UploadVisibility.PRIVATE.asURLparam();
}

View file

@ -2,7 +2,9 @@ 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;
@ -16,6 +18,7 @@ import androidx.recyclerview.widget.RecyclerView;
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.base.MenuBottomSheetDialogFragment;
@ -32,13 +35,14 @@ import net.osmand.util.Algorithms;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
public static final String TAG = SendGpxBottomSheetFragment.class.getSimpleName();
private GpxInfo[] gpxInfos;
private UploadVisibility selectedUploadVisibility = UploadVisibility.Public;
private UploadVisibility selectedUploadVisibility = UploadVisibility.PUBLIC;
private TextInputEditText tagsField;
private TextInputEditText messageField;
@ -49,12 +53,14 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
@Override
public void createMenuItems(Bundle savedInstanceState) {
View sendOsmPoiView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.send_gpx_fragment, null);
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);
OsmandSettings settings = requiredMyApplication().getSettings();
OsmandApplication app = requiredMyApplication();
OsmandSettings settings = app.getSettings();
TextView accountName = sendOsmPoiView.findViewById(R.id.user_name);
if (!Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get())) {
@ -63,32 +69,29 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
accountName.setText(settings.USER_NAME.get());
}
if (gpxInfos.length > 0 && gpxInfos[0].getFileName() != null) {
int dt = gpxInfos[0].getFileName().indexOf('.');
messageField.setText(gpxInfos[0].getFileName().substring(0, dt));
}
tagsField.setText(R.string.app_name_osmand);
String fileName = gpxInfos[0].getFileName();
messageField.setText(Algorithms.getFileNameWithoutExtension(fileName));
final TextView visibilityName = sendOsmPoiView.findViewById(R.id.visibility_name);
final TextView visibilityDescription = sendOsmPoiView.findViewById(R.id.visibility_description);
visibilityName.setText(selectedUploadVisibility.stringResource());
visibilityName.setText(selectedUploadVisibility.getTitleId());
visibilityDescription.setText(selectedUploadVisibility.getDescriptionId());
List<HorizontalSelectionItem> itemsVisibility = new ArrayList<>();
for (UploadVisibility visibilityType : UploadVisibility.values()) {
String title = getString(visibilityType.stringResource());
String title = getString(visibilityType.getTitleId());
HorizontalSelectionItem item = new HorizontalSelectionAdapter.HorizontalSelectionItem(title, visibilityType);
itemsVisibility.add(item);
}
final HorizontalSelectionAdapter horizontalSelectionAdapter = new HorizontalSelectionAdapter(getMyApplication(), nightMode);
final HorizontalSelectionAdapter horizontalSelectionAdapter = new HorizontalSelectionAdapter(app, nightMode);
horizontalSelectionAdapter.setItems(itemsVisibility);
horizontalSelectionAdapter.setSelectedItemByTitle(getString(selectedUploadVisibility.stringResource()));
horizontalSelectionAdapter.setSelectedItemByTitle(getString(selectedUploadVisibility.getTitleId()));
horizontalSelectionAdapter.setListener(new HorizontalSelectionAdapterListener() {
@Override
public void onItemSelected(HorizontalSelectionAdapter.HorizontalSelectionItem item) {
selectedUploadVisibility = (OsmEditingPlugin.UploadVisibility) item.getObject();
visibilityName.setText(selectedUploadVisibility.stringResource());
visibilityName.setText(selectedUploadVisibility.getTitleId());
visibilityDescription.setText(selectedUploadVisibility.getDescriptionId());
horizontalSelectionAdapter.notifyDataSetChanged();
}
@ -97,17 +100,14 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
RecyclerView iconCategoriesRecyclerView = sendOsmPoiView.findViewById(R.id.description_view);
iconCategoriesRecyclerView.setAdapter(horizontalSelectionAdapter);
iconCategoriesRecyclerView.setLayoutManager(new LinearLayoutManager(getMyApplication(), RecyclerView.HORIZONTAL, false));
iconCategoriesRecyclerView.setLayoutManager(new LinearLayoutManager(app, RecyclerView.HORIZONTAL, false));
horizontalSelectionAdapter.notifyDataSetChanged();
SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
.setCustomView(sendOsmPoiView)
.create();
items.add(titleItem);
}
private boolean isLoginOAuth() {
return !Algorithms.isEmpty(getMyApplication().getSettings().USER_DISPLAY_NAME.get());
setRetainInstance(true);
}
@Override
@ -124,8 +124,10 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment {
protected void onRightBottomButtonClick() {
FragmentActivity activity = getActivity();
if (activity != null) {
String tags = tagsField.getText().toString();
String descr = messageField.getText().toString();
Editable tagsText = tagsField.getText();
Editable descrText = messageField.getText();
String tags = tagsText != null ? tagsText.toString() : "";
String descr = descrText != null ? descrText.toString() : "";
UploadGPXFilesTask uploadGPXFilesTask = new UploadGPXFilesTask(activity, descr, tags, selectedUploadVisibility);
uploadGPXFilesTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, gpxInfos);