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:background="?attr/selectableItemBackground"
|
||||
android:ellipsize="end"
|
||||
android:gravity="end|center_vertical"
|
||||
android:gravity="start|center_vertical"
|
||||
android:maxLines="1"
|
||||
android:paddingLeft="@dimen/content_padding_small"
|
||||
android:paddingTop="@dimen/content_padding_half"
|
||||
|
@ -110,6 +110,8 @@
|
|||
android:layout_height="@dimen/toolbar_height_expanded"
|
||||
android:background="?attr/colorPrimary"
|
||||
osmand:collapsedTitleTextAppearance="@style/AppBarTitle"
|
||||
osmand:expandedTitleMarginStart="16dp"
|
||||
osmand:expandedTitleMarginBottom="12dp"
|
||||
osmand:expandedTitleGravity="start|bottom"
|
||||
osmand:expandedTitleTextAppearance="@style/AppBarTitle"
|
||||
tools:title="@string/shared_string_import"
|
||||
|
@ -121,7 +123,8 @@
|
|||
android:layout_height="@dimen/toolbar_height"
|
||||
android:minHeight="@dimen/toolbar_height"
|
||||
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>
|
||||
|
||||
|
|
|
@ -319,7 +319,7 @@
|
|||
<dimen name="coords_input_keyboard_item_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_article_card_icon_size">80dp</dimen>
|
||||
|
|
|
@ -8,6 +8,7 @@ import android.os.AsyncTask;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.style.AlignmentSpan;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
@ -113,6 +114,10 @@ public class SettingsHelper {
|
|||
void onSettingsExportFinished(@NonNull File file, boolean succeed);
|
||||
}
|
||||
|
||||
public interface CheckDuplicatesListener {
|
||||
void onDuplicatesChecked(@NonNull List<Object> duplicates, List<SettingsItem> items);
|
||||
}
|
||||
|
||||
public SettingsHelper(OsmandApplication 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,
|
||||
boolean askBeforeImport, @Nullable SettingsImportListener listener) {
|
||||
new ImportAsyncTask(settingsFile, latestChanges, version, askBeforeImport, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus.settings;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
@ -22,7 +23,10 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.SettingsHelper.SettingsItem;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
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.profiles.AdditionalDataWrapper;
|
||||
import net.osmand.plus.quickaction.QuickActionListFragment;
|
||||
|
@ -131,43 +135,43 @@ public class ImportCompleteFragment extends BaseOsmAndFragment {
|
|||
if (fm == null) {
|
||||
return;
|
||||
}
|
||||
Fragment fragment;
|
||||
String TAG;
|
||||
switch (type) {
|
||||
case CUSTOM_ROUTING:
|
||||
case PROFILE:
|
||||
BaseSettingsFragment.showInstance(
|
||||
getActivity(),
|
||||
requireActivity(),
|
||||
BaseSettingsFragment.SettingsScreenType.MAIN_SETTINGS
|
||||
);
|
||||
break;
|
||||
case QUICK_ACTIONS:
|
||||
fm.beginTransaction()
|
||||
.add(R.id.fragmentContainer, new QuickActionListFragment(), QuickActionListFragment.TAG)
|
||||
.addToBackStack(QuickActionListFragment.TAG).commitAllowingStateLoss();
|
||||
.addToBackStack(QuickActionListFragment.TAG).commit();
|
||||
break;
|
||||
case POI_TYPES:
|
||||
QuickSearchDialogFragment quickSearchDialogFragment = new QuickSearchDialogFragment();
|
||||
quickSearchDialogFragment.show(fm, QuickSearchDialogFragment.TAG);
|
||||
new QuickSearchDialogFragment().show(fm, QuickSearchDialogFragment.TAG);
|
||||
break;
|
||||
case MAP_SOURCES:
|
||||
|
||||
Activity activity = getActivity();
|
||||
if (activity instanceof MapActivity) {
|
||||
((MapActivity) activity).getDashboard()
|
||||
.setDashboardVisibility(
|
||||
true,
|
||||
DashboardOnMap.DashboardType.CONFIGURE_MAP,
|
||||
null
|
||||
);
|
||||
}
|
||||
break;
|
||||
case CUSTOM_RENDER_STYLE:
|
||||
|
||||
fragment = new SelectMapStyleBottomSheetDialogFragment();
|
||||
TAG = SelectMapStyleBottomSheetDialogFragment.TAG;
|
||||
new SelectMapStyleBottomSheetDialogFragment().show(fm, SelectMapStyleBottomSheetDialogFragment.TAG);
|
||||
break;
|
||||
case CUSTOM_ROUTING:
|
||||
|
||||
return;
|
||||
case AVOID_ROADS:
|
||||
fragment = new AvoidRoadsBottomSheetDialogFragment();
|
||||
TAG = AvoidRoadsBottomSheetDialogFragment.TAG;
|
||||
new AvoidRoadsBottomSheetDialogFragment().show(fm, AvoidRoadsBottomSheetDialogFragment.TAG);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
dismissFragment();
|
||||
// dismissFragment();
|
||||
app.getSettingsHelper().setImportedItems(null);
|
||||
}
|
||||
|
||||
|
|
|
@ -54,12 +54,11 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
|
|||
private ExportImportSettingsAdapter adapter;
|
||||
private ExpandableListView expandableList;
|
||||
private TextViewEx selectBtn;
|
||||
private TextView description;
|
||||
private List<SettingsItem> settingsItems;
|
||||
private File file;
|
||||
private boolean allSelected;
|
||||
private boolean nightMode;
|
||||
private Toolbar toolbar;
|
||||
private TextView description;
|
||||
private String fileName;
|
||||
private LinearLayout buttonsContainer;
|
||||
private ProgressBar progressBar;
|
||||
|
@ -93,7 +92,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
|
|||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
inflater = UiUtilities.getInflater(app, nightMode);
|
||||
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);
|
||||
setupToolbar(toolbar);
|
||||
TextViewEx continueBtn = root.findViewById(R.id.continue_button);
|
||||
|
@ -101,7 +100,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
|
|||
expandableList = root.findViewById(R.id.list);
|
||||
ViewCompat.setNestedScrollingEnabled(expandableList, true);
|
||||
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);
|
||||
expandableList.addHeaderView(header);
|
||||
continueBtn.setOnClickListener(this);
|
||||
|
@ -154,38 +153,42 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
|
|||
adapter.clearSettingsList();
|
||||
final FragmentManager fm = getFragmentManager();
|
||||
List<SettingsItem> settingsItems = getSettingsItemsFromData(adapter.getDataToOperate());
|
||||
List<Object> duplicateItems = getDuplicatesData(settingsItems);
|
||||
if (duplicateItems.isEmpty()) {
|
||||
toolbarLayout.setTitle(getString(R.string.shared_string_importing));
|
||||
description.setText(UiUtilities.createSpannableString(
|
||||
String.format(getString(R.string.importing_from), file.getName()),
|
||||
file.getName(),
|
||||
new StyleSpan(Typeface.BOLD)
|
||||
));
|
||||
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.getRendererRegistry().updateExternalRenderers();
|
||||
AppInitializer.loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() {
|
||||
@Override
|
||||
public void onRoutingFilesLoaded() {
|
||||
app.getSettingsHelper().checkDuplicates(settingsItems, new SettingsHelper.CheckDuplicatesListener() {
|
||||
@Override
|
||||
public void onDuplicatesChecked(@NonNull List<Object> duplicates, List<SettingsItem> items) {
|
||||
if (duplicates.isEmpty()) {
|
||||
toolbarLayout.setTitle(getString(R.string.shared_string_importing));
|
||||
description.setText(UiUtilities.createSpannableString(
|
||||
String.format(getString(R.string.importing_from), file.getName()),
|
||||
file.getName(),
|
||||
new StyleSpan(Typeface.BOLD)
|
||||
));
|
||||
app.getSettingsHelper().importSettings(file, items, "", 1, new SettingsHelper.SettingsImportListener() {
|
||||
@Override
|
||||
public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
|
||||
if (succeed) {
|
||||
app.getRendererRegistry().updateExternalRenderers();
|
||||
AppInitializer.loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() {
|
||||
@Override
|
||||
public void onRoutingFilesLoaded() {
|
||||
}
|
||||
});
|
||||
if (fm != null) {
|
||||
ImportCompleteFragment.showInstance(fm, items, file.getName());
|
||||
}
|
||||
} else if (empty) {
|
||||
app.showShortToastMessage(app.getString(R.string.file_import_error, file.getName(), app.getString(R.string.shared_string_unexpected_error)));
|
||||
dismissFragment();
|
||||
}
|
||||
});
|
||||
if (fm != null) {
|
||||
ImportCompleteFragment.showInstance(fm, items, file.getName());
|
||||
}
|
||||
} else if (empty) {
|
||||
app.showShortToastMessage(app.getString(R.string.file_import_error, file.getName(), app.getString(R.string.shared_string_unexpected_error)));
|
||||
dismissFragment();
|
||||
});
|
||||
} else {
|
||||
if (fm != null) {
|
||||
ImportDuplicatesFragment.showInstance(fm, duplicates, items, file);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (fm != null) {
|
||||
ImportDuplicatesFragment.showInstance(fm, duplicateItems, settingsItems, file);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void dismissFragment() {
|
||||
|
|
Loading…
Reference in a new issue