Refactor CoordinateInputAdapter and landscape layout for CoordinateInputDialogFragment; add another small fixes

This commit is contained in:
Alexander Sytnyk 2018-02-14 13:45:40 +02:00
parent 516be4b8e2
commit 2454fab872
4 changed files with 103 additions and 143 deletions

View file

@ -2,6 +2,7 @@
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto" xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
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">
@ -10,109 +11,60 @@
android:id="@+id/app_bar" android:id="@+id/app_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical"
tools:background="@color/route_info_bottom_view_bg_dark">
<android.support.v7.widget.Toolbar <android.support.v7.widget.Toolbar
android:id="@+id/coordinate_input_toolbar" android:id="@+id/coordinate_input_toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="48dp"
android:paddingBottom="12dp" osmand:contentInsetEnd="0dp"
android:paddingTop="12dp"
osmand:contentInsetLeft="4dp" osmand:contentInsetLeft="4dp"
osmand:contentInsetStart="4dp" osmand:contentInsetRight="0dp"
osmand:contentInsetRight="16dp" osmand:contentInsetStart="4dp">
osmand:contentInsetEnd="16dp">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:gravity="center_vertical">
<ImageButton <ImageButton
android:id="@+id/back_button" android:id="@+id/back_button"
style="@style/Widget.AppCompat.ActionButton" style="@style/Widget.AppCompat.ActionButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/ic_arrow_back" android:layout_marginEnd="16dp"
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"/> android:src="@drawable/ic_arrow_back"/>
<View <net.osmand.plus.widgets.TextViewEx
android:id="@+id/toolbar_text"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"/>
<net.osmand.plus.widgets.OsmandTextFieldBoxes
android:theme="@style/OsmandTextFieldBoxes"
android:id="@+id/latitude_box"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
osmand:labelText="@string/navigate_point_latitude" android:ellipsize="end"
android:layout_marginEnd="12dp" android:gravity="center_vertical"
android:layout_marginRight="12dp"> android:maxLines="1"
android:text="@string/coordinates"
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:textColor="@color/color_white" android:textColor="@color/color_white"
android:textColorHint="@color/white_50_transparent" android:textSize="@dimen/dialog_header_text_size"
android:inputType="numberSigned|numberDecimal" osmand:typeface="@string/font_roboto_medium"/>
android:imeOptions="actionNext"
android:id="@+id/latitude_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</net.osmand.plus.widgets.OsmandTextFieldBoxes> <net.osmand.plus.widgets.TextViewEx
<net.osmand.plus.widgets.OsmandTextFieldBoxes
android:theme="@style/OsmandTextFieldBoxes"
android:id="@+id/longitude_box"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
osmand:labelText="@string/navigate_point_longitude"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:textColor="@color/color_white"
android:textColorHint="@color/white_50_transparent"
android:inputType="numberSigned|numberDecimal"
android:imeOptions="actionNext"
android:id="@+id/longitude_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</net.osmand.plus.widgets.OsmandTextFieldBoxes>
<net.osmand.plus.widgets.OsmandTextFieldBoxes
android:theme="@style/OsmandTextFieldBoxes"
android:id="@+id/name_box"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
osmand:labelText="@string/shared_string_name"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp">
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
android:textColor="@color/color_white"
android:textColorHint="@color/white_50_transparent"
android:inputType="text"
android:imeOptions="actionDone"
android:id="@+id/name_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/access_hint_enter_name"/>
</net.osmand.plus.widgets.OsmandTextFieldBoxes>
<ImageButton
android:id="@+id/options_button" android:id="@+id/options_button"
style="@style/Widget.AppCompat.ActionButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:src="@drawable/ic_overflow_menu_white"/> android:background="?attr/selectableItemBackground"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="@string/shared_string_options"
android:textAllCaps="true"
android:textColor="@color/color_white"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular"/>
</LinearLayout> </LinearLayout>
@ -124,8 +76,6 @@
android:id="@+id/hand_container" android:id="@+id/hand_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="horizontal"> android:orientation="horizontal"/>
</LinearLayout>
</LinearLayout> </LinearLayout>

