Commit ceab0740 by Kunj Gupta

UOFLMA-89: Fix - App is force closed when we clicked on date button.

parent b4bf90c9
......@@ -20,6 +20,7 @@ import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.LinearLayout;
......@@ -350,9 +351,9 @@ public class CatalogueVariableScreen extends AppCompatActivity {
String jsonColumnValue = value;
/*Convert date and time long value to string for server communication*/
if(viewType == ViewType.DATE) {
jsonColumnValue = Util.getDateFromLong(Long.parseLong(value));
jsonColumnValue = Util.getDateFromLong(Util.getDateFromString(value));
} else if(viewType == ViewType.DATE_AND_TIME) {
jsonColumnValue = Util.getDateTimeFromLong(Long.parseLong(value));
jsonColumnValue = Util.getDateTime(Util.getDateTimeFromString(value));
}
if(viewType != ViewType.SELECT_BOX) {
......@@ -423,14 +424,20 @@ public class CatalogueVariableScreen extends AppCompatActivity {
DatePickerDialog.OnDateSetListener dateListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
((TextView)v).setText(String.format(getString(R.string.date_string), (dayOfMonth < 10 ? "0" + dayOfMonth : dayOfMonth), getMonth(monthOfYear), year));
((Button)v).setText(String.format(getString(R.string.date_string), (dayOfMonth < 10 ? "0" + dayOfMonth : dayOfMonth), getMonth(monthOfYear), year));
}
};
TimePickerDialog.OnTimeSetListener timeListener = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
((TextView)v).append(String.format(getString(R.string.date_and_time_string), (hourOfDay < 10 ? "0" + hourOfDay : hourOfDay), (minute < 10 ? "0" + minute : minute)));
Button button = (Button)v;
String existText = button.getText().toString();
StringBuilder builder = new StringBuilder();
builder.append(existText);
builder.append(" ");
builder.append(String.format(getString(R.string.date_and_time_string), (hourOfDay < 10 ? "0" + hourOfDay : hourOfDay), (minute < 10 ? "0" + minute : minute)));
button.setText(builder.toString());
}
};
......
......@@ -31,7 +31,6 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
/**
* Created by Kunj on 12/8/16.
......@@ -100,7 +99,7 @@ public class Util {
return dateTextButton;
case DATE_AND_TIME:
Button dateTimeButton = new Button(context);
dateTimeButton.setText(getDefaultDate() + " " + getDefaultTime());
dateTimeButton.setText(getDefaultDateTime()/* + " " + getDefaultTime()*/);
dateTimeButton.setGravity(Gravity.CENTER_VERTICAL);
return dateTimeButton;
case REFERENCE:
......@@ -208,10 +207,10 @@ public class Util {
return wideSingleLineEditText.getText().toString();
case DATE:
Button dateTextButton = (Button) view;
return ""+ getDateFromString(dateTextButton.getText().toString());
return dateTextButton.getText().toString();
case DATE_AND_TIME:
Button dateTimeButton = (Button) view;
return ""+ getDateTimeFromString(dateTimeButton.getText().toString());
return dateTimeButton.getText().toString();
case REFERENCE:
TagObject tagObject = (TagObject) view.getTag();
Reference reference = (Reference)tagObject.getTagObject();
......@@ -244,19 +243,18 @@ public class Util {
public static String getDefaultDate() {
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("dd MMM, yyyy", Locale.US);
SimpleDateFormat df = new SimpleDateFormat("dd MMM, yyyy");
return df.format(c.getTime());
}
public static String getDefaultTime() {
public static String getDefaultDateTime() {
Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int min = c.get(Calendar.MINUTE);
return (hour < 10 ? ("0" + hour) : hour) + ":" + (min < 10 ? ("0" + min) : min);
SimpleDateFormat df = new SimpleDateFormat("dd MMM, yyyy HH:mm");
return df.format(c.getTime());
}
public static long getDateFromString(String strDate) {
SimpleDateFormat df = new SimpleDateFormat("dd MMM, yyyy", Locale.US);
SimpleDateFormat df = new SimpleDateFormat("dd MMM, yyyy");
Date date = null;
try {
date = df.parse(strDate);
......@@ -266,14 +264,8 @@ public class Util {
return date.getTime();
}
public static String getDateFromLong(long timeStamp) {
SimpleDateFormat dateFormat = new SimpleDateFormat
("yyyy-MM-dd", Locale.US);
return dateFormat.format(timeStamp);
}
public static long getDateTimeFromString(String strDate) {
SimpleDateFormat df = new SimpleDateFormat("dd MMM, yyyy HH:mm", Locale.US);
SimpleDateFormat df = new SimpleDateFormat("dd MMM, yyyy HH:mm");
Date date = null;
try {
date = df.parse(strDate);
......@@ -283,14 +275,24 @@ public class Util {
return date.getTime();
}
public static String getDateFromLong(long timeStamp) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
return dateFormat.format(timeStamp);
}
public static String getDateTime(long timeStamp) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
return dateFormat.format(timeStamp);
}
public static String getDateTimeFromLong(long timeStamp) {
SimpleDateFormat dateFormat = new SimpleDateFormat
("dd MMM, yyyy HH:mm", Locale.US);
("dd MMM, yyyy HH:mm");
return dateFormat.format(timeStamp);
}
public static long getDateTimeForMyIncidentFromString(String strDate) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = df.parse(strDate);
......@@ -301,7 +303,7 @@ public class Util {
}
public static long getDateTimeForMyRequestFromString(String strDate) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = df.parse(strDate);
......
......@@ -25,7 +25,7 @@
<string name="rejected">Rejected</string>
<string name="date_string">%1$s %2$s, %3$s</string>
<string name="date_and_time_string"> %1$s:%2$s</string>
<string name="date_and_time_string">%1$s:%2$s</string>
<!--Failed to fetch-->
<string name="failed_to_fetch_catalogue_category_string">Failed to fetch Catalogue Category.</string>
......
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 sign in to comment