Refactorings

This commit is contained in:
Martin Fietz 2015-04-06 18:13:44 +02:00
parent b44e0dde58
commit 76b6ae654b
4 changed files with 62 additions and 72 deletions

View File

@ -29,7 +29,6 @@ import com.squareup.picasso.Picasso;
import org.apache.commons.lang3.StringUtils;
import de.danoeh.antennapod.BuildConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.adapter.ChapterListAdapter;
import de.danoeh.antennapod.adapter.NavListAdapter;
@ -96,30 +95,25 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc
FragmentTransaction fT = getSupportFragmentManager().beginTransaction();
if (coverFragment != null) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Removing cover fragment");
Log.d(TAG, "Removing cover fragment");
fT.remove(coverFragment);
}
if (descriptionFragment != null) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Removing description fragment");
Log.d(TAG, "Removing description fragment");
fT.remove(descriptionFragment);
}
if (chapterFragment != null) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Removing chapter fragment");
Log.d(TAG, "Removing chapter fragment");
fT.remove(chapterFragment);
}
if (currentlyShownFragment != null) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Removing currently shown fragment");
Log.d(TAG, "Removing currently shown fragment");
fT.remove(currentlyShownFragment);
}
for (int i = 0; i < detachedFragments.length; i++) {
Fragment f = detachedFragments[i];
if (f != null) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Removing detached fragment");
Log.d(TAG, "Removing detached fragment");
fT.remove(f);
}
}
@ -152,8 +146,7 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc
}
private void savePreferences() {
if (BuildConfig.DEBUG)
Log.d(TAG, "Saving preferences");
Log.d(TAG, "Saving preferences");
SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
if (currentlyShownPosition >= 0 && controller != null
@ -180,9 +173,7 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc
@Override
protected void onSaveInstanceState(Bundle outState) {
// super.onSaveInstanceState(outState); would cause crash
if (BuildConfig.DEBUG)
Log.d(TAG, "onSaveInstanceState");
Log.d(TAG, "onSaveInstanceState");
}
@Override
@ -205,8 +196,7 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc
* @return true if restoreFromPrefernces changed the activity's state
*/
private boolean restoreFromPreferences() {
if (BuildConfig.DEBUG)
Log.d(TAG, "Restoring instance state");
Log.d(TAG, "Restoring instance state");
SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE);
int savedPosition = prefs.getInt(PREF_KEY_SELECTED_FRAGMENT_POSITION,
-1);
@ -220,15 +210,10 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc
switchToFragment(savedPosition);
return true;
} else if (controller == null || controller.getMedia() == null) {
if (BuildConfig.DEBUG)
Log.d(TAG,
"Couldn't restore from preferences: controller or media was null");
Log.d(TAG, "Couldn't restore from preferences: controller or media was null");
} else {
if (BuildConfig.DEBUG)
Log.d(TAG,
"Couldn't restore from preferences: savedPosition was -1 or saved identifier and playable identifier didn't match.\nsavedPosition: "
+ savedPosition + ", id: " + playableId
);
Log.d(TAG, "Couldn't restore from preferences: savedPosition was -1 or saved identifier and playable identifier didn't match.\nsavedPosition: "
+ savedPosition + ", id: " + playableId);
}
return false;
@ -239,9 +224,7 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc
super.onResume();
if (StringUtils.equals(getIntent().getAction(), Intent.ACTION_VIEW)) {
Intent intent = getIntent();
if (BuildConfig.DEBUG)
Log.d(TAG, "Received VIEW intent: "
+ intent.getData().getPath());
Log.d(TAG, "Received VIEW intent: " + intent.getData().getPath());
ExternalMedia media = new ExternalMedia(intent.getData().getPath(),
MediaType.AUDIO);
Intent launchIntent = new Intent(this, PlaybackService.class);
@ -269,8 +252,7 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc
@Override
protected void onAwaitingVideoSurface() {
if (BuildConfig.DEBUG)
Log.d(TAG, "onAwaitingVideoSurface was called in audio player -> switching to video player");
Log.d(TAG, "onAwaitingVideoSurface was called in audio player -> switching to video player");
startActivity(new Intent(this, VideoplayerActivity.class));
}
@ -295,8 +277,7 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc
* @param pos Must be POS_COVER, POS_DESCR, or POS_CHAPTERS
*/
private void switchToFragment(int pos) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Switching contentView to position " + pos);
Log.d(TAG, "Switching contentView to position " + pos);
if (currentlyShownPosition != pos && controller != null) {
Playable media = controller.getMedia();
if (media != null) {
@ -354,9 +335,7 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc
lastShownPosition = currentlyShownPosition;
currentlyShownPosition = pos;
if (detachedFragments[pos] != null) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Reattaching fragment at position "
+ pos);
Log.d(TAG, "Reattaching fragment at position " + pos);
ft.attach(detachedFragments[pos]);
} else {
ft.add(R.id.contentView, currentlyShownFragment);
@ -630,9 +609,7 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc
@Override
protected void onReloadNotification(int notificationCode) {
if (notificationCode == PlaybackService.EXTRA_CODE_VIDEO) {
if (BuildConfig.DEBUG)
Log.d(TAG,
"ReloadNotification received, switching to Videoplayer now");
Log.d(TAG, "ReloadNotification received, switching to Videoplayer now");
finish();
startActivity(new Intent(this, VideoplayerActivity.class));
@ -729,8 +706,7 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc
@Override
public void update(EventDistributor eventDistributor, Integer arg) {
if ((EventDistributor.FEED_LIST_UPDATE & arg) != 0) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Received contentUpdate Intent.");
Log.d(TAG, "Received contentUpdate Intent.");
loadData();
}
}

View File

@ -14,13 +14,13 @@
package com.aocate.media;
import java.io.IOException;
import android.content.Context;
import android.media.MediaPlayer;
import android.net.Uri;
import android.util.Log;
import java.io.IOException;
public class AndroidMediaPlayer extends MediaPlayerImpl {
private final static String AMP_TAG = "AocateAndroidMediaPlayer";

View File

@ -58,7 +58,8 @@ public class UserPreferences implements
private static final String PREF_PLAYBACK_SPEED = "prefPlaybackSpeed";
private static final String PREF_PLAYBACK_SPEED_ARRAY = "prefPlaybackSpeedArray";
public static final String PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS = "prefPauseForFocusLoss";
private static final String PREF_SEEK_DELTA_SECS = "prefSeekDeltaSecs";
private static final String PREF_FAST_FORWARD_SECS = "prefFastForwardSecs";
private static final String PREF_REWIND_SECS = "prefRewindSecs";
private static final String PREF_EXPANDED_NOTIFICATION = "prefExpandNotify";
private static final String PREF_PERSISTENT_NOTIFICATION = "prefPersistNotify";
public static final String PREF_QUEUE_ADD_TO_FRONT = "prefQueueAddToFront";
@ -93,7 +94,8 @@ public class UserPreferences implements
private String playbackSpeed;
private String[] playbackSpeedArray;
private boolean pauseForFocusLoss;
private int seekDeltaSecs;
private int fastForwardSecs;
private int rewindSecs;
private boolean isFreshInstall;
private int notifyPriority;
private boolean persistNotify;
@ -109,8 +111,7 @@ public class UserPreferences implements
* @throws IllegalArgumentException if context is null
*/
public static void createInstance(Context context) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Creating new instance of UserPreferences");
Log.d(TAG, "Creating new instance of UserPreferences");
Validate.notNull(context);
instance = new UserPreferences(context);
@ -157,7 +158,8 @@ public class UserPreferences implements
playbackSpeedArray = readPlaybackSpeedArray(sp.getString(
PREF_PLAYBACK_SPEED_ARRAY, null));
pauseForFocusLoss = sp.getBoolean(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, false);
seekDeltaSecs = Integer.valueOf(sp.getString(PREF_SEEK_DELTA_SECS, "30"));
fastForwardSecs = sp.getInt(PREF_FAST_FORWARD_SECS, 30);
rewindSecs = sp.getInt(PREF_REWIND_SECS, 30);
if (sp.getBoolean(PREF_EXPANDED_NOTIFICATION, false)) {
notifyPriority = NotificationCompat.PRIORITY_MAX;
}
@ -343,9 +345,14 @@ public class UserPreferences implements
return instance.playbackSpeedArray;
}
public static int getSeekDeltaMs() {
public static int getFastFowardSecs() {
instanceAvailable();
return 1000 * instance.seekDeltaSecs;
return instance.fastForwardSecs;
}
public static int getRewindSecs() {
instanceAvailable();
return instance.rewindSecs;
}
/**
@ -429,8 +436,10 @@ public class UserPreferences implements
PREF_PLAYBACK_SPEED_ARRAY, null));
} else if (key.equals(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS)) {
pauseForFocusLoss = sp.getBoolean(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, false);
} else if (key.equals(PREF_SEEK_DELTA_SECS)) {
seekDeltaSecs = Integer.valueOf(sp.getString(PREF_SEEK_DELTA_SECS, "30"));
} else if (key.equals(PREF_FAST_FORWARD_SECS)) {
fastForwardSecs = sp.getInt(PREF_FAST_FORWARD_SECS, 30);
} else if (key.equals(PREF_REWIND_SECS)) {
rewindSecs = sp.getInt(PREF_REWIND_SECS, 30);
} else if (key.equals(PREF_PAUSE_ON_HEADSET_DISCONNECT)) {
pauseOnHeadsetDisconnect = sp.getBoolean(PREF_PAUSE_ON_HEADSET_DISCONNECT, true);
} else if (key.equals(PREF_UNPAUSE_ON_HEADSET_RECONNECT)) {
@ -450,6 +459,18 @@ public class UserPreferences implements
}
}
public static void setPrefFastForwardSecs(int secs) {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(instance.context).edit();
editor.putInt(PREF_FAST_FORWARD_SECS, secs);
editor.commit();
}
public static void setPrefRewindSecs(int secs) {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(instance.context).edit();
editor.putInt(PREF_REWIND_SECS, secs);
editor.commit();
}
public static void setPlaybackSpeed(String speed) {
PreferenceManager.getDefaultSharedPreferences(instance.context).edit()
.putString(PREF_PLAYBACK_SPEED, speed).apply();
@ -524,8 +545,7 @@ public class UserPreferences implements
.getDefaultSharedPreferences(context.getApplicationContext());
String strDir = prefs.getString(PREF_DATA_FOLDER, null);
if (strDir == null) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Using default data folder");
Log.d(TAG, "Using default data folder");
return context.getExternalFilesDir(type);
} else {
File dataDir = new File(strDir);
@ -556,8 +576,7 @@ public class UserPreferences implements
if (!typeDir.exists()) {
if (dataDir.canWrite()) {
if (!typeDir.mkdir()) {
Log.e(TAG, "Could not create data folder named "
+ type);
Log.e(TAG, "Could not create data folder named " + type);
return null;
}
}
@ -569,8 +588,7 @@ public class UserPreferences implements
}
public static void setDataFolder(String dir) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Result from DirectoryChooser: " + dir);
Log.d(TAG, "Result from DirectoryChooser: " + dir);
instanceAvailable();
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(instance.context);
@ -607,16 +625,13 @@ public class UserPreferences implements
IMPORT_DIR);
if (importDir != null) {
if (importDir.exists()) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Import directory already exists");
Log.d(TAG, "Import directory already exists");
} else {
if (BuildConfig.DEBUG)
Log.d(TAG, "Creating import directory");
Log.d(TAG, "Creating import directory");
importDir.mkdir();
}
} else {
if (BuildConfig.DEBUG)
Log.d(TAG, "Could not access external storage.");
Log.d(TAG, "Could not access external storage.");
}
}
@ -625,8 +640,7 @@ public class UserPreferences implements
*/
public static void restartUpdateAlarm(long triggerAtMillis, long intervalMillis) {
instanceAvailable();
if (BuildConfig.DEBUG)
Log.d(TAG, "Restarting update alarm.");
Log.d(TAG, "Restarting update alarm.");
AlarmManager alarmManager = (AlarmManager) instance.context
.getSystemService(Context.ALARM_SERVICE);
PendingIntent updateIntent = PendingIntent.getBroadcast(
@ -635,11 +649,9 @@ public class UserPreferences implements
if (intervalMillis != 0) {
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, triggerAtMillis, intervalMillis,
updateIntent);
if (BuildConfig.DEBUG)
Log.d(TAG, "Changed alarm to new interval");
Log.d(TAG, "Changed alarm to new interval");
} else {
if (BuildConfig.DEBUG)
Log.d(TAG, "Automatic update was deactivated");
Log.d(TAG, "Automatic update was deactivated");
}
}

View File

@ -19,8 +19,10 @@ import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.QueueEvent;
import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.util.playback.Playable;
import de.greenrobot.event.EventBus;
/**
* Manages the background tasks of PlaybackSerivce, i.e.
* the sleep timer, the position saver, the widget updater and
@ -147,9 +149,9 @@ public class PlaybackServiceTaskManager {
positionSaverFuture = schedExecutor.scheduleWithFixedDelay(positionSaver, POSITION_SAVER_WAITING_INTERVAL,
POSITION_SAVER_WAITING_INTERVAL, TimeUnit.MILLISECONDS);
if (BuildConfig.DEBUG) Log.d(TAG, "Started PositionSaver");
Log.d(TAG, "Started PositionSaver");
} else {
if (BuildConfig.DEBUG) Log.d(TAG, "Call to startPositionSaver was ignored.");
Log.d(TAG, "Call to startPositionSaver was ignored.");
}
}