|
@ -65,13 +65,14 @@ import static gr.thmmy.mthmmy.activities.profile.ProfileActivity.BUNDLE_PROFILE_ |
|
|
import static gr.thmmy.mthmmy.activities.topic.Posting.replyStatus; |
|
|
import static gr.thmmy.mthmmy.activities.topic.Posting.replyStatus; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Activity for topics. When creating an Intent of this activity you need to bundle a <b>String</b> |
|
|
* Activity for parsing and rendering topics. When creating an Intent of this activity you need to |
|
|
* containing this topics's url using the key {@link #BUNDLE_TOPIC_URL} and a <b>String</b> containing |
|
|
* bundle a <b>String</b> containing this topic's url using the key {@link #BUNDLE_TOPIC_URL}. |
|
|
* this topic's title using the key {@link #BUNDLE_TOPIC_TITLE}. |
|
|
* You can also bundle a <b>String</b> containing this topic's title, if its available, using the |
|
|
|
|
|
* key {@link #BUNDLE_TOPIC_TITLE} for faster title rendering. |
|
|
*/ |
|
|
*/ |
|
|
@SuppressWarnings("unchecked") |
|
|
@SuppressWarnings("unchecked") |
|
|
public class TopicActivity extends BaseActivity { |
|
|
public class TopicActivity extends BaseActivity { |
|
|
//Class variables
|
|
|
//Activity's variables
|
|
|
/** |
|
|
/** |
|
|
* The key to use when putting topic's url String to {@link TopicActivity}'s Bundle. |
|
|
* The key to use when putting topic's url String to {@link TopicActivity}'s Bundle. |
|
|
*/ |
|
|
*/ |
|
@ -81,46 +82,110 @@ public class TopicActivity extends BaseActivity { |
|
|
*/ |
|
|
*/ |
|
|
public static final String BUNDLE_TOPIC_TITLE = "TOPIC_TITLE"; |
|
|
public static final String BUNDLE_TOPIC_TITLE = "TOPIC_TITLE"; |
|
|
private static TopicTask topicTask; |
|
|
private static TopicTask topicTask; |
|
|
//About posts
|
|
|
private MaterialProgressBar progressBar; |
|
|
|
|
|
private TextView toolbarTitle; |
|
|
|
|
|
/** |
|
|
|
|
|
* Holds this topic's base url. For example a topic with url similar to |
|
|
|
|
|
* "https://www.thmmy.gr/smf/index.php?topic=1.15;topicseen" or |
|
|
|
|
|
* "https://www.thmmy.gr/smf/index.php?topic=1.msg1#msg1" |
|
|
|
|
|
* has the base url "https://www.thmmy.gr/smf/index.php?topic=1" |
|
|
|
|
|
*/ |
|
|
|
|
|
private static String base_url = ""; |
|
|
|
|
|
/** |
|
|
|
|
|
* Holds this topic's title. At first this gets the value of the topic title that came with |
|
|
|
|
|
* bundle and is rendered in the toolbar while parsing this topic. Later, after topic's parsing |
|
|
|
|
|
* is done, it gets the value of {@link #parsedTitle} if bundle title and parsed title differ. |
|
|
|
|
|
*/ |
|
|
|
|
|
private String topicTitle; |
|
|
|
|
|
/** |
|
|
|
|
|
* Holds this topic's title as parsed from the html source. If this (parsed) title is different |
|
|
|
|
|
* than the one that came with activity's bundle then the parsed title is preferred over the |
|
|
|
|
|
* bundle one and gets rendered in the toolbar. |
|
|
|
|
|
*/ |
|
|
|
|
|
private String parsedTitle; |
|
|
|
|
|
private RecyclerView recyclerView; |
|
|
|
|
|
/** |
|
|
|
|
|
* Holds the url of this page |
|
|
|
|
|
*/ |
|
|
|
|
|
private String loadedPageUrl = ""; |
|
|
|
|
|
/** |
|
|
|
|
|
* Becomes true after user has posted in this topic and the page is being reloaded and false |
|
|
|
|
|
* when topic's reloading is done |
|
|
|
|
|
*/ |
|
|
|
|
|
private boolean reloadingPage = false; |
|
|
|
|
|
//Posts related
|
|
|
private TopicAdapter topicAdapter; |
|
|
private TopicAdapter topicAdapter; |
|
|
|
|
|
/** |
|
|
|
|
|
* Holds a list of this topic's posts |
|
|
|
|
|
*/ |
|
|
private ArrayList<Post> postsList; |
|
|
private ArrayList<Post> postsList; |
|
|
|
|
|
/** |
|
|
|
|
|
* Gets assigned to {@link #postFocus} when there is no post focus information in the url |
|
|
|
|
|
*/ |
|
|
private static final int NO_POST_FOCUS = -1; |
|
|
private static final int NO_POST_FOCUS = -1; |
|
|
|
|
|
/** |
|
|
|
|
|
* Holds the index of the post that has focus |
|
|
|
|
|
*/ |
|
|
private int postFocus = NO_POST_FOCUS; |
|
|
private int postFocus = NO_POST_FOCUS; |
|
|
|
|
|
/** |
|
|
|
|
|
* Holds the position in the {@link #postsList} of the post with focus |
|
|
|
|
|
*/ |
|
|
private static int postFocusPosition = 0; |
|
|
private static int postFocusPosition = 0; |
|
|
//Reply
|
|
|
//Reply related
|
|
|
private FloatingActionButton replyFAB; |
|
|
private FloatingActionButton replyFAB; |
|
|
|
|
|
/** |
|
|
|
|
|
* Holds this topic's reply url |
|
|
|
|
|
*/ |
|
|
private String replyPageUrl = null; |
|
|
private String replyPageUrl = null; |
|
|
//Topic's pages
|
|
|
//Topic's pages related
|
|
|
|
|
|
/** |
|
|
|
|
|
* Holds current page's index (starting from 1, not 0) |
|
|
|
|
|
*/ |
|
|
private int thisPage = 1; |
|
|
private int thisPage = 1; |
|
|
|
|
|
/** |
|
|
|
|
|
* Holds this topic's number of pages |
|
|
|
|
|
*/ |
|
|
private int numberOfPages = 1; |
|
|
private int numberOfPages = 1; |
|
|
|
|
|
/** |
|
|
|
|
|
* Holds a list of this topic's pages urls |
|
|
|
|
|
*/ |
|
|
private final SparseArray<String> pagesUrls = new SparseArray<>(); |
|
|
private final SparseArray<String> pagesUrls = new SparseArray<>(); |
|
|
//Page select
|
|
|
//Page select related
|
|
|
|
|
|
/** |
|
|
|
|
|
* Used for handling bottom navigation bar's buttons long click user interactions |
|
|
|
|
|
*/ |
|
|
private final Handler repeatUpdateHandler = new Handler(); |
|
|
private final Handler repeatUpdateHandler = new Handler(); |
|
|
|
|
|
/** |
|
|
|
|
|
* Holds the initial time delay before a click on bottom navigation bar is considered long |
|
|
|
|
|
*/ |
|
|
private final long INITIAL_DELAY = 500; |
|
|
private final long INITIAL_DELAY = 500; |
|
|
private boolean autoIncrement = false; |
|
|
private boolean autoIncrement = false; |
|
|
private boolean autoDecrement = false; |
|
|
private boolean autoDecrement = false; |
|
|
|
|
|
/** |
|
|
|
|
|
* Holds the number of pages to be added or subtracted from current page on each step while a |
|
|
|
|
|
* long click is held in either next or previous buttons |
|
|
|
|
|
*/ |
|
|
private static final int SMALL_STEP = 1; |
|
|
private static final int SMALL_STEP = 1; |
|
|
|
|
|
/** |
|
|
|
|
|
* Holds the number of pages to be added or subtracted from current page on each step while a |
|
|
|
|
|
* long click is held in either first or last buttons |
|
|
|
|
|
*/ |
|
|
private static final int LARGE_STEP = 10; |
|
|
private static final int LARGE_STEP = 10; |
|
|
|
|
|
/** |
|
|
|
|
|
* Holds the value (index) of the page to be requested when a user interaction with bottom |
|
|
|
|
|
* navigation bar occurs |
|
|
|
|
|
*/ |
|
|
private Integer pageRequestValue; |
|
|
private Integer pageRequestValue; |
|
|
//Bottom navigation graphics
|
|
|
//Bottom navigation bar graphics related
|
|
|
private LinearLayout bottomNavBar; |
|
|
private LinearLayout bottomNavBar; |
|
|
private ImageButton firstPage; |
|
|
private ImageButton firstPage; |
|
|
private ImageButton previousPage; |
|
|
private ImageButton previousPage; |
|
|
private TextView pageIndicator; |
|
|
private TextView pageIndicator; |
|
|
private ImageButton nextPage; |
|
|
private ImageButton nextPage; |
|
|
private ImageButton lastPage; |
|
|
private ImageButton lastPage; |
|
|
//Topic's info
|
|
|
//Topic's info related
|
|
|
private SpannableStringBuilder topicTreeAndMods = new SpannableStringBuilder("Loading..."), |
|
|
private SpannableStringBuilder topicTreeAndMods = new SpannableStringBuilder("Loading..."), |
|
|
topicViewers = new SpannableStringBuilder("Loading..."); |
|
|
topicViewers = new SpannableStringBuilder("Loading..."); |
|
|
//Other variables
|
|
|
|
|
|
private MaterialProgressBar progressBar; |
|
|
|
|
|
private TextView toolbarTitle; |
|
|
|
|
|
private static String base_url = ""; |
|
|
|
|
|
private String topicTitle; |
|
|
|
|
|
private String parsedTitle; |
|
|
|
|
|
private RecyclerView recyclerView; |
|
|
|
|
|
private String loadedPageUrl = ""; |
|
|
|
|
|
private boolean reloadingPage = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -149,6 +214,7 @@ public class TopicActivity extends BaseActivity { |
|
|
toolbarTitle.setMarqueeRepeatLimit(-1); |
|
|
toolbarTitle.setMarqueeRepeatLimit(-1); |
|
|
toolbarTitle.setText(topicTitle); |
|
|
toolbarTitle.setText(topicTitle); |
|
|
toolbarTitle.setSelected(true); |
|
|
toolbarTitle.setSelected(true); |
|
|
|
|
|
toolbarTitle.setEnabled(false); |
|
|
setSupportActionBar(toolbar); |
|
|
setSupportActionBar(toolbar); |
|
|
if (getSupportActionBar() != null) { |
|
|
if (getSupportActionBar() != null) { |
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true); |
|
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true); |
|
@ -171,6 +237,7 @@ public class TopicActivity extends BaseActivity { |
|
|
new View.OnTouchListener() { |
|
|
new View.OnTouchListener() { |
|
|
@Override |
|
|
@Override |
|
|
public boolean onTouch(View v, MotionEvent event) { |
|
|
public boolean onTouch(View v, MotionEvent event) { |
|
|
|
|
|
v.performClick(); |
|
|
return topicTask != null && topicTask.getStatus() == AsyncTask.Status.RUNNING; |
|
|
return topicTask != null && topicTask.getStatus() == AsyncTask.Status.RUNNING; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -179,7 +246,7 @@ public class TopicActivity extends BaseActivity { |
|
|
CustomLinearLayoutManager layoutManager = new CustomLinearLayoutManager( |
|
|
CustomLinearLayoutManager layoutManager = new CustomLinearLayoutManager( |
|
|
getApplicationContext(), loadedPageUrl); |
|
|
getApplicationContext(), loadedPageUrl); |
|
|
recyclerView.setLayoutManager(layoutManager); |
|
|
recyclerView.setLayoutManager(layoutManager); |
|
|
topicAdapter = new TopicAdapter(this, postsList, topicTask); |
|
|
topicAdapter = new TopicAdapter(this, postsList, base_url, topicTask); |
|
|
recyclerView.setAdapter(topicAdapter); |
|
|
recyclerView.setAdapter(topicAdapter); |
|
|
|
|
|
|
|
|
replyFAB = findViewById(R.id.topic_fab); |
|
|
replyFAB = findViewById(R.id.topic_fab); |
|
@ -191,12 +258,8 @@ public class TopicActivity extends BaseActivity { |
|
|
@Override |
|
|
@Override |
|
|
public void onClick(View view) { |
|
|
public void onClick(View view) { |
|
|
if (sessionManager.isLoggedIn()) { |
|
|
if (sessionManager.isLoggedIn()) { |
|
|
postsList.add(null); |
|
|
PrepareForReply prepareForReply = new PrepareForReply(); |
|
|
topicAdapter.notifyItemInserted(postsList.size()); |
|
|
prepareForReply.execute(topicAdapter.getToQuoteList()); |
|
|
topicAdapter.prepareForReply(new ReplyTask(), topicTitle, loadedPageUrl); |
|
|
|
|
|
replyFAB.hide(); |
|
|
|
|
|
bottomNavBar.setVisibility(View.GONE); |
|
|
|
|
|
recyclerView.scrollToPosition(postsList.size() - 1); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
@ -464,12 +527,10 @@ public class TopicActivity extends BaseActivity { |
|
|
//------------------------------------BOTTOM NAV BAR METHODS END------------------------------------
|
|
|
//------------------------------------BOTTOM NAV BAR METHODS END------------------------------------
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* An {@link AsyncTask} that handles asynchronous fetching of a topic page and parsing it's |
|
|
* An {@link AsyncTask} that handles asynchronous fetching of this topic page and parsing of it's |
|
|
* data. {@link AsyncTask#onPostExecute(Object) OnPostExecute} method calls {@link RecyclerView#swapAdapter} |
|
|
* data. |
|
|
* to build graphics. |
|
|
* <p>TopicTask's {@link AsyncTask#execute execute} method needs a topic's url as String |
|
|
* <p> |
|
|
* parameter.</p> |
|
|
* <p>Calling TopicTask's {@link AsyncTask#execute execute} method needs to have profile's url |
|
|
|
|
|
* as String parameter!</p> |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
class TopicTask extends AsyncTask<String, Void, Integer> { |
|
|
class TopicTask extends AsyncTask<String, Void, Integer> { |
|
|
private static final int SUCCESS = 0; |
|
|
private static final int SUCCESS = 0; |
|
@ -477,6 +538,8 @@ public class TopicActivity extends BaseActivity { |
|
|
private static final int OTHER_ERROR = 2; |
|
|
private static final int OTHER_ERROR = 2; |
|
|
private static final int SAME_PAGE = 3; |
|
|
private static final int SAME_PAGE = 3; |
|
|
|
|
|
|
|
|
|
|
|
ArrayList<Post> localPostsList; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
protected void onPreExecute() { |
|
|
protected void onPreExecute() { |
|
|
progressBar.setVisibility(ProgressBar.VISIBLE); |
|
|
progressBar.setVisibility(ProgressBar.VISIBLE); |
|
@ -530,7 +593,15 @@ public class TopicActivity extends BaseActivity { |
|
|
try { |
|
|
try { |
|
|
Response response = client.newCall(request).execute(); |
|
|
Response response = client.newCall(request).execute(); |
|
|
document = Jsoup.parse(response.body().string()); |
|
|
document = Jsoup.parse(response.body().string()); |
|
|
parse(document); |
|
|
localPostsList = parse(document); |
|
|
|
|
|
|
|
|
|
|
|
//Finds the position of the focused message if present
|
|
|
|
|
|
for (int i = 0; i < localPostsList.size(); ++i) { |
|
|
|
|
|
if (localPostsList.get(i).getPostIndex() == postFocus) { |
|
|
|
|
|
postFocusPosition = i; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
return SUCCESS; |
|
|
return SUCCESS; |
|
|
} catch (IOException e) { |
|
|
} catch (IOException e) { |
|
|
Timber.i(e, "IO Exception"); |
|
|
Timber.i(e, "IO Exception"); |
|
@ -542,14 +613,6 @@ public class TopicActivity extends BaseActivity { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected void onPostExecute(Integer parseResult) { |
|
|
protected void onPostExecute(Integer parseResult) { |
|
|
//Finds the position of the focused message if present
|
|
|
|
|
|
for (int i = 0; i < postsList.size(); ++i) { |
|
|
|
|
|
if (postsList.get(i).getPostIndex() == postFocus) { |
|
|
|
|
|
postFocusPosition = i; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
switch (parseResult) { |
|
|
switch (parseResult) { |
|
|
case SUCCESS: |
|
|
case SUCCESS: |
|
|
if (topicTitle == null || Objects.equals(topicTitle, "") |
|
|
if (topicTitle == null || Objects.equals(topicTitle, "") |
|
@ -560,12 +623,19 @@ public class TopicActivity extends BaseActivity { |
|
|
invalidateOptionsMenu(); |
|
|
invalidateOptionsMenu(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!(postsList.isEmpty() || postsList.size() == 0)) { |
|
|
|
|
|
recyclerView.getRecycledViewPool().clear(); //Avoid inconsistency detected bug
|
|
|
|
|
|
postsList.clear(); |
|
|
|
|
|
topicAdapter.notifyItemRangeRemoved(0, postsList.size() - 1); |
|
|
|
|
|
} |
|
|
|
|
|
postsList.addAll(localPostsList); |
|
|
|
|
|
topicAdapter.notifyItemRangeInserted(0, postsList.size()); |
|
|
progressBar.setVisibility(ProgressBar.INVISIBLE); |
|
|
progressBar.setVisibility(ProgressBar.INVISIBLE); |
|
|
recyclerView.getRecycledViewPool().clear(); //Avoid inconsistency detected bug
|
|
|
|
|
|
if (replyPageUrl == null) { |
|
|
if (replyPageUrl == null) { |
|
|
replyFAB.hide(); |
|
|
replyFAB.hide(); |
|
|
topicAdapter.customNotifyDataSetChanged(new TopicTask(), false); |
|
|
topicAdapter.resetTopic(base_url, new TopicTask(), false); |
|
|
} else topicAdapter.customNotifyDataSetChanged(new TopicTask(), true); |
|
|
} else topicAdapter.resetTopic(base_url, new TopicTask(), true); |
|
|
|
|
|
|
|
|
if (replyFAB.getVisibility() != View.GONE) replyFAB.setEnabled(true); |
|
|
if (replyFAB.getVisibility() != View.GONE) replyFAB.setEnabled(true); |
|
|
|
|
|
|
|
@ -582,8 +652,8 @@ public class TopicActivity extends BaseActivity { |
|
|
progressBar.setVisibility(ProgressBar.INVISIBLE); |
|
|
progressBar.setVisibility(ProgressBar.INVISIBLE); |
|
|
if (replyPageUrl == null) { |
|
|
if (replyPageUrl == null) { |
|
|
replyFAB.hide(); |
|
|
replyFAB.hide(); |
|
|
topicAdapter.customNotifyDataSetChanged(new TopicTask(), false); |
|
|
topicAdapter.resetTopic(base_url, new TopicTask(), false); |
|
|
} else topicAdapter.customNotifyDataSetChanged(new TopicTask(), true); |
|
|
} else topicAdapter.resetTopic(base_url, new TopicTask(), true); |
|
|
if (replyFAB.getVisibility() != View.GONE) replyFAB.setEnabled(true); |
|
|
if (replyFAB.getVisibility() != View.GONE) replyFAB.setEnabled(true); |
|
|
paginationEnabled(true); |
|
|
paginationEnabled(true); |
|
|
Toast.makeText(TopicActivity.this, "That's the same page.", Toast.LENGTH_SHORT).show(); |
|
|
Toast.makeText(TopicActivity.this, "That's the same page.", Toast.LENGTH_SHORT).show(); |
|
@ -604,7 +674,7 @@ public class TopicActivity extends BaseActivity { |
|
|
* @param topic {@link Document} object containing this topic's source code |
|
|
* @param topic {@link Document} object containing this topic's source code |
|
|
* @see org.jsoup.Jsoup Jsoup |
|
|
* @see org.jsoup.Jsoup Jsoup |
|
|
*/ |
|
|
*/ |
|
|
private void parse(Document topic) { |
|
|
private ArrayList<Post> parse(Document topic) { |
|
|
ParseHelpers.Language language = ParseHelpers.Language.getLanguage(topic); |
|
|
ParseHelpers.Language language = ParseHelpers.Language.getLanguage(topic); |
|
|
|
|
|
|
|
|
//Finds topic's tree, mods and users viewing
|
|
|
//Finds topic's tree, mods and users viewing
|
|
@ -646,11 +716,7 @@ public class TopicActivity extends BaseActivity { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
postsList.clear(); |
|
|
return TopicParser.parseTopic(topic, language); |
|
|
int oldSize = postsList.size(); |
|
|
|
|
|
topicAdapter.notifyItemRangeRemoved(0, oldSize); |
|
|
|
|
|
recyclerView.getRecycledViewPool().clear(); //Avoid inconsistency detected bug
|
|
|
|
|
|
postsList.addAll(TopicParser.parseTopic(topic, language)); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void makeLinkClickable(SpannableStringBuilder strBuilder, final URLSpan span) { |
|
|
private void makeLinkClickable(SpannableStringBuilder strBuilder, final URLSpan span) { |
|
@ -703,23 +769,25 @@ public class TopicActivity extends BaseActivity { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
class ReplyTask extends AsyncTask<String, Void, Boolean> { |
|
|
class PrepareForReply extends AsyncTask<ArrayList<Integer>, Void, Boolean> { |
|
|
|
|
|
String numReplies, seqnum, sc, topic, buildedQuotes = ""; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
protected void onPreExecute() { |
|
|
protected void onPreExecute() { |
|
|
progressBar.setVisibility(ProgressBar.VISIBLE); |
|
|
progressBar.setVisibility(ProgressBar.VISIBLE); |
|
|
paginationEnabled(false); |
|
|
paginationEnabled(false); |
|
|
replyFAB.setEnabled(false); |
|
|
replyFAB.setEnabled(false); |
|
|
|
|
|
replyFAB.hide(); |
|
|
|
|
|
bottomNavBar.setVisibility(View.GONE); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
protected Boolean doInBackground(String... message) { |
|
|
protected Boolean doInBackground(ArrayList<Integer>... quoteList) { |
|
|
Document document; |
|
|
Document document; |
|
|
String numReplies, seqnum, sc, topic; |
|
|
|
|
|
|
|
|
|
|
|
Request request = new Request.Builder() |
|
|
Request request = new Request.Builder() |
|
|
.url(replyPageUrl + ";wap2") |
|
|
.url(replyPageUrl + ";wap2") |
|
|
.build(); |
|
|
.build(); |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
Response response = client.newCall(request).execute(); |
|
|
Response response = client.newCall(request).execute(); |
|
|
document = Jsoup.parse(response.body().string()); |
|
|
document = Jsoup.parse(response.body().string()); |
|
@ -728,22 +796,61 @@ public class TopicActivity extends BaseActivity { |
|
|
seqnum = document.select("input[name=seqnum]").first().attr("value"); |
|
|
seqnum = document.select("input[name=seqnum]").first().attr("value"); |
|
|
sc = document.select("input[name=sc]").first().attr("value"); |
|
|
sc = document.select("input[name=sc]").first().attr("value"); |
|
|
topic = document.select("input[name=topic]").first().attr("value"); |
|
|
topic = document.select("input[name=topic]").first().attr("value"); |
|
|
} catch (IOException e) { |
|
|
} catch (IOException | Selector.SelectorParseException e) { |
|
|
Timber.e(e, "Post failed."); |
|
|
Timber.e(e, "Prepare failed."); |
|
|
return false; |
|
|
|
|
|
} catch (Selector.SelectorParseException e) { |
|
|
|
|
|
Timber.e(e, "Post failed."); |
|
|
|
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (Integer quotePosition : quoteList[0]) { |
|
|
|
|
|
request = new Request.Builder() |
|
|
|
|
|
.url("https://www.thmmy.gr/smf/index.php?action=quotefast;quote=" + |
|
|
|
|
|
postsList.get(quotePosition).getPostIndex() + |
|
|
|
|
|
";" + "sesc=" + sc + ";xml") |
|
|
|
|
|
.build(); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
Response response = client.newCall(request).execute(); |
|
|
|
|
|
String body = response.body().string(); |
|
|
|
|
|
buildedQuotes += body.substring(body.indexOf("<quote>") + 7, body.indexOf("</quote>")); |
|
|
|
|
|
buildedQuotes += "\n\n"; |
|
|
|
|
|
} catch (IOException | Selector.SelectorParseException e) { |
|
|
|
|
|
Timber.e(e, "Quote building failed."); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
protected void onPostExecute(Boolean result) { |
|
|
|
|
|
postsList.add(null); |
|
|
|
|
|
topicAdapter.notifyItemInserted(postsList.size()); |
|
|
|
|
|
topicAdapter.prepareForReply(new ReplyTask(), topicTitle, numReplies, seqnum, sc, |
|
|
|
|
|
topic, buildedQuotes); |
|
|
|
|
|
recyclerView.scrollToPosition(postsList.size() - 1); |
|
|
|
|
|
progressBar.setVisibility(ProgressBar.GONE); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class ReplyTask extends AsyncTask<String, Void, Boolean> { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
protected void onPreExecute() { |
|
|
|
|
|
progressBar.setVisibility(ProgressBar.VISIBLE); |
|
|
|
|
|
paginationEnabled(false); |
|
|
|
|
|
replyFAB.setEnabled(false); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
protected Boolean doInBackground(String... args) { |
|
|
RequestBody postBody = new MultipartBody.Builder() |
|
|
RequestBody postBody = new MultipartBody.Builder() |
|
|
.setType(MultipartBody.FORM) |
|
|
.setType(MultipartBody.FORM) |
|
|
.addFormDataPart("message", message[1]) |
|
|
.addFormDataPart("message", args[1]) |
|
|
.addFormDataPart("num_replies", numReplies) |
|
|
.addFormDataPart("num_replies", args[2]) |
|
|
.addFormDataPart("seqnum", seqnum) |
|
|
.addFormDataPart("seqnum", args[3]) |
|
|
.addFormDataPart("sc", sc) |
|
|
.addFormDataPart("sc", args[4]) |
|
|
.addFormDataPart("subject", message[0]) |
|
|
.addFormDataPart("subject", args[0]) |
|
|
.addFormDataPart("topic", topic) |
|
|
.addFormDataPart("topic", args[5]) |
|
|
.build(); |
|
|
.build(); |
|
|
|
|
|
|
|
|
Request post = new Request.Builder() |
|
|
Request post = new Request.Builder() |
|
|