Search in sources :

Example 6 with ArrayMap

use of android.support.v4.util.ArrayMap in project Tangram-Android by alibaba.

the class MVHelper method loadMethod.

private void loadMethod(BaseCell cell, View view) {
    if (view instanceof ITangramViewLifeCycle) {
        return;
    }
    if (methodMap.get(cell) != null) {
        return;
    }
    ArrayMap<Method, Object> paramMap = new ArrayMap<>();
    Method[] methods;
    if (methodCacheMap.get(view.getClass()) == null) {
        methods = view.getClass().getDeclaredMethods();
        methodCacheMap.put(view.getClass(), methods);
    } else {
        methods = methodCacheMap.get(view.getClass());
    }
    CellRender cellRender;
    Class[] paramClazz;
    for (Method method : methods) {
        cellRender = method.getAnnotation(CellRender.class);
        paramClazz = method.getParameterTypes();
        if (!method.isAnnotationPresent(CellRender.class) || paramClazz == null || paramClazz.length != 1) {
            continue;
        }
        if (method.getName().equals("postBindView")) {
            postBindMap.put(cell, method);
            continue;
        }
        if (method.getName().equals("postUnBindView")) {
            postUnBindMap.put(cell, method);
            continue;
        }
        if (method.getName().equals("cellInited")) {
            cellInitedMap.put(cell, method);
            continue;
        }
        if (!TextUtils.isEmpty(cellRender.key()) && cell.hasParam(cellRender.key())) {
            if ("null".equals(cell.optParam(cellRender.key()))) {
                paramMap.put(method, null);
            } else if (paramClazz[0].equals(Integer.class) || paramClazz[0].equals(int.class)) {
                paramMap.put(method, cell.optIntParam(cellRender.key()));
            } else if (paramClazz[0].equals(String.class)) {
                paramMap.put(method, cell.optStringParam(cellRender.key()));
            } else if (paramClazz[0].equals(Boolean.class) || paramClazz[0].equals(boolean.class)) {
                paramMap.put(method, cell.optBoolParam(cellRender.key()));
            } else if (paramClazz[0].equals(Double.class) || paramClazz[0].equals(double.class)) {
                paramMap.put(method, cell.optDoubleParam(cellRender.key()));
            } else if (paramClazz[0].equals(JSONArray.class)) {
                paramMap.put(method, cell.optJsonArrayParam(cellRender.key()));
            } else if (paramClazz[0].equals(Long.class) || paramClazz[0].equals(long.class)) {
                paramMap.put(method, cell.optLongParam(cellRender.key()));
            } else if (paramClazz[0].equals(JSONObject.class)) {
                paramMap.put(method, cell.optJsonObjectParam(cellRender.key()));
            } else {
                paramMap.put(method, cell.optParam(cellRender.key()));
            }
        } else if (cell.hasParam(method.getName())) {
            if ("null".equals(cell.optParam(method.getName()))) {
                paramMap.put(method, null);
            } else if (paramClazz[0].equals(Integer.class) || paramClazz[0].equals(int.class)) {
                paramMap.put(method, cell.optIntParam(method.getName()));
            } else if (paramClazz[0].equals(String.class)) {
                paramMap.put(method, cell.optStringParam(method.getName()));
            } else if (paramClazz[0].equals(Boolean.class) || paramClazz[0].equals(boolean.class)) {
                paramMap.put(method, cell.optBoolParam(method.getName()));
            } else if (paramClazz[0].equals(Double.class) || paramClazz[0].equals(double.class)) {
                paramMap.put(method, cell.optDoubleParam(method.getName()));
            } else if (paramClazz[0].equals(JSONArray.class)) {
                paramMap.put(method, cell.optJsonArrayParam(method.getName()));
            } else if (paramClazz[0].equals(Long.class) || paramClazz[0].equals(long.class)) {
                paramMap.put(method, cell.optLongParam(method.getName()));
            } else if (paramClazz[0].equals(JSONObject.class)) {
                paramMap.put(method, cell.optJsonObjectParam(method.getName()));
            } else {
                paramMap.put(method, cell.optParam(method.getName()));
            }
        } else {
            if (paramClazz[0].equals(Integer.class) || paramClazz[0].equals(int.class)) {
                paramMap.put(method, 0);
            } else if (paramClazz[0].equals(String.class)) {
                paramMap.put(method, "");
            } else if (paramClazz[0].equals(Boolean.class) || paramClazz[0].equals(boolean.class)) {
                paramMap.put(method, false);
            } else if (paramClazz[0].equals(Double.class) || paramClazz[0].equals(double.class)) {
                paramMap.put(method, 0);
            } else if (paramClazz[0].equals(JSONArray.class)) {
                paramMap.put(method, null);
            } else if (paramClazz[0].equals(Long.class) || paramClazz[0].equals(long.class)) {
                paramMap.put(method, 0);
            } else if (paramClazz[0].equals(JSONObject.class)) {
                paramMap.put(method, null);
            } else {
                paramMap.put(method, "");
            }
        }
    }
    if (!paramMap.isEmpty()) {
        methodMap.put(cell, paramMap);
    }
}
Also used : ITangramViewLifeCycle(com.tmall.wireless.tangram.structure.view.ITangramViewLifeCycle) JSONArray(org.json.JSONArray) ArrayMap(android.support.v4.util.ArrayMap) Method(java.lang.reflect.Method) CellRender(com.tmall.wireless.tangram.structure.CellRender) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject)

Example 7 with ArrayMap

use of android.support.v4.util.ArrayMap in project GeekNews by codeestX.

the class NodeAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    holder.tvTitle.setText(mMap.keyAt(position));
    holder.flContent.removeAllViews();
    ArrayMap<String, String> mNodeBlock = mMap.valueAt(position);
    for (ArrayMap.Entry<String, String> node : mNodeBlock.entrySet()) {
        TextView tvNode = new TextView(mContext);
        tvNode.setText(node.getValue());
        tvNode.setTextColor(ContextCompat.getColor(mContext, R.color.colorText));
        tvNode.setPadding(SystemUtil.dp2px(6f), SystemUtil.dp2px(6f), SystemUtil.dp2px(6f), SystemUtil.dp2px(6f));
        tvNode.setOnClickListener(new OnNodeClickListener(node.getKey()));
        holder.flContent.addView(tvNode);
    }
}
Also used : ArrayMap(android.support.v4.util.ArrayMap) TextView(android.widget.TextView)

Example 8 with ArrayMap

use of android.support.v4.util.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(android.support.v4.util.ArrayMap)

Example 9 with ArrayMap

use of android.support.v4.util.ArrayMap in project AntennaPod by AntennaPod.

the class GpodnetSyncService method processEpisodeActions.

private synchronized void processEpisodeActions(List<GpodnetEpisodeAction> localActions, List<GpodnetEpisodeAction> remoteActions) throws DownloadRequestException {
    if (remoteActions.size() == 0) {
        return;
    }
    Map<Pair<String, String>, GpodnetEpisodeAction> localMostRecentPlayAction = new ArrayMap<>();
    for (GpodnetEpisodeAction action : localActions) {
        Pair<String, String> key = new Pair<>(action.getPodcast(), action.getEpisode());
        GpodnetEpisodeAction mostRecent = localMostRecentPlayAction.get(key);
        if (mostRecent == null || mostRecent.getTimestamp() == null) {
            localMostRecentPlayAction.put(key, action);
        } else if (mostRecent.getTimestamp().before(action.getTimestamp())) {
            localMostRecentPlayAction.put(key, action);
        }
    }
    // make sure more recent local actions are not overwritten by older remote actions
    Map<Pair<String, String>, GpodnetEpisodeAction> mostRecentPlayAction = new ArrayMap<>();
    for (GpodnetEpisodeAction action : remoteActions) {
        switch(action.getAction()) {
            case NEW:
                FeedItem newItem = DBReader.getFeedItem(action.getPodcast(), action.getEpisode());
                if (newItem != null) {
                    DBWriter.markItemPlayed(newItem, FeedItem.UNPLAYED, true);
                } else {
                    Log.i(TAG, "Unknown feed item: " + action);
                }
                break;
            case DOWNLOAD:
                break;
            case PLAY:
                Pair<String, String> key = new Pair<>(action.getPodcast(), action.getEpisode());
                GpodnetEpisodeAction localMostRecent = localMostRecentPlayAction.get(key);
                if (localMostRecent == null || localMostRecent.getTimestamp() == null || localMostRecent.getTimestamp().before(action.getTimestamp())) {
                    GpodnetEpisodeAction mostRecent = mostRecentPlayAction.get(key);
                    if (mostRecent == null || mostRecent.getTimestamp() == null) {
                        mostRecentPlayAction.put(key, action);
                    } else if (action.getTimestamp() != null && mostRecent.getTimestamp().before(action.getTimestamp())) {
                        mostRecentPlayAction.put(key, action);
                    } else {
                        Log.d(TAG, "No date information in action, skipping it");
                    }
                }
                break;
            case DELETE:
                // NEVER EVER call DBWriter.deleteFeedMediaOfItem() here, leads to an infinite loop
                break;
        }
    }
    for (GpodnetEpisodeAction action : mostRecentPlayAction.values()) {
        FeedItem playItem = DBReader.getFeedItem(action.getPodcast(), action.getEpisode());
        if (playItem != null) {
            FeedMedia media = playItem.getMedia();
            media.setPosition(action.getPosition() * 1000);
            DBWriter.setFeedMedia(media);
            if (playItem.getMedia().hasAlmostEnded()) {
                DBWriter.markItemPlayed(playItem, FeedItem.PLAYED, true);
                DBWriter.addItemToPlaybackHistory(playItem.getMedia());
            }
        }
    }
}
Also used : GpodnetEpisodeAction(de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) ArrayMap(android.support.v4.util.ArrayMap) Pair(android.util.Pair)

Example 10 with ArrayMap

use of android.support.v4.util.ArrayMap in project AntennaPod by AntennaPod.

the class DBReader method getFeedMedia.

private static Map<Long, FeedMedia> getFeedMedia(PodDBAdapter adapter, long... itemIds) {
    String[] ids = new String[itemIds.length];
    for (int i = 0, len = itemIds.length; i < len; i++) {
        ids[i] = String.valueOf(itemIds[i]);
    }
    Map<Long, FeedMedia> result = new ArrayMap<>(itemIds.length);
    Cursor cursor = adapter.getFeedMediaCursor(ids);
    try {
        if (cursor.moveToFirst()) {
            do {
                int index = cursor.getColumnIndex(PodDBAdapter.KEY_FEEDITEM);
                long itemId = cursor.getLong(index);
                FeedMedia media = FeedMedia.fromCursor(cursor);
                result.put(itemId, media);
            } while (cursor.moveToNext());
        }
    } finally {
        cursor.close();
    }
    return result;
}
Also used : FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) ArrayMap(android.support.v4.util.ArrayMap) Cursor(android.database.Cursor)

Aggregations

ArrayMap (android.support.v4.util.ArrayMap)16 JSONArray (org.json.JSONArray)3 JSONObject (org.json.JSONObject)3 Cursor (android.database.Cursor)2 View (android.view.View)2 TextView (android.widget.TextView)2 BusSupport (com.tmall.wireless.tangram.eventbus.BusSupport)2 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)2 ArrayList (java.util.ArrayList)2 Animator (android.animation.Animator)1 SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 Drawable (android.graphics.drawable.Drawable)1 LongSparseArray (android.support.v4.util.LongSparseArray)1 SimpleArrayMap (android.support.v4.util.SimpleArrayMap)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 Spanned (android.text.Spanned)1 ClickableSpan (android.text.style.ClickableSpan)1