blob: 0b3c4338183c6d6845970bea9812594a9bc8107f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
package de.danoeh.antennapod;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.util.Log;
import org.antennapod.audio.MediaPlayer;
import java.io.File;
import java.util.List;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.feed.FeedImage;
import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBWriter;
/*
* This class's job is do perform maintenance tasks whenever the app has been updated
*/
public class UpdateManager {
public static final String TAG = UpdateManager.class.getSimpleName();
private static final String PREF_NAME = "app_version";
private static final String KEY_VERSION_CODE = "version_code";
private static int currentVersionCode;
private static Context context;
private static SharedPreferences prefs;
public static void init(Context context) {
UpdateManager.context = context;
prefs = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
PackageManager pm = context.getPackageManager();
try {
PackageInfo info = pm.getPackageInfo(context.getPackageName(), 0);
currentVersionCode = info.versionCode;
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Failed to obtain package info for package name: " + context.getPackageName(), e);
currentVersionCode = 0;
return;
}
final int oldVersionCode = getStoredVersionCode();
Log.d(TAG, "old: " + oldVersionCode + ", current: " + currentVersionCode);
if(oldVersionCode < currentVersionCode) {
onUpgrade(oldVersionCode, currentVersionCode);
setCurrentVersionCode();
}
}
public static int getStoredVersionCode() {
return prefs.getInt(KEY_VERSION_CODE, -1);
}
public static void setCurrentVersionCode() {
prefs.edit().putInt(KEY_VERSION_CODE, currentVersionCode).apply();
}
private static void onUpgrade(final int oldVersionCode, final int newVersionCode) {
if(oldVersionCode < 1030099) {
// delete the now obsolete image cache
// from now on, Glide will handle caching images
new Thread() {
public void run() {
List<Feed> feeds = DBReader.getFeedList();
for (Feed podcast : feeds) {
List<FeedItem> episodes = DBReader.getFeedItemList(podcast);
for (FeedItem episode : episodes) {
FeedImage image = episode.getImage();
if (image != null && image.isDownloaded() && image.getFile_url() != null) {
File imageFile = new File(image.getFile_url());
if (imageFile.exists()) {
imageFile.delete();
}
image.setFile_url(null); // calls setDownloaded(false)
DBWriter.setFeedImage(image);
}
}
}
}
}.start();
}
if(oldVersionCode < 1050004) {
if(MediaPlayer.isPrestoLibraryInstalled(context) && Build.VERSION.SDK_INT >= 16) {
UserPreferences.enableSonic(true);
}
}
}
}
|