|
@ -19,7 +19,6 @@ import android.text.Editable; |
|
|
import android.text.TextUtils; |
|
|
import android.text.TextUtils; |
|
|
import android.text.TextWatcher; |
|
|
import android.text.TextWatcher; |
|
|
import android.view.LayoutInflater; |
|
|
import android.view.LayoutInflater; |
|
|
import android.view.MotionEvent; |
|
|
|
|
|
import android.view.View; |
|
|
import android.view.View; |
|
|
import android.view.ViewGroup; |
|
|
import android.view.ViewGroup; |
|
|
import android.webkit.WebResourceRequest; |
|
|
import android.webkit.WebResourceRequest; |
|
@ -74,35 +73,30 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
private static int THUMBNAIL_SIZE; |
|
|
private static int THUMBNAIL_SIZE; |
|
|
private final Context context; |
|
|
private final Context context; |
|
|
private String topicTitle; |
|
|
private String topicTitle; |
|
|
private ArrayList<Integer> toQuoteList = new ArrayList<>(); |
|
|
private final 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 |
|
|
* otherwise changed. Used in combination with {@link #isPostDateAndNumberVisibile}, |
|
|
* otherwise changed. Used in combination with {@link #isUserExtraInfoVisibile} and |
|
|
* {@link #isUserExtraInfoVisibile} and {@link #isQuoteButtonChecked}. |
|
|
* {@link #isQuoteButtonChecked}. |
|
|
*/ |
|
|
*/ |
|
|
private final ArrayList<boolean[]> viewProperties = new ArrayList<>(); |
|
|
private final ArrayList<boolean[]> viewProperties = new ArrayList<>(); |
|
|
/** |
|
|
|
|
|
* Index of state indicator in the boolean array. If true post is expanded and post's date and |
|
|
|
|
|
* number are visible. |
|
|
|
|
|
*/ |
|
|
|
|
|
private static final int isPostDateAndNumberVisibile = 0; |
|
|
|
|
|
/** |
|
|
/** |
|
|
* Index of state indicator in the boolean array. If true user's extra info are expanded and |
|
|
* Index of state indicator in the boolean array. If true user's extra info are expanded and |
|
|
* visible. |
|
|
* visible. |
|
|
*/ |
|
|
*/ |
|
|
private static final int isUserExtraInfoVisibile = 1; |
|
|
private static final int isUserExtraInfoVisibile = 0; |
|
|
/** |
|
|
/** |
|
|
* Index of state indicator in the boolean array. If true quote button for this post is checked. |
|
|
* Index of state indicator in the boolean array. If true quote button for this post is checked. |
|
|
*/ |
|
|
*/ |
|
|
private static final int isQuoteButtonChecked = 2; |
|
|
private static final int isQuoteButtonChecked = 1; |
|
|
private TopicActivity.TopicTask topicTask; |
|
|
private TopicActivity.TopicTask topicTask; |
|
|
private TopicActivity.ReplyTask replyTask; |
|
|
private TopicActivity.ReplyTask replyTask; |
|
|
private final int VIEW_TYPE_POST = 0; |
|
|
private final int VIEW_TYPE_POST = 0; |
|
|
private final int VIEW_TYPE_QUICK_REPLY = 1; |
|
|
private final int VIEW_TYPE_QUICK_REPLY = 1; |
|
|
|
|
|
|
|
|
private String[] replyDataHolder = new String[2]; |
|
|
private final String[] replyDataHolder = new String[2]; |
|
|
private int replySubject = 0, replyText = 1; |
|
|
private final int replySubject = 0, replyText = 1; |
|
|
private String loadedPageUrl = ""; |
|
|
private String loadedPageUrl = ""; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -323,9 +317,23 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
if (!currentPost.isDeleted() && viewProperties.get(position)[isUserExtraInfoVisibile]) { |
|
|
if (!currentPost.isDeleted() && viewProperties.get(position)[isUserExtraInfoVisibile]) { |
|
|
holder.userExtraInfo.setVisibility(View.VISIBLE); |
|
|
holder.userExtraInfo.setVisibility(View.VISIBLE); |
|
|
holder.userExtraInfo.setAlpha(1.0f); |
|
|
holder.userExtraInfo.setAlpha(1.0f); |
|
|
|
|
|
|
|
|
|
|
|
holder.username.setMaxLines(Integer.MAX_VALUE); |
|
|
|
|
|
holder.username.setEllipsize(null); |
|
|
|
|
|
|
|
|
|
|
|
holder.subject.setTextColor(Color.parseColor("#FFFFFF")); |
|
|
|
|
|
holder.subject.setMaxLines(Integer.MAX_VALUE); |
|
|
|
|
|
holder.subject.setEllipsize(null); |
|
|
} else { |
|
|
} else { |
|
|
holder.userExtraInfo.setVisibility(View.GONE); |
|
|
holder.userExtraInfo.setVisibility(View.GONE); |
|
|
holder.userExtraInfo.setAlpha(0.0f); |
|
|
holder.userExtraInfo.setAlpha(0.0f); |
|
|
|
|
|
|
|
|
|
|
|
holder.username.setMaxLines(1); |
|
|
|
|
|
holder.username.setEllipsize(TextUtils.TruncateAt.END); |
|
|
|
|
|
|
|
|
|
|
|
holder.subject.setTextColor(Color.parseColor("#757575")); |
|
|
|
|
|
holder.subject.setMaxLines(1); |
|
|
|
|
|
holder.subject.setEllipsize(TextUtils.TruncateAt.END); |
|
|
} |
|
|
} |
|
|
if (!currentPost.isDeleted()) { |
|
|
if (!currentPost.isDeleted()) { |
|
|
//Sets graphics behavior
|
|
|
//Sets graphics behavior
|
|
@ -353,7 +361,9 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
boolean[] tmp = viewProperties.get(holder.getAdapterPosition()); |
|
|
boolean[] tmp = viewProperties.get(holder.getAdapterPosition()); |
|
|
tmp[isUserExtraInfoVisibile] = !tmp[isUserExtraInfoVisibile]; |
|
|
tmp[isUserExtraInfoVisibile] = !tmp[isUserExtraInfoVisibile]; |
|
|
viewProperties.set(holder.getAdapterPosition(), tmp); |
|
|
viewProperties.set(holder.getAdapterPosition(), tmp); |
|
|
TopicAnimations.animateUserExtraInfoVisibility(holder.userExtraInfo); |
|
|
TopicAnimations.animateUserExtraInfoVisibility(holder.username, |
|
|
|
|
|
holder.subject, Color.parseColor("#FFFFFF"), |
|
|
|
|
|
Color.parseColor("#757575"), holder.userExtraInfo); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
//Clicking the expanded part of a header (the extra info) makes it collapse
|
|
|
//Clicking the expanded part of a header (the extra info) makes it collapse
|
|
@ -364,7 +374,9 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
tmp[isUserExtraInfoVisibile] = false; |
|
|
tmp[isUserExtraInfoVisibile] = false; |
|
|
viewProperties.set(holder.getAdapterPosition(), tmp); |
|
|
viewProperties.set(holder.getAdapterPosition(), tmp); |
|
|
|
|
|
|
|
|
TopicAnimations.animateUserExtraInfoVisibility(v); |
|
|
TopicAnimations.animateUserExtraInfoVisibility(holder.username, |
|
|
|
|
|
holder.subject, Color.parseColor("#FFFFFF"), |
|
|
|
|
|
Color.parseColor("#757575"), v); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} else { |
|
|
} else { |
|
@ -372,30 +384,6 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
holder.userExtraInfo.setOnClickListener(null); |
|
|
holder.userExtraInfo.setOnClickListener(null); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Avoid's view's visibility recycling
|
|
|
|
|
|
if (viewProperties.get(position)[isPostDateAndNumberVisibile]) { //Expanded
|
|
|
|
|
|
holder.postDateAndNumberExp.setVisibility(View.VISIBLE); |
|
|
|
|
|
holder.postDateAndNumberExp.setAlpha(1.0f); |
|
|
|
|
|
holder.postDateAndNumberExp.setTranslationY(0); |
|
|
|
|
|
|
|
|
|
|
|
holder.username.setMaxLines(Integer.MAX_VALUE); |
|
|
|
|
|
holder.username.setEllipsize(null); |
|
|
|
|
|
|
|
|
|
|
|
holder.subject.setTextColor(Color.parseColor("#FFFFFF")); |
|
|
|
|
|
holder.subject.setMaxLines(Integer.MAX_VALUE); |
|
|
|
|
|
holder.subject.setEllipsize(null); |
|
|
|
|
|
} else { //Collapsed
|
|
|
|
|
|
holder.postDateAndNumberExp.setVisibility(View.GONE); |
|
|
|
|
|
holder.postDateAndNumberExp.setAlpha(0.0f); |
|
|
|
|
|
holder.postDateAndNumberExp.setTranslationY(holder.postDateAndNumberExp.getHeight()); |
|
|
|
|
|
|
|
|
|
|
|
holder.username.setMaxLines(1); |
|
|
|
|
|
holder.username.setEllipsize(TextUtils.TruncateAt.END); |
|
|
|
|
|
|
|
|
|
|
|
holder.subject.setTextColor(Color.parseColor("#757575")); |
|
|
|
|
|
holder.subject.setMaxLines(1); |
|
|
|
|
|
holder.subject.setEllipsize(TextUtils.TruncateAt.END); |
|
|
|
|
|
} |
|
|
|
|
|
//noinspection PointlessBooleanExpression,ConstantConditions
|
|
|
//noinspection PointlessBooleanExpression,ConstantConditions
|
|
|
if (!BaseActivity.getSessionManager().isLoggedIn()) |
|
|
if (!BaseActivity.getSessionManager().isLoggedIn()) |
|
|
holder.quoteToggle.setVisibility(View.GONE); |
|
|
holder.quoteToggle.setVisibility(View.GONE); |
|
@ -425,23 +413,6 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
//Card expand/collapse when card is touched
|
|
|
|
|
|
holder.cardView.setOnClickListener(new View.OnClickListener() { |
|
|
|
|
|
@Override |
|
|
|
|
|
public void onClick(View view) { |
|
|
|
|
|
//Change post's viewProperties accordingly
|
|
|
|
|
|
boolean[] tmp = viewProperties.get(holder.getAdapterPosition()); |
|
|
|
|
|
tmp[isPostDateAndNumberVisibile] = !tmp[isPostDateAndNumberVisibile]; |
|
|
|
|
|
viewProperties.set(holder.getAdapterPosition(), tmp); |
|
|
|
|
|
|
|
|
|
|
|
TopicAnimations.animatePostExtraInfoVisibility(holder.postDateAndNumberExp |
|
|
|
|
|
, holder.username, holder.subject |
|
|
|
|
|
, Color.parseColor("#FFFFFF") |
|
|
|
|
|
, Color.parseColor("#757575")); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
//Also when post is clicked
|
|
|
|
|
|
holder.post.setOnTouchListener(new CustomTouchListener(holder.post, holder.cardView)); |
|
|
|
|
|
} else if (currentHolder instanceof QuickReplyViewHolder) { |
|
|
} else if (currentHolder instanceof QuickReplyViewHolder) { |
|
|
final QuickReplyViewHolder holder = (QuickReplyViewHolder) currentHolder; |
|
|
final QuickReplyViewHolder holder = (QuickReplyViewHolder) currentHolder; |
|
|
|
|
|
|
|
@ -501,7 +472,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
private class PostViewHolder extends RecyclerView.ViewHolder { |
|
|
private class PostViewHolder extends RecyclerView.ViewHolder { |
|
|
final CardView cardView; |
|
|
final CardView cardView; |
|
|
final LinearLayout cardChildLinear; |
|
|
final LinearLayout cardChildLinear; |
|
|
final FrameLayout postDateAndNumberExp; |
|
|
final FrameLayout postDateAndNumber; |
|
|
final TextView postDate, postNum, username, subject; |
|
|
final TextView postDate, postNum, username, subject; |
|
|
final ImageView thumbnail; |
|
|
final ImageView thumbnail; |
|
|
final public WebView post; |
|
|
final public WebView post; |
|
@ -519,7 +490,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
//Standard stuff
|
|
|
//Standard stuff
|
|
|
cardView = (CardView) view.findViewById(R.id.card_view); |
|
|
cardView = (CardView) view.findViewById(R.id.card_view); |
|
|
cardChildLinear = (LinearLayout) view.findViewById(R.id.card_child_linear); |
|
|
cardChildLinear = (LinearLayout) view.findViewById(R.id.card_child_linear); |
|
|
postDateAndNumberExp = (FrameLayout) view.findViewById(R.id.post_date_and_number_exp); |
|
|
postDateAndNumber = (FrameLayout) view.findViewById(R.id.post_date_and_number_exp); |
|
|
postDate = (TextView) view.findViewById(R.id.post_date); |
|
|
postDate = (TextView) view.findViewById(R.id.post_date); |
|
|
postNum = (TextView) view.findViewById(R.id.post_number); |
|
|
postNum = (TextView) view.findViewById(R.id.post_number); |
|
|
thumbnail = (ImageView) view.findViewById(R.id.thumbnail); |
|
|
thumbnail = (ImageView) view.findViewById(R.id.thumbnail); |
|
@ -568,71 +539,6 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* This class is a gesture detector for WebViews. It handles post's clicks, long clicks and |
|
|
|
|
|
* touch and drag. |
|
|
|
|
|
*/ |
|
|
|
|
|
private class CustomTouchListener implements View.OnTouchListener { |
|
|
|
|
|
//Long press handling
|
|
|
|
|
|
private float downCoordinateX; |
|
|
|
|
|
private float downCoordinateY; |
|
|
|
|
|
private final float SCROLL_THRESHOLD = 7; |
|
|
|
|
|
final private WebView post; |
|
|
|
|
|
final private CardView cardView; |
|
|
|
|
|
|
|
|
|
|
|
//Other variables
|
|
|
|
|
|
final static int FINGER_RELEASED = 0; |
|
|
|
|
|
final static int FINGER_TOUCHED = 1; |
|
|
|
|
|
final static int FINGER_DRAGGING = 2; |
|
|
|
|
|
final static int FINGER_UNDEFINED = 3; |
|
|
|
|
|
|
|
|
|
|
|
private int fingerState = FINGER_RELEASED; |
|
|
|
|
|
|
|
|
|
|
|
CustomTouchListener(WebView pPost, CardView pCard) { |
|
|
|
|
|
post = pPost; |
|
|
|
|
|
cardView = pCard; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public boolean onTouch(View view, MotionEvent motionEvent) { |
|
|
|
|
|
switch (motionEvent.getAction()) { |
|
|
|
|
|
case MotionEvent.ACTION_DOWN: |
|
|
|
|
|
//Logs XY
|
|
|
|
|
|
downCoordinateX = motionEvent.getX(); |
|
|
|
|
|
downCoordinateY = motionEvent.getY(); |
|
|
|
|
|
|
|
|
|
|
|
if (fingerState == FINGER_RELEASED) |
|
|
|
|
|
fingerState = FINGER_TOUCHED; |
|
|
|
|
|
else |
|
|
|
|
|
fingerState = FINGER_UNDEFINED; |
|
|
|
|
|
break; |
|
|
|
|
|
case MotionEvent.ACTION_UP: |
|
|
|
|
|
if (fingerState != FINGER_DRAGGING) { |
|
|
|
|
|
//Doesn't expand the card if this was a link
|
|
|
|
|
|
WebView.HitTestResult htResult = post.getHitTestResult(); |
|
|
|
|
|
if (htResult.getExtra() != null |
|
|
|
|
|
&& htResult.getExtra() != null) { |
|
|
|
|
|
fingerState = FINGER_RELEASED; |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
cardView.performClick(); |
|
|
|
|
|
} |
|
|
|
|
|
fingerState = FINGER_RELEASED; |
|
|
|
|
|
break; |
|
|
|
|
|
case MotionEvent.ACTION_MOVE: |
|
|
|
|
|
//Cancels long click if finger moved too much
|
|
|
|
|
|
if (((Math.abs(downCoordinateX - motionEvent.getX()) > SCROLL_THRESHOLD || |
|
|
|
|
|
Math.abs(downCoordinateY - motionEvent.getY()) > SCROLL_THRESHOLD))) { |
|
|
|
|
|
fingerState = FINGER_DRAGGING; |
|
|
|
|
|
} else fingerState = FINGER_UNDEFINED; |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
fingerState = FINGER_UNDEFINED; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* This class is used to handle link clicks in WebViews. When link url is one that the app can |
|
|
* This class is used to handle link clicks in WebViews. When link url is one that the app can |
|
|
* handle internally, it does. Otherwise user is prompt to open the link in a browser. |
|
|
* handle internally, it does. Otherwise user is prompt to open the link in a browser. |
|
|