From 5b509686452f0f1d5c7eb470b0d405bba686ee62 Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Mon, 22 Feb 2016 08:16:51 +0100 Subject: [PATCH 01/21] Do not refresh when not attached --- .../java/de/danoeh/antennapod/fragment/CoverFragment.java | 7 +------ .../antennapod/fragment/ItemDescriptionFragment.java | 4 +--- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java index 931d14924..d3b97f9df 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java @@ -63,12 +63,7 @@ public class CoverFragment extends Fragment implements AudioplayerContentFragmen } private void loadMediaInfo() { - if(imgvCover == null) { - return; - } if (media != null) { - Log.d(TAG, "feed title: " + media.getFeedTitle()); - Log.d(TAG, "episode title: " + media.getEpisodeTitle()); txtvPodcastTitle.setText(media.getFeedTitle()); txtvEpisodeTitle.setText(media.getEpisodeTitle()); Glide.with(this) @@ -103,7 +98,7 @@ public class CoverFragment extends Fragment implements AudioplayerContentFragmen @Override public void onMediaChanged(Playable media) { - if(this.media == media) { + if(!isAdded() || this.media == media) { return; } this.media = media; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java index 4c723e5ff..c1c1aab6c 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemDescriptionFragment.java @@ -62,7 +62,6 @@ public class ItemDescriptionFragment extends Fragment implements AudioplayerCont private static final String ARG_HIGHLIGHT_TIMECODES = "arg.highlightTimecodes"; private WebView webvDescription; - private String webvData; private ShownotesProvider shownotesProvider; private Playable media; @@ -309,7 +308,6 @@ public class ItemDescriptionFragment extends Fragment implements AudioplayerCont .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(data -> { - webvData = data; webvDescription.loadDataWithBaseURL(null, data, "text/html", "utf-8", "about:blank"); Log.d(TAG, "Webview loaded"); @@ -384,7 +382,7 @@ public class ItemDescriptionFragment extends Fragment implements AudioplayerCont @Override public void onMediaChanged(Playable media) { - if(this.media == media) { + if(this.media == media || webvDescription == null) { return; } this.media = media; From b1df272797ec82ae1e697f996c146ec9cde0d9ef Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Tue, 23 Feb 2016 08:26:56 +0100 Subject: [PATCH 02/21] Refactor --- .../activity/AudioplayerActivity.java | 34 ++++----- .../activity/MediaplayerActivity.java | 71 ++++++++----------- 2 files changed, 45 insertions(+), 60 deletions(-) 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 8af6f3552..2dacb5121 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java @@ -94,8 +94,8 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe private int mPosition = -1; private Playable media; - private ViewPager mPager; - private AudioplayerPagerAdapter mPagerAdapter; + private ViewPager pager; + private AudioplayerPagerAdapter pagerAdapter; private Subscription subscription; @@ -116,8 +116,8 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe // don't risk creating memory leaks navAdapter = null; drawerToggle = null; - mPager = null; - mPagerAdapter = null; + pager = null; + pagerAdapter = null; } @Override @@ -126,13 +126,13 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe } private void saveCurrentFragment() { - if(mPager == null) { + if(pager == null) { return; } Log.d(TAG, "Saving preferences"); SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE); prefs.edit() - .putInt(PREF_KEY_SELECTED_FRAGMENT_POSITION, mPager.getCurrentItem()) + .putInt(PREF_KEY_SELECTED_FRAGMENT_POSITION, pager.getCurrentItem()) .commit(); } @@ -146,7 +146,7 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe Log.d(TAG, "Restoring instance state"); SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE); int lastPosition = prefs.getInt(PREF_KEY_SELECTED_FRAGMENT_POSITION, -1); - mPager.setCurrentItem(lastPosition); + pager.setCurrentItem(lastPosition); } @Override @@ -166,9 +166,9 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe true); startService(launchIntent); } - if(mPagerAdapter != null && controller != null && controller.getMedia() != media) { + if(pagerAdapter != null && controller != null && controller.getMedia() != media) { media = controller.getMedia(); - mPagerAdapter.onMediaChanged(media); + pagerAdapter.onMediaChanged(media); } EventDistributor.getInstance().register(contentUpdate); @@ -255,13 +255,13 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe startActivity(new Intent(AudioplayerActivity.this, PreferenceController.getPreferenceActivity())); }); - mPager = (ViewPager) findViewById(R.id.pager); - mPagerAdapter = new AudioplayerPagerAdapter(getSupportFragmentManager()); - mPager.setAdapter(mPagerAdapter); + pager = (ViewPager) findViewById(R.id.pager); + pagerAdapter = new AudioplayerPagerAdapter(getSupportFragmentManager()); + pager.setAdapter(pagerAdapter); CirclePageIndicator pageIndicator = (CirclePageIndicator) findViewById(R.id.page_indicator); - pageIndicator.setViewPager(mPager); + pageIndicator.setViewPager(pager); loadLastFragment(); - mPager.onSaveInstanceState(); + pager.onSaveInstanceState(); } @Override @@ -277,7 +277,7 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe } if(controller.getMedia() != media) { media = controller.getMedia(); - mPagerAdapter.onMediaChanged(media); + pagerAdapter.onMediaChanged(media); } return true; } @@ -411,13 +411,13 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe public void onBackPressed() { if(isDrawerOpen()) { drawerLayout.closeDrawer(navDrawer); - } else if (mPager.getCurrentItem() == 0) { + } else if (pager == null || pager.getCurrentItem() == 0) { // If the user is currently looking at the first step, allow the system to handle the // Back button. This calls finish() on this activity and pops the back stack. super.onBackPressed(); } else { // Otherwise, select the previous step. - mPager.setCurrentItem(mPager.getCurrentItem() - 1); + pager.setCurrentItem(pager.getCurrentItem() - 1); } } 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 e890f03b7..27212acd6 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -229,8 +229,7 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O protected void onBufferUpdate(float progress) { if (sbPosition != null) { - sbPosition.setSecondaryProgress((int) progress - * sbPosition.getMax()); + sbPosition.setSecondaryProgress((int) progress * sbPosition.getMax()); } } @@ -597,28 +596,24 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O protected abstract void clearStatusMsg(); protected void onPositionObserverUpdate() { - if (controller != null) { - int currentPosition = controller.getPosition(); - int duration = controller.getDuration(); - Log.d(TAG, "currentPosition " + Converter - .getDurationStringLong(currentPosition)); - if (currentPosition != PlaybackService.INVALID_TIME - && duration != PlaybackService.INVALID_TIME - && controller.getMedia() != null) { - txtvPosition.setText(Converter - .getDurationStringLong(currentPosition)); - if (showTimeLeft) { - txtvLength.setText("-" + Converter - .getDurationStringLong(duration - currentPosition)); - } else { - txtvLength.setText(Converter - .getDurationStringLong(duration)); - } - updateProgressbarPosition(currentPosition, duration); - } else { - Log.w(TAG, "Could not react to position observer update because of invalid time"); - } + if (controller == null || txtvPosition == null || txtvLength == null) { + return; } + int currentPosition = controller.getPosition(); + int duration = controller.getDuration(); + Log.d(TAG, "currentPosition " + Converter.getDurationStringLong(currentPosition)); + if (currentPosition == PlaybackService.INVALID_TIME || + duration == PlaybackService.INVALID_TIME) { + Log.w(TAG, "Could not react to position observer update because of invalid time"); + return; + } + txtvPosition.setText(Converter.getDurationStringLong(currentPosition)); + if (showTimeLeft) { + txtvLength.setText("-" + Converter.getDurationStringLong(duration - currentPosition)); + } else { + txtvLength.setText(Converter.getDurationStringLong(duration)); + } + updateProgressbarPosition(currentPosition, duration); } private void updateProgressbarPosition(int position, int duration) { @@ -639,17 +634,7 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE); showTimeLeft = prefs.getBoolean(PREF_SHOW_TIME_LEFT, false); if (media != null) { - txtvPosition.setText(Converter.getDurationStringLong((media.getPosition()))); - - if (media.getDuration() != 0) { - txtvLength.setText(Converter.getDurationStringLong(media.getDuration())); - float progress = ((float) media.getPosition()) / media.getDuration(); - sbPosition.setProgress((int) (progress * sbPosition.getMax())); - if (showTimeLeft) { - int timeLeft = media.getDuration() - media.getPosition(); - txtvLength.setText("-" + Converter.getDurationStringLong(timeLeft)); - } - } + onPositionObserverUpdate(); checkFavorite(); if(butPlaybackSpeed != null) { if (controller == null) { @@ -857,8 +842,7 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O void handleError(int errorCode) { final AlertDialog.Builder errorDialog = new AlertDialog.Builder(this); errorDialog.setTitle(R.string.error_label); - errorDialog - .setMessage(MediaPlayerError.getErrorString(this, errorCode)); + errorDialog.setMessage(MediaPlayerError.getErrorString(this, errorCode)); errorDialog.setNeutralButton("OK", (dialog, which) -> { dialog.dismiss(); @@ -872,13 +856,14 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O @Override public void onProgressChanged (SeekBar seekBar,int progress, boolean fromUser) { - if (controller != null) { - prog = controller.onSeekBarProgressChanged(seekBar, progress, fromUser, txtvPosition); - if (showTimeLeft && prog != 0) { - int duration = controller.getDuration(); - String length = "-" + Converter.getDurationStringLong(duration - (int) (prog * duration)); - txtvLength.setText(length); - } + if (controller == null || txtvLength == null) { + return; + } + prog = controller.onSeekBarProgressChanged(seekBar, progress, fromUser, txtvPosition); + if (showTimeLeft && prog != 0) { + int duration = controller.getDuration(); + String length = "-" + Converter.getDurationStringLong(duration - (int) (prog * duration)); + txtvLength.setText(length); } } From 4366e134cf99321ca8166a8021b3cdb031b7d246 Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Tue, 23 Feb 2016 08:27:09 +0100 Subject: [PATCH 03/21] Prevent NPE --- .../antennapod/activity/AudioplayerActivity.java | 9 +++++++-- .../antennapod/activity/MediaplayerActivity.java | 13 ++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) 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 2dacb5121..b4e8d4d71 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java @@ -139,7 +139,9 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); - drawerToggle.onConfigurationChanged(newConfig); + if(drawerToggle != null) { + drawerToggle.onConfigurationChanged(newConfig); + } } private void loadLastFragment() { @@ -283,7 +285,10 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe } public void notifyMediaPositionChanged() { - ChaptersFragment chaptersFragment = mPagerAdapter.getChaptersFragment(); + if(pagerAdapter == null) { + return; + } + ChaptersFragment chaptersFragment = pagerAdapter.getChaptersFragment(); if(chaptersFragment != null) { ChaptersListAdapter adapter = (ChaptersListAdapter) chaptersFragment.getListAdapter(); if (adapter != null) { 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 27212acd6..0d878b556 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -206,8 +206,10 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O @Override protected void onPause() { super.onPause(); - controller.reinitServiceIfPaused(); - controller.pause(); + if(controller != null) { + controller.reinitServiceIfPaused(); + controller.pause(); + } } /** @@ -582,7 +584,9 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O super.onResume(); Log.d(TAG, "onResume()"); StorageUtils.checkStorageAvailability(this); - controller.init(); + if(controller != null) { + controller.init(); + } } /** @@ -618,6 +622,9 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O private void updateProgressbarPosition(int position, int duration) { Log.d(TAG, "updateProgressbarPosition(" + position + ", " + duration + ")"); + if(sbPosition == null) { + return; + } float progress = ((float) position) / duration; sbPosition.setProgress((int) (progress * sbPosition.getMax())); } From 0677c70a4df9cb51d9f45b729129de51ad49a93a Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Tue, 23 Feb 2016 20:19:02 +0100 Subject: [PATCH 04/21] Do not show full disk icon if cache size is unlimited --- .../main/java/de/danoeh/antennapod/adapter/NavListAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java index 269614d35..6d7e6dcac 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java @@ -232,7 +232,7 @@ public class NavListAdapter extends BaseAdapter int spaceUsed = itemAccess.getNumberOfDownloadedItems() - itemAccess.getReclaimableItems(); - if (spaceUsed >= epCacheSize) { + if (epCacheSize > 0 && spaceUsed >= epCacheSize) { holder.count.setText("{md-disc-full 150%}"); Iconify.addIcons(holder.count); holder.count.setVisibility(View.VISIBLE); From a97788aaa5da60c7d1bdea70cf5dfa694b48ffa7 Mon Sep 17 00:00:00 2001 From: Tom Hennen Date: Thu, 25 Feb 2016 17:53:55 -0500 Subject: [PATCH 05/21] 1.5.0.9 --- app/src/main/AndroidManifest.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b0c47f5a1..36067d52e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="1050009" + android:versionName="1.5.0.9">