Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/news-android.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Development <david-dev@live.de>2014-07-04 13:06:39 +0400
committerDavid Development <david-dev@live.de>2014-07-04 13:06:39 +0400
commit63d2c5700f9451722a244ac9969de766a60be6e6 (patch)
treef8fce9035a6b76f8ca810dcff07d2afdb04a0e4f /News-Android-App/src/main
parent99b35d1d70f13c4b58be617ec03e65515525262e (diff)
Fix app crash (modify data without calling notifyDataSetChanged)
Diffstat (limited to 'News-Android-App/src/main')
-rw-r--r--News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/SubscriptionExpandableListAdapter.java124
-rw-r--r--News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListFragment.java26
2 files changed, 87 insertions, 63 deletions
diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/SubscriptionExpandableListAdapter.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/SubscriptionExpandableListAdapter.java
index 76017382..1e1040f3 100644
--- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/SubscriptionExpandableListAdapter.java
+++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/ListView/SubscriptionExpandableListAdapter.java
@@ -51,6 +51,7 @@ import de.luhmer.owncloudnewsreader.R;
import de.luhmer.owncloudnewsreader.SettingsActivity;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
import de.luhmer.owncloudnewsreader.helper.FavIconHandler;
+import de.luhmer.owncloudnewsreader.helper.FileUtils;
import de.luhmer.owncloudnewsreader.helper.FontHelper;
import de.luhmer.owncloudnewsreader.helper.ImageHandler;
import de.luhmer.owncloudnewsreader.helper.ThemeChooser;
@@ -105,7 +106,7 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
LayoutInflater inflater;
private final String favIconPath;
boolean mIsTwoPane;
- private static boolean isTwoPane(Context context) {
+ public static boolean isTwoPane(Context context) {
return context.getResources().getBoolean(R.bool.two_pane);
//return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE;
}
@@ -116,7 +117,7 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
//Picasso.with(mContext).setDebugging(true);
- this.favIconPath = ImageHandler.getPathFavIcons(mContext);
+ this.favIconPath = FileUtils.getPathFavIcons(mContext);
this.inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.mContext = mContext;
this.dbConn = dbConn;
@@ -139,18 +140,18 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
this.listView = listView;
}
- private void AddEverythingInCursorFolderToSubscriptions(Cursor itemsCursor)
+ private void AddEverythingInCursorFolderToSubscriptions(Cursor itemsCursor, ArrayList<AbstractItem> dest)
{
while (itemsCursor.moveToNext()) {
String header = itemsCursor.getString(itemsCursor.getColumnIndex(DatabaseConnection.FOLDER_LABEL));
//String id_folder = itemsCursor.getString(itemsCursor.getColumnIndex(DatabaseConnection.FOLDER_LABEL_ID));
long id = itemsCursor.getLong(0);
- mCategoriesArrayList.add(new FolderSubscribtionItem(header, null, id, null));
+ dest.add(new FolderSubscribtionItem(header, null, id, null));
}
itemsCursor.close();
}
- private void AddEverythingInCursorFeedsToSubscriptions(Cursor itemsCursor)
+ private void AddEverythingInCursorFeedsToSubscriptions(Cursor itemsCursor, ArrayList<AbstractItem> dest)
{
while (itemsCursor.moveToNext()) {
String header = itemsCursor.getString(itemsCursor.getColumnIndex(DatabaseConnection.SUBSCRIPTION_HEADERTEXT));
@@ -158,7 +159,7 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
long id = itemsCursor.getLong(0);
String subscriptionId = itemsCursor.getString(itemsCursor.getColumnIndex(DatabaseConnection.SUBSCRIPTION_ID));
String favIconUrl = itemsCursor.getString(itemsCursor.getColumnIndex(DatabaseConnection.SUBSCRIPTION_FAVICON_URL));
- mCategoriesArrayList.add(new ConcreteFeedItem(header, ITEMS_WITHOUT_FOLDER.getValueString(), subscriptionId, favIconUrl, id));
+ dest.add(new ConcreteFeedItem(header, ITEMS_WITHOUT_FOLDER.getValueString(), subscriptionId, favIconUrl, id));
}
itemsCursor.close();
}
@@ -495,28 +496,31 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
}
+ ArrayList<AbstractItem> mCategoriesArrayListAsync;
+ SparseArray<SparseArray<ConcreteFeedItem>> mItemsArrayListAsync;
public void ReloadAdapter()
{
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
showOnlyUnread = mPrefs.getBoolean(SettingsActivity.CB_SHOWONLYUNREAD_STRING, false);
- mCategoriesArrayList = new ArrayList<AbstractItem>();
- mCategoriesArrayList.add(new FolderSubscribtionItem(mContext.getString(R.string.allUnreadFeeds), null, ALL_UNREAD_ITEMS.getValue(), null));
- mCategoriesArrayList.add(new FolderSubscribtionItem(mContext.getString(R.string.starredFeeds), null, ALL_STARRED_ITEMS.getValue(), null));
+ mCategoriesArrayListAsync = new ArrayList<AbstractItem>();
+ mCategoriesArrayListAsync.add(new FolderSubscribtionItem(mContext.getString(R.string.allUnreadFeeds), null, ALL_UNREAD_ITEMS.getValue(), null));
+ mCategoriesArrayListAsync.add(new FolderSubscribtionItem(mContext.getString(R.string.starredFeeds), null, ALL_STARRED_ITEMS.getValue(), null));
//mCategoriesArrayList.add(new FolderSubscribtionItem(mContext.getString(R.string.starredFeeds), -11, null, null));
- AddEverythingInCursorFolderToSubscriptions(dbConn.getAllTopSubscriptions(showOnlyUnread));
- AddEverythingInCursorFeedsToSubscriptions(dbConn.getAllTopSubscriptionsWithoutFolder(showOnlyUnread));
+ AddEverythingInCursorFolderToSubscriptions(dbConn.getAllTopSubscriptions(showOnlyUnread), mCategoriesArrayListAsync);
+ AddEverythingInCursorFeedsToSubscriptions(dbConn.getAllTopSubscriptionsWithoutFolder(showOnlyUnread), mCategoriesArrayListAsync);
//AddEverythingInCursorToSubscriptions(dbConn.getAllTopSubscriptionsWithUnreadFeeds());
- mItemsArrayList = new SparseArray<SparseArray<ConcreteFeedItem>>();
+ mItemsArrayListAsync = new SparseArray<SparseArray<ConcreteFeedItem>>();
- for(int groupPosition = 0; groupPosition < mCategoriesArrayList.size(); groupPosition++) {
- int parent_id = (int)getGroupId(groupPosition);
+ for(int groupPosition = 0; groupPosition < mCategoriesArrayListAsync.size(); groupPosition++) {
+ //int parent_id = (int)getGroupId(groupPosition);
+ int parent_id = (int) mCategoriesArrayListAsync.get(groupPosition).id_database;
String parentId = String.valueOf(parent_id);
- mItemsArrayList.append(parent_id, new SparseArray<ConcreteFeedItem>());
+ mItemsArrayListAsync.append(parent_id, new SparseArray<ConcreteFeedItem>());
Cursor itemsCursor = dbConn.getAllSubscriptionForFolder(parentId, showOnlyUnread);
itemsCursor.requery();
int childPosTemp = 0;
@@ -527,7 +531,7 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
String subscription_id = itemsCursor.getString(itemsCursor.getColumnIndex(DatabaseConnection.SUBSCRIPTION_ID));
String urlFavicon = itemsCursor.getString(itemsCursor.getColumnIndex(DatabaseConnection.SUBSCRIPTION_FAVICON_URL));
ConcreteFeedItem newItem = new ConcreteFeedItem(name, parentId, subscription_id, urlFavicon, id_database);
- mItemsArrayList.get(parent_id).put(childPosTemp, newItem);
+ mItemsArrayListAsync.get(parent_id).put(childPosTemp, newItem);
childPosTemp++;
} while (itemsCursor.moveToNext());
itemsCursor.close();
@@ -552,50 +556,94 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
private class NotifyDataSetChangedAsyncTask extends AsyncTask<Void, Void, Void> {
- // Block children layout for now
- BlockingExpandableListView bView;
SparseArray<String> unreadCountFoldersTemp;
SparseArray<String> unreadCountFeedsTemp;
SparseArray<String> urlsToFavIconsTemp;
+ @Override
+ protected Void doInBackground(Void... voids) {
+ unreadCountFoldersTemp = dbConn.getUnreadItemCountForFolder(mContext);
+ unreadCountFeedsTemp = dbConn.getUnreadItemCountForFeed();
+ urlsToFavIconsTemp = dbConn.getUrlsToFavIcons();
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ notifyCountDataSetChanged(unreadCountFoldersTemp, unreadCountFeedsTemp, urlsToFavIconsTemp);
+ super.onPostExecute(aVoid);
+ }
+ }
+
+ public void ReloadAdapterAsync(View progressBar) {
+ new ReloadAdapterAsyncTask(progressBar).execute((Void) null);
+ }
+
+ private class ReloadAdapterAsyncTask extends AsyncTask<Void, Void, Void> {
+
+ View progressBar;
+
+ public ReloadAdapterAsyncTask(View progressBar) {
+ this.progressBar = progressBar;
+ }
@Override
protected void onPreExecute() {
- bView = (BlockingExpandableListView) listView;
+ progressBar.setVisibility(View.VISIBLE);
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... voids) {
- unreadCountFoldersTemp = dbConn.getUnreadItemCountForFolder(mContext);
- unreadCountFeedsTemp = dbConn.getUnreadItemCountForFeed();
- urlsToFavIconsTemp = dbConn.getUrlsToFavIcons();
+ ReloadAdapter();
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
- unreadCountFolders = unreadCountFoldersTemp;
- unreadCountFeeds = unreadCountFeedsTemp;
- urlsToFavIcons = urlsToFavIconsTemp;
+ notifyReloadAdapterDataChanged();
- int firstVisPos = bView.getFirstVisiblePosition();
- View firstVisView = bView.getChildAt(0);
- int top = firstVisView != null ? firstVisView.getTop() : 0;
+ progressBar.setVisibility(View.GONE);
- // Number of items added before the first visible item
- int itemsAddedBeforeFirstVisible = 0;
+ super.onPostExecute(aVoid);
+ }
+ }
- bView.setBlockLayoutChildren(true);
- notifyDataSetChanged();
- bView.setBlockLayoutChildren(false);
- // Call setSelectionFromTop to change the ListView position
- if(bView.getCount() >= firstVisPos + itemsAddedBeforeFirstVisible)
- bView.setSelectionFromTop(firstVisPos + itemsAddedBeforeFirstVisible, top);
+ public void notifyReloadAdapterDataChanged()
+ {
+ mCategoriesArrayList = mCategoriesArrayListAsync;
+ mCategoriesArrayListAsync = null;
- super.onPostExecute(aVoid);
- }
+ mItemsArrayList = mItemsArrayListAsync;
+ mItemsArrayListAsync = null;
+
+ notifyDataSetChanged();
+
+ NotifyDataSetChangedAsync();
+ }
+
+ public void notifyCountDataSetChanged(SparseArray<String> unreadCountFolders, SparseArray<String> unreadCountFeeds, SparseArray<String> urlsToFavIcons) {
+ this.unreadCountFolders = unreadCountFolders;
+ this.unreadCountFeeds = unreadCountFeeds;
+ this.urlsToFavIcons = urlsToFavIcons;
+
+ BlockingExpandableListView bView = (BlockingExpandableListView) listView;
+
+ int firstVisPos = bView.getFirstVisiblePosition();
+ View firstVisView = bView.getChildAt(0);
+ int top = firstVisView != null ? firstVisView.getTop() : 0;
+
+ // Number of items added before the first visible item
+ int itemsAddedBeforeFirstVisible = 0;
+
+ bView.setBlockLayoutChildren(true);
+ notifyDataSetChanged();
+ bView.setBlockLayoutChildren(false);
+
+ // Call setSelectionFromTop to change the ListView position
+ if(bView.getCount() >= firstVisPos + itemsAddedBeforeFirstVisible)
+ bView.setSelectionFromTop(firstVisPos + itemsAddedBeforeFirstVisible, top);
}
diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListFragment.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListFragment.java
index 95e8ae4f..6d9606ce 100644
--- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListFragment.java
+++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListFragment.java
@@ -30,7 +30,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
-import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@@ -165,33 +164,10 @@ public class NewsReaderListFragment extends SherlockFragment implements OnCreate
}
public void ReloadAdapter() {
- new ReloadAdapterAsync().execute((Void) null);
+ lvAdapter.ReloadAdapterAsync(progressBar);
}
- private class ReloadAdapterAsync extends AsyncTask<Void, Void, Void> {
- @Override
- protected void onPreExecute() {
- progressBar.setVisibility(View.VISIBLE);
- super.onPreExecute();
- }
-
- @Override
- protected Void doInBackground(Void... voids) {
- lvAdapter.ReloadAdapter();
- return null;
- }
-
- @Override
- protected void onPostExecute(Void aVoid) {
- //lvAdapter.notifyDataSetChanged();
- lvAdapter.NotifyDataSetChangedAsync();
-
- progressBar.setVisibility(View.GONE);
-
- super.onPostExecute(aVoid);
- }
- }