Search in sources :

Example 1 with ArrayMap

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);
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ArrayMap(androidx.collection.ArrayMap)

Example 2 with ArrayMap

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);
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) ArrayMap(androidx.collection.ArrayMap)

Example 3 with ArrayMap

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;
}
Also used : ArrayMap(androidx.collection.ArrayMap) EpisodeAction(de.danoeh.antennapod.net.sync.model.EpisodeAction) Pair(androidx.core.util.Pair)

Example 4 with ArrayMap

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));
}
Also used : Context(android.content.Context) PocketHub(com.github.pockethub.android.PocketHub) ArrayMap(androidx.collection.ArrayMap) GistFile(com.meisolsson.githubsdk.model.GistFile) Before(org.junit.Before)

Example 5 with ArrayMap

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);
    }
}
Also used : FeedItem(de.danoeh.antennapod.model.feed.FeedItem) ArrayMap(androidx.collection.ArrayMap) Feed(de.danoeh.antennapod.model.feed.Feed)

Aggregations

ArrayMap (androidx.collection.ArrayMap)7 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 Context (android.content.Context)1 Resources (android.content.res.Resources)1 Pair (androidx.core.util.Pair)1 ListPreference (androidx.preference.ListPreference)1 PocketHub (com.github.pockethub.android.PocketHub)1 GistFile (com.meisolsson.githubsdk.model.GistFile)1 Feed (de.danoeh.antennapod.model.feed.Feed)1 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)1 EpisodeAction (de.danoeh.antennapod.net.sync.model.EpisodeAction)1 Element (org.jsoup.nodes.Element)1 Elements (org.jsoup.select.Elements)1 Before (org.junit.Before)1