View file

@ -69,16 +69,11 @@
android:textColor="@color/dashboard_blue" android:textColor="@color/dashboard_blue"
android:textSize="@dimen/default_list_text_size" android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular"/> osmand:typeface="@string/font_roboto_regular"/>
</LinearLayout> </LinearLayout>
</android.support.v7.widget.Toolbar> </android.support.v7.widget.Toolbar>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:focusable="true"
android:focusableInTouchMode="true"/>
<include layout="@layout/coordinate_input_data_area"/> <include layout="@layout/coordinate_input_data_area"/>
</android.support.design.widget.AppBarLayout> </android.support.design.widget.AppBarLayout>

View file

@ -155,7 +155,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
mainView = inflater.inflate(R.layout.fragment_coordinate_input_dialog, container); mainView = inflater.inflate(R.layout.fragment_coordinate_input_dialog, container);
ImageButton backBtn = (ImageButton) mainView.findViewById(R.id.back_button); ImageButton backBtn = (ImageButton) mainView.findViewById(R.id.back_button);
backBtn.setImageDrawable(getActiveIcon(R.drawable.ic_arrow_back));
backBtn.setOnClickListener(new View.OnClickListener() { backBtn.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -164,11 +163,16 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
} }
}); });
if (orientationPortrait) {
backBtn.setImageDrawable(getActiveIcon(R.drawable.ic_arrow_back));
((TextView) mainView.findViewById(R.id.toolbar_text)).setTextColor(ContextCompat.getColor(getContext(), ((TextView) mainView.findViewById(R.id.toolbar_text)).setTextColor(ContextCompat.getColor(getContext(),
lightTheme ? R.color.color_black : R.color.color_white)); lightTheme ? R.color.color_black : R.color.color_white));
mainView.findViewById(R.id.app_bar).setBackgroundColor(ContextCompat.getColor(getContext(), mainView.findViewById(R.id.app_bar).setBackgroundColor(ContextCompat.getColor(getContext(),
lightTheme ? R.color.route_info_bg_light : R.color.route_info_bg_dark)); lightTheme ? R.color.route_info_bg_light : R.color.route_info_bg_dark));
} else {
mainView.findViewById(R.id.app_bar).setBackgroundColor(ContextCompat.getColor(getContext(),
lightTheme ? R.color.actionbar_light_color : R.color.route_info_bottom_view_bg_dark));
}
mainView.findViewById(R.id.options_button).setOnClickListener(new View.OnClickListener() { mainView.findViewById(R.id.options_button).setOnClickListener(new View.OnClickListener() {
@Override @Override

View file

@ -1,5 +1,7 @@
package net.osmand.plus.mapmarkers.adapters; package net.osmand.plus.mapmarkers.adapters;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -19,21 +21,23 @@ import java.util.List;
public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemViewHolder> { public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemViewHolder> {
private MapActivity mapActivity; private MapActivity mapActivity;
private boolean nightTheme;
private IconsCache iconsCache; private IconsCache iconsCache;
private List<MapMarker> mapMarkers; private List<MapMarker> mapMarkers;
private boolean nightTheme;
private boolean portrait;
private LatLon location; private LatLon location;
private Float heading; private Float heading;
private boolean useCenter; private boolean useCenter;
private int screenOrientation; private int screenOrientation;
private boolean portrait;
public CoordinateInputAdapter(MapActivity mapActivity, List<MapMarker> mapMarkers) { public CoordinateInputAdapter(MapActivity mapActivity, List<MapMarker> mapMarkers) {
this.mapActivity = mapActivity; this.mapActivity = mapActivity;
nightTheme = !mapActivity.getMyApplication().getSettings().isLightContent();
iconsCache = mapActivity.getMyApplication().getIconsCache(); iconsCache = mapActivity.getMyApplication().getIconsCache();
portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
this.mapMarkers = mapMarkers; this.mapMarkers = mapMarkers;
nightTheme = !mapActivity.getMyApplication().getSettings().isLightContent();
portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
} }
public void setLocation(LatLon location) { public void setLocation(LatLon location) {
@ -61,16 +65,18 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemVi
@Override @Override
public void onBindViewHolder(final MapMarkerItemViewHolder holder, int position) { public void onBindViewHolder(final MapMarkerItemViewHolder holder, int position) {
final MapMarker mapMarker = getItem(position); final MapMarker mapMarker = getItem(position);
holder.iconDirection.setVisibility(View.VISIBLE); holder.iconDirection.setVisibility(View.VISIBLE);
holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(mapMarker.colorIndex))); holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(mapMarker.colorIndex)));
holder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, nightTheme ? R.color.bg_color_dark : R.color.bg_color_light)); holder.mainLayout.setBackgroundColor(getResolvedColor(nightTheme ? R.color.bg_color_dark : R.color.bg_color_light));
holder.title.setTextColor(ContextCompat.getColor(mapActivity, nightTheme ? R.color.color_white : R.color.color_black)); holder.title.setTextColor(getResolvedColor(nightTheme ? R.color.color_white : R.color.color_black));
holder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, nightTheme ? R.color.actionbar_dark_color : R.color.dashboard_divider_light)); holder.divider.setBackgroundColor(getResolvedColor(nightTheme ? R.color.actionbar_dark_color : R.color.dashboard_divider_light));
holder.optionsBtn.setBackgroundDrawable(mapActivity.getResources().getDrawable(nightTheme ? R.drawable.marker_circle_background_dark_with_inset : R.drawable.marker_circle_background_light_with_inset)); holder.optionsBtn.setBackgroundDrawable(ContextCompat.getDrawable(mapActivity, nightTheme
? R.drawable.marker_circle_background_dark_with_inset : R.drawable.marker_circle_background_light_with_inset));
holder.optionsBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_remove_dark)); holder.optionsBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_remove_dark));
holder.iconReorder.setVisibility(View.GONE); holder.iconReorder.setVisibility(View.GONE);
holder.numberText.setVisibility(View.VISIBLE); holder.numberText.setVisibility(View.VISIBLE);
holder.numberText.setText(Integer.toString(position + 1)); holder.numberText.setText(String.valueOf(position + 1));
holder.description.setVisibility(View.GONE); holder.description.setVisibility(View.GONE);
holder.optionsBtn.setOnClickListener(new View.OnClickListener() { holder.optionsBtn.setOnClickListener(new View.OnClickListener() {
@ -78,8 +84,7 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemVi
public void onClick(View view) { public void onClick(View view) {
int position = holder.getAdapterPosition(); int position = holder.getAdapterPosition();
if (position != RecyclerView.NO_POSITION) { if (position != RecyclerView.NO_POSITION) {
MapMarker mapMarker = getItem(position); mapMarkers.remove(getItem(position));
mapMarkers.remove(mapMarker);
notifyDataSetChanged(); notifyDataSetChanged();
} }
} }
@ -88,6 +93,7 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemVi
boolean singleItem = getItemCount() == 1; boolean singleItem = getItemCount() == 1;
boolean fistItem = position == 0; boolean fistItem = position == 0;
boolean lastItem = position == getItemCount() - 1; boolean lastItem = position == getItemCount() - 1;
if (portrait) { if (portrait) {
holder.topDivider.setVisibility(fistItem ? View.VISIBLE : View.GONE); holder.topDivider.setVisibility(fistItem ? View.VISIBLE : View.GONE);
holder.bottomShadow.setVisibility(lastItem ? View.VISIBLE : View.GONE); holder.bottomShadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
@ -114,4 +120,9 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemVi
public MapMarker getItem(int position) { public MapMarker getItem(int position) {
return mapMarkers.get(position); return mapMarkers.get(position);
} }
@ColorInt
private int getResolvedColor(@ColorRes int colorResId) {
return ContextCompat.getColor(mapActivity, colorResId);
}
} }