complete settings screen
This commit is contained in:
parent
d64684fbff
commit
9a6c9d111d
5 changed files with 147 additions and 50 deletions
|
@ -80,7 +80,7 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="?attr/selectableItemBackground"
|
android:background="?attr/selectableItemBackground"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:gravity="end|center_vertical"
|
android:gravity="start|center_vertical"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:paddingLeft="@dimen/content_padding_small"
|
android:paddingLeft="@dimen/content_padding_small"
|
||||||
android:paddingTop="@dimen/content_padding_half"
|
android:paddingTop="@dimen/content_padding_half"
|
||||||
|
@ -110,6 +110,8 @@
|
||||||
android:layout_height="@dimen/toolbar_height_expanded"
|
android:layout_height="@dimen/toolbar_height_expanded"
|
||||||
android:background="?attr/colorPrimary"
|
android:background="?attr/colorPrimary"
|
||||||
osmand:collapsedTitleTextAppearance="@style/AppBarTitle"
|
osmand:collapsedTitleTextAppearance="@style/AppBarTitle"
|
||||||
|
osmand:expandedTitleMarginStart="16dp"
|
||||||
|
osmand:expandedTitleMarginBottom="12dp"
|
||||||
osmand:expandedTitleGravity="start|bottom"
|
osmand:expandedTitleGravity="start|bottom"
|
||||||
osmand:expandedTitleTextAppearance="@style/AppBarTitle"
|
osmand:expandedTitleTextAppearance="@style/AppBarTitle"
|
||||||
tools:title="@string/shared_string_import"
|
tools:title="@string/shared_string_import"
|
||||||
|
@ -121,7 +123,8 @@
|
||||||
android:layout_height="@dimen/toolbar_height"
|
android:layout_height="@dimen/toolbar_height"
|
||||||
android:minHeight="@dimen/toolbar_height"
|
android:minHeight="@dimen/toolbar_height"
|
||||||
osmand:layout_collapseMode="pin"
|
osmand:layout_collapseMode="pin"
|
||||||
osmand:layout_scrollFlags="scroll|enterAlways|exitUntilCollapsed">
|
osmand:layout_scrollFlags="scroll|enterAlways|exitUntilCollapsed"
|
||||||
|
android:layout_marginLeft="0dp">
|
||||||
|
|
||||||
</android.support.v7.widget.Toolbar>
|
</android.support.v7.widget.Toolbar>
|
||||||
|
|
||||||
|
|
|
@ -319,7 +319,7 @@
|
||||||
<dimen name="coords_input_keyboard_item_height">56dp</dimen>
|
<dimen name="coords_input_keyboard_item_height">56dp</dimen>
|
||||||
|
|
||||||
<dimen name="toolbar_height">56dp</dimen>
|
<dimen name="toolbar_height">56dp</dimen>
|
||||||
<dimen name="toolbar_height_expanded">112dp</dimen>
|
<dimen name="toolbar_height_expanded">96dp</dimen>
|
||||||
|
|
||||||
<dimen name="wikivoyage_search_list_header_height">36dp</dimen>
|
<dimen name="wikivoyage_search_list_header_height">36dp</dimen>
|
||||||
<dimen name="wikivoyage_article_card_icon_size">80dp</dimen>
|
<dimen name="wikivoyage_article_card_icon_size">80dp</dimen>
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.os.AsyncTask;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
|
import android.text.style.AlignmentSpan;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
@ -113,6 +114,10 @@ public class SettingsHelper {
|
||||||
void onSettingsExportFinished(@NonNull File file, boolean succeed);
|
void onSettingsExportFinished(@NonNull File file, boolean succeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface CheckDuplicatesListener {
|
||||||
|
void onDuplicatesChecked(@NonNull List<Object> duplicates, List<SettingsItem> items);
|
||||||
|
}
|
||||||
|
|
||||||
public SettingsHelper(OsmandApplication app) {
|
public SettingsHelper(OsmandApplication app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
}
|
}
|
||||||
|
@ -2044,6 +2049,88 @@ public class SettingsHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("StaticFieldLeak")
|
||||||
|
public class CheckDuplicateTask extends AsyncTask<Void, Void, List<Object>> {
|
||||||
|
|
||||||
|
private List<SettingsItem> items;
|
||||||
|
private List<Object> duplicates;
|
||||||
|
private CheckDuplicatesListener listener;
|
||||||
|
private long startTime;
|
||||||
|
|
||||||
|
CheckDuplicateTask(@NonNull List<SettingsItem> items, CheckDuplicatesListener listener) {
|
||||||
|
this.items = items;
|
||||||
|
this.listener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
startTime = System.currentTimeMillis();
|
||||||
|
super.onPreExecute();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<Object> doInBackground(Void... voids) {
|
||||||
|
return getDuplicatesData(this.items);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(List<Object> objects) {
|
||||||
|
duplicates = objects;
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
|
if (currentTime - startTime < 700) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(500);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (listener != null) {
|
||||||
|
listener.onDuplicatesChecked(objects, this.items);
|
||||||
|
}
|
||||||
|
super.onPostExecute(objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Object> getDuplicatesData(List<SettingsItem> items) {
|
||||||
|
List<Object> duplicateItems = new ArrayList<>();
|
||||||
|
for (SettingsItem item : items) {
|
||||||
|
if (item instanceof SettingsHelper.ProfileSettingsItem) {
|
||||||
|
if (item.exists()) {
|
||||||
|
duplicateItems.add(((SettingsHelper.ProfileSettingsItem) item).getModeBean());
|
||||||
|
}
|
||||||
|
} else if (item instanceof SettingsHelper.QuickActionSettingsItem) {
|
||||||
|
List<QuickAction> duplicates = ((SettingsHelper.QuickActionSettingsItem) item).excludeDuplicateItems();
|
||||||
|
if (!duplicates.isEmpty()) {
|
||||||
|
duplicateItems.addAll(duplicates);
|
||||||
|
}
|
||||||
|
} else if (item instanceof SettingsHelper.PoiUiFilterSettingsItem) {
|
||||||
|
List<PoiUIFilter> duplicates = ((SettingsHelper.PoiUiFilterSettingsItem) item).excludeDuplicateItems();
|
||||||
|
if (!duplicates.isEmpty()) {
|
||||||
|
duplicateItems.addAll(duplicates);
|
||||||
|
}
|
||||||
|
} else if (item instanceof SettingsHelper.MapSourcesSettingsItem) {
|
||||||
|
List<ITileSource> duplicates = ((SettingsHelper.MapSourcesSettingsItem) item).excludeDuplicateItems();
|
||||||
|
if (!duplicates.isEmpty()) {
|
||||||
|
duplicateItems.addAll(duplicates);
|
||||||
|
}
|
||||||
|
} else if (item instanceof SettingsHelper.FileSettingsItem) {
|
||||||
|
if (item.exists()) {
|
||||||
|
duplicateItems.add(((SettingsHelper.FileSettingsItem) item).getFile());
|
||||||
|
}
|
||||||
|
} else if (item instanceof SettingsHelper.AvoidRoadsSettingsItem) {
|
||||||
|
List<AvoidRoadInfo> avoidRoads = ((SettingsHelper.AvoidRoadsSettingsItem) item).excludeDuplicateItems();
|
||||||
|
if (!avoidRoads.isEmpty()) {
|
||||||
|
duplicateItems.addAll(avoidRoads);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return duplicateItems;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkDuplicates(@NonNull List<SettingsItem> items, CheckDuplicatesListener listener) {
|
||||||
|
new CheckDuplicateTask(items, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
}
|
||||||
|
|
||||||
public void importSettings(@NonNull File settingsFile, String latestChanges, int version,
|
public void importSettings(@NonNull File settingsFile, String latestChanges, int version,
|
||||||
boolean askBeforeImport, @Nullable SettingsImportListener listener) {
|
boolean askBeforeImport, @Nullable SettingsImportListener listener) {
|
||||||
new ImportAsyncTask(settingsFile, latestChanges, version, askBeforeImport, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
new ImportAsyncTask(settingsFile, latestChanges, version, askBeforeImport, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.osmand.plus.settings;
|
package net.osmand.plus.settings;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -22,7 +23,10 @@ import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.SettingsHelper.SettingsItem;
|
import net.osmand.plus.SettingsHelper.SettingsItem;
|
||||||
import net.osmand.plus.UiUtilities;
|
import net.osmand.plus.UiUtilities;
|
||||||
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||||
|
import net.osmand.plus.dashboard.DashboardOnMap;
|
||||||
|
import net.osmand.plus.dialogs.ConfigureMapMenu;
|
||||||
import net.osmand.plus.dialogs.SelectMapStyleBottomSheetDialogFragment;
|
import net.osmand.plus.dialogs.SelectMapStyleBottomSheetDialogFragment;
|
||||||
import net.osmand.plus.profiles.AdditionalDataWrapper;
|
import net.osmand.plus.profiles.AdditionalDataWrapper;
|
||||||
import net.osmand.plus.quickaction.QuickActionListFragment;
|
import net.osmand.plus.quickaction.QuickActionListFragment;
|
||||||
|
@ -131,43 +135,43 @@ public class ImportCompleteFragment extends BaseOsmAndFragment {
|
||||||
if (fm == null) {
|
if (fm == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Fragment fragment;
|
|
||||||
String TAG;
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case CUSTOM_ROUTING:
|
||||||
case PROFILE:
|
case PROFILE:
|
||||||
BaseSettingsFragment.showInstance(
|
BaseSettingsFragment.showInstance(
|
||||||
getActivity(),
|
requireActivity(),
|
||||||
BaseSettingsFragment.SettingsScreenType.MAIN_SETTINGS
|
BaseSettingsFragment.SettingsScreenType.MAIN_SETTINGS
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case QUICK_ACTIONS:
|
case QUICK_ACTIONS:
|
||||||
fm.beginTransaction()
|
fm.beginTransaction()
|
||||||
.add(R.id.fragmentContainer, new QuickActionListFragment(), QuickActionListFragment.TAG)
|
.add(R.id.fragmentContainer, new QuickActionListFragment(), QuickActionListFragment.TAG)
|
||||||
.addToBackStack(QuickActionListFragment.TAG).commitAllowingStateLoss();
|
.addToBackStack(QuickActionListFragment.TAG).commit();
|
||||||
break;
|
break;
|
||||||
case POI_TYPES:
|
case POI_TYPES:
|
||||||
QuickSearchDialogFragment quickSearchDialogFragment = new QuickSearchDialogFragment();
|
new QuickSearchDialogFragment().show(fm, QuickSearchDialogFragment.TAG);
|
||||||
quickSearchDialogFragment.show(fm, QuickSearchDialogFragment.TAG);
|
|
||||||
break;
|
break;
|
||||||
case MAP_SOURCES:
|
case MAP_SOURCES:
|
||||||
|
Activity activity = getActivity();
|
||||||
|
if (activity instanceof MapActivity) {
|
||||||
|
((MapActivity) activity).getDashboard()
|
||||||
|
.setDashboardVisibility(
|
||||||
|
true,
|
||||||
|
DashboardOnMap.DashboardType.CONFIGURE_MAP,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case CUSTOM_RENDER_STYLE:
|
case CUSTOM_RENDER_STYLE:
|
||||||
|
new SelectMapStyleBottomSheetDialogFragment().show(fm, SelectMapStyleBottomSheetDialogFragment.TAG);
|
||||||
fragment = new SelectMapStyleBottomSheetDialogFragment();
|
|
||||||
TAG = SelectMapStyleBottomSheetDialogFragment.TAG;
|
|
||||||
break;
|
break;
|
||||||
case CUSTOM_ROUTING:
|
|
||||||
|
|
||||||
return;
|
|
||||||
case AVOID_ROADS:
|
case AVOID_ROADS:
|
||||||
fragment = new AvoidRoadsBottomSheetDialogFragment();
|
new AvoidRoadsBottomSheetDialogFragment().show(fm, AvoidRoadsBottomSheetDialogFragment.TAG);
|
||||||
TAG = AvoidRoadsBottomSheetDialogFragment.TAG;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dismissFragment();
|
// dismissFragment();
|
||||||
app.getSettingsHelper().setImportedItems(null);
|
app.getSettingsHelper().setImportedItems(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,12 +54,11 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
|
||||||
private ExportImportSettingsAdapter adapter;
|
private ExportImportSettingsAdapter adapter;
|
||||||
private ExpandableListView expandableList;
|
private ExpandableListView expandableList;
|
||||||
private TextViewEx selectBtn;
|
private TextViewEx selectBtn;
|
||||||
|
private TextView description;
|
||||||
private List<SettingsItem> settingsItems;
|
private List<SettingsItem> settingsItems;
|
||||||
private File file;
|
private File file;
|
||||||
private boolean allSelected;
|
private boolean allSelected;
|
||||||
private boolean nightMode;
|
private boolean nightMode;
|
||||||
private Toolbar toolbar;
|
|
||||||
private TextView description;
|
|
||||||
private String fileName;
|
private String fileName;
|
||||||
private LinearLayout buttonsContainer;
|
private LinearLayout buttonsContainer;
|
||||||
private ProgressBar progressBar;
|
private ProgressBar progressBar;
|
||||||
|
@ -93,7 +92,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
inflater = UiUtilities.getInflater(app, nightMode);
|
inflater = UiUtilities.getInflater(app, nightMode);
|
||||||
View root = inflater.inflate(R.layout.fragment_import, container, false);
|
View root = inflater.inflate(R.layout.fragment_import, container, false);
|
||||||
toolbar = root.findViewById(R.id.toolbar);
|
Toolbar toolbar = root.findViewById(R.id.toolbar);
|
||||||
toolbarLayout = root.findViewById(R.id.toolbar_layout);
|
toolbarLayout = root.findViewById(R.id.toolbar_layout);
|
||||||
setupToolbar(toolbar);
|
setupToolbar(toolbar);
|
||||||
TextViewEx continueBtn = root.findViewById(R.id.continue_button);
|
TextViewEx continueBtn = root.findViewById(R.id.continue_button);
|
||||||
|
@ -101,7 +100,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
|
||||||
expandableList = root.findViewById(R.id.list);
|
expandableList = root.findViewById(R.id.list);
|
||||||
ViewCompat.setNestedScrollingEnabled(expandableList, true);
|
ViewCompat.setNestedScrollingEnabled(expandableList, true);
|
||||||
View header = inflater.inflate(R.layout.list_item_description_header, null);
|
View header = inflater.inflate(R.layout.list_item_description_header, null);
|
||||||
TextView description = header.findViewById(R.id.description);
|
description = header.findViewById(R.id.description);
|
||||||
description.setText(R.string.select_data_to_import);
|
description.setText(R.string.select_data_to_import);
|
||||||
expandableList.addHeaderView(header);
|
expandableList.addHeaderView(header);
|
||||||
continueBtn.setOnClickListener(this);
|
continueBtn.setOnClickListener(this);
|
||||||
|
@ -154,15 +153,17 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
|
||||||
adapter.clearSettingsList();
|
adapter.clearSettingsList();
|
||||||
final FragmentManager fm = getFragmentManager();
|
final FragmentManager fm = getFragmentManager();
|
||||||
List<SettingsItem> settingsItems = getSettingsItemsFromData(adapter.getDataToOperate());
|
List<SettingsItem> settingsItems = getSettingsItemsFromData(adapter.getDataToOperate());
|
||||||
List<Object> duplicateItems = getDuplicatesData(settingsItems);
|
app.getSettingsHelper().checkDuplicates(settingsItems, new SettingsHelper.CheckDuplicatesListener() {
|
||||||
if (duplicateItems.isEmpty()) {
|
@Override
|
||||||
|
public void onDuplicatesChecked(@NonNull List<Object> duplicates, List<SettingsItem> items) {
|
||||||
|
if (duplicates.isEmpty()) {
|
||||||
toolbarLayout.setTitle(getString(R.string.shared_string_importing));
|
toolbarLayout.setTitle(getString(R.string.shared_string_importing));
|
||||||
description.setText(UiUtilities.createSpannableString(
|
description.setText(UiUtilities.createSpannableString(
|
||||||
String.format(getString(R.string.importing_from), file.getName()),
|
String.format(getString(R.string.importing_from), file.getName()),
|
||||||
file.getName(),
|
file.getName(),
|
||||||
new StyleSpan(Typeface.BOLD)
|
new StyleSpan(Typeface.BOLD)
|
||||||
));
|
));
|
||||||
app.getSettingsHelper().importSettings(file, settingsItems, "", 1, new SettingsHelper.SettingsImportListener() {
|
app.getSettingsHelper().importSettings(file, items, "", 1, new SettingsHelper.SettingsImportListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
|
public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
|
||||||
if (succeed) {
|
if (succeed) {
|
||||||
|
@ -183,10 +184,12 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (fm != null) {
|
if (fm != null) {
|
||||||
ImportDuplicatesFragment.showInstance(fm, duplicateItems, settingsItems, file);
|
ImportDuplicatesFragment.showInstance(fm, duplicates, items, file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void dismissFragment() {
|
private void dismissFragment() {
|
||||||
FragmentManager fm = getFragmentManager();
|
FragmentManager fm = getFragmentManager();
|
||||||
|
|
Loading…
Reference in a new issue