Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
MatkovIvan committed Oct 4, 2018
1 parent 7403360 commit 30d0c02
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,29 @@

public class CustomPropertyFragment extends EditDateTimeFragment {

public static final int TYPE_CLEAR = 0;
public static final int TYPE_BOOLEAN = 1;
public static final int TYPE_NUMBER = 2;
public static final int TYPE_DATETIME = 3;
public static final int TYPE_STRING = 4;

private EditText mEditKey;

private Spinner mEditType;

private EditText mEditString;

private EditText mEditNumber;

private CheckBox mEditBool;

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.custom_property, container, false);

/* Find views. */
mEditKey = view.findViewById(R.id.key);
mEditType = view.findViewById(R.id.type);
mEditString = view.findViewById(R.id.string);
mEditNumber = view.findViewById(R.id.number);
mEditBool = view.findViewById(R.id.bool);

/* Set change type callback. */
mEditType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

@Override
Expand All @@ -49,33 +49,32 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
public void onNothingSelected(AdapterView<?> parent) {
}
});

return view;
}

private void updateValueType() {
int type = getType();
mEditString.setVisibility(type == TYPE_STRING ? View.VISIBLE : View.GONE);
mEditNumber.setVisibility(type == TYPE_NUMBER ? View.VISIBLE : View.GONE);
mEditBool.setVisibility(type == TYPE_BOOLEAN ? View.VISIBLE : View.GONE);
mDateTime.setVisibility(type == TYPE_DATETIME ? View.VISIBLE : View.GONE);
CustomPropertyType type = getType();
mEditString.setVisibility(type == CustomPropertyType.STRING ? View.VISIBLE : View.GONE);
mEditNumber.setVisibility(type == CustomPropertyType.NUMBER ? View.VISIBLE : View.GONE);
mEditBool.setVisibility(type == CustomPropertyType.BOOLEAN ? View.VISIBLE : View.GONE);
mDateTime.setVisibility(type == CustomPropertyType.DATETIME ? View.VISIBLE : View.GONE);
}

