Merge pull request #3284 from ByteHamster/default-exoplayer

Make ExoPlayer the default player
This commit is contained in:
H. Lehmann 2019-07-23 22:11:48 +02:00 committed by GitHub
commit f7251af8be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 89 deletions

View File

@ -208,7 +208,6 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi
checkFirstLaunch();
PreferenceUpgrader.checkUpgrades(this);
NotificationUtils.createChannels(this);
}
private void saveLastNavFragment(String tag) {

View File

@ -2,28 +2,51 @@ package de.danoeh.antennapod.preferences;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import de.danoeh.antennapod.BuildConfig;
import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.util.gui.NotificationUtils;
public class PreferenceUpgrader {
private static final String PREF_CONFIGURED_VERSION = "configuredVersion";
private static final String PREF_NAME = "PreferenceUpgrader";
private static SharedPreferences prefs;
public static void checkUpgrades(Context context) {
SharedPreferences prefs = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
int oldVersion = prefs.getInt(PREF_CONFIGURED_VERSION, 1070200);
prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences upgraderPrefs = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
int oldVersion = upgraderPrefs.getInt(PREF_CONFIGURED_VERSION, 1070200);
int newVersion = BuildConfig.VERSION_CODE;
if (oldVersion != newVersion) {
prefs.edit().putInt(PREF_CONFIGURED_VERSION, newVersion).apply();
NotificationUtils.createChannels(context);
upgraderPrefs.edit().putInt(PREF_CONFIGURED_VERSION, newVersion).apply();
upgrade(oldVersion);
}
}
private static void upgrade(int oldVersion) {
if (oldVersion < 1070196) {
// migrate episode cleanup value (unit changed from days to hours)
int oldValueInDays = UserPreferences.getEpisodeCleanupValue();
if (oldValueInDays > 0) {
UserPreferences.setEpisodeCleanupValue(oldValueInDays * 24);
} // else 0 or special negative values, no change needed
}
if (oldVersion < 1070197) {
if (prefs.getBoolean("prefMobileUpdate", false)) {
prefs.edit().putString(UserPreferences.PREF_MOBILE_UPDATE, "everything").apply();
}
}
if (oldVersion < 1070300) {
UserPreferences.restartUpdateAlarm();
if (UserPreferences.getMediaPlayer().equals("builtin")) {
prefs.edit().putString(UserPreferences.PREF_MEDIA_PLAYER,
UserPreferences.PREF_MEDIA_PLAYER_EXOPLAYER).apply();
}
}
}
}

View File

@ -115,7 +115,7 @@
<PreferenceCategory android:title="@string/media_player">
<ListPreference
android:defaultValue="sonic"
android:defaultValue="exoplayer"
android:entries="@array/media_player_options"
android:key="prefMediaPlayer"
android:title="@string/media_player"

View File

@ -1,81 +0,0 @@
package de.danoeh.antennapod.core;
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 de.danoeh.antennapod.core.preferences.UserPreferences;
/*
* This class's job is do perform maintenance tasks whenever the app has been updated
*/
class UpdateManager {
private UpdateManager(){}
private 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();
}
}
private static int getStoredVersionCode() {
return prefs.getInt(KEY_VERSION_CODE, -1);
}
private static void setCurrentVersionCode() {
prefs.edit().putInt(KEY_VERSION_CODE, currentVersionCode).apply();
}
private static void onUpgrade(final int oldVersionCode, final int newVersionCode) {
if (oldVersionCode < 1050004) {
if(MediaPlayer.isPrestoLibraryInstalled(context) && Build.VERSION.SDK_INT >= 16) {
UserPreferences.enableSonic();
}
}
if (oldVersionCode < 1070196) {
// migrate episode cleanup value (unit changed from days to hours)
int oldValueInDays = UserPreferences.getEpisodeCleanupValue();
if (oldValueInDays > 0) {
UserPreferences.setEpisodeCleanupValue(oldValueInDays * 24);
} // else 0 or special negative values, no change needed
}
if (oldVersionCode < 1070197) {
if (prefs.getBoolean("prefMobileUpdate", false)) {
prefs.edit().putString(UserPreferences.PREF_MOBILE_UPDATE, "everything").apply();
}
}
}
}

View File

@ -647,12 +647,16 @@ public class UserPreferences {
return selectedSpeeds;
}
public static String getMediaPlayer() {
return prefs.getString(PREF_MEDIA_PLAYER, PREF_MEDIA_PLAYER_EXOPLAYER);
}
public static boolean useSonic() {
return prefs.getString(PREF_MEDIA_PLAYER, "sonic").equals("sonic");
return getMediaPlayer().equals("sonic");
}
public static boolean useExoplayer() {
return prefs.getString(PREF_MEDIA_PLAYER, "sonic").equals(PREF_MEDIA_PLAYER_EXOPLAYER);
return getMediaPlayer().equals(PREF_MEDIA_PLAYER_EXOPLAYER);
}
public static void enableSonic() {

View File

@ -41,7 +41,6 @@ public class ClientConfig {
}
PodDBAdapter.init(context);
UserPreferences.init(context);
UpdateManager.init(context);
PlaybackPreferences.init(context);
NetworkUtils.init(context);
CastManager.init(context);