Browse Source

Topic reply fixes.

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
48583ccba3
  1. 19
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  2. 50
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  3. BIN
      app/src/main/res/drawable-hdpi/ic_send.png
  4. BIN
      app/src/main/res/drawable-mdpi/ic_send.png
  5. BIN
      app/src/main/res/drawable-xhdpi/ic_send.png
  6. BIN
      app/src/main/res/drawable-xxhdpi/ic_send.png
  7. BIN
      app/src/main/res/drawable-xxxhdpi/ic_send.png

19
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("message", message[0])
.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();
}
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) {

50
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<RecyclerView.ViewHolder> {
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<RecyclerView.ViewHolder> {
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<RecyclerView.ViewHolder> {
//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);

BIN
app/src/main/res/drawable-hdpi/ic_send.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 B

BIN
app/src/main/res/drawable-mdpi/ic_send.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

BIN
app/src/main/res/drawable-xhdpi/ic_send.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 419 B

BIN
app/src/main/res/drawable-xxhdpi/ic_send.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 553 B

BIN
app/src/main/res/drawable-xxxhdpi/ic_send.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 729 B

Loading…
Cancel
Save