import ui, duplicate quick actions

This commit is contained in:
veliymolfar 2020-02-13 18:49:31 +02:00
parent 44ccddc3dc
commit 3f753c5677
15 changed files with 782 additions and 137 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout 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"
@ -8,8 +8,10 @@
android:orientation="vertical">
<LinearLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:orientation="vertical">
@ -38,6 +40,7 @@
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar_layout"
android:background="?attr/bg_color"
android:paddingStart="@dimen/content_padding"
android:paddingTop="@dimen/list_header_settings_top_margin"
@ -48,20 +51,27 @@
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_medium" />
<include layout="@layout/list_item_divider" />
<include
android:id="@+id/description_divider"
layout="@layout/card_bottom_divider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/description" />
<ExpandableListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="?attr/expandable_list_background"
android:groupIndicator="@android:color/transparent" />
android:layout_height="wrap_content"
android:layout_below="@+id/description_divider"
android:layout_marginBottom="@dimen/dialog_button_ex_height"
android:groupIndicator="@android:color/transparent"
android:listSelector="@android:color/transparent" />
<LinearLayout
android:id="@+id/buttons_container"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_button_ex_height"
android:layout_alignParentBottom="true"
android:background="?attr/bg_color"
android:gravity="center"
android:orientation="horizontal"
@ -127,4 +137,4 @@
</LinearLayout>
</LinearLayout>
</RelativeLayout>

View file

@ -50,7 +50,7 @@
<include layout="@layout/list_item_divider" />
<android.support.v7.widget.RecyclerView
android:id="@android:id/list"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"

View file

@ -0,0 +1,44 @@
<?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:orientation="vertical">
<include
android:id="@+id/top_divider"
layout="@layout/card_top_divider"
android:visibility="gone"
tools:visibility="visible" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/bg_color"
android:gravity="center_vertical"
android:minHeight="66dp"
android:orientation="vertical"
android:paddingStart="@dimen/content_padding"
android:paddingTop="@dimen/list_header_settings_top_margin"
android:paddingEnd="@dimen/content_padding"
android:paddingBottom="@dimen/list_header_settings_top_margin">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/preference_category_title"
android:textSize="@dimen/default_list_text_size"
tools:text="Quick actions" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/sub_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
tools:text="Listed quick actions, already exist in OsmAnd." />
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,54 @@
<?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:gravity="center_vertical"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/bg_color"
android:gravity="center_vertical"
android:minHeight="66dp">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/content_padding"
tools:src="@drawable/ic_action_offroad" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
tools:text="OffRoad" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/sub_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
tools:text="Navigation type: Car" />
</LinearLayout>
</LinearLayout>
<include
android:id="@+id/bottom_divider"
layout="@layout/card_bottom_divider"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>

View file

@ -1,49 +1,74 @@
<?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:gravity="center_vertical"
android:orientation="vertical">
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:minHeight="66dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/bg_color"
android:gravity="center_vertical"
android:minHeight="66dp">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/content_padding"
tools:src="@drawable/ic_action_info_dark" />
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/content_padding"
tools:src="@drawable/ic_action_info_dark" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title_tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
tools:text="Quick actions" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding"
android:focusable="false" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title_tv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
tools:text="Quick actions" />
</LinearLayout>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/sub_title_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
android:visibility="gone"
tools:text="description"
tools:visibility="visible" />
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/list_divider"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding"
android:focusable="false" />
</LinearLayout>
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/list_divider"
android:visibility="gone"
tools:visibility="visible" />
<include
android:id="@+id/card_bottom_divider"
layout="@layout/card_bottom_divider"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>

View file

@ -1,72 +1,85 @@
<?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:orientation="vertical">
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:minHeight="66dp"
android:orientation="horizontal">
<include
android:id="@+id/card_top_divider"
layout="@layout/card_top_divider"
android:visibility="gone"
tools:visibility="visible" />
<ImageView
android:id="@+id/explist_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/content_padding"
android:src="@drawable/ic_action_arrow_down" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/bg_color"
android:gravity="center_vertical"
android:minHeight="66dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical">
<ImageView
android:id="@+id/explist_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/content_padding"
android:src="@drawable/ic_action_arrow_down" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
tools:text="Quick actions" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/sub_text_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
tools:text="8 of 4" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
tools:text="Quick actions" />
</LinearLayout>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/sub_text_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
tools:text="8 of 4" />
<View
android:id="@+id/vertical_divider"
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/content_padding"
android:layout_marginBottom="@dimen/content_padding"
android:background="?attr/list_divider" />
</LinearLayout>
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/content_padding"
android:focusable="false" />
<View
android:id="@+id/vertical_divider"
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/content_padding"
android:layout_marginBottom="@dimen/content_padding"
android:background="?attr/list_divider" />
</LinearLayout>
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/content_padding"
android:focusable="false" />
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/list_divider"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>
<View
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/list_divider"
android:visibility="gone"
tools:visibility="visible" />
<include
android:id="@+id/card_bottom_divider"
layout="@layout/card_bottom_divider"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>

View file

@ -11,6 +11,10 @@
Thx - Hardy
-->
<string name="shared_sting_nothing_selected">Nothing selected</string>
<string name="shared_sting_quick_actions">Quick actions</string>
<string name="shared_sting_profiles">Profiles</string>
<string name="listed_exist">Listed %1$s, already exist in OsmAnd.</string>
<string name="replace_all_desc">Current items will be replaced with items from the file</string>
<string name="replace_all">Replace all</string>
<string name="keep_both">Keep both</string>

View file

@ -658,8 +658,4 @@ public class SQLiteTileSource implements ITileSource {
public String getReferer() {
return referer;
}
public String getUrlTemplate() {
return urlTemplate;
}
}

View file

