public RedditInboxItemView(final Context context, final int headerCol, final int bodyCol) { super(context); this.bodyCol = bodyCol; setOrientation(HORIZONTAL); final LinearLayout main = new LinearLayout(context); main.setOrientation(VERTICAL); header = new TextView(context); header.setTextSize(11.0f); header.setTextColor(headerCol); main.addView(header); bodyHolder = new FrameLayout(context); bodyHolder.setPadding(0, General.dpToPixels(context, 2), 0, 0); main.addView(bodyHolder); final int paddingPixels = General.dpToPixels(context, 8.0f); setPadding(paddingPixels + paddingPixels, paddingPixels, paddingPixels, paddingPixels); setDescendantFocusability(FOCUS_BLOCK_DESCENDANTS); addView(main); }
@Override protected void prepare(Activity context, LinearLayout items) { final RedditPost post = getArguments().getParcelable("post"); items.addView( propView( context, R.string.props_title, StringEscapeUtils.unescapeHtml4(post.title.trim()), true)); items.addView(propView(context, R.string.props_author, post.author, false)); items.addView( propView(context, R.string.props_url, StringEscapeUtils.unescapeHtml4(post.url), false)); items.addView( propView( context, R.string.props_created, RRTime.formatDateTime(post.created_utc * 1000, context), false)); if (post.edited instanceof Long) { items.addView( propView( context, R.string.props_edited, RRTime.formatDateTime((Long) post.edited * 1000, context), false)); } else { items.addView(propView(context, R.string.props_edited, R.string.props_never, false)); } items.addView(propView(context, R.string.props_subreddit, post.subreddit, false)); items.addView( propView( context, R.string.props_score, String.format( "%d (%d %s, %d %s)", post.score, post.ups, context.getString(R.string.props_up), post.downs, context.getString(R.string.props_down)), false)); items.addView( propView(context, R.string.props_num_comments, String.valueOf(post.num_comments), false)); if (post.selftext != null && post.selftext.length() > 0) { items.addView( propView( context, R.string.props_self_markdown, StringEscapeUtils.unescapeHtml4(post.selftext), false)); } }
@Override protected void prepare(Context context, LinearLayout items) { final RedditComment comment = getArguments().getParcelable("comment"); items.addView(propView(context, R.string.props_author, comment.author, false)); if (comment.author_flair_text != null && comment.author_flair_text.length() > 0) { items.addView( propView(context, R.string.props_author_flair, comment.author_flair_text, false)); } items.addView( propView( context, R.string.props_created, RRTime.formatDateTime(comment.created_utc * 1000), false)); if (comment.edited instanceof Long) { items.addView( propView( context, R.string.props_edited, RRTime.formatDateTime((Long) comment.edited * 1000), false)); } else { items.addView(propView(context, R.string.props_edited, R.string.props_never, false)); } items.addView( propView( context, R.string.props_score, String.format( "%d (%d %s, %d %s)", comment.ups - comment.downs, comment.ups, context.getString(R.string.props_up), comment.downs, context.getString(R.string.props_down)), false)); items.addView(propView(context, R.string.props_subreddit, comment.subreddit, false)); if (comment.body != null && comment.body.length() > 0) { items.addView(propView(context, R.string.props_body_markdown, comment.body, false)); } }
private void fillComponent() { if (mRecipeDetailInfo != null) { mImageLoader.displayImage( MeishiApplication.getApplication().isShowPic() ? mRecipeDetailInfo.getRecipeCover().trim() : null, mImageViewTop, mOptions); mImageLoader.displayImage( MeishiApplication.getApplication().isShowPic() ? mRecipeDetailInfo.getRecipeAuthorAvator().trim() : null, mImageViewUser, mOptions2); mTextViewUserName.setText(mRecipeDetailInfo.getRecipeAuthor().trim()); mTextViewRecipeName.setText(mRecipeDetailInfo.getRecipeTitle().trim()); mTextViewDescr.setText( mRecipeDetailInfo.getRecipeDescr().replace("<br />", "").replace(" ", "")); mTextViewKouwei.setText(mRecipeDetailInfo.getCuisine().trim()); mTextViewGongyi.setText(mRecipeDetailInfo.getTechnics().trim()); mTextViewTime.setText(mRecipeDetailInfo.getDuring().trim()); mTextViewDifficulty.setText(mRecipeDetailInfo.getLevel().trim()); mImageViewUser.setOnClickListener(RecipeDetailFragment.this); List<IngredientInfo> mIngredientInfos01 = mRecipeDetailInfo.getmIngredientInfos1(); if (mIngredientInfos01 != null && mIngredientInfos01.size() > 0) { RelativeLayout localRelativeLayout = (RelativeLayout) LayoutInflater.inflate( getSupportActivity(), R.layout.recipe_detail_ingredients_category_name); TextView mTextView = (TextView) localRelativeLayout.findViewById(R.id.ingredientsCategoryName); mTextView.setText( MeishiApplication.getApplication().getString(R.string.fragment_recipe_detail_zhuliao)); mLinearLayoutIngredients.addView(localRelativeLayout); for (int i = 0; i < mIngredientInfos01.size(); i = i + 2) { View view = LayoutInflater.inflate(getSupportActivity(), R.layout.recipe_detail_ingredients_item); TextView textView01 = (TextView) view.findViewById(R.id.text11); TextView textView02 = (TextView) view.findViewById(R.id.text12); textView01.setText(mIngredientInfos01.get(i).getIngredientName().trim()); textView02.setText(mIngredientInfos01.get(i).getIngredientScale().trim()); if (i + 1 < mIngredientInfos01.size()) { TextView textView03 = (TextView) view.findViewById(R.id.text21); TextView textView04 = (TextView) view.findViewById(R.id.text22); textView03.setText(mIngredientInfos01.get(i + 1).getIngredientName().trim()); textView04.setText(mIngredientInfos01.get(i + 1).getIngredientScale().trim()); } this.mLinearLayoutIngredients.addView(view); } } List<IngredientInfo> mIngredientInfos02 = mRecipeDetailInfo.getmIngredientInfos2(); if (mIngredientInfos02 != null && mIngredientInfos02.size() > 0) { RelativeLayout localRelativeLayout = (RelativeLayout) LayoutInflater.inflate( getSupportActivity(), R.layout.recipe_detail_ingredients_category_name); TextView mTextView = (TextView) localRelativeLayout.findViewById(R.id.ingredientsCategoryName); mTextView.setText( MeishiApplication.getApplication().getString(R.string.fragment_recipe_detail_fuliao)); mLinearLayoutIngredients.addView(localRelativeLayout); for (int i = 0; i < mIngredientInfos02.size(); i = i + 2) { View view = LayoutInflater.inflate(getSupportActivity(), R.layout.recipe_detail_ingredients_item); TextView textView01 = (TextView) view.findViewById(R.id.text11); TextView textView02 = (TextView) view.findViewById(R.id.text12); textView01.setText(mIngredientInfos02.get(i).getIngredientName().trim()); textView02.setText(mIngredientInfos02.get(i).getIngredientScale().trim()); if (i + 1 < mIngredientInfos02.size()) { TextView textView03 = (TextView) view.findViewById(R.id.text21); TextView textView04 = (TextView) view.findViewById(R.id.text22); textView03.setText(mIngredientInfos02.get(i + 1).getIngredientName().trim()); textView04.setText(mIngredientInfos02.get(i + 1).getIngredientScale().trim()); } this.mLinearLayoutIngredients.addView(view); } } List<IngredientInfo> mIngredientInfos03 = mRecipeDetailInfo.getmIngredientInfos3(); if (mIngredientInfos03 != null && mIngredientInfos03.size() > 0) { RelativeLayout localRelativeLayout = (RelativeLayout) LayoutInflater.inflate( getSupportActivity(), R.layout.recipe_detail_ingredients_category_name); TextView mTextView = (TextView) localRelativeLayout.findViewById(R.id.ingredientsCategoryName); mTextView.setText( MeishiApplication.getApplication().getString(R.string.fragment_recipe_detail_peiliao)); mLinearLayoutIngredients.addView(localRelativeLayout); for (int i = 0; i < mIngredientInfos03.size(); i = i + 2) { View view = LayoutInflater.inflate(getSupportActivity(), R.layout.recipe_detail_ingredients_item); TextView textView01 = (TextView) view.findViewById(R.id.text11); TextView textView02 = (TextView) view.findViewById(R.id.text12); textView01.setText(mIngredientInfos03.get(i).getIngredientName().trim()); textView02.setText(mIngredientInfos03.get(i).getIngredientScale().trim()); if (i + 1 < mIngredientInfos03.size()) { TextView textView03 = (TextView) view.findViewById(R.id.text21); TextView textView04 = (TextView) view.findViewById(R.id.text22); textView03.setText(mIngredientInfos03.get(i + 1).getIngredientName().trim()); textView04.setText(mIngredientInfos03.get(i + 1).getIngredientScale().trim()); } this.mLinearLayoutIngredients.addView(view); } } if ((mIngredientInfos01 == null || mIngredientInfos01.size() == 0) && (mIngredientInfos02 == null || mIngredientInfos02.size() == 0) && (mIngredientInfos03 == null || mIngredientInfos03.size() == 0)) { TextView mTextView = (TextView) this.mLinearLayoutIngredients.findViewById( R.id.fragment_recipe_detail_main_ingredients_text); mTextView.setVisibility(View.VISIBLE); mTextView.setText( mRecipeDetailInfo.getMainIngredient().replace("<br />", "").replace(" ", "")); } if (!"".equals(mRecipeDetailInfo.getRecipeTips().trim())) { mTextViewTips.setText( mRecipeDetailInfo.getRecipeTips().replace("<br />", "").replace(" ", "")); } else { mTextViewTips.setVisibility(View.GONE); mTextViewTipsText.setVisibility(View.GONE); } mStepInfos = mRecipeDetailInfo.getmStepInfos(); if (mStepInfos != null && mStepInfos.size() > 0) { for (int i = 0; i < mStepInfos.size(); i++) { View view = LayoutInflater.inflate(getSupportActivity(), R.layout.recipe_detail_step_item); ImageView mImageView = (ImageView) view.findViewById(R.id.fragment_recipe_detail_step_image); TextView mTextViewIndex = (TextView) view.findViewById(R.id.fragment_recipe_detail_step_index); TextView mTextViewDesc = (TextView) view.findViewById(R.id.fragment_recipe_detail_step_description); String idx = mStepInfos.get(i).getIdx(); String pic = mStepInfos.get(i).getPic(); String note = mStepInfos.get(i).getNote(); if (!"".equals(pic.trim())) { mImageLoader.displayImage( MeishiApplication.getApplication().isShowPic() ? pic.trim() : null, mImageView, mOptions); } SpannableString spannableString = new SpannableString(idx + "."); spannableString.setSpan( new StyleSpan(Typeface.BOLD_ITALIC), 0, idx.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); mTextViewIndex.setText(spannableString); mTextViewDesc.setText(note.replace("<br />", "").replace(" ", "")); this.mLinearLayoutSteps.addView(view); view.setTag(Integer.valueOf(i)); StepInfoClick stepInfoClick = new StepInfoClick(); view.setOnClickListener(stepInfoClick); } } } }
@Override public final void prepare(final Context context, final LinearLayout items) { final LoadingView loadingView = new LoadingView(context, R.string.download_waiting, true, true); items.addView(loadingView); username = getArguments().getString("user"); final CacheManager cm = CacheManager.getInstance(context); RedditAPI.getUser( cm, username, new APIResponseHandler.UserResponseHandler(context) { @Override protected void onDownloadStarted() { if (!active) return; loadingView.setIndeterminate(R.string.download_connecting); } @Override protected void onSuccess(final RedditUser user, long timestamp) { new Handler(Looper.getMainLooper()) .post( new Runnable() { public void run() { if (!active) return; loadingView.setDone(R.string.download_done); final LinearLayout karmaLayout = (LinearLayout) getLayoutInflater().inflate(R.layout.karma); items.addView(karmaLayout); final TextView linkKarma = (TextView) karmaLayout.findViewById(R.id.layout_karma_text_link); final TextView commentKarma = (TextView) karmaLayout.findViewById(R.id.layout_karma_text_comment); linkKarma.setText(String.valueOf(user.link_karma)); commentKarma.setText(String.valueOf(user.comment_karma)); items.addView( propView( context, R.string.userprofile_created, RRTime.formatDateTime(user.created_utc * 1000, context), false)); if (user.has_mail != null) { items.addView( propView( context, R.string.userprofile_hasmail, user.has_mail ? R.string.general_true : R.string.general_false, false)); } if (user.has_mod_mail != null) { items.addView( propView( context, R.string.userprofile_hasmodmail, user.has_mod_mail ? R.string.general_true : R.string.general_false, false)); } if (user.is_friend) { items.addView( propView( context, R.string.userprofile_isfriend, R.string.general_true, false)); } if (user.is_gold) { items.addView( propView( context, R.string.userprofile_isgold, R.string.general_true, false)); } if (user.is_mod) { items.addView( propView( context, R.string.userprofile_moderator, R.string.general_true, false)); } final Button commentsButton = new Button(context); commentsButton.setText(R.string.userprofile_viewcomments); commentsButton.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { final Intent intent = new Intent(context, CommentListingActivity.class); intent.setData( Uri.parse( Constants.Reddit.getUri( "/user/" + username + "/comments.json") .toString())); startActivity(intent); dismiss(); } }); items.addView(commentsButton); // TODO use margin? or framelayout? scale padding dp // TODO change button color commentsButton.setPadding(20, 20, 20, 20); final Button postsButton = new Button(context); postsButton.setText(R.string.userprofile_viewposts); postsButton.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { final Intent intent = new Intent(context, PostListingActivity.class); intent.putExtra( "subreddit", new RedditSubreddit( "/user/" + username + "/submitted", "Submitted by " + username, false)); startActivity(intent); dismiss(); } }); items.addView(postsButton); // TODO use margin? or framelayout? scale padding dp postsButton.setPadding(20, 20, 20, 20); } }); } @Override protected void onCallbackException(Throwable t) { BugReportActivity.handleGlobalError(context, t); } @Override protected void onFailure( final RequestFailureType type, final Throwable t, final StatusLine status, final String readableMessage) { new Handler(Looper.getMainLooper()) .post( new Runnable() { public void run() { if (!active) return; loadingView.setDone(R.string.download_failed); final RRError error = General.getGeneralErrorForFailure(context, type, t, status); items.addView(new ErrorView(getSupportActivity(), error)); } }); } @Override protected void onFailure(final APIFailureType type) { new Handler(Looper.getMainLooper()) .post( new Runnable() { public void run() { if (!active) return; loadingView.setDone(R.string.download_failed); final RRError error = General.getGeneralErrorForFailure(context, type); items.addView(new ErrorView(getSupportActivity(), error)); } }); } }, RedditAccountManager.getInstance(context).getDefaultAccount(), CacheRequest.DownloadType.FORCE, true, context); }