use of androidx.collection.ArrayMap in project AntennaPod by AntennaPod.
the class GpodnetEpisodeActionPostResponse method fromJSONObject.
/**
* Creates a new GpodnetUploadChangesResponse-object from a JSON object that was
* returned by an uploadChanges call.
*
* @throws org.json.JSONException If the method could not parse the JSONObject.
*/
public static GpodnetEpisodeActionPostResponse fromJSONObject(String objectString) throws JSONException {
final JSONObject object = new JSONObject(objectString);
final long timestamp = object.getLong("timestamp");
JSONArray urls = object.getJSONArray("update_urls");
Map<String, String> updatedUrls = new ArrayMap<>(urls.length());
for (int i = 0; i < urls.length(); i++) {
JSONArray urlPair = urls.getJSONArray(i);
updatedUrls.put(urlPair.getString(0), urlPair.getString(1));
}
return new GpodnetEpisodeActionPostResponse(timestamp, updatedUrls);
}
use of androidx.collection.ArrayMap in project AntennaPod by AntennaPod.
the class GpodnetUploadChangesResponse method fromJSONObject.
/**
* Creates a new GpodnetUploadChangesResponse-object from a JSON object that was
* returned by an uploadChanges call.
*
* @throws org.json.JSONException If the method could not parse the JSONObject.
*/
public static GpodnetUploadChangesResponse fromJSONObject(String objectString) throws JSONException {
final JSONObject object = new JSONObject(objectString);
final long timestamp = object.getLong("timestamp");
Map<String, String> updatedUrls = new ArrayMap<>();
JSONArray urls = object.getJSONArray("update_urls");
for (int i = 0; i < urls.length(); i++) {
JSONArray urlPair = urls.getJSONArray(i);
updatedUrls.put(urlPair.getString(0), urlPair.getString(1));
}
return new GpodnetUploadChangesResponse(timestamp, updatedUrls);
}
use of androidx.collection.ArrayMap in project AntennaPod by AntennaPod.
the class EpisodeActionFilter method getRemoteActionsOverridingLocalActions.
public static Map<Pair<String, String>, EpisodeAction> getRemoteActionsOverridingLocalActions(List<EpisodeAction> remoteActions, List<EpisodeAction> queuedEpisodeActions) {
// make sure more recent local actions are not overwritten by older remote actions
Map<Pair<String, String>, EpisodeAction> remoteActionsThatOverrideLocalActions = new ArrayMap<>();
Map<Pair<String, String>, EpisodeAction> localMostRecentPlayActions = createUniqueLocalMostRecentPlayActions(queuedEpisodeActions);
for (EpisodeAction remoteAction : remoteActions) {
Pair<String, String> key = new Pair<>(remoteAction.getPodcast(), remoteAction.getEpisode());
switch(remoteAction.getAction()) {
case NEW:
remoteActionsThatOverrideLocalActions.put(key, remoteAction);
break;
case DOWNLOAD:
break;
case PLAY:
EpisodeAction localMostRecent = localMostRecentPlayActions.get(key);
if (secondActionOverridesFirstAction(remoteAction, localMostRecent)) {
break;
}
EpisodeAction remoteMostRecentAction = remoteActionsThatOverrideLocalActions.get(key);
if (secondActionOverridesFirstAction(remoteAction, remoteMostRecentAction)) {
break;
}
remoteActionsThatOverrideLocalActions.put(key, remoteAction);
break;
case DELETE:
// NEVER EVER call DBWriter.deleteFeedMediaOfItem() here, leads to an infinite loop
break;
default:
Log.e(TAG, "Unknown remoteAction: " + remoteAction);
break;
}
}
return remoteActionsThatOverrideLocalActions;
}
use of androidx.collection.ArrayMap in project PocketHub by pockethub.
the class GistFilesViewActivityTest method setUp.
@Before
public void setUp() {
Context context = getInstrumentation().getTargetContext();
PocketHub pocketHub = (PocketHub) context.getApplicationContext();
store = pocketHub.applicationComponent().gistStore();
Map<String, GistFile> files = new ArrayMap<>();
GistFile a = GistFile.builder().content("aa").filename("a").build();
GistFile b = GistFile.builder().content("bb").filename("b").build();
files.put("a", a);
files.put("b", b);
gist = Gist.builder().id("abcd").files(files).build();
store.addGist(gist);
activityTestRule.launchActivity(GistFilesViewActivity.Companion.createIntent(gist, 0));
}
use of androidx.collection.ArrayMap in project AntennaPod by AntennaPod.
the class DBReader method loadFeedDataOfFeedItemList.
/**
* Takes a list of FeedItems and loads their corresponding Feed-objects from the database.
* The feedID-attribute of a FeedItem must be set to the ID of its feed or the method will
* not find the correct feed of an item.
*
* @param items The FeedItems whose Feed-objects should be loaded.
*/
private static void loadFeedDataOfFeedItemList(List<FeedItem> items) {
List<Feed> feeds = getFeedList();
Map<Long, Feed> feedIndex = new ArrayMap<>(feeds.size());
for (Feed feed : feeds) {
feedIndex.put(feed.getId(), feed);
}
for (FeedItem item : items) {
Feed feed = feedIndex.get(item.getFeedId());
if (feed == null) {
Log.w(TAG, "No match found for item with ID " + item.getId() + ". Feed ID was " + item.getFeedId());
feed = new Feed("", "", "Error: Item without feed");
}
item.setFeed(feed);
}
}
Aggregations