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 0228e56a..9a71fa96 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 @@ -633,21 +633,16 @@ public class TopicActivity extends BaseActivity implements TopicAdapter.OnPostFo topicRecyclerviewItems.addAll(postList); topicAdapter.notifyDataSetChanged(); }); - viewModel.getFocusedPostIndex().observe(this, focusedPostIndex -> { + /*viewModel.getFocusedPostIndex().observe(this, focusedPostIndex -> { if (focusedPostIndex == null) return; - if (viewModel.isFocusedPostLastSeenMessage() && focusedPostIndex != viewModel.postCount() - 1) { - topicRecyclerviewItems.add(focusedPostIndex, new NewPostSeparator()); - topicAdapter.notifyItemInserted(focusedPostIndex); - } - //recyclerView.scrollToPosition(focusedPostIndex); - }); + recyclerView.scrollToPosition(focusedPostIndex); + });*/ viewModel.getTopicTaskResultCode().observe(this, resultCode -> { if (resultCode == null) return; progressBar.setVisibility(ProgressBar.GONE); switch (resultCode) { case SUCCESS: Timber.i("Successfully loaded topic with URL %s", viewModel.getTopicUrl()); - Timber.i("load " + viewModel.isFocusedPostLastSeenMessage()); paginationEnabled(true); break; case NETWORK_ERROR: diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java index e6970a80..2b5c44bc 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicParser.java @@ -146,10 +146,10 @@ public class TopicParser { * @return {@link ArrayList} of {@link Post}s * @see org.jsoup.Jsoup Jsoup */ - public static ArrayList parseTopic(Document topic, ParseHelpers.Language language) { + public static ArrayList parseTopic(Document topic, ParseHelpers.Language language) { //Method's variables final int NO_INDEX = -1; - ArrayList parsedPostsList = new ArrayList<>(); + ArrayList parsedPostsList = new ArrayList<>(); Elements postRows; //Each row is a post diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java index c2b53086..48799a4c 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java @@ -9,7 +9,9 @@ import org.jsoup.nodes.Element; import java.io.IOException; import java.util.ArrayList; +import gr.thmmy.mthmmy.activities.topic.NewPostSeparator; import gr.thmmy.mthmmy.activities.topic.TopicParser; +import gr.thmmy.mthmmy.activities.topic.TopicRecyclerViewItem; import gr.thmmy.mthmmy.base.BaseApplication; import gr.thmmy.mthmmy.model.Post; import gr.thmmy.mthmmy.model.ThmmyPage; @@ -50,11 +52,11 @@ public class TopicTask extends AsyncTask { String tmp = newPageUrl.substring(newPageUrl.indexOf("msg") + 3); if (tmp.contains(";")) { postFocus = Integer.parseInt(tmp.substring(0, tmp.indexOf(";"))); - if (newPageUrl.contains("topicseen")) + if (newPageUrl.contains("topicseen") && !newPageUrl.contains("#new")) focusedPostLastSeenMessage = true; } else if (tmp.contains("#")) { postFocus = Integer.parseInt(tmp.substring(0, tmp.indexOf("#"))); - if (newPageUrl.contains("topicseen")) + if (newPageUrl.contains("topicseen") && !newPageUrl.contains("#new")) focusedPostLastSeenMessage = true; } } @@ -96,31 +98,33 @@ public class TopicTask extends AsyncTask { //Finds number of pages int pageCount = TopicParser.parseTopicNumberOfPages(topic, currentPageIndex, language); - ArrayList newPostsList = TopicParser.parseTopic(topic, language); + ArrayList newPostsList = TopicParser.parseTopic(topic, language); int loadedPageTopicId = Integer.parseInt(ThmmyPage.getTopicId(newPageUrl)); //Finds the position of the focused message if present int focusedPostIndex = 0; for (int i = 0; i < newPostsList.size(); ++i) { - if (newPostsList.get(i).getPostIndex() == postFocus) { + if (((Post) newPostsList.get(i)).getPostIndex() == postFocus) { focusedPostIndex = i; break; } } + if (focusedPostLastSeenMessage) + newPostsList.add(focusedPostIndex, new NewPostSeparator()); return new TopicTaskResult(ResultCode.SUCCESS, topicTitle, replyPageUrl, newPostsList, loadedPageTopicId, - currentPageIndex, pageCount, focusedPostIndex, topicTreeAndMods, topicViewers, focusedPostLastSeenMessage); + currentPageIndex, pageCount, focusedPostIndex, topicTreeAndMods, topicViewers); } catch (IOException e) { return new TopicTaskResult(ResultCode.NETWORK_ERROR, null, null, null, - 0, 0, 0, 0, null, null, false); + 0, 0, 0, 0, null, null); } catch (Exception e) { if (isUnauthorized(topic)) { return new TopicTaskResult(ResultCode.UNAUTHORIZED, null, null, null, - 0, 0, 0, 0, null, null, false); + 0, 0, 0, 0, null, null); } else { Timber.e(e, "Topic parse failed"); return new TopicTaskResult(ResultCode.PARSING_ERROR, null, null, null, - 0, 0, 0, 0, null, null, false); + 0, 0, 0, 0, null, null); } } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTaskResult.java b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTaskResult.java index 2e098c16..a4d0dc37 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTaskResult.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTaskResult.java @@ -2,6 +2,7 @@ package gr.thmmy.mthmmy.activities.topic.tasks; import java.util.ArrayList; +import gr.thmmy.mthmmy.activities.topic.TopicRecyclerViewItem; import gr.thmmy.mthmmy.model.Post; public class TopicTaskResult { @@ -16,7 +17,7 @@ public class TopicTaskResult { * This topic's reply url */ private final String replyPageUrl; - private final ArrayList newPostsList; + private final ArrayList newPostsList; /** * The topicId of the loaded page */ @@ -36,12 +37,11 @@ public class TopicTaskResult { //Topic's info related private final String topicTreeAndMods; private final String topicViewers; - private final boolean focusedPostLastSeenMessage; public TopicTaskResult(TopicTask.ResultCode resultCode, String topicTitle, - String replyPageUrl, ArrayList newPostsList, int loadedPageTopicId, + String replyPageUrl, ArrayList newPostsList, int loadedPageTopicId, int currentPageIndex, int pageCount, int focusedPostIndex, String topicTreeAndMods, - String topicViewers, boolean focusedPostLastSeenMessage) { + String topicViewers) { this.resultCode = resultCode; this.topicTitle = topicTitle; this.replyPageUrl = replyPageUrl; @@ -52,7 +52,6 @@ public class TopicTaskResult { this.focusedPostIndex = focusedPostIndex; this.topicTreeAndMods = topicTreeAndMods; this.topicViewers = topicViewers; - this.focusedPostLastSeenMessage = focusedPostLastSeenMessage; } public TopicTask.ResultCode getResultCode() { @@ -67,7 +66,7 @@ public class TopicTaskResult { return replyPageUrl; } - public ArrayList getNewPostsList() { + public ArrayList getNewPostsList() { return newPostsList; } @@ -94,8 +93,4 @@ public class TopicTaskResult { public String getTopicViewers() { return topicViewers; } - - public boolean isFocusedPostLastSeenMessage() { - return focusedPostLastSeenMessage; - } } diff --git a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java index fbc40ece..785a92fa 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java +++ b/app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java @@ -9,6 +9,7 @@ import android.preference.PreferenceManager; import java.util.ArrayList; import gr.thmmy.mthmmy.activities.settings.SettingsActivity; +import gr.thmmy.mthmmy.activities.topic.TopicRecyclerViewItem; import gr.thmmy.mthmmy.activities.topic.tasks.DeleteTask; import gr.thmmy.mthmmy.activities.topic.tasks.EditTask; import gr.thmmy.mthmmy.activities.topic.tasks.PrepareForEditResult; @@ -65,7 +66,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa private MutableLiveData replyPageUrl = new MutableLiveData<>(); private MutableLiveData pageTopicId = new MutableLiveData<>(); private MutableLiveData topicTitle = new MutableLiveData<>(); - private MutableLiveData> postsList = new MutableLiveData<>(); + private MutableLiveData> postsList = new MutableLiveData<>(); private MutableLiveData focusedPostIndex = new MutableLiveData<>(); private MutableLiveData topicTaskResultCode = new MutableLiveData<>(); private MutableLiveData topicTreeAndMods = new MutableLiveData<>(); @@ -73,7 +74,6 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa private String topicUrl; private int currentPageIndex; private int pageCount; - private boolean focusedPostLastSeenMessage; private MutableLiveData prepareForReplyResult = new MutableLiveData<>(); private MutableLiveData prepareForEditResult = new MutableLiveData<>(); @@ -188,7 +188,6 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa if (result.getResultCode() == TopicTask.ResultCode.SUCCESS) { currentPageIndex = result.getCurrentPageIndex(); pageCount = result.getPageCount(); - focusedPostLastSeenMessage = result.isFocusedPostLastSeenMessage(); topicTreeAndMods.setValue(result.getTopicTreeAndMods()); topicViewers.setValue(result.getTopicViewers()); pageTopicId.setValue(result.getLoadedPageTopicId()); @@ -264,7 +263,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa return focusedPostIndex; } - public MutableLiveData> getPostsList() { + public MutableLiveData> getPostsList() { return postsList; } @@ -394,8 +393,4 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa throw new NullPointerException("No page has been loaded yet!"); return postsList.getValue().size(); } - - public boolean isFocusedPostLastSeenMessage() { - return focusedPostLastSeenMessage; - } } diff --git a/app/src/main/res/layout/activity_topic_new_message_separator.xml b/app/src/main/res/layout/activity_topic_new_message_separator.xml index b7e5507f..6705535b 100644 --- a/app/src/main/res/layout/activity_topic_new_message_separator.xml +++ b/app/src/main/res/layout/activity_topic_new_message_separator.xml @@ -9,12 +9,13 @@ android:layout_height="1dp" android:layout_weight="1" android:layout_gravity="center_vertical" + android:layout_marginStart="8dp" android:background="@color/red"/> @@ -24,5 +25,6 @@ android:layout_height="1dp" android:layout_weight="1" android:layout_gravity="center_vertical" + android:layout_marginEnd="8dp" android:background="@color/red"/> \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c6130e59..8dabb232 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -180,4 +180,5 @@ Link URL Link text Required + NEW MESSAGES