From 48583ccba361672c88d5e984edc3f92bb255ab61 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Wed, 22 Feb 2017 23:43:58 +0200 Subject: [PATCH] Topic reply fixes. --- .../activities/topic/TopicActivity.java | 35 ++++-------- .../mthmmy/activities/topic/TopicAdapter.java | 50 +++++++++++++++--- app/src/main/res/drawable-hdpi/ic_send.png | Bin 0 -> 324 bytes app/src/main/res/drawable-mdpi/ic_send.png | Bin 0 -> 257 bytes app/src/main/res/drawable-xhdpi/ic_send.png | Bin 0 -> 419 bytes app/src/main/res/drawable-xxhdpi/ic_send.png | Bin 0 -> 553 bytes app/src/main/res/drawable-xxxhdpi/ic_send.png | Bin 0 -> 729 bytes 7 files changed, 53 insertions(+), 32 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_send.png create mode 100644 app/src/main/res/drawable-mdpi/ic_send.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_send.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_send.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_send.png 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 92cc5317..e6860ff0 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 @@ -9,7 +9,6 @@ import android.support.design.widget.FloatingActionButton; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; -import android.util.Log; import android.util.SparseArray; import android.view.MotionEvent; import android.view.View; @@ -25,8 +24,6 @@ import org.jsoup.nodes.Element; import org.jsoup.select.Selector; import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; import java.util.ArrayList; import java.util.Objects; @@ -578,17 +575,11 @@ public class TopicActivity extends BaseActivity { Response response = client.newCall(request).execute(); document = Jsoup.parse(response.body().string()); - //https://www.thmmy.gr/smf/index.php?action=post;topic=67565.15;num_replies=27 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"); - Log.d(TAG, "numReplies " + numReplies + "\n" - + "seqnum " + seqnum + "\n" - + "sc " + sc + "\n" - + "subject " + subject + "\n" - + "topic " + topic + "\n"); } catch (IOException e) { Report.i(TAG, "Post failed.", e); return false; @@ -597,22 +588,17 @@ public class TopicActivity extends BaseActivity { return false; } - Log.d(TAG, message[0]); RequestBody postBody = null; - try { - postBody = new MultipartBody.Builder() - .setType(MultipartBody.FORM) - .addFormDataPart("message", URLEncoder.encode(message[0], "UTF-8")) - .addFormDataPart("num_replies", numReplies) - .addFormDataPart("seqnum", seqnum) - .addFormDataPart("sc", sc) - .addFormDataPart("subject", subject) - .addFormDataPart("topic", topic) - .addFormDataPart("goback", "1") - .build(); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } + + postBody = new MultipartBody.Builder() + .setType(MultipartBody.FORM) + .addFormDataPart("message", message[0]) + .addFormDataPart("num_replies", numReplies) + .addFormDataPart("seqnum", seqnum) + .addFormDataPart("sc", sc) + .addFormDataPart("subject", subject) + .addFormDataPart("topic", topic) + .build(); Request post = new Request.Builder() .url("https://www.thmmy.gr/smf/index.php?action=post2") @@ -621,6 +607,7 @@ public class TopicActivity extends BaseActivity { .build(); try { + client.newCall(post).execute(); client.newCall(post).execute(); return true; } catch (IOException e) { 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 d989f608..230388be 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 @@ -33,9 +33,14 @@ import android.widget.TextView; import com.squareup.picasso.Picasso; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Calendar; import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.Objects; import gr.thmmy.mthmmy.R; @@ -355,7 +360,7 @@ class TopicAdapter extends RecyclerView.Adapter { holder.subject.setEllipsize(TextUtils.TruncateAt.END); } //noinspection PointlessBooleanExpression,ConstantConditions - if (!BaseActivity.getSessionManager().isLoggedIn() || true) //Hide it until reply is implemented + if (!BaseActivity.getSessionManager().isLoggedIn()) holder.quoteToggle.setVisibility(View.GONE); else { if (viewProperties.get(position)[isQuoteButtonChecked]) @@ -368,14 +373,14 @@ class TopicAdapter extends RecyclerView.Adapter { public void onClick(View view) { boolean[] tmp = viewProperties.get(holder.getAdapterPosition()); if (tmp[isQuoteButtonChecked]) { - if (toQuoteList.contains(currentPost.getPostNumber())) { - toQuoteList.remove(toQuoteList.indexOf(currentPost.getPostNumber())); + if (toQuoteList.contains(postsList.indexOf(currentPost))) { + toQuoteList.remove(toQuoteList.indexOf(postsList.indexOf(currentPost))); } else 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 { - toQuoteList.add(currentPost.getPostNumber()); + toQuoteList.add(postsList.indexOf(currentPost)); holder.quoteToggle.setImageResource(R.drawable.ic_format_quote_checked); } tmp[isQuoteButtonChecked] = !tmp[isQuoteButtonChecked]; @@ -406,15 +411,44 @@ class TopicAdapter extends RecyclerView.Adapter { //Build quotes String quotes = ""; for (int quotePosition : toQuoteList) { - //Date postDate = new Date(); - Log.d(TAG, postsList.get(quotePosition).getPostDate()); + Date postDate = null; + { + String date = postsList.get(quotePosition).getPostDate(); + if (date != null) { + DateFormat format = new SimpleDateFormat("MMMM d, yyyy, h:m:s a", Locale.ENGLISH); + if (date.contains("Today")) { + date = date.replace("Today at", + Calendar.getInstance().getDisplayName(Calendar.MONTH, + Calendar.LONG, Locale.ENGLISH) + + " " + Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + + ", " + Calendar.getInstance().get(Calendar.YEAR) + ","); + } else if (date.contains("Σήμερα")) { + date = date.replace("Σήμερα στις", + Calendar.getInstance().getDisplayName(Calendar.MONTH, + Calendar.LONG, Locale.ENGLISH) + + " " + Calendar.getInstance().get(Calendar.DAY_OF_MONTH) + + ", " + Calendar.getInstance().get(Calendar.YEAR) + ","); + if (date.contains("πμ")) date = date.replace("πμ", "am"); + if (date.contains("μμ")) date = date.replace("μμ", "pm"); + } + + Log.d(TAG, date); + + try { + postDate = format.parse(date); + } catch (ParseException e) { + e.printStackTrace(); + } + } + } if (postsList.get(quotePosition).getPostIndex() != 0) { + assert postDate != null; quotes += "[quote author=" + postsList.get(quotePosition).getAuthor() + " link=topic=68525.msg" + postsList.get(quotePosition).getPostIndex() + "#msg" + postsList.get(quotePosition).getPostIndex() - + " date=" + "1000" + + " date=" + postDate.getTime() / 1000 + "]" + "\n" + postsList.get(quotePosition).getContent() - + "\n" + "[/quote]" + "\n"; + + "\n" + "[/quote]" + "\n\n"; } } holder.quickReply.setText(quotes); diff --git a/app/src/main/res/drawable-hdpi/ic_send.png b/app/src/main/res/drawable-hdpi/ic_send.png new file mode 100644 index 0000000000000000000000000000000000000000..a8fd035d0d23fcac869997482ed1d5395d0aba82 GIT binary patch literal 324 zcmV-K0lWT*P)S35LzoYFzo zat0lwo>Oy>N=_St0_C(hNR;#Sg)|DNp^YIH*y0pMPCtE<$e@Gvy;e@m-w^4i z`;=3AP!V->Fv1eM9|jr8pj)ym%4nj8Db_d$lFd;0mQ4CC{d}qW$hmOY8_8v_{loY+ zOBA<`k6FUJxtgeNuA(fq9?-;Dv>#zj)Q_<0S%MsctYncK6pbqfMdyyv@xLGOAiu69 Wl6gt;kN*e&00009pV literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_send.png b/app/src/main/res/drawable-mdpi/ic_send.png new file mode 100644 index 0000000000000000000000000000000000000000..c914ae97b6e506d6abf13cd9ddf7898d7d02a255 GIT binary patch literal 257 zcmV+c0sj7pP)XltOlag`CJFo`J@BleA)r$e9?zAim0QD zF_zfjqRr>}vJ%LliZ+IrV}s+Te3F4YYUp5u1-3ZF3`|gtOH@JwJ%m_cFG$o!#^NP6 zk@WqUJ~R0K(Oxq6Ix5~~_~x*4%Ah%}MHwU)jw-|d+{q?xDVxL}pq;B600000NkvXX Hu0mjfQ|oRn literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/ic_send.png b/app/src/main/res/drawable-xhdpi/ic_send.png new file mode 100644 index 0000000000000000000000000000000000000000..c104e00d0a84603d3118c9a63980483b69620d7f GIT binary patch literal 419 zcmV;U0bKrxP)uJTkr|g48teTQc+`w)9g$p6HJnO?|aw0 z;xy?_a`N)tO*TL5XP(KDKoUp-|4-l=wqU}mz$fJJ42Lk|Rba$B3}MBqK#|+n@~XP{ z^@~7W$m<}6yqXG>^IG;Q5IiqQfpT8cp#*XvO!CqcFv-hGKrJt8fnr_*iM&Dy6uE)T zrg_C6&?>L0i<7Vb>#z$aZ~+hSVVGA(<2*11v#<)=a0F*?2QMM=l3tg!p57Dms`9ej zw@5s_w{l+A0&}niJ8%r=a1XCF1WsW|GoeM;fIaBLB|Hiwv=37fFLB$uSobCF!g$?f zRO2q@O*8TGA^UNq@vxQXdfQ5jGU<5R%r(j+27y*P&X7mSfkY+Nh?BbGoBH}!-f z!Jt)X%u^K8IaNF&nIzScIMvLAH?SmiC2=lsIihiS-;&k4qWFJ3-&g*=I=*1hNx!?7 zFWZ0LYIV4-yQf`9qoWCq>WY}RInHkC`pLvu!DwsX?Rc~)$nJo^nt*_f3v|jiJ_!#E zm~`^J#*;sgkvQC`O?YQi7vF?eOy8VA=SUA+y?PFbe z-hc9fnmS{VFXeU2_kU)JO?fJo^Yg^{E`|J`k-|@G>{mC%iwpSUoKN|`dbPgvm)G;>kKcuy{_2#RBm7^JIJ|%f&al;M#uDolTJz93CwSr?RGHvH+9N3 zWcrF{uGG}1o_LRC^1gr1V*MP~_AJR0G4*j&{vT2*XKLc-IJM_iO~l%XfjUiE=^}@@ zH%CdfYG|BYar>cm_|G1vpKp|>O$>EBXS7M}M5S98OXcsXRkeRpA6P5*a))HPEfZhi zwlQT%VrOuvo89#W-;^iG6Yqq$t?N^oan|FPLHEy|C4J7UlLIHSzuKc8nq@ml^2^K( ptD4p&pX@k(ND~nw0Rfr&7y}cY`f6y(?*}FU22WQ%mvv4FO#s$F^FaUr literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/ic_send.png b/app/src/main/res/drawable-xxxhdpi/ic_send.png new file mode 100644 index 0000000000000000000000000000000000000000..ca6a867c3e419748826014293e63d0906bb973cb GIT binary patch literal 729 zcmV;~0w(>5P)fgS;3T_`w$h7bsP1W6SGh*?qmQRP;R zeAO(ov;U8N!ONxy=5@badU|@tI^Cr)u!Ea`00aO65C8~303ZMXfB*!5GXWdoiJ0Jq z*$CJdhvKJrBd&4dYy|Y_i4}2|8)ze-$`|s~zJT620{ZNT*W}4g0C{pEpvsnbOrGon zkf$LD_|;HAHBZar$xZ-yawLE}4Itp4MFGe2bO!-80#3`*Wdzs==<`Fo5?2vmBcO;p z)w$@mv4AR@;!&nNMH7%NPf-O_^VE%;r#ct?aV#Kwo-zptnWu~bLggv5fDn1AbJ1ZU zj`H-#XGSkzKXpT1-uuxN=nd8F)N;n zCGkmY8zkt3xRUWhc+{hK&=28<;!^alp&mwY!pZDqxd43FD5BCt%+GS=bB}v zpgW*TdPT`)X0pGe=RPx8UsDZ}nQSj=hs#V;0UnMj=tj;=Q~_x+6HUNY zC)s%r5d@^pOj7}EA6b_EOdyW}ipq=^0pU+Ju@cZDGjWeDCNl