Refactor the structure

This commit is contained in:
Alexander Sytnyk 2017-06-26 16:37:27 +03:00
parent ed3d1d2dc2
commit 62be4e773e
9 changed files with 221 additions and 506 deletions

View file

@ -6,6 +6,7 @@
android:orientation="vertical"> android:orientation="vertical">
<RelativeLayout <RelativeLayout
android:id="@+id/toggle_row"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/bg_color" android:background="?attr/bg_color"
@ -13,7 +14,7 @@
tools:layout_height="60dp"> tools:layout_height="60dp">
<android.support.v7.widget.AppCompatImageView <android.support.v7.widget.AppCompatImageView
android:id="@+id/display_icon" android:id="@+id/toggle_row_icon"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
@ -24,7 +25,7 @@
tools:src="@drawable/ic_action_gabout_dark" /> tools:src="@drawable/ic_action_gabout_dark" />
<android.support.v7.widget.SwitchCompat <android.support.v7.widget.SwitchCompat
android:id="@+id/display_toggle" android:id="@+id/toggle_row_toggle"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
@ -37,16 +38,16 @@
android:focusable="false" /> android:focusable="false" />
<android.support.v7.widget.AppCompatTextView <android.support.v7.widget.AppCompatTextView
android:id="@+id/display_title" android:id="@+id/toggle_row_title"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_marginLeft="16dp" android:layout_marginLeft="16dp"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_toEndOf="@+id/display_icon" android:layout_toEndOf="@+id/toggle_row_icon"
android:layout_toLeftOf="@id/display_toggle" android:layout_toLeftOf="@id/toggle_row_toggle"
android:layout_toRightOf="@+id/display_icon" android:layout_toRightOf="@+id/toggle_row_icon"
android:layout_toStartOf="@id/display_toggle" android:layout_toStartOf="@id/toggle_row_toggle"
android:textAppearance="@style/TextAppearance.ListItemTitle" android:textAppearance="@style/TextAppearance.ListItemTitle"
tools:text="Some title text" /> tools:text="Some title text" />
</RelativeLayout> </RelativeLayout>
@ -110,10 +111,11 @@
android:minHeight="60dp"> android:minHeight="60dp">
<android.support.v7.widget.AppCompatImageView <android.support.v7.widget.AppCompatImageView
android:id="@+id/mapillary_filters_user_icon"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="16dp" android:layout_margin="16dp"
android:src="@drawable/ic_action_user" /> tools:src="@drawable/ic_action_user" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -146,6 +148,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="?attr/bg_color" android:background="?attr/bg_color"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="52dp" android:paddingLeft="52dp"
@ -202,10 +205,11 @@
android:minHeight="60dp"> android:minHeight="60dp">
<android.support.v7.widget.AppCompatImageView <android.support.v7.widget.AppCompatImageView
android:id="@+id/mapillary_filters_date_icon"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="16dp" android:layout_margin="16dp"
android:src="@drawable/ic_action_data" /> tools:src="@drawable/ic_action_data" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -1,55 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:orientation="vertical"
android:paddingLeft="52dp"
android:paddingStart="52dp">
<net.osmand.plus.views.controls.DelayAutoCompleteTextView
android:id="@+id/auto_complete_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:completionThreshold="1"
android:hint="@string/mapillary_menu_edit_text_hint"
android:inputType="text"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
tools:text="Username" />
<LinearLayout
android:id="@+id/warning_linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone">
<ImageView
android:id="@+id/warning_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:text="@string/wrong_user_name"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_sub_text_size"
tools:text="Wrong user name!" />
</LinearLayout>
<View
android:id="@+id/divider"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginTop="12dp"
android:background="?attr/dashboard_divider" />
</LinearLayout>

View file

@ -1,42 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color">
<Button
android:id="@+id/button_apply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="32dp"
android:layout_marginStart="32dp"
android:background="?attr/selectableItemBackground"
android:text="@string/shared_string_apply"
android:textColor="?attr/color_dialog_buttons" />
<Button
android:id="@+id/button_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:background="?attr/selectableItemBackground"
android:text="@string/shared_string_clear"
android:textColor="?attr/color_dialog_buttons" />
</RelativeLayout>
<include layout="@layout/card_bottom_divider" />
<View
android:layout_width="match_parent"
android:layout_height="18dp" />
</LinearLayout>

