Merge pull request #93 from DanielWeigl/master

split token with a space every three letters
Closes #83
This commit is contained in:
Jakob Nixdorf 2018-01-11 15:25:13 +01:00 committed by GitHub
commit 62f3ffba39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 69 additions and 2 deletions

View file

@ -0,0 +1,18 @@
package org.shadowice.flocke.andotp.Utilities;
import junit.framework.TestCase;
public class ToolsTest extends TestCase {
public void testFormatToken() throws Exception {
assertEquals("123 456", Tools.formatToken("123456", 3));
assertEquals("12 34 56", Tools.formatToken("123456", 2));
assertEquals("123456", Tools.formatToken("123456", 0));
assertEquals("123456", Tools.formatToken("123456", 10));
assertEquals("1 234 567", Tools.formatToken("1234567", 3));
assertEquals("1ab 234 567", Tools.formatToken("1ab234567", 3));
assertEquals("123", Tools.formatToken("123", 3));
assertEquals("1 234", Tools.formatToken("1234", 3));
assertEquals("1", Tools.formatToken("1", 3));
assertEquals("", Tools.formatToken("", 3));
}
}

View file

@ -354,6 +354,7 @@ public class MainActivity extends BaseActivity
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if (key.equals(getString(R.string.settings_key_label_size)) ||
key.equals(getString(R.string.settings_key_label_scroll)) ||
key.equals(getString(R.string.settings_key_split_group_size)) ||
key.equals(getString(R.string.settings_key_thumbnail_size))) {
adapter.notifyDataSetChanged();
} else if (key.equals(getString(R.string.settings_key_tap_to_reveal)) ||

View file

@ -419,6 +419,13 @@ public class Settings {
}
}
public int getTokenSplitGroupSize() {
// the setting is of type "String", because ListPreference does not support integer arrays for its entryValues
return Integer.valueOf(
getString(R.string.settings_key_split_group_size, R.string.settings_default_split_group_size)
);
}
public boolean getScreenshotsEnabled() {
return getBoolean(R.string.settings_key_enable_screenshot, false);
}

View file

@ -80,4 +80,19 @@ public class Tools {
return Resources.getSystem().getConfiguration().locale;
}
}
public static String formatToken(String s, int chunkSize) {
if (chunkSize==0) {
return s;
}
StringBuilder ret = new StringBuilder("");
final int len = s.length();
int index = len;
while (index > 0) {
ret.insert(0, s.substring(Math.max(index - chunkSize, 0), index));
ret.insert(0, " ");
index = index - chunkSize;
}
return ret.toString().trim();
}
}

View file

@ -100,7 +100,7 @@ public class EntryViewHolder extends RecyclerView.ViewHolder
@Override
public void onClick(View view) {
if (callback != null)
callback.onCopyButtonClicked(value.getText().toString(), getAdapterPosition());
callback.onCopyButtonClicked(value.getTag().toString(), getAdapterPosition());
}
});
@ -109,9 +109,12 @@ public class EntryViewHolder extends RecyclerView.ViewHolder
public void updateValues(String label, String token, List<String> tags, EntryThumbnail.EntryThumbnails thumbnail, boolean isVisible) {
Settings settings = new Settings(context);
final String tokenFormatted = Tools.formatToken(token, settings.getTokenSplitGroupSize());
this.label.setText(label);
value.setText(token);
value.setText(tokenFormatted);
// save the unformatted token to the tag of this TextView for copy/paste
value.setTag(token);
StringBuilder stringBuilder = new StringBuilder();
for(int i = 0; i < tags.size(); i++) {

View file

@ -21,6 +21,7 @@
<string name="settings_key_label_size" translatable="false">pref_label_size_sp</string>
<string name="settings_key_label_scroll" translatable="false">pref_label_scroll</string>
<string name="settings_key_thumbnail_size" translatable="false">pref_thumbnail_size</string>
<string name="settings_key_split_group_size" translatable="false">pref_split_group_size</string>
<string name="settings_key_backup_ask" translatable="false">pref_backup_ask</string>
<string name="settings_key_backup_directory" translatable="false">pref_backup_directory</string>
@ -50,6 +51,7 @@
<string name="settings_default_theme" translatable="false">light</string>
<integer name="settings_default_label_size">18</integer>
<string name="settings_default_thumbnail_size">46dp</string>
<string name="settings_default_split_group_size">3</string>
<!-- All of the possible tile background colors -->
<array name="letter_tile_colors">
@ -102,6 +104,12 @@
<item>96dp</item>
</string-array>
<string-array name="settings_values_split_group_size" translatable="false">
<item>0</item>
<item>2</item>
<item>3</item>
</string-array>
<string-array name="settings_entries_lang" translatable="false">
<item>@string/settings_lang_sys_default</item>
<item>English</item>

View file

@ -21,6 +21,7 @@
<string name="settings_title_label_size">Label font size</string>
<string name="settings_title_label_scroll">Scroll label</string>
<string name="settings_title_thumbnail_size_ask">Thumbnail size</string>
<string name="settings_title_split_group_size">Split Token with space</string>
<string name="settings_title_backup_ask">Ask for filename</string>
<string name="settings_title_backup_directory">Backup directory</string>
@ -136,6 +137,12 @@
<item>Large</item>
</string-array>
<string-array name="settings_entries_split_group_size">
<item>Don\'t split</item>
<item>After two characters</item>
<item>After three characters</item>
</string-array>
<!-- Special -->
<string name="settings_lang_sys_default">System default</string>

View file

@ -83,6 +83,14 @@
android:entryValues="@array/settings_values_thumbnail_size"
android:defaultValue="@string/settings_default_thumbnail_size" />
<ListPreference
android:key="@string/settings_key_split_group_size"
android:title="@string/settings_title_split_group_size"
android:summary="%s"
android:entries="@array/settings_entries_split_group_size"
android:entryValues="@array/settings_values_split_group_size"
android:defaultValue="@string/settings_default_split_group_size" />
</PreferenceCategory>
<PreferenceCategory