|
@ -81,6 +81,10 @@ public class TopicActivity extends BaseActivity { |
|
|
* The key to use when putting topic's title String to {@link TopicActivity}'s Bundle. |
|
|
* The key to use when putting topic's title String to {@link TopicActivity}'s Bundle. |
|
|
*/ |
|
|
*/ |
|
|
public static final String BUNDLE_TOPIC_TITLE = "TOPIC_TITLE"; |
|
|
public static final String BUNDLE_TOPIC_TITLE = "TOPIC_TITLE"; |
|
|
|
|
|
/** |
|
|
|
|
|
* The key to use when activity should scroll to bottom, for example when coming from recent. |
|
|
|
|
|
*/ |
|
|
|
|
|
public static final String BUNDLE_FOCUS_TO_LAST_POST = "BUNDLE_FOCUS_TO_LAST_POST"; |
|
|
private static TopicTask topicTask; |
|
|
private static TopicTask topicTask; |
|
|
private MaterialProgressBar progressBar; |
|
|
private MaterialProgressBar progressBar; |
|
|
private TextView toolbarTitle; |
|
|
private TextView toolbarTitle; |
|
@ -103,6 +107,7 @@ public class TopicActivity extends BaseActivity { |
|
|
* bundle one and gets rendered in the toolbar. |
|
|
* bundle one and gets rendered in the toolbar. |
|
|
*/ |
|
|
*/ |
|
|
private String parsedTitle; |
|
|
private String parsedTitle; |
|
|
|
|
|
private Boolean focusToLastPost; |
|
|
private RecyclerView recyclerView; |
|
|
private RecyclerView recyclerView; |
|
|
/** |
|
|
/** |
|
|
* Holds the url of this page |
|
|
* Holds the url of this page |
|
@ -203,6 +208,7 @@ public class TopicActivity extends BaseActivity { |
|
|
Toast.makeText(this, "An error has occurred\n Aborting.", Toast.LENGTH_SHORT).show(); |
|
|
Toast.makeText(this, "An error has occurred\n Aborting.", Toast.LENGTH_SHORT).show(); |
|
|
finish(); |
|
|
finish(); |
|
|
} |
|
|
} |
|
|
|
|
|
focusToLastPost = extras.getBoolean(BUNDLE_FOCUS_TO_LAST_POST); |
|
|
|
|
|
|
|
|
thisPageBookmark = new Bookmark(topicTitle, ThmmyPage.getTopicId(topicPageUrl)); |
|
|
thisPageBookmark = new Bookmark(topicTitle, ThmmyPage.getTopicId(topicPageUrl)); |
|
|
|
|
|
|
|
@ -246,7 +252,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); |
|
@ -594,6 +600,14 @@ public class TopicActivity extends BaseActivity { |
|
|
Response response = client.newCall(request).execute(); |
|
|
Response response = client.newCall(request).execute(); |
|
|
document = Jsoup.parse(response.body().string()); |
|
|
document = Jsoup.parse(response.body().string()); |
|
|
localPostsList = 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"); |
|
@ -605,14 +619,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, "") |
|
@ -634,8 +640,8 @@ public class TopicActivity extends BaseActivity { |
|
|
|
|
|
|
|
|
if (replyPageUrl == null) { |
|
|
if (replyPageUrl == null) { |
|
|
replyFAB.hide(); |
|
|
replyFAB.hide(); |
|
|
topicAdapter.resetTopic(new TopicTask(), false); |
|
|
topicAdapter.resetTopic(base_url, new TopicTask(), false); |
|
|
} else topicAdapter.resetTopic(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); |
|
|
|
|
|
|
|
@ -643,6 +649,10 @@ public class TopicActivity extends BaseActivity { |
|
|
pageIndicator.setText(String.valueOf(thisPage) + "/" + String.valueOf(numberOfPages)); |
|
|
pageIndicator.setText(String.valueOf(thisPage) + "/" + String.valueOf(numberOfPages)); |
|
|
pageRequestValue = thisPage; |
|
|
pageRequestValue = thisPage; |
|
|
|
|
|
|
|
|
|
|
|
if (focusToLastPost) { |
|
|
|
|
|
recyclerView.scrollToPosition(postsList.size() - 1); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
paginationEnabled(true); |
|
|
paginationEnabled(true); |
|
|
break; |
|
|
break; |
|
|
case NETWORK_ERROR: |
|
|
case NETWORK_ERROR: |
|
@ -652,8 +662,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.resetTopic(new TopicTask(), false); |
|
|
topicAdapter.resetTopic(base_url, new TopicTask(), false); |
|
|
} else topicAdapter.resetTopic(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(); |
|
|