From d46f4415222d531cafda885e819faddabe0c87eb Mon Sep 17 00:00:00 2001 From: Apostolof Date: Sat, 31 Dec 2016 20:10:45 +0200 Subject: [PATCH] Code cleanup and fixes. --- .../activities/topic/TopicActivity.java | 4 +- .../mthmmy/activities/topic/TopicAdapter.java | 55 ++++++++---------- .../drawable-hdpi/ic_format_quote_checked.png | Bin 0 -> 258 bytes .../ic_format_quote_unchecked.png | Bin 0 -> 257 bytes .../drawable-mdpi/ic_format_quote_checked.png | Bin 0 -> 189 bytes .../ic_format_quote_unchecked.png | Bin 0 -> 187 bytes .../ic_format_quote_checked.png | Bin 0 -> 240 bytes .../ic_format_quote_unchecked.png | Bin 0 -> 236 bytes .../ic_format_quote_checked.png | Bin 0 -> 424 bytes .../ic_format_quote_unchecked.png | Bin 0 -> 421 bytes .../ic_format_quote_checked.png | Bin 0 -> 505 bytes .../ic_format_quote_unchecked.png | Bin 0 -> 502 bytes .../res/drawable/ic_format_quote_accent.png | Bin 264 -> 0 bytes .../res/drawable/ic_format_quote_grey.png | Bin 259 -> 0 bytes .../main/res/drawable/ic_toggle_quote_bg.xml | 5 -- .../layout-v21/activity_topic_post_row.xml | 8 ++- .../res/layout/activity_topic_post_row.xml | 6 +- 17 files changed, 34 insertions(+), 44 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_format_quote_checked.png create mode 100644 app/src/main/res/drawable-hdpi/ic_format_quote_unchecked.png create mode 100644 app/src/main/res/drawable-mdpi/ic_format_quote_checked.png create mode 100644 app/src/main/res/drawable-mdpi/ic_format_quote_unchecked.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_format_quote_checked.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_format_quote_unchecked.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_format_quote_checked.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_format_quote_unchecked.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_format_quote_checked.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_format_quote_unchecked.png delete mode 100644 app/src/main/res/drawable/ic_format_quote_accent.png delete mode 100644 app/src/main/res/drawable/ic_format_quote_grey.png delete mode 100644 app/src/main/res/drawable/ic_toggle_quote_bg.xml 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 53849692..bd8ba2e9 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 @@ -214,8 +214,7 @@ public class TopicActivity extends BaseActivity { topicTask.cancel(true); } - - //--------------------------------------BOTTOM NAV BAR METHODS-------------------------------------- +//--------------------------------------BOTTOM NAV BAR METHODS-------------------------------------- private void initIncrementButton(ImageButton increment, final int step) { // Increment once for a click increment.setOnClickListener(new View.OnClickListener() { @@ -361,6 +360,7 @@ public class TopicActivity extends BaseActivity { } if (!loadedPageUrl.contains(base_url)) { + loadedPageUrl = newPageUrl; Request request = new Request.Builder() .url(newPageUrl) .build(); 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 7cbce162..27267f12 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 @@ -10,13 +10,13 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; -import android.os.Handler; import android.os.PowerManager; import android.support.annotation.NonNull; import android.support.v4.content.res.ResourcesCompat; import android.support.v7.widget.CardView; import android.support.v7.widget.RecyclerView; import android.text.TextUtils; +import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; @@ -179,7 +179,7 @@ class TopicAdapter extends RecyclerView.Adapter { @SuppressLint("SetJavaScriptEnabled") @Override - public void onBindViewHolder(final MyViewHolder holder, int position) { + public void onBindViewHolder(final MyViewHolder holder, final int position) { final Post currentPost = postsList.get(position); //Post's WebView parameters @@ -359,27 +359,38 @@ class TopicAdapter extends RecyclerView.Adapter { holder.subject.setMaxLines(1); holder.subject.setEllipsize(TextUtils.TruncateAt.END); } + if(viewProperties.get(position)[isQuoteButtonChecked]) + holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_checked); + else + holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_unchecked); //Sets graphics behavior holder.quoteToggle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - if (view.isSelected()) { + boolean[] tmp = viewProperties.get(holder.getAdapterPosition()); + Log.d(TAG, "GOT"); + if (tmp[isQuoteButtonChecked]) { if (toQuoteList.contains(currentPost.getPostNumber())) { toQuoteList.remove(toQuoteList.indexOf(currentPost.getPostNumber())); - view.setSelected(false); + Log.d(TAG, "GOT1"); } else - Report.i(TAG, "An error occurred while trying to exclude post from" + - "toQuoteList, post wasn't there!"); + Log.d(TAG, "GOT2"); + //Report.i(TAG, "An error occurred while trying to exclude post from" + + // "toQuoteList, post wasn't there!"); + holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_unchecked); } else { + Log.d(TAG, "GOT3"); toQuoteList.add(currentPost.getPostNumber()); - view.setSelected(true); + holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_checked); } + tmp[isQuoteButtonChecked] = !tmp[isQuoteButtonChecked]; + viewProperties.set(holder.getAdapterPosition(), tmp); } }); //Card expand/collapse when card is touched holder.cardView.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View v) { + public void onClick(View view) { //Change post's viewProperties accordingly boolean[] tmp = viewProperties.get(holder.getAdapterPosition()); tmp[isPostDateAndNumberVisibile] = !tmp[isPostDateAndNumberVisibile]; @@ -392,7 +403,7 @@ class TopicAdapter extends RecyclerView.Adapter { } }); //Also when post is clicked - holder.post.setOnTouchListener(new CustomTouchListener(holder.post, holder.cardView, holder.quoteToggle)); + holder.post.setOnTouchListener(new CustomTouchListener(holder.post, holder.cardView)); } @Override @@ -406,15 +417,11 @@ class TopicAdapter extends RecyclerView.Adapter { */ private class CustomTouchListener implements View.OnTouchListener { //Long press handling - private final int LONG_PRESS_REQUIRED_DURATION = 650; - private final Handler webViewLongClickHandler = new Handler(); - private boolean wasLongClick = false; private float downCoordinateX; private float downCoordinateY; private final float SCROLL_THRESHOLD = 7; final private WebView post; final private CardView cardView; - final private ImageButton quoteToggle; //Other variables final static int FINGER_RELEASED = 0; @@ -424,19 +431,11 @@ class TopicAdapter extends RecyclerView.Adapter { private int fingerState = FINGER_RELEASED; - CustomTouchListener(WebView pPost, CardView pCard, ImageButton pQuoteToggle) { + CustomTouchListener(WebView pPost, CardView pCard) { post = pPost; cardView = pCard; - quoteToggle = pQuoteToggle; } - final Runnable WebViewLongClick = new Runnable() { - public void run() { - wasLongClick = true; - quoteToggle.performClick(); - } - }; - @Override public boolean onTouch(View view, MotionEvent motionEvent) { switch (motionEvent.getAction()) { @@ -449,14 +448,9 @@ class TopicAdapter extends RecyclerView.Adapter { fingerState = FINGER_TOUCHED; else fingerState = FINGER_UNDEFINED; - - webViewLongClickHandler.postDelayed(WebViewLongClick - , LONG_PRESS_REQUIRED_DURATION); break; case MotionEvent.ACTION_UP: - webViewLongClickHandler.removeCallbacks(WebViewLongClick); - - if (!wasLongClick && fingerState != FINGER_DRAGGING) { + if (fingerState != FINGER_DRAGGING) { //Doesn't expand the card if this was a link WebView.HitTestResult htResult = post.getHitTestResult(); if (htResult.getExtra() != null @@ -464,17 +458,14 @@ class TopicAdapter extends RecyclerView.Adapter { fingerState = FINGER_RELEASED; return false; } - cardView.performClick(); - } else - wasLongClick = false; + } 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))) { - webViewLongClickHandler.removeCallbacks(WebViewLongClick); fingerState = FINGER_DRAGGING; } else fingerState = FINGER_UNDEFINED; break; diff --git a/app/src/main/res/drawable-hdpi/ic_format_quote_checked.png b/app/src/main/res/drawable-hdpi/ic_format_quote_checked.png new file mode 100644 index 0000000000000000000000000000000000000000..bd7be5355ae869a35efa3f9fa2b69bcdabeb6e3f GIT binary patch literal 258 zcmeAS@N?(olHy`uVBq!ia0vp^W+2SL1|)l2v+e?^lb$Y)Ar-gY-q^_7Y#`8@Xv|P6 z)*v{ka8hMLv&oVq=C*`MUrIb3i#+r!yNpjoKGcu<{l(6Enri#5{q6NW3~W3S1_=im z7@664ZX8UQ-|}aZFkAr0Xm8DZsxos5V{`a(xee_`4^&s~u?h|pKe?tS!^S!|pfx3g z%|>-;dOFveZG}76-?ph^Yk<)$xQO@d(=}T_UCB!{CnvqH$4$Z=Bf5!VB?W6NI1~I z$jrub<6y%5o06g{rqmrqE#hL-pt2JKCPP@7O|RV#(TG5r{$>*x|Q0>R?1nQ{Z4l{ qN*XNvzP!V)uBj1ZE7Z2Iin^~)Zlp=5%fA8oiNVv=&t;ucLK6T60Ak|+ literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_format_quote_checked.png b/app/src/main/res/drawable-mdpi/ic_format_quote_checked.png new file mode 100644 index 0000000000000000000000000000000000000000..9b28f144f3db5989c009145aa1124543f002a594 GIT binary patch literal 189 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k1|%Oc%$NbBT0C7GLn>~)y|z)XK|#PJQ0IWr z65X}#)*BeC7jS4TWb^#Ow5a>s#~F%04z}&y(;&(5(dw`VX9EKx6Uzy{s-BOpfD8_S z1^fMvtDMX-srdrl5YoyT1kW)qw6{@O1TaS?83{1OOa6L>K@7 literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_format_quote_unchecked.png b/app/src/main/res/drawable-mdpi/ic_format_quote_unchecked.png new file mode 100644 index 0000000000000000000000000000000000000000..0b2b07fa009a6128124df3f298993848e2d71091 GIT binary patch literal 187 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k1|%Oc%$NbBnmk<`Ln>~)y|z)XK|#PJQ0IWr z7Tw$?wJma83xu*RxaceFdLi>ZjiYYELp}WjwxDyCy;E2?1QZ+^-YhsSv0e_yU|{_9 zyToVGD!1If2d>3iBdCAI$%8Sxj=VopBdiYMY*cq*zS3ihd-Q3V6wf66# lwl6;nnV48OF1%PEuC4bjuI1ulDWGc@JYD@<);T3K0RT^rNT>h+ literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/ic_format_quote_checked.png b/app/src/main/res/drawable-xhdpi/ic_format_quote_checked.png new file mode 100644 index 0000000000000000000000000000000000000000..e56dbcea37a5c03b96921d3f5140b41692dae09f GIT binary patch literal 240 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY1|&n@ZgvM!+dW+zLn>~)y|t0I!GOp0pwD5M znUfi3D9=8~;-Q&zbmO`oYgw0vE8hBg=j=arMgawf1_nkZmJ=X?1H|J263ZF(c5i!a z2bBX0!{v=?i{1+J+Y8<2XO|MzzaV@+|J6;7k{a8I4yvy@S+oNEMFM74EowM*MVK*U x)jW;`L0{LfX@#H9T2S=$$6r?L_B9B-Wu9?i16Pz9Qy|a_44$rjF6*2UngB`lO4$Ga literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/ic_format_quote_unchecked.png b/app/src/main/res/drawable-xhdpi/ic_format_quote_unchecked.png new file mode 100644 index 0000000000000000000000000000000000000000..18a5f529b731e738702a5372247df5f477a8366e GIT binary patch literal 236 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY1|&n@ZgvM!n>}3|Ln>~)y>*bcK|#PJ&}*^g zuf@h|5412#7kuI?zWd^|z2t3)#W%kzFfg%j2q-u-Fi3(3Mj&qjka(f*aDLg`UHlL! zkSJIUn6Y5C-Og{V?eoR&>$A_|*1w>?@BWoyffwJuhA_Ea3FZ_D^cM~Au?=-F{2IdG zdNr6)B=mgVf*n<5%tx<2{w@x+L_mQVW~LEHXjg`Q+)X8~_|BDuK<6`fy85}Sb4q9e E00$pQz5oCK literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/ic_format_quote_checked.png b/app/src/main/res/drawable-xxhdpi/ic_format_quote_checked.png new file mode 100644 index 0000000000000000000000000000000000000000..f23788f70e0a948fa362534ecba8817b91ae8a37 GIT binary patch literal 424 zcmeAS@N?(olHy`uVBq!ia0vp^IUvlz1|<8_!p|}=Fy?!@IEGZ*dV6PMD3hZ|+eOt0 zJvGt=-UsBiaO5_rZDAJbc+sGw!6>a@e%WDWg7l4Yi!*)i+2a5G$Uk5yoMSGtZSJj; z90yo@4m5DiXkZjJU}RQHU}Ez*z``@5fm6Z&D3ZXWmH<{Dsi=D+e(As0a}P8yGPChW z7$lI!$h*3zgsZ3EOxg381NWGeYo^O>zH7<8CiJC{#3S3sbBh^%bMzEQvip>$=dM}! zMOfmI>Fc>$5B4<*`aPasf66*LX)lZ058buK_anKpBY*MmY&>0;uDiiEp=Ev0{J-a< zBL4nZyo_&SVY=*w+Ju(kmj~y5XRns}KVdoF$2aGGH&^QC@SLembWXU(EzSHn?uNjO u?}v^Z*dzYyz*7DgE)36N4Gq(aqU%K#Y!*9kU>z_97(8A5T-G@yGywo@*`BHZ literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/ic_format_quote_unchecked.png b/app/src/main/res/drawable-xxhdpi/ic_format_quote_unchecked.png new file mode 100644 index 0000000000000000000000000000000000000000..3d17a5d900ba7da6e9457c4e741b116c985c19a4 GIT binary patch literal 421 zcmeAS@N?(olHy`uVBq!ia0vp^IUvlz1|<8_!p|}=Fy?r=IEGZ*dV6PMD3hZ|+eOue zGd0o&gf_72GR>NywuK|JNlC*|T0woX!^{Nf2eSN|5AQxW-Tt3+!8sP|DM4&sCkr-k z&S+p1Heh5{OJHL2Il#g*qk&Vx04S2cq?T}i#peK6fw5E6hW&1~ujU?TU}R?FkuXRg zjqz`_>stwlhZEkO+u87zN%_x}Yd7D`VZIjpRz%{F?c=${48J*g3TCnSl&5E}d45aP z;E37lxoZ#dH464!o?m~;Iyz}DtJ{yYxkmSIa%G49=HvM|^Y6K^1XY7WJI&JeZ)Uw_ z@pnaZyT-d5=572vA3~#deg2oAe_8(1TIW3=<~?p}=Ff3A1ZR9dbnd_&@iLZYdp8&x qyl=HDc*#5+=uJExhlfmT3F|b?#4Sr+?5P9>KZB>MpUXO@geCw{?w-Z~ literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/ic_format_quote_checked.png b/app/src/main/res/drawable-xxxhdpi/ic_format_quote_checked.png new file mode 100644 index 0000000000000000000000000000000000000000..1a6cc0abf18cf9da4bcd1fe0617854aaadbce1ae GIT binary patch literal 505 zcmeAS@N?(olHy`uVBq!ia0vp^6F``Q4M;wBd$farf$@N+i(^Q|t+%%wc^e!=oE@($ zV4ln2z<$nwIYl_CjPL!w%|2Dhk^Qw3?>!S_nZO|Az~sT?!N94&sKThy02G)67Gm%O z3jqc2sNqxqX={)xZ8g39mw}N*z=5X3g&o@*`|Eer`#C&cz`tQozDi8sHl|!N<8@L2{irCb#+;wMEv{|hil6dY9|4W zYWnI4w8QI~I?xWy$ockvt|?=N9XL3J96%wAGknq2*uG`UWj-K${pX1?V3aa=y85}S Ib4q9e0HNiJpa1{> literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/ic_format_quote_unchecked.png b/app/src/main/res/drawable-xxxhdpi/ic_format_quote_unchecked.png new file mode 100644 index 0000000000000000000000000000000000000000..8cb083658fb8367c6ab57d9668ac3bdaa7cac40c GIT binary patch literal 502 zcmeAS@N?(olHy`uVBq!ia0vp^6F``Q4M;wBd$farfpM>=i(^Q|t+%%~@-`TVI6Jx} zuY5E8Yyw+=N>0(y*ZU8hlszu-c*4DBf-DmlgdCVWm^>Ib6&O_*RT_W-lfXg@o?s!M z03J1*3LtF_a;2?XZ~tXrWD#(nDRE)fIoE#syZhA_?0msI=iPn&315F!)ZSu@oZo+a zx#WbeoDuWW9ImM+)J6e?CVb6gO{sOdwp5jEcpD3MWniy?CUhOe2-DYb{LE$0ME z#LQO%N)*&a0VOVc&13}XxW1ebC=oZG4Jc7jdkJXNhp(ROKpofBfp%y{%ujK+wmhLW z2q-b>t0&M7uWQfw_kZO8g#z>% literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable/ic_format_quote_accent.png b/app/src/main/res/drawable/ic_format_quote_accent.png deleted file mode 100644 index 01b9b61eabbe43bc3912a192744bbc4cd8836313..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 264 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTCwj^(N7a$D;Kb?2i11Zh|kH}&m z?E%JaC$sH9f@KAc=|CE+pW)oQo^T*%vZsqx^5R+Dh4AnCCh?}9#hD_M8%&`@cE10! zf4<*TJuWF5%f{c|AMl;YbNQQc-_QELLm9uRc6gkadt7K4r nJDs)QN?jy_`&(w94cq*580}Z_uU`8Q$YJnw^>bP0l+XkKEmK+I diff --git a/app/src/main/res/drawable/ic_format_quote_grey.png b/app/src/main/res/drawable/ic_format_quote_grey.png deleted file mode 100644 index cacaa152e7cb10d1b920d071bd386270c2a93601..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 259 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTCwj^(N7a$D;Kb?2i11Zh|kH}&m z?E%JaC$sH9f@KAc=|CE+pW)oQo^T+i&(p;*B;(%OYa4kR40v1unFVdQ&MBb@03DN8UjP6A diff --git a/app/src/main/res/drawable/ic_toggle_quote_bg.xml b/app/src/main/res/drawable/ic_toggle_quote_bg.xml deleted file mode 100644 index 59940e3d..00000000 --- a/app/src/main/res/drawable/ic_toggle_quote_bg.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file 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 6ba494ff..983090c5 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,8 +1,8 @@ + android:background="@color/card_background" + android:clickable="true" + android:contentDescription="@string/quote" + android:src="@drawable/ic_format_quote_unchecked"/> + android:background="@color/card_background" + android:clickable="true" + android:contentDescription="@string/quote" + android:src="@drawable/ic_format_quote_unchecked"/>