Removed copy-paste code

This commit is contained in:
PaulStets 2018-08-09 11:16:15 +03:00
parent 1eb9b1a87b
commit 87ae02f88c
3 changed files with 27 additions and 64 deletions

View file

@ -52,6 +52,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import static net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu.getVoiceFiles;
public class SettingsNavigationActivity extends SettingsBaseActivity {
public static final String MORE_VALUE = "MORE_VALUE";
@ -244,7 +246,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
private void reloadVoiceListPreference(PreferenceScreen screen) {
String[] entries;
String[] entrieValues;
Set<String> voiceFiles = getVoiceFiles();
Set<String> voiceFiles = getVoiceFiles(this);
entries = new String[voiceFiles.size() + 2];
entrieValues = new String[voiceFiles.size() + 2];
int k = 0;
@ -262,34 +264,6 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
registerListPreference(settings.VOICE_PROVIDER, screen, entries, entrieValues);
}
private Set<String> getVoiceFiles() {
// read available voice data
File extStorage = ((OsmandApplication) getApplication()).getAppPath(IndexConstants.VOICE_INDEX_DIR);
Set<String> setFiles = new LinkedHashSet<String>();
boolean addJS = settings.USE_JS_VOICE_GUIDANCE.get();
if (extStorage.exists()) {
for (File f : extStorage.listFiles()) {
if (f.isDirectory()) {
if (addJS && hasJavaScript(f)) {
setFiles.add(f.getName());
} else if (!addJS) {
setFiles.add(f.getName());
}
}
}
}
return setFiles;
}
private boolean hasJavaScript(File f) {
for (File file : f.listFiles()) {
if (file.getName().endsWith(IndexConstants.TTSVOICE_INDEX_EXT_JS)) {
return true;
}
}
return false;
}
private void addVoicePrefs(PreferenceGroup cat) {
if (!Version.isBlackberry((OsmandApplication) getApplication())) {

View file

@ -40,6 +40,8 @@ import java.util.Set;
import alice.tuprolog.Struct;
import alice.tuprolog.Term;
import static net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu.getVoiceFiles;
/**
* Test Voice activity
@ -84,41 +86,11 @@ public class TestVoiceActivity extends OsmandActionBarActivity {
selectVoice(ll);
}
private Set<String> getVoiceFiles() {
// read available voice data
File extStorage = ((OsmandApplication) getApplication()).getAppPath(IndexConstants.VOICE_INDEX_DIR);
Set<String> setFiles = new LinkedHashSet<String>();
OsmandApplication app = (OsmandApplication) getApplication();
boolean addJS = app.getSettings().USE_JS_VOICE_GUIDANCE.get();
if (extStorage.exists()) {
for (File f : extStorage.listFiles()) {
if (f.isDirectory()) {
if (addJS && hasJavaScript(f)) {
setFiles.add(f.getName());
} else if (!addJS) {
setFiles.add(f.getName());
}
}
}
}
return setFiles;
}
private boolean hasJavaScript(File f) {
for (File file : f.listFiles()) {
if (file.getName().endsWith(IndexConstants.TTSVOICE_INDEX_EXT_JS)) {
return true;
}
}
return false;
}
private void selectVoice(final LinearLayout ll) {
String[] entries;
final String[] entrieValues;
Set<String> voiceFiles = getVoiceFiles();
Set<String> voiceFiles = getVoiceFiles(this);
entries = new String[voiceFiles.size() ];
entrieValues = new String[voiceFiles.size() ];
int k = 0;

View file

@ -1,5 +1,6 @@
package net.osmand.plus.mapcontextmenu.other;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@ -329,20 +330,36 @@ public class RoutePreferencesMenu {
app.initVoiceCommandPlayer(mapActivity, app.getRoutingHelper().getAppMode(), false, null, true, false);
}
private static Set<String> getVoiceFiles(MapActivity mapActivity) {
public static Set<String> getVoiceFiles(Activity activity) {
// read available voice data
File extStorage = mapActivity.getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR);
Set<String> setFiles = new LinkedHashSet<>();
OsmandApplication app = ((OsmandApplication) activity.getApplication());
File extStorage = app.getAppPath(IndexConstants.VOICE_INDEX_DIR);
Set<String> setFiles = new LinkedHashSet<String>();
boolean addJS = app.getSettings().USE_JS_VOICE_GUIDANCE.get();
if (extStorage.exists()) {
for (File f : extStorage.listFiles()) {
if (f.isDirectory()) {
setFiles.add(f.getName());
if (addJS && hasJavaScript(f)) {
setFiles.add(f.getName());
} else if (!addJS) {
setFiles.add(f.getName());
}
}
}
}
return setFiles;
}
private static boolean hasJavaScript(File f) {
for (File file : f.listFiles()) {
if (file.getName().endsWith(IndexConstants.TTSVOICE_INDEX_EXT_JS)) {
return true;
}
}
return false;
}
public OnItemClickListener getItemClickListener(final ArrayAdapter<?> listAdapter) {
return new OnItemClickListener() {
@Override