|
@ -11,9 +11,11 @@ import android.os.Build; |
|
|
import android.os.Bundle; |
|
|
import android.os.Bundle; |
|
|
import android.support.annotation.NonNull; |
|
|
import android.support.annotation.NonNull; |
|
|
import android.support.v4.content.res.ResourcesCompat; |
|
|
import android.support.v4.content.res.ResourcesCompat; |
|
|
|
|
|
import android.support.v7.widget.AppCompatImageButton; |
|
|
import android.support.v7.widget.CardView; |
|
|
import android.support.v7.widget.CardView; |
|
|
import android.support.v7.widget.RecyclerView; |
|
|
import android.support.v7.widget.RecyclerView; |
|
|
import android.text.TextUtils; |
|
|
import android.text.TextUtils; |
|
|
|
|
|
import android.util.Log; |
|
|
import android.view.LayoutInflater; |
|
|
import android.view.LayoutInflater; |
|
|
import android.view.MotionEvent; |
|
|
import android.view.MotionEvent; |
|
|
import android.view.View; |
|
|
import android.view.View; |
|
@ -21,6 +23,7 @@ import android.view.ViewGroup; |
|
|
import android.webkit.WebResourceRequest; |
|
|
import android.webkit.WebResourceRequest; |
|
|
import android.webkit.WebView; |
|
|
import android.webkit.WebView; |
|
|
import android.webkit.WebViewClient; |
|
|
import android.webkit.WebViewClient; |
|
|
|
|
|
import android.widget.EditText; |
|
|
import android.widget.FrameLayout; |
|
|
import android.widget.FrameLayout; |
|
|
import android.widget.ImageButton; |
|
|
import android.widget.ImageButton; |
|
|
import android.widget.ImageView; |
|
|
import android.widget.ImageView; |
|
@ -31,6 +34,7 @@ import android.widget.TextView; |
|
|
import com.squareup.picasso.Picasso; |
|
|
import com.squareup.picasso.Picasso; |
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.util.Date; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Objects; |
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
@ -50,12 +54,11 @@ import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL; |
|
|
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_THUMBNAIL_URL; |
|
|
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_THUMBNAIL_URL; |
|
|
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL; |
|
|
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_URL; |
|
|
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME; |
|
|
import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_USERNAME; |
|
|
import static gr.thmmy.mthmmy.activities.topic.TopicActivity.toQuoteList; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Custom {@link android.support.v7.widget.RecyclerView.Adapter} used for topics. |
|
|
* Custom {@link android.support.v7.widget.RecyclerView.Adapter} used for topics. |
|
|
*/ |
|
|
*/ |
|
|
class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> { |
|
|
class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
/** |
|
|
/** |
|
|
* Debug Tag for logging debug output to LogCat |
|
|
* Debug Tag for logging debug output to LogCat |
|
|
*/ |
|
|
*/ |
|
@ -65,6 +68,7 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> { |
|
|
*/ |
|
|
*/ |
|
|
private static int THUMBNAIL_SIZE; |
|
|
private static int THUMBNAIL_SIZE; |
|
|
private final Context context; |
|
|
private final Context context; |
|
|
|
|
|
private ArrayList<Integer> toQuoteList = new ArrayList<>(); |
|
|
private final List<Post> postsList; |
|
|
private final List<Post> postsList; |
|
|
/** |
|
|
/** |
|
|
* Used to hold the state of visibility and other attributes for views that are animated or |
|
|
* Used to hold the state of visibility and other attributes for views that are animated or |
|
@ -87,69 +91,16 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> { |
|
|
*/ |
|
|
*/ |
|
|
private static final int isQuoteButtonChecked = 2; |
|
|
private static final int isQuoteButtonChecked = 2; |
|
|
private TopicActivity.TopicTask topicTask; |
|
|
private TopicActivity.TopicTask topicTask; |
|
|
|
|
|
private TopicActivity.ReplyTask replyTask; |
|
|
/** |
|
|
private final int VIEW_TYPE_POST = 0; |
|
|
* Custom {@link RecyclerView.ViewHolder} implementation |
|
|
private final int VIEW_TYPE_QUICK_REPLY = 1; |
|
|
*/ |
|
|
private boolean firstTime = false; |
|
|
class MyViewHolder extends RecyclerView.ViewHolder { |
|
|
|
|
|
final CardView cardView; |
|
|
|
|
|
final LinearLayout cardChildLinear; |
|
|
|
|
|
final FrameLayout postDateAndNumberExp; |
|
|
|
|
|
final TextView postDate, postNum, username, subject; |
|
|
|
|
|
final ImageView thumbnail; |
|
|
|
|
|
final public WebView post; |
|
|
|
|
|
final ImageButton quoteToggle; |
|
|
|
|
|
final RelativeLayout header; |
|
|
|
|
|
final LinearLayout userExtraInfo; |
|
|
|
|
|
final View bodyFooterDivider; |
|
|
|
|
|
final LinearLayout postFooter; |
|
|
|
|
|
|
|
|
|
|
|
final TextView specialRank, rank, gender, numberOfPosts, personalText, stars; |
|
|
|
|
|
|
|
|
|
|
|
MyViewHolder(View view) { |
|
|
|
|
|
super(view); |
|
|
|
|
|
//Initializes layout's graphic elements
|
|
|
|
|
|
//Standard stuff
|
|
|
|
|
|
cardView = (CardView) view.findViewById(R.id.card_view); |
|
|
|
|
|
cardChildLinear = (LinearLayout) view.findViewById(R.id.card_child_linear); |
|
|
|
|
|
postDateAndNumberExp = (FrameLayout) view.findViewById(R.id.post_date_and_number_exp); |
|
|
|
|
|
postDate = (TextView) view.findViewById(R.id.post_date); |
|
|
|
|
|
postNum = (TextView) view.findViewById(R.id.post_number); |
|
|
|
|
|
thumbnail = (ImageView) view.findViewById(R.id.thumbnail); |
|
|
|
|
|
username = (TextView) view.findViewById(R.id.username); |
|
|
|
|
|
subject = (TextView) view.findViewById(R.id.subject); |
|
|
|
|
|
post = (WebView) view.findViewById(R.id.post); |
|
|
|
|
|
post.setBackgroundColor(Color.argb(1, 255, 255, 255)); |
|
|
|
|
|
quoteToggle = (ImageButton) view.findViewById(R.id.toggle_quote_button); |
|
|
|
|
|
bodyFooterDivider = view.findViewById(R.id.body_footer_divider); |
|
|
|
|
|
postFooter = (LinearLayout) view.findViewById(R.id.post_footer); |
|
|
|
|
|
|
|
|
|
|
|
//User's extra info
|
|
|
|
|
|
header = (RelativeLayout) view.findViewById(R.id.header); |
|
|
|
|
|
userExtraInfo = (LinearLayout) view.findViewById(R.id.user_extra_info); |
|
|
|
|
|
specialRank = (TextView) view.findViewById(R.id.special_rank); |
|
|
|
|
|
rank = (TextView) view.findViewById(R.id.rank); |
|
|
|
|
|
gender = (TextView) view.findViewById(R.id.gender); |
|
|
|
|
|
numberOfPosts = (TextView) view.findViewById(R.id.number_of_posts); |
|
|
|
|
|
personalText = (TextView) view.findViewById(R.id.personal_text); |
|
|
|
|
|
stars = (TextView) view.findViewById(R.id.stars); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Cancels all pending Picasso requests |
|
|
|
|
|
*/ |
|
|
|
|
|
void cleanup() { |
|
|
|
|
|
Picasso.with(context).cancelRequest(thumbnail); |
|
|
|
|
|
thumbnail.setImageDrawable(null); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @param context the context of the {@link RecyclerView} |
|
|
* @param context the context of the {@link RecyclerView} |
|
|
* @param postsList List of {@link Post} objects to use |
|
|
* @param postsList List of {@link Post} objects to use |
|
|
*/ |
|
|
*/ |
|
|
TopicAdapter(Context context, List<Post> postsList, |
|
|
TopicAdapter(Context context, List<Post> postsList, TopicActivity.TopicTask topicTask) { |
|
|
TopicActivity.TopicTask topicTask) { |
|
|
|
|
|
this.context = context; |
|
|
this.context = context; |
|
|
this.postsList = postsList; |
|
|
this.postsList = postsList; |
|
|
|
|
|
|
|
@ -161,22 +112,36 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> { |
|
|
this.topicTask = topicTask; |
|
|
this.topicTask = topicTask; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void prepareForReply(TopicActivity.ReplyTask replyTask) { |
|
|
|
|
|
this.replyTask = replyTask; |
|
|
|
|
|
firstTime = true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void onViewRecycled(final MyViewHolder holder) { |
|
|
public int getItemViewType(int position) { |
|
|
holder.cleanup(); |
|
|
return postsList.get(position) == null ? VIEW_TYPE_QUICK_REPLY : VIEW_TYPE_POST; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { |
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { |
|
|
|
|
|
if (viewType == VIEW_TYPE_POST) { |
|
|
View itemView = LayoutInflater.from(parent.getContext()) |
|
|
View itemView = LayoutInflater.from(parent.getContext()) |
|
|
.inflate(R.layout.activity_topic_post_row, parent, false); |
|
|
.inflate(R.layout.activity_topic_post_row, parent, false); |
|
|
return new MyViewHolder(itemView); |
|
|
return new PostViewHolder(itemView); |
|
|
|
|
|
} else if (viewType == VIEW_TYPE_QUICK_REPLY) { |
|
|
|
|
|
View view = LayoutInflater.from(parent.getContext()). |
|
|
|
|
|
inflate(R.layout.activity_topic_quick_reply_row, parent, false); |
|
|
|
|
|
return new QuickReplyViewHolder(view); |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@SuppressLint("SetJavaScriptEnabled") |
|
|
@SuppressLint("SetJavaScriptEnabled") |
|
|
@Override |
|
|
@Override |
|
|
public void onBindViewHolder(final MyViewHolder holder, final int position) { |
|
|
public void onBindViewHolder(final RecyclerView.ViewHolder currentHolder, final int position) { |
|
|
|
|
|
if (currentHolder instanceof PostViewHolder) { |
|
|
final Post currentPost = postsList.get(position); |
|
|
final Post currentPost = postsList.get(position); |
|
|
|
|
|
final PostViewHolder holder = (PostViewHolder) currentHolder; |
|
|
|
|
|
|
|
|
//Post's WebView parameters
|
|
|
//Post's WebView parameters
|
|
|
holder.post.setClickable(true); |
|
|
holder.post.setClickable(true); |
|
@ -435,6 +400,34 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> { |
|
|
}); |
|
|
}); |
|
|
//Also when post is clicked
|
|
|
//Also when post is clicked
|
|
|
holder.post.setOnTouchListener(new CustomTouchListener(holder.post, holder.cardView)); |
|
|
holder.post.setOnTouchListener(new CustomTouchListener(holder.post, holder.cardView)); |
|
|
|
|
|
} else if (currentHolder instanceof QuickReplyViewHolder) { |
|
|
|
|
|
final QuickReplyViewHolder holder = (QuickReplyViewHolder) currentHolder; |
|
|
|
|
|
if (firstTime) { |
|
|
|
|
|
//Build quotes
|
|
|
|
|
|
String quotes = ""; |
|
|
|
|
|
for (int quotePosition : toQuoteList) { |
|
|
|
|
|
//Date postDate = new Date();
|
|
|
|
|
|
Log.d(TAG, postsList.get(quotePosition).getPostDate()); |
|
|
|
|
|
if (postsList.get(quotePosition).getPostIndex() != 0) { |
|
|
|
|
|
quotes += "[quote author=" + postsList.get(quotePosition).getAuthor() |
|
|
|
|
|
+ " link=topic=68525.msg" + postsList.get(quotePosition).getPostIndex() |
|
|
|
|
|
+ "#msg" + postsList.get(quotePosition).getPostIndex() |
|
|
|
|
|
+ " date=" + "1000" |
|
|
|
|
|
+ "\n" + postsList.get(quotePosition).getContent() |
|
|
|
|
|
+ "\n" + "[/quote]" + "\n"; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
holder.quickReply.setText(quotes); |
|
|
|
|
|
} |
|
|
|
|
|
holder.submitButton.setOnClickListener(new View.OnClickListener() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onClick(View view) { |
|
|
|
|
|
if (holder.quickReply.getText().toString().isEmpty()) return; |
|
|
|
|
|
holder.submitButton.setEnabled(false); |
|
|
|
|
|
replyTask.execute(holder.quickReply.getText().toString()); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void customNotifyDataSetChanged(TopicActivity.TopicTask topicTask) { |
|
|
void customNotifyDataSetChanged(TopicActivity.TopicTask topicTask) { |
|
@ -452,6 +445,68 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> { |
|
|
return postsList.size(); |
|
|
return postsList.size(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Custom {@link RecyclerView.ViewHolder} implementation |
|
|
|
|
|
*/ |
|
|
|
|
|
private class PostViewHolder extends RecyclerView.ViewHolder { |
|
|
|
|
|
final CardView cardView; |
|
|
|
|
|
final LinearLayout cardChildLinear; |
|
|
|
|
|
final FrameLayout postDateAndNumberExp; |
|
|
|
|
|
final TextView postDate, postNum, username, subject; |
|
|
|
|
|
final ImageView thumbnail; |
|
|
|
|
|
final public WebView post; |
|
|
|
|
|
final ImageButton quoteToggle; |
|
|
|
|
|
final RelativeLayout header; |
|
|
|
|
|
final LinearLayout userExtraInfo; |
|
|
|
|
|
final View bodyFooterDivider; |
|
|
|
|
|
final LinearLayout postFooter; |
|
|
|
|
|
|
|
|
|
|
|
final TextView specialRank, rank, gender, numberOfPosts, personalText, stars; |
|
|
|
|
|
|
|
|
|
|
|
PostViewHolder(View view) { |
|
|
|
|
|
super(view); |
|
|
|
|
|
//Initializes layout's graphic elements
|
|
|
|
|
|
//Standard stuff
|
|
|
|
|
|
cardView = (CardView) view.findViewById(R.id.card_view); |
|
|
|
|
|
cardChildLinear = (LinearLayout) view.findViewById(R.id.card_child_linear); |
|
|
|
|
|
postDateAndNumberExp = (FrameLayout) view.findViewById(R.id.post_date_and_number_exp); |
|
|
|
|
|
postDate = (TextView) view.findViewById(R.id.post_date); |
|
|
|
|
|
postNum = (TextView) view.findViewById(R.id.post_number); |
|
|
|
|
|
thumbnail = (ImageView) view.findViewById(R.id.thumbnail); |
|
|
|
|
|
username = (TextView) view.findViewById(R.id.username); |
|
|
|
|
|
subject = (TextView) view.findViewById(R.id.subject); |
|
|
|
|
|
post = (WebView) view.findViewById(R.id.post); |
|
|
|
|
|
post.setBackgroundColor(Color.argb(1, 255, 255, 255)); |
|
|
|
|
|
quoteToggle = (ImageButton) view.findViewById(R.id.toggle_quote_button); |
|
|
|
|
|
bodyFooterDivider = view.findViewById(R.id.body_footer_divider); |
|
|
|
|
|
postFooter = (LinearLayout) view.findViewById(R.id.post_footer); |
|
|
|
|
|
|
|
|
|
|
|
//User's extra info
|
|
|
|
|
|
header = (RelativeLayout) view.findViewById(R.id.header); |
|
|
|
|
|
userExtraInfo = (LinearLayout) view.findViewById(R.id.user_extra_info); |
|
|
|
|
|
specialRank = (TextView) view.findViewById(R.id.special_rank); |
|
|
|
|
|
rank = (TextView) view.findViewById(R.id.rank); |
|
|
|
|
|
gender = (TextView) view.findViewById(R.id.gender); |
|
|
|
|
|
numberOfPosts = (TextView) view.findViewById(R.id.number_of_posts); |
|
|
|
|
|
personalText = (TextView) view.findViewById(R.id.personal_text); |
|
|
|
|
|
stars = (TextView) view.findViewById(R.id.stars); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Custom {@link RecyclerView.ViewHolder} implementation |
|
|
|
|
|
*/ |
|
|
|
|
|
private static class QuickReplyViewHolder extends RecyclerView.ViewHolder { |
|
|
|
|
|
final EditText quickReply; |
|
|
|
|
|
final AppCompatImageButton submitButton; |
|
|
|
|
|
|
|
|
|
|
|
QuickReplyViewHolder(View quickReply) { |
|
|
|
|
|
super(quickReply); |
|
|
|
|
|
this.quickReply = (EditText) quickReply.findViewById(R.id.quick_reply_text); |
|
|
|
|
|
submitButton = (AppCompatImageButton) quickReply.findViewById(R.id.quick_reply_submit); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* This class is a gesture detector for WebViews. It handles post's clicks, long clicks and |
|
|
* This class is a gesture detector for WebViews. It handles post's clicks, long clicks and |
|
|
* touch and drag. |
|
|
* touch and drag. |
|
@ -592,6 +647,7 @@ class TopicAdapter extends RecyclerView.Adapter<TopicAdapter.MyViewHolder> { |
|
|
//Method always returns true as no url should be loaded in the WebViews
|
|
|
//Method always returns true as no url should be loaded in the WebViews
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|