Fix orientation change and material in api 16

This commit is contained in:
Dima-1 2020-08-26 16:48:02 +03:00
parent 3e6a495139
commit eb3094f253
7 changed files with 73 additions and 69 deletions

View file

@ -41,6 +41,7 @@
android:layout_marginRight="@dimen/content_padding_small"
android:layout_gravity="end"
android:background="@null"
android:saveEnabled="false"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false" />

View file

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:focusable="true"
android:focusableInTouchMode="true"/>
<net.osmand.plus.widgets.OsmandTextFieldBoxes
android:id="@+id/name_text_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingEnd="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingStart="@dimen/content_padding"
app:labelText="@string/shared_string_name">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:id="@+id/name_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</net.osmand.plus.widgets.OsmandTextFieldBoxes>
</LinearLayout>

View file

@ -8,7 +8,7 @@
android:layout_width="0dp"
android:layout_height="0dp"
android:focusable="true"
android:focusableInTouchMode="true"/>
android:focusableInTouchMode="true" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/name_text_box"
@ -23,7 +23,7 @@
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/name_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>

View file

@ -1,6 +1,5 @@
package net.osmand.plus.mapmarkers;
import android.os.Build;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.view.ContextThemeWrapper;
@ -70,14 +69,10 @@ public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragm
titleTv.setText(openFromCoordinateInput ? R.string.coord_input_save_as_track : R.string.marker_save_as_track);
titleTv.setTextColor(ContextCompat.getColor(getContext(), textPrimaryColor));
TextView descriptionTv = (TextView) mainView.findViewById(R.id.save_as_track_description);
descriptionTv.setText(openFromCoordinateInput ? getString(R.string.coord_input_save_as_track_descr, number) : getString(R.string.marker_save_as_track_descr));
int layoutRes;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
layoutRes = R.layout.markers_track_name_text_field_box;
} else {
layoutRes = R.layout.markers_track_name_edit_text;
}
contentLayout.addView(getLayoutInflater().inflate(layoutRes, contentLayout, false), 2);
descriptionTv.setText(openFromCoordinateInput
? getString(R.string.coord_input_save_as_track_descr, String.valueOf(number))
: getString(R.string.marker_save_as_track_descr));
contentLayout.addView(getLayoutInflater().inflate(R.layout.track_name_edit_text, contentLayout, false), 2);
if (portrait) {
AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
}

View file

@ -29,17 +29,15 @@ public class FolderListAdapter extends RecyclerView.Adapter<FolderListAdapter.Gr
List<String> items = new ArrayList<>();
void setSelectedItemName(String selectedItemName) {
this.selectedItemName = selectedItemName;
}
String selectedItemName;
OsmandApplication app;
boolean nightMode;
FolderListAdapterListener listener;
FolderListAdapter(OsmandApplication app, boolean nightMode) {
FolderListAdapter(OsmandApplication app, boolean nightMode, String folderName) {
this.app = app;
this.nightMode = nightMode;
selectedItemName = folderName;
fillGroups();
}
@ -85,6 +83,9 @@ public class FolderListAdapter extends RecyclerView.Adapter<FolderListAdapter.Gr
selectedItemName = items.get(holder.getAdapterPosition());
notifyItemChanged(holder.getAdapterPosition());
notifyItemChanged(previousSelectedPosition);
if (listener != null) {
listener.onItemSelected(selectedItemName);
}
}
});
final String group = Algorithms.capitalizeFirstLetter(items.get(position));
@ -120,14 +121,14 @@ public class FolderListAdapter extends RecyclerView.Adapter<FolderListAdapter.Gr
return items == null ? 0 : items.size();
}
String getSelectedItem() {
return selectedItemName;
}
int getItemPosition(String name) {
return items.indexOf(name);
}
public void setListener(FolderListAdapterListener listener) {
this.listener = listener;
}
static class GroupsViewHolder extends RecyclerView.ViewHolder {
final TextView groupName;
@ -141,4 +142,9 @@ public class FolderListAdapter extends RecyclerView.Adapter<FolderListAdapter.Gr
groupButton = itemView.findViewById(R.id.outlineRect);
}
}
public interface FolderListAdapterListener {
void onItemSelected(String item);
}
}

View file

@ -1033,7 +1033,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
private void openSaveAsNewTrackMenu(MapActivity mapActivity) {
if (mapActivity != null) {
if (editingCtx.getPointsCount() > 0) {
SaveAsNewTrackBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(), this);
SaveAsNewTrackBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(),
this, getSuggestedFileName());
} else {
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
}
@ -1329,7 +1330,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
});
showOnMapToggle.setChecked(true);
String displayedName = getSuggestedFileName(dir);
String displayedName = getSuggestedFileName();
nameEt.setText(displayedName);
nameEt.setSelection(displayedName.length());
final boolean[] textChanged = new boolean[1];
@ -1388,18 +1389,22 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
}
}
private String getSuggestedFileName(File dir) {
private String getSuggestedFileName() {
GpxData gpxData = editingCtx.getGpxData();
String displayedName;
if (gpxData == null) {
final String suggestedName = new SimpleDateFormat("EEE dd MMM yyyy", Locale.US).format(new Date());
displayedName = suggestedName;
OsmandApplication app = getMyApplication();
if (app != null) {
File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
File fout = new File(dir, suggestedName + GPX_FILE_EXT);
int ind = 0;
while (fout.exists()) {
displayedName = suggestedName + "_" + (++ind);
fout = new File(dir, displayedName + GPX_FILE_EXT);
}
}
} else {
displayedName = AndroidUtils.trimExtension(new File(gpxData.getGpxFile().path).getName());
}
@ -1639,7 +1644,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
return;
}
final GpxData gpxData = editingCtx.getGpxData();
String fileName = getSuggestedFileName(mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR));
String fileName = getSuggestedFileName();
String actionStr = getString(R.string.plan_route);
boolean editMode = isInEditMode();
if (editMode) {

View file

@ -13,6 +13,7 @@ import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import net.osmand.AndroidUtils;
@ -33,10 +34,14 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
public static final String TAG = SaveAsNewTrackBottomSheetDialogFragment.class.getSimpleName();
private static final Log LOG = PlatformUtil.getLog(SaveAsNewTrackBottomSheetDialogFragment.class);
public static final String SHOW_ON_MAP_KEY = "show_on_map_key";
public static final String SIMPLIFIED_TRACK_KEY = "simplified_track_key";
public static final String FOLDER_NAME_KEY = "folder_name_key";
boolean showOnMap;
boolean simplifiedTrack;
String fileName;
String folderName;
@Override
public void createMenuItems(Bundle savedInstanceState) {
@ -44,11 +49,16 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
if (app == null) {
return;
}
if (savedInstanceState != null) {
showOnMap = savedInstanceState.getBoolean(SHOW_ON_MAP_KEY);
simplifiedTrack = savedInstanceState.getBoolean(SIMPLIFIED_TRACK_KEY);
folderName = savedInstanceState.getString(FOLDER_NAME_KEY);
}
int activeColorRes = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
items.add(new TitleItem(getString(R.string.shared_string_save_as_gpx)));
View editNameView = UiUtilities.getInflater(app, nightMode).inflate(R.layout.markers_track_name_edit_text,
View editNameView = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.track_name_edit_text,
null, false);
TextInputLayout nameTextBox = editNameView.findViewById(R.id.name_text_box);
nameTextBox.setBoxBackgroundColorResource(R.color.material_text_input_layout_bg);
@ -56,9 +66,8 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
ColorStateList colorStateList = ColorStateList.valueOf(ContextCompat
.getColor(app, nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light));
nameTextBox.setDefaultHintTextColor(colorStateList);
if (nameTextBox.getEditText() != null) {
AndroidUtils.setHintTextSecondaryColor(app, nameTextBox.getEditText(), nightMode);
}
TextInputEditText nameText = editNameView.findViewById(R.id.name_edit_text);
nameText.setText(fileName);
BaseBottomSheetItem editFileName = new BaseBottomSheetItem.Builder()
.setCustomView(editNameView)
.create();
@ -70,7 +79,8 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
items.add(new DividerSpaceItem(app, contentPaddingSmall));
FolderListAdapter adapter = new FolderListAdapter(app, nightMode);
FolderListAdapter adapter = new FolderListAdapter(app, nightMode, folderName);
adapter.setListener(createFolderSelectListener());
View view = UiUtilities.getInflater(app, nightMode).inflate(R.layout.bottom_sheet_item_recyclerview,
null, false);
View recyclerView = view.findViewById(R.id.recycler_view);
@ -131,11 +141,29 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
items.add(new DividerSpaceItem(app, contentPaddingSmall));
}
public static void showInstance(@NonNull FragmentManager fm, @Nullable Fragment targetFragment) {
private FolderListAdapter.FolderListAdapterListener createFolderSelectListener() {
return new FolderListAdapter.FolderListAdapterListener() {
@Override
public void onItemSelected(String item) {
folderName = item;
}
};
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putBoolean(SHOW_ON_MAP_KEY, showOnMap);
outState.putBoolean(SIMPLIFIED_TRACK_KEY, simplifiedTrack);
outState.putString(FOLDER_NAME_KEY, folderName);
super.onSaveInstanceState(outState);
}
public static void showInstance(@NonNull FragmentManager fm, @Nullable Fragment targetFragment, String fileName) {
try {
if (!fm.isStateSaved()) {
SaveAsNewTrackBottomSheetDialogFragment fragment = new SaveAsNewTrackBottomSheetDialogFragment();
fragment.setTargetFragment(targetFragment, 0);
fragment.fileName = fileName;
fragment.show(fm, TAG);
}
} catch (RuntimeException e) {