Commit 0e9da290 by Kunj Gupta

Fix - In My Incidents screen, record shuold be sorted according to date.

parent f3c9603d
...@@ -9,6 +9,7 @@ import android.widget.TextView; ...@@ -9,6 +9,7 @@ import android.widget.TextView;
import com.vsoft.uoflservicenow.R; import com.vsoft.uoflservicenow.R;
import com.vsoft.uoflservicenow.db.models.Incident; import com.vsoft.uoflservicenow.db.models.Incident;
import com.vsoft.uoflservicenow.utils.Util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -68,7 +69,7 @@ public class MyIncidentsAdapter extends BaseAdapter { ...@@ -68,7 +69,7 @@ public class MyIncidentsAdapter extends BaseAdapter {
Incident incident = mIncidentList.get(position); Incident incident = mIncidentList.get(position);
holder.numberTextView.setText(incident.getNumber()); holder.numberTextView.setText(incident.getNumber());
holder.dateTextView.setText(incident.getOpenedAt()); holder.dateTextView.setText(Util.getDateTimeFromLong(incident.getOpenedAt()));
holder.shortDesTextView.setText(incident.getShortDescription()); holder.shortDesTextView.setText(incident.getShortDescription());
return convertView; return convertView;
......
...@@ -21,7 +21,7 @@ public class Incident { ...@@ -21,7 +21,7 @@ public class Incident {
private String shortDescription; private String shortDescription;
@SerializedName("opened_at") @SerializedName("opened_at")
// @Expose // @Expose
private String openedAt; private long openedAt;
@SerializedName("impact") @SerializedName("impact")
// @Expose // @Expose
private Impact impact; private Impact impact;
...@@ -34,11 +34,11 @@ public class Incident { ...@@ -34,11 +34,11 @@ public class Incident {
this.impact = impact; this.impact = impact;
} }
public String getOpenedAt() { public long getOpenedAt() {
return openedAt; return openedAt;
} }
public void setOpenedAt(String openedAt) { public void setOpenedAt(long openedAt) {
this.openedAt = openedAt; this.openedAt = openedAt;
} }
...@@ -68,7 +68,7 @@ public class Incident { ...@@ -68,7 +68,7 @@ public class Incident {
e.printStackTrace(); e.printStackTrace();
} }
this.setOpenedAt(Util.getDateTime(openedAt)); this.setOpenedAt(Util.getDateTimeForMyIncidentFromString(openedAt));
this.setImpact(Impact.from(impact)); this.setImpact(Impact.from(impact));
} }
......
...@@ -22,6 +22,8 @@ import com.vsoft.uoflservicenow.enums.SyncStatus; ...@@ -22,6 +22,8 @@ import com.vsoft.uoflservicenow.enums.SyncStatus;
import com.vsoft.uoflservicenow.utils.CatalogueLog; import com.vsoft.uoflservicenow.utils.CatalogueLog;
import com.vsoft.uoflservicenow.utils.Util; import com.vsoft.uoflservicenow.utils.Util;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import butterknife.BindView; import butterknife.BindView;
...@@ -134,10 +136,19 @@ public class MyIncidentScreen extends AppCompatActivity { ...@@ -134,10 +136,19 @@ public class MyIncidentScreen extends AppCompatActivity {
private void setData(final List<Incident> catalogueList) { private void setData(final List<Incident> catalogueList) {
MyIncidentsAdapter adapter = new MyIncidentsAdapter(MyIncidentScreen.this); MyIncidentsAdapter adapter = new MyIncidentsAdapter(MyIncidentScreen.this);
Collections.sort(catalogueList, new StringDateComparator());
adapter.setIncidentList(catalogueList); adapter.setIncidentList(catalogueList);
mListView.setAdapter(adapter); mListView.setAdapter(adapter);
} }
class StringDateComparator implements Comparator<Incident> {
public int compare(Incident lhs, Incident rhs) {
return lhs.getOpenedAt()>rhs.getOpenedAt() ? -1 : 1;
}
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem menuItem) { public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == android.R.id.home) { if (menuItem.getItemId() == android.R.id.home) {
......
...@@ -271,7 +271,7 @@ public class Util { ...@@ -271,7 +271,7 @@ public class Util {
return dateFormat.format(timeStamp); return dateFormat.format(timeStamp);
} }
public static String getDateTime(String strDate) { 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", Locale.US);
Date date = null; Date date = null;
try { try {
...@@ -279,10 +279,7 @@ public class Util { ...@@ -279,10 +279,7 @@ public class Util {
} catch (ParseException e) { } catch (ParseException e) {
e.printStackTrace(); e.printStackTrace();
} }
return date.getTime();
SimpleDateFormat dateFormat = new SimpleDateFormat
("dd MMM, yyyy HH:mm", Locale.US);
return dateFormat.format(date.getTime());
} }
/*Record a screen view hit for the visible*/ /*Record a screen view hit for the visible*/
......
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