Skip to content

Commit b809eb0

Browse files
Update to 0.5.2
1 parent 663d4ea commit b809eb0

File tree

7 files changed

+168
-93
lines changed

7 files changed

+168
-93
lines changed

AndroidManifest.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="de.luhmer.owncloudnewsreader"
4-
android:versionCode="36"
5-
android:versionName="0.5.1" >
4+
android:versionCode="37"
5+
android:versionName="0.5.2" >
66

77
<uses-sdk
88
android:minSdkVersion="7"

News-Android-App.apk

22.8 KB
Binary file not shown.

README.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,26 @@ How to compile the App
4949
==================================
5050
Requirements:
5151
-----------------------
52-
>1) Eclipse + ADT Plugin + Android SDK installed
52+
>1) Eclipse + ADT Plugin + Android SDK installed or Android Studio
5353
>2) Git installed (you can do the following stuff without git but I'm not going to show how).
5454
5555
Download and install:
5656
-----------------------
57-
>1) Open cmd/terminal
57+
>1) Open cmd/terminal
5858
>2) Navigate to your workspace
59-
>3) Then type in:
59+
>3) Then type in:
6060
><pre>
6161
git clone https://github.com/JakeWharton/ActionBarSherlock.git
6262
git clone https://github.com/David-Development/Android-PullToRefresh.git
6363
git clone https://github.com/owncloud/News-Android-App.git
64+
git clone https://github.com/gabrielemariotti/changeloglib.git
65+
git clone https://github.com/MichaelFlisar/MessageBar.git
6466
></pre>
6567
6668
>Go to Eclipse and do the following:
6769
>--> File --> Import --> Android Project from Exsisting Source --> [...]/ActionBarSherlock/actionbarsherlock
6870
>--> File --> Import --> Android Project from Exsisting Source --> [...]/Android-PullToRefresh/library
69-
>--> File --> Import --> Android Project from Exsisting Source --> [...]/News-Android-App
71+
... for all other Dependencies the same ...
7072

7173

7274
>Then make a right click on the News-Android-App Project and select "Properties". Select the tab "Android". In this Window you should see the Project Build Target at the top and Libarys at the buttom of the window. Two of them are maybe marked with a read cross. So remove them and add the ActionBarSherlock and the Android PullToRefresh Libary
@@ -87,6 +89,7 @@ Updates
8789
---------------------
8890
- Improvement - Notification when background sync is enabled and new items are received
8991
- Improvement - Fix high CPU-Load in Detail-View
92+
- Improvement - Speed up image caching
9093

9194
0.5.0 (Google Play)
9295
---------------------

src/de/luhmer/owncloudnewsreader/async_tasks/GetImageAsyncTask.java

+9-36
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ public class GetImageAsyncTask extends AsyncTask<Void, Void, String>
5353
{
5454
//private static final String TAG = "GetImageAsyncTask";
5555

56-
private static int count = 0;
56+
//private static int count = 0;
5757

5858
private URL WEB_URL_TO_FILE;
5959
private ImageDownloadFinished imageDownloadFinished;
60-
private int AsynkTaskId;
60+
private int AsyncTaskId;
6161
private String rootPath;
6262
private Context cont;
6363

@@ -66,7 +66,7 @@ public class GetImageAsyncTask extends AsyncTask<Void, Void, String>
6666
public String feedID = null;
6767
public boolean scaleImage = false;
6868
public int dstHeight; // height in pixels
69-
public int dstWidth; // width in pixels
69+
public int dstWidth; // width in pixels
7070

7171
//private ImageView imgView;
7272
//private WeakReference<ImageView> imageViewReference;
@@ -83,15 +83,15 @@ public GetImageAsyncTask(String WEB_URL_TO_FILE, ImageDownloadFinished imgDownlo
8383
this.lruCache = lruCache;
8484
this.cont = cont;
8585
imageDownloadFinished = imgDownloadFinished;
86-
this.AsynkTaskId = AsynkTaskId;
86+
this.AsyncTaskId = AsynkTaskId;
8787
this.rootPath = rootPath;
8888
//this.imageViewReference = new WeakReference<ImageView>(imageView);
8989
}
9090

9191
@Override
9292
protected void onPostExecute(String result) {
9393
if(imageDownloadFinished != null)
94-
imageDownloadFinished.DownloadFinished(AsynkTaskId, result, lruCache);
94+
imageDownloadFinished.DownloadFinished(AsyncTaskId, result, lruCache);
9595
//imgView.setImageDrawable(GetFavIconFromCache(WEB_URL_TO_FILE.toString(), context));
9696
super.onPostExecute(result);
9797
}
@@ -102,12 +102,12 @@ protected void onPostExecute(String result) {
102102
protected String doInBackground(Void... params) {
103103
try
104104
{
105-
File cacheFile = ImageHandler.getFullPathOfCacheFile(WEB_URL_TO_FILE.toString(), rootPath);
105+
File cacheFile = ImageHandler.getFullPathOfCacheFile(WEB_URL_TO_FILE.toString(), rootPath);
106106
if(!cacheFile.isFile())
107107
{
108108
File dir = new File(rootPath);
109109
dir.mkdirs();
110-
cacheFile = ImageHandler.getFullPathOfCacheFile(WEB_URL_TO_FILE.toString(), rootPath);
110+
cacheFile = ImageHandler.getFullPathOfCacheFile(WEB_URL_TO_FILE.toString(), rootPath);
111111
//cacheFile.createNewFile();
112112

113113

@@ -161,6 +161,7 @@ protected String doInBackground(Void... params) {
161161
fOut.close();
162162
*/
163163

164+
/*
164165
count++;
165166
if(count >= 25)//Check every 25 images the cache size
166167
{
@@ -188,7 +189,7 @@ protected String doInBackground(Void... params) {
188189
break;
189190
}
190191
}
191-
}
192+
} */
192193
}
193194
return cacheFile.getPath();
194195
}
@@ -200,33 +201,5 @@ protected String doInBackground(Void... params) {
200201
}
201202

202203

203-
@SuppressWarnings({ "rawtypes", "unchecked" })
204-
public static LinkedHashMap sortHashMapByValuesD(HashMap passedMap) {
205-
List mapKeys = new ArrayList(passedMap.keySet());
206-
List mapValues = new ArrayList(passedMap.values());
207-
Collections.sort(mapValues);
208-
Collections.sort(mapKeys);
209-
210-
LinkedHashMap sortedMap = new LinkedHashMap();
211-
212-
Iterator valueIt = mapValues.iterator();
213-
while (valueIt.hasNext()) {
214-
Object val = valueIt.next();
215-
Iterator keyIt = mapKeys.iterator();
216-
217-
while (keyIt.hasNext()) {
218-
Object key = keyIt.next();
219-
String comp1 = passedMap.get(key).toString();
220-
String comp2 = val.toString();
221204

222-
if (comp1.equals(comp2)){
223-
passedMap.remove(key);
224-
mapKeys.remove(key);
225-
sortedMap.put((String)key, (Double)val);
226-
break;
227-
}
228-
}
229-
}
230-
return sortedMap;
231-
}
232205
}

src/de/luhmer/owncloudnewsreader/services/DownloadImagesService.java

+82-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121

2222
package de.luhmer.owncloudnewsreader.services;
2323

24+
import java.io.File;
2425
import java.util.ArrayList;
26+
import java.util.Collections;
27+
import java.util.HashMap;
28+
import java.util.Iterator;
29+
import java.util.LinkedHashMap;
2530
import java.util.List;
2631
import java.util.Random;
2732

@@ -31,10 +36,13 @@
3136
import android.app.PendingIntent;
3237
import android.content.Context;
3338
import android.content.Intent;
39+
import android.content.SharedPreferences;
3440
import android.database.Cursor;
41+
import android.preference.PreferenceManager;
3542
import android.support.v4.app.NotificationCompat;
3643
import de.luhmer.owncloudnewsreader.NewsReaderListActivity;
3744
import de.luhmer.owncloudnewsreader.R;
45+
import de.luhmer.owncloudnewsreader.SettingsActivity;
3846
import de.luhmer.owncloudnewsreader.async_tasks.GetImageAsyncTask;
3947
import de.luhmer.owncloudnewsreader.database.DatabaseConnection;
4048
import de.luhmer.owncloudnewsreader.helper.BitmapDrawableLruCache;
@@ -51,10 +59,10 @@ public class DownloadImagesService extends IntentService {
5159
private NotificationCompat.Builder NotificationDownloadImages;
5260
private int count;
5361
private int maxCount;
54-
62+
//private int total_size = 0;
5563

5664
public DownloadImagesService() {
57-
super(null);
65+
super(null);
5866
initService();
5967
}
6068

@@ -128,17 +136,83 @@ protected void onHandleIntent(Intent intent) {
128136
notify.flags |= Notification.FLAG_AUTO_CANCEL;
129137
//notify.flags |= Notification.FLAG_NO_CLEAR;
130138

131-
if(maxCount > 0)
139+
if(maxCount > 0)
132140
notificationManager.notify(NOTIFICATION_ID, notify);
133141

134-
for(String link : links)
142+
for(String link : links)
135143
new GetImageAsyncTask(link, imgDownloadFinished, 999, ImageHandler.getPathImageCache(this), this, null).execute();
136144
}
145+
146+
private void RemoveOldImages(Context context) {
147+
HashMap<File, Long> files;
148+
long size = ImageHandler.getFolderSize(new File(ImageHandler.getPath(context)));
149+
size = (long) (size / 1024d / 1024d);
150+
151+
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
152+
int max_allowed_size = Integer.parseInt(mPrefs.getString(SettingsActivity.SP_MAX_CACHE_SIZE, "1000"));//Default is 1Gb --> 1000mb
153+
if(size > max_allowed_size)
154+
{
155+
files = new HashMap<File, Long>();
156+
for(File file : ImageHandler.getFilesFromDir(new File(ImageHandler.getPathImageCache(context))))
157+
{
158+
files.put(file, file.lastModified());
159+
}
160+
161+
for(Object itemObj : sortHashMapByValuesD(files).entrySet())
162+
{
163+
File file = (File) itemObj;
164+
file.delete();
165+
size -= file.length();
166+
if(size < max_allowed_size)
167+
break;
168+
}
169+
}
170+
}
171+
172+
@SuppressWarnings({ "rawtypes", "unchecked" })
173+
public static LinkedHashMap sortHashMapByValuesD(HashMap passedMap) {
174+
List mapKeys = new ArrayList(passedMap.keySet());
175+
List mapValues = new ArrayList(passedMap.values());
176+
Collections.sort(mapValues);
177+
Collections.sort(mapKeys);
178+
179+
LinkedHashMap sortedMap = new LinkedHashMap();
180+
181+
Iterator valueIt = mapValues.iterator();
182+
while (valueIt.hasNext()) {
183+
Object val = valueIt.next();
184+
Iterator keyIt = mapKeys.iterator();
185+
186+
while (keyIt.hasNext()) {
187+
Object key = keyIt.next();
188+
String comp1 = passedMap.get(key).toString();
189+
String comp2 = val.toString();
190+
191+
if (comp1.equals(comp2)){
192+
passedMap.remove(key);
193+
mapKeys.remove(key);
194+
sortedMap.put((String)key, (Double)val);
195+
break;
196+
}
197+
}
198+
}
199+
return sortedMap;
200+
}
137201

138202
ImageDownloadFinished imgDownloadFinished = new ImageDownloadFinished() {
139203

140204
@Override
141205
public void DownloadFinished(int AsynkTaskId, String fileCachePath, BitmapDrawableLruCache lruCache) {
206+
207+
if(fileCachePath != null) {
208+
File file = new File(fileCachePath);
209+
long size = file.length();
210+
//total_size += size;
211+
if(size == 0)
212+
file.delete();
213+
}
214+
215+
142216
count++;
143217
// Sets the progress indicator to a max value, the
144218
// current completion percentage, and "determinate"
@@ -148,8 +222,11 @@ public void DownloadFinished(int AsynkTaskId, String fileCachePath, BitmapDrawab
148222
// Displays the progress bar for the first time.
149223
notificationManager.notify(NOTIFICATION_ID, NotificationDownloadImages.build());
150224

151-
if(maxCount == count)
225+
if(maxCount == count) {
152226
notificationManager.cancel(NOTIFICATION_ID);
227+
if(DownloadImagesService.this != null)
228+
RemoveOldImages(DownloadImagesService.this);
229+
}
153230
}
154231
};
155232
}

src/de/luhmer/owncloudnewsreader/services/OwnCloudSyncService.java

+24-8
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import android.app.ActivityManager;
2828
import android.app.Service;
29+
import android.appwidget.AppWidgetManager;
2930
import android.content.ComponentName;
3031
import android.content.Intent;
3132
import android.content.SharedPreferences;
@@ -46,6 +47,7 @@
4647
import de.luhmer.owncloudnewsreader.reader.owncloud.API;
4748
import de.luhmer.owncloudnewsreader.reader.owncloud.OwnCloud_Reader;
4849
import de.luhmer.owncloudnewsreader.services.IOwnCloudSyncService.Stub;
50+
import de.luhmer.owncloudnewsreader.widget.WidgetProvider;
4951

5052
public class OwnCloudSyncService extends Service {
5153

@@ -188,19 +190,20 @@ public void onAsyncTaskCompleted(int task_id, Object task_result) {
188190
ThrowException((Exception) task_result);
189191
else
190192
{
191-
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
192-
List<ActivityManager.RunningTaskInfo> runningTaskInfo = am.getRunningTasks(1);
193+
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(OwnCloudSyncService.this);
194+
int newItemsCount = mPrefs.getInt(Constants.LAST_UPDATE_NEW_ITEMS_COUNT_STRING, 0);
195+
if(newItemsCount > 0) {
196+
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
197+
List<ActivityManager.RunningTaskInfo> runningTaskInfo = am.getRunningTasks(1);
193198

194-
ComponentName componentInfo = runningTaskInfo.get(0).topActivity;
195-
if(!componentInfo.getPackageName().equals("de.luhmer.owncloudnewsreader")) {
196-
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(OwnCloudSyncService.this);
197-
int newItemsCount = mPrefs.getInt(Constants.LAST_UPDATE_NEW_ITEMS_COUNT_STRING, 0);
198-
if(newItemsCount > 0) {
199+
ComponentName componentInfo = runningTaskInfo.get(0).topActivity;
200+
if(!componentInfo.getPackageName().equals("de.luhmer.owncloudnewsreader")) {
199201
String tickerText = getString(R.string.notification_new_items_ticker).replace("X", String.valueOf(newItemsCount));
200202
String contentText = getString(R.string.notification_new_items_text).replace("X", String.valueOf(newItemsCount));
201203
String title = getString(R.string.app_name);
202204
NotificationManagerNewsReader.getInstance(OwnCloudSyncService.this).ShowMessage(title, tickerText, contentText);
203205
}
206+
UpdateWidget();
204207
}
205208
}
206209

@@ -209,7 +212,20 @@ public void onAsyncTaskCompleted(int task_id, Object task_result) {
209212

210213
}
211214
};
212-
215+
216+
private void UpdateWidget()
217+
{
218+
Intent intent = new Intent(this, WidgetProvider.class);
219+
intent.setAction("android.appwidget.action.APPWIDGET_UPDATE");
220+
// Use an array and EXTRA_APPWIDGET_IDS instead of AppWidgetManager.EXTRA_APPWIDGET_ID,
221+
// since it seems the onUpdate() is only fired on that:
222+
223+
int ids[] = AppWidgetManager.getInstance(getApplication()).getAppWidgetIds(new ComponentName(getApplication(), WidgetProvider.class));
224+
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS,ids);
225+
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,ids);
226+
sendBroadcast(intent);
227+
}
228+
213229
private void ThrowException(Exception ex) {
214230
List<IOwnCloudSyncServiceCallback> callbackList = getCallBackItemsAndBeginBroadcast();
215231
for (IOwnCloudSyncServiceCallback icb : callbackList) {

0 commit comments

Comments
 (0)