Skip to content

Commit

Permalink
add reply comment support
Browse files Browse the repository at this point in the history
  • Loading branch information
kyze8439690 committed Mar 6, 2014
1 parent 6b0b951 commit 8f3347a
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 32 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
android:value=".activity.MainActivity" />
</activity>
<activity android:name=".activity.UserActivity"
android:label=""
android:theme="@style/AppTheme.OverlayActionBar"
android:parentActivityName=".activity.MainActivity">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public class CommentDialogFragment extends DialogFragment implements DialogInter
public Dialog onCreateDialog(Bundle savedInstanceState) {
mEditText = (EditText) getActivity().getLayoutInflater().inflate(R.layout.fragment_comment_dialog, null);
if(getArguments().containsKey("comment_content")){
mEditText.setText(getArguments().getString("comment_content"));
mEditText.setText(getArguments().getString("comment_content"));
mEditText.setSelection(mEditText.getText().length());
}
return new AlertDialog.Builder(getActivity())
.setView(mEditText)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class TopicFragment extends Fragment implements AdapterView.OnItemClickLi
private ListView mListView;

private TopicModel mTopicModel;
private ArrayList<ReplyModel> mReplyModels;

private static final int TYPE_EMPTY = 0;
private static final int TYPE_NORMAL = 1;
Expand Down Expand Up @@ -142,8 +143,8 @@ public void onSuccess(JSONArray response) {
return;
}
try {
ArrayList<ReplyModel> models = getModels(response);
mListView.setAdapter(new TopicReplyAdapter(models));
mReplyModels = getModels(response);
mListView.setAdapter(new TopicReplyAdapter(mReplyModels));
mType = TYPE_NORMAL;
mPullToRefreshLayout.setRefreshComplete();
} catch (JSONException e) {
Expand Down Expand Up @@ -194,8 +195,8 @@ public boolean onOptionsItemSelected(MenuItem item) {

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(mType == TYPE_NORMAL){
// MessageUtils.toast(getActivity(), position + "");
if(mType == TYPE_NORMAL && mLogined){

}
}

Expand Down Expand Up @@ -233,8 +234,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
if(item == null){
item = new ReplyView(getActivity());
}
item.parse(getItem(position));
item.setFloorNum(position + 1);
item.parse(mLogined, mTopicModel.id, getItem(position));
return item;
}
}
Expand Down
62 changes: 44 additions & 18 deletions app/src/main/java/com/yugy/v2ex/daily/widget/ReplyView.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.yugy.v2ex.daily.widget;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
Expand All @@ -9,17 +10,21 @@
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.ImageSpan;
import android.text.util.Linkify;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.yugy.v2ex.daily.R;
import com.yugy.v2ex.daily.activity.PhotoViewActivity;
import com.yugy.v2ex.daily.activity.UserActivity;
import com.yugy.v2ex.daily.fragment.CommentDialogFragment;
import com.yugy.v2ex.daily.model.MemberModel;
import com.yugy.v2ex.daily.model.ReplyModel;
import com.yugy.v2ex.daily.model.TopicModel;
import com.yugy.v2ex.daily.network.AsyncImageGetter;

import java.util.ArrayList;
Expand All @@ -44,30 +49,41 @@ public ReplyView(Context context, AttributeSet attrs, int defStyle) {
}

private SelectorImageView mHead;
private TextView mFloor;
private TextView mName;
private ImageButton mReply;
private RelativeTimeTextView mTime;
private TextView mContent;

private MemberModel mMember;

private int mTopicId;
private boolean mLogined;

private void init(){
inflate(getContext(), R.layout.view_reply, this);
mHead = (SelectorImageView) findViewById(R.id.img_view_reply_head);
mFloor = (TextView) findViewById(R.id.txt_view_reply_floor);
mReply = (ImageButton) findViewById(R.id.btn_view_reply_reply);
mName = (TextView) findViewById(R.id.txt_view_reply_name);
mTime = (RelativeTimeTextView) findViewById(R.id.txt_view_reply_time);
mContent = (TextView) findViewById(R.id.txt_view_reply_content);

mHead.setOnClickListener(this);
mReply.setOnClickListener(this);
}

public void parse(ReplyModel model){
mName.setText(model.member.username);
mTime.setReferenceTime(model.created * 1000);
public void parse(boolean logined, int topicId, ReplyModel replyModel){
mLogined = logined;
if(mLogined){
mReply.setVisibility(INVISIBLE);
}else{
mReply.setVisibility(VISIBLE);
}
mTopicId = topicId;
mName.setText(replyModel.member.username);
mTime.setReferenceTime(replyModel.created * 1000);

Spanned spanned = Html.fromHtml(model.contentRendered, new AsyncImageGetter(getContext(), mContent), null);
SpannableStringBuilder htmlSpannable = null;
Spanned spanned = Html.fromHtml(replyModel.contentRendered, new AsyncImageGetter(getContext(), mContent), null);
SpannableStringBuilder htmlSpannable;
if(spanned instanceof SpannableStringBuilder){
htmlSpannable = (SpannableStringBuilder) spanned;
} else {
Expand Down Expand Up @@ -110,21 +126,31 @@ public void onClick(View widget) {
mContent.setText(spanned);
mContent.setMovementMethod(LinkMovementMethod.getInstance());

mMember = model.member;

ImageLoader.getInstance().displayImage(model.member.avatarLarge, mHead);
}
mMember = replyModel.member;

public void setFloorNum(int floorNum){
mFloor.setText(String.valueOf(floorNum));
ImageLoader.getInstance().displayImage(replyModel.member.avatarLarge, mHead);
}

@Override
public void onClick(View v) {
Intent intent = new Intent(getContext(), UserActivity.class);
Bundle argument = new Bundle();
argument.putParcelable("model", mMember);
intent.putExtra("argument", argument);
getContext().startActivity(intent);
Bundle argument;
switch (v.getId()){
case R.id.img_view_reply_head:
Intent intent = new Intent(getContext(), UserActivity.class);
argument = new Bundle();
argument.putParcelable("model", mMember);
intent.putExtra("argument", argument);
getContext().startActivity(intent);
break;
case R.id.btn_view_reply_reply:
CommentDialogFragment commentDialogFragment = new CommentDialogFragment();
argument = new Bundle();
argument.putInt("topic_id", mTopicId);
argument.putString("comment_content", "@" + mMember.username + " ");
commentDialogFragment.setArguments(argument);
commentDialogFragment.show(((Activity)getContext()).getFragmentManager(), "comment");
break;
}

}
}
Binary file added app/src/main/res/drawable-xhdpi/ic_action_reply.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 6 additions & 7 deletions app/src/main/res/layout/view_reply.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
android:background="@drawable/bg_reply"
android:padding="8dp">

<TextView
android:id="@+id/txt_view_reply_floor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<ImageButton
android:id="@+id/btn_view_reply_reply"
android:layout_width="24dp"
android:layout_height="24dp"
style="?android:borderlessButtonStyle"
android:layout_alignParentRight="true"
android:text="1"
android:textColor="#aaa"
android:textSize="12sp"
android:src="@drawable/ic_action_reply"
/>

<com.yugy.v2ex.daily.widget.SelectorImageView
Expand Down

0 comments on commit 8f3347a

Please sign in to comment.