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

@ -1,131 +1,81 @@
<?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="match_parent"
android:orientation="vertical">
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:background="@color/route_info_bottom_view_bg_dark">
<android.support.v7.widget.Toolbar
android:id="@+id/coordinate_input_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="12dp"
android:paddingTop="12dp"
osmand:contentInsetLeft="4dp"
osmand:contentInsetStart="4dp"
osmand:contentInsetRight="16dp"
osmand:contentInsetEnd="16dp">
<android.support.v7.widget.Toolbar
android:id="@+id/coordinate_input_toolbar"
android:layout_width="match_parent"
android:layout_height="48dp"
osmand:contentInsetEnd="0dp"
osmand:contentInsetLeft="4dp"
osmand:contentInsetRight="0dp"
osmand:contentInsetStart="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<ImageButton
android:id="@+id/back_button"
style="@style/Widget.AppCompat.ActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_arrow_back"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"/>
<ImageButton
android:id="@+id/back_button"
style="@style/Widget.AppCompat.ActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:src="@drawable/ic_arrow_back"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:focusable="true"
android:focusableInTouchMode="true"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/toolbar_text"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:text="@string/coordinates"
android:textColor="@color/color_white"
android:textSize="@dimen/dialog_header_text_size"
osmand:typeface="@string/font_roboto_medium"/>
<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"
osmand:labelText="@string/navigate_point_latitude"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/options_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
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"/>
<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/latitude_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</net.osmand.plus.widgets.OsmandTextFieldBoxes>
</android.support.v7.widget.Toolbar>
<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">
</android.support.design.widget.AppBarLayout>
<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"/>
<LinearLayout
android:id="@+id/hand_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"/>
</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"
style="@style/Widget.AppCompat.ActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_overflow_menu_white"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:id="@+id/hand_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -69,16 +69,11 @@
android:textColor="@color/dashboard_blue"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular"/>
</LinearLayout>
</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"/>
</android.support.design.widget.AppBarLayout>
@ -151,4 +146,4 @@
</LinearLayout>
</FrameLayout>
</FrameLayout>

View file

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

View file

@ -1,5 +1,7 @@
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.v7.widget.RecyclerView;
import android.view.LayoutInflater;
@ -19,21 +21,23 @@ import java.util.List;
public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemViewHolder> {
private MapActivity mapActivity;
private boolean nightTheme;
private IconsCache iconsCache;
private List<MapMarker> mapMarkers;
private boolean nightTheme;
private boolean portrait;
private LatLon location;
private Float heading;
private boolean useCenter;
private int screenOrientation;
private boolean portrait;
public CoordinateInputAdapter (MapActivity mapActivity, List<MapMarker> mapMarkers) {
public CoordinateInputAdapter(MapActivity mapActivity, List<MapMarker> mapMarkers) {
this.mapActivity = mapActivity;
nightTheme = !mapActivity.getMyApplication().getSettings().isLightContent();
iconsCache = mapActivity.getMyApplication().getIconsCache();
portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
this.mapMarkers = mapMarkers;
nightTheme = !mapActivity.getMyApplication().getSettings().isLightContent();
portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
}
public void setLocation(LatLon location) {
@ -61,16 +65,18 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemVi
@Override
public void onBindViewHolder(final MapMarkerItemViewHolder holder, int position) {
final MapMarker mapMarker = getItem(position);
holder.iconDirection.setVisibility(View.VISIBLE);
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.title.setTextColor(ContextCompat.getColor(mapActivity, 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.optionsBtn.setBackgroundDrawable(mapActivity.getResources().getDrawable(nightTheme ? R.drawable.marker_circle_background_dark_with_inset : R.drawable.marker_circle_background_light_with_inset));
holder.mainLayout.setBackgroundColor(getResolvedColor(nightTheme ? R.color.bg_color_dark : R.color.bg_color_light));
holder.title.setTextColor(getResolvedColor(nightTheme ? R.color.color_white : R.color.color_black));
holder.divider.setBackgroundColor(getResolvedColor(nightTheme ? R.color.actionbar_dark_color : R.color.dashboard_divider_light));
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.iconReorder.setVisibility(View.GONE);
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.optionsBtn.setOnClickListener(new View.OnClickListener() {
@ -78,8 +84,7 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemVi
public void onClick(View view) {
int position = holder.getAdapterPosition();
if (position != RecyclerView.NO_POSITION) {
MapMarker mapMarker = getItem(position);
mapMarkers.remove(mapMarker);
mapMarkers.remove(getItem(position));
notifyDataSetChanged();
}
}
@ -88,6 +93,7 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemVi
boolean singleItem = getItemCount() == 1;
boolean fistItem = position == 0;
boolean lastItem = position == getItemCount() - 1;
if (portrait) {
holder.topDivider.setVisibility(fistItem ? 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) {
return mapMarkers.get(position);
}
@ColorInt
private int getResolvedColor(@ColorRes int colorResId) {
return ContextCompat.getColor(mapActivity, colorResId);
}
}