diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/MenuUtilsFragmentActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/MenuUtilsFragmentActivity.java index 2e7f6f92..1a411f96 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/MenuUtilsFragmentActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/MenuUtilsFragmentActivity.java @@ -114,8 +114,9 @@ public class MenuUtilsFragmentActivity extends PodcastFragmentActivity { if(ndf != null) { DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(activity); - //dbConn.markAllItemsAsReadForCurrentView(); + dbConn.markAllItemsAsReadForCurrentView(); + /* for(int i = 0; i < ndf.getListAdapter().getCount(); i++) { RssItem rssItem = (RssItem) ndf.getListAdapter().getItem(i); rssItem.setRead_temp(true); @@ -123,11 +124,13 @@ public class MenuUtilsFragmentActivity extends PodcastFragmentActivity { } ndf.notifyDataSetChangedOnAdapter(); + */ //If tablet view is enabled update the listview as well if(activity instanceof NewsReaderListActivity) ((NewsReaderListActivity) activity).updateAdapter(); + ndf.UpdateCurrentRssView(activity, false); } return true; diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderDetailFragment.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderDetailFragment.java index 1a41643d..0b587f5a 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderDetailFragment.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderDetailFragment.java @@ -372,6 +372,10 @@ public class NewsReaderDetailFragment extends ListFragment implements IOnStayUnr BlockingListView bView = ((BlockingListView) getListView()); bView.setBlockLayoutChildren(true); + if(getListAdapter() != null) { + ((NewsListArrayAdapter) getListAdapter()).getLazyList().close(); //Close cursor to release resources + } + NewsListArrayAdapter lvAdapter = new NewsListArrayAdapter(getActivity(), rssItemLazyList, NewsReaderDetailFragment.this, (PodcastFragmentActivity) getActivity()); setListAdapter(lvAdapter); diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnectionOrm.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnectionOrm.java index 8ea42062..b0e8381c 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnectionOrm.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/database/DatabaseConnectionOrm.java @@ -15,6 +15,7 @@ import java.util.List; import de.greenrobot.dao.query.LazyList; import de.greenrobot.dao.query.WhereCondition; import de.luhmer.owncloudnewsreader.Constants; +import de.luhmer.owncloudnewsreader.database.model.CurrentRssItemView; import de.luhmer.owncloudnewsreader.database.model.CurrentRssItemViewDao; import de.luhmer.owncloudnewsreader.database.model.DaoSession; import de.luhmer.owncloudnewsreader.database.model.Feed; @@ -265,6 +266,33 @@ public class DatabaseConnectionOrm { daoSession.getRssItemDao().update(rssItem); } + public void markAllItemsAsReadForCurrentView() { + /* + String sql = "UPDATE " + RssItemDao.TABLENAME + " SET " + RssItemDao.Properties.Read_temp.columnName + " = 1 " + + "WHERE " + RssItemDao.Properties.Id.columnName + " IN (SELECT " + CurrentRssItemViewDao.Properties.RssItemId.columnName + " FROM " + CurrentRssItemViewDao.TABLENAME + ")"; + daoSession.getDatabase().execSQL(sql); + */ + + WhereCondition whereCondition = new WhereCondition.StringCondition(RssItemDao.Properties.Id.columnName + " IN " + + "(SELECT " + CurrentRssItemViewDao.Properties.RssItemId.columnName + " FROM " + CurrentRssItemViewDao.TABLENAME + ")"); + + int iterationCount = 0; + final int itemsPerIteration = 100; + List rssItemList; + do { + int offset = iterationCount * itemsPerIteration; + int limit = itemsPerIteration; + rssItemList = daoSession.getRssItemDao().queryBuilder().where(whereCondition).limit(limit).offset(offset).listLazy(); + for (RssItem rssItem : rssItemList) { + rssItem.setRead_temp(true); + } + daoSession.getRssItemDao().updateInTx(rssItemList); + + iterationCount++; + } while(rssItemList.size() == itemsPerIteration); + } + + public List getRssItemsIdsFromList(List rssItemList) { List itemIds = new ArrayList(); for(RssItem rssItem : rssItemList) {