saving quick actions
This commit is contained in:
parent
c4ebbb4436
commit
891ca8f71c
4 changed files with 281 additions and 19 deletions
229
OsmAnd/res/layout/quick_action_favorite.xml
Normal file
229
OsmAnd/res/layout/quick_action_favorite.xml
Normal file
|
@ -0,0 +1,229 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/editor_scroll_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fillViewport="true">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingLeft="24dp"
|
||||
android:paddingRight="16dp">
|
||||
|
||||
<android.support.v7.widget.AppCompatTextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"
|
||||
tools:text="Some title text"/>
|
||||
|
||||
<android.support.v7.widget.SwitchCompat
|
||||
android:id="@+id/toggle_item"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:focusable="false"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/main_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/title_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/bg_color"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:baselineAligned="false"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="42dp"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/name_image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="12dp"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="2dp"
|
||||
android:scaleType="centerInside"
|
||||
android:src="@drawable/ic_action_building_number"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/name_caption"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="12dp"
|
||||
android:layout_marginRight="12dp"
|
||||
android:text="@string/favourites_edit_dialog_name"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textSize="@dimen/default_list_text_size"/>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/name_edit"
|
||||
tools:text="Name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:imeOptions="actionDone"
|
||||
android:inputType="text"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textColorHint="?android:textColorSecondary"/>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:baselineAligned="false"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="42dp"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/category_image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="12dp"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="2dp"
|
||||
android:scaleType="centerInside"
|
||||
android:src="@drawable/ic_action_building_number"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/category_caption"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="12dp"
|
||||
android:layout_marginRight="12dp"
|
||||
android:text="@string/favourites_edit_dialog_name"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textSize="@dimen/default_list_text_size"/>
|
||||
|
||||
<net.osmand.plus.widgets.AutoCompleteTextViewEx
|
||||
android:id="@+id/category_edit"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:drawableRight="@drawable/ic_action_arrow_drop_down"
|
||||
android:editable="false"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="48dp"
|
||||
android:foreground="@drawable/bg_contextmenu_shadow"
|
||||
android:foregroundGravity="top|fill_horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/description_info_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:baselineAligned="false"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="42dp"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/description_image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="12dp"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/ic_action_note_dark"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/description_edit"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:inputType="textMultiLine"
|
||||
android:maxLines="8"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textColorHint="?android:textColorSecondary"/>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
|
@ -25,7 +25,7 @@ public class QuickActionFactory {
|
|||
Type type = new TypeToken<List<QuickAction>>(){}.getType();
|
||||
ArrayList<QuickAction> quickActions = new Gson().fromJson(json, type);
|
||||
|
||||
return quickActions;
|
||||
return quickActions != null ? quickActions : new ArrayList<QuickAction>();
|
||||
}
|
||||
|
||||
public static List<QuickAction> produceTypeActionsList() {
|
||||
|
|
|
@ -33,6 +33,12 @@ public class QuickActionItemTouchHelperCallback extends ItemTouchHelper.Callback
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
|
||||
super.clearView(recyclerView, viewHolder);
|
||||
itemMoveCallback.onViewDropped(recyclerView, viewHolder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
|
||||
return itemMoveCallback.onMove(recyclerView, viewHolder, target);
|
||||
|
@ -49,5 +55,6 @@ public class QuickActionItemTouchHelperCallback extends ItemTouchHelper.Callback
|
|||
|
||||
interface OnItemMoveCallback {
|
||||
boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target);
|
||||
void onViewDropped(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,8 +43,8 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements AddQu
|
|||
FloatingActionButton fab;
|
||||
|
||||
QuickActionFactory quickActionFactory = new QuickActionFactory();
|
||||
QuickActionAdapter adapter;
|
||||
ItemTouchHelper touchHelper;
|
||||
QuickActionAdapter adapter;
|
||||
ItemTouchHelper touchHelper;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
|
@ -59,7 +59,6 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements AddQu
|
|||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// adapter.addItem(new QuickActionItem(R.string.map_marker, R.drawable.ic_action_flag_dark));
|
||||
|
||||
AddQuickActionDialog dialog = new AddQuickActionDialog();
|
||||
dialog.show(getFragmentManager(), AddQuickActionDialog.TAG);
|
||||
|
@ -90,7 +89,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements AddQu
|
|||
ItemTouchHelper.Callback touchHelperCallback = new QuickActionItemTouchHelperCallback(adapter);
|
||||
touchHelper = new ItemTouchHelper(touchHelperCallback);
|
||||
touchHelper.attachToRecyclerView(quickActionRV);
|
||||
adapter.addItems(createMockDada());
|
||||
adapter.addItems(getSavedActions());
|
||||
|
||||
quickActionRV.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
|
@ -130,24 +129,31 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements AddQu
|
|||
getMapActivity().enableDrawer();
|
||||
}
|
||||
|
||||
private List<QuickAction> createMockDada() {
|
||||
List<QuickAction> result = new ArrayList<>();
|
||||
for (int i = 0; i < 4; i++) {
|
||||
result.addAll(quickActionFactory.produceTypeActionsList());
|
||||
}
|
||||
private List<QuickAction> getSavedActions() {
|
||||
String actionsJson = getMyApplication().getSettings().QUICK_ACTION_LIST.get();
|
||||
|
||||
return result;
|
||||
return quickActionFactory.parseActiveActionsList(actionsJson);
|
||||
// List<QuickAction> result = new ArrayList<>();
|
||||
// for (int i = 0; i < 4; i++) {
|
||||
// result.addAll(quickActionFactory.produceTypeActionsList());
|
||||
// }
|
||||
//
|
||||
// return result;
|
||||
}
|
||||
|
||||
private MapActivity getMapActivity() {
|
||||
return (MapActivity) getActivity();
|
||||
}
|
||||
|
||||
private void saveQuickActions(){
|
||||
String json = quickActionFactory.quickActionListToString((ArrayList<QuickAction>) adapter.getQuickActions());
|
||||
getMyApplication().getSettings().QUICK_ACTION_LIST.set(json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionSelected(QuickAction action) {
|
||||
adapter.addItem(action);
|
||||
|
||||
//TODO save
|
||||
saveQuickActions();
|
||||
}
|
||||
|
||||
public class QuickActionAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements QuickActionItemTouchHelperCallback.OnItemMoveCallback {
|
||||
|
@ -174,7 +180,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements AddQu
|
|||
|
||||
@Override
|
||||
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
|
||||
int viewType = getItemViewType(position);
|
||||
int viewType = getItemViewType(position);
|
||||
QuickAction item = itemsList.get(position);
|
||||
|
||||
if (viewType == SCREEN_ITEM_TYPE) {
|
||||
|
@ -202,7 +208,8 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements AddQu
|
|||
});
|
||||
|
||||
// LinearLayout.LayoutParams dividerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
LinearLayout.LayoutParams dividerParams = (LinearLayout.LayoutParams) itemVH.divider.getLayoutParams();
|
||||
LinearLayout.LayoutParams dividerParams = (LinearLayout.LayoutParams) itemVH.divider.getLayoutParams();
|
||||
//noinspection ResourceType
|
||||
dividerParams.setMargins(!isLongDivider(position) ? dpToPx(56f) : 0, 0, 0, 0);
|
||||
itemVH.divider.setLayoutParams(dividerParams);
|
||||
} else {
|
||||
|
@ -228,6 +235,12 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements AddQu
|
|||
itemsList.remove(position);
|
||||
notifyItemRemoved(position);
|
||||
|
||||
moveHeaders(position);
|
||||
showFABIfNotScrollable();
|
||||
saveQuickActions();
|
||||
}
|
||||
|
||||
private void moveHeaders(int position) {
|
||||
for (int i = position; i < itemsList.size(); i++) {
|
||||
if (getItemViewType(i) == SCREEN_HEADER_TYPE) {
|
||||
if (i != itemsList.size() - 2) {
|
||||
|
@ -241,8 +254,6 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements AddQu
|
|||
}
|
||||
}
|
||||
notifyItemRangeChanged(position, itemsList.size() - position);
|
||||
|
||||
showFABIfNotScrollable();
|
||||
}
|
||||
|
||||
private void showFABIfNotScrollable() {
|
||||
|
@ -255,11 +266,21 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements AddQu
|
|||
fab.show();
|
||||
}
|
||||
|
||||
public List<QuickAction> getQuickActions() {
|
||||
List<QuickAction> result = new ArrayList<>();
|
||||
for (int i = 0; i < itemsList.size(); i++) {
|
||||
if (getItemViewType(i) == SCREEN_ITEM_TYPE)
|
||||
result.add(itemsList.get(i));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void addItems(List<QuickAction> data) {
|
||||
List<QuickAction> resultList = new ArrayList<>();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
if (i % ITEMS_IN_GROUP == 0)
|
||||
resultList.add(createHeader()); //creates header item
|
||||
resultList.add(createHeader());
|
||||
|
||||
resultList.add(data.get(i));
|
||||
}
|
||||
|
@ -285,7 +306,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements AddQu
|
|||
}
|
||||
|
||||
private boolean isLongDivider(int globalPosition) {
|
||||
return getActionPosition(globalPosition) == ITEMS_IN_GROUP || globalPosition == getItemCount() - 1;
|
||||
return getActionPosition(globalPosition) == ITEMS_IN_GROUP || globalPosition == getItemCount() - 1;
|
||||
}
|
||||
|
||||
public boolean isRecyclerScrollable(RecyclerView recyclerView) {
|
||||
|
@ -325,6 +346,11 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements AddQu
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewDropped(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
|
||||
saveQuickActions();
|
||||
}
|
||||
|
||||
public class QuickActionItemVH extends RecyclerView.ViewHolder {
|
||||
public TextView title;
|
||||
public TextView subTitle;
|
||||
|
|
Loading…
Reference in a new issue