improve performance - v.0.5.9

This commit is contained in:
David Development 2014-04-21 20:28:11 +02:00
parent 1b86ec8359
commit 2dc3c20f0d
6 changed files with 93 additions and 56 deletions

View file

@ -20,7 +20,7 @@
<application
android:allowBackup="true"
android:debuggable="true"
android:debuggable="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >

View file

@ -182,13 +182,14 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
String headerText = (item.header != null) ? item.header : "";
viewHolder.tV_HeaderText.setText(headerText);
/*
String unreadCount = unreadCountFeeds.get((int) item.id_database);
if(unreadCount != null)
viewHolder.tV_UnreadCount.setText(unreadCount);
else {
else {*/
boolean execludeStarredItems = (item.folder_id.equals(ALL_STARRED_ITEMS)) ? false : true;
SetUnreadCountForFeed(viewHolder.tV_UnreadCount, String.valueOf(item.id_database), execludeStarredItems);
}
//}
loadFavIconForFeed(item.favIcon, viewHolder.imgView_FavIcon);
}
@ -292,11 +293,13 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
{
if(group.idFolder.equals(ITEMS_WITHOUT_FOLDER))
{
/*
String unreadCount = unreadCountFeeds.get((int) group.id_database);
if(unreadCount != null)
viewHolder.txt_UnreadCount.setText(unreadCount);
else
*/
SetUnreadCountForFeed(viewHolder.txt_UnreadCount, String.valueOf(group.id_database), true);
skipGetUnread = true;
@ -304,11 +307,12 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
}
if(!skipGetUnread) {
/*
String unreadCount = unreadCountFolders.get((int) group.id_database);
if(unreadCount != null)
viewHolder.txt_UnreadCount.setText(unreadCount);
else
else */
SetUnreadCountForFolder(viewHolder.txt_UnreadCount, String.valueOf(group.id_database));
}
@ -397,27 +401,28 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
private void SetUnreadCountForFeed(TextView textView, String idDatabase, boolean execludeStarredItems)
{
IGetTextForTextViewAsyncTask iGetter = new UnreadFeedCount(mContext, idDatabase, execludeStarredItems);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
// Execute in parallel
new FillTextForTextViewAsyncTask(textView, iGetter).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ((Void) null));
else
new FillTextForTextViewAsyncTask(textView, iGetter).execute((Void) null);
FillTextForTextView(textView, iGetter);
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void SetUnreadCountForFolder(TextView textView, String idDatabase)
{
IGetTextForTextViewAsyncTask iGetter = new UnreadFolderCount(mContext, idDatabase);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
// Execute in parallel
new FillTextForTextViewAsyncTask(textView, iGetter).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ((Void) null));
else
new FillTextForTextViewAsyncTask(textView, iGetter).execute((Void) null);
FillTextForTextView(textView, iGetter);
}
public static void FillTextForTextView(TextView textView, IGetTextForTextViewAsyncTask iGetter) {
textView.setVisibility(View.INVISIBLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
// Execute in parallel
new FillTextForTextViewAsyncTask(textView, iGetter).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ((Void) null));
else
new FillTextForTextViewAsyncTask(textView, iGetter).execute((Void) null);
}
static class GroupHolder
@ -469,13 +474,13 @@ public class SubscriptionExpandableListAdapter extends BaseExpandableListAdapter
}
SparseArray<String> unreadCountFolders;
SparseArray<String> unreadCountFeeds;
//SparseArray<String> unreadCountFolders;
//SparseArray<String> unreadCountFeeds;
SparseArray<String> urlsToFavIcons;
@Override
public void notifyDataSetChanged() {
unreadCountFolders = dbConn.getUnreadItemCountForFolder();
unreadCountFeeds = dbConn.getUnreadItemCountForFeed();
//unreadCountFolders = dbConn.getUnreadItemCountForFolder();
//unreadCountFeeds = dbConn.getUnreadItemCountForFeed();
urlsToFavIcons = dbConn.getUrlsToFavIcons();
super.notifyDataSetChanged();

View file

@ -27,32 +27,42 @@ import android.widget.TextView;
import java.lang.ref.WeakReference;
import de.luhmer.owncloudnewsreader.cursor.NewsListCursorAdapter;
public class FillTextForTextViewAsyncTask extends AsyncTask<Void, Void, String> {
IGetTextForTextViewAsyncTask iGetter;
WeakReference<TextView> textView;
public FillTextForTextViewAsyncTask(TextView textView, IGetTextForTextViewAsyncTask iGetter)
{
this.iGetter = iGetter;
this.textView = new WeakReference<TextView>(textView);
this.textView = new WeakReference<TextView>(textView);
}
//http://stackoverflow.com/a/14217816
@Override
protected String doInBackground(Void... params) {
Process.setThreadPriority(9);
//Process.setThreadPriority(9);
return iGetter.getText();
}
/* (non-Javadoc)
* @see android.os.AsyncTask#onPostExecute(java.lang.Object)
*/
@Override
protected void onPostExecute(String result) {
if(result != null)
if(!result.equals("0"))
if(textView.get() != null)
textView.get().setText(result);
super.onPostExecute(result);
protected void onPostExecute(String text) {
if (isCancelled()) {
text = null;
}
if(text != null) {
if (!text.equals("0")) {
if (textView.get() != null) {
textView.get().setText(text);
NewsListCursorAdapter.FadeInTextView(textView.get());
}
}
}
}
}

View file

@ -55,10 +55,13 @@ import java.lang.ref.WeakReference;
import butterknife.ButterKnife;
import butterknife.InjectView;
import de.luhmer.owncloudnewsreader.ListView.SubscriptionExpandableListAdapter;
import de.luhmer.owncloudnewsreader.ListView.UnreadFeedCount;
import de.luhmer.owncloudnewsreader.NewsDetailFragment;
import de.luhmer.owncloudnewsreader.NewsReaderListActivity;
import de.luhmer.owncloudnewsreader.R;
import de.luhmer.owncloudnewsreader.SettingsActivity;
import de.luhmer.owncloudnewsreader.async_tasks.IGetTextForTextViewAsyncTask;
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
import de.luhmer.owncloudnewsreader.helper.FontHelper;
import de.luhmer.owncloudnewsreader.helper.PostDelayHandler;
@ -250,11 +253,8 @@ public class NewsListCursorAdapter extends CursorAdapter {
extendedLayout.textViewItemBody.setVisibility(View.INVISIBLE);
String idItemDb = cursor.getString(0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
// Execute in parallel
new DescriptionTextLoaderTask(extendedLayout.textViewItemBody, idItemDb).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ((Void) null));
else
new DescriptionTextLoaderTask(extendedLayout.textViewItemBody, idItemDb).execute((Void) null);
IGetTextForTextViewAsyncTask iGetter = new DescriptionTextGetter(idItemDb);
SubscriptionExpandableListAdapter.FillTextForTextView(extendedLayout.textViewItemBody, iGetter);
extendedLayout.textViewTitle.setText(dbConn.getTitleOfSubscriptionByRowID(cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_SUBSCRIPTION_ID))));
extendedLayout.textViewSummary.setTag(cursor.getString(0));
@ -366,10 +366,31 @@ public class NewsListCursorAdapter extends CursorAdapter {
class DescriptionTextGetter implements IGetTextForTextViewAsyncTask {
private String idItemDb;
public DescriptionTextGetter(String idItemDb) {
this.idItemDb = idItemDb;
}
@Override
public String getText() {
DatabaseConnection dbConn = new DatabaseConnection(mContext);
Cursor cursor = dbConn.getItemByDbID(idItemDb);
cursor.moveToFirst();
String body = cursor.getString(cursor.getColumnIndex(DatabaseConnection.RSS_ITEM_BODY));
String result = getBodyText(body);
cursor.close();
return result;
}
}
/*
class DescriptionTextLoaderTask extends AsyncTask<Void, Void, String> {
private String idItemDb;
private final WeakReference<TextView> textViewWeakReference;
@ -406,30 +427,29 @@ public class NewsListCursorAdapter extends CursorAdapter {
if (textView != null) {
textView.setText(text);
fadeInTextView(textView);
FadeInTextView(textView);
}
}
}
}
*/
public static void FadeInTextView(final TextView textView)
{
Animation fadeOut = new AlphaAnimation(0, 1);
fadeOut.setInterpolator(new AccelerateInterpolator());
fadeOut.setDuration(300);
private void fadeInTextView(final TextView textView)
fadeOut.setAnimationListener(new Animation.AnimationListener()
{
Animation fadeOut = new AlphaAnimation(0, 1);
fadeOut.setInterpolator(new AccelerateInterpolator());
fadeOut.setDuration(300);
fadeOut.setAnimationListener(new Animation.AnimationListener()
public void onAnimationEnd(Animation animation)
{
public void onAnimationEnd(Animation animation)
{
textView.setVisibility(View.VISIBLE);
}
public void onAnimationRepeat(Animation animation) {}
public void onAnimationStart(Animation animation) {}
});
textView.setVisibility(View.VISIBLE);
}
public void onAnimationRepeat(Animation animation) {}
public void onAnimationStart(Animation animation) {}
});
textView.startAnimation(fadeOut);
}
textView.startAnimation(fadeOut);
}
}

View file

@ -363,11 +363,13 @@ public class DatabaseConnection {
database.execSQL(sql);
}
/*
public void removeReadItems(int limit) {
String sql = "DELETE FROM " + RSS_ITEM_TABLE + " WHERE rowid IN (SELECT rowid FROM " + RSS_ITEM_TABLE + " WHERE " + RSS_ITEM_READ_TEMP + " = 1 " +
" AND " + RSS_ITEM_READ + " = 1 ORDER BY " + RSS_ITEM_PUBDATE + " desc LIMIT " + limit + ")";
database.execSQL(sql);
}
*/
/*
public Cursor getAllData(String TABLE_NAME) {

View file

@ -92,8 +92,8 @@ public class AsyncTask_GetItems extends AsyncTask_Reader {
do {
offset = dbConn.getLowestItemId(true);
requestCount = api.GetItems(TAGS.ALL_STARRED, context, String.valueOf(offset), true, "0", "2", api);
if(requestCount > 0)
offset = dbConn.getLowestItemId(true);
//if(requestCount > 0)
// offset = dbConn.getLowestItemId(true);
totalCount += requestCount;
} while(requestCount == maxSyncSize && totalCount < maxItemsInDatabase);
}