Merge pull request #1615 from mfietz/issue/1606-player-skip-update
Fix player skip issues
This commit is contained in:
commit
b53fe7874b
@ -6,11 +6,11 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.AppBarLayout;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
@ -28,6 +28,7 @@ import android.widget.ListView;
|
||||
import com.viewpagerindicator.CirclePageIndicator;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.adapter.ChaptersListAdapter;
|
||||
@ -83,6 +84,8 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe
|
||||
AddFeedFragment.TAG
|
||||
};
|
||||
|
||||
private AtomicBoolean isSetup = new AtomicBoolean(false);
|
||||
|
||||
private DrawerLayout drawerLayout;
|
||||
private NavListAdapter navAdapter;
|
||||
private ListView navList;
|
||||
@ -107,6 +110,16 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe
|
||||
saveCurrentFragment();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
// don't risk creating memory leaks
|
||||
navAdapter = null;
|
||||
drawerToggle = null;
|
||||
mPager = null;
|
||||
mPagerAdapter = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void chooseTheme() {
|
||||
setTheme(UserPreferences.getNoTitleTheme());
|
||||
@ -116,7 +129,6 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe
|
||||
if(mPager == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Log.d(TAG, "Saving preferences");
|
||||
SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE);
|
||||
prefs.edit()
|
||||
@ -156,10 +168,9 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe
|
||||
}
|
||||
if(mPagerAdapter != null && controller != null && controller.getMedia() != media) {
|
||||
media = controller.getMedia();
|
||||
mPagerAdapter.notifyDataSetChanged();
|
||||
mPagerAdapter.onMediaChanged(media);
|
||||
}
|
||||
|
||||
|
||||
EventDistributor.getInstance().register(contentUpdate);
|
||||
loadData();
|
||||
}
|
||||
@ -193,6 +204,9 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe
|
||||
|
||||
@Override
|
||||
protected void setupGUI() {
|
||||
if(isSetup.getAndSet(true)) {
|
||||
return;
|
||||
}
|
||||
super.setupGUI();
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
@ -242,13 +256,11 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe
|
||||
});
|
||||
|
||||
mPager = (ViewPager) findViewById(R.id.pager);
|
||||
if(mPager.getAdapter() == null) {
|
||||
mPagerAdapter = new AudioplayerPagerAdapter(getSupportFragmentManager());
|
||||
mPager.setAdapter(mPagerAdapter);
|
||||
CirclePageIndicator pageIndicator = (CirclePageIndicator) findViewById(R.id.page_indicator);
|
||||
pageIndicator.setViewPager(mPager);
|
||||
loadLastFragment();
|
||||
}
|
||||
mPagerAdapter = new AudioplayerPagerAdapter(getSupportFragmentManager());
|
||||
mPager.setAdapter(mPagerAdapter);
|
||||
CirclePageIndicator pageIndicator = (CirclePageIndicator) findViewById(R.id.page_indicator);
|
||||
pageIndicator.setViewPager(mPager);
|
||||
loadLastFragment();
|
||||
mPager.onSaveInstanceState();
|
||||
}
|
||||
|
||||
@ -265,16 +277,18 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe
|
||||
}
|
||||
if(controller.getMedia() != media) {
|
||||
media = controller.getMedia();
|
||||
mPagerAdapter.notifyDataSetChanged();
|
||||
mPagerAdapter.onMediaChanged(media);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void notifyMediaPositionChanged() {
|
||||
ListFragment chapterFragment = (ListFragment) mPagerAdapter.getItem(POS_CHAPTERS);
|
||||
ChaptersListAdapter adapter = (ChaptersListAdapter) chapterFragment.getListAdapter();
|
||||
if(adapter != null) {
|
||||
adapter.notifyDataSetChanged();
|
||||
ChaptersFragment chaptersFragment = mPagerAdapter.getChaptersFragment();
|
||||
if(chaptersFragment != null) {
|
||||
ChaptersListAdapter adapter = (ChaptersListAdapter) chaptersFragment.getListAdapter();
|
||||
if (adapter != null) {
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -510,7 +524,7 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe
|
||||
};
|
||||
|
||||
public interface AudioplayerContentFragment {
|
||||
void onDataSetChanged(Playable media);
|
||||
void onMediaChanged(Playable media);
|
||||
}
|
||||
|
||||
private class AudioplayerPagerAdapter extends FragmentStatePagerAdapter {
|
||||
@ -519,22 +533,51 @@ public class AudioplayerActivity extends MediaplayerActivity implements NavDrawe
|
||||
super(fm);
|
||||
}
|
||||
|
||||
private CoverFragment coverFragment;
|
||||
private ItemDescriptionFragment itemDescriptionFragment;
|
||||
private ChaptersFragment chaptersFragment;
|
||||
|
||||
public void onMediaChanged(Playable media) {
|
||||
if(coverFragment != null) {
|
||||
coverFragment.onMediaChanged(media);
|
||||
}
|
||||
if(itemDescriptionFragment != null) {
|
||||
itemDescriptionFragment.onMediaChanged(media);
|
||||
}
|
||||
if(chaptersFragment != null) {
|
||||
chaptersFragment.onMediaChanged(media);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ChaptersFragment getChaptersFragment() {
|
||||
return chaptersFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
Log.d(TAG, "getItem(" + position + ")");
|
||||
switch (position) {
|
||||
case POS_COVER:
|
||||
return CoverFragment.newInstance(media);
|
||||
if(coverFragment == null) {
|
||||
coverFragment = CoverFragment.newInstance(media);
|
||||
}
|
||||
return coverFragment;
|
||||
case POS_DESCR:
|
||||
return ItemDescriptionFragment.newInstance(media, true, true);
|
||||
if(itemDescriptionFragment == null) {
|
||||
itemDescriptionFragment = ItemDescriptionFragment.newInstance(media, true, true);
|
||||
}
|
||||
return itemDescriptionFragment;
|
||||
case POS_CHAPTERS:
|
||||
return ChaptersFragment.newInstance(media, controller);
|
||||
if(chaptersFragment == null) {
|
||||
chaptersFragment = ChaptersFragment.newInstance(media, controller);
|
||||
}
|
||||
return chaptersFragment;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return NUM_CONTENT_FRAGMENTS;
|
||||
|
@ -20,6 +20,7 @@ import android.widget.ProgressBar;
|
||||
import android.widget.SeekBar;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.feed.MediaType;
|
||||
@ -43,6 +44,8 @@ public class VideoplayerActivity extends MediaplayerActivity {
|
||||
|
||||
private VideoControlsHider videoControlsHider = new VideoControlsHider(this);
|
||||
|
||||
private AtomicBoolean isSetup = new AtomicBoolean(false);
|
||||
|
||||
private LinearLayout controls;
|
||||
private LinearLayout videoOverlay;
|
||||
private AspectRatioVideoView videoview;
|
||||
@ -115,6 +118,9 @@ public class VideoplayerActivity extends MediaplayerActivity {
|
||||
|
||||
@Override
|
||||
protected void setupGUI() {
|
||||
if(isSetup.getAndSet(true)) {
|
||||
return;
|
||||
}
|
||||
super.setupGUI();
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
controls = (LinearLayout) findViewById(R.id.controls);
|
||||
|
@ -55,8 +55,17 @@ public class ChaptersFragment extends ListFragment implements AudioplayerContent
|
||||
}
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
adapter = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataSetChanged(Playable media) {
|
||||
public void onMediaChanged(Playable media) {
|
||||
if(this.media == media || adapter == null) {
|
||||
return;
|
||||
}
|
||||
this.media = media;
|
||||
adapter.setMedia(media);
|
||||
adapter.notifyDataSetChanged();
|
||||
if(media.getChapters() == null) {
|
||||
|
@ -19,8 +19,8 @@ import de.danoeh.antennapod.core.util.playback.Playable;
|
||||
/**
|
||||
* Displays the cover and the title of a FeedItem.
|
||||
*/
|
||||
public class CoverFragment extends Fragment implements
|
||||
AudioplayerContentFragment {
|
||||
public class CoverFragment extends Fragment implements AudioplayerContentFragment {
|
||||
|
||||
private static final String TAG = "CoverFragment";
|
||||
private static final String ARG_PLAYABLE = "arg.playable";
|
||||
|
||||
@ -71,14 +71,12 @@ public class CoverFragment extends Fragment implements
|
||||
Log.d(TAG, "episode title: " + media.getEpisodeTitle());
|
||||
txtvPodcastTitle.setText(media.getFeedTitle());
|
||||
txtvEpisodeTitle.setText(media.getEpisodeTitle());
|
||||
imgvCover.post(() -> {
|
||||
Glide.with(this)
|
||||
.load(media.getImageUri())
|
||||
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
||||
.dontAnimate()
|
||||
.fitCenter()
|
||||
.into(imgvCover);
|
||||
});
|
||||
Glide.with(this)
|
||||
.load(media.getImageUri())
|
||||
.diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY)
|
||||
.dontAnimate()
|
||||
.fitCenter()
|
||||
.into(imgvCover);
|
||||
} else {
|
||||
Log.w(TAG, "loadMediaInfo was called while media was null");
|
||||
}
|
||||
@ -97,7 +95,17 @@ public class CoverFragment extends Fragment implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataSetChanged(Playable media) {
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
// prevent memory leaks
|
||||
root = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMediaChanged(Playable media) {
|
||||
if(this.media == media) {
|
||||
return;
|
||||
}
|
||||
this.media = media;
|
||||
loadMediaInfo();
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.WebSettings.LayoutAlgorithm;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.Toast;
|
||||
@ -67,7 +67,6 @@ public class ItemDescriptionFragment extends Fragment implements AudioplayerCont
|
||||
private ShownotesProvider shownotesProvider;
|
||||
private Playable media;
|
||||
|
||||
|
||||
private Subscription webViewLoader;
|
||||
|
||||
/**
|
||||
@ -124,7 +123,7 @@ public class ItemDescriptionFragment extends Fragment implements AudioplayerCont
|
||||
ta.recycle();
|
||||
webvDescription.setBackgroundColor(backgroundColor);
|
||||
webvDescription.getSettings().setUseWideViewPort(false);
|
||||
webvDescription.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
|
||||
webvDescription.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
|
||||
webvDescription.getSettings().setLoadWithOverviewMode(true);
|
||||
webvDescription.setOnLongClickListener(webViewLongClickListener);
|
||||
webvDescription.setWebViewClient(new WebViewClient() {
|
||||
@ -384,7 +383,10 @@ public class ItemDescriptionFragment extends Fragment implements AudioplayerCont
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataSetChanged(Playable media) {
|
||||
public void onMediaChanged(Playable media) {
|
||||
if(this.media == media) {
|
||||
return;
|
||||
}
|
||||
this.media = media;
|
||||
this.shownotesProvider = media;
|
||||
load();
|
||||
|
@ -24,7 +24,6 @@ import android.view.SurfaceHolder;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.target.Target;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
@ -982,6 +981,8 @@ public class PlaybackServiceMediaPlayer implements SharedPreferences.OnSharedPre
|
||||
playerLock.lock();
|
||||
releaseWifiLockIfNecessary();
|
||||
|
||||
boolean isPlaying = playerStatus == PlayerStatus.PLAYING;
|
||||
|
||||
if (playerStatus != PlayerStatus.INDETERMINATE) {
|
||||
setPlayerStatus(PlayerStatus.INDETERMINATE, media);
|
||||
}
|
||||
@ -990,7 +991,7 @@ public class PlaybackServiceMediaPlayer implements SharedPreferences.OnSharedPre
|
||||
|
||||
}
|
||||
audioManager.abandonAudioFocus(audioFocusChangeListener);
|
||||
callback.endPlayback(true, wasSkipped);
|
||||
callback.endPlayback(isPlaying, wasSkipped);
|
||||
|
||||
playerLock.unlock();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user