Commit 8d63ee8b authored by Toni Beier's avatar Toni Beier

Merge branch 'feed_module_rest_api_version_2' into 'develop'

Implementieren der Feed-REST-Api Version 2 des ASiST-Servers

See merge request OpenASiST/openasist4android_core!2
parents 8552801c 2626fe8e
......@@ -2,6 +2,9 @@ package de.bps.asist.module.feeds;
import android.content.Context;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
......@@ -66,16 +69,24 @@ public class FeedModule extends AbstractAsistModule {
}
public static void refreshData(Context context, OnRefreshFinishedListener listener) {
StringBuilder sb = new StringBuilder();
sb.append(context.getResources().getString(R.string.rootUrl));
sb.append("/feed/").append(context.getResources().getString(R.string.institutionName));
sb.append("/list");
UriComponentsBuilder getFeedDescriptionUriBuilder = UriComponentsBuilder.fromUriString(context.getString(R.string.rootUrl));
String feedApiVersion = context.getString(R.string.rest_feed_api_version);
if (feedApiVersion != null) {
if (!feedApiVersion.isEmpty()) {
getFeedDescriptionUriBuilder.pathSegment(feedApiVersion);
}
}
getFeedDescriptionUriBuilder.pathSegment("feed", context.getResources().getString(R.string.institutionName), "list");
UriComponents getFeedDescriptionUri = getFeedDescriptionUriBuilder.build();
final FeedCallBack cb = new FeedCallBack(context, listener);
if(listener == null) {
ASiSTParser.getInstance().parse(sb.toString(), FeedDescriptionList.class, cb);
ASiSTParser.getInstance().parse(getFeedDescriptionUri.toUriString(), FeedDescriptionList.class, cb);
} else {
ASiSTParser.getInstance().parseWithTask(sb.toString(), FeedDescriptionList.class, cb);
ASiSTParser.getInstance().parseWithTask(getFeedDescriptionUri.toUriString(), FeedDescriptionList.class, cb);
}
}
......@@ -161,15 +172,25 @@ public class FeedModule extends AbstractAsistModule {
}
}
private static void parseFeed(final FeedDescription fd, final Context context, OnRefreshFinishedListener listener) {
private static void parseFeed(final FeedDescription feedDescription, final Context context, OnRefreshFinishedListener listener) {
try {
final Long id = fd.getFeedid();
StringBuilder sb = new StringBuilder();
sb.append(context.getResources().getString(R.string.rootUrl));
sb.append("/feed/").append(context.getResources().getString(R.string.institutionName));
sb.append("/items/").append(String.valueOf(id));
final FeedItemCallback cb = new FeedItemCallback(id, context);
ASiSTParser.getInstance().parseWithThread(sb.toString(), FeedItemList.class, cb);
UriComponentsBuilder getFeedItemsUri = UriComponentsBuilder.fromUriString(context.getString(R.string.rootUrl));
String feedApiVersion = context.getString(R.string.rest_feed_api_version);
if (feedApiVersion != null) {
if (!feedApiVersion.isEmpty()) {
getFeedItemsUri.pathSegment(feedApiVersion);
}
}
getFeedItemsUri
.pathSegment("feed")
.pathSegment(context.getResources().getString(R.string.institutionName))
.pathSegment("items")
.pathSegment(String.valueOf(feedDescription.getFeedid()));
final FeedItemCallback cb = new FeedItemCallback(feedDescription.getFeedid(), context);
ASiSTParser.getInstance().parseWithThread(getFeedItemsUri.build().toUriString(), FeedItemList.class, cb);
} catch (final Exception e) {
////Log.e(TAG, "could not parseWithThread " + fd.getFeedid(), e);
}
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="rest_feed_api_version">v2</string>
</resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment