Merge branch 'master' into tagging-support

This commit is contained in:
Richy HBM 2017-11-15 19:42:04 +00:00 committed by GitHub
commit 22d2c8ff02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 200 additions and 31 deletions

View file

@ -40,6 +40,7 @@ import android.util.Log;
import android.view.View;
import android.view.ViewStub;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
@ -92,6 +93,8 @@ public class BackupActivity extends BaseActivity {
private Uri encryptTargetFile;
private Uri decryptSourceFile;
private Switch replace;
private boolean reload = false;
@Override
@ -193,6 +196,8 @@ public class BackupActivity extends BaseActivity {
});
}
replace = v.findViewById(R.id.backup_replace);
}
// End with a result
@ -361,10 +366,18 @@ public class BackupActivity extends BaseActivity {
private void doRestorePlain(Uri uri) {
if (Tools.isExternalStorageReadable()) {
boolean success = DatabaseHelper.importFromJSON(this, uri);
ArrayList<Entry> entries = DatabaseHelper.importFromJSON(this, uri);
if (success) {
if (entries != null) {
if (! replace.isChecked()) {
ArrayList<Entry> currentEntries = DatabaseHelper.loadDatabase(this);
entries.removeAll(currentEntries);
entries.addAll(currentEntries);
}
DatabaseHelper.saveDatabase(this, entries);
reload = true;
Toast.makeText(this, R.string.backup_toast_import_success, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, R.string.backup_toast_import_failed, Toast.LENGTH_LONG).show();
@ -427,6 +440,13 @@ public class BackupActivity extends BaseActivity {
byte[] decrypted = EncryptionHelper.decrypt(key, encrypted);
ArrayList<Entry> entries = DatabaseHelper.stringToEntries(new String(decrypted, StandardCharsets.UTF_8));
if (! replace.isChecked()) {
ArrayList<Entry> currentEntries = DatabaseHelper.loadDatabase(this);
entries.removeAll(currentEntries);
entries.addAll(currentEntries);
}
DatabaseHelper.saveDatabase(this, entries);
} catch (Exception e) {
e.printStackTrace();
@ -491,9 +511,15 @@ public class BackupActivity extends BaseActivity {
ArrayList<Entry> entries = DatabaseHelper.stringToEntries(content);
if (entries.size() > 0) {
DatabaseHelper.saveDatabase(this, entries);
if (! replace.isChecked()) {
ArrayList<Entry> currentEntries = DatabaseHelper.loadDatabase(this);
entries.removeAll(currentEntries);
entries.addAll(currentEntries);
}
DatabaseHelper.saveDatabase(this, entries);
reload = true;
Toast.makeText(this, R.string.backup_toast_import_success, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, R.string.backup_toast_import_failed, Toast.LENGTH_LONG).show();

View file

@ -428,9 +428,11 @@ 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_tap_to_reveal))) {
key.equals(getString(R.string.settings_key_tap_to_reveal)) ||
key.equals(getString(R.string.settings_key_label_scroll))) {
adapter.notifyDataSetChanged();
} else if (key.equals(getString(R.string.settings_key_theme))) {
} else if (key.equals(getString(R.string.settings_key_theme)) ||
key.equals(getString(R.string.settings_key_lang))) {
recreate();
}
}

View file

@ -85,7 +85,8 @@ public class SettingsActivity extends BaseActivity
}
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if (key.equals(getString(R.string.settings_key_theme))) {
if (key.equals(getString(R.string.settings_key_theme)) ||
key.equals(getString(R.string.settings_key_lang))) {
recreate();
}
}

View file

@ -22,12 +22,15 @@
package org.shadowice.flocke.andotp.Activities;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import org.shadowice.flocke.andotp.R;
import org.shadowice.flocke.andotp.Utilities.Settings;
import java.util.Locale;
public abstract class ThemedActivity extends AppCompatActivity {
public Settings settings;
@ -35,6 +38,20 @@ public abstract class ThemedActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
settings = new Settings(this);
setTheme();
setLocale();
super.onCreate(savedInstanceState);
}
@Override
public void onResume() {
setLocale();
super.onResume();
}
public void setTheme() {
String theme = settings.getTheme();
if (theme.equals("light")) {
@ -44,7 +61,15 @@ public abstract class ThemedActivity extends AppCompatActivity {
} else if (theme.equals("black")) {
setTheme(R.style.AppTheme_Black_NoActionBar);
}
}
super.onCreate(savedInstanceState);
public void setLocale() {
Locale locale = settings.getLang();
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
}
}

View file

@ -132,7 +132,7 @@ public class Entry {
}
public Entry (JSONObject jsonObj) throws JSONException {
this.secret = new Base32().decode(jsonObj.getString(JSON_SECRET));
this.secret = new Base32().decode(jsonObj.getString(JSON_SECRET).toUpperCase());
this.label = jsonObj.getString(JSON_LABEL);
this.period = jsonObj.getInt(JSON_PERIOD);

View file

@ -113,19 +113,14 @@ public class DatabaseHelper {
return FileHelper.writeStringToFile(context, file, entriesToString(entries));
}
public static boolean importFromJSON(Context context, Uri file) {
boolean success = false;
public static ArrayList<Entry> importFromJSON(Context context, Uri file) {
String content = FileHelper.readFileToString(context, file);
if (! content.isEmpty()) {
ArrayList<Entry> entries = stringToEntries(content);
ArrayList<Entry> entries = null;
saveDatabase(context, entries);
if (! content.isEmpty())
entries = stringToEntries(content);
success = true;
}
return success;
return entries;
}
}

View file

@ -37,6 +37,7 @@ import java.nio.charset.StandardCharsets;
import java.security.KeyPair;
import java.util.Collections;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import static org.shadowice.flocke.andotp.Preferences.PasswordEncryptedPreference.KEY_ALIAS;
@ -213,10 +214,23 @@ public class Settings {
return settings.getStringSet(getResString(R.string.settings_key_panic), Collections.<String>emptySet());
}
public Locale getLang() {
String lang = getString(R.string.settings_key_lang, R.string.settings_default_lang);
if (lang.equals("system"))
return Tools.getSystemLocale();
else
return new Locale(lang);
}
public String getTheme() {
return getString(R.string.settings_key_theme, R.string.settings_default_theme);
}
public boolean getScrollLabel() {
return getBoolean(R.string.settings_key_label_scroll, false);
}
public boolean getFirstTimeWarningShown() {
return getBoolean(R.string.settings_key_security_backup_warning, false);
}

View file

@ -29,9 +29,11 @@ import android.graphics.ColorFilter;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import java.io.File;
import java.util.Locale;
public class Tools {
/* Checks if external storage is available for read and write */
@ -70,4 +72,12 @@ public class Tools {
File dir = new File(path);
return dir.exists() || dir.mkdirs();
}
public static Locale getSystemLocale() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return Resources.getSystem().getConfiguration().getLocales().get(0);
} else {
return Resources.getSystem().getConfiguration().locale;
}
}
}

View file

@ -169,6 +169,8 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
int fontSize = sharedPrefs.getInt(context.getString(R.string.settings_key_label_size), context.getResources().getInteger(R.integer.settings_default_label_size));
entryViewHolder.setLabelSize(fontSize);
entryViewHolder.setLabelScroll(sharedPrefs.getBoolean(context.getString(R.string.settings_key_label_scroll), false));
}
@Override

View file

@ -26,6 +26,7 @@ import android.content.Context;
import android.graphics.ColorFilter;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageButton;
@ -136,6 +137,18 @@ public class EntryViewHolder extends RecyclerView.ViewHolder
tags.setTextSize(TypedValue.COMPLEX_UNIT_PT, size - 2);
}
public void setLabelScroll(boolean active) {
if (active) {
label.setEllipsize(TextUtils.TruncateAt.MARQUEE);
label.setHorizontallyScrolling(true);
label.setSelected(true);
} else {
label.setEllipsize(TextUtils.TruncateAt.END);
label.setHorizontallyScrolling(false);
label.setSelected(false);
}
}
public void enableTapToReveal() {
valueLayout.setVisibility(View.GONE);
coverLayout.setVisibility(View.VISIBLE);

View file

@ -66,7 +66,7 @@
android:textColor="?android:attr/textColorSecondary"
android:textSize="28sp"
android:textStyle="bold"
android:text="@string/label_tap_to_reveal" />
android:text="@string/label_hidden" />
</LinearLayout>
</LinearLayout>

View file

@ -486,7 +486,7 @@
android:id="@+id/about_layout_bugs"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_margin"
android:paddingTop="@dimen/activity_margin_small"
android:paddingBottom="@dimen/activity_margin_small"
@ -504,7 +504,7 @@
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical" >
<TextView
@ -528,7 +528,7 @@
android:id="@+id/about_layout_translate"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_height="wrap_content"
android:paddingTop="@dimen/activity_margin_small"
android:paddingBottom="@dimen/activity_margin_small"
android:background="?android:attr/selectableItemBackground"
@ -545,7 +545,7 @@
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical" >
<TextView

View file

@ -191,5 +191,31 @@
</LinearLayout>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_margin"
android:layout_gravity="center"
android:padding="@dimen/activity_margin"
android:background="?android:attr/selectableItemBackground" >
<CheckedTextView
android:id="@+id/backup_replace_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toStartOf="@id/backup_replace"
android:text="@string/backup_desc_replace"
android:textAppearance="?android:attr/textAppearanceListItem" />
<Switch
android:id="@+id/backup_replace"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:checked="true" />
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

View file

@ -9,10 +9,11 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:layout_weight="2"
android:layout_weight="3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/label_type"/>
@ -28,10 +29,11 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:layout_weight="2"
android:layout_weight="3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/label_label"/>
@ -48,10 +50,11 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:layout_weight="2"
android:layout_weight="3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/label_secret"/>
@ -61,7 +64,7 @@
android:layout_weight="7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:lines="2"
android:lines="3"
android:hint="@string/hint_secret" />
</LinearLayout>
@ -69,10 +72,11 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:layout_weight="2"
android:layout_weight="3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/label_period"/>
@ -90,10 +94,11 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:layout_weight="2"
android:layout_weight="3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/label_digits"/>
@ -111,10 +116,11 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:layout_weight="2"
android:layout_weight="3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/label_algorithm"/>

View file

@ -11,8 +11,10 @@
<string name="settings_key_auth_pin_hash" translatable="false">pref_auth_pin_hash</string>
<string name="settings_key_panic" translatable="false">pref_panic</string>
<string name="settings_key_lang" translatable="false">pref_lang</string>
<string name="settings_key_theme" translatable="false">pref_theme</string>
<string name="settings_key_label_size" translatable="false">pref_label_size</string>
<string name="settings_key_label_scroll" translatable="false">pref_label_scroll</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>
@ -32,6 +34,7 @@
<!-- Default values -->
<string name="settings_default_auth" translatable="false">none</string>
<string name="settings_default_lang" translatable="false">system</string>
<string name="settings_default_theme" translatable="false">light</string>
<integer name="settings_default_label_size">8</integer>
@ -48,6 +51,19 @@
<item>settings</item>
</string-array>
<string-array name="settings_values_lang" translatable="false">
<item>system</item>
<item>en</item>
<item>cs</item>
<item>de</item>
<item>es</item>
<item>fr</item>
<item>gl</item>
<item>nl</item>
<item>pl</item>
<item>ru</item>
</string-array>
<string-array name="settings_values_theme" translatable="false">
<item>light</item>
<item>dark</item>

View file

@ -31,6 +31,8 @@
before you can create encrypted backups.
</string>
<string name="backup_desc_replace">Replace already existing entries</string>
<!-- Dialogs -->
<string name="backup_dialog_title_security_warning">Security warning</string>

View file

@ -20,7 +20,7 @@
<!-- Labels -->
<string name="label_clipboard_content" translatable="false">OTP Token</string>
<string name="label_tap_to_reveal">Tap to reveal</string>
<string name="label_hidden">Hidden</string>
<string name="label_type">Type</string>
<string name="label_secret">Secret</string>
<string name="label_period">Period</string>

View file

@ -14,8 +14,10 @@
<string name="settings_title_auth_pin">PIN</string>
<string name="settings_title_panic">Panic Trigger</string>
<string name="settings_title_lang">Language</string>
<string name="settings_title_theme">Theme</string>
<string name="settings_title_label_size">Label font size</string>
<string name="settings_title_label_scroll">Scroll label</string>
<string name="settings_title_backup_ask">Ask for filename</string>
<string name="settings_title_backup_directory">Backup directory</string>
@ -30,6 +32,8 @@
revealed manually</string>
<string name="settings_desc_panic">Decide what happens when a Panic Trigger is received</string>
<string name="settings_desc_label_scroll">Scroll overlong labels instead of truncating them</string>
<string name="settings_desc_backup_ask">Ask for the filename every time a backup is created or
restored</string>
<string name="settings_desc_backup_directory">Directory for the backups (filenames will depend
@ -61,6 +65,19 @@
<item>Reset app settings</item>
</string-array>
<string-array name="settings_entries_lang">
<item>System default</item>
<item>English</item>
<item>Czech</item>
<item>German</item>
<item>Spanish</item>
<item>French</item>
<item>Galician</item>
<item>Dutch</item>
<item>Polish</item>
<item>Russian</item>
</string-array>
<string-array name="settings_entries_theme">
<item>Light theme</item>
<item>Dark theme</item>

View file

@ -37,6 +37,14 @@
<PreferenceCategory
android:title="@string/settings_category_title_ui">
<ListPreference
android:key="@string/settings_key_lang"
android:title="@string/settings_title_lang"
android:summary="%s"
android:entries="@array/settings_entries_lang"
android:entryValues="@array/settings_values_lang"
android:defaultValue="@string/settings_default_lang" />
<ListPreference
android:key="@string/settings_key_theme"
android:title="@string/settings_title_theme"
@ -52,6 +60,12 @@
app:vnt_maxValue="@integer/settings_max_label_size"
app:vnt_minValue="@integer/settings_min_label_size" />
<CheckBoxPreference
android:key="@string/settings_key_label_scroll"
android:title="@string/settings_title_label_scroll"
android:summary="@string/settings_desc_label_scroll"
android:defaultValue="false" />
</PreferenceCategory>
<PreferenceCategory