Small improvements

This commit is contained in:
M66B 2018-11-10 10:45:03 +00:00
parent 439a1cc627
commit a9450edc3f
6 changed files with 58 additions and 46 deletions

View File

@ -17,9 +17,9 @@ android {
}
}
//lintOptions {
// disable 'MissingTranslation'
//}
lintOptions {
disable 'MissingTranslation'
}
buildTypes {
release {

View File

@ -66,27 +66,6 @@ public class EntityAccount {
public String state;
public String error;
@Override
public boolean equals(Object obj) {
if (obj instanceof EntityAccount) {
EntityAccount other = (EntityAccount) obj;
return ((this.name == null ? other.name == null : this.name.equals(other.name)) &&
(this.signature == null ? other.signature == null : this.signature.equals(other.signature)) &&
this.host.equals(other.host) &&
this.port.equals(other.port) &&
this.user.equals(other.user) &&
this.password.equals(other.password) &&
this.auth_type.equals(other.auth_type) &&
this.synchronize.equals(other.synchronize) &&
this.primary.equals(other.primary) &&
(this.color == null ? other.color == null : this.color.equals(other.color)) &&
this.poll_interval.equals(other.poll_interval) &&
(this.state == null ? other.state == null : this.state.equals(other.state)) &&
(this.error == null ? other.error == null : this.error.equals(other.error)));
} else
return false;
}
public JSONObject toJSON() throws JSONException {
JSONObject json = new JSONObject();
json.put("name", name);
@ -103,6 +82,9 @@ public class EntityAccount {
if (color != null)
json.put("color", color);
json.put("poll_interval", poll_interval);
// not created
// not state
// not error
return json;
}
@ -127,6 +109,30 @@ public class EntityAccount {
return account;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof EntityAccount) {
EntityAccount other = (EntityAccount) obj;
return ((this.name == null ? other.name == null : this.name.equals(other.name)) &&
(this.signature == null ? other.signature == null : this.signature.equals(other.signature)) &&
this.host.equals(other.host) &&
this.starttls == other.starttls &&
this.insecure == other.insecure &&
this.port.equals(other.port) &&
this.user.equals(other.user) &&
this.password.equals(other.password) &&
this.auth_type.equals(other.auth_type) &&
this.synchronize.equals(other.synchronize) &&
this.primary.equals(other.primary) &&
(this.color == null ? other.color == null : this.color.equals(other.color)) &&
this.poll_interval.equals(other.poll_interval) &&
(this.created == null ? other.created == null : this.created.equals(other.created)) &&
(this.state == null ? other.state == null : this.state.equals(other.state)) &&
(this.error == null ? other.error == null : this.error.equals(other.error)));
} else
return false;
}
@Override
public String toString() {
return name + (primary ? "" : "");

View File

@ -79,16 +79,19 @@ public class EntityIdentity {
json.put("name", name);
json.put("email", email);
json.put("replyto", replyto);
// not account
json.put("host", host);
json.put("port", port);
json.put("starttls", starttls);
json.put("insecure", insecure);
json.put("port", port);
json.put("user", user);
json.put("password", "");
json.put("auth_type", auth_type);
json.put("primary", primary);
json.put("synchronize", false);
json.put("store_sent", store_sent);
// not state
// not error
return json;
}
@ -99,9 +102,9 @@ public class EntityIdentity {
if (json.has("replyto"))
identity.replyto = json.getString("replyto");
identity.host = json.getString("host");
identity.port = json.getInt("port");
identity.starttls = json.getBoolean("starttls");
identity.insecure = (json.has("insecure") && json.getBoolean("insecure"));
identity.port = json.getInt("port");
identity.user = json.getString("user");
identity.password = json.getString("password");
identity.auth_type = json.getInt("auth_type");
@ -120,8 +123,9 @@ public class EntityIdentity {
(this.replyto == null ? other.replyto == null : this.replyto.equals(other.replyto)) &&
this.account.equals(other.account) &&
this.host.equals(other.host) &&
this.port.equals(other.port) &&
this.starttls.equals(other.starttls) &&
this.insecure.equals(other.insecure) &&
this.port.equals(other.port) &&
this.user.equals(other.user) &&
this.password.equals(other.password) &&
this.primary.equals(other.primary) &&

View File

@ -40,7 +40,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.SwitchCompat;
public class FragmentOptions extends FragmentEx {
public class FragmentOptions extends FragmentEx implements SharedPreferences.OnSharedPreferenceChangeListener {
private SwitchCompat swEnabled;
private SwitchCompat swAvatars;
private SwitchCompat swIdenticons;
@ -233,6 +233,20 @@ public class FragmentOptions extends FragmentEx {
swLight.setVisibility(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O ? View.VISIBLE : View.GONE);
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);
return view;
}
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if ("enabled".equals(key))
swEnabled.setChecked(prefs.getBoolean(key, true));
}
@Override
public void onDestroyView() {
PreferenceManager.getDefaultSharedPreferences(getContext()).unregisterOnSharedPreferenceChangeListener(this);
super.onDestroyView();
}
}

View File

@ -60,7 +60,6 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@ -104,21 +103,6 @@ public class FragmentSetup extends FragmentEx {
Manifest.permission.READ_CONTACTS
};
static final List<String> EXPORT_SETTINGS = Arrays.asList(
"enabled",
"compact",
"avatars",
"identicons",
"preview",
"light",
"browse",
"swipe",
"navigation",
"sender",
"insecure",
"sort"
);
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@ -582,7 +566,7 @@ public class FragmentSetup extends FragmentEx {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
JSONArray jsettings = new JSONArray();
for (String key : prefs.getAll().keySet())
if (EXPORT_SETTINGS.contains(key)) {
if (!"pro".equals(key)) {
JSONObject jsetting = new JSONObject();
jsetting.put("key", key);
jsetting.put("value", prefs.getAll().get(key));
@ -688,10 +672,14 @@ public class FragmentSetup extends FragmentEx {
for (int s = 0; s < jsettings.length(); s++) {
JSONObject jsetting = (JSONObject) jsettings.get(s);
String key = jsetting.getString("key");
if (EXPORT_SETTINGS.contains(key)) {
if (!"pro".equals(key)) {
Object value = jsetting.get("value");
if (value instanceof Boolean)
editor.putBoolean(key, (Boolean) value);
else if (value instanceof Integer)
editor.putInt(key, (Integer) value);
else if (value instanceof Long)
editor.putLong(key, (Long) value);
else if (value instanceof String)
editor.putString(key, (String) value);
else