regression: fixed 0-key chars corruption when the saved list was empty
This commit is contained in:
parent
13673aa036
commit
31859fbf9d
3 changed files with 18 additions and 10 deletions
|
|
@ -7,6 +7,7 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import io.github.sspanak.tt9.R;
|
import io.github.sspanak.tt9.R;
|
||||||
|
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||||
|
|
||||||
public class PreferenceSentencePunctuationList extends AbstractPreferenceCharList {
|
public class PreferenceSentencePunctuationList extends AbstractPreferenceCharList {
|
||||||
public static final String NAME = "punctuation_order_sentence";
|
public static final String NAME = "punctuation_order_sentence";
|
||||||
|
|
@ -35,7 +36,7 @@ public class PreferenceSentencePunctuationList extends AbstractPreferenceCharLis
|
||||||
public boolean validateCurrentChars() {
|
public boolean validateCurrentChars() {
|
||||||
StringBuilder missingCharList = new StringBuilder();
|
StringBuilder missingCharList = new StringBuilder();
|
||||||
|
|
||||||
for (char c : getSettings().mandatoryPunctuation) {
|
for (char c : SettingsStore.MANDATORY_PUNCTUATION) {
|
||||||
if (currentChars.indexOf(c) == -1) {
|
if (currentChars.indexOf(c) == -1) {
|
||||||
missingCharList.append(" ").append(c).append(",");
|
missingCharList.append(" ").append(c).append(",");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ import android.util.AttributeSet;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
|
||||||
|
|
||||||
public class PreferenceSpecialCharList extends AbstractPreferenceCharList {
|
public class PreferenceSpecialCharList extends AbstractPreferenceCharList {
|
||||||
public static final String NAME = "punctuation_order_special_chars";
|
public static final String NAME = "punctuation_order_special_chars";
|
||||||
|
|
||||||
|
|
@ -23,7 +25,7 @@ public class PreferenceSpecialCharList extends AbstractPreferenceCharList {
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
protected char[] getMandatoryChars() {
|
protected char[] getMandatoryChars() {
|
||||||
return getSettings().mandatorySpecialChars;
|
return SettingsStore.MANDATORY_SPECIAL_CHARS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -9,23 +9,26 @@ import java.util.ArrayList;
|
||||||
import io.github.sspanak.tt9.languages.Language;
|
import io.github.sspanak.tt9.languages.Language;
|
||||||
|
|
||||||
class SettingsPunctuation extends SettingsInput {
|
class SettingsPunctuation extends SettingsInput {
|
||||||
|
private final static String KEY_PREFIX_PUNCTUATION = "pref_punctuation_";
|
||||||
|
private final static String KEY_PREFIX_SPECIAL = "pref_special_chars_";
|
||||||
|
public final static char[] MANDATORY_PUNCTUATION = new char[] {'\'', '"', '-'};
|
||||||
|
public final static char[] MANDATORY_SPECIAL_CHARS = new char[] {' ', '\n'};
|
||||||
|
|
||||||
|
|
||||||
SettingsPunctuation(Context context) {
|
SettingsPunctuation(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public final char[] mandatoryPunctuation = new char[] {'\'', '"', '-'};
|
|
||||||
public final char[] mandatorySpecialChars = new char[] {' ', '\n'};
|
|
||||||
|
|
||||||
|
|
||||||
public void savePunctuation(@NonNull Language language, @NonNull String punctuation) {
|
public void savePunctuation(@NonNull Language language, @NonNull String punctuation) {
|
||||||
prefsEditor.putString("pref_punctuation_" + language.getId(), punctuation);
|
prefsEditor.putString(KEY_PREFIX_PUNCTUATION + language.getId(), punctuation);
|
||||||
prefsEditor.apply();
|
prefsEditor.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void saveSpecialChars(@NonNull Language language, @NonNull String specialChars) {
|
public void saveSpecialChars(@NonNull Language language, @NonNull String specialChars) {
|
||||||
prefsEditor.putString("pref_special_chars_" + language.getId(), specialChars);
|
String safeChars = specialChars.replace("\n", "⏎");
|
||||||
|
prefsEditor.putString(KEY_PREFIX_SPECIAL + language.getId(), safeChars);
|
||||||
prefsEditor.apply();
|
prefsEditor.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,7 +50,7 @@ class SettingsPunctuation extends SettingsInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
return getCharsAsList(
|
return getCharsAsList(
|
||||||
prefs.getString("pref_punctuation_" + language.getId(), null),
|
prefs.getString(KEY_PREFIX_PUNCTUATION + language.getId(), null),
|
||||||
language.getKeyCharacters(1)
|
language.getKeyCharacters(1)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -59,8 +62,10 @@ class SettingsPunctuation extends SettingsInput {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String safeChars = prefs.getString(KEY_PREFIX_SPECIAL + language.getId(), null);
|
||||||
|
|
||||||
return getCharsAsList(
|
return getCharsAsList(
|
||||||
prefs.getString("pref_special_chars_" + language.getId(), null),
|
safeChars == null ? null : safeChars.replace("⏎", "\n"),
|
||||||
language.getKeyCharacters(0)
|
language.getKeyCharacters(0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue