Make FeedItemTags an enum class, add String values to enum constants

This commit is contained in:
Daniel Schaal 2015-09-25 14:23:44 +02:00
parent 3bdfcdd4fe
commit 9092f1afce
10 changed files with 66 additions and 58 deletions

View file

@ -21,7 +21,28 @@
package de.luhmer.owncloudnewsreader.reader;
public class FeedItemTags {
public enum TAGS { MARK_ITEM_AS_READ, MARK_ITEM_AS_UNREAD, MARK_ITEM_AS_STARRED, MARK_ITEM_AS_UNSTARRED, ALL_STARRED, ALL };
public enum FeedItemTags {
MARK_ITEM_AS_READ("read"),
MARK_ITEM_AS_UNREAD("unread"),
MARK_ITEM_AS_STARRED("star"),
MARK_ITEM_AS_UNSTARRED("unstar"),
ALL_STARRED,
ALL;
private String segment;
FeedItemTags() {
}
FeedItemTags(String segment) {
this.segment = segment;
}
@Override
public String toString() {
if(this.segment != null)
return this.segment;
return super.toString();
}
}

View file

@ -35,7 +35,6 @@ import java.util.regex.Pattern;
import de.luhmer.owncloudnewsreader.SettingsActivity;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv1.APIv1;
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv2.APIv2;
@ -112,13 +111,13 @@ public abstract class API {
return OwnCloudReaderMethods.GetFolderTags(cont, api);
}
public int GetItems(TAGS tag, Context cont, String offset, boolean getRead, int id, String type, API api) throws Exception {
public int GetItems(FeedItemTags tag, Context cont, String offset, boolean getRead, int id, String type, API api) throws Exception {
return OwnCloudReaderMethods.GetItems(tag, cont, offset, getRead, String.valueOf(id), type, api);
}
public int[] GetUpdatedItems(TAGS tag, Context cont, long lastSync, API api) throws Exception {
public int[] GetUpdatedItems(FeedItemTags tag, Context cont, long lastSync, API api) throws Exception {
return OwnCloudReaderMethods.GetUpdatedItems(tag, cont, lastSync, api);
}
public abstract boolean PerformTagExecution(List<String> itemIds, FeedItemTags.TAGS tag, Context context, API api);
public abstract boolean PerformTagExecution(List<String> itemIds, FeedItemTags tag, Context context, API api);
}

View file

@ -40,7 +40,7 @@ import de.luhmer.owncloudnewsreader.SettingsActivity;
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
import de.luhmer.owncloudnewsreader.helper.NetworkConnection;
import de.luhmer.owncloudnewsreader.reader.AsyncTask_Reader;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
import de.luhmer.owncloudnewsreader.services.DownloadImagesService;
@ -92,7 +92,7 @@ public class AsyncTask_GetItems extends AsyncTask_Reader {
int maxItemsInDatabase = Constants.maxItemsCount;
do {
requestCount = api.GetItems(TAGS.ALL, context, String.valueOf(offset), false, 0, "3", api);
requestCount = api.GetItems(FeedItemTags.ALL, context, String.valueOf(offset), false, 0, "3", api);
if(requestCount > 0)
offset = dbConn.getLowestItemId(false);
totalCount += requestCount;
@ -104,7 +104,7 @@ public class AsyncTask_GetItems extends AsyncTask_Reader {
do {
offset = dbConn.getLowestItemId(true);
requestCount = api.GetItems(TAGS.ALL_STARRED, context, String.valueOf(offset), true, 0, "2", api);
requestCount = api.GetItems(FeedItemTags.ALL_STARRED, context, String.valueOf(offset), true, 0, "2", api);
//if(requestCount > 0)
// offset = dbConn.getLowestItemId(true);
totalCount += requestCount;
@ -115,7 +115,7 @@ public class AsyncTask_GetItems extends AsyncTask_Reader {
//First reset the count of last updated items
mPrefs.edit().putInt(Constants.LAST_UPDATE_NEW_ITEMS_COUNT_STRING, 0).commit();
//Get all updated items
int[] result = api.GetUpdatedItems(TAGS.ALL, context, lastModified + 1, api);
int[] result = api.GetUpdatedItems(FeedItemTags.ALL, context, lastModified + 1, api);
//If no exception occurs, set the number of updated items
mPrefs.edit().putInt(Constants.LAST_UPDATE_NEW_ITEMS_COUNT_STRING, result[1]).commit();
}

View file

@ -31,7 +31,7 @@ import de.luhmer.owncloudnewsreader.R;
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
import de.luhmer.owncloudnewsreader.database.model.RssItem;
import de.luhmer.owncloudnewsreader.reader.AsyncTask_Reader;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
public class AsyncTask_GetOldItems extends AsyncTask_Reader {
@ -82,7 +82,7 @@ public class AsyncTask_GetOldItems extends AsyncTask_Reader {
}
downloadedItemsCount = api.GetItems(TAGS.ALL, context, String.valueOf(offset), true, id.intValue(), type, api);
downloadedItemsCount = api.GetItems(FeedItemTags.ALL, context, String.valueOf(offset), true, id.intValue(), type, api);
/*
int totalCount = dbConn.getCountOfAllItems(false);

View file

@ -28,7 +28,7 @@ import java.util.List;
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
import de.luhmer.owncloudnewsreader.reader.AsyncTask_Reader;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
public class AsyncTask_PerformItemStateChange extends AsyncTask_Reader
@ -49,28 +49,28 @@ public class AsyncTask_PerformItemStateChange extends AsyncTask_Reader
//Mark as READ
List<String> itemIds = dbConn.getRssItemsIdsFromList(dbConn.getAllNewReadRssItems());
boolean result = api.PerformTagExecution(itemIds, TAGS.MARK_ITEM_AS_READ, context, api);
boolean result = api.PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_READ, context, api);
if(result)
dbConn.change_readUnreadStateOfItem(itemIds, true);
succeeded.add(result);
//Mark as UNREAD
itemIds = dbConn.getRssItemsIdsFromList(dbConn.getAllNewUnreadRssItems());
result = api.PerformTagExecution(itemIds, TAGS.MARK_ITEM_AS_UNREAD, context, api);
result = api.PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_UNREAD, context, api);
if(result)
dbConn.change_readUnreadStateOfItem(itemIds, false);
succeeded.add(result);
//Mark as STARRED
itemIds = dbConn.getRssItemsIdsFromList(dbConn.getAllNewStarredRssItems());
result = api.PerformTagExecution(itemIds, TAGS.MARK_ITEM_AS_STARRED, context, api);
result = api.PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_STARRED, context, api);
if(result)
dbConn.change_starrUnstarrStateOfItem(itemIds, true);
succeeded.add(result);
//Mark as UNSTARRED
itemIds = dbConn.getRssItemsIdsFromList(dbConn.getAllNewUnstarredRssItems());
result = api.PerformTagExecution(itemIds, TAGS.MARK_ITEM_AS_UNSTARRED, context, api);
result = api.PerformTagExecution(itemIds, FeedItemTags.MARK_ITEM_AS_UNSTARRED, context, api);
if(result)
dbConn.change_starrUnstarrStateOfItem(itemIds, false);
succeeded.add(result);

View file

@ -43,7 +43,6 @@ import java.util.Map;
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
import de.luhmer.owncloudnewsreader.database.model.RssItem;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
import de.luhmer.owncloudnewsreader.reader.HttpJsonRequest;
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv1.APIv1;
import de.luhmer.owncloudnewsreader.reader.owncloud.apiv2.APIv2;
@ -52,16 +51,16 @@ public class OwnCloudReaderMethods {
private static final String TAG = "OwnCloudReaderMethods";
public static String maxSizePerSync = "300";
public static int[] GetUpdatedItems(TAGS tag, Context cont, long lastSync, API api) throws Exception
public static int[] GetUpdatedItems(FeedItemTags tag, Context cont, long lastSync, API api) throws Exception
{
HashMap<String,String> nVPairs = new HashMap<>();
//nVPairs.put("batchSize", maxSizePerSync));
if(tag.equals(TAGS.ALL_STARRED))
if(tag.equals(FeedItemTags.ALL_STARRED))
{
nVPairs.put("type", "2");
nVPairs.put("id", "0");
}
else if(tag.equals(TAGS.ALL))
else if(tag.equals(FeedItemTags.ALL))
{
nVPairs.put("type", "3");
nVPairs.put("id", "0");
@ -85,16 +84,16 @@ public class OwnCloudReaderMethods {
}
//"type": 1, // the type of the query (Feed: 0, Folder: 1, Starred: 2, All: 3)
public static int GetItems(TAGS tag, Context cont, String offset, boolean getRead, String id, String type, API api) throws Exception
public static int GetItems(FeedItemTags tag, Context cont, String offset, boolean getRead, String id, String type, API api) throws Exception
{
HashMap<String,String> nVPairs = new HashMap<>();
nVPairs.put("batchSize", maxSizePerSync);
if(tag.equals(TAGS.ALL_STARRED))
if(tag.equals(FeedItemTags.ALL_STARRED))
{
nVPairs.put("type", type);
nVPairs.put("id", id);
}
else if(tag.equals(TAGS.ALL))
else if(tag.equals(FeedItemTags.ALL))
{
nVPairs.put("type", type);
nVPairs.put("id", id);
@ -339,21 +338,16 @@ public class OwnCloudReaderMethods {
public static boolean PerformTagExecutionAPIv2(List<String> itemIds, FeedItemTags.TAGS tag, Context context, API api)
public static boolean PerformTagExecutionAPIv2(List<String> itemIds, FeedItemTags tag, Context context, API api)
{
String jsonIds;
HttpUrl.Builder urlBuilder = api.getTagBaseUrl().newBuilder();
if(tag.equals(TAGS.MARK_ITEM_AS_READ) || tag.equals(TAGS.MARK_ITEM_AS_UNREAD))
if(tag.equals(FeedItemTags.MARK_ITEM_AS_READ) || tag.equals(FeedItemTags.MARK_ITEM_AS_UNREAD))
{
jsonIds = buildIdsToJSONArray(itemIds);
if(tag.equals(TAGS.MARK_ITEM_AS_READ))
urlBuilder.addPathSegment("read");
else
urlBuilder.addPathSegment("unread");
urlBuilder.addPathSegment("multiple");
urlBuilder.addPathSegment(tag.toString());
} else {
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(context);
@ -372,12 +366,8 @@ public class OwnCloudReaderMethods {
nameValuePairs.put("itemIds", jsonIds));
}*/
if(tag.equals(TAGS.MARK_ITEM_AS_STARRED))
urlBuilder.addPathSegment("star");
else if(tag.equals(TAGS.MARK_ITEM_AS_UNSTARRED))
urlBuilder.addPathSegment("unstar");
urlBuilder.addPathSegment("multiple");
if(tag.equals(FeedItemTags.MARK_ITEM_AS_STARRED) || tag.equals(FeedItemTags.MARK_ITEM_AS_UNSTARRED))
urlBuilder.addPathSegment(tag.toString());
/*
url += "/" + guidHash;
@ -389,6 +379,9 @@ public class OwnCloudReaderMethods {
*/
}
urlBuilder.addPathSegment("multiple");
try
{
int result = HttpJsonRequest.getInstance().performTagChangeRequest(urlBuilder.build(), jsonIds);
@ -402,16 +395,13 @@ public class OwnCloudReaderMethods {
}
}
public static boolean PerformTagExecutionAPIv1(String itemId, FeedItemTags.TAGS tag, Context context, API api)
public static boolean PerformTagExecutionAPIv1(String itemId, FeedItemTags tag, Context context, API api)
{
HttpUrl.Builder urlBuilder = api.getTagBaseUrl().newBuilder();
if(tag.equals(TAGS.MARK_ITEM_AS_READ) || tag.equals(TAGS.MARK_ITEM_AS_UNREAD))
{
urlBuilder.addPathSegment(itemId);
if(tag.equals(TAGS.MARK_ITEM_AS_READ))
urlBuilder.addPathSegment("read");
else
urlBuilder.addPathSegment("unread");
if(tag.equals(FeedItemTags.MARK_ITEM_AS_READ) || tag.equals(FeedItemTags.MARK_ITEM_AS_UNREAD)) {
urlBuilder
.addPathSegment(itemId)
.addPathSegment(tag.toString());
} else {
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(context);
@ -421,10 +411,8 @@ public class OwnCloudReaderMethods {
urlBuilder.addPathSegment(rssItem.getGuidHash());
if(tag.equals(TAGS.MARK_ITEM_AS_STARRED))
urlBuilder.addPathSegment("star");
else if(tag.equals(TAGS.MARK_ITEM_AS_UNSTARRED))
urlBuilder.addPathSegment("unstar");
if(tag.equals(FeedItemTags.MARK_ITEM_AS_STARRED) || tag.equals(FeedItemTags.MARK_ITEM_AS_UNSTARRED))
urlBuilder.addPathSegment(tag.toString());
}
try
{

View file

@ -37,7 +37,7 @@ public class OwnCloud_Reader {
}
public void Start_AsyncTask_GetItems(int task_id,
Context context, OnAsyncTaskCompletedListener listener, FeedItemTags.TAGS tag) {
Context context, OnAsyncTaskCompletedListener listener, FeedItemTags tag) {
setSyncRunning(true);
new AsyncTask_GetItems(task_id, context, new OnAsyncTaskCompletedListener[] { AsyncTask_finished, listener }, api).execute(tag);
}

View file

@ -28,7 +28,7 @@ import com.squareup.okhttp.HttpUrl;
import java.util.ArrayList;
import java.util.List;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
import de.luhmer.owncloudnewsreader.reader.owncloud.API;
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudConstants;
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudReaderMethods;
@ -65,7 +65,7 @@ public class APIv1 extends API {
}
@Override
public boolean PerformTagExecution(List<String> itemIds, TAGS tag,
public boolean PerformTagExecution(List<String> itemIds, FeedItemTags tag,
Context context, API api) {
List<Boolean> succeeded = new ArrayList<>();

View file

@ -27,7 +27,7 @@ import com.squareup.okhttp.HttpUrl;
import java.util.List;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
import de.luhmer.owncloudnewsreader.reader.owncloud.API;
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudConstants;
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloudReaderMethods;
@ -64,7 +64,7 @@ public class APIv2 extends API {
}
@Override
public boolean PerformTagExecution(List<String> itemIds, TAGS tag,
public boolean PerformTagExecution(List<String> itemIds, FeedItemTags tag,
Context context, API api) {
if(itemIds.size() > 0)
return OwnCloudReaderMethods.PerformTagExecutionAPIv2(itemIds, tag, context, api);

View file

@ -45,7 +45,7 @@ import de.luhmer.owncloudnewsreader.R;
import de.luhmer.owncloudnewsreader.SettingsActivity;
import de.luhmer.owncloudnewsreader.helper.AidlException;
import de.luhmer.owncloudnewsreader.helper.NotificationManagerNewsReader;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags.TAGS;
import de.luhmer.owncloudnewsreader.reader.FeedItemTags;
import de.luhmer.owncloudnewsreader.reader.OnAsyncTaskCompletedListener;
import de.luhmer.owncloudnewsreader.reader.owncloud.API;
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloud_Reader;
@ -186,7 +186,7 @@ public class OwnCloudSyncService extends Service {
if(task_result != null)
ThrowException((Exception) task_result);
else {
_Reader.Start_AsyncTask_GetItems(Constants.TaskID_GetItems, OwnCloudSyncService.this, onAsyncTask_GetItems, TAGS.ALL);//Recieve all unread Items
_Reader.Start_AsyncTask_GetItems(Constants.TaskID_GetItems, OwnCloudSyncService.this, onAsyncTask_GetItems, FeedItemTags.ALL);//Recieve all unread Items
startedSync(SYNC_TYPES.SYNC_TYPE__ITEMS);
}