Showing event dates in a decent fashion.
This commit is contained in:
parent
88eda3b268
commit
85d6ed5983
|
@ -42,8 +42,10 @@ public class EventAdapter extends CursorAdapter {
|
|||
public void bindView(View view, Context context, Cursor cursor) {
|
||||
ViewHolder viewHolder = (ViewHolder) view.getTag();
|
||||
viewHolder.titleView.setText(cursor.getString(EventFragment.COL_EVENT_TITLE));
|
||||
viewHolder.dateFromView.setText(cursor.getString(EventFragment.COL_EVENT_DATE_FROM));
|
||||
viewHolder.dateToView.setText(cursor.getString(EventFragment.COL_EVENT_DATE_TO));
|
||||
viewHolder.dateFromView.setText("From: " +
|
||||
Utility.getFriendLyDate(cursor.getString(EventFragment.COL_EVENT_DATE_FROM)));
|
||||
viewHolder.dateToView.setText("Until: " +
|
||||
Utility.getFriendLyDate(cursor.getString(EventFragment.COL_EVENT_DATE_TO)));
|
||||
viewHolder.categoryView.setText(cursor.getString(EventFragment.COL_EVENT_TYPE));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,13 +25,14 @@ public class EventFragment extends Fragment implements LoaderManager.LoaderCallb
|
|||
private static final String SELECTED_KEY = "selected_position";
|
||||
|
||||
static final int COL_EVENT_ID = 0;
|
||||
static final int COL_EVENT_TYPE = 1;
|
||||
static final int COL_EVENT_TITLE = 2;
|
||||
static final int COL_EVENT_DATE_FROM = 3;
|
||||
static final int COL_EVENT_DATE_TO = 4;
|
||||
static final int COL_EVENT_LOCATION = 5;
|
||||
static final int COL_EVENT_DETAILS = 6;
|
||||
static final int COL_EVENT_URL = 7;
|
||||
static final int COL_EVENT_API_ID = 1;
|
||||
static final int COL_EVENT_TYPE = 2;
|
||||
static final int COL_EVENT_TITLE = 3;
|
||||
static final int COL_EVENT_DATE_FROM = 4;
|
||||
static final int COL_EVENT_DATE_TO = 5;
|
||||
static final int COL_EVENT_LOCATION = 6;
|
||||
static final int COL_EVENT_DETAILS = 7;
|
||||
static final int COL_EVENT_URL = 8;
|
||||
|
||||
private static final int EVENT_LOADER = 0;
|
||||
|
||||
|
|
29
app/src/main/java/no/nilsnh/uibevents/Utility.java
Normal file
29
app/src/main/java/no/nilsnh/uibevents/Utility.java
Normal file
|
@ -0,0 +1,29 @@
|
|||
package no.nilsnh.uibevents;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
public class Utility {
|
||||
|
||||
public static String getFriendLyDate(String dateString) {
|
||||
|
||||
SimpleDateFormat dateInputFormat =
|
||||
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.GERMAN);
|
||||
|
||||
SimpleDateFormat dateOutPutFormat =
|
||||
new SimpleDateFormat("dd.MM.yy HH:mm", Locale.GERMAN);
|
||||
|
||||
Date date = null;
|
||||
try {
|
||||
date = dateInputFormat.parse(dateString);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return dateOutPutFormat.format(date);
|
||||
}
|
||||
|
||||
}
|
|
@ -27,21 +27,30 @@
|
|||
android:padding="10dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<TextView
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="@string/list_item_date_from_textview"
|
||||
android:id="@+id/list_item_date_from_textview"
|
||||
android:padding="10dp" />
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="@string/list_item_date_to_textview"
|
||||
android:id="@+id/list_item_date_to_textview"
|
||||
android:padding="10dp" />
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="@string/list_item_date_from_textview"
|
||||
android:id="@+id/list_item_date_from_textview"
|
||||
android:padding="10dp"
|
||||
android:gravity="center_vertical|right" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="@string/list_item_date_to_textview"
|
||||
android:id="@+id/list_item_date_to_textview"
|
||||
android:padding="10dp"
|
||||
android:gravity="center_vertical|right" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
Loading…
Reference in a new issue