Quick Action redesign p.3 replace "Add action" AlertDialog with BottomSheet
This commit is contained in:
parent
f8e4bc8607
commit
00cebdba08
6 changed files with 78 additions and 228 deletions
|
@ -1,45 +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:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:background="?attr/bg_color"
|
|
||||||
android:paddingTop="24dp">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvTitle"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/dialog_add_action_title"
|
|
||||||
android:layout_marginLeft="24dp"
|
|
||||||
android:layout_marginRight="24dp"
|
|
||||||
android:textSize="@dimen/dialog_header_text_size"
|
|
||||||
android:textColor="?android:textColorPrimary"
|
|
||||||
android:layout_marginBottom="8dp"
|
|
||||||
android:layout_marginEnd="24dp"
|
|
||||||
android:layout_marginStart="24dp" />
|
|
||||||
|
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
|
||||||
android:id="@+id/recycler_view"
|
|
||||||
android:layout_weight="1"
|
|
||||||
app:layoutManager="LinearLayoutManager"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:scrollbars="vertical"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/btnDismiss"
|
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginRight="8dp"
|
|
||||||
android:layout_marginBottom="8dp"
|
|
||||||
android:text="@string/shared_string_dismiss"
|
|
||||||
android:layout_gravity="end"
|
|
||||||
android:background="?attr/selectableItemBackground"
|
|
||||||
android:textColor="?attr/color_dialog_buttons"
|
|
||||||
android:textAllCaps="true"
|
|
||||||
android:layout_marginEnd="8dp" />
|
|
||||||
</LinearLayout>
|
|
|
@ -3,25 +3,26 @@
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="40dp"
|
android:layout_height="wrap_content"
|
||||||
|
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||||
android:background="?attr/bg_color">
|
android:background="?attr/bg_color">
|
||||||
|
|
||||||
<TextView
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
android:id="@+id/header"
|
android:id="@+id/header"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="@dimen/list_header_height"
|
||||||
android:layout_gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:textColor="?android:textColorSecondary"
|
android:textColor="@color/preference_category_title"
|
||||||
android:textSize="@dimen/default_sub_text_size"
|
android:textSize="@dimen/default_desc_text_size"
|
||||||
android:layout_marginLeft="24dp"
|
android:layout_marginLeft="@dimen/content_padding"
|
||||||
android:layout_marginRight="24dp"
|
android:layout_marginRight="@dimen/content_padding"
|
||||||
tools:text="Screen 1"
|
tools:text="Screen 1"
|
||||||
android:layout_marginStart="24dp"
|
osmand:typeface="@string/font_roboto_medium" />
|
||||||
android:layout_marginEnd="24dp" />
|
|
||||||
|
|
||||||
<View android:id="@+id/divider"
|
<View android:id="@+id/divider"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="1dp"
|
android:layout_height="1dp"
|
||||||
|
android:layout_gravity="top"
|
||||||
android:background="?attr/dashboard_divider"/>
|
android:background="?attr/dashboard_divider"/>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
|
@ -6,33 +6,32 @@
|
||||||
android:id="@+id/searchListItemLayout"
|
android:id="@+id/searchListItemLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:minHeight="48dp"
|
android:minHeight="@dimen/bottom_sheet_list_item_height"
|
||||||
android:paddingRight="24dp"
|
android:paddingLeft="@dimen/content_padding"
|
||||||
android:paddingLeft="24dp"
|
android:paddingRight="@dimen/content_padding"
|
||||||
android:paddingStart="24dp"
|
|
||||||
android:paddingEnd="24dp"
|
|
||||||
android:background="?attr/selectableItemBackground"
|
android:background="?attr/selectableItemBackground"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatImageView
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
android:id="@+id/image"
|
android:id="@+id/image"
|
||||||
android:layout_width="24dp"
|
android:layout_width="@dimen/standard_icon_size"
|
||||||
android:layout_height="24dp"
|
android:layout_height="@dimen/standard_icon_size"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:layout_marginRight="16dp"
|
android:layout_marginRight="@dimen/content_padding"
|
||||||
android:scaleType="centerInside"
|
android:scaleType="centerInside"
|
||||||
android:tint="?attr/default_icon_color"
|
android:tint="?attr/default_icon_color"
|
||||||
osmand:srcCompat="@drawable/ic_action_flag"
|
osmand:srcCompat="@drawable/ic_action_flag"
|
||||||
android:layout_marginEnd="16dp" />
|
android:layout_marginEnd="@dimen/content_padding" />
|
||||||
|
|
||||||
<TextView
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
android:id="@+id/title"
|
android:id="@+id/title"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:textColor="?android:textColorPrimary"
|
android:textColor="?android:textColorPrimary"
|
||||||
android:textSize="@dimen/default_list_text_size"
|
android:textSize="@dimen/default_list_text_size"
|
||||||
|
osmand:typeface="@string/font_roboto_regular"
|
||||||
tools:text="Add marker" />
|
tools:text="Add marker" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
|
@ -1,25 +1,20 @@
|
||||||
package net.osmand.plus.quickaction;
|
package net.osmand.plus.quickaction;
|
||||||
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.view.Window;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
import androidx.fragment.app.DialogFragment;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
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.base.MenuBottomSheetDialogFragment;
|
||||||
|
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||||
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -27,160 +22,59 @@ import java.util.List;
|
||||||
* Created by rosty on 12/22/16.
|
* Created by rosty on 12/22/16.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class AddQuickActionDialog extends DialogFragment {
|
public class AddQuickActionDialog extends MenuBottomSheetDialogFragment {
|
||||||
|
|
||||||
public static final String TAG = AddQuickActionDialog.class.getSimpleName();
|
public static final String TAG = AddQuickActionDialog.class.getSimpleName();
|
||||||
|
|
||||||
private boolean isLightContent;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
|
||||||
|
|
||||||
OsmandApplication application = (OsmandApplication) getActivity().getApplication();
|
|
||||||
isLightContent = application.getSettings().isLightContent() && !application.getDaynightHelper().isNightMode();
|
|
||||||
|
|
||||||
return new Dialog(UiUtilities.getThemedContext(getActivity(), !isLightContent, R.style.Dialog90Light, R.style.Dialog90Dark), getTheme());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
||||||
|
|
||||||
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
|
|
||||||
QuickActionRegistry quickActionRegistry = ((MapActivity) getActivity())
|
|
||||||
.getMyApplication()
|
|
||||||
.getQuickActionRegistry();
|
|
||||||
|
|
||||||
View root = UiUtilities.getInflater(getActivity(), !isLightContent).inflate(R.layout.quick_action_add_dialog, container, false);
|
|
||||||
Adapter adapter = new Adapter(quickActionRegistry.produceTypeActionsListWithHeaders());
|
|
||||||
|
|
||||||
TextView tvTitle = root.findViewById(R.id.tvTitle);
|
|
||||||
RecyclerView recyclerView = (RecyclerView) root.findViewById(R.id.recycler_view);
|
|
||||||
Button btnDismiss = (Button) root.findViewById(R.id.btnDismiss);
|
|
||||||
|
|
||||||
tvTitle.setTextColor(ContextCompat.getColor(getContext(),
|
|
||||||
isLightContent ? R.color.text_color_primary_light : R.color.text_color_primary_dark));
|
|
||||||
|
|
||||||
btnDismiss.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
dismiss();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
recyclerView.setAdapter(adapter);
|
|
||||||
|
|
||||||
return root;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
OsmandApplication app = requiredMyApplication();
|
||||||
}
|
final FragmentActivity activity = getActivity();
|
||||||
|
LayoutInflater inflater = UiUtilities.getInflater(app, nightMode);
|
||||||
public class Adapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
QuickActionRegistry quickActionRegistry = app.getQuickActionRegistry();
|
||||||
|
|
||||||
private static final int HEADER = 1;
|
|
||||||
private static final int ITEM = 2;
|
|
||||||
|
|
||||||
private List<QuickActionType> data;
|
|
||||||
|
|
||||||
public class ItemViewHolder extends RecyclerView.ViewHolder {
|
|
||||||
|
|
||||||
private TextView title;
|
|
||||||
private ImageView icon;
|
|
||||||
|
|
||||||
public ItemViewHolder(View v) {
|
|
||||||
super(v);
|
|
||||||
|
|
||||||
title = (TextView) v.findViewById(R.id.title);
|
|
||||||
icon = (ImageView) v.findViewById(R.id.image);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class HeaderViewHolder extends RecyclerView.ViewHolder {
|
|
||||||
|
|
||||||
private TextView header;
|
|
||||||
private View divider;
|
|
||||||
|
|
||||||
public HeaderViewHolder(View v) {
|
|
||||||
super(v);
|
|
||||||
|
|
||||||
header = (TextView) v.findViewById(R.id.header);
|
|
||||||
divider = v.findViewById(R.id.divider);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Adapter(List<QuickActionType> data) {
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
||||||
|
|
||||||
if (viewType == HEADER) {
|
|
||||||
|
|
||||||
return new HeaderViewHolder(LayoutInflater.from(parent.getContext())
|
|
||||||
.inflate(R.layout.quick_action_add_dialog_header, parent, false));
|
|
||||||
|
|
||||||
|
items.add(new TitleItem(getString(R.string.dialog_add_action_title)));
|
||||||
|
List<QuickActionType> actions = quickActionRegistry.produceTypeActionsListWithHeaders();
|
||||||
|
boolean firstHeader = true;
|
||||||
|
for (final QuickActionType action : actions) {
|
||||||
|
if (action.getId() == 0) {
|
||||||
|
View itemView = inflater.inflate(R.layout.quick_action_add_dialog_header,
|
||||||
|
null, false);
|
||||||
|
TextView title = itemView.findViewById(R.id.header);
|
||||||
|
View divider = itemView.findViewById(R.id.divider);
|
||||||
|
title.setText(action.getNameRes());
|
||||||
|
divider.setVisibility(firstHeader ? View.GONE : View.VISIBLE);
|
||||||
|
items.add(new BaseBottomSheetItem.Builder()
|
||||||
|
.setCustomView(itemView)
|
||||||
|
.create());
|
||||||
|
firstHeader = false;
|
||||||
} else {
|
} else {
|
||||||
|
View itemView = inflater.inflate(R.layout.quick_action_add_dialog_item,
|
||||||
return new ItemViewHolder(LayoutInflater.from(parent.getContext())
|
null, false);
|
||||||
.inflate(R.layout.quick_action_add_dialog_item, parent, false));
|
TextView title = itemView.findViewById(R.id.title);
|
||||||
|
ImageView icon = itemView.findViewById(R.id.image);
|
||||||
|
title.setText(action.getNameRes());
|
||||||
|
icon.setImageResource(action.getIconRes());
|
||||||
|
items.add(new BaseBottomSheetItem.Builder()
|
||||||
|
.setCustomView(itemView)
|
||||||
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
CreateEditActionDialog dialog =
|
||||||
|
CreateEditActionDialog.newInstance(action.getId());
|
||||||
|
dialog.show(activity.getSupportFragmentManager(),
|
||||||
|
CreateEditActionDialog.TAG);
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.create());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showInstance(FragmentManager fm, boolean usedOnMap) {
|
||||||
@Override
|
AddQuickActionDialog fragment = new AddQuickActionDialog();
|
||||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
fragment.setUsedOnMap(usedOnMap);
|
||||||
|
fragment.show(fm, AddQuickActionDialog.TAG);
|
||||||
final QuickActionType action = data.get(position);
|
|
||||||
|
|
||||||
if (getItemViewType(position) == HEADER) {
|
|
||||||
|
|
||||||
HeaderViewHolder headerHolder = (HeaderViewHolder) holder;
|
|
||||||
|
|
||||||
headerHolder.header.setText(action.getNameRes());
|
|
||||||
if (position == 0) headerHolder.divider.setVisibility(View.GONE);
|
|
||||||
else headerHolder.divider.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
ItemViewHolder itemHolder = (ItemViewHolder) holder;
|
|
||||||
|
|
||||||
itemHolder.title.setText(action.getNameRes());
|
|
||||||
itemHolder.title.setTextColor(ContextCompat.getColor(getContext(),
|
|
||||||
isLightContent ? R.color.text_color_primary_light : R.color.text_color_primary_dark));
|
|
||||||
itemHolder.icon.setImageResource(action.getIconRes());
|
|
||||||
|
|
||||||
itemHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
|
|
||||||
CreateEditActionDialog dialog = CreateEditActionDialog.newInstance(action.getId());
|
|
||||||
dialog.show(getFragmentManager(), CreateEditActionDialog.TAG);
|
|
||||||
|
|
||||||
dismiss();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemCount() {
|
|
||||||
return data.size();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemViewType(int position) {
|
|
||||||
|
|
||||||
if (data.get(position).getId() == 0)
|
|
||||||
return HEADER;
|
|
||||||
|
|
||||||
return ITEM;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -534,8 +534,12 @@ public class QuickActionListFragment extends BaseOsmAndFragment
|
||||||
h.itemContainer.setOnClickListener(new View.OnClickListener() {
|
h.itemContainer.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
CreateEditActionDialog dialog = CreateEditActionDialog.newInstance(action.id);
|
CreateEditActionDialog dialog =
|
||||||
dialog.show(getFragmentManager(), AddQuickActionDialog.TAG);
|
CreateEditActionDialog.newInstance(action.id);
|
||||||
|
FragmentManager fm = getFragmentManager();
|
||||||
|
if (fm != null && !dialog.isStateSaved()) {
|
||||||
|
dialog.show(fm, CreateEditActionDialog.TAG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -871,8 +875,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment
|
||||||
private void showAddQuickActionDialog() {
|
private void showAddQuickActionDialog() {
|
||||||
FragmentManager fm = getFragmentManager();
|
FragmentManager fm = getFragmentManager();
|
||||||
if (fm != null) {
|
if (fm != null) {
|
||||||
AddQuickActionDialog dialog = new AddQuickActionDialog();
|
AddQuickActionDialog.showInstance(fm, false);
|
||||||
dialog.show(fm, AddQuickActionDialog.TAG);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,7 @@ public class NewAction extends QuickAction {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(MapActivity activity) {
|
public void execute(MapActivity activity) {
|
||||||
|
AddQuickActionDialog.showInstance(activity.getSupportFragmentManager(), true);
|
||||||
AddQuickActionDialog dialog = new AddQuickActionDialog();
|
|
||||||
dialog.show(activity.getSupportFragmentManager(), AddQuickActionDialog.TAG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue