Commit 246821de authored by Marcin Wiacek's avatar Marcin Wiacek Committed by Commit Bot

Migrate DetailsField to @IntDef

@IntDef annotation are preferred way for declaring set of int values.

1. they need less space in APK than enum, see
https://developer.android.com/topic/performance/reduce-apk-size#remove-enums
2. they give more control over allowed values than "static final" values

Main goal of patch is replacing DetailsField enum to the style common with other @IntDef:

1. with @IntDef first, @Retention second
   and related @interface third
2. with values inside @interface
3. with @Retention(RetentionPolicy.SOURCE)
4. without "static final" in the @interface


Change-Id: I4e551520fd51c23a60f5d9d561fb23f6f0e93909
Reviewed-on: https://chromium-review.googlesource.com/c/1350901Reviewed-by: default avatarMathias Carlen <mcarlen@chromium.org>
Commit-Queue: Marcin Wiącek <marcin@mwiacek.com>
Cr-Commit-Position: refs/heads/master@{#611498}
parent 39536eb8
...@@ -4,10 +4,13 @@ ...@@ -4,10 +4,13 @@
package org.chromium.chrome.browser.autofill_assistant; package org.chromium.chrome.browser.autofill_assistant;
import android.support.annotation.IntDef;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import org.json.JSONObject; import org.json.JSONObject;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Collections; import java.util.Collections;
...@@ -22,7 +25,17 @@ import java.util.Set; ...@@ -22,7 +25,17 @@ import java.util.Set;
* Java side equivalent of autofill_assistant::DetailsProto. * Java side equivalent of autofill_assistant::DetailsProto.
*/ */
class Details { class Details {
enum DetailsField { TITLE, URL, DATE, DESCRIPTION, MID, IS_FINAL } @IntDef({DetailsField.TITLE, DetailsField.URL, DetailsField.DATE, DetailsField.DESCRIPTION,
DetailsField.MID, DetailsField.IS_FINAL})
@Retention(RetentionPolicy.SOURCE)
public @interface DetailsField {
int TITLE = 0;
int URL = 1;
int DATE = 2;
int DESCRIPTION = 3;
int MID = 4;
int IS_FINAL = 5;
}
private final String mTitle; private final String mTitle;
private final String mUrl; private final String mUrl;
...@@ -32,7 +45,7 @@ class Details { ...@@ -32,7 +45,7 @@ class Details {
private final String mMid; private final String mMid;
private final boolean mIsFinal; private final boolean mIsFinal;
/** Contains the fields that have changed when merging with other Details object. */ /** Contains the fields that have changed when merging with other Details object. */
private final Set<DetailsField> mFieldsChanged; private final Set<Integer> mFieldsChanged;
// NOTE: When adding a new field, update the isEmpty and toJSONObject methods. // NOTE: When adding a new field, update the isEmpty and toJSONObject methods.
static final Details EMPTY_DETAILS = static final Details EMPTY_DETAILS =
...@@ -41,7 +54,7 @@ class Details { ...@@ -41,7 +54,7 @@ class Details {
private static final String RFC_3339_FORMAT_WITHOUT_TIMEZONE = "yyyy'-'MM'-'dd'T'HH':'mm':'ss"; private static final String RFC_3339_FORMAT_WITHOUT_TIMEZONE = "yyyy'-'MM'-'dd'T'HH':'mm':'ss";
Details(String title, String url, @Nullable Date date, String description, String mId, Details(String title, String url, @Nullable Date date, String description, String mId,
boolean isFinal, Set<DetailsField> fieldsChanged) { boolean isFinal, Set<Integer> fieldsChanged) {
this.mTitle = title; this.mTitle = title;
this.mUrl = url; this.mUrl = url;
this.mDate = date; this.mDate = date;
...@@ -91,7 +104,7 @@ class Details { ...@@ -91,7 +104,7 @@ class Details {
return mIsFinal; return mIsFinal;
} }
Set<DetailsField> getFieldsChanged() { Set<Integer> getFieldsChanged() {
return mFieldsChanged; return mFieldsChanged;
} }
...@@ -154,7 +167,7 @@ class Details { ...@@ -154,7 +167,7 @@ class Details {
Collections.emptySet()); Collections.emptySet());
} }
Set<DetailsField> changedFields = new HashSet<>(); Set<Integer> changedFields = new HashSet<>();
String title = oldDetails.getTitle(); String title = oldDetails.getTitle();
String mId = oldDetails.getMid(); String mId = oldDetails.getMid();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment