Browse Source

Bug fixes

pull/24/head
Apostolos Fanakis 8 years ago
parent
commit
4ee13d970f
  1. 13
      app/src/main/java/gr/thmmy/mthmmy/activities/board/BoardActivity.java
  2. 20
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicActivity.java
  3. 10
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

13
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 boardUrl;
private String boardTitle; private String boardTitle;
private String parsedTitle;
private int numberOfPages = -1; private int numberOfPages = -1;
private int pagesLoaded = 0; private int pagesLoaded = 0;
@ -175,7 +176,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
* <p>BoardTask's {@link AsyncTask#execute execute} method needs a boards's url as String * <p>BoardTask's {@link AsyncTask#execute execute} method needs a boards's url as String
* parameter!</p> * parameter!</p>
*/ */
public class BoardTask extends AsyncTask<String, Void, Void> { private class BoardTask extends AsyncTask<String, Void, Void> {
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
if (!isLoadingMore) progressBar.setVisibility(ProgressBar.VISIBLE); if (!isLoadingMore) progressBar.setVisibility(ProgressBar.VISIBLE);
@ -200,7 +201,12 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
@Override @Override
protected void onPostExecute(Void voids) { 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 //Parse was successful
++pagesLoaded; ++pagesLoaded;
@ -211,8 +217,7 @@ public class BoardActivity extends BaseActivity implements BoardAdapter.OnLoadMo
} }
private void parseBoard(Document boardPage) { private void parseBoard(Document boardPage) {
if (boardTitle == null || Objects.equals(boardTitle, "")) parsedTitle = boardPage.select("div.nav a.nav").last().text();
boardTitle = boardPage.select("div.nav a.nav").last().text();
//Removes loading item //Removes loading item
if (isLoadingMore) { if (isLoadingMore) {

20
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.method.ScrollingMovementMethod;
import android.text.style.ClickableSpan; import android.text.style.ClickableSpan;
import android.text.style.URLSpan; import android.text.style.URLSpan;
import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@ -165,7 +166,7 @@ public class TopicActivity extends BaseActivity {
recyclerView.setHasFixedSize(true); recyclerView.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext()); LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(layoutManager); recyclerView.setLayoutManager(layoutManager);
topicAdapter = new TopicAdapter(this, postsList, topicTask, topicTitle, loadedPageUrl); topicAdapter = new TopicAdapter(this, postsList, topicTask);
recyclerView.setAdapter(topicAdapter); recyclerView.setAdapter(topicAdapter);
replyFAB = (FloatingActionButton) findViewById(R.id.topic_fab); replyFAB = (FloatingActionButton) findViewById(R.id.topic_fab);
@ -178,10 +179,10 @@ public class TopicActivity extends BaseActivity {
public void onClick(View view) { public void onClick(View view) {
if (sessionManager.isLoggedIn()) { if (sessionManager.isLoggedIn()) {
postsList.add(null); postsList.add(null);
topicAdapter.prepareForReply(new ReplyTask()); topicAdapter.notifyItemInserted(postsList.size());
topicAdapter.prepareForReply(new ReplyTask(), topicTitle, loadedPageUrl);
replyFAB.hide(); replyFAB.hide();
bottomNavBar.setVisibility(View.GONE); bottomNavBar.setVisibility(View.GONE);
topicAdapter.notifyItemInserted(postsList.size());
} }
} }
}); });
@ -536,14 +537,16 @@ public class TopicActivity extends BaseActivity {
switch (parseResult) { switch (parseResult) {
case SUCCESS: 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)); thisPageBookmark = new Bookmark(parsedTitle, ThmmyPage.getTopicId(loadedPageUrl));
invalidateOptionsMenu(); invalidateOptionsMenu();
} }
progressBar.setVisibility(ProgressBar.INVISIBLE); progressBar.setVisibility(ProgressBar.INVISIBLE);
topicAdapter.customNotifyDataSetChanged(new TopicTask()); topicAdapter.customNotifyDataSetChanged(new TopicTask());
topicAdapter.setTopicInfo(parsedTitle, loadedPageUrl);
if (replyPageUrl == null) replyFAB.hide(); if (replyPageUrl == null) replyFAB.hide();
if (replyFAB.getVisibility() != View.GONE) replyFAB.setEnabled(true); if (replyFAB.getVisibility() != View.GONE) replyFAB.setEnabled(true);
@ -552,11 +555,6 @@ public class TopicActivity extends BaseActivity {
pageRequestValue = thisPage; pageRequestValue = thisPage;
paginationEnabled(true); paginationEnabled(true);
if (topicTitle != null)
if (parsedTitle != null)
if (topicTitle == null || Objects.equals(topicTitle, ""))
toolbarTitle.setText(parsedTitle);
break; break;
case NETWORK_ERROR: case NETWORK_ERROR:
Toast.makeText(getBaseContext(), "Network Error", Toast.LENGTH_SHORT).show(); Toast.makeText(getBaseContext(), "Network Error", Toast.LENGTH_SHORT).show();
@ -602,7 +600,7 @@ public class TopicActivity extends BaseActivity {
} }
//Finds topic title if missing //Finds topic title if missing
if (topicTitle == null || Objects.equals(topicTitle, "")) { {
parsedTitle = topic.select("td[id=top_subject]").first().text(); parsedTitle = topic.select("td[id=top_subject]").first().text();
if (parsedTitle.contains("Topic:")) { if (parsedTitle.contains("Topic:")) {
parsedTitle = parsedTitle.substring(parsedTitle.indexOf("Topic:") + 7 parsedTitle = parsedTitle.substring(parsedTitle.indexOf("Topic:") + 7

10
app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java

@ -111,8 +111,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
* @param context the context of the {@link RecyclerView} * @param context the context of the {@link RecyclerView}
* @param postsList List of {@link Post} objects to use * @param postsList List of {@link Post} objects to use
*/ */
TopicAdapter(Context context, List<Post> postsList, TopicActivity.TopicTask topicTask TopicAdapter(Context context, List<Post> postsList, TopicActivity.TopicTask topicTask) {
, String topicTitle, String loadedPageUrl) {
this.context = context; this.context = context;
this.postsList = postsList; this.postsList = postsList;
@ -122,15 +121,10 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
viewProperties.add(new boolean[3]); viewProperties.add(new boolean[3]);
} }
this.topicTask = topicTask; 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; this.replyTask = replyTask;
}
void setTopicInfo(String topicTitle, String loadedPageUrl) {
this.topicTitle = topicTitle; this.topicTitle = topicTitle;
this.loadedPageUrl = loadedPageUrl; this.loadedPageUrl = loadedPageUrl;
} }

Loading…
Cancel
Save