Sync the "n new posts" snackbar with the db

multisite
Floens 9 years ago
parent 482ddae618
commit 02a2bc93eb
  1. 3
      Clover/app/src/main/java/org/floens/chan/chan/ChanLoader.java
  2. 10
      Clover/app/src/main/java/org/floens/chan/core/database/DatabaseHelper.java
  3. 2
      Clover/app/src/main/java/org/floens/chan/core/database/DatabaseLoadableManager.java
  4. 37
      Clover/app/src/main/java/org/floens/chan/core/model/Loadable.java
  5. 23
      Clover/app/src/main/java/org/floens/chan/core/presenter/ThreadPresenter.java
  6. 4
      docs/database.txt

@ -113,8 +113,7 @@ public class ChanLoader implements Response.ErrorListener, Response.Listener<Cha
if (loadable.isCatalogMode()) { if (loadable.isCatalogMode()) {
loadable.no = 0; loadable.no = 0;
loadable. loadable.listViewIndex = 0;
listViewIndex = 0;
loadable.listViewTop = 0; loadable.listViewTop = 0;
} }

@ -43,7 +43,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
private static final String TAG = "DatabaseHelper"; private static final String TAG = "DatabaseHelper";
private static final String DATABASE_NAME = "ChanDB"; private static final String DATABASE_NAME = "ChanDB";
private static final int DATABASE_VERSION = 20; private static final int DATABASE_VERSION = 21;
public Dao<Pin, Integer> pinDao; public Dao<Pin, Integer> pinDao;
public Dao<Loadable, Integer> loadableDao; public Dao<Loadable, Integer> loadableDao;
@ -195,6 +195,14 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
Logger.e(TAG, "Error upgrading to version 20", e); Logger.e(TAG, "Error upgrading to version 20", e);
} }
} }
if (oldVersion < 21) {
try {
loadableDao.executeRawNoArgs("ALTER TABLE loadable ADD COLUMN lastLoaded default -1;");
} catch (SQLException e) {
Logger.e(TAG, "Error upgrading to version 21", e);
}
}
} }
public void reset() { public void reset() {

@ -62,7 +62,7 @@ public class DatabaseLoadableManager {
} }
if (!toFlush.isEmpty()) { if (!toFlush.isEmpty()) {
Logger.d(TAG, "Flushing " + toFlush.size() + " loadable(s) list positions"); Logger.d(TAG, "Flushing " + toFlush.size() + " loadable(s)");
long start = Time.startTiming(); long start = Time.startTiming();
for (int i = 0; i < toFlush.size(); i++) { for (int i = 0; i < toFlush.size(); i++) {
Loadable loadable = toFlush.get(i); Loadable loadable = toFlush.get(i);

@ -18,6 +18,7 @@
package org.floens.chan.core.model; package org.floens.chan.core.model;
import android.os.Parcel; import android.os.Parcel;
import android.text.TextUtils;
import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable; import com.j256.ormlite.table.DatabaseTable;
@ -51,6 +52,9 @@ public class Loadable {
@DatabaseField @DatabaseField
public int lastViewed = -1; public int lastViewed = -1;
@DatabaseField
public int lastLoaded = -1;
public int markedNo = -1; public int markedNo = -1;
// when the title, listViewTop, listViewIndex or lastViewed were changed // when the title, listViewTop, listViewIndex or lastViewed were changed
@ -87,23 +91,38 @@ public class Loadable {
} }
public void setTitle(String title) { public void setTitle(String title) {
this.title = title; if (!TextUtils.equals(this.title, title)) {
dirty = true; this.title = title;
dirty = true;
}
} }
public void setLastViewed(int lastViewed) { public void setLastViewed(int lastViewed) {
this.lastViewed = lastViewed; if (this.lastViewed != lastViewed) {
dirty = true; this.lastViewed = lastViewed;
dirty = true;
}
}
public void setLastLoaded(int lastLoaded) {
if (this.lastLoaded != lastLoaded) {
this.lastLoaded = lastLoaded;
dirty = true;
}
} }
public void setListViewTop(int listViewTop) { public void setListViewTop(int listViewTop) {
this.listViewTop = listViewTop; if (this.listViewTop != listViewTop) {
dirty = true; this.listViewTop = listViewTop;
dirty = true;
}
} }
public void setListViewIndex(int listViewIndex) { public void setListViewIndex(int listViewIndex) {
this.listViewIndex = listViewIndex; if (this.listViewIndex != listViewIndex) {
dirty = true; this.listViewIndex = listViewIndex;
dirty = true;
}
} }
/** /**
@ -157,6 +176,7 @@ public class Loadable {
", listViewIndex=" + listViewIndex + ", listViewIndex=" + listViewIndex +
", listViewTop=" + listViewTop + ", listViewTop=" + listViewTop +
", lastViewed=" + lastViewed + ", lastViewed=" + lastViewed +
", lastLoaded=" + lastLoaded +
", markedNo=" + markedNo + ", markedNo=" + markedNo +
", dirty=" + dirty + ", dirty=" + dirty +
'}'; '}';
@ -202,6 +222,7 @@ public class Loadable {
copy.listViewIndex = listViewIndex; copy.listViewIndex = listViewIndex;
copy.listViewTop = listViewTop; copy.listViewTop = listViewTop;
copy.lastViewed = lastViewed; copy.lastViewed = lastViewed;
copy.lastLoaded = lastLoaded;
return copy; return copy;
} }

@ -85,7 +85,6 @@ public class ThreadPresenter implements ChanLoader.ChanLoaderCallback, PostAdapt
private String searchQuery; private String searchQuery;
private PostsFilter.Order order = PostsFilter.Order.BUMP; private PostsFilter.Order order = PostsFilter.Order.BUMP;
private boolean historyAdded = false; private boolean historyAdded = false;
private int notificationPostCount = -1;
public ThreadPresenter(ThreadPresenterCallback threadPresenterCallback) { public ThreadPresenter(ThreadPresenterCallback threadPresenterCallback) {
this.threadPresenterCallback = threadPresenterCallback; this.threadPresenterCallback = threadPresenterCallback;
@ -122,7 +121,6 @@ public class ThreadPresenter implements ChanLoader.ChanLoaderCallback, PostAdapt
chanLoader = null; chanLoader = null;
loadable = null; loadable = null;
historyAdded = false; historyAdded = false;
notificationPostCount = -1;
threadPresenterCallback.showNewPostsNotification(false, -1); threadPresenterCallback.showNewPostsNotification(false, -1);
threadPresenterCallback.showLoading(); threadPresenterCallback.showLoading();
@ -253,14 +251,21 @@ public class ThreadPresenter implements ChanLoader.ChanLoaderCallback, PostAdapt
showPosts(); showPosts();
if (loadable.isThreadMode()) { if (loadable.isThreadMode()) {
int postsSize = result.posts.size(); int lastLoaded = loadable.lastLoaded;
List<Post> posts = result.posts;
if (notificationPostCount < 0) { int more = 0;
notificationPostCount = postsSize; if (lastLoaded > 0) {
} else if (postsSize > notificationPostCount) { for (int i = 0; i < posts.size(); i++) {
int more = postsSize - notificationPostCount; Post post = posts.get(i);
notificationPostCount = postsSize; if (post.no == lastLoaded) {
more = posts.size() - i - 1;
break;
}
}
}
loadable.setLastLoaded(posts.get(posts.size() - 1).no);
if (more > 0) {
threadPresenterCallback.showNewPostsNotification(true, more); threadPresenterCallback.showNewPostsNotification(true, more);
} }
} }

@ -60,3 +60,7 @@ CREATE TABLE `filter` (`action` INTEGER NOT NULL , `allBoards` SMALLINT NOT NULL
Changes in version 20: Changes in version 20:
ALTER TABLE loadable ADD COLUMN lastViewed default -1; ALTER TABLE loadable ADD COLUMN lastViewed default -1;
Changes in version 21:
ALTER TABLE loadable ADD COLUMN lastLoaded default -1;

Loading…
Cancel
Save