Rewrite UI in AddGroupBottomSheetDialogFragment

This commit is contained in:
Alexander Sytnyk 2018-02-27 18:50:06 +02:00
parent 3c1f14b1fe
commit fa4a8ef876
5 changed files with 37 additions and 41 deletions

View file

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/close_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_cancel_button_height"
android:background="?attr/selectableItemBackground">
<TextView
android:id="@+id/close_row_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/shared_string_cancel"
android:textAllCaps="true"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_desc_text_size"
android:textStyle="bold"/>
</FrameLayout>

View file

@ -27,6 +27,23 @@
android:layout_height="1dp" android:layout_height="1dp"
android:background="?attr/dashboard_divider"/> android:background="?attr/dashboard_divider"/>
<include layout="@layout/bottom_sheet_item_cancel"/> <FrameLayout
android:id="@+id/close_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_cancel_button_height"
android:background="?attr/selectableItemBackground">
<TextView
android:id="@+id/close_row_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/shared_string_cancel"
android:textAllCaps="true"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_desc_text_size"
android:textStyle="bold"/>
</FrameLayout>
</LinearLayout> </LinearLayout>

View file

@ -11,8 +11,7 @@
android:id="@+id/groups_recycler_view" android:id="@+id/groups_recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:clipToPadding="false" android:clipToPadding="false"/>
android:paddingBottom="@dimen/bottom_sheet_content_padding_small"/>
<ProgressBar <ProgressBar
android:id="@+id/progress_bar" android:id="@+id/progress_bar"
@ -36,11 +35,4 @@
osmand:typeface="@string/font_roboto_medium" osmand:typeface="@string/font_roboto_medium"
tools:visibility="visible"/> tools:visibility="visible"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
<include layout="@layout/bottom_sheet_item_cancel"/>
</LinearLayout> </LinearLayout>

View file

@ -37,6 +37,8 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
protected boolean usedOnMap = true; protected boolean usedOnMap = true;
protected boolean nightMode; protected boolean nightMode;
private LinearLayout itemsContainer;
public void setUsedOnMap(boolean usedOnMap) { public void setUsedOnMap(boolean usedOnMap) {
this.usedOnMap = usedOnMap; this.usedOnMap = usedOnMap;
} }
@ -62,10 +64,10 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
View mainView = View.inflate(new ContextThemeWrapper(app, themeRes), R.layout.bottom_sheet_menu_base, null); View mainView = View.inflate(new ContextThemeWrapper(app, themeRes), R.layout.bottom_sheet_menu_base, null);
LinearLayout container = (LinearLayout) mainView.findViewById(R.id.items_container); itemsContainer = (LinearLayout) mainView.findViewById(R.id.items_container);
for (BaseBottomSheetItem item : items) { for (BaseBottomSheetItem item : items) {
item.inflate(app, container, nightMode); item.inflate(app, itemsContainer, nightMode);
} }
int closeRowDividerColorId = getCloseRowDividerColorId(); int closeRowDividerColorId = getCloseRowDividerColorId();
@ -106,6 +108,15 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
outState.putBoolean(USED_ON_MAP_KEY, usedOnMap); outState.putBoolean(USED_ON_MAP_KEY, usedOnMap);
} }
@Override
public void onDestroyView() {
super.onDestroyView();
items.clear();
if (itemsContainer != null) {
itemsContainer.removeAllViews();
}
}
// inflater, parent and return value are temporary and will be deleted // inflater, parent and return value are temporary and will be deleted
public abstract View createMenuItems(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState); public abstract View createMenuItems(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState);

View file

@ -13,6 +13,7 @@ import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup; import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.mapmarkers.adapters.GroupsAdapter; import net.osmand.plus.mapmarkers.adapters.GroupsAdapter;
public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
@ -37,7 +38,8 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD
@Override @Override
public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_add_group_bottom_sheet_dialog, container); mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
R.layout.fragment_marker_add_group_bottom_sheet_dialog, null);
final RecyclerView recyclerView = mainView.findViewById(R.id.groups_recycler_view); final RecyclerView recyclerView = mainView.findViewById(R.id.groups_recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
@ -65,16 +67,9 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD
}); });
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
mainView.findViewById(R.id.close_row).setOnClickListener(new View.OnClickListener() { items.add(new BaseBottomSheetItem.Builder().setCustomView(mainView).create());
@Override
public void onClick(View view) {
dismiss();
}
});
setupHeightAndBackground(mainView, R.id.groups_recycler_view); return null;
return mainView;
} }
@Override @Override