Merge remote-tracking branch 'origin/master'

This commit is contained in:
Rosty 2016-12-22 16:05:20 +02:00
commit 0bfdb32825
2 changed files with 68 additions and 35 deletions

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" 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_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
@ -14,8 +15,8 @@
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view" android:id="@+id/recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_below="@id/custom_toolbar"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_below="@id/custom_toolbar"
android:background="?attr/ctx_menu_info_view_bg" android:background="?attr/ctx_menu_info_view_bg"
android:clipToPadding="false" android:clipToPadding="false"
android:paddingTop="16dp"/> android:paddingTop="16dp"/>
@ -27,6 +28,7 @@
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_alignParentRight="true" android:layout_alignParentRight="true"
android:layout_margin="16dp" android:layout_margin="16dp"
android:src="@drawable/map_quick_action"/> android:src="@drawable/map_quick_action"
app:backgroundTint="@color/dashboard_blue"/>
</RelativeLayout> </RelativeLayout>

View file

@ -1,5 +1,7 @@
package net.osmand.plus.quickaction; package net.osmand.plus.quickaction;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
@ -14,8 +16,6 @@ import android.support.v7.widget.Toolbar;
import android.support.v7.widget.helper.ItemTouchHelper; import android.support.v7.widget.helper.ItemTouchHelper;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -24,16 +24,14 @@ import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.base.BaseOsmAndFragment;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import static android.R.attr.scrollY;
import static android.util.TypedValue.COMPLEX_UNIT_DIP; import static android.util.TypedValue.COMPLEX_UNIT_DIP;
import static net.osmand.plus.R.id.index_item;
import static net.osmand.plus.R.id.toolbar;
/** /**
* Created by okorsun on 20.12.16. * Created by okorsun on 20.12.16.
@ -42,23 +40,35 @@ import static net.osmand.plus.R.id.toolbar;
public class QuickActionListFragment extends BaseOsmAndFragment { public class QuickActionListFragment extends BaseOsmAndFragment {
public static final String TAG = QuickActionListFragment.class.getSimpleName(); public static final String TAG = QuickActionListFragment.class.getSimpleName();
QuickActionAdapter adapter;
ItemTouchHelper touchHelper;
RecyclerView quickActionRV; RecyclerView quickActionRV;
FloatingActionButton fab; FloatingActionButton fab;
QuickActionAdapter adapter;
ItemTouchHelper touchHelper;
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.quick_action_list, container, false); View view = inflater.inflate(R.layout.quick_action_list, container, false);
quickActionRV = (RecyclerView) view.findViewById(R.id.recycler_view); quickActionRV = (RecyclerView) view.findViewById(R.id.recycler_view);
// quickActionRV.setBackgroundColor( fab = (FloatingActionButton) view.findViewById(R.id.fabButton);
// getResources().getColor(
// getMyApplication().getSettings().isLightContent() ? R.color.bg_color_light
// : R.color.bg_color_dark));
setUpQuickActionRV();
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));
}
});
setUpToolbar(view);
return view;
}
private void setUpQuickActionRV() {
adapter = new QuickActionAdapter(new OnStartDragListener() { adapter = new QuickActionAdapter(new OnStartDragListener() {
@Override @Override
public void onStartDrag(RecyclerView.ViewHolder viewHolder) { public void onStartDrag(RecyclerView.ViewHolder viewHolder) {
@ -73,9 +83,6 @@ public class QuickActionListFragment extends BaseOsmAndFragment {
touchHelper.attachToRecyclerView(quickActionRV); touchHelper.attachToRecyclerView(quickActionRV);
adapter.addItems(createMockDada()); adapter.addItems(createMockDada());
fab = (FloatingActionButton) view.findViewById(R.id.fabButton);
quickActionRV.setOnScrollListener(new RecyclerView.OnScrollListener() {
});
quickActionRV.addOnScrollListener(new RecyclerView.OnScrollListener() { quickActionRV.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override @Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) { public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
@ -85,9 +92,9 @@ public class QuickActionListFragment extends BaseOsmAndFragment {
fab.show(); fab.show();
} }
}); });
}
private void setUpToolbar(View view) {
Toolbar toolbar = (Toolbar) view.findViewById(R.id.custom_toolbar); Toolbar toolbar = (Toolbar) view.findViewById(R.id.custom_toolbar);
Drawable back = getMyApplication().getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha); Drawable back = getMyApplication().getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
back.setColorFilter(ContextCompat.getColor(getContext(), R.color.color_white), PorterDuff.Mode.MULTIPLY); back.setColorFilter(ContextCompat.getColor(getContext(), R.color.color_white), PorterDuff.Mode.MULTIPLY);
@ -100,13 +107,11 @@ public class QuickActionListFragment extends BaseOsmAndFragment {
}); });
toolbar.setTitle(R.string.configure_screen_quick_action); toolbar.setTitle(R.string.configure_screen_quick_action);
toolbar.setTitleTextColor(ContextCompat.getColor(getContext(), R.color.color_white)); toolbar.setTitleTextColor(ContextCompat.getColor(getContext(), R.color.color_white));
return view;
} }
private List<QuickActionItem> createMockDada() { private List<QuickActionItem> createMockDada() {
List<QuickActionItem> result = new ArrayList<>(); List<QuickActionItem> result = new ArrayList<>();
for (int i = 0; i < 5; i ++){ for (int i = 0; i < 3; i++) {
result.add(new QuickActionItem(R.string.favorite, R.drawable.ic_action_flag_dark)); result.add(new QuickActionItem(R.string.favorite, R.drawable.ic_action_flag_dark));
result.add(new QuickActionItem(R.string.poi, R.drawable.ic_action_flag_dark)); result.add(new QuickActionItem(R.string.poi, R.drawable.ic_action_flag_dark));
result.add(new QuickActionItem(R.string.map_marker, R.drawable.ic_action_flag_dark)); result.add(new QuickActionItem(R.string.map_marker, R.drawable.ic_action_flag_dark));
@ -116,10 +121,22 @@ public class QuickActionListFragment extends BaseOsmAndFragment {
} }
@Override @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onAttach(Context context) {
super.onCreateOptionsMenu(menu, inflater); super.onAttach(context);
getMapActivity().disableDrawer();
} }
@Override
public void onDetach() {
super.onDetach();
getMapActivity().enableDrawer();
}
private MapActivity getMapActivity() {
return (MapActivity) getActivity();
}
public class QuickActionAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements QuickActionItemTouchHelperCallback.OnItemMoveCallback { public class QuickActionAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements QuickActionItemTouchHelperCallback.OnItemMoveCallback {
public static final int SCREEN_ITEM_TYPE = 1; public static final int SCREEN_ITEM_TYPE = 1;
public static final int SCREEN_HEADER_TYPE = 2; public static final int SCREEN_HEADER_TYPE = 2;
@ -129,7 +146,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment {
private List<QuickActionItem> itemsList = new ArrayList<>(); private List<QuickActionItem> itemsList = new ArrayList<>();
private final OnStartDragListener onStartDragListener; private final OnStartDragListener onStartDragListener;
public QuickActionAdapter(OnStartDragListener onStartDragListener){ public QuickActionAdapter(OnStartDragListener onStartDragListener) {
this.onStartDragListener = onStartDragListener; this.onStartDragListener = onStartDragListener;
} }
@ -175,7 +192,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment {
dividerParams.setMargins(isShortDivider(position) ? dpToPx(56f) : 0, 0, 0, 0); dividerParams.setMargins(isShortDivider(position) ? dpToPx(56f) : 0, 0, 0, 0);
} else { } else {
QuickActionHeaderVH headerVH = (QuickActionHeaderVH) holder; QuickActionHeaderVH headerVH = (QuickActionHeaderVH) holder;
headerVH.headerName.setText(getResources().getString(R.string.quick_action_item_screen, position/(ITEMS_IN_GROUP + 1) + 1)); headerVH.headerName.setText(getResources().getString(R.string.quick_action_item_screen, position / (ITEMS_IN_GROUP + 1) + 1));
} }
} }
@ -190,13 +207,16 @@ public class QuickActionListFragment extends BaseOsmAndFragment {
} }
public void deleteItem(int position) { public void deleteItem(int position) {
if (position == -1)
return;
itemsList.remove(position); itemsList.remove(position);
notifyItemRemoved(position); notifyItemRemoved(position);
for (int i = position; i < itemsList.size(); i++ ){ for (int i = position; i < itemsList.size(); i++) {
if (getItemViewType(i) == SCREEN_HEADER_TYPE) { if (getItemViewType(i) == SCREEN_HEADER_TYPE) {
if (i != itemsList.size() - 2){ if (i != itemsList.size() - 2) {
Collections.swap(itemsList, i, i +1); Collections.swap(itemsList, i, i + 1);
notifyItemMoved(i, i + 1); notifyItemMoved(i, i + 1);
i++; i++;
} else { } else {
@ -207,9 +227,12 @@ public class QuickActionListFragment extends BaseOsmAndFragment {
} }
notifyItemRangeChanged(position, itemsList.size() - position); notifyItemRangeChanged(position, itemsList.size() - position);
showFABIfNotScrollable();
}
private void showFABIfNotScrollable() {
LinearLayoutManager layoutManager = (LinearLayoutManager) quickActionRV.getLayoutManager(); LinearLayoutManager layoutManager = (LinearLayoutManager) quickActionRV.getLayoutManager();
int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition(); int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition();
if ((lastVisibleItemPosition == itemsList.size() - 1 || lastVisibleItemPosition == itemsList.size()) && if ((lastVisibleItemPosition == itemsList.size() - 1 || lastVisibleItemPosition == itemsList.size()) &&
layoutManager.findFirstVisibleItemPosition() == 0 && layoutManager.findFirstVisibleItemPosition() == 0 &&
fab.getVisibility() != View.VISIBLE || fab.getVisibility() != View.VISIBLE ||
@ -230,6 +253,14 @@ public class QuickActionListFragment extends BaseOsmAndFragment {
notifyDataSetChanged(); notifyDataSetChanged();
} }
public void addItem(QuickActionItem item) {
int oldSize = itemsList.size();
if (oldSize % (ITEMS_IN_GROUP + 1) == 0)
itemsList.add(QuickActionItem.createHeaderItem());
itemsList.add(item);
notifyItemRangeInserted(oldSize, itemsList.size() - oldSize);
}
private int getActionPosition(int globalPosition) { private int getActionPosition(int globalPosition) {
return globalPosition % (ITEMS_IN_GROUP + 1); return globalPosition % (ITEMS_IN_GROUP + 1);
@ -261,7 +292,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment {
int targetPosition = target.getAdapterPosition(); int targetPosition = target.getAdapterPosition();
Collections.swap(itemsList, selectedPosition, targetPosition); Collections.swap(itemsList, selectedPosition, targetPosition);
if (selectedPosition - targetPosition < -1){ if (selectedPosition - targetPosition < -1) {
notifyItemMoved(selectedPosition, targetPosition); notifyItemMoved(selectedPosition, targetPosition);
notifyItemMoved(targetPosition - 1, selectedPosition); notifyItemMoved(targetPosition - 1, selectedPosition);
} else if (selectedPosition - targetPosition > 1) { } else if (selectedPosition - targetPosition > 1) {