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()) {
loadable.no = 0;
loadable.
listViewIndex = 0;
loadable.listViewIndex = 0;
loadable.listViewTop = 0;
}

@ -43,7 +43,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
private static final String TAG = "DatabaseHelper";
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<Loadable, Integer> loadableDao;
@ -195,6 +195,14 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
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() {

@ -62,7 +62,7 @@ public class DatabaseLoadableManager {
}
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();
for (int i = 0; i < toFlush.size(); i++) {
Loadable loadable = toFlush.get(i);

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

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

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

Loading…
Cancel
Save