working on quick action list

This commit is contained in:
Korusn Oleksandr 2016-12-20 19:26:34 +02:00
parent 481ea7551c
commit 368bb2738f
4 changed files with 43 additions and 5 deletions

View file

@ -8,6 +8,7 @@
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/ctx_menu_info_view_bg"
/>
</LinearLayout>

View file

@ -2,10 +2,11 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:background="?attr/bg_color"
android:paddingRight="16dp"
android:paddingTop="8dp">

View file

@ -2,6 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="?attr/bg_color"
android:layout_height="wrap_content"
android:orientation="vertical">
@ -20,7 +21,7 @@
android:layout_marginRight="4dp"
android:focusable="false"
android:scaleType="centerInside"
android:src="@drawable/map_drawer"
android:src="@drawable/ic_action_reorder"
android:visibility="gone"
tools:visibility="visible"/>
@ -69,7 +70,7 @@
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:layout_marginRight="16dp"
android:src="@drawable/ic_action_close_dark"
android:src="@drawable/ic_action_remove_dark"
android:scaleType="centerInside"/>
</LinearLayout>

View file

@ -3,6 +3,7 @@ package net.osmand.plus.quickaction;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.TypedValue;
import android.view.LayoutInflater;
@ -25,8 +26,10 @@ import static android.util.TypedValue.COMPLEX_UNIT_DIP;
*/
public class QuickActionListFragment extends BaseOsmAndFragment {
public static final String TAG = QuickActionListFragment.class.getSimpleName();
RecyclerView quickActionRV;
QuickActionAdapter adapter;
@Nullable
@Override
@ -34,11 +37,30 @@ public class QuickActionListFragment extends BaseOsmAndFragment {
View view = inflater.inflate(R.layout.quick_action_list, container, false);
quickActionRV = (RecyclerView) view.findViewById(R.id.recycler_view);
// quickActionRV.setBackgroundColor(
// getResources().getColor(
// getMyApplication().getSettings().isLightContent() ? R.color.bg_color_light
// : R.color.bg_color_dark));
adapter = new QuickActionAdapter();
quickActionRV.setAdapter(adapter);
quickActionRV.setLayoutManager(new LinearLayoutManager(getContext()));
adapter.addItems(createMockDada());
return view;
}
private List<QuickActionItem> createMockDada() {
List<QuickActionItem> result = new ArrayList<>();
for (int i = 0; i < 15; i ++){
result.add(new QuickActionItem(R.string.favorite, R.drawable.ic_action_flag_dark));
}
return result;
}
public class QuickActionAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int SCREEN_ITEM_TYPE = 1;
@ -66,13 +88,13 @@ public class QuickActionListFragment extends BaseOsmAndFragment {
QuickActionItemVH itemVH = (QuickActionItemVH) holder;
itemVH.icon.setImageResource(item.getDrawableRes());
itemVH.title.setText(item.getNameRes());
itemVH.subTitle.setText("Action" + getActionPosition(position)); //TODO: get proper string
itemVH.subTitle.setText("Action " + getActionPosition(position)); //TODO: get proper string
LinearLayout.LayoutParams dividerParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
dividerParams.setMargins(isShortDivider(position) ? dpToPx(56f) : 0, 0, 0, 0);
} else {
QuickActionHeaderVH headerVH = (QuickActionHeaderVH) holder;
headerVH.headerName.setText("Screen" + (position/(ITEMS_IN_GROUP + 1) + 1)); //TODO: get proper string
headerVH.headerName.setText("Screen " + (position/(ITEMS_IN_GROUP + 1) + 1)); //TODO: get proper string
}
}
@ -92,6 +114,19 @@ public class QuickActionListFragment extends BaseOsmAndFragment {
notifyItemRemoved(position);
}
public void addItems(List<QuickActionItem> data) {
List<QuickActionItem> resultList = new ArrayList<>();
for (int i = 0; i < data.size(); i++) {
if (i % ITEMS_IN_GROUP == 0)
resultList.add(QuickActionItem.createHeaderItem());
resultList.add(data.get(i));
}
itemsList = resultList;
notifyDataSetChanged();
}
private int getActionPosition(int globalPosition) {
return globalPosition % (ITEMS_IN_GROUP + 1);