@ -153,6 +153,8 @@ public class SettingsHelper {
private SettingsItemType type;
boolean shouldReplace = false;
SettingsItem(@NonNull SettingsItemType type) {
this.type = type;
}
@ -176,10 +178,14 @@ public class SettingsHelper {
@NonNull
public abstract String getFileName();
public Boolean shouldReadOnCollecting() {
public boolean shouldReadOnCollecting() {
return false;
}
public void setShouldReplace(boolean shouldReplace) {
this.shouldReplace = shouldReplace;
}
static SettingsItemType parseItemType(@NonNull JSONObject json) throws IllegalArgumentException, JSONException {
return SettingsItemType.valueOf(json.getString("type"));
}
@ -760,20 +766,42 @@ public class SettingsHelper {
QuickActionFactory factory = new QuickActionFactory();
List<QuickAction> savedActions = factory.parseActiveActionsList(getSettings().QUICK_ACTION_LIST.get());
List<QuickAction> newActions = new ArrayList<>(savedActions);
for (QuickAction action : quickActions) {
for (QuickAction savedAction : savedActions) {
if (action.getName(app).equals(savedAction.getName(app))) {
newActions.remove(savedAction);
if (shouldReplace) {
for (QuickAction action : quickActions) {
for (QuickAction savedAction : savedActions) {
if (action.getName(app).equals(savedAction.getName(app))) {
newActions.remove(savedAction);
}
}
}
} else {
for (QuickAction action : quickActions) {
action.setName("new_" + action.getName(app));
}
}
newActions.addAll(quickActions);
((MapActivity) app.getSettingsHelper().getActivity()).getMapLayers().getQuickActionRegistry().updateQuickActions(newActions);
}
}
public List<QuickAction> getDuplicates() {
List<QuickAction> duplicates = new ArrayList<>();
if (!quickActions.isEmpty()) {
QuickActionFactory factory = new QuickActionFactory();
List<QuickAction> savedActions = factory.parseActiveActionsList(getSettings().QUICK_ACTION_LIST.get());
for (QuickAction action : quickActions) {
for (QuickAction savedAction : savedActions) {
if (action.getName(app).equals(savedAction.getName(app))) {
duplicates.add(action);
}
}
}
}
return duplicates;
}
@Override
public Boolean shouldReadOnCollecting() {
public boolean shouldReadOnCollecting() {
return true;
}
@ -916,7 +944,7 @@ public class SettingsHelper {
}
@Override
public Boolean shouldReadOnCollecting() {
public boolean shouldReadOnCollecting() {
return true;
}
@ -1053,7 +1081,7 @@ public class SettingsHelper {
}
@Override
public Boolean shouldReadOnCollecting() {
public boolean shouldReadOnCollecting() {
return true;
}

View file

@ -786,11 +786,7 @@ public class ImportHelper {
if (succeed) {
FragmentManager fragmentManager = activity.getSupportFragmentManager();
if (fragmentManager != null) {
ExportImportProfileBottomSheet.showInstance(
fragmentManager,
ExportImportProfileBottomSheet.State.IMPORT,
file,
items);
ImportSettingsFragment.showInstance(fragmentManager, items, file);
}
} else {
app.showShortToastMessage(app.getString(R.string.file_import_error, name, app.getString(R.string.shared_string_unexpected_error)));

View file

@ -26,6 +26,7 @@ public class AdditionalDataWrapper {
}
public enum Type {
PROFILE,
QUICK_ACTIONS,
POI_TYPES,
MAP_SOURCES,

View file

@ -0,0 +1,143 @@
package net.osmand.plus.settings;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.quickaction.QuickAction;
import java.util.List;
public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int HEADER_TYPE = 0;
private static final int ITEM_TYPE = 1;
private boolean nightMode;
private OsmandApplication app;
private List<? super Object> items;
DuplicatesSettingsAdapter(OsmandApplication app, List<? super Object> items, boolean nightMode) {
this.app = app;
this.items = items;
this.nightMode = nightMode;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(app);
if (viewType == HEADER_TYPE) {
View view = inflater.inflate(R.layout.list_item_header_import, parent, false);
return new HeaderViewHolder(view);
} else {
View view = inflater.inflate(R.layout.list_item_import, parent, false);
return new ItemViewHolder(view);
}
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
Object currentItem = items.get(position);
if (holder instanceof HeaderViewHolder) {
((HeaderViewHolder) holder).title.setText((String) currentItem);
((HeaderViewHolder) holder).subTitle.setText(String.format(
app.getString(R.string.listed_exist),
(String) currentItem));
((HeaderViewHolder) holder).divider.setVisibility(View.VISIBLE);
} else if (holder instanceof ItemViewHolder) {
String title = null;
String subTitle = null;
Drawable drawable = null;
if (currentItem instanceof ApplicationMode) {
title = ((ApplicationMode) currentItem).toHumanString();
subTitle = ((ApplicationMode) currentItem).getRoutingProfile();
drawable = app.getUIUtilities().getIcon(
((ApplicationMode) currentItem).getIconRes(),
((ApplicationMode) currentItem).getIconColorInfo().getColor(nightMode)
);
} else if (currentItem instanceof QuickAction) {
title = ((QuickAction) currentItem).getName(app);
drawable = app.getUIUtilities().getIcon(((QuickAction) currentItem).getIconRes(), nightMode);
}
((ItemViewHolder) holder).title.setText(title != null ? title : "");
if (subTitle != null) {
((ItemViewHolder) holder).subTitle.setText(subTitle);
((ItemViewHolder) holder).subTitle.setVisibility(View.VISIBLE);
} else {
((ItemViewHolder) holder).subTitle.setVisibility(View.GONE);
}
if (drawable != null) {
((ItemViewHolder) holder).icon.setImageDrawable(drawable);
((ItemViewHolder) holder).icon.setImageResource(View.VISIBLE);
} else {
((ItemViewHolder) holder).icon.setImageResource(R.drawable.ic_action_info_dark);
((ItemViewHolder) holder).icon.setVisibility(View.GONE);
}
((ItemViewHolder) holder).divider.setVisibility(shouldShowDivider(position) ? View.VISIBLE : View.GONE);
}
}
@Override
public int getItemCount() {
return items.size();
}
@Override
public int getItemViewType(int position) {
if (items.get(position) instanceof String) {
return HEADER_TYPE;
} else {
return ITEM_TYPE;
}
}
private class HeaderViewHolder extends RecyclerView.ViewHolder {
TextView title;
TextView subTitle;
View divider;
HeaderViewHolder(View itemView) {
super(itemView);
title = itemView.findViewById(R.id.title);
subTitle = itemView.findViewById(R.id.sub_title);
divider = itemView.findViewById(R.id.top_divider);
}
}
private class ItemViewHolder extends RecyclerView.ViewHolder {
TextView title;
TextView subTitle;
ImageView icon;
View divider;
ItemViewHolder(View itemView) {
super(itemView);
title = itemView.findViewById(R.id.title);
subTitle = itemView.findViewById(R.id.sub_title);
icon = itemView.findViewById(R.id.icon);
divider = itemView.findViewById(R.id.bottom_divider);
}
}
private boolean shouldShowDivider(int position) {
boolean isLast = position == items.size() - 1;
if (isLast) {
return true;
} else {
Object next = items.get(position + 1);
return next instanceof String;
}
}
}

View file

@ -0,0 +1,260 @@
package net.osmand.plus.settings;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.map.ITileSource;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.profiles.AdditionalDataWrapper;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.render.RenderingIcons;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
private OsmandApplication app;
private List<? super Object> settingsToOperate;
private List<AdditionalDataWrapper> settingsList;
private boolean nightMode;
private boolean importState;
ExportImportSettingsAdapter(OsmandApplication app, List<AdditionalDataWrapper> settingsList, boolean nightMode, boolean importState) {
this.app = app;
this.settingsList = settingsList;
this.nightMode = nightMode;
this.importState = importState;
this.settingsToOperate = new ArrayList<>();
}
public void updateSettingsList(List<AdditionalDataWrapper> settingsList) {
this.settingsList = settingsList;
notifyDataSetChanged();
}
public List<? super Object> getSettingsToOperate() {
return this.settingsToOperate;
}
public void selectAll(boolean selectAll) {
settingsToOperate.clear();
if (selectAll) {
for (AdditionalDataWrapper item : settingsList) {
settingsToOperate.addAll(item.getItems());
}
}
notifyDataSetChanged();
}
@Override
public int getGroupCount() {
return settingsList.size();
}
@Override
public int getChildrenCount(int i) {
return settingsList.get(i).getItems().size();
}
@Override
public Object getGroup(int i) {
return settingsList.get(i);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return settingsList.get(groupPosition).getItems().get(childPosition);
}
@Override
public long getGroupId(int i) {
return i;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return groupPosition * 10000 + childPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View group = convertView;
if (group == null) {
// LayoutInflater inflater = UiUtilities.getInflater(app, nightMode);
LayoutInflater inflater = LayoutInflater.from(app);
group = inflater.inflate(R.layout.profile_data_list_item_group, parent, false);
}
boolean isLastGroup = groupPosition == getGroupCount() - 1;
final AdditionalDataWrapper.Type type = settingsList.get(groupPosition).getType();
TextView titleTv = group.findViewById(R.id.title_tv);
TextView subTextTv = group.findViewById(R.id.sub_text_tv);
final CheckBox checkBox = group.findViewById(R.id.check_box);
ImageView expandIv = group.findViewById(R.id.explist_indicator);
View divider = group.findViewById(R.id.divider);
View cardTopDivider = group.findViewById(R.id.card_top_divider);
View cardBottomDivider = group.findViewById(R.id.card_bottom_divider);
titleTv.setText(getGroupTitle(type));
cardTopDivider.setVisibility(importState ? View.VISIBLE : View.GONE);
if (importState) {
cardBottomDivider.setVisibility(isExpanded ? View.GONE : View.VISIBLE);
divider.setVisibility(View.GONE);
} else {
cardBottomDivider.setVisibility(View.GONE);
divider.setVisibility(isExpanded || isLastGroup ? View.GONE : View.VISIBLE);
}
// CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(ContextCompat.getColor(app, profileColor)));
final List<?> listItems = settingsList.get(groupPosition).getItems();
subTextTv.setText(String.valueOf(listItems.size()));
checkBox.setChecked(settingsToOperate.containsAll(listItems));
checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (checkBox.isChecked()) {
for (Object object : listItems) {
if (!settingsToOperate.contains(object)) {
settingsToOperate.add(object);
}
}
} else {
settingsToOperate.removeAll(listItems);
}
notifyDataSetInvalidated();
}
});
adjustIndicator(app, groupPosition, isExpanded, group, true);
return group;
}
@Override
public View getChildView(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
View child = convertView;
if (child == null) {
// LayoutInflater inflater = UiUtilities.getInflater(app, nightMode);
LayoutInflater inflater = LayoutInflater.from(app);
child = inflater.inflate(R.layout.profile_data_list_item_child, parent, false);
}
final Object currentItem = settingsList.get(groupPosition).getItems().get(childPosition);
boolean isLastGroup = groupPosition == getGroupCount() - 1;
final AdditionalDataWrapper.Type type = settingsList.get(groupPosition).getType();
TextView title = child.findViewById(R.id.title_tv);
// TextView subText = child.findViewById(R.id.sub_text_tv);
final CheckBox checkBox = child.findViewById(R.id.check_box);
ImageView icon = child.findViewById(R.id.icon);
View divider = child.findViewById(R.id.divider);
View cardBottomDivider = child.findViewById(R.id.card_bottom_divider);
divider.setVisibility(isLastChild && !isLastGroup && !importState ? View.VISIBLE : View.GONE);
cardBottomDivider.setVisibility(isLastChild && importState ? View.VISIBLE : View.GONE);
// CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(ContextCompat.getColor(app, profileColor)));
checkBox.setChecked(settingsToOperate.contains(currentItem));
checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (checkBox.isChecked()) {
settingsToOperate.add(currentItem);
} else {
settingsToOperate.remove(currentItem);
}
notifyDataSetInvalidated();
}
});
switch (type) {
case PROFILE:
title.setText(((ApplicationMode) currentItem).toHumanString());
// subText.setText(((ApplicationMode) currentItem));
icon.setVisibility(View.INVISIBLE);
icon.setImageResource(((ApplicationMode) currentItem).getIconRes());
break;
case QUICK_ACTIONS:
title.setText(((QuickAction) currentItem).getName(app.getApplicationContext()));
icon.setVisibility(View.INVISIBLE);
icon.setImageResource(R.drawable.ic_action_info_dark);
break;
case POI_TYPES:
title.setText(((PoiUIFilter) currentItem).getName());
icon.setVisibility(View.VISIBLE);
int iconRes = RenderingIcons.getBigIconResourceId(((PoiUIFilter) currentItem).getIconId());
// icon.setImageDrawable(app.getUIUtilities().getIcon(iconRes != 0 ? iconRes : R.drawable.ic_person, profileColor));
break;
case MAP_SOURCES:
title.setText(((ITileSource) currentItem).getName());
icon.setVisibility(View.INVISIBLE);
icon.setImageResource(R.drawable.ic_action_info_dark);
break;
case CUSTOM_RENDER_STYLE:
String renderName = ((File) currentItem).getName();
renderName = renderName.replace('_', ' ').replaceAll(".render.xml", "");
title.setText(renderName);
icon.setVisibility(View.INVISIBLE);
icon.setImageResource(R.drawable.ic_action_info_dark);
break;
case CUSTOM_ROUTING:
String routingName = ((File) currentItem).getName();
routingName = routingName.replace('_', ' ').replaceAll(".xml", "");
title.setText(routingName);
icon.setVisibility(View.INVISIBLE);
icon.setImageResource(R.drawable.ic_action_info_dark);
break;
default:
return child;
}
return child;
}
@Override
public boolean isChildSelectable(int i, int i1) {
return false;
}
private int getGroupTitle(AdditionalDataWrapper.Type type) {
switch (type) {
case PROFILE:
return R.string.shared_sting_profiles;
case QUICK_ACTIONS:
return R.string.configure_screen_quick_action;
case POI_TYPES:
return R.string.poi_dialog_poi_type;
case MAP_SOURCES:
return R.string.quick_action_map_source_title;
case CUSTOM_RENDER_STYLE:
return R.string.shared_string_custom_rendering_style;
case CUSTOM_ROUTING:
return R.string.shared_string_routing;
default:
return R.string.access_empty_list;
}
}
}

View file

@ -4,31 +4,52 @@ import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.SettingsHelper;
import net.osmand.plus.SettingsHelper.SettingsItem;
import net.osmand.plus.base.BaseOsmAndDialogFragment;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.view.ComplexButton;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implements View.OnClickListener {
public static final String TAG = ImportSettingsFragment.class.getSimpleName();
private OsmandApplication app;
private RecyclerView list;
private List<? super Object> duplicatesList;
private List<SettingsItem> settingsItems;
private DuplicatesSettingsAdapter adapter;
private File file;
public static void showInstance(@NonNull FragmentManager fm) {
public static void showInstance(@NonNull FragmentManager fm, List<? super Object> duplicatesList,
List<SettingsItem> settingsItems, File file) {
ImportDuplicatesFragment fragment = new ImportDuplicatesFragment();
fragment.setDuplicatesList(duplicatesList);
fragment.setSettingsItems(settingsItems);
fragment.setFile(file);
fragment.show(fm, TAG);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
app = getMyApplication();
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@ -53,30 +74,68 @@ public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implement
return root;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
adapter = new DuplicatesSettingsAdapter(getMyApplication(), prepareDuplicates(), getSettings().isLightContent());
list.setLayoutManager(new LinearLayoutManager(getMyApplication()));
list.setAdapter(adapter);
}
private List<Object> prepareDuplicates() {
List<Object> duplicates = new ArrayList<>();
List<ApplicationMode> profiles = new ArrayList<>();
List<QuickAction> actions = new ArrayList<>();
for (Object object : duplicatesList) {
if (object instanceof ApplicationMode) {
profiles.add((ApplicationMode) object);
} else if (object instanceof QuickAction) {
actions.add((QuickAction) object);
}
}
if (!profiles.isEmpty()) {
duplicates.add(getString(R.string.shared_sting_profiles));
duplicates.addAll(profiles);
}
if (!actions.isEmpty()) {
duplicates.add(getString(R.string.shared_sting_quick_actions));
duplicates.addAll(actions);
}
return duplicates;
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.keep_both_btn: {
keepBothItems();
importItems(false);
break;
}
case R.id.replace_all_btn: {
replaceAllItems();
importItems(true);
break;
}
}
}
private void keepBothItems() {
}
private void replaceAllItems() {
}
private void importItems(List<SettingsItem> list) {
private void importItems(boolean shouldReplace) {
for (SettingsItem item : settingsItems) {
item.setShouldReplace(shouldReplace);
}
app.getSettingsHelper().importSettings(file, settingsItems, "", 1, new SettingsHelper.SettingsImportListener() {
@Override
public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
if (succeed) {
app.showShortToastMessage(app.getString(R.string.file_imported_successfully, file.getName()));
} else if (empty) {
app.showShortToastMessage(app.getString(R.string.file_import_error, file.getName(), app.getString(R.string.shared_string_unexpected_error)));
}
}
});
dismiss();
}
private void setupToolbar(Toolbar toolbar) {
@ -92,4 +151,16 @@ public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implement
}
});
}
public void setDuplicatesList(List<? super Object> duplicatesList) {
this.duplicatesList = duplicatesList;
}
public void setSettingsItems(List<SettingsItem> settingsItems) {
this.settingsItems = settingsItems;
}
public void setFile(File file) {
this.file = file;
}
}

File diff suppressed because one or more lines are too long