diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
index d4cf2236..00dbb69a 100644
--- a/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
+++ b/app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
@@ -54,6 +54,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
private String boardUrl;
private String boardTitle;
+ private String parsedTitle;
private int numberOfPages = -1;
private int pagesLoaded = 0;
@@ -71,7 +72,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
boardUrl = extras.getString(BUNDLE_BOARD_URL);
ThmmyPage.PageCategory target = ThmmyPage.resolvePageCategory(Uri.parse(boardUrl));
if (!target.is(ThmmyPage.PageCategory.BOARD)) {
- Timber.e("Bundle came with a non board url!\nUrl:\n%s" , boardUrl);
+ Timber.e("Bundle came with a non board url!\nUrl:\n%s", boardUrl);
Toast.makeText(this, "An error has occurred\nAborting.", Toast.LENGTH_SHORT).show();
finish();
}
@@ -175,7 +176,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
*
BoardTask's {@link AsyncTask#execute execute} method needs a boards's url as String
* parameter!
*/
- public class BoardTask extends AsyncTask {
+ private class BoardTask extends AsyncTask {
@Override
protected void onPreExecute() {
if (!isLoadingMore) progressBar.setVisibility(ProgressBar.VISIBLE);
@@ -200,7 +201,12 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
@Override
protected void onPostExecute(Void voids) {
- if (boardTitle == null || Objects.equals(boardTitle, "")) toolbar.setTitle(boardTitle);
+ if (boardTitle == null || Objects.equals(boardTitle, "")
+ || !Objects.equals(boardTitle, parsedTitle)) {
+ boardTitle = parsedTitle;
+ toolbar.setTitle(boardTitle);
+ thisPageBookmark = new Bookmark(boardTitle, ThmmyPage.getBoardId(boardUrl));
+ }
//Parse was successful
++pagesLoaded;
@@ -211,8 +217,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
}
private void parseBoard(Document boardPage) {
- if (boardTitle == null || Objects.equals(boardTitle, ""))
- boardTitle = boardPage.select("div.nav a.nav").last().text();
+ parsedTitle = boardPage.select("div.nav a.nav").last().text();
//Removes loading item
if (isLoadingMore) {
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 a733caf5..16528844 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
@@ -18,6 +18,7 @@ import android.text.method.LinkMovementMethod;
import android.text.method.ScrollingMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.URLSpan;
+import android.util.Log;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -165,7 +166,7 @@ public class TopicActivity extends BaseActivity {
recyclerView.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(layoutManager);
- topicAdapter = new TopicAdapter(this, postsList, topicTask, topicTitle, loadedPageUrl);
+ topicAdapter = new TopicAdapter(this, postsList, topicTask);
recyclerView.setAdapter(topicAdapter);
replyFAB = (FloatingActionButton) findViewById(R.id.topic_fab);
@@ -178,10 +179,10 @@ public class TopicActivity extends BaseActivity {
public void onClick(View view) {
if (sessionManager.isLoggedIn()) {
postsList.add(null);
- topicAdapter.prepareForReply(new ReplyTask());
+ topicAdapter.notifyItemInserted(postsList.size());
+ topicAdapter.prepareForReply(new ReplyTask(), topicTitle, loadedPageUrl);
replyFAB.hide();
bottomNavBar.setVisibility(View.GONE);
- topicAdapter.notifyItemInserted(postsList.size());
}
}
});
@@ -536,14 +537,16 @@ public class TopicActivity extends BaseActivity {
switch (parseResult) {
case SUCCESS:
- if (topicTitle == null || Objects.equals(topicTitle, "")) {
+ if (topicTitle == null || Objects.equals(topicTitle, "")
+ || !Objects.equals(topicTitle, parsedTitle)) {
+ toolbarTitle.setText(parsedTitle);
+ topicTitle = parsedTitle;
thisPageBookmark = new Bookmark(parsedTitle, ThmmyPage.getTopicId(loadedPageUrl));
invalidateOptionsMenu();
}
progressBar.setVisibility(ProgressBar.INVISIBLE);
topicAdapter.customNotifyDataSetChanged(new TopicTask());
- topicAdapter.setTopicInfo(parsedTitle, loadedPageUrl);
if (replyPageUrl == null) replyFAB.hide();
if (replyFAB.getVisibility() != View.GONE) replyFAB.setEnabled(true);
@@ -552,11 +555,6 @@ public class TopicActivity extends BaseActivity {
pageRequestValue = thisPage;
paginationEnabled(true);
-
- if (topicTitle != null)
- if (parsedTitle != null)
- if (topicTitle == null || Objects.equals(topicTitle, ""))
- toolbarTitle.setText(parsedTitle);
break;
case NETWORK_ERROR:
Toast.makeText(getBaseContext(), "Network Error", Toast.LENGTH_SHORT).show();
@@ -602,7 +600,7 @@ public class TopicActivity extends BaseActivity {
}
//Finds topic title if missing
- if (topicTitle == null || Objects.equals(topicTitle, "")) {
+ {
parsedTitle = topic.select("td[id=top_subject]").first().text();
if (parsedTitle.contains("Topic:")) {
parsedTitle = parsedTitle.substring(parsedTitle.indexOf("Topic:") + 7
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 b06b684a..0e6d326d 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
@@ -111,8 +111,7 @@ class TopicAdapter extends RecyclerView.Adapter {
* @param context the context of the {@link RecyclerView}
* @param postsList List of {@link Post} objects to use
*/
- TopicAdapter(Context context, List postsList, TopicActivity.TopicTask topicTask
- , String topicTitle, String loadedPageUrl) {
+ TopicAdapter(Context context, List postsList, TopicActivity.TopicTask topicTask) {
this.context = context;
this.postsList = postsList;
@@ -122,15 +121,10 @@ class TopicAdapter extends RecyclerView.Adapter {
viewProperties.add(new boolean[3]);
}
this.topicTask = topicTask;
- this.topicTitle = topicTitle;
- this.loadedPageUrl = loadedPageUrl;
}
- void prepareForReply(TopicActivity.ReplyTask replyTask) {
+ void prepareForReply(TopicActivity.ReplyTask replyTask, String topicTitle, String loadedPageUrl) {
this.replyTask = replyTask;
- }
-
- void setTopicInfo(String topicTitle, String loadedPageUrl) {
this.topicTitle = topicTitle;
this.loadedPageUrl = loadedPageUrl;
}