public int getType() {
return mEditType.getSelectedItemPosition();
public CustomPropertyType getType() {
return CustomPropertyType.values()[mEditType.getSelectedItemPosition()];
}

public void set(CustomProperties customProperties) {
int type = getType();
CustomPropertyType type = getType();
String key = mEditKey.getText().toString();
switch (type) {
case TYPE_CLEAR:
case CLEAR:
customProperties.clear(key);
break;
case TYPE_BOOLEAN:
case BOOLEAN:
customProperties.set(key, mEditBool.isChecked());
break;
case TYPE_NUMBER:
case NUMBER:
String stringValue = mEditNumber.getText().toString();
Number value;
try {
Expand All @@ -85,12 +84,20 @@ public void set(CustomProperties customProperties) {
}
customProperties.set(key, value);
break;
case TYPE_DATETIME:
case DATETIME:
customProperties.set(key, mDate);
break;
case TYPE_STRING:
case STRING:
customProperties.set(key, mEditString.getText().toString());
break;
}
}

public enum CustomPropertyType {
CLEAR,
BOOLEAN,
NUMBER,
DATETIME,
STRING
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,22 @@ public abstract class EditDateTimeFragment extends Fragment
implements DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener {

private EditText mEditDate;

private EditText mEditTime;

protected View mDateTime;

protected Date mDate;

@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {

/* Find views. */
mEditDate = view.findViewById(R.id.date);
mEditTime = view.findViewById(R.id.time);
mDateTime = view.findViewById(R.id.datetime);

/* Set listeners. */
mEditDate.setOnClickListener(new View.OnClickListener() {

@Override
Expand All @@ -47,6 +52,7 @@ public void onClick(View view) {
}
});

/* Set the current date. */
setDate(new Date());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private void addProperty() {

private boolean onlyStringProperties() {
for (TypedPropertyFragment fragment : mProperties) {
if (fragment.getType() != TypedPropertyFragment.TYPE_STRING) {
if (fragment.getType() != TypedPropertyFragment.EventPropertyType.STRING) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,32 @@
// TODO move to main folder once new APIs available in jCenter
public class TypedPropertyFragment extends EditDateTimeFragment {

public static final int TYPE_BOOLEAN = 0;
public static final int TYPE_NUMBER_DOUBLE = 1;
public static final int TYPE_NUMBER_LONG = 2;
public static final int TYPE_DATETIME = 3;
public static final int TYPE_STRING = 4;

private EditText mEditKey;

private Spinner mEditType;

private EditText mEditString;

private EditText mEditNumberDouble;

private EditText mEditNumberLong;

private CheckBox mEditBool;

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.typed_property, container, false);

/* Find views. */
mEditKey = view.findViewById(R.id.key);
mEditType = view.findViewById(R.id.type);
mEditString = view.findViewById(R.id.string);
mEditNumberDouble = view.findViewById(R.id.number_double);
mEditNumberLong = view.findViewById(R.id.number_long);
mEditBool = view.findViewById(R.id.bool);

/* Set change type callback. */
mEditType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

@Override
Expand All @@ -54,58 +55,65 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
public void onNothingSelected(AdapterView<?> parent) {
}
});

return view;
}

private void updateValueType() {
int type = getType();
mEditString.setVisibility(type == TYPE_STRING ? View.VISIBLE : View.GONE);
mEditBool.setVisibility(type == TYPE_BOOLEAN ? View.VISIBLE : View.GONE);
mEditNumberDouble.setVisibility(type == TYPE_NUMBER_DOUBLE ? View.VISIBLE : View.GONE);
mEditNumberLong.setVisibility(type == TYPE_NUMBER_LONG ? View.VISIBLE : View.GONE);
mDateTime.setVisibility(type == TYPE_DATETIME ? View.VISIBLE : View.GONE);
EventPropertyType type = getType();
mEditString.setVisibility(type == EventPropertyType.STRING ? View.VISIBLE : View.GONE);
mEditBool.setVisibility(type == EventPropertyType.BOOLEAN ? View.VISIBLE : View.GONE);
mEditNumberDouble.setVisibility(type == EventPropertyType.NUMBER_DOUBLE ? View.VISIBLE : View.GONE);
mEditNumberLong.setVisibility(type == EventPropertyType.NUMBER_LONG ? View.VISIBLE : View.GONE);
mDateTime.setVisibility(type == EventPropertyType.DATETIME ? View.VISIBLE : View.GONE);
}

public int getType() {
return mEditType.getSelectedItemPosition();
public EventPropertyType getType() {
return EventPropertyType.values()[mEditType.getSelectedItemPosition()];
}

public void set(Map<String, String> eventProperties) {
int type = getType();
EventPropertyType type = getType();
String key = mEditKey.getText().toString();
switch (type) {
case TYPE_STRING:
case STRING:
eventProperties.put(key, mEditString.getText().toString());
break;
}
}

public void set(EventProperties eventProperties) {
int type = getType();
EventPropertyType type = getType();
String key = mEditKey.getText().toString();
switch (type) {
case TYPE_BOOLEAN:
case BOOLEAN:
eventProperties.set(key, mEditBool.isChecked());
break;
case TYPE_NUMBER_DOUBLE: {
case NUMBER_DOUBLE: {
String stringValue = mEditNumberDouble.getText().toString();
Double value = Double.parseDouble(stringValue);
eventProperties.set(key, value);
break;
}
case TYPE_NUMBER_LONG: {
case NUMBER_LONG: {
String stringValue = mEditNumberLong.getText().toString();
Long value = Long.parseLong(stringValue);
eventProperties.set(key, value);
break;
}
case TYPE_DATETIME:
case DATETIME:
eventProperties.set(key, mDate);
break;
case TYPE_STRING:
case STRING:
eventProperties.set(key, mEditString.getText().toString());
break;
}
}

public enum EventPropertyType {
BOOLEAN,
NUMBER_DOUBLE,
NUMBER_LONG,
DATETIME,
STRING
}
}

0 comments on commit 30d0c02

Please sign in to comment.