Refactoring
This commit is contained in:
parent
4b710a77df
commit
ae0cbad342
5 changed files with 17 additions and 17 deletions
|
@ -21,7 +21,7 @@ public class NewsReaderApplication extends Application {
|
||||||
|
|
||||||
public void initImageLoader() {
|
public void initImageLoader() {
|
||||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
int diskCacheSize = Integer.parseInt(preferences.getString(SettingsActivity.SP_MAX_CACHE_SIZE,"1000"))*1024*1024;
|
int diskCacheSize = Integer.parseInt(preferences.getString(SettingsActivity.SP_MAX_CACHE_SIZE,"500"))*1024*1024;
|
||||||
if(ImageLoader.getInstance().isInited())
|
if(ImageLoader.getInstance().isInited())
|
||||||
ImageLoader.getInstance().destroy();
|
ImageLoader.getInstance().destroy();
|
||||||
DisplayImageOptions imageOptions = new DisplayImageOptions.Builder().
|
DisplayImageOptions imageOptions = new DisplayImageOptions.Builder().
|
||||||
|
|
|
@ -555,7 +555,7 @@ public class SettingsActivity extends PreferenceActivity {
|
||||||
|
|
||||||
((EditTextPreference) preference).getDialog().dismiss();
|
((EditTextPreference) preference).getDialog().dismiss();
|
||||||
|
|
||||||
CheckForUnsycedChangesInDatabaseAndResetDatabase(_mActivity);
|
checkForUnsycedChangesInDatabaseAndResetDatabase(_mActivity);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -587,7 +587,7 @@ public class SettingsActivity extends PreferenceActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void CheckForUnsycedChangesInDatabaseAndResetDatabase(final Context context) {
|
public static void checkForUnsycedChangesInDatabaseAndResetDatabase(final Context context) {
|
||||||
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(context);
|
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(context);
|
||||||
boolean resetDatabase = true;
|
boolean resetDatabase = true;
|
||||||
if(dbConn.areThereAnyUnsavedChangesInDatabase())
|
if(dbConn.areThereAnyUnsavedChangesInDatabase())
|
||||||
|
|
|
@ -34,7 +34,6 @@ import de.luhmer.owncloudnewsreader.helper.ImageDownloadFinished;
|
||||||
public class GetImageThreaded extends Thread
|
public class GetImageThreaded extends Thread
|
||||||
{
|
{
|
||||||
private static final String TAG = "GetImageAsyncTask";
|
private static final String TAG = "GetImageAsyncTask";
|
||||||
//private static int count = 0;
|
|
||||||
|
|
||||||
private URL WEB_URL_TO_FILE;
|
private URL WEB_URL_TO_FILE;
|
||||||
private ImageDownloadFinished imageDownloadFinished;
|
private ImageDownloadFinished imageDownloadFinished;
|
||||||
|
|
|
@ -326,7 +326,7 @@ public class DatabaseConnectionOrm {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LazyList<RssItem> getAllItemsWithIdHigher(long id) {
|
public LazyList<RssItem> getAllItemsWithIdHigher(long id) {
|
||||||
return daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.Id.ge(id)).listLazyUncached();
|
return daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.Id.ge(id)).listLazy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateRssItem(RssItem rssItem) {
|
public void updateRssItem(RssItem rssItem) {
|
||||||
|
|
|
@ -38,6 +38,7 @@ import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import de.greenrobot.dao.query.LazyList;
|
||||||
import de.luhmer.owncloudnewsreader.NewsReaderListActivity;
|
import de.luhmer.owncloudnewsreader.NewsReaderListActivity;
|
||||||
import de.luhmer.owncloudnewsreader.R;
|
import de.luhmer.owncloudnewsreader.R;
|
||||||
import de.luhmer.owncloudnewsreader.async_tasks.GetImageThreaded;
|
import de.luhmer.owncloudnewsreader.async_tasks.GetImageThreaded;
|
||||||
|
@ -56,7 +57,7 @@ public class DownloadImagesService extends IntentService {
|
||||||
|
|
||||||
private int NOTIFICATION_ID = 1;
|
private int NOTIFICATION_ID = 1;
|
||||||
private NotificationManager notificationManager;
|
private NotificationManager notificationManager;
|
||||||
private NotificationCompat.Builder NotificationDownloadImages;
|
private NotificationCompat.Builder mNotificationDownloadImages;
|
||||||
|
|
||||||
private int maxCount;
|
private int maxCount;
|
||||||
//private int total_size = 0;
|
//private int total_size = 0;
|
||||||
|
@ -86,7 +87,7 @@ public class DownloadImagesService extends IntentService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
if(NotificationDownloadImages != null)
|
if(mNotificationDownloadImages != null)
|
||||||
{
|
{
|
||||||
if(maxCount == 0)
|
if(maxCount == 0)
|
||||||
notificationManager.cancel(NOTIFICATION_ID);
|
notificationManager.cancel(NOTIFICATION_ID);
|
||||||
|
@ -101,9 +102,6 @@ public class DownloadImagesService extends IntentService {
|
||||||
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(this);
|
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(this);
|
||||||
Notification notify = BuildNotification();
|
Notification notify = BuildNotification();
|
||||||
|
|
||||||
//if(linksFavIcons.size() > 0)
|
|
||||||
//notificationManager.notify(NOTIFICATION_ID, notify);
|
|
||||||
|
|
||||||
List<Feed> feedList = dbConn.getListOfFeeds();
|
List<Feed> feedList = dbConn.getListOfFeeds();
|
||||||
FavIconHandler favIconHandler = new FavIconHandler(this);
|
FavIconHandler favIconHandler = new FavIconHandler(this);
|
||||||
for(Feed feed : feedList) {
|
for(Feed feed : feedList) {
|
||||||
|
@ -124,12 +122,13 @@ public class DownloadImagesService extends IntentService {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
((LazyList)rssItemList).close();
|
||||||
|
|
||||||
maxCount = links.size();
|
maxCount = links.size();
|
||||||
|
|
||||||
if (maxCount > 0)
|
if (maxCount > 0) {
|
||||||
notificationManager.notify(NOTIFICATION_ID, notify);
|
notificationManager.notify(NOTIFICATION_ID, notify);
|
||||||
|
}
|
||||||
|
|
||||||
linksToImages.addAll(links);
|
linksToImages.addAll(links);
|
||||||
|
|
||||||
|
@ -169,13 +168,13 @@ public class DownloadImagesService extends IntentService {
|
||||||
Intent intentNewsReader = new Intent(this, NewsReaderListActivity.class);
|
Intent intentNewsReader = new Intent(this, NewsReaderListActivity.class);
|
||||||
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intentNewsReader, 0);
|
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intentNewsReader, 0);
|
||||||
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
NotificationDownloadImages = new NotificationCompat.Builder(this)
|
mNotificationDownloadImages = new NotificationCompat.Builder(this)
|
||||||
.setContentTitle("ownCloud News Reader")
|
.setContentTitle("ownCloud News Reader")
|
||||||
.setContentText("Downloading Images for offline usage")
|
.setContentText("Downloading Images for offline usage")
|
||||||
.setSmallIcon(R.drawable.ic_notification)
|
.setSmallIcon(R.drawable.ic_notification)
|
||||||
.setContentIntent(pIntent);
|
.setContentIntent(pIntent);
|
||||||
|
|
||||||
Notification notify = NotificationDownloadImages.build();
|
Notification notify = mNotificationDownloadImages.build();
|
||||||
|
|
||||||
//Hide the notification after its selected
|
//Hide the notification after its selected
|
||||||
notify.flags |= Notification.FLAG_AUTO_CANCEL;
|
notify.flags |= Notification.FLAG_AUTO_CANCEL;
|
||||||
|
@ -200,9 +199,11 @@ public class DownloadImagesService extends IntentService {
|
||||||
notificationManager.cancel(NOTIFICATION_ID);
|
notificationManager.cancel(NOTIFICATION_ID);
|
||||||
RemoveOldImages();
|
RemoveOldImages();
|
||||||
} else {
|
} else {
|
||||||
NotificationDownloadImages.setProgress(maxCount, count+1, false);
|
mNotificationDownloadImages
|
||||||
NotificationDownloadImages.setContentText("Downloading Images for offline usage - " + (count+1) + "/" + maxCount);
|
.setContentText("Downloading Images for offline usage - " + (count + 1) + "/" + maxCount)
|
||||||
notificationManager.notify(NOTIFICATION_ID, NotificationDownloadImages.build());
|
.setProgress(maxCount, count + 1, false);
|
||||||
|
|
||||||
|
notificationManager.notify(NOTIFICATION_ID, mNotificationDownloadImages.build());
|
||||||
|
|
||||||
StartNextDownloadInQueue();
|
StartNextDownloadInQueue();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue