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);
}
}
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);
}
}
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);
}
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());
}
}
}
}
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;
}
Aggregations