Rewrite UI in ShareMenuFragment

This commit is contained in:
Alexander Sytnyk 2018-03-02 12:39:39 +02:00
parent d85d3063c1
commit 6dd0e35702
2 changed files with 24 additions and 130 deletions

View file

@ -1,61 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:orientation="vertical">
<LinearLayout
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title_text_view"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_title_height"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:text="@string/share_menu_location"
android:textAppearance="@style/TextAppearance.ListItemTitle"
osmand:typeface="@string/font_roboto_medium"/>
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@null"
android:dividerHeight="0dp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
<FrameLayout
android:id="@+id/cancel_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_cancel_button_height"
android:background="?attr/selectableItemBackground">
<TextView
android:id="@+id/cancel_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>

View file

@ -1,32 +1,22 @@
package net.osmand.plus.mapcontextmenu.other;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.plus.R;
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.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.mapcontextmenu.other.ShareMenu.ShareItem;
import net.osmand.plus.widgets.TextViewEx;
import java.util.List;
public class ShareMenuFragment extends MenuBottomSheetDialogFragment {
public class ShareMenuFragment extends MenuBottomSheetDialogFragment implements OnItemClickListener {
public static final String TAG = "ShareMenuFragment";
private ArrayAdapter<ShareItem> listAdapter;
private ShareMenu menu;
@Override
@ -39,33 +29,33 @@ public class ShareMenuFragment extends MenuBottomSheetDialogFragment implements
@Override
public View createMenuItems(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
final View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
R.layout.share_menu_fragment, container);
items.add(new TitleItem(getString(R.string.share_menu_location)));
if (nightMode) {
((TextViewEx) view.findViewById(R.id.title_text_view)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark));
View.OnClickListener itemOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
menu.share((ShareItem) v.getTag());
}
};
for (ShareItem shareItem : menu.getItems()) {
BaseBottomSheetItem item = new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(shareItem.getIconResourceId()))
.setTitle(getString(shareItem.getTitleResourceId()))
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setOnClickListener(itemOnClickListener)
.setTag(shareItem)
.create();
items.add(item);
}
ListView listView = (ListView) view.findViewById(R.id.list);
listAdapter = createAdapter();
listView.setAdapter(listAdapter);
listView.setOnItemClickListener(this);
view.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
setupHeightAndBackground(view, R.id.scroll_view);
return view;
return null;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
menu.saveMenu(outState);
}
@ -75,39 +65,4 @@ public class ShareMenuFragment extends MenuBottomSheetDialogFragment implements
fragment.setUsedOnMap(true);
fragment.show(menu.getMapActivity().getSupportFragmentManager(), ShareMenuFragment.TAG);
}
private ArrayAdapter<ShareItem> createAdapter() {
final List<ShareItem> items = menu.getItems();
return new ArrayAdapter<ShareItem>(menu.getMapActivity(), R.layout.share_list_item, items) {
@SuppressLint("InflateParams")
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
v = menu.getMapActivity().getLayoutInflater().inflate(R.layout.share_list_item, null);
}
AndroidUtils.setBackground(v.getContext(), v, nightMode, R.drawable.expandable_list_item_background_light, R.drawable.expandable_list_item_background_dark);
final ShareItem item = getItem(position);
ImageView icon = (ImageView) v.findViewById(R.id.icon);
icon.setImageDrawable(menu.getMapActivity().getMyApplication()
.getIconsCache().getIcon(item.getIconResourceId(), !nightMode));
TextView name = (TextView) v.findViewById(R.id.name);
AndroidUtils.setTextPrimaryColor(v.getContext(), name, nightMode);
name.setText(getContext().getText(item.getTitleResourceId()));
return v;
}
};
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
dismiss();
menu.share(listAdapter.getItem(position));
}
public void dismissMenu() {
dismiss();
menu.getMapActivity().getContextMenu().close();
}
}