Refactoring
This commit is contained in:
parent
e9a1bad5ab
commit
cd250108ae
5 changed files with 53 additions and 75 deletions
|
@ -45,7 +45,7 @@ public class FileSettingsItem extends StreamSettingsItem {
|
|||
}
|
||||
|
||||
public boolean isMap() {
|
||||
return this == OBF_MAP || this == WIKI_MAP || this == SRTM_MAP;
|
||||
return this == OBF_MAP || this == WIKI_MAP || this == SRTM_MAP || this == TILES_MAP;
|
||||
}
|
||||
|
||||
public boolean isDirectory() {
|
||||
|
|
|
@ -684,10 +684,7 @@ public class SettingsHelper {
|
|||
multimediaFilesList.add(fileItem.getFile());
|
||||
} else if (fileItem.getSubtype() == FileSubtype.GPX) {
|
||||
tracksFilesList.add(fileItem.getFile());
|
||||
} else if (fileItem.getSubtype() == FileSubtype.OBF_MAP
|
||||
|| fileItem.getSubtype() == FileSubtype.WIKI_MAP
|
||||
|| fileItem.getSubtype() == FileSubtype.SRTM_MAP
|
||||
|| fileItem.getSubtype() == FileSubtype.TILES_MAP) {
|
||||
} else if (fileItem.getSubtype().isMap()) {
|
||||
mapFilesList.add(fileItem);
|
||||
} else if (fileItem.getSubtype() == FileSubtype.TTS_VOICE) {
|
||||
ttsVoiceFilesList.add(fileItem.getFile());
|
||||
|
|
|
@ -303,17 +303,13 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
|
|||
subText.setVisibility(View.VISIBLE);
|
||||
break;
|
||||
case TTS_VOICE:
|
||||
file = (File) currentItem;
|
||||
title.setText(FileNameTranslationHelper.getFileName(app,
|
||||
app.getResourceManager().getOsmandRegions(),
|
||||
file.getName()));
|
||||
setupIcon(icon, R.drawable.ic_action_volume_up, itemSelected);
|
||||
case VOICE:
|
||||
file = (File) currentItem;
|
||||
title.setText(FileNameTranslationHelper.getFileName(app,
|
||||
app.getResourceManager().getOsmandRegions(),
|
||||
file.getName()));
|
||||
setupIcon(icon, R.drawable.ic_action_volume_up, itemSelected);
|
||||
break;
|
||||
default:
|
||||
return child;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import androidx.annotation.Nullable;
|
|||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.widget.NestedScrollView;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
@ -25,7 +26,6 @@ import com.google.android.material.appbar.CollapsingToolbarLayout;
|
|||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.map.ITileSource;
|
||||
import net.osmand.plus.AppInitializer;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
|
@ -37,6 +37,7 @@ import net.osmand.plus.settings.backend.ApplicationMode;
|
|||
import net.osmand.plus.settings.backend.backup.SettingsHelper;
|
||||
import net.osmand.plus.settings.backend.backup.SettingsHelper.ImportAsyncTask;
|
||||
import net.osmand.plus.settings.backend.backup.SettingsHelper.ImportType;
|
||||
import net.osmand.plus.settings.backend.backup.SettingsHelper.SettingsImportListener;
|
||||
import net.osmand.plus.settings.backend.backup.SettingsItem;
|
||||
import net.osmand.view.ComplexButton;
|
||||
|
||||
|
@ -51,7 +52,7 @@ import static net.osmand.IndexConstants.ROUTING_PROFILES_DIR;
|
|||
import static net.osmand.plus.settings.fragments.ImportSettingsFragment.IMPORT_SETTINGS_TAG;
|
||||
|
||||
|
||||
public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View.OnClickListener {
|
||||
public class ImportDuplicatesFragment extends BaseOsmAndFragment {
|
||||
|
||||
public static final String TAG = ImportDuplicatesFragment.class.getSimpleName();
|
||||
private OsmandApplication app;
|
||||
|
@ -68,8 +69,9 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View
|
|||
private SettingsHelper settingsHelper;
|
||||
|
||||
public static void showInstance(@NonNull FragmentManager fm, List<? super Object> duplicatesList,
|
||||
List<SettingsItem> settingsItems, File file) {
|
||||
List<SettingsItem> settingsItems, File file, Fragment targetFragment) {
|
||||
ImportDuplicatesFragment fragment = new ImportDuplicatesFragment();
|
||||
fragment.setTargetFragment(targetFragment, 0);
|
||||
fragment.setDuplicatesList(duplicatesList);
|
||||
fragment.setSettingsItems(settingsItems);
|
||||
fragment.setFile(file);
|
||||
|
@ -96,7 +98,11 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View
|
|||
if (file == null) {
|
||||
file = importTask.getFile();
|
||||
}
|
||||
importTask.setImportListener(getImportListener());
|
||||
Fragment target = getTargetFragment();
|
||||
if (target instanceof ImportSettingsFragment) {
|
||||
SettingsImportListener importListener = ((ImportSettingsFragment) target).getImportListener();
|
||||
importTask.setImportListener(importListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,8 +130,18 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View
|
|||
? getResources().getColor(R.color.active_buttons_and_links_text_dark)
|
||||
: getResources().getColor(R.color.active_buttons_and_links_text_light))
|
||||
);
|
||||
keepBothBtn.setOnClickListener(this);
|
||||
replaceAllBtn.setOnClickListener(this);
|
||||
keepBothBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
importItems(false);
|
||||
}
|
||||
});
|
||||
replaceAllBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
importItems(true);
|
||||
}
|
||||
});
|
||||
list = root.findViewById(R.id.list);
|
||||
ViewCompat.setNestedScrollingEnabled(list, false);
|
||||
ViewTreeObserver treeObserver = buttonsContainer.getViewTreeObserver();
|
||||
|
@ -242,20 +258,6 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View
|
|||
return duplicates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.keep_both_btn: {
|
||||
importItems(false);
|
||||
break;
|
||||
}
|
||||
case R.id.replace_all_btn: {
|
||||
importItems(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStatusBarColorId() {
|
||||
return nightMode ? R.color.status_bar_color_dark : R.color.status_bar_color_light;
|
||||
|
@ -267,7 +269,11 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View
|
|||
for (SettingsItem item : settingsItems) {
|
||||
item.setShouldReplace(shouldReplace);
|
||||
}
|
||||
settingsHelper.importSettings(file, settingsItems, "", 1, getImportListener());
|
||||
Fragment target = getTargetFragment();
|
||||
if (target instanceof ImportSettingsFragment) {
|
||||
SettingsImportListener importListener = ((ImportSettingsFragment) target).getImportListener();
|
||||
settingsHelper.importSettings(file, settingsItems, "", 1, importListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -282,22 +288,6 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View
|
|||
buttonsContainer.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private SettingsHelper.SettingsImportListener getImportListener() {
|
||||
return new SettingsHelper.SettingsImportListener() {
|
||||
@Override
|
||||
public void onSettingsImportFinished(boolean succeed, @NonNull List<SettingsItem> items) {
|
||||
if (succeed) {
|
||||
app.getRendererRegistry().updateExternalRenderers();
|
||||
AppInitializer.loadRoutingFiles(app, null);
|
||||
FragmentManager fm = getFragmentManager();
|
||||
if (fm != null && file != null) {
|
||||
ImportCompleteFragment.showInstance(fm, items, file.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void setupToolbar(Toolbar toolbar) {
|
||||
toolbar.setTitle(R.string.import_duplicates_title);
|
||||
toolbar.setNavigationIcon(getPaintedContentIcon(
|
||||
|
|
|
@ -71,8 +71,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ImportSettingsFragment extends BaseOsmAndFragment
|
||||
implements View.OnClickListener {
|
||||
public class ImportSettingsFragment extends BaseOsmAndFragment {
|
||||
|
||||
public static final String TAG = ImportSettingsFragment.class.getSimpleName();
|
||||
public static final Log LOG = PlatformUtil.getLog(ImportSettingsFragment.class.getSimpleName());
|
||||
|
@ -135,12 +134,28 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
|
|||
progressBar = root.findViewById(R.id.progress_bar);
|
||||
setupToolbar(toolbar);
|
||||
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, container, false);
|
||||
description = header.findViewById(R.id.description);
|
||||
description.setText(R.string.select_data_to_import);
|
||||
expandableList.addHeaderView(header);
|
||||
continueBtn.setOnClickListener(this);
|
||||
selectBtn.setOnClickListener(this);
|
||||
continueBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (adapter.getData().isEmpty()) {
|
||||
app.showShortToastMessage(getString(R.string.shared_string_nothing_selected));
|
||||
} else {
|
||||
importItems();
|
||||
}
|
||||
}
|
||||
});
|
||||
selectBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
allSelected = !allSelected;
|
||||
selectBtn.setText(allSelected ? R.string.shared_string_deselect_all : R.string.shared_string_select_all);
|
||||
adapter.selectAll(allSelected);
|
||||
}
|
||||
});
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
AndroidUtils.addStatusBarPadding21v(app, root);
|
||||
}
|
||||
|
@ -222,26 +237,6 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.select_button: {
|
||||
allSelected = !allSelected;
|
||||
selectBtn.setText(allSelected ? R.string.shared_string_deselect_all : R.string.shared_string_select_all);
|
||||
adapter.selectAll(allSelected);
|
||||
break;
|
||||
}
|
||||
case R.id.continue_button: {
|
||||
if (adapter.getData().isEmpty()) {
|
||||
app.showShortToastMessage(getString(R.string.shared_string_nothing_selected));
|
||||
} else {
|
||||
importItems();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateUi(int toolbarTitleRes, int descriptionRes) {
|
||||
if (file != null) {
|
||||
String fileName = file.getName();
|
||||
|
@ -265,15 +260,15 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
|
|||
}
|
||||
}
|
||||
|
||||
private SettingsHelper.SettingsImportListener getImportListener() {
|
||||
public SettingsHelper.SettingsImportListener getImportListener() {
|
||||
return new SettingsHelper.SettingsImportListener() {
|
||||
@Override
|
||||
public void onSettingsImportFinished(boolean succeed, @NonNull List<SettingsItem> items) {
|
||||
FragmentManager fm = getFragmentManager();
|
||||
if (succeed) {
|
||||
app.getRendererRegistry().updateExternalRenderers();
|
||||
AppInitializer.loadRoutingFiles(app, null);
|
||||
reloadIndexes(items);
|
||||
FragmentManager fm = getFragmentManager();
|
||||
if (fm != null && file != null) {
|
||||
ImportCompleteFragment.showInstance(fm, items, file.getName());
|
||||
}
|
||||
|
@ -348,7 +343,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
|
|||
}
|
||||
settingsHelper.importSettings(file, items, "", 1, getImportListener());
|
||||
} else if (fm != null && !isStateSaved()) {
|
||||
ImportDuplicatesFragment.showInstance(fm, duplicates, items, file);
|
||||
ImportDuplicatesFragment.showInstance(fm, duplicates, items, file, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue