зеркало из https://github.com/mozilla/gecko-dev.git
Bug 965622 - (Part 1) Add EmptyViewConfig to HomeConfig. r=liuche
This commit is contained in:
Родитель
aa799a33df
Коммит
3ed88db4d5
|
@ -612,6 +612,7 @@ public final class HomeConfig {
|
|||
private final ItemHandler mItemHandler;
|
||||
private final String mBackImageUrl;
|
||||
private final String mFilter;
|
||||
private final EmptyViewConfig mEmptyViewConfig;
|
||||
|
||||
private static final String JSON_KEY_TYPE = "type";
|
||||
private static final String JSON_KEY_DATASET = "dataset";
|
||||
|
@ -619,6 +620,7 @@ public final class HomeConfig {
|
|||
private static final String JSON_KEY_ITEM_HANDLER = "itemHandler";
|
||||
private static final String JSON_KEY_BACK_IMAGE_URL = "backImageUrl";
|
||||
private static final String JSON_KEY_FILTER = "filter";
|
||||
private static final String JSON_KEY_EMPTY = "empty";
|
||||
|
||||
public ViewConfig(int index, JSONObject json) throws JSONException, IllegalArgumentException {
|
||||
mIndex = index;
|
||||
|
@ -629,6 +631,13 @@ public final class HomeConfig {
|
|||
mBackImageUrl = json.optString(JSON_KEY_BACK_IMAGE_URL, null);
|
||||
mFilter = json.optString(JSON_KEY_FILTER, null);
|
||||
|
||||
final JSONObject jsonEmptyViewConfig = json.optJSONObject(JSON_KEY_EMPTY);
|
||||
if (jsonEmptyViewConfig != null) {
|
||||
mEmptyViewConfig = new EmptyViewConfig(jsonEmptyViewConfig);
|
||||
} else {
|
||||
mEmptyViewConfig = null;
|
||||
}
|
||||
|
||||
validate();
|
||||
}
|
||||
|
||||
|
@ -641,6 +650,7 @@ public final class HomeConfig {
|
|||
mItemHandler = (ItemHandler) in.readParcelable(getClass().getClassLoader());
|
||||
mBackImageUrl = in.readString();
|
||||
mFilter = in.readString();
|
||||
mEmptyViewConfig = (EmptyViewConfig) in.readParcelable(getClass().getClassLoader());
|
||||
|
||||
validate();
|
||||
}
|
||||
|
@ -653,12 +663,14 @@ public final class HomeConfig {
|
|||
mItemHandler = viewConfig.mItemHandler;
|
||||
mBackImageUrl = viewConfig.mBackImageUrl;
|
||||
mFilter = viewConfig.mFilter;
|
||||
mEmptyViewConfig = viewConfig.mEmptyViewConfig;
|
||||
|
||||
validate();
|
||||
}
|
||||
|
||||
public ViewConfig(int index, ViewType type, String datasetId, ItemType itemType,
|
||||
ItemHandler itemHandler, String backImageUrl, String filter) {
|
||||
ItemHandler itemHandler, String backImageUrl, String filter,
|
||||
EmptyViewConfig emptyViewConfig) {
|
||||
mIndex = index;
|
||||
mType = type;
|
||||
mDatasetId = datasetId;
|
||||
|
@ -666,6 +678,7 @@ public final class HomeConfig {
|
|||
mItemHandler = itemHandler;
|
||||
mBackImageUrl = backImageUrl;
|
||||
mFilter = filter;
|
||||
mEmptyViewConfig = emptyViewConfig;
|
||||
|
||||
validate();
|
||||
}
|
||||
|
@ -716,6 +729,10 @@ public final class HomeConfig {
|
|||
return mFilter;
|
||||
}
|
||||
|
||||
public EmptyViewConfig getEmptyViewConfig() {
|
||||
return mEmptyViewConfig;
|
||||
}
|
||||
|
||||
public JSONObject toJSON() throws JSONException {
|
||||
final JSONObject json = new JSONObject();
|
||||
|
||||
|
@ -732,6 +749,10 @@ public final class HomeConfig {
|
|||
json.put(JSON_KEY_FILTER, mFilter);
|
||||
}
|
||||
|
||||
if (mEmptyViewConfig != null) {
|
||||
json.put(JSON_KEY_EMPTY, mEmptyViewConfig.toJSON());
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
|
@ -749,6 +770,7 @@ public final class HomeConfig {
|
|||
dest.writeParcelable(mItemHandler, 0);
|
||||
dest.writeString(mBackImageUrl);
|
||||
dest.writeString(mFilter);
|
||||
dest.writeParcelable(mEmptyViewConfig, 0);
|
||||
}
|
||||
|
||||
public static final Creator<ViewConfig> CREATOR = new Creator<ViewConfig>() {
|
||||
|
@ -764,6 +786,75 @@ public final class HomeConfig {
|
|||
};
|
||||
}
|
||||
|
||||
public static class EmptyViewConfig implements Parcelable {
|
||||
private final String mText;
|
||||
private final String mImageUrl;
|
||||
|
||||
private static final String JSON_KEY_TEXT = "text";
|
||||
private static final String JSON_KEY_IMAGE_URL = "imageUrl";
|
||||
|
||||
public EmptyViewConfig(JSONObject json) throws JSONException, IllegalArgumentException {
|
||||
mText = json.optString(JSON_KEY_TEXT, null);
|
||||
mImageUrl = json.optString(JSON_KEY_IMAGE_URL, null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public EmptyViewConfig(Parcel in) {
|
||||
mText = in.readString();
|
||||
mImageUrl = in.readString();
|
||||
}
|
||||
|
||||
public EmptyViewConfig(EmptyViewConfig emptyViewConfig) {
|
||||
mText = emptyViewConfig.mText;
|
||||
mImageUrl = emptyViewConfig.mImageUrl;
|
||||
}
|
||||
|
||||
public EmptyViewConfig(String text, String imageUrl) {
|
||||
mText = text;
|
||||
mImageUrl = imageUrl;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return mText;
|
||||
}
|
||||
|
||||
public String getImageUrl() {
|
||||
return mImageUrl;
|
||||
}
|
||||
|
||||
public JSONObject toJSON() throws JSONException {
|
||||
final JSONObject json = new JSONObject();
|
||||
|
||||
json.put(JSON_KEY_TEXT, mText);
|
||||
json.put(JSON_KEY_IMAGE_URL, mImageUrl);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(mText);
|
||||
dest.writeString(mImageUrl);
|
||||
}
|
||||
|
||||
public static final Creator<EmptyViewConfig> CREATOR = new Creator<EmptyViewConfig>() {
|
||||
@Override
|
||||
public EmptyViewConfig createFromParcel(final Parcel in) {
|
||||
return new EmptyViewConfig(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmptyViewConfig[] newArray(final int size) {
|
||||
return new EmptyViewConfig[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static class AuthConfig implements Parcelable {
|
||||
private final String mMessageText;
|
||||
private final String mButtonText;
|
||||
|
|
Загрузка…
Ссылка в новой задаче