diff options
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod/activity')
14 files changed, 198 insertions, 209 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java index 1b42b274c..041053a25 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AboutActivity.java @@ -75,53 +75,50 @@ public class AboutActivity extends AppCompatActivity { } private void loadAsset(String filename) { - subscription = Observable.create(new Observable.OnSubscribe<String>() { - @Override - public void call(Subscriber<? super String> subscriber) { - InputStream input = null; - try { - TypedArray res = AboutActivity.this.getTheme().obtainStyledAttributes( - new int[] { android.R.attr.textColorPrimary }); - int colorResource = res.getColor(0, 0); - String colorString = String.format("#%06X", 0xFFFFFF & colorResource); - res.recycle(); - input = getAssets().open(filename); - String webViewData = IOUtils.toString(input, Charset.defaultCharset()); - if(!webViewData.startsWith("<!DOCTYPE html>")) { - //webViewData = webViewData.replace("\n\n", "</p><p>"); - webViewData = webViewData.replace("%", "%"); - webViewData = - "<!DOCTYPE html>" + - "<html>" + - "<head>" + - " <meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">" + - " <style type=\"text/css\">" + - " @font-face {" + - " font-family: 'Roboto-Light';" + - " src: url('file:///android_asset/Roboto-Light.ttf');" + - " }" + - " * {" + - " color: %s;" + - " font-family: roboto-Light;" + - " font-size: 8pt;" + - " }" + - " </style>" + - "</head><body><p>" + webViewData + "</p></body></html>"; - webViewData = webViewData.replace("\n", "<br/>"); - depth++; - } else { - depth = 0; - } - webViewData = String.format(webViewData, colorString); - subscriber.onNext(webViewData); - } catch (IOException e) { - subscriber.onError(e); - } finally { - IOUtils.closeQuietly(input); - } - subscriber.onCompleted(); - } - }) + subscription = Observable.create((Observable.OnSubscribe<String>) subscriber -> { + InputStream input = null; + try { + TypedArray res = AboutActivity.this.getTheme().obtainStyledAttributes( + new int[] { android.R.attr.textColorPrimary }); + int colorResource = res.getColor(0, 0); + String colorString = String.format("#%06X", 0xFFFFFF & colorResource); + res.recycle(); + input = getAssets().open(filename); + String webViewData = IOUtils.toString(input, Charset.defaultCharset()); + if(!webViewData.startsWith("<!DOCTYPE html>")) { + //webViewData = webViewData.replace("\n\n", "</p><p>"); + webViewData = webViewData.replace("%", "%"); + webViewData = + "<!DOCTYPE html>" + + "<html>" + + "<head>" + + " <meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">" + + " <style type=\"text/css\">" + + " @font-face {" + + " font-family: 'Roboto-Light';" + + " src: url('file:///android_asset/Roboto-Light.ttf');" + + " }" + + " * {" + + " color: %s;" + + " font-family: roboto-Light;" + + " font-size: 8pt;" + + " }" + + " </style>" + + "</head><body><p>" + webViewData + "</p></body></html>"; + webViewData = webViewData.replace("\n", "<br/>"); + depth++; + } else { + depth = 0; + } + webViewData = String.format(webViewData, colorString); + subscriber.onNext(webViewData); + } catch (IOException e) { + subscriber.onError(e); + } finally { + IOUtils.closeQuietly(input); + } + subscriber.onCompleted(); + }) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java index ca214de9e..123f66661 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java @@ -6,6 +6,7 @@ import android.text.TextUtils; import android.util.Log; import android.view.View; +import java.text.DecimalFormat; import java.util.concurrent.atomic.AtomicBoolean; import de.danoeh.antennapod.core.feed.MediaType; @@ -18,15 +19,18 @@ import de.danoeh.antennapod.dialog.VariableSpeedDialog; * Activity for playing audio files. */ public class AudioplayerActivity extends MediaplayerInfoActivity { - public static final String TAG = "AudioPlayerActivity"; + private static final String TAG = "AudioPlayerActivity"; - private AtomicBoolean isSetup = new AtomicBoolean(false); + private final AtomicBoolean isSetup = new AtomicBoolean(false); @Override protected void onResume() { super.onResume(); if (TextUtils.equals(getIntent().getAction(), Intent.ACTION_VIEW)) { Intent intent = getIntent(); + if (intent.getData() == null) { + return; + } Log.d(TAG, "Received VIEW intent: " + intent.getData().getPath()); ExternalMedia media = new ExternalMedia(intent.getData().getPath(), MediaType.AUDIO); @@ -40,7 +44,8 @@ public class AudioplayerActivity extends MediaplayerInfoActivity { startService(launchIntent); } else if (PlaybackService.isCasting()) { Intent intent = PlaybackService.getPlayerActivityIntent(this); - if (!intent.getComponent().getClassName().equals(AudioplayerActivity.class.getName())) { + if (intent.getComponent() != null && + !intent.getComponent().getClassName().equals(AudioplayerActivity.class.getName())) { saveCurrentFragment(); finish(); startActivity(intent); @@ -95,7 +100,7 @@ public class AudioplayerActivity extends MediaplayerInfoActivity { UserPreferences.setPlaybackSpeed(String.valueOf(speed)); } } - String speedStr = String.format("%.2fx", speed); + String speedStr = new DecimalFormat("0.00x").format(speed); butPlaybackSpeed.setText(speedStr); } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/CastplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/CastplayerActivity.java index a7e9b1e70..871e9c279 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/CastplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/CastplayerActivity.java @@ -13,9 +13,9 @@ import de.danoeh.antennapod.core.service.playback.PlaybackService; * Activity for controlling the remote playback on a Cast device. */ public class CastplayerActivity extends MediaplayerInfoActivity { - public static final String TAG = "CastPlayerActivity"; + private static final String TAG = "CastPlayerActivity"; - private AtomicBoolean isSetup = new AtomicBoolean(false); + private final AtomicBoolean isSetup = new AtomicBoolean(false); @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java index 41b2debdc..e726afaec 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/DownloadAuthenticationActivity.java @@ -3,15 +3,14 @@ package de.danoeh.antennapod.activity; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.support.v7.app.ActionBarActivity; -import android.util.Log; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import org.apache.commons.lang3.Validate; -import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.download.DownloadRequest; @@ -23,8 +22,7 @@ import de.danoeh.antennapod.core.storage.DownloadRequester; * Other arguments are optional. * The activity's result will be the same DownloadRequest with the entered username and password. */ -public class DownloadAuthenticationActivity extends ActionBarActivity { - private static final String TAG = "DownloadAuthenticationActivity"; +public class DownloadAuthenticationActivity extends AppCompatActivity { /** * The download request object that contains information about the resource that requires a username and a password @@ -36,47 +34,39 @@ public class DownloadAuthenticationActivity extends ActionBarActivity { */ public static final String ARG_SEND_TO_DOWNLOAD_REQUESTER_BOOL = "send_to_downloadrequester"; - public static final String RESULT_REQUEST = "request"; + private static final String RESULT_REQUEST = "request"; private EditText etxtUsername; private EditText etxtPassword; - private Button butConfirm; - private Button butCancel; - private TextView txtvDescription; - - private DownloadRequest request; - private boolean sendToDownloadRequester; @Override protected void onCreate(Bundle savedInstanceState) { setTheme(UserPreferences.getTheme()); super.onCreate(savedInstanceState); - getSupportActionBar().hide(); - setContentView(R.layout.download_authentication_activity); + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.hide(); + } + setContentView(R.layout.download_authentication_activity); + TextView txtvDescription = (TextView) findViewById(R.id.txtvDescription); etxtUsername = (EditText) findViewById(R.id.etxtUsername); etxtPassword = (EditText) findViewById(R.id.etxtPassword); - butConfirm = (Button) findViewById(R.id.butConfirm); - butCancel = (Button) findViewById(R.id.butCancel); - txtvDescription = (TextView) findViewById(R.id.txtvDescription); + Button butConfirm = (Button) findViewById(R.id.butConfirm); + Button butCancel = (Button) findViewById(R.id.butCancel); Validate.isTrue(getIntent().hasExtra(ARG_DOWNLOAD_REQUEST), "Download request missing"); + DownloadRequest request = getIntent().getParcelableExtra(ARG_DOWNLOAD_REQUEST); + boolean sendToDownloadRequester = getIntent().getBooleanExtra(ARG_SEND_TO_DOWNLOAD_REQUESTER_BOOL, false); - request = getIntent().getParcelableExtra(ARG_DOWNLOAD_REQUEST); - sendToDownloadRequester = getIntent().getBooleanExtra(ARG_SEND_TO_DOWNLOAD_REQUESTER_BOOL, false); + String newDescription = txtvDescription.getText() + ":\n\n" + request.getTitle(); + txtvDescription.setText(newDescription); if (savedInstanceState != null) { etxtUsername.setText(savedInstanceState.getString("username")); etxtPassword.setText(savedInstanceState.getString("password")); } - txtvDescription.setText(txtvDescription.getText() + ":\n\n" + request.getTitle()); - - butCancel.setOnClickListener(v -> { - setResult(Activity.RESULT_CANCELED); - finish(); - }); - butConfirm.setOnClickListener(v -> { String username = etxtUsername.getText().toString(); String password = etxtPassword.getText().toString(); @@ -87,11 +77,16 @@ public class DownloadAuthenticationActivity extends ActionBarActivity { setResult(Activity.RESULT_OK, result); if (sendToDownloadRequester) { - if (BuildConfig.DEBUG) Log.d(TAG, "Sending request to DownloadRequester"); DownloadRequester.getInstance().download(DownloadAuthenticationActivity.this, request); } finish(); }); + + butCancel.setOnClickListener(v -> { + setResult(Activity.RESULT_CANCELED); + finish(); + }); + } @Override diff --git a/app/src/main/java/de/danoeh/antennapod/activity/FeedInfoActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/FeedInfoActivity.java index cc9db5e6e..8dea41b7c 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/FeedInfoActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/FeedInfoActivity.java @@ -100,7 +100,7 @@ public class FeedInfoActivity extends AppCompatActivity { private boolean authInfoChanged = false; - private TextWatcher authTextWatcher = new TextWatcher() { + private final TextWatcher authTextWatcher = new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @@ -117,7 +117,7 @@ public class FeedInfoActivity extends AppCompatActivity { private boolean filterTextChanged = false; - private TextWatcher filterTextWatcher = new TextWatcher() { + private final TextWatcher filterTextWatcher = new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java index 9949c01a0..f56dca173 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -82,7 +82,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi public static final String PREF_NAME = "MainActivityPrefs"; public static final String PREF_IS_FIRST_LAUNCH = "prefMainActivityIsFirstLaunch"; - public static final String PREF_LAST_FRAGMENT_TAG = "prefMainActivityLastFragmentTag"; + private static final String PREF_LAST_FRAGMENT_TAG = "prefMainActivityLastFragmentTag"; public static final String EXTRA_NAV_TYPE = "nav_type"; public static final String EXTRA_NAV_INDEX = "nav_index"; @@ -90,8 +90,8 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi public static final String EXTRA_FRAGMENT_ARGS = "fragment_args"; public static final String EXTRA_FEED_ID = "fragment_feed_id"; - public static final String SAVE_BACKSTACK_COUNT = "backstackCount"; - public static final String SAVE_TITLE = "title"; + private static final String SAVE_BACKSTACK_COUNT = "backstackCount"; + private static final String SAVE_TITLE = "title"; public static final String[] NAV_DRAWER_TAGS = { QueueFragment.TAG, @@ -235,7 +235,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi } } - public void showDrawerPreferencesDialog() { + private void showDrawerPreferencesDialog() { final List<String> hiddenDrawerItems = UserPreferences.getHiddenDrawerItems(); String[] navLabels = new String[NAV_DRAWER_TAGS.length]; final boolean[] checked = new boolean[NAV_DRAWER_TAGS.length]; @@ -269,7 +269,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi return (navDrawerData != null) ? navDrawerData.feeds : null; } - public void loadFragment(int index, Bundle args) { + private void loadFragment(int index, Bundle args) { Log.d(TAG, "loadFragment(index: " + index + ", args: " + args + ")"); if (index < navAdapter.getSubscriptionOffset()) { String tag = navAdapter.getTags().get(index); @@ -398,7 +398,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi } } - private AdapterView.OnItemClickListener navListClickListener = new AdapterView.OnItemClickListener() { + private final AdapterView.OnItemClickListener navListClickListener = new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { int viewType = parent.getAdapter().getItemViewType(position); @@ -409,7 +409,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi } }; - private AdapterView.OnItemLongClickListener newListLongClickListener = new AdapterView.OnItemLongClickListener() { + private final AdapterView.OnItemLongClickListener newListLongClickListener = new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { if(position < navAdapter.getTags().size()) { @@ -630,7 +630,7 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi private DBReader.NavDrawerData navDrawerData; private int selectedNavListIndex = 0; - private NavListAdapter.ItemAccess itemAccess = new NavListAdapter.ItemAccess() { + private final NavListAdapter.ItemAccess itemAccess = new NavListAdapter.ItemAccess() { @Override public int getCount() { if (navDrawerData != null) { @@ -743,14 +743,12 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi View parentLayout = findViewById(R.id.drawer_layout); Snackbar snackbar = Snackbar.make(parentLayout, event.message, Snackbar.LENGTH_SHORT); if(event.action != null) { - snackbar.setAction(getString(R.string.undo), v -> { - event.action.run(); - }); + snackbar.setAction(getString(R.string.undo), v -> event.action.run()); } snackbar.show(); } - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java index b0cbd355b..232ff4311 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -67,19 +67,19 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements private static final String PREFS = "MediaPlayerActivityPreferences"; private static final String PREF_SHOW_TIME_LEFT = "showTimeLeft"; - protected PlaybackController controller; + PlaybackController controller; - protected TextView txtvPosition; - protected TextView txtvLength; - protected SeekBar sbPosition; - protected ImageButton butRev; - protected TextView txtvRev; - protected ImageButton butPlay; - protected ImageButton butFF; - protected TextView txtvFF; - protected ImageButton butSkip; + private TextView txtvPosition; + private TextView txtvLength; + SeekBar sbPosition; + private ImageButton butRev; + private TextView txtvRev; + private ImageButton butPlay; + private ImageButton butFF; + private TextView txtvFF; + private ImageButton butSkip; - protected boolean showTimeLeft = false; + private boolean showTimeLeft = false; private boolean isFavorite = false; @@ -184,31 +184,31 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements }; } - protected static TextView getTxtvFFFromActivity(MediaplayerActivity activity) { + private static TextView getTxtvFFFromActivity(MediaplayerActivity activity) { return activity.txtvFF; } - protected static TextView getTxtvRevFromActivity(MediaplayerActivity activity) { + private static TextView getTxtvRevFromActivity(MediaplayerActivity activity) { return activity.txtvRev; } - protected void onSetSpeedAbilityChanged() { + private void onSetSpeedAbilityChanged() { Log.d(TAG, "onSetSpeedAbilityChanged()"); updatePlaybackSpeedButton(); } - protected void onPlaybackSpeedChange() { + private void onPlaybackSpeedChange() { updatePlaybackSpeedButtonText(); } - protected void onServiceQueried() { + private void onServiceQueried() { supportInvalidateOptionsMenu(); } - protected void chooseTheme() { + void chooseTheme() { setTheme(UserPreferences.getTheme()); } - protected void setScreenOn(boolean enable) { + void setScreenOn(boolean enable) { } @Override @@ -249,7 +249,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements */ protected abstract void onBufferEnd(); - protected void onBufferUpdate(float progress) { + private void onBufferUpdate(float progress) { if (sbPosition != null) { sbPosition.setSecondaryProgress((int) progress * sbPosition.getMax()); } @@ -258,7 +258,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements /** * Current screen orientation. */ - protected int orientation; + private int orientation; @Override protected void onStart() { @@ -619,7 +619,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements protected abstract void clearStatusMsg(); - protected void onPositionObserverUpdate() { + void onPositionObserverUpdate() { if (controller == null || txtvPosition == null || txtvLength == null) { return; } @@ -655,7 +655,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements * to the PlaybackService to ensure that the activity has the right * FeedMedia object. */ - protected boolean loadMediaInfo() { + boolean loadMediaInfo() { Log.d(TAG, "loadMediaInfo()"); if(controller == null || controller.getMedia() == null) { return false; @@ -669,18 +669,18 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements return true; } - protected void updatePlaybackSpeedButton() { + void updatePlaybackSpeedButton() { // Only meaningful on AudioplayerActivity, where it is overridden. } - protected void updatePlaybackSpeedButtonText() { + void updatePlaybackSpeedButtonText() { // Only meaningful on AudioplayerActivity, where it is overridden. } /** * Abstract directions to skip forward or back (rewind) and encapsulates behavior to get or set preference (including update of UI on the skip buttons). */ - static public enum SkipDirection { + public enum SkipDirection { SKIP_FORWARD( UserPreferences::getFastForwardSecs, MediaplayerActivity::getTxtvFFFromActivity, @@ -763,7 +763,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements builder.create().show(); } - protected void setupGUI() { + void setupGUI() { setContentView(getContentViewResourceId()); sbPosition = (SeekBar) findViewById(R.id.sbPosition); txtvPosition = (TextView) findViewById(R.id.txtvPosition); @@ -837,7 +837,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements } } - protected void onRewind() { + void onRewind() { if (controller == null) { return; } @@ -845,14 +845,14 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements controller.seekTo(curr - UserPreferences.getRewindSecs() * 1000); } - protected void onPlayPause() { + void onPlayPause() { if(controller == null) { return; } controller.playPause(); } - protected void onFastForward() { + void onFastForward() { if (controller == null) { return; } @@ -862,7 +862,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements protected abstract int getContentViewResourceId(); - void handleError(int errorCode) { + private void handleError(int errorCode) { final AlertDialog.Builder errorDialog = new AlertDialog.Builder(this); errorDialog.setTitle(R.string.error_label); errorDialog.setMessage(MediaPlayerError.getErrorString(this, errorCode)); @@ -875,7 +875,7 @@ public abstract class MediaplayerActivity extends CastEnabledActivity implements errorDialog.create().show(); } - float prog; + private float prog; @Override public void onProgressChanged (SeekBar seekBar,int progress, boolean fromUser) { diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java index d85c2fe8f..f3ed1cb62 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerInfoActivity.java @@ -72,16 +72,17 @@ import rx.schedulers.Schedulers; */ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implements NavDrawerActivity { + private static final String TAG = "MediaplayerInfoActivity"; + private static final int POS_COVER = 0; private static final int POS_DESCR = 1; private static final int POS_CHAPTERS = 2; private static final int NUM_CONTENT_FRAGMENTS = 3; - final static String TAG = "MediaplayerInfoActivity"; private static final String PREFS = "AudioPlayerActivityPreferences"; private static final String PREF_KEY_SELECTED_FRAGMENT_POSITION = "selectedFragmentPosition"; - public static final String[] NAV_DRAWER_TAGS = { + private static final String[] NAV_DRAWER_TAGS = { QueueFragment.TAG, EpisodesFragment.TAG, SubscriptionFragment.TAG, @@ -91,8 +92,8 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem NavListAdapter.SUBSCRIPTION_LIST_TAG }; - protected Button butPlaybackSpeed; - protected ImageButton butCastDisconnect; + Button butPlaybackSpeed; + ImageButton butCastDisconnect; private DrawerLayout drawerLayout; private NavListAdapter navAdapter; private ListView navList; @@ -151,7 +152,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem setTheme(UserPreferences.getNoTitleTheme()); } - protected void saveCurrentFragment() { + void saveCurrentFragment() { if(pager == null) { return; } @@ -159,7 +160,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE); prefs.edit() .putInt(PREF_KEY_SELECTED_FRAGMENT_POSITION, pager.getCurrentItem()) - .commit(); + .apply(); } @Override @@ -241,7 +242,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close); drawerToggle.setDrawerIndicatorEnabled(false); - drawerLayout.setDrawerListener(drawerToggle); + drawerLayout.addDrawerListener(drawerToggle); navAdapter = new NavListAdapter(itemAccess, this); navList.setAdapter(navAdapter); @@ -305,7 +306,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem return true; } - public void notifyMediaPositionChanged() { + private void notifyMediaPositionChanged() { if(pagerAdapter == null) { return; } @@ -395,12 +396,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem new RenameFeedDialog(this, feed).show(); return true; case R.id.remove_item: - final FeedRemover remover = new FeedRemover(this, feed) { - @Override - protected void onPostExecute(Void result) { - super.onPostExecute(result); - } - }; + final FeedRemover remover = new FeedRemover(this, feed); ConfirmationDialog conDialog = new ConfirmationDialog(this, R.string.remove_feed_label, getString(R.string.feed_delete_confirmation_msg, feed.getTitle())) { @@ -412,7 +408,8 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem Playable playable = controller.getMedia(); if (playable != null && playable instanceof FeedMedia) { FeedMedia media = (FeedMedia) playable; - if (media.getItem().getFeed().getId() == feed.getId()) { + if (media.getItem() != null && media.getItem().getFeed() != null && + media.getItem().getFeed().getId() == feed.getId()) { Log.d(TAG, "Currently playing episode is about to be deleted, skipping"); remover.skipOnCompletion = true; if(controller.getStatus() == PlayerStatus.PLAYING) { @@ -446,7 +443,7 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem } } - public void showDrawerPreferencesDialog() { + private void showDrawerPreferencesDialog() { final List<String> hiddenDrawerItems = UserPreferences.getHiddenDrawerItems(); String[] navLabels = new String[NAV_DRAWER_TAGS.length]; final boolean[] checked = new boolean[NAV_DRAWER_TAGS.length]; @@ -491,14 +488,12 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem View parentLayout = findViewById(R.id.drawer_layout); Snackbar snackbar = Snackbar.make(parentLayout, event.message, Snackbar.LENGTH_SHORT); if (event.action != null) { - snackbar.setAction(getString(R.string.undo), v -> { - event.action.run(); - }); + snackbar.setAction(getString(R.string.undo), v -> event.action.run()); } snackbar.show(); } - private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { + private final EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java index f6bf11e66..f859f5466 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OnlineFeedViewActivity.java @@ -5,8 +5,9 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; -import android.os.Looper; +import android.support.annotation.UiThread; import android.support.v4.app.NavUtils; +import android.support.v7.app.ActionBar; import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; @@ -55,7 +56,6 @@ import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DownloadRequestException; import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.syndication.handler.FeedHandler; -import de.danoeh.antennapod.core.syndication.handler.FeedHandlerResult; import de.danoeh.antennapod.core.syndication.handler.UnsupportedFeedtypeException; import de.danoeh.antennapod.core.util.DownloadError; import de.danoeh.antennapod.core.util.FileNameGenerator; @@ -66,7 +66,6 @@ import de.danoeh.antennapod.core.util.syndication.HtmlToPlainText; import de.danoeh.antennapod.dialog.AuthenticationDialog; import de.greenrobot.event.EventBus; import rx.Observable; -import rx.Subscriber; import rx.Subscription; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; @@ -84,7 +83,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { public static final String ARG_FEEDURL = "arg.feedurl"; // Optional argument: specify a title for the actionbar. public static final String ARG_TITLE = "title"; - public static final int RESULT_ERROR = 2; + private static final int RESULT_ERROR = 2; private static final String TAG = "OnlineFeedViewActivity"; private static final int EVENTS = EventDistributor.FEED_LIST_UPDATE; private volatile List<Feed> feeds; @@ -101,7 +100,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { private Subscription download; private Subscription parser; private Subscription updater; - private EventDistributor.EventListener listener = new EventDistributor.EventListener() { + private final EventDistributor.EventListener listener = new EventDistributor.EventListener() { @Override public void update(EventDistributor eventDistributor, Integer arg) { if ((arg & EventDistributor.FEED_LIST_UPDATE) != 0) { @@ -112,9 +111,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { feeds -> { OnlineFeedViewActivity.this.feeds = feeds; setSubscribeButtonState(feed); - }, error -> { - Log.e(TAG, Log.getStackTraceString(error)); - } + }, error -> Log.e(TAG, Log.getStackTraceString(error)) ); } else if ((arg & EVENTS) != 0) { setSubscribeButtonState(feed); @@ -131,10 +128,13 @@ public class OnlineFeedViewActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { setTheme(UserPreferences.getTheme()); super.onCreate(savedInstanceState); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setDisplayHomeAsUpEnabled(true); + } - if (getIntent() != null && getIntent().hasExtra(ARG_TITLE)) { - getSupportActionBar().setTitle(getIntent().getStringExtra(ARG_TITLE)); + if (actionBar != null && getIntent() != null && getIntent().hasExtra(ARG_TITLE)) { + actionBar.setTitle(getIntent().getStringExtra(ARG_TITLE)); } StorageUtils.checkStorageAvailability(this); @@ -146,7 +146,9 @@ public class OnlineFeedViewActivity extends AppCompatActivity { || TextUtils.equals(getIntent().getAction(), Intent.ACTION_VIEW)) { feedUrl = (TextUtils.equals(getIntent().getAction(), Intent.ACTION_SEND)) ? getIntent().getStringExtra(Intent.EXTRA_TEXT) : getIntent().getDataString(); - getSupportActionBar().setTitle(R.string.add_feed_label); + if (actionBar != null) { + actionBar.setTitle(R.string.add_feed_label); + } } else { throw new IllegalArgumentException("Activity must be started with feedurl argument!"); } @@ -265,16 +267,11 @@ public class OnlineFeedViewActivity extends AppCompatActivity { feed.getDownload_url(), "OnlineFeed", 0, Feed.FEEDFILETYPE_FEED, username, password, true, null); - download = Observable.create(new Observable.OnSubscribe<DownloadStatus>() { - @Override - public void call(Subscriber<? super DownloadStatus> subscriber) { - feeds = DBReader.getFeedList(); - downloader = new HttpDownloader(request); - downloader.call(); - Log.d(TAG, "Download was completed"); - subscriber.onNext(downloader.getResult()); - subscriber.onCompleted(); - } + download = Observable.fromCallable(() -> { + feeds = DBReader.getFeedList(); + downloader = new HttpDownloader(request); + downloader.call(); + return downloader.getResult(); }) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) @@ -286,6 +283,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { if (status == null) { Log.wtf(TAG, "DownloadStatus returned by Downloader was null"); finish(); + return; } if (status.isCancelled()) { return; @@ -300,7 +298,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { } } else { String errorMsg = status.getReason().getErrorString(OnlineFeedViewActivity.this); - if (errorMsg != null && status.getReasonDetailed() != null) { + if (status.getReasonDetailed() != null) { errorMsg += " (" + status.getReasonDetailed() + ")"; } showErrorDialog(errorMsg); @@ -313,35 +311,33 @@ public class OnlineFeedViewActivity extends AppCompatActivity { } Log.d(TAG, "Parsing feed"); - parser = Observable.create(new Observable.OnSubscribe<FeedHandlerResult>() { - @Override - public void call(Subscriber<? super FeedHandlerResult> subscriber) { - FeedHandler handler = new FeedHandler(); - try { - FeedHandlerResult result = handler.parseFeed(feed); - subscriber.onNext(result); - } catch (UnsupportedFeedtypeException e) { - Log.d(TAG, "Unsupported feed type detected"); - if (TextUtils.equals("html", e.getRootElement().toLowerCase())) { - showFeedDiscoveryDialog(new File(feed.getFile_url()), feed.getDownload_url()); - } else { - subscriber.onError(e); - } - } catch (Exception e) { - Log.e(TAG, Log.getStackTraceString(e)); - subscriber.onError(e); - } finally { - boolean rc = new File(feed.getFile_url()).delete(); - Log.d(TAG, "Deleted feed source file. Result: " + rc); - subscriber.onCompleted(); + parser = Observable.fromCallable(() -> { + FeedHandler handler = new FeedHandler(); + try { + return handler.parseFeed(feed); + } catch (UnsupportedFeedtypeException e) { + Log.d(TAG, "Unsupported feed type detected"); + if (TextUtils.equals("html", e.getRootElement().toLowerCase())) { + showFeedDiscoveryDialog(new File(feed.getFile_url()), feed.getDownload_url()); + return null; + } else { + throw e; } + } catch (Exception e) { + Log.e(TAG, Log.getStackTraceString(e)); + throw e; + } finally { + boolean rc = new File(feed.getFile_url()).delete(); + Log.d(TAG, "Deleted feed source file. Result: " + rc); } }) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(result -> { - beforeShowFeedInformation(result.feed); - showFeedInformation(result.feed, result.alternateFeedUrls); + if(result != null) { + beforeShowFeedInformation(result.feed); + showFeedInformation(result.feed, result.alternateFeedUrls); + } }, error -> { String errorMsg = DownloadError.ERROR_PARSER_EXCEPTION.getErrorString( OnlineFeedViewActivity.this) + " (" + error.getMessage() + ")"; @@ -383,8 +379,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { this.selectedDownloadUrl = feed.getDownload_url(); EventDistributor.getInstance().register(listener); ListView listView = (ListView) findViewById(R.id.listview); - LayoutInflater inflater = (LayoutInflater) - getSystemService(Context.LAYOUT_INFLATER_SERVICE); + LayoutInflater inflater = LayoutInflater.from(this); View header = inflater.inflate(R.layout.onlinefeedview_header, listView, false); listView.addHeaderView(header); @@ -414,7 +409,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { description.setText(feed.getDescription()); subscribeButton.setOnClickListener(v -> { - if(feed != null && feedInFeedlist(feed)) { + if(feedInFeedlist(feed)) { Intent intent = new Intent(OnlineFeedViewActivity.this, MainActivity.class); // feed.getId() is always 0, we have to retrieve the id from the feed list from // the database @@ -508,8 +503,8 @@ public class OnlineFeedViewActivity extends AppCompatActivity { return 0; } + @UiThread private void showErrorDialog(String errorMsg) { - assert(Looper.myLooper() == Looper.getMainLooper()); // run on UI thread if (!isFinishing() && !isPaused) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.error_label); @@ -586,7 +581,7 @@ public class OnlineFeedViewActivity extends AppCompatActivity { private class FeedViewAuthenticationDialog extends AuthenticationDialog { - private String feedUrl; + private final String feedUrl; FeedViewAuthenticationDialog(Context context, int titleRes, String feedUrl) { super(context, titleRes, true, false, null, null); diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OpmlFeedChooserActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OpmlFeedChooserActivity.java index 355e0f372..cd375a65a 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OpmlFeedChooserActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OpmlFeedChooserActivity.java @@ -97,7 +97,7 @@ public class OpmlFeedChooserActivity extends AppCompatActivity { } private List<String> getTitleList() { - List<String> result = new ArrayList<String>(); + List<String> result = new ArrayList<>(); if (OpmlImportHolder.getReadElements() != null) { for (OpmlElement element : OpmlImportHolder.getReadElements()) { result.add(element.getText()); diff --git a/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportBaseActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportBaseActivity.java index 07b0b3cdb..c04ae051e 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportBaseActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/OpmlImportBaseActivity.java @@ -68,7 +68,7 @@ public class OpmlImportBaseActivity extends AppCompatActivity { } } - protected void importUri(@Nullable Uri uri) { + void importUri(@Nullable Uri uri) { if(uri == null) { new MaterialDialog.Builder(this) .content(R.string.opml_import_error_no_file) @@ -114,7 +114,7 @@ public class OpmlImportBaseActivity extends AppCompatActivity { } /** Starts the import process. */ - protected void startImport() { + private void startImport() { try { Reader mReader = new InputStreamReader(getContentResolver().openInputStream(uri), LangUtils.UTF_8); importWorker = new OpmlImportWorker(this, mReader) { @@ -144,7 +144,7 @@ public class OpmlImportBaseActivity extends AppCompatActivity { } } - protected boolean finishWhenCanceled() { + boolean finishWhenCanceled() { return false; } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/StorageErrorActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/StorageErrorActivity.java index d104a9e93..a2a49f54e 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/StorageErrorActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/StorageErrorActivity.java @@ -164,7 +164,7 @@ public class StorageErrorActivity extends AppCompatActivity { startActivity(new Intent(this, MainActivity.class)); } - private BroadcastReceiver mediaUpdate = new BroadcastReceiver() { + private final BroadcastReceiver mediaUpdate = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { diff --git a/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java index fb5c4d273..54758acf4 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/VideoplayerActivity.java @@ -7,6 +7,7 @@ import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.support.v4.view.WindowCompat; +import android.support.v7.app.ActionBar; import android.util.Log; import android.util.Pair; import android.view.MotionEvent; @@ -45,7 +46,7 @@ public class VideoplayerActivity extends MediaplayerActivity { private VideoControlsHider videoControlsHider = new VideoControlsHider(this); - private AtomicBoolean isSetup = new AtomicBoolean(false); + private final AtomicBoolean isSetup = new AtomicBoolean(false); private LinearLayout controls; private LinearLayout videoOverlay; @@ -173,7 +174,7 @@ public class VideoplayerActivity extends MediaplayerActivity { progressIndicator.setVisibility(View.INVISIBLE); } - View.OnTouchListener onVideoviewTouched = (v, event) -> { + private final View.OnTouchListener onVideoviewTouched = (v, event) -> { if (event.getAction() == MotionEvent.ACTION_DOWN) { videoControlsHider.stop(); toggleVideoControlsVisibility(); @@ -187,7 +188,7 @@ public class VideoplayerActivity extends MediaplayerActivity { }; @SuppressLint("NewApi") - void setupVideoControlsToggler() { + private void setupVideoControlsToggler() { videoControlsHider.stop(); videoControlsHider.start(); } @@ -355,18 +356,21 @@ public class VideoplayerActivity extends MediaplayerActivity { private WeakReference<VideoplayerActivity> activity; - public VideoControlsHider(VideoplayerActivity activity) { + VideoControlsHider(VideoplayerActivity activity) { this.activity = new WeakReference<>(activity); } private final Runnable hideVideoControls = () -> { - VideoplayerActivity vpa = activity.get(); + VideoplayerActivity vpa = activity != null ? activity.get() : null; if(vpa == null) { return; } if (vpa.videoControlsShowing) { Log.d(TAG, "Hiding video controls"); - vpa.getSupportActionBar().hide(); + ActionBar actionBar = vpa.getSupportActionBar(); + if (actionBar != null) { + actionBar.hide(); + } vpa.hideVideoControls(); vpa.videoControlsShowing = false; } @@ -376,7 +380,7 @@ public class VideoplayerActivity extends MediaplayerActivity { this.postDelayed(hideVideoControls, DELAY); } - public void stop() { + void stop() { this.removeCallbacks(hideVideoControls); } diff --git a/app/src/main/java/de/danoeh/antennapod/activity/gpoddernet/GpodnetAuthenticationActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/gpoddernet/GpodnetAuthenticationActivity.java index 31d0fb1a3..8f447ac90 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/gpoddernet/GpodnetAuthenticationActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/gpoddernet/GpodnetAuthenticationActivity.java @@ -61,7 +61,7 @@ public class GpodnetAuthenticationActivity extends AppCompatActivity { private volatile String password; private volatile GpodnetDevice selectedDevice; - View[] views; + private View[] views; @Override protected void onCreate(Bundle savedInstanceState) { |