Refactoring

This commit is contained in:
Dima-1 2020-10-31 15:37:26 +02:00
parent e9a1bad5ab
commit cd250108ae
5 changed files with 53 additions and 75 deletions

View file

@ -45,7 +45,7 @@ public class FileSettingsItem extends StreamSettingsItem {
} }
public boolean isMap() { 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() { public boolean isDirectory() {

View file

@ -684,10 +684,7 @@ public class SettingsHelper {
multimediaFilesList.add(fileItem.getFile()); multimediaFilesList.add(fileItem.getFile());
} else if (fileItem.getSubtype() == FileSubtype.GPX) { } else if (fileItem.getSubtype() == FileSubtype.GPX) {
tracksFilesList.add(fileItem.getFile()); tracksFilesList.add(fileItem.getFile());
} else if (fileItem.getSubtype() == FileSubtype.OBF_MAP } else if (fileItem.getSubtype().isMap()) {
|| fileItem.getSubtype() == FileSubtype.WIKI_MAP
|| fileItem.getSubtype() == FileSubtype.SRTM_MAP
|| fileItem.getSubtype() == FileSubtype.TILES_MAP) {
mapFilesList.add(fileItem); mapFilesList.add(fileItem);
} else if (fileItem.getSubtype() == FileSubtype.TTS_VOICE) { } else if (fileItem.getSubtype() == FileSubtype.TTS_VOICE) {
ttsVoiceFilesList.add(fileItem.getFile()); ttsVoiceFilesList.add(fileItem.getFile());

View file

@ -303,17 +303,13 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
subText.setVisibility(View.VISIBLE); subText.setVisibility(View.VISIBLE);
break; break;
case TTS_VOICE: 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: case VOICE:
file = (File) currentItem; file = (File) currentItem;
title.setText(FileNameTranslationHelper.getFileName(app, title.setText(FileNameTranslationHelper.getFileName(app,
app.getResourceManager().getOsmandRegions(), app.getResourceManager().getOsmandRegions(),
file.getName())); file.getName()));
setupIcon(icon, R.drawable.ic_action_volume_up, itemSelected); setupIcon(icon, R.drawable.ic_action_volume_up, itemSelected);
break;
default: default:
return child; return child;
} }

View file

@ -17,6 +17,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.core.view.ViewCompat; import androidx.core.view.ViewCompat;
import androidx.core.widget.NestedScrollView; import androidx.core.widget.NestedScrollView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -25,7 +26,6 @@ import com.google.android.material.appbar.CollapsingToolbarLayout;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.map.ITileSource; import net.osmand.map.ITileSource;
import net.osmand.plus.AppInitializer;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; 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;
import net.osmand.plus.settings.backend.backup.SettingsHelper.ImportAsyncTask; 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.ImportType;
import net.osmand.plus.settings.backend.backup.SettingsHelper.SettingsImportListener;
import net.osmand.plus.settings.backend.backup.SettingsItem; import net.osmand.plus.settings.backend.backup.SettingsItem;
import net.osmand.view.ComplexButton; 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; 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(); public static final String TAG = ImportDuplicatesFragment.class.getSimpleName();
private OsmandApplication app; private OsmandApplication app;
@ -68,8 +69,9 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View
private SettingsHelper settingsHelper; private SettingsHelper settingsHelper;
public static void showInstance(@NonNull FragmentManager fm, List<? super Object> duplicatesList, 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(); ImportDuplicatesFragment fragment = new ImportDuplicatesFragment();
fragment.setTargetFragment(targetFragment, 0);
fragment.setDuplicatesList(duplicatesList); fragment.setDuplicatesList(duplicatesList);
fragment.setSettingsItems(settingsItems); fragment.setSettingsItems(settingsItems);
fragment.setFile(file); fragment.setFile(file);
@ -96,7 +98,11 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View
if (file == null) { if (file == null) {
file = importTask.getFile(); 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_dark)
: getResources().getColor(R.color.active_buttons_and_links_text_light)) : getResources().getColor(R.color.active_buttons_and_links_text_light))
); );
keepBothBtn.setOnClickListener(this); keepBothBtn.setOnClickListener(new View.OnClickListener() {
replaceAllBtn.setOnClickListener(this); @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); list = root.findViewById(R.id.list);
ViewCompat.setNestedScrollingEnabled(list, false); ViewCompat.setNestedScrollingEnabled(list, false);
ViewTreeObserver treeObserver = buttonsContainer.getViewTreeObserver(); ViewTreeObserver treeObserver = buttonsContainer.getViewTreeObserver();
@ -242,20 +258,6 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View
return duplicates; 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 @Override
public int getStatusBarColorId() { public int getStatusBarColorId() {
return nightMode ? R.color.status_bar_color_dark : R.color.status_bar_color_light; 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) { for (SettingsItem item : settingsItems) {
item.setShouldReplace(shouldReplace); 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); 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) { private void setupToolbar(Toolbar toolbar) {
toolbar.setTitle(R.string.import_duplicates_title); toolbar.setTitle(R.string.import_duplicates_title);
toolbar.setNavigationIcon(getPaintedContentIcon( toolbar.setNavigationIcon(getPaintedContentIcon(

View file

@ -71,8 +71,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class ImportSettingsFragment extends BaseOsmAndFragment public class ImportSettingsFragment extends BaseOsmAndFragment {
implements View.OnClickListener {
public static final String TAG = ImportSettingsFragment.class.getSimpleName(); public static final String TAG = ImportSettingsFragment.class.getSimpleName();
public static final Log LOG = PlatformUtil.getLog(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); progressBar = root.findViewById(R.id.progress_bar);
setupToolbar(toolbar); setupToolbar(toolbar);
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, container, false);
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(new View.OnClickListener() {
selectBtn.setOnClickListener(this); @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) { if (Build.VERSION.SDK_INT >= 21) {
AndroidUtils.addStatusBarPadding21v(app, root); 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) { private void updateUi(int toolbarTitleRes, int descriptionRes) {
if (file != null) { if (file != null) {
String fileName = file.getName(); 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() { return new SettingsHelper.SettingsImportListener() {
@Override @Override
public void onSettingsImportFinished(boolean succeed, @NonNull List<SettingsItem> items) { public void onSettingsImportFinished(boolean succeed, @NonNull List<SettingsItem> items) {
FragmentManager fm = getFragmentManager();
if (succeed) { if (succeed) {
app.getRendererRegistry().updateExternalRenderers(); app.getRendererRegistry().updateExternalRenderers();
AppInitializer.loadRoutingFiles(app, null); AppInitializer.loadRoutingFiles(app, null);
reloadIndexes(items); reloadIndexes(items);
FragmentManager fm = getFragmentManager();
if (fm != null && file != null) { if (fm != null && file != null) {
ImportCompleteFragment.showInstance(fm, items, file.getName()); ImportCompleteFragment.showInstance(fm, items, file.getName());
} }
@ -348,7 +343,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
} }
settingsHelper.importSettings(file, items, "", 1, getImportListener()); settingsHelper.importSettings(file, items, "", 1, getImportListener());
} else if (fm != null && !isStateSaved()) { } else if (fm != null && !isStateSaved()) {
ImportDuplicatesFragment.showInstance(fm, duplicates, items, file); ImportDuplicatesFragment.showInstance(fm, duplicates, items, file, this);
} }
} }
} }