Skip to content

Commit

Permalink
fixing complication error
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Jan 8, 2016
1 parent 7d3b599 commit 0b26875
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

package org.mariotaku.twidere.annotation;

import android.support.annotation.IntDef;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand All @@ -46,10 +44,6 @@

boolean hasDefault() default false;

@Type int type() default Type.NULL;
@PreferenceType int type() default PreferenceType.NULL;

@IntDef({Type.BOOLEAN, Type.INT, Type.LONG, Type.FLOAT, Type.STRING, Type.NULL, Type.INVALID})
@interface Type {
int BOOLEAN = 1, INT = 2, LONG = 3, FLOAT = 4, STRING = 5, NULL = 0, INVALID = -1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.mariotaku.twidere.annotation;

import android.support.annotation.IntDef;

/**
* Created by mariotaku on 16/1/8.
*/
@IntDef({PreferenceType.BOOLEAN, PreferenceType.INT, PreferenceType.LONG, PreferenceType.FLOAT,
PreferenceType.STRING, PreferenceType.NULL, PreferenceType.INVALID})
public @interface PreferenceType {
int BOOLEAN = 1, INT = 2, LONG = 3, FLOAT = 4, STRING = 5, NULL = 0, INVALID = -1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
import org.mariotaku.twidere.annotation.Preference;
import org.mariotaku.twidere.model.ParcelableCredentials;

import static org.mariotaku.twidere.annotation.Preference.Type.BOOLEAN;
import static org.mariotaku.twidere.annotation.Preference.Type.INT;
import static org.mariotaku.twidere.annotation.Preference.Type.LONG;
import static org.mariotaku.twidere.annotation.Preference.Type.STRING;
import static org.mariotaku.twidere.annotation.PreferenceType.BOOLEAN;
import static org.mariotaku.twidere.annotation.PreferenceType.INT;
import static org.mariotaku.twidere.annotation.PreferenceType.LONG;
import static org.mariotaku.twidere.annotation.PreferenceType.STRING;

public interface SharedPreferenceConstants {

Expand Down
4 changes: 2 additions & 2 deletions twidere/src/main/java/org/mariotaku/twidere/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

import org.mariotaku.twidere.annotation.Preference;

import static org.mariotaku.twidere.annotation.Preference.Type.BOOLEAN;
import static org.mariotaku.twidere.annotation.Preference.Type.STRING;
import static org.mariotaku.twidere.annotation.PreferenceType.BOOLEAN;
import static org.mariotaku.twidere.annotation.PreferenceType.STRING;

/**
* Constants requires full application to build or useless for other
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.json.JSONObject;
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.annotation.Preference;
import org.mariotaku.twidere.annotation.Preference.Type;
import org.mariotaku.twidere.annotation.PreferenceType;
import org.mariotaku.twidere.constant.SharedPreferenceConstants;

import java.io.BufferedOutputStream;
Expand Down Expand Up @@ -122,7 +122,7 @@ public static HashMap<String, Preference> getSupportedPreferencesMap(Class cls)
for (final Field field : fields) {
final Preference annotation = field.getAnnotation(Preference.class);
if (Modifier.isStatic(field.getModifiers()) && CompareUtils.classEquals(field.getType(), String.class)
&& annotation != null && annotation.exportable() && annotation.type() != Type.INVALID) {
&& annotation != null && annotation.exportable() && annotation.type() != PreferenceType.INVALID) {
try {
supportedPrefsMap.put((String) field.get(null), annotation);
} catch (final IllegalAccessException | IllegalArgumentException e) {
Expand Down Expand Up @@ -255,19 +255,19 @@ public boolean importValue(JSONObject json, String key, SharedPreferences.Editor
final Preference preference = supportedMap.get(key);
if (preference == null || !preference.exportable()) return false;
switch (preference.type()) {
case Type.BOOLEAN:
case PreferenceType.BOOLEAN:
editor.putBoolean(key, json.optBoolean(key, preference.defaultBoolean()));
break;
case Type.INT:
case PreferenceType.INT:
editor.putInt(key, json.optInt(key, preference.defaultInt()));
break;
case Type.LONG:
case PreferenceType.LONG:
editor.putLong(key, json.optLong(key, preference.defaultLong()));
break;
case Type.FLOAT:
case PreferenceType.FLOAT:
editor.putFloat(key, (float) json.optDouble(key, preference.defaultFloat()));
break;
case Type.STRING:
case PreferenceType.STRING:
editor.putString(key, json.optString(key, preference.defaultString()));
break;
default:
Expand All @@ -282,19 +282,19 @@ public boolean exportValue(JSONObject json, String key, SharedPreferences prefer
if (preference == null || !preference.exportable()) return false;
try {
switch (preference.type()) {
case Type.BOOLEAN:
case PreferenceType.BOOLEAN:
json.put(key, preferences.getBoolean(key, preference.defaultBoolean()));
break;
case Type.INT:
case PreferenceType.INT:
json.put(key, preferences.getInt(key, preference.defaultInt()));
break;
case Type.LONG:
case PreferenceType.LONG:
json.put(key, preferences.getLong(key, preference.defaultLong()));
break;
case Type.FLOAT:
case PreferenceType.FLOAT:
json.put(key, preferences.getFloat(key, preference.defaultFloat()));
break;
case Type.STRING:
case PreferenceType.STRING:
json.put(key, preferences.getString(key, preference.defaultString()));
break;
default:
Expand Down

0 comments on commit 0b26875

Please sign in to comment.