aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java20
-rw-r--r--src/main/java/de/pixart/messenger/utils/RichPreview.java15
2 files changed, 21 insertions, 14 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index 539f89553..b57d9846f 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -66,6 +66,7 @@ import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
+import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
@@ -169,6 +170,7 @@ import static de.pixart.messenger.ui.SettingsActivity.CONFIRM_MESSAGES;
import static de.pixart.messenger.ui.SettingsActivity.ENABLE_MULTI_ACCOUNTS;
import static de.pixart.messenger.ui.SettingsActivity.INDICATE_RECEIVED;
import static de.pixart.messenger.ui.SettingsActivity.SHOW_OWN_ACCOUNTS;
+import static de.pixart.messenger.utils.RichPreview.RICH_LINK_METADATA;
public class XmppConnectionService extends Service {
@@ -757,10 +759,28 @@ public class XmppConnectionService extends Service {
}
if (SystemClock.elapsedRealtime() - mLastExpiryRun.get() >= Config.EXPIRY_INTERVAL) {
expireOldMessages();
+ deleteWebpreviewCache();
}
return START_STICKY;
}
+ private void deleteWebpreviewCache() {
+ final String path = getApplicationContext().getCacheDir() + "/" + RICH_LINK_METADATA;
+ final Calendar time = Calendar.getInstance();
+ time.add(Calendar.DAY_OF_YEAR, -7);
+ final File directory = new File(path);
+ final File[] files = directory.listFiles();
+ int count = 0;
+ for (File file : files) {
+ Date lastModified = new Date(file.lastModified());
+ if (lastModified.before(time.getTime())) {
+ file.delete();
+ count++;
+ }
+ }
+ Log.d(Config.LOGTAG, "Deleted " + count + " old webpreview cache files");
+ }
+
private boolean processAccountState(Account account, boolean interactive, boolean isUiAction, boolean isAccountPushed, HashSet<Account> pingCandidates) {
storeNumberOfAccounts(this.getAccounts().size());
boolean pingNow = false;
diff --git a/src/main/java/de/pixart/messenger/utils/RichPreview.java b/src/main/java/de/pixart/messenger/utils/RichPreview.java
index d0ced8233..1f9c58b80 100644
--- a/src/main/java/de/pixart/messenger/utils/RichPreview.java
+++ b/src/main/java/de/pixart/messenger/utils/RichPreview.java
@@ -3,7 +3,6 @@ package de.pixart.messenger.utils;
import android.content.Context;
import android.os.AsyncTask;
import android.view.View;
-import android.webkit.URLUtil;
import org.json.JSONObject;
import org.jsoup.Jsoup;
@@ -15,7 +14,6 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
-import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
@@ -23,8 +21,6 @@ import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
-import java.util.Calendar;
-import java.util.Date;
import java.util.regex.Pattern;
import de.pixart.messenger.Config;
@@ -35,7 +31,7 @@ import de.pixart.messenger.Config;
public class RichPreview {
- private static final String RICH_LINK_METADATA = "richlink_meta_data";
+ public static final String RICH_LINK_METADATA = "richlink_meta_data";
private MetaData metaData;
private ResponseListener responseListener;
private String url;
@@ -61,15 +57,6 @@ public class RichPreview {
FileInputStream fis = null;
ObjectInputStream is = null;
final File file = new File(context.getCacheDir(), RICH_LINK_METADATA + "/" + filename);
- if (file.exists()) {
- // todo add this into a cron job
- Calendar time = Calendar.getInstance();
- time.add(Calendar.DAY_OF_YEAR, -7);
- Date lastModified = new Date(file.lastModified());
- if (lastModified.before(time.getTime())) {
- file.delete();
- }
- }
try {
fis = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(fis);