mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Format short dates for list item fragments
This commit is contained in:
parent
f0f760315f
commit
4443594480
9 changed files with 38 additions and 12 deletions
|
@ -61,7 +61,7 @@ public class AllSharedStoriesItemListFragment extends ItemListFragment implement
|
|||
|
||||
contentResolver = getActivity().getContentResolver();
|
||||
|
||||
String[] groupFrom = new String[] { DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_AUTHORS, DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_SHORTDATE, DatabaseConstants.STORY_INTELLIGENCE_AUTHORS, DatabaseConstants.FEED_TITLE };
|
||||
String[] groupFrom = new String[] { DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_AUTHORS, DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_DATE, DatabaseConstants.STORY_INTELLIGENCE_AUTHORS, DatabaseConstants.FEED_TITLE };
|
||||
int[] groupTo = new int[] { R.id.row_item_title, R.id.row_item_author, R.id.row_item_title, R.id.row_item_date, R.id.row_item_sidebar, R.id.row_item_feedtitle };
|
||||
// TODO: defer creation of the adapter until the loader's first callback so we don't leak this first ListView cursor
|
||||
Cursor cursor = contentResolver.query(FeedProvider.ALL_SHARED_STORIES_URI, null, DatabaseConstants.getStorySelectionFromState(currentState), null, DatabaseConstants.getStorySortOrder(storyOrder));
|
||||
|
|
|
@ -59,7 +59,7 @@ public class AllStoriesItemListFragment extends StoryItemListFragment implements
|
|||
|
||||
Cursor cursor = getActivity().getContentResolver().query(FeedProvider.ALL_STORIES_URI, null, DatabaseConstants.getStorySelectionFromState(currentState), null, DatabaseConstants.getStorySortOrder(storyOrder));
|
||||
getActivity().startManagingCursor(cursor);
|
||||
String[] groupFrom = new String[] { DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_AUTHORS, DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_SHORTDATE, DatabaseConstants.STORY_INTELLIGENCE_AUTHORS, DatabaseConstants.FEED_TITLE };
|
||||
String[] groupFrom = new String[] { DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_AUTHORS, DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_DATE, DatabaseConstants.STORY_INTELLIGENCE_AUTHORS, DatabaseConstants.FEED_TITLE };
|
||||
int[] groupTo = new int[] { R.id.row_item_title, R.id.row_item_author, R.id.row_item_title, R.id.row_item_date, R.id.row_item_sidebar, R.id.row_item_feedtitle };
|
||||
|
||||
adapter = new MultipleFeedItemsAdapter(getActivity(), R.layout.row_socialitem, cursor, groupFrom, groupTo, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
|
||||
|
|
|
@ -88,7 +88,7 @@ public class FeedItemListFragment extends StoryItemListFragment implements Loade
|
|||
Feed feed = Feed.fromCursor(feedCursor);
|
||||
feedCursor.close();
|
||||
|
||||
String[] groupFrom = new String[] { DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_AUTHORS, DatabaseConstants.STORY_READ, DatabaseConstants.STORY_SHORTDATE, DatabaseConstants.STORY_INTELLIGENCE_AUTHORS };
|
||||
String[] groupFrom = new String[] { DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_AUTHORS, DatabaseConstants.STORY_READ, DatabaseConstants.STORY_DATE, DatabaseConstants.STORY_INTELLIGENCE_AUTHORS };
|
||||
int[] groupTo = new int[] { R.id.row_item_title, R.id.row_item_author, R.id.row_item_title, R.id.row_item_date, R.id.row_item_sidebar };
|
||||
|
||||
// create the adapter before starting the loader, since the callback updates the adapter
|
||||
|
|
|
@ -83,7 +83,7 @@ public class FolderItemListFragment extends StoryItemListFragment implements Loa
|
|||
Cursor cursor = contentResolver.query(FeedProvider.MULTIFEED_STORIES_URI, null, DatabaseConstants.getStorySelectionFromState(currentState), feedIds, DatabaseConstants.getStorySortOrder(storyOrder));
|
||||
getActivity().startManagingCursor(cursor);
|
||||
|
||||
String[] groupFrom = new String[] { DatabaseConstants.STORY_TITLE, DatabaseConstants.FEED_TITLE, DatabaseConstants.STORY_READ, DatabaseConstants.STORY_SHORTDATE, DatabaseConstants.STORY_INTELLIGENCE_AUTHORS, DatabaseConstants.STORY_AUTHORS };
|
||||
String[] groupFrom = new String[] { DatabaseConstants.STORY_TITLE, DatabaseConstants.FEED_TITLE, DatabaseConstants.STORY_READ, DatabaseConstants.STORY_DATE, DatabaseConstants.STORY_INTELLIGENCE_AUTHORS, DatabaseConstants.STORY_AUTHORS };
|
||||
int[] groupTo = new int[] { R.id.row_item_title, R.id.row_item_feedtitle, R.id.row_item_title, R.id.row_item_date, R.id.row_item_sidebar, R.id.row_item_author };
|
||||
|
||||
getLoaderManager().initLoader(ITEMLIST_LOADER , null, this);
|
||||
|
|
|
@ -52,7 +52,7 @@ public class SavedStoriesItemListFragment extends ItemListFragment implements Lo
|
|||
contentResolver = getActivity().getContentResolver();
|
||||
Cursor cursor = contentResolver.query(FeedProvider.STARRED_STORIES_URI, null, null, null, DatabaseConstants.STARRED_STORY_ORDER);
|
||||
|
||||
String[] groupFrom = new String[] { DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_AUTHORS, DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_SHORTDATE, DatabaseConstants.STORY_INTELLIGENCE_AUTHORS, DatabaseConstants.FEED_TITLE };
|
||||
String[] groupFrom = new String[] { DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_AUTHORS, DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_DATE, DatabaseConstants.STORY_INTELLIGENCE_AUTHORS, DatabaseConstants.FEED_TITLE };
|
||||
int[] groupTo = new int[] { R.id.row_item_title, R.id.row_item_author, R.id.row_item_title, R.id.row_item_date, R.id.row_item_sidebar, R.id.row_item_feedtitle };
|
||||
|
||||
getLoaderManager().initLoader(ITEMLIST_LOADER , null, this);
|
||||
|
|
|
@ -60,7 +60,7 @@ public class SocialFeedItemListFragment extends ItemListFragment implements Load
|
|||
Uri uri = FeedProvider.SOCIALFEED_STORIES_URI.buildUpon().appendPath(userId).build();
|
||||
Cursor cursor = getActivity().getContentResolver().query(uri, null, DatabaseConstants.getStorySelectionFromState(currentState), null, DatabaseConstants.getStorySharedSortOrder(storyOrder));
|
||||
|
||||
groupFroms = new String[] { DatabaseConstants.FEED_FAVICON_URL, DatabaseConstants.FEED_TITLE, DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_SHORTDATE, DatabaseConstants.STORY_AUTHORS, DatabaseConstants.STORY_INTELLIGENCE_AUTHORS};
|
||||
groupFroms = new String[] { DatabaseConstants.FEED_FAVICON_URL, DatabaseConstants.FEED_TITLE, DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_DATE, DatabaseConstants.STORY_AUTHORS, DatabaseConstants.STORY_INTELLIGENCE_AUTHORS};
|
||||
groupTos = new int[] { R.id.row_item_feedicon, R.id.row_item_feedtitle, R.id.row_item_title, R.id.row_item_date, R.id.row_item_author, R.id.row_item_sidebar};
|
||||
|
||||
adapter = new MultipleFeedItemsAdapter(getActivity(), R.layout.row_socialitem, cursor, groupFroms, groupTos, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
|
||||
|
|
|
@ -13,6 +13,7 @@ public class StoryUtils {
|
|||
private static final SimpleDateFormat monthLongFormat = new SimpleDateFormat("EEEE, MMMM d");
|
||||
private static final SimpleDateFormat yearLongFormat = new SimpleDateFormat("yyyy");
|
||||
private static final SimpleDateFormat twelveHourFormat = new SimpleDateFormat("h:mma");
|
||||
private static final SimpleDateFormat shortDateFormat = new SimpleDateFormat("d MMM yyyy");
|
||||
|
||||
public static String formatLongDate(Date storyDate) {
|
||||
|
||||
|
@ -24,10 +25,6 @@ public class StoryUtils {
|
|||
storyCalendar.setTime(storyDate);
|
||||
int month = storyCalendar.get(Calendar.DAY_OF_MONTH);
|
||||
|
||||
// F = Long Month
|
||||
// l = Long Day
|
||||
// j = day number
|
||||
// S = st/th etc.
|
||||
if (storyDate.getTime() > midnightToday.getTime()) {
|
||||
// Today, January 1st 00:00
|
||||
return "Today, " + todayLongFormat.format(storyDate) + getDayOfMonthSuffix(month) + " " + twelveHourFormat.format(storyDate);
|
||||
|
@ -78,4 +75,21 @@ public class StoryUtils {
|
|||
default: return "th";
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatShortDate(Date storyDate) {
|
||||
|
||||
Date midnightToday = midnightToday();
|
||||
Date midnightYesterday = midnightYesterday();
|
||||
|
||||
if (storyDate.getTime() > midnightToday.getTime()) {
|
||||
// 00:00
|
||||
return twelveHourFormat.format(storyDate);
|
||||
} else if (storyDate.getTime() > midnightYesterday.getTime()) {
|
||||
// Yesterday, 00:00
|
||||
return "Yesterday, " + twelveHourFormat.format(storyDate);
|
||||
} else {
|
||||
// 1 Jan 2014, 00:00
|
||||
return shortDateFormat.format(storyDate) +", " + twelveHourFormat.format(storyDate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,9 @@ import android.widget.TextView;
|
|||
import com.newsblur.R;
|
||||
import com.newsblur.database.DatabaseConstants;
|
||||
import com.newsblur.domain.Story;
|
||||
import com.newsblur.util.StoryUtils;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class FeedItemViewBinder implements ViewBinder {
|
||||
|
||||
|
@ -68,7 +71,10 @@ public class FeedItemViewBinder implements ViewBinder {
|
|||
} else if (TextUtils.equals(columnName, DatabaseConstants.STORY_TITLE)) {
|
||||
((TextView) view).setText(Html.fromHtml(cursor.getString(columnIndex)));
|
||||
return true;
|
||||
}
|
||||
} else if (TextUtils.equals(columnName, DatabaseConstants.STORY_DATE)) {
|
||||
((TextView) view).setText(StoryUtils.formatShortDate(new Date(cursor.getLong(columnIndex))));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,9 @@ import com.newsblur.activity.NewsBlurApplication;
|
|||
import com.newsblur.database.DatabaseConstants;
|
||||
import com.newsblur.domain.Story;
|
||||
import com.newsblur.util.ImageLoader;
|
||||
import com.newsblur.util.StoryUtils;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class SocialItemViewBinder implements ViewBinder {
|
||||
|
||||
|
@ -72,7 +75,10 @@ public class SocialItemViewBinder implements ViewBinder {
|
|||
} else if (TextUtils.equals(columnName, DatabaseConstants.STORY_TITLE)) {
|
||||
((TextView) view).setText(Html.fromHtml(cursor.getString(columnIndex)));
|
||||
return true;
|
||||
}
|
||||
} else if (TextUtils.equals(columnName, DatabaseConstants.STORY_DATE)) {
|
||||
((TextView) view).setText(StoryUtils.formatShortDate(new Date(cursor.getLong(columnIndex))));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue