From 8b995830004c05bcf6a09aaa43ebd6fb184c3d69 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Sat, 15 Jul 2017 00:11:01 +0300 Subject: [PATCH] Post's date and index visible by default, unread posts tab minor fix --- .../main/unread/UnreadFragment.java | 6 +- .../activities/topic/TopicActivity.java | 16 +- .../mthmmy/activities/topic/TopicAdapter.java | 152 ++++-------------- .../activities/topic/TopicAnimations.java | 86 +++------- .../layout-v21/activity_topic_post_row.xml | 112 ++++++------- .../res/layout/activity_topic_post_row.xml | 99 ++++++------ app/src/main/res/menu/topic_menu.xml | 4 +- app/src/main/res/values/strings.xml | 1 + 8 files changed, 161 insertions(+), 315 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java index 4b5e6b6c..f5145c43 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java @@ -150,18 +150,20 @@ public class UnreadFragment extends BaseFragment { Log.d("UnreadFragment", unread.html()); for (Element row : unread) { Elements information = row.select("td"); - String link = information.get(2).select("a").first().attr("href"); + String link = information.last().select("a").first().attr("href"); String title = information.get(2).select("a").first().text(); Element lastUserAndDate = information.get(6); String lastUser = lastUserAndDate.select("a").text(); String dateTime = lastUserAndDate.select("span").html(); - dateTime = dateTime.substring(3, dateTime.indexOf("
")); + //dateTime = dateTime.replace("
", ""); + dateTime = dateTime.substring(0, dateTime.indexOf("
")); dateTime = dateTime.replace("", ""); topicSummaries.add(new TopicSummary(link, title, lastUser, dateTime)); } } else { + topicSummaries.clear(); String message = document.select("table.bordercolor[cellspacing=1]").first().text(); if (message.contains("No messages")){ //It's english message = "No unread posts!"; diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java index e097f937..f96f30bc 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.graphics.Rect; import android.net.Uri; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.support.design.widget.FloatingActionButton; @@ -114,12 +115,12 @@ public class TopicActivity extends BaseActivity { topicViewers = new SpannableStringBuilder("Loading..."); //Other variables private MaterialProgressBar progressBar; - TextView toolbarTitle; + private TextView toolbarTitle; private static String base_url = ""; private String topicTitle; private String parsedTitle; private RecyclerView recyclerView; - String loadedPageUrl = ""; + private String loadedPageUrl = ""; private boolean reloadingPage = false; @@ -665,7 +666,13 @@ public class TopicActivity extends BaseActivity { } private SpannableStringBuilder getSpannableFromHtml(String html) { - CharSequence sequence = Html.fromHtml(html); + CharSequence sequence; + if (Build.VERSION.SDK_INT >= 24) { + sequence = Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY); + } else { + //noinspection deprecation + sequence = Html.fromHtml(html); + } SpannableStringBuilder strBuilder = new SpannableStringBuilder(sequence); URLSpan[] urls = strBuilder.getSpans(0, sequence.length(), URLSpan.class); for (URLSpan span : urls) { @@ -687,7 +694,7 @@ public class TopicActivity extends BaseActivity { @Override protected Boolean doInBackground(String... message) { Document document; - String numReplies, seqnum, sc, subject, topic; + String numReplies, seqnum, sc, topic; Request request = new Request.Builder() .url(replyPageUrl + ";wap2") @@ -699,7 +706,6 @@ public class TopicActivity extends BaseActivity { numReplies = replyPageUrl.substring(replyPageUrl.indexOf("num_replies=") + 12); seqnum = document.select("input[name=seqnum]").first().attr("value"); sc = document.select("input[name=sc]").first().attr("value"); - //subject = document.select("input[name=subject]").first().attr("value"); topic = document.select("input[name=topic]").first().attr("value"); } catch (IOException e) { Timber.e(e,"Post failed."); diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java index 42c29531..3c848c72 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java @@ -19,7 +19,6 @@ import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; import android.view.LayoutInflater; -import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.webkit.WebResourceRequest; @@ -74,35 +73,30 @@ class TopicAdapter extends RecyclerView.Adapter { private static int THUMBNAIL_SIZE; private final Context context; private String topicTitle; - private ArrayList toQuoteList = new ArrayList<>(); + private final ArrayList toQuoteList = new ArrayList<>(); private final List postsList; /** * Used to hold the state of visibility and other attributes for views that are animated or - * otherwise changed. Used in combination with {@link #isPostDateAndNumberVisibile}, - * {@link #isUserExtraInfoVisibile} and {@link #isQuoteButtonChecked}. + * otherwise changed. Used in combination with {@link #isUserExtraInfoVisibile} and + * {@link #isQuoteButtonChecked}. */ private final ArrayList 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 * 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. */ - private static final int isQuoteButtonChecked = 2; + private static final int isQuoteButtonChecked = 1; private TopicActivity.TopicTask topicTask; private TopicActivity.ReplyTask replyTask; private final int VIEW_TYPE_POST = 0; private final int VIEW_TYPE_QUICK_REPLY = 1; - private String[] replyDataHolder = new String[2]; - private int replySubject = 0, replyText = 1; + private final String[] replyDataHolder = new String[2]; + private final int replySubject = 0, replyText = 1; private String loadedPageUrl = ""; /** @@ -323,9 +317,23 @@ class TopicAdapter extends RecyclerView.Adapter { if (!currentPost.isDeleted() && viewProperties.get(position)[isUserExtraInfoVisibile]) { holder.userExtraInfo.setVisibility(View.VISIBLE); 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 { holder.userExtraInfo.setVisibility(View.GONE); 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()) { //Sets graphics behavior @@ -353,7 +361,9 @@ class TopicAdapter extends RecyclerView.Adapter { boolean[] tmp = viewProperties.get(holder.getAdapterPosition()); tmp[isUserExtraInfoVisibile] = !tmp[isUserExtraInfoVisibile]; 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 @@ -364,7 +374,9 @@ class TopicAdapter extends RecyclerView.Adapter { tmp[isUserExtraInfoVisibile] = false; viewProperties.set(holder.getAdapterPosition(), tmp); - TopicAnimations.animateUserExtraInfoVisibility(v); + TopicAnimations.animateUserExtraInfoVisibility(holder.username, + holder.subject, Color.parseColor("#FFFFFF"), + Color.parseColor("#757575"), v); } }); } else { @@ -372,30 +384,6 @@ class TopicAdapter extends RecyclerView.Adapter { 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 if (!BaseActivity.getSessionManager().isLoggedIn()) holder.quoteToggle.setVisibility(View.GONE); @@ -425,23 +413,6 @@ class TopicAdapter extends RecyclerView.Adapter { } }); } - //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) { final QuickReplyViewHolder holder = (QuickReplyViewHolder) currentHolder; @@ -501,7 +472,7 @@ class TopicAdapter extends RecyclerView.Adapter { private class PostViewHolder extends RecyclerView.ViewHolder { final CardView cardView; final LinearLayout cardChildLinear; - final FrameLayout postDateAndNumberExp; + final FrameLayout postDateAndNumber; final TextView postDate, postNum, username, subject; final ImageView thumbnail; final public WebView post; @@ -519,7 +490,7 @@ class TopicAdapter extends RecyclerView.Adapter { //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); + postDateAndNumber = (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); @@ -568,71 +539,6 @@ class TopicAdapter extends RecyclerView.Adapter { } } - /** - * 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 * handle internally, it does. Otherwise user is prompt to open the link in a browser. diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAnimations.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAnimations.java index c0206a1d..ae4516ef 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAnimations.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAnimations.java @@ -7,80 +7,16 @@ import android.view.View; import android.widget.TextView; class TopicAnimations { - //--------------------------POST'S INFO VISIBILITY CHANGE ANIMATION METHOD-------------------------- - - /** - * Method that animates view's visibility changes for post's extra info - */ - static void animatePostExtraInfoVisibility(final View dateAndPostNum, TextView username, - TextView subject, int expandedColor, int collapsedColor) { - //If the view is gone fade it in - if (dateAndPostNum.getVisibility() == View.GONE) { - //Show full username - username.setMaxLines(Integer.MAX_VALUE); //As in the android sourcecode - username.setEllipsize(null); - - //Show full subject - subject.setTextColor(expandedColor); - subject.setMaxLines(Integer.MAX_VALUE); //As in the android sourcecode - subject.setEllipsize(null); - - - dateAndPostNum.clearAnimation(); - // Prepare the View for the animation - dateAndPostNum.setVisibility(View.VISIBLE); - dateAndPostNum.setAlpha(0.0f); - - // Start the animation - dateAndPostNum.animate() - .translationY(0) - .alpha(1.0f) - .setDuration(300) - .setListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - super.onAnimationEnd(animation); - dateAndPostNum.setVisibility(View.VISIBLE); - } - }); - } - //If the view is visible fade it out - else { - username.setMaxLines(1); //As in the android sourcecode - username.setEllipsize(TextUtils.TruncateAt.END); - - subject.setTextColor(collapsedColor); - subject.setMaxLines(1); //As in the android sourcecode - subject.setEllipsize(TextUtils.TruncateAt.END); - - dateAndPostNum.clearAnimation(); - - // Start the animation - dateAndPostNum.animate() - .translationY(dateAndPostNum.getHeight()) - .alpha(0.0f) - .setDuration(300) - .setListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - super.onAnimationEnd(animation); - dateAndPostNum.setVisibility(View.GONE); - } - }); - } - } -//------------------------POST'S INFO VISIBILITY CHANGE ANIMATION METHOD END------------------------ - //--------------------------USER'S INFO VISIBILITY CHANGE ANIMATION METHOD-------------------------- /** * Method that animates view's visibility changes for user's extra info */ - static void animateUserExtraInfoVisibility(final View userExtra) { - + static void animateUserExtraInfoVisibility(TextView username, TextView subject, + int expandedColor, int collapsedColor, + final View userExtra) { //If the view is gone fade it in if (userExtra.getVisibility() == View.GONE) { - userExtra.clearAnimation(); userExtra.setVisibility(View.VISIBLE); userExtra.setAlpha(0.0f); @@ -96,6 +32,15 @@ class TopicAnimations { userExtra.setVisibility(View.VISIBLE); } }); + + //Show full username + username.setMaxLines(Integer.MAX_VALUE); //As in the android sourcecode + username.setEllipsize(null); + + //Show full subject + subject.setTextColor(expandedColor); + subject.setMaxLines(Integer.MAX_VALUE); //As in the android sourcecode + subject.setEllipsize(null); } //If the view is visible fade it out else { @@ -112,6 +57,13 @@ class TopicAnimations { userExtra.setVisibility(View.GONE); } }); + + username.setMaxLines(1); //As in the android sourcecode + username.setEllipsize(TextUtils.TruncateAt.END); + + subject.setTextColor(collapsedColor); + subject.setMaxLines(1); //As in the android sourcecode + subject.setEllipsize(TextUtils.TruncateAt.END); } } //------------------------POST'S INFO VISIBILITY CHANGE ANIMATION METHOD END------------------------ diff --git a/app/src/main/res/layout-v21/activity_topic_post_row.xml b/app/src/main/res/layout-v21/activity_topic_post_row.xml index 8b745727..64bd6610 100644 --- a/app/src/main/res/layout-v21/activity_topic_post_row.xml +++ b/app/src/main/res/layout-v21/activity_topic_post_row.xml @@ -1,48 +1,14 @@ - - - - - - - - - + + + android:transitionName="user_thumbnail" /> + android:textStyle="bold" /> + android:text="@string/post_subject" /> + android:src="@drawable/ic_format_quote_unchecked" /> + android:visibility="gone" /> + android:visibility="gone" /> - + android:visibility="gone" /> + android:visibility="gone" /> + android:visibility="gone" /> + android:visibility="gone" /> + + + + + + + + + android:layout_marginTop="5dp" + android:background="@color/divider" /> + android:text="@string/post" /> + android:visibility="gone" /> - + android:paddingRight="16dp" /> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_topic_post_row.xml b/app/src/main/res/layout/activity_topic_post_row.xml index 677a58db..696566e1 100644 --- a/app/src/main/res/layout/activity_topic_post_row.xml +++ b/app/src/main/res/layout/activity_topic_post_row.xml @@ -1,6 +1,5 @@ - - - - - - - - - + android:src="@drawable/ic_default_user_thumbnail" /> + android:textStyle="bold" /> + android:text="@string/post_subject" /> + android:src="@drawable/ic_format_quote_unchecked" /> + android:visibility="gone" /> + android:visibility="gone" /> - + android:visibility="gone" /> + android:visibility="gone" /> + android:visibility="gone" /> + android:visibility="gone" /> + + + + + + + + + android:layout_marginTop="5dp" + android:background="@color/divider" /> + android:text="@string/post" /> + android:visibility="gone" /> - + android:paddingRight="16dp" /> \ No newline at end of file diff --git a/app/src/main/res/menu/topic_menu.xml b/app/src/main/res/menu/topic_menu.xml index 16c60e0a..e9ca1807 100644 --- a/app/src/main/res/menu/topic_menu.xml +++ b/app/src/main/res/menu/topic_menu.xml @@ -5,12 +5,12 @@ android:id="@+id/menu_bookmark" android:icon="@drawable/ic_bookmark_false" app:showAsAction="ifRoom" - android:title="Bookmark"> + android:title="@string/bookmark"> + android:title="@string/info"> \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6faf81e1..5c6dc980 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -9,6 +9,7 @@ About Home Bookmarks + Info thmmy.gr