add new button "Add new folder" in "Save as new track" dialog;

fix show edit text with an empty name in "Add new folder" dialog;
fix start typing a name with a capital letter
This commit is contained in:
Skalii 2021-02-18 18:40:06 +02:00
parent 2b20857230
commit 90c29ef6fe
5 changed files with 91 additions and 40 deletions

View file

@ -24,6 +24,7 @@
android:id="@+id/name_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapSentences"
android:lineSpacingMultiplier="@dimen/bottom_sheet_text_spacing_multiplier" />
</com.google.android.material.textfield.TextInputLayout>

View file

@ -39,6 +39,7 @@ import net.osmand.plus.base.bottomsheetmenu.HorizontalRecyclerBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.measurementtool.adapter.FolderListAdapter;
import net.osmand.plus.myplaces.AddNewTrackFolderBottomSheet;
import net.osmand.plus.myplaces.MoveGpxFileBottomSheet;
import net.osmand.plus.myplaces.MoveGpxFileBottomSheet.OnTrackFileMoveListener;
import net.osmand.util.Algorithms;
@ -49,7 +50,8 @@ import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDialogFragment implements OnTrackFileMoveListener {
public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDialogFragment
implements OnTrackFileMoveListener, AddNewTrackFolderBottomSheet.OnTrackFolderAddListener {
public static final String TAG = SaveAsNewTrackBottomSheetDialogFragment.class.getSimpleName();
private static final Log LOG = PlatformUtil.getLog(SaveAsNewTrackBottomSheetDialogFragment.class);
@ -250,6 +252,15 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
updateFileNameFromEditText(editText.getText().toString());
}
}
@Override
public void onAddNewItemSelected() {
FragmentActivity activity = getActivity();
if (activity != null) {
AddNewTrackFolderBottomSheet.showInstance(activity.getSupportFragmentManager(),
SaveAsNewTrackBottomSheetDialogFragment.this, usedOnMap);
}
}
};
}
@ -400,6 +411,13 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
return nightMode ? R.color.activity_background_color_dark : R.color.list_background_color_light;
}
@Override
public void onTrackFolderAdd(String folderName) {
File file = getFile(app, this.folderName, fileName);
File destFolder = new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), folderName);
this.onFileMove(file, new File(destFolder, file.getName()));
}
public interface SaveAsNewTrackFragmentListener {
void onSaveAsNewTrack(String folderName, String fileName, boolean showOnMap, boolean simplifiedTrack);

View file

@ -1,5 +1,6 @@
package net.osmand.plus.measurementtool.adapter;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.text.TextUtils;
@ -24,6 +25,8 @@ import java.util.List;
public class FolderListAdapter extends RecyclerView.Adapter<FolderListAdapter.GroupsViewHolder> {
private static final int VIEW_TYPE_FOOTER = 1;
private static final int VIEW_TYPE_CELL = 0;
List<String> items = new ArrayList<>();
String selectedItemName;
@ -59,55 +62,86 @@ public class FolderListAdapter extends RecyclerView.Adapter<FolderListAdapter.Gr
groupName.setMaxLines(1);
groupName.setEllipsize(TextUtils.TruncateAt.END);
groupName.setTextColor(ContextCompat.getColor(app, activeColorRes));
if (viewType != VIEW_TYPE_CELL) {
groupName.setText(R.string.add_new_folder);
int activeColorResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
Drawable iconAdd = app.getUIUtilities().getIcon(R.drawable.ic_action_add, activeColorResId);
ImageView groupIcon = view.findViewById(R.id.groupIcon);
groupIcon.setImageDrawable(iconAdd);
GradientDrawable rectContourDrawable = (GradientDrawable) AppCompatResources.getDrawable(app,
R.drawable.bg_select_group_button_outline);
if (rectContourDrawable != null) {
int strokeColor = ContextCompat.getColor(app, nightMode ? R.color.stroked_buttons_and_links_outline_dark
: R.color.stroked_buttons_and_links_outline_light);
rectContourDrawable.setStroke(AndroidUtils.dpToPx(app, 1), strokeColor);
((ImageView) view.findViewById(R.id.outlineRect)).setImageDrawable(rectContourDrawable);
}
((TextView) view.findViewById(R.id.groupName)).setTextColor(app.getResources().getColor(activeColorResId));
}
return new FolderListAdapter.GroupsViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull final GroupsViewHolder holder, int position) {
holder.groupButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int previousSelectedPosition = getItemPosition(selectedItemName);
selectedItemName = items.get(holder.getAdapterPosition());
notifyItemChanged(holder.getAdapterPosition());
notifyItemChanged(previousSelectedPosition);
if (listener != null) {
listener.onItemSelected(selectedItemName);
if (position == items.size()) {
holder.groupButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
listener.onAddNewItemSelected();
}
}
}
});
final String group = Algorithms.capitalizeFirstLetter(items.get(position));
holder.groupName.setText(group);
int activeColorRes = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
int strokeColor;
int strokeWidth;
if (selectedItemName != null && selectedItemName.equals(items.get(position))) {
strokeColor = activeColorRes;
strokeWidth = 2;
});
} else {
strokeColor = nightMode ? R.color.stroked_buttons_and_links_outline_dark
: R.color.stroked_buttons_and_links_outline_light;
strokeWidth = 1;
holder.groupButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int previousSelectedPosition = getItemPosition(selectedItemName);
selectedItemName = items.get(holder.getAdapterPosition());
notifyItemChanged(holder.getAdapterPosition());
notifyItemChanged(previousSelectedPosition);
if (listener != null) {
listener.onItemSelected(selectedItemName);
}
}
});
final String group = Algorithms.capitalizeFirstLetter(items.get(position));
holder.groupName.setText(group);
int activeColorRes = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
int strokeColor;
int strokeWidth;
if (selectedItemName != null && selectedItemName.equals(items.get(position))) {
strokeColor = activeColorRes;
strokeWidth = 2;
} else {
strokeColor = nightMode ? R.color.stroked_buttons_and_links_outline_dark
: R.color.stroked_buttons_and_links_outline_light;
strokeWidth = 1;
}
GradientDrawable rectContourDrawable = (GradientDrawable) AppCompatResources.getDrawable(app,
R.drawable.bg_select_group_button_outline);
if (rectContourDrawable != null) {
rectContourDrawable.setStroke(AndroidUtils.dpToPx(app, strokeWidth), ContextCompat.getColor(app, strokeColor));
holder.groupButton.setImageDrawable(rectContourDrawable);
}
int iconID;
iconID = R.drawable.ic_action_folder;
holder.groupIcon.setImageDrawable(app.getUIUtilities().getIcon(iconID, activeColorRes));
}
GradientDrawable rectContourDrawable = (GradientDrawable) AppCompatResources.getDrawable(app,
R.drawable.bg_select_group_button_outline);
if (rectContourDrawable != null) {
rectContourDrawable.setStroke(AndroidUtils.dpToPx(app, strokeWidth), ContextCompat.getColor(app, strokeColor));
holder.groupButton.setImageDrawable(rectContourDrawable);
}
int iconID;
iconID = R.drawable.ic_action_folder;
holder.groupIcon.setImageDrawable(app.getUIUtilities().getIcon(iconID, activeColorRes));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
AndroidUtils.setBackground(app, holder.groupButton, nightMode, R.drawable.ripple_solid_light_6dp,
R.drawable.ripple_solid_dark_6dp);
}
}
@Override
public int getItemViewType(int position) {
return (position == items.size()) ? VIEW_TYPE_FOOTER : VIEW_TYPE_CELL;
}
@Override
public int getItemCount() {
return items == null ? 0 : items.size();
return items == null ? 0 : items.size() + 1;
}
int getItemPosition(String name) {
@ -135,5 +169,7 @@ public class FolderListAdapter extends RecyclerView.Adapter<FolderListAdapter.Gr
public interface FolderListAdapterListener {
void onItemSelected(String item);
void onAddNewItemSelected();
}
}

View file

@ -51,8 +51,6 @@ public class AddNewTrackFolderBottomSheet extends MenuBottomSheetDialogFragment
app = requiredMyApplication();
if (savedInstanceState != null) {
folderName = savedInstanceState.getString(FOLDER_NAME_KEY);
} else if (Algorithms.isEmpty(folderName)) {
folderName = app.getAppPath(IndexConstants.GPX_INDEX_DIR).getName();
}
items.add(new TitleItem(getString(R.string.add_new_folder)));
@ -141,12 +139,10 @@ public class AddNewTrackFolderBottomSheet extends MenuBottomSheetDialogFragment
void onTrackFolderAdd(String folderName);
}
public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment target,
@NonNull String folderName, boolean usedOnMap) {
public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment target, boolean usedOnMap) {
try {
if (!fragmentManager.isStateSaved() && fragmentManager.findFragmentByTag(AddNewTrackFolderBottomSheet.TAG) == null) {
AddNewTrackFolderBottomSheet fragment = new AddNewTrackFolderBottomSheet();
fragment.folderName = folderName;
fragment.setUsedOnMap(usedOnMap);
fragment.setTargetFragment(target, 0);
fragment.show(fragmentManager, AddNewTrackFolderBottomSheet.TAG);

View file

@ -74,7 +74,7 @@ public class MoveGpxFileBottomSheet extends MenuBottomSheetDialogFragment implem
FragmentActivity activity = getActivity();
if (activity != null) {
AddNewTrackFolderBottomSheet.showInstance(activity.getSupportFragmentManager(),
MoveGpxFileBottomSheet.this, fileDir.getName(), usedOnMap);
MoveGpxFileBottomSheet.this, usedOnMap);
}
}
})