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