mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Android widget date time format. Exclude hidden stories in widget
This commit is contained in:
parent
4323aeb0f9
commit
f1f89c3573
5 changed files with 43 additions and 9 deletions
|
@ -179,7 +179,7 @@ public class WidgetConfig extends NbActivity {
|
|||
ArrayList<Feed> feeds = new ArrayList<>();
|
||||
while (cursor != null && cursor.moveToNext()) {
|
||||
Feed feed = Feed.fromCursor(cursor);
|
||||
if (!feed.feedId.equals("0") && feed.active) {
|
||||
if (feed.active) {
|
||||
feeds.add(feed);
|
||||
feedMap.put(feed.feedId, feed);
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ import com.newsblur.util.PrefConstants;
|
|||
import com.newsblur.util.PrefsUtils;
|
||||
import com.newsblur.util.ReadFilter;
|
||||
import com.newsblur.util.StoryOrder;
|
||||
import com.newsblur.widget.WidgetUtils;
|
||||
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
@ -296,7 +297,13 @@ public class APIManager {
|
|||
ValueMultimap values = new ValueMultimap();
|
||||
|
||||
// create the URI and populate request params depending on what kind of stories we want
|
||||
if (fs.getSingleFeed() != null) {
|
||||
if (fs.isForWidget()) {
|
||||
uri = Uri.parse(buildUrl(APIConstants.PATH_RIVER_STORIES));
|
||||
for (String feedId : fs.getAllFeeds()) values.put(APIConstants.PARAMETER_FEEDS, feedId);
|
||||
values.put(APIConstants.PARAMETER_INCLUDE_HIDDEN, APIConstants.VALUE_FALSE);
|
||||
values.put(APIConstants.PARAMETER_INFREQUENT, APIConstants.VALUE_FALSE);
|
||||
values.put(APIConstants.PARAMETER_LIMIT, String.valueOf(WidgetUtils.STORIES_LIMIT));
|
||||
} else if (fs.getSingleFeed() != null) {
|
||||
uri = Uri.parse(buildUrl(APIConstants.PATH_FEED_STORIES)).buildUpon().appendPath(fs.getSingleFeed()).build();
|
||||
values.put(APIConstants.PARAMETER_FEEDS, fs.getSingleFeed());
|
||||
values.put(APIConstants.PARAMETER_INCLUDE_HIDDEN, APIConstants.VALUE_TRUE);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.newsblur.util;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
@ -29,6 +30,7 @@ public class FeedSet implements Serializable {
|
|||
private boolean isAllRead;
|
||||
private boolean isGlobalShared;
|
||||
private boolean isInfrequent;
|
||||
private boolean isForWidget;
|
||||
|
||||
private String folderName;
|
||||
private String searchQuery;
|
||||
|
@ -149,6 +151,22 @@ public class FeedSet implements Serializable {
|
|||
return fs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience constructor for widget feed.
|
||||
*/
|
||||
public static FeedSet widgetFeeds(@Nullable Set<String> feedIds){
|
||||
FeedSet fs = new FeedSet();
|
||||
fs.isForWidget = true;
|
||||
if (feedIds != null) {
|
||||
fs.feeds = new HashSet<>(feedIds.size());
|
||||
fs.feeds.addAll(feedIds);
|
||||
fs.feeds = Collections.unmodifiableSet(fs.feeds);
|
||||
} else {
|
||||
fs.feeds = Collections.EMPTY_SET;
|
||||
}
|
||||
return fs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience constructor for a folder.
|
||||
*/
|
||||
|
@ -174,6 +192,13 @@ public class FeedSet implements Serializable {
|
|||
if (feeds != null && ((feeds.size() > 1) || (folderName != null))) return feeds; else return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a set of all feed IDs if there are any or null otherwise.
|
||||
*/
|
||||
public Set<String> getAllFeeds() {
|
||||
if (feeds != null) return feeds; else return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a single social feed ID and username iff there is only one or null otherwise.
|
||||
*/
|
||||
|
@ -212,6 +237,10 @@ public class FeedSet implements Serializable {
|
|||
return ((savedTags != null) && (savedTags.size() == 1));
|
||||
}
|
||||
|
||||
public boolean isForWidget() {
|
||||
return this.isForWidget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a single saved tag iff there is only one or null otherwise.
|
||||
*/
|
||||
|
|
|
@ -94,7 +94,7 @@ public class WidgetRemoteViewsFactory implements RemoteViewsService.RemoteViewsF
|
|||
rv.setTextViewText(R.id.story_item_content, story.shortContent);
|
||||
rv.setTextViewText(R.id.story_item_author, story.authors);
|
||||
rv.setTextViewText(R.id.story_item_feedtitle, story.extern_feedTitle);
|
||||
CharSequence time = StoryUtils.formatRelativeTime(context, story.timestamp);
|
||||
CharSequence time = StoryUtils.formatShortDate(context, story.timestamp);
|
||||
rv.setTextViewText(R.id.story_item_date, time);
|
||||
|
||||
// image dimensions same as R.layout.view_widget_story_item
|
||||
|
@ -205,7 +205,7 @@ public class WidgetRemoteViewsFactory implements RemoteViewsService.RemoteViewsF
|
|||
*/
|
||||
@Override
|
||||
public int getCount() {
|
||||
return Math.min(storyItems.size(), 5);
|
||||
return Math.min(storyItems.size(), WidgetUtils.STORIES_LIMIT);
|
||||
}
|
||||
|
||||
private void processStories(final Story[] stories) {
|
||||
|
@ -259,11 +259,8 @@ public class WidgetRemoteViewsFactory implements RemoteViewsService.RemoteViewsF
|
|||
|
||||
private void setFeedSet() {
|
||||
Set<String> feedIds = PrefsUtils.getWidgetFeedIds(context);
|
||||
if (feedIds == null) {
|
||||
// show all feeds by default
|
||||
fs = FeedSet.allFeeds();
|
||||
} else if (!feedIds.isEmpty()) {
|
||||
fs = FeedSet.multipleFeeds(feedIds);
|
||||
if (feedIds == null || !feedIds.isEmpty()) {
|
||||
fs = FeedSet.widgetFeeds(feedIds);
|
||||
} else {
|
||||
// no feeds selected. Widget will show tap to config view
|
||||
fs = null;
|
||||
|
|
|
@ -24,6 +24,7 @@ public class WidgetUtils {
|
|||
public static int RC_WIDGET_UPDATE = 1;
|
||||
public static int RC_WIDGET_STORY = 2;
|
||||
public static int RC_WIDGET_CONFIG = 3;
|
||||
public static int STORIES_LIMIT = 5;
|
||||
|
||||
static void enableWidgetUpdate(Context context) {
|
||||
Log.d(TAG, "enableWidgetUpdate");
|
||||
|
|
Loading…
Add table
Reference in a new issue