View file

@ -1,61 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:orientation="vertical"
android:paddingLeft="52dp"
android:paddingStart="52dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp">
<android.support.design.widget.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp"
android:layout_weight="1">
<EditText
android:id="@+id/date_from_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:hint="@string/mapillary_menu_date_from"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
tools:text="From" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_weight="1">
<EditText
android:id="@+id/date_to_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:hint="@string/shared_string_to"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
tools:text="To" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<View
android:id="@+id/divider"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginTop="16dp"
android:background="?attr/dashboard_divider" />
</LinearLayout>

View file

@ -1,50 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:minHeight="60dp">
<android.support.v7.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
tools:src="@drawable/ic_action_user" />
<LinearLayout
android:id="@+id/text_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:minHeight="60dp"
android:orientation="vertical"
android:paddingBottom="12dp"
android:paddingTop="10dp">
<android.support.v7.widget.AppCompatTextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.ListItemTitle"
tools:text="Username" />
<android.support.v7.widget.AppCompatTextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ellipsize="end"
android:lines="1"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
tools:text="View images added by a certain user." />
</LinearLayout>
</LinearLayout>

View file

@ -1,7 +1,6 @@
package net.osmand.plus; package net.osmand.plus;
import android.app.Activity; import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.Intent; import android.content.Intent;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
@ -11,18 +10,12 @@ import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes; import android.support.annotation.LayoutRes;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.AppCompatImageView; import android.support.v7.widget.AppCompatImageView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.SeekBar; import android.widget.SeekBar;
@ -30,20 +23,13 @@ import android.widget.TextView;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.activities.HelpActivity; import net.osmand.plus.activities.HelpActivity;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.actions.AppModeDialog; import net.osmand.plus.activities.actions.AppModeDialog;
import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.dialogs.HelpArticleDialogFragment; import net.osmand.plus.dialogs.HelpArticleDialogFragment;
import net.osmand.plus.views.controls.DelayAutoCompleteTextView;
import net.osmand.plus.mapillary.MapillaryAutoCompleteAdapter;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -55,15 +41,6 @@ public class ContextMenuAdapter {
private int DEFAULT_LAYOUT_ID = R.layout.list_menu_item_native; private int DEFAULT_LAYOUT_ID = R.layout.list_menu_item_native;
List<ContextMenuItem> items = new ArrayList<>(); List<ContextMenuItem> items = new ArrayList<>();
private ConfigureMapMenu.OnClickListener changeAppModeListener = null; private ConfigureMapMenu.OnClickListener changeAppModeListener = null;
private MapActivity mapActivity;
public ContextMenuAdapter() {
}
public ContextMenuAdapter(MapActivity mapActivity) {
this.mapActivity = mapActivity;
}
public int length() { public int length() {
return items.size(); return items.size();
@ -352,167 +329,6 @@ public class ContextMenuAdapter {
} }
} }
final View autoCompleteTextView = convertView.findViewById(R.id.auto_complete_text_view);
if (autoCompleteTextView != null) {
final DelayAutoCompleteTextView textView = (DelayAutoCompleteTextView) autoCompleteTextView;
textView.setAdapter(new MapillaryAutoCompleteAdapter(getContext(), R.layout.auto_complete_suggestion, app));
String selectedUsername = app.getSettings().MAPILLARY_FILTER_USERNAME.get();
if (!selectedUsername.equals("") && app.getSettings().USE_MAPILLARY_FILTER.get()) {
textView.setText(selectedUsername);
textView.setSelection(selectedUsername.length());
}
textView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
((View)textView.getParent()).findViewById(R.id.warning_linear_layout).setVisibility(View.GONE);
}
@Override
public void afterTextChanged(Editable editable) {
}
});
ImageView imageView = (ImageView) ((View) textView.getParent()).findViewById(R.id.warning_image_view);
imageView.setImageDrawable(mIconsCache.getPaintedIcon(R.drawable.ic_small_warning,
app.getResources().getColor(R.color.color_warning)));
}
final View dateFromEditText = convertView.findViewById(R.id.date_from_edit_text);
if (dateFromEditText != null) {
final EditText dateFrom = (EditText) dateFromEditText;
final DateFormat dateFormat = SimpleDateFormat.getDateInstance(DateFormat.MEDIUM);
final OsmandSettings settings = app.getSettings();
final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Calendar from = Calendar.getInstance();
from.set(Calendar.YEAR, year);
from.set(Calendar.MONTH, monthOfYear);
from.set(Calendar.DAY_OF_MONTH, dayOfMonth);
dateFrom.setText(dateFormat.format(from.getTime()));
settings.MAPILLARY_FILTER_FROM_DATE.set(from.getTimeInMillis());
}
};
dateFrom.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Calendar now = Calendar.getInstance();
new DatePickerDialog(mapActivity, date,
now.get(Calendar.YEAR),
now.get(Calendar.MONTH),
now.get(Calendar.DAY_OF_MONTH)).show();
}
});
if (settings.USE_MAPILLARY_FILTER.get()) {
long from = settings.MAPILLARY_FILTER_FROM_DATE.get();
if (from != 0) {
dateFrom.setText(dateFormat.format(new Date(from)));
}
}
dateFrom.setCompoundDrawablesWithIntrinsicBounds(null, null,
mIconsCache.getThemedIcon(R.drawable.ic_action_arrow_drop_down), null);
}
final View dateToEditText = convertView.findViewById(R.id.date_to_edit_text);
if (dateToEditText != null) {
final EditText dateTo = (EditText) dateToEditText;
final DateFormat dateFormat = SimpleDateFormat.getDateInstance(DateFormat.MEDIUM);
final OsmandSettings settings = app.getSettings();
final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Calendar to = Calendar.getInstance();
to.set(Calendar.YEAR, year);
to.set(Calendar.MONTH, monthOfYear);
to.set(Calendar.DAY_OF_MONTH, dayOfMonth);
dateTo.setText(dateFormat.format(to.getTime()));
settings.MAPILLARY_FILTER_TO_DATE.set(to.getTimeInMillis());
}
};
dateTo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Calendar now = Calendar.getInstance();
new DatePickerDialog(mapActivity, date,
now.get(Calendar.YEAR),
now.get(Calendar.MONTH),
now.get(Calendar.DAY_OF_MONTH)).show();
}
});
if (settings.USE_MAPILLARY_FILTER.get()) {
long to = settings.MAPILLARY_FILTER_TO_DATE.get();
if (to != 0) {
dateTo.setText(dateFormat.format(new Date(to)));
}
}
dateTo.setCompoundDrawablesWithIntrinsicBounds(null, null,
mIconsCache.getThemedIcon(R.drawable.ic_action_arrow_drop_down), null);
}
final View applyBtn = convertView.findViewById(R.id.button_apply);
if (applyBtn != null) {
final Button apply = (Button) applyBtn;
apply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
View list = (View) view.getParent().getParent().getParent();
String username = ((AutoCompleteTextView) list.findViewById(R.id.auto_complete_text_view)).getText().toString();
String dateFrom = ((EditText) list.findViewById(R.id.date_from_edit_text)).getText().toString();
String dateTo = ((EditText) list.findViewById(R.id.date_to_edit_text)).getText().toString();
OsmandSettings settings = app.getSettings();
if (!settings.MAPILLARY_FILTER_USERNAME.get().equals("") || !dateFrom.equals("") || !dateTo.equals("")) {
settings.USE_MAPILLARY_FILTER.set(true);
}
if (!username.equals("") && settings.MAPILLARY_FILTER_USERNAME.get().equals("")) {
list.findViewById(R.id.warning_linear_layout).setVisibility(View.VISIBLE);
}
if (dateFrom.equals("")) {
settings.MAPILLARY_FILTER_FROM_DATE.set(0L);
}
if (dateTo.equals("")) {
settings.MAPILLARY_FILTER_TO_DATE.set(0L);
}
}
});
}
final View clearBtn = convertView.findViewById(R.id.button_clear);
if (clearBtn != null) {
final Button clear = (Button) clearBtn;
clear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
View list = (View) view.getParent().getParent().getParent();
OsmandSettings settings = app.getSettings();
((AutoCompleteTextView) list.findViewById(R.id.auto_complete_text_view)).setText("");
((EditText) list.findViewById(R.id.date_from_edit_text)).setText("");
((EditText) list.findViewById(R.id.date_to_edit_text)).setText("");
settings.USE_MAPILLARY_FILTER.set(false);
settings.MAPILLARY_FILTER_USER_KEY.set("");
settings.MAPILLARY_FILTER_USERNAME.set("");
settings.MAPILLARY_FILTER_FROM_DATE.set(0L);
settings.MAPILLARY_FILTER_TO_DATE.set(0L);
}
});
}
if (item.isCategory()) { if (item.isCategory()) {
convertView.setFocusable(false); convertView.setFocusable(false);
convertView.setClickable(false); convertView.setClickable(false);

View file

@ -1050,7 +1050,13 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
} }
public void refreshContent(boolean force) { public void refreshContent(boolean force) {
if (visibleType == DashboardType.WAYPOINTS if (visibleType == DashboardType.MAPILLARY) {
Fragment mapillaryFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(MapillaryFiltersFragment.TAG);
mapActivity.getSupportFragmentManager().beginTransaction()
.detach(mapillaryFragment)
.attach(mapillaryFragment)
.commit();
} else if (visibleType == DashboardType.WAYPOINTS
|| visibleType == DashboardType.MAP_MARKERS || visibleType == DashboardType.MAP_MARKERS
|| visibleType == DashboardType.MAP_MARKERS_SELECTION || visibleType == DashboardType.MAP_MARKERS_SELECTION
|| visibleType == DashboardType.CONFIGURE_SCREEN || visibleType == DashboardType.CONFIGURE_SCREEN

View file

@ -1,14 +1,35 @@
package net.osmand.plus.mapillary; package net.osmand.plus.mapillary;
import android.app.DatePickerDialog;
import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.views.controls.DelayAutoCompleteTextView;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class MapillaryFiltersFragment extends BaseOsmAndFragment { public class MapillaryFiltersFragment extends BaseOsmAndFragment {
@ -20,13 +41,191 @@ public class MapillaryFiltersFragment extends BaseOsmAndFragment {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_mapillary_filters, container, false); final MapActivity mapActivity = (MapActivity) getActivity();
final OsmandSettings settings = getSettings();
final MapillaryPlugin plugin = OsmandPlugin.getPlugin(MapillaryPlugin.class);
boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); final boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
final int backgroundColor = ContextCompat.getColor(getActivity(), final int backgroundColor = ContextCompat.getColor(getActivity(),
nightMode ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light); nightMode ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
final DateFormat dateFormat = SimpleDateFormat.getDateInstance(DateFormat.MEDIUM);
final View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_mapillary_filters, null);
view.setBackgroundColor(backgroundColor); view.setBackgroundColor(backgroundColor);
final View toggleRow = view.findViewById(R.id.toggle_row);
toggleRow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showOrHideMapillaryLayers(settings, plugin, mapActivity);
}
});
final boolean selected = settings.SHOW_MAPILLARY.get();
final int toggleActionStringId = selected ? R.string.shared_string_enabled : R.string.shared_string_disabled;
int toggleIconColorId;
int toggleIconId;
if (selected) {
toggleIconId = R.drawable.ic_action_view;
toggleIconColorId = nightMode ? R.color.color_dialog_buttons_dark : R.color.color_dialog_buttons_light;
} else {
toggleIconId = R.drawable.ic_action_hide;
toggleIconColorId = nightMode ? 0 : R.color.icon_color;
}
((AppCompatTextView) toggleRow.findViewById(R.id.toggle_row_title)).setText(toggleActionStringId);
final Drawable drawable = getIcon(toggleIconId, toggleIconColorId);
((AppCompatImageView) toggleRow.findViewById(R.id.toggle_row_icon)).setImageDrawable(drawable);
final CompoundButton toggle = (CompoundButton) toggleRow.findViewById(R.id.toggle_row_toggle);
toggle.setChecked(selected);
toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
showOrHideMapillaryLayers(settings, plugin, mapActivity);
}
});
final int colorRes = nightMode ? R.color.color_white : R.color.icon_color;
((AppCompatImageView) view.findViewById(R.id.mapillary_filters_user_icon)).setImageDrawable(getIcon(R.drawable.ic_action_user, colorRes));
((AppCompatImageView) view.findViewById(R.id.mapillary_filters_date_icon)).setImageDrawable(getIcon(R.drawable.ic_action_data, colorRes));
final DelayAutoCompleteTextView textView = (DelayAutoCompleteTextView) view.findViewById(R.id.auto_complete_text_view);
textView.setAdapter(new MapillaryAutoCompleteAdapter(getContext(), R.layout.auto_complete_suggestion, getMyApplication()));
String selectedUsername = settings.MAPILLARY_FILTER_USERNAME.get();
if (!selectedUsername.equals("") && settings.USE_MAPILLARY_FILTER.get()) {
textView.setText(selectedUsername);
textView.setSelection(selectedUsername.length());
}
textView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
view.findViewById(R.id.warning_linear_layout).setVisibility(View.GONE);
}
@Override
public void afterTextChanged(Editable editable) {
}
});
ImageView imageView = (ImageView) view.findViewById(R.id.warning_image_view);
imageView.setImageDrawable(getPaintedContentIcon(R.drawable.ic_small_warning,
getResources().getColor(R.color.color_warning)));
final EditText dateFromEt = (EditText) view.findViewById(R.id.date_from_edit_text);
final DatePickerDialog.OnDateSetListener dateFromDialog = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Calendar from = Calendar.getInstance();
from.set(Calendar.YEAR, year);
from.set(Calendar.MONTH, monthOfYear);
from.set(Calendar.DAY_OF_MONTH, dayOfMonth);
dateFromEt.setText(dateFormat.format(from.getTime()));
settings.MAPILLARY_FILTER_FROM_DATE.set(from.getTimeInMillis());
}
};
dateFromEt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Calendar now = Calendar.getInstance();
new DatePickerDialog(mapActivity, dateFromDialog,
now.get(Calendar.YEAR),
now.get(Calendar.MONTH),
now.get(Calendar.DAY_OF_MONTH)).show();
}
});
dateFromEt.setCompoundDrawablesWithIntrinsicBounds(null, null, getContentIcon(R.drawable.ic_action_arrow_drop_down), null);
final EditText dateToEt = (EditText) view.findViewById(R.id.date_to_edit_text);
final DatePickerDialog.OnDateSetListener dateToDialog = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Calendar to = Calendar.getInstance();
to.set(Calendar.YEAR, year);
to.set(Calendar.MONTH, monthOfYear);
to.set(Calendar.DAY_OF_MONTH, dayOfMonth);
dateToEt.setText(dateFormat.format(to.getTime()));
settings.MAPILLARY_FILTER_TO_DATE.set(to.getTimeInMillis());
}
};
dateToEt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Calendar now = Calendar.getInstance();
new DatePickerDialog(mapActivity, dateToDialog,
now.get(Calendar.YEAR),
now.get(Calendar.MONTH),
now.get(Calendar.DAY_OF_MONTH)).show();
}
});
dateToEt.setCompoundDrawablesWithIntrinsicBounds(null, null, getContentIcon(R.drawable.ic_action_arrow_drop_down), null);
if (settings.USE_MAPILLARY_FILTER.get()) {
long to = settings.MAPILLARY_FILTER_TO_DATE.get();
if (to != 0) {
dateToEt.setText(dateFormat.format(new Date(to)));
}
long from = settings.MAPILLARY_FILTER_FROM_DATE.get();
if (from != 0) {
dateFromEt.setText(dateFormat.format(new Date(from)));
}
}
final Button apply = (Button) view.findViewById(R.id.button_apply);
apply.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = textView.getText().toString();
String dateFrom = dateFromEt.getText().toString();
String dateTo = dateToEt.getText().toString();
if (!settings.MAPILLARY_FILTER_USERNAME.get().equals("") || !dateFrom.equals("") || !dateTo.equals("")) {
settings.USE_MAPILLARY_FILTER.set(true);
}
if (!username.equals("") && settings.MAPILLARY_FILTER_USERNAME.get().equals("")) {
view.findViewById(R.id.warning_linear_layout).setVisibility(View.VISIBLE);
}
if (dateFrom.equals("")) {
settings.MAPILLARY_FILTER_FROM_DATE.set(0L);
}
if (dateTo.equals("")) {
settings.MAPILLARY_FILTER_TO_DATE.set(0L);
}
}
});
final Button clear = (Button) view.findViewById(R.id.button_clear);
clear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
textView.setText("");
dateFromEt.setText("");
dateToEt.setText("");
settings.USE_MAPILLARY_FILTER.set(false);
settings.MAPILLARY_FILTER_USER_KEY.set("");
settings.MAPILLARY_FILTER_USERNAME.set("");
settings.MAPILLARY_FILTER_FROM_DATE.set(0L);
settings.MAPILLARY_FILTER_TO_DATE.set(0L);
}
});
return view; return view;
} }
private void showOrHideMapillaryLayers(OsmandSettings settings, MapillaryPlugin plugin, MapActivity mapActivity) {
settings.SHOW_MAPILLARY.set(!settings.SHOW_MAPILLARY.get());
plugin.updateLayers(mapActivity.getMapView(), mapActivity);
mapActivity.getDashboard().refreshContent(true);
}
} }

View file

@ -1,102 +0,0 @@
package net.osmand.plus.mapillary;
import android.widget.ArrayAdapter;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
public class MapillaryMenu {
public static ContextMenuAdapter createListAdapter(final MapActivity mapActivity) {
ContextMenuAdapter adapter = new ContextMenuAdapter(mapActivity);
adapter.setDefaultLayoutId(R.layout.list_item_icon_and_menu);
createLayersItems(adapter, mapActivity);
return adapter;
}
private static void createLayersItems(final ContextMenuAdapter contextMenuAdapter, final MapActivity mapActivity) {
final OsmandApplication app = mapActivity.getMyApplication();
final OsmandSettings settings = app.getSettings();
final MapillaryPlugin plugin = OsmandPlugin.getPlugin(MapillaryPlugin.class);
if (plugin == null) {
return;
}
final boolean selected = settings.SHOW_MAPILLARY.get();
final int toggleActionStringId = selected ? R.string.shared_string_enabled : R.string.shared_string_disabled;
ContextMenuAdapter.OnRowItemClick l = new ContextMenuAdapter.OnRowItemClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked) {
if (itemId == toggleActionStringId) {
settings.SHOW_MAPILLARY.set(!settings.SHOW_MAPILLARY.get());
plugin.updateLayers(mapActivity.getMapView(), mapActivity);
mapActivity.getDashboard().refreshContent(true);
}
return false;
}
};
boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
int toggleIconColorId;
int toggleIconId;
if (selected) {
toggleIconId = R.drawable.ic_action_view;
toggleIconColorId = nightMode ? R.color.color_dialog_buttons_dark : R.color.color_dialog_buttons_light;
} else {
toggleIconId = R.drawable.ic_action_hide;
toggleIconColorId = nightMode ? 0 : R.color.icon_color;
}
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(toggleActionStringId, mapActivity)
.setIcon(toggleIconId)
.setColor(toggleIconColorId)
.setListener(l)
.setSelected(selected)
.createItem());
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.search_poi_filter, mapActivity)
.setDescription(app.getString(R.string.mapillary_menu_filter_description))
.setCategory(true)
.setLayout(R.layout.list_group_title_with_descr)
.createItem());
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.mapillary_menu_title_username, mapActivity)
.setDescription(app.getString(R.string.mapillary_menu_descr_username))
.setIcon(R.drawable.ic_action_user)
.setClickable(false)
.setLayout(R.layout.list_item_icon_with_title_and_descr)
.createItem());
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.setLayout(R.layout.list_item_auto_complete_text_view)
.setClickable(false)
.createItem());
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.mapillary_menu_title_dates, mapActivity)
.setDescription(app.getString(R.string.mapillary_menu_descr_dates))
.setIcon(R.drawable.ic_action_data)
.setClickable(false)
.setLayout(R.layout.list_item_icon_with_title_and_descr)
.createItem());
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.setLayout(R.layout.list_item_date_from_and_to)
.setClickable(false)
.createItem());
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
.setLayout(R.layout.list_item_buttons)
.setClickable(false)
.createItem());
}
}