Reorder screen ui polishing first part

This commit is contained in:
Chumva 2019-12-12 19:10:11 +02:00
parent 521a691144
commit 8e173260e1
7 changed files with 147 additions and 52 deletions

View file

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/list_background_color"
android:gravity="center_vertical">
<LinearLayout
android:id="@+id/selectable_list_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:background="?android:attr/selectableItemBackground">
<ImageButton
android:id="@+id/action_icon"
style="@style/Widget.AppCompat.ActionButton"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginTop="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/content_padding"
android:layout_marginBottom="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_remove"
tools:tint="@color/icon_color_default_light" />
<ImageView
android:id="@+id/icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginTop="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/content_padding"
android:layout_marginBottom="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_car_dark"
tools:tint="@color/profile_icon_color_blue_light_default" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular"
tools:text="@string/app_mode_car" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:letterSpacing="@dimen/description_letter_spacing"
android:maxLines="4"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular"
tools:text="@string/base_profile_descr_car" />
</LinearLayout>
<ImageView
android:id="@+id/move_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="@dimen/content_padding"
android:paddingTop="@dimen/bottom_sheet_icon_margin"
android:paddingRight="@dimen/content_padding"
android:paddingBottom="@dimen/bottom_sheet_icon_margin"
android:src="@drawable/ic_action_item_move"
android:tint="?attr/secondary_icon_color" />
</LinearLayout>
</LinearLayout>

View file

@ -12,6 +12,7 @@
--> -->
<string name="shared_string_downloading_formatted">Downloading %s</string> <string name="shared_string_downloading_formatted">Downloading %s</string>
<string name="edit_profiles_descr">You cant delete default OsmAnd profiles, but you can disable them in previous screen, or move them to the bottom.</string>
<string name="edit_profiles">Edit profiles</string> <string name="edit_profiles">Edit profiles</string>
<string name="select_nav_profile_dialog_message">Navigation type affects the rules for route calculations.</string> <string name="select_nav_profile_dialog_message">Navigation type affects the rules for route calculations.</string>
<string name="distance_and_address">%1$s • %2$s</string> <string name="distance_and_address">%1$s • %2$s</string>

View file

@ -58,7 +58,7 @@
android:layout="@layout/preference_button" android:layout="@layout/preference_button"
android:persistent="false" android:persistent="false"
android:title="@string/reorder_profiles" android:title="@string/reorder_profiles"
app:fragment="net.osmand.plus.settings.EditProfilesFragment" app:fragment="net.osmand.plus.profiles.EditProfilesFragment"
tools:icon="@drawable/ic_action_edit_dark" /> tools:icon="@drawable/ic_action_edit_dark" />
<Preference <Preference

View file

@ -1,4 +1,4 @@
package net.osmand.plus.settings; package net.osmand.plus.profiles;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
@ -19,8 +19,6 @@ import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.profiles.ProfilesAdapter;
import net.osmand.plus.profiles.ReorderItemTouchHelperCallback;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -62,11 +60,6 @@ public class EditProfilesFragment extends BaseOsmAndFragment {
private int fromPosition; private int fromPosition;
private int toPosition; private int toPosition;
@Override
public void onItemClick(View view) {
}
@Override @Override
public void onDragStarted(RecyclerView.ViewHolder holder) { public void onDragStarted(RecyclerView.ViewHolder holder) {
fromPosition = holder.getAdapterPosition(); fromPosition = holder.getAdapterPosition();

View file

@ -1,13 +1,18 @@
package net.osmand.plus.profiles; package net.osmand.plus.profiles;
import android.annotation.SuppressLint;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.view.MotionEventCompat; import android.support.v4.view.MotionEventCompat;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
@ -20,19 +25,21 @@ import net.osmand.plus.settings.BaseSettingsFragment;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
public class ProfilesAdapter extends AbstractProfileMenuAdapter<ProfilesAdapter.SelectProfileViewHolder> public class ProfilesAdapter extends RecyclerView.Adapter<ProfilesAdapter.ProfileViewHolder>
implements ReorderItemTouchHelperCallback.OnItemMoveCallback { implements ReorderItemTouchHelperCallback.OnItemMoveCallback {
private OsmandApplication app; private OsmandApplication app;
private UiUtilities uiUtilities;
private List<ApplicationMode> applicationModes; private List<ApplicationMode> applicationModes;
private ProfilesAdapterListener listener; private ProfilesAdapterListener listener;
private boolean nightMode; private boolean nightMode;
public ProfilesAdapter(MapActivity mapActivity, List<ApplicationMode> applicationModes) { public ProfilesAdapter(MapActivity mapActivity, List<ApplicationMode> appModes) {
setHasStableIds(true); setHasStableIds(true);
app = mapActivity.getMyApplication(); app = mapActivity.getMyApplication();
this.applicationModes = applicationModes; uiUtilities = app.getUIUtilities();
applicationModes = appModes;
nightMode = !mapActivity.getMyApplication().getSettings().isLightContent(); nightMode = !mapActivity.getMyApplication().getSettings().isLightContent();
} }
@ -42,39 +49,23 @@ public class ProfilesAdapter extends AbstractProfileMenuAdapter<ProfilesAdapter.
@NonNull @NonNull
@Override @Override
public SelectProfileViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { public ProfileViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View itemView = UiUtilities.getInflater(viewGroup.getContext(), nightMode).inflate(R.layout.profile_list_item, null); LayoutInflater themedInflater = UiUtilities.getInflater(viewGroup.getContext(), nightMode);
itemView.setOnClickListener(new View.OnClickListener() { View itemView = themedInflater.inflate(R.layout.profile_edit_list_item, viewGroup, false);
@Override return new ProfileViewHolder(itemView);
public void onClick(View view) {
listener.onItemClick(view);
}
});
return new SelectProfileViewHolder(itemView);
} }
@SuppressLint("ClickableViewAccessibility")
@Override @Override
public void onBindViewHolder(final SelectProfileViewHolder holder, final int pos) { public void onBindViewHolder(final ProfileViewHolder holder, final int pos) {
ApplicationMode mode = applicationModes.get(pos); ApplicationMode mode = applicationModes.get(pos);
holder.icon.setVisibility(View.VISIBLE);
holder.descr.setVisibility(View.VISIBLE);
holder.switcher.setVisibility(View.GONE);
holder.menuIcon.setVisibility(View.VISIBLE);
holder.title.setText(mode.toHumanString(app)); holder.title.setText(mode.toHumanString(app));
holder.descr.setText(BaseSettingsFragment.getAppModeDescription(app, mode)); holder.description.setText(BaseSettingsFragment.getAppModeDescription(app, mode));
//set up cell color
int profileColorResId = mode.getIconColorInfo().getColor(nightMode);
int colorNoAlpha = ContextCompat.getColor(app, profileColorResId);
Drawable drawable = UiUtilities.getColoredSelectableDrawable(app, colorNoAlpha, 0.3f);
AndroidUtils.setBackground(holder.profileOptions, drawable);
updateViewHolder(holder, mode); updateViewHolder(holder, mode);
holder.menuIcon.setOnTouchListener(new View.OnTouchListener() { holder.moveIcon.setOnTouchListener(new View.OnTouchListener() {
@Override @Override
public boolean onTouch(View view, MotionEvent event) { public boolean onTouch(View view, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) { if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
@ -107,31 +98,51 @@ public class ProfilesAdapter extends AbstractProfileMenuAdapter<ProfilesAdapter.
listener.onDragOrSwipeEnded(holder); listener.onDragOrSwipeEnded(holder);
} }
private void updateViewHolder(SelectProfileViewHolder holder, ApplicationMode mode) { private void updateViewHolder(ProfileViewHolder holder, ApplicationMode mode) {
int iconRes = mode.getIconRes(); int iconRes = mode.getIconRes();
if (iconRes == 0 || iconRes == -1) { if (iconRes == 0 || iconRes == -1) {
iconRes = R.drawable.ic_action_world_globe; iconRes = R.drawable.ic_action_world_globe;
} }
int selectedIconColorRes = mode.getIconColorInfo().getColor(nightMode); int profileColorResId = mode.getIconColorInfo().getColor(nightMode);
holder.icon.setImageDrawable(app.getUIUtilities().getIcon(iconRes, selectedIconColorRes)); int colorNoAlpha = ContextCompat.getColor(app, profileColorResId);
int removeIconColor = mode.isCustomProfile() ? R.color.color_osm_edit_delete : R.color.icon_color_default_light;
holder.icon.setImageDrawable(uiUtilities.getIcon(iconRes, profileColorResId));
holder.actionIcon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_remove, removeIconColor));
//set up cell color
Drawable drawable = UiUtilities.getColoredSelectableDrawable(app, colorNoAlpha, 0.3f);
AndroidUtils.setBackground(holder.itemsContainer, drawable);
} }
public ApplicationMode getItem(int position) { public ApplicationMode getItem(int position) {
return applicationModes.get(position); return applicationModes.get(position);
} }
class SelectProfileViewHolder extends ProfileAbstractViewHolder {
SelectProfileViewHolder(View itemView) {
super(itemView);
}
}
public interface ProfilesAdapterListener { public interface ProfilesAdapterListener {
void onItemClick(View view);
void onDragStarted(RecyclerView.ViewHolder holder); void onDragStarted(RecyclerView.ViewHolder holder);
void onDragOrSwipeEnded(RecyclerView.ViewHolder holder); void onDragOrSwipeEnded(RecyclerView.ViewHolder holder);
} }
class ProfileViewHolder extends RecyclerView.ViewHolder {
TextView title;
TextView description;
ImageView icon;
ImageView moveIcon;
ImageButton actionIcon;
View itemsContainer;
public ProfileViewHolder(View itemView) {
super(itemView);
title = itemView.findViewById(R.id.title);
description = itemView.findViewById(R.id.description);
actionIcon = itemView.findViewById(R.id.action_icon);
icon = itemView.findViewById(R.id.icon);
moveIcon = itemView.findViewById(R.id.move_icon);
itemsContainer = itemView.findViewById(R.id.selectable_list_item);
}
}
} }

View file

@ -30,8 +30,8 @@ public class ReorderItemTouchHelperCallback extends ItemTouchHelper.Callback {
} }
@Override @Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder source, RecyclerView.ViewHolder target) {
int from = viewHolder.getAdapterPosition(); int from = source.getAdapterPosition();
int to = target.getAdapterPosition(); int to = target.getAdapterPosition();
if (from == RecyclerView.NO_POSITION || to == RecyclerView.NO_POSITION) { if (from == RecyclerView.NO_POSITION || to == RecyclerView.NO_POSITION) {
return false; return false;

View file

@ -20,11 +20,11 @@ public class QuickActionItemTouchHelperCallback extends ReorderItemTouchHelperCa
} }
@Override @Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder source, RecyclerView.ViewHolder target) {
if (isaHeaderType(viewHolder) || isaHeaderType(target)) { if (isaHeaderType(source) || isaHeaderType(target)) {
return false; return false;
} }
return super.onMove(recyclerView, viewHolder, target); return super.onMove(recyclerView, source, target);
} }
private boolean isaHeaderType(RecyclerView.ViewHolder viewHolder) { private boolean isaHeaderType(RecyclerView.ViewHolder viewHolder) {