Browse Source

Refresh sesc/markAsReadUrl if needed

pull/70/head
Ezerous 5 years ago
parent
commit
104b568467
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 15
      app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java
  2. 4
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/TopicAdapter.java
  3. 25
      app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java
  4. 2
      app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java

15
app/src/main/java/gr/thmmy/mthmmy/activities/main/unread/UnreadFragment.java

@ -307,9 +307,12 @@ public class UnreadFragment extends BaseFragment {
}
Element topBar = document.select("table:not(.bordercolor):not(#bodyarea):has(td.middletext)").first();
Element pagesElement = null;
if (topBar != null)
Element pagesElement = null, markRead = null;
if (topBar != null) {
pagesElement = topBar.select("td.middletext").first();
markRead = document.select("table:not(.bordercolor):not([width])").select("a")
.first();
}
if (numberOfPages == 0 && pagesElement != null) {
Elements pages = pagesElement.select("a");
@ -319,6 +322,14 @@ public class UnreadFragment extends BaseFragment {
numberOfPages = 1;
}
if (markRead != null && loadedPages == numberOfPages - 1){
String retrievedMarkAsReadUrl = markRead.attr("href");
if(!retrievedMarkAsReadUrl.equals(markAsReadUrl)) {
markAsReadUrl = retrievedMarkAsReadUrl;
BaseApplication.getInstance().getSessionManager().refreshSescFromUrl(retrievedMarkAsReadUrl);
}
}
return fetchedTopicSummaries;
}
return new ArrayList<>();

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

@ -967,7 +967,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
if (viewModel.getCurrentPageIndex() == viewModel.getPageCount()) {
//same page
postFocusListener.onPostFocusChange(getItemCount() - 1);
Timber.e("new");
Timber.d("new");
return true;
}
}
@ -979,7 +979,7 @@ class TopicAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
for (int i = 0; i < topicItems.size(); i++) {
if (topicItems.get(i) instanceof Post && ((Post) topicItems.get(i)).getPostIndex() == testAgainst) {
//same page
Timber.e(Integer.toString(i));
Timber.d(Integer.toString(i));
postFocusListener.onPostFocusChange(i);
return true;
}

25
app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java

@ -244,6 +244,15 @@ public class SessionManager {
guestLogin();
}
}
public void refreshSescFromUrl(String url){
String sesc = extractSescFromLink(url);
if(sesc!=null){
setSesc(sesc);
setLogoutLink(generateLogoutLink(sesc));
setMarkAsReadLink(sesc);
}
}
//--------------------------------------AUTH ENDS-----------------------------------------------
//---------------------------------------GETTERS------------------------------------------------
@ -271,7 +280,7 @@ public class SessionManager {
public String getMarkAllAsReadLink() {
String markAsReadLink = sharedPrefs.getString(MARK_ALL_AS_READ_LINK, null);
if(markAsReadLink == null){ //For older versions, extract it from logout link (otherwise user would have to login again)
String sesc = extractSescFromLogoutLink(getLogoutLink());
String sesc = extractSescFromLink(getLogoutLink());
if(sesc!=null) {
setSesc(sesc);
markAsReadLink = generateMarkAllAsReadLink(sesc);
@ -313,6 +322,12 @@ public class SessionManager {
editor.apply();
}
private void setLogoutLink(String logoutLink){
SharedPreferences.Editor editor = sharedPrefs.edit();
editor.putString(LOGOUT_LINK, logoutLink);
editor.apply();
}
//--------------------------------------SETTERS END---------------------------------------------
//------------------------------------OTHER FUNCTIONS-------------------------------------------
@ -421,16 +436,16 @@ public class SessionManager {
Elements logoutLink = doc.select("a[href^=https://www.thmmy.gr/smf/index.php?action=logout;sesc=]");
if (!logoutLink.isEmpty()) {
String link = logoutLink.first().attr("href");
return extractSescFromLogoutLink(link);
return extractSescFromLink(link);
}
Timber.e(new ParseException("Parsing failed(extractSesc)"),"ParseException");
return null;
}
private String extractSescFromLogoutLink(String logoutLink){
if (logoutLink != null){
private String extractSescFromLink(String link){
if (link != null){
Pattern pattern = Pattern.compile(".+;sesc=(\\w+)");
Matcher matcher = pattern.matcher(logoutLink);
Matcher matcher = pattern.matcher(link);
if (matcher.find())
return matcher.group(1);
}

2
app/src/main/java/gr/thmmy/mthmmy/viewmodel/TopicViewModel.java

@ -132,7 +132,7 @@ public class TopicViewModel extends BaseViewModel implements TopicTask.OnTopicTa
int pageRequested = pageIndicatorIndex.getValue() - 1;
if (pageRequested != currentPageIndex - 1) {
Timber.i("Changing to page " + pageRequested + 1);
loadUrl(ParseHelpers.getBaseURL(topicUrl) + "." + String.valueOf(pageRequested * 15));
loadUrl(ParseHelpers.getBaseURL(topicUrl) + "." + pageRequested * 15);
pageIndicatorIndex.setValue(pageRequested + 1);
} else {
stopLoading();

Loading…
Cancel
Save