mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-21 05:45:13 +00:00
Make Story.read a boolean rather than an int.
This commit is contained in:
parent
3051836cd6
commit
19cf0ac2e2
10 changed files with 59 additions and 24 deletions
Binary file not shown.
BIN
media/android/NewsBlur/libs/gson-2.2.3.jar
Normal file
BIN
media/android/NewsBlur/libs/gson-2.2.3.jar
Normal file
Binary file not shown.
|
@ -200,7 +200,7 @@ public abstract class Reading extends NbFragmentActivity implements OnPageChange
|
||||||
*/
|
*/
|
||||||
protected void addStoryToMarkAsRead(Story story) {
|
protected void addStoryToMarkAsRead(Story story) {
|
||||||
if (story == null) return;
|
if (story == null) return;
|
||||||
if (story.read != Story.UNREAD) return;
|
if (story.read) return;
|
||||||
synchronized (this.storiesToMarkAsRead) {
|
synchronized (this.storiesToMarkAsRead) {
|
||||||
this.storiesToMarkAsRead.add(story);
|
this.storiesToMarkAsRead.add(story);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ public class BlurDatabase extends SQLiteOpenHelper {
|
||||||
|
|
||||||
private final String TEXT = " text";
|
private final String TEXT = " text";
|
||||||
private final String INTEGER = " integer";
|
private final String INTEGER = " integer";
|
||||||
private final static String TAG = "DatabaseHelper";
|
|
||||||
public final static String DB_NAME = "blur.db";
|
public final static String DB_NAME = "blur.db";
|
||||||
private final static int VERSION = 1;
|
private final static int VERSION = 1;
|
||||||
|
|
||||||
|
@ -105,7 +104,7 @@ public class BlurDatabase extends SQLiteOpenHelper {
|
||||||
DatabaseConstants.STORY_FRIEND_USER_IDS + TEXT + ", " +
|
DatabaseConstants.STORY_FRIEND_USER_IDS + TEXT + ", " +
|
||||||
DatabaseConstants.STORY_TAGS + TEXT + ", " +
|
DatabaseConstants.STORY_TAGS + TEXT + ", " +
|
||||||
DatabaseConstants.STORY_PERMALINK + TEXT + ", " +
|
DatabaseConstants.STORY_PERMALINK + TEXT + ", " +
|
||||||
DatabaseConstants.STORY_READ + TEXT + ", " +
|
DatabaseConstants.STORY_READ + INTEGER + ", " +
|
||||||
DatabaseConstants.STORY_TITLE + TEXT +
|
DatabaseConstants.STORY_TITLE + TEXT +
|
||||||
")";
|
")";
|
||||||
|
|
||||||
|
|
|
@ -60,8 +60,7 @@ public class FeedItemsAdapter extends SimpleCursorAdapter {
|
||||||
borderTwo.setBackgroundColor(Color.LTGRAY);
|
borderTwo.setBackgroundColor(Color.LTGRAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1 is read
|
if (! Story.fromCursor(cursor).read) {
|
||||||
if (Story.fromCursor(cursor).read == Story.UNREAD) {
|
|
||||||
((TextView) v.findViewById(R.id.row_item_author)).setTextColor(storyAuthorUnread);
|
((TextView) v.findViewById(R.id.row_item_author)).setTextColor(storyAuthorUnread);
|
||||||
((TextView) v.findViewById(R.id.row_item_date)).setTextColor(storyDateUnread);
|
((TextView) v.findViewById(R.id.row_item_date)).setTextColor(storyDateUnread);
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ public class MultipleFeedItemsAdapter extends SimpleCursorAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1 is read
|
// 1 is read
|
||||||
if (Story.fromCursor(cursor).read == Story.UNREAD) {
|
if (! Story.fromCursor(cursor).read) {
|
||||||
((TextView) v.findViewById(R.id.row_item_author)).setTextColor(storyAuthorUnread);
|
((TextView) v.findViewById(R.id.row_item_author)).setTextColor(storyAuthorUnread);
|
||||||
((TextView) v.findViewById(R.id.row_item_date)).setTextColor(storyDateUnread);
|
((TextView) v.findViewById(R.id.row_item_date)).setTextColor(storyDateUnread);
|
||||||
((TextView) v.findViewById(R.id.row_item_feedtitle)).setTextColor(storyFeedUnread);
|
((TextView) v.findViewById(R.id.row_item_feedtitle)).setTextColor(storyFeedUnread);
|
||||||
|
|
|
@ -18,9 +18,6 @@ public class Story implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 7629596752129163308L;
|
private static final long serialVersionUID = 7629596752129163308L;
|
||||||
|
|
||||||
public static final int UNREAD = 0;
|
|
||||||
public static final int READ = 1;
|
|
||||||
|
|
||||||
public String id;
|
public String id;
|
||||||
|
|
||||||
@SerializedName("story_permalink")
|
@SerializedName("story_permalink")
|
||||||
|
@ -42,7 +39,7 @@ public class Story implements Serializable {
|
||||||
public int commentCount;
|
public int commentCount;
|
||||||
|
|
||||||
@SerializedName("read_status")
|
@SerializedName("read_status")
|
||||||
public int read;
|
public boolean read;
|
||||||
|
|
||||||
@SerializedName("story_tags")
|
@SerializedName("story_tags")
|
||||||
public String[] tags;
|
public String[] tags;
|
||||||
|
@ -135,7 +132,7 @@ public class Story implements Serializable {
|
||||||
story.intelligence.intelligenceFeed = cursor.getInt(cursor.getColumnIndex(DatabaseConstants.STORY_INTELLIGENCE_FEED));
|
story.intelligence.intelligenceFeed = cursor.getInt(cursor.getColumnIndex(DatabaseConstants.STORY_INTELLIGENCE_FEED));
|
||||||
story.intelligence.intelligenceTags = cursor.getInt(cursor.getColumnIndex(DatabaseConstants.STORY_INTELLIGENCE_TAGS));
|
story.intelligence.intelligenceTags = cursor.getInt(cursor.getColumnIndex(DatabaseConstants.STORY_INTELLIGENCE_TAGS));
|
||||||
story.intelligence.intelligenceTitle = cursor.getInt(cursor.getColumnIndex(DatabaseConstants.STORY_INTELLIGENCE_TITLE));
|
story.intelligence.intelligenceTitle = cursor.getInt(cursor.getColumnIndex(DatabaseConstants.STORY_INTELLIGENCE_TITLE));
|
||||||
story.read = cursor.getInt(cursor.getColumnIndex(DatabaseConstants.STORY_READ));
|
story.read = cursor.getInt(cursor.getColumnIndex(DatabaseConstants.STORY_READ)) > 0;
|
||||||
story.tags = TextUtils.split(cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_TAGS)), ",");
|
story.tags = TextUtils.split(cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_TAGS)), ",");
|
||||||
story.feedId = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_FEED_ID));
|
story.feedId = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_FEED_ID));
|
||||||
story.id = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_ID));
|
story.id = cursor.getString(cursor.getColumnIndex(DatabaseConstants.STORY_ID));
|
||||||
|
|
|
@ -183,7 +183,7 @@ public class FeedItemListFragment extends ItemListFragment implements LoaderMana
|
||||||
final AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
|
final AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
|
||||||
if (item.getItemId() == R.id.menu_mark_story_as_read) {
|
if (item.getItemId() == R.id.menu_mark_story_as_read) {
|
||||||
final Story story = adapter.getStory(menuInfo.position);
|
final Story story = adapter.getStory(menuInfo.position);
|
||||||
if(story.read == Story.UNREAD) {
|
if(! story.read) {
|
||||||
ArrayList<Story> storiesToMarkAsRead = new ArrayList<Story>();
|
ArrayList<Story> storiesToMarkAsRead = new ArrayList<Story>();
|
||||||
storiesToMarkAsRead.add(story);
|
storiesToMarkAsRead.add(story);
|
||||||
FeedUtils.markStoriesAsRead(storiesToMarkAsRead, getActivity());
|
FeedUtils.markStoriesAsRead(storiesToMarkAsRead, getActivity());
|
||||||
|
@ -193,7 +193,7 @@ public class FeedItemListFragment extends ItemListFragment implements LoaderMana
|
||||||
final ArrayList<Story> previousStories = adapter.getPreviousStories(menuInfo.position);
|
final ArrayList<Story> previousStories = adapter.getPreviousStories(menuInfo.position);
|
||||||
ArrayList<Story> storiesToMarkAsRead = new ArrayList<Story>();
|
ArrayList<Story> storiesToMarkAsRead = new ArrayList<Story>();
|
||||||
for(Story story: previousStories) {
|
for(Story story: previousStories) {
|
||||||
if(story.read == Story.UNREAD) {
|
if(! story.read) {
|
||||||
storiesToMarkAsRead.add(story);
|
storiesToMarkAsRead.add(story);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,27 +44,24 @@ import com.newsblur.network.domain.Message;
|
||||||
import com.newsblur.network.domain.ProfileResponse;
|
import com.newsblur.network.domain.ProfileResponse;
|
||||||
import com.newsblur.network.domain.SocialFeedResponse;
|
import com.newsblur.network.domain.SocialFeedResponse;
|
||||||
import com.newsblur.network.domain.StoriesResponse;
|
import com.newsblur.network.domain.StoriesResponse;
|
||||||
|
import com.newsblur.serialization.BooleanTypeAdapter;
|
||||||
import com.newsblur.serialization.DateStringTypeAdapter;
|
import com.newsblur.serialization.DateStringTypeAdapter;
|
||||||
import com.newsblur.util.PrefsUtils;
|
import com.newsblur.util.PrefsUtils;
|
||||||
|
|
||||||
public class APIManager {
|
public class APIManager {
|
||||||
|
|
||||||
private Context context;
|
private Context context;
|
||||||
private static Gson gson;
|
private Gson gson;
|
||||||
private ContentResolver contentResolver;
|
private ContentResolver contentResolver;
|
||||||
|
|
||||||
public APIManager(final Context context) {
|
public APIManager(final Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
contentResolver = context.getContentResolver();
|
this.contentResolver = context.getContentResolver();
|
||||||
initGsonIfNeededBuilder();
|
this.gson = new GsonBuilder()
|
||||||
}
|
.registerTypeAdapter(Date.class, new DateStringTypeAdapter())
|
||||||
|
.registerTypeAdapter(Boolean.class, new BooleanTypeAdapter())
|
||||||
private static synchronized void initGsonIfNeededBuilder() {
|
.registerTypeAdapter(boolean.class, new BooleanTypeAdapter())
|
||||||
if(gson == null) {
|
.create();
|
||||||
final GsonBuilder builder = new GsonBuilder();
|
|
||||||
builder.registerTypeAdapter(Date.class, new DateStringTypeAdapter());
|
|
||||||
gson = builder.create();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public LoginResponse login(final String username, final String password) {
|
public LoginResponse login(final String username, final String password) {
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.newsblur.serialization;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import com.google.gson.TypeAdapter;
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
|
import com.google.gson.stream.JsonToken;
|
||||||
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A more forgiving type adapter to deserialize JSON booleans. Specifically, this implementation is
|
||||||
|
* friendly to backend code that may send numeric 0s and 1s for boolean fields, on which the strict
|
||||||
|
* GSON base impl would choke.
|
||||||
|
*/
|
||||||
|
public class BooleanTypeAdapter extends TypeAdapter<Boolean> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean read(JsonReader in) throws IOException {
|
||||||
|
JsonToken type = in.peek();
|
||||||
|
if (type == JsonToken.NULL) {
|
||||||
|
in.nextNull();
|
||||||
|
return null;
|
||||||
|
} else if (type == JsonToken.BOOLEAN) {
|
||||||
|
return in.nextBoolean();
|
||||||
|
} else if (type == JsonToken.NUMBER) {
|
||||||
|
return in.nextInt() > 0;
|
||||||
|
} else if (type == JsonToken.STRING) {
|
||||||
|
return Boolean.parseBoolean(in.nextString());
|
||||||
|
} else {
|
||||||
|
throw new IOException( "Could not parse JSON boolean." );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(JsonWriter out, Boolean b) throws IOException{
|
||||||
|
if (b == null) {
|
||||||
|
out.nullValue();
|
||||||
|
} else {
|
||||||
|
out.value(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue