Merge pull request #3997 from ByteHamster/more-performance
Some more performance improvements
This commit is contained in:
commit
69085ae73c
|
@ -102,7 +102,7 @@ public class AudioPlayerFragment extends Fragment implements
|
||||||
toolbar.setOnMenuItemClickListener(this);
|
toolbar.setOnMenuItemClickListener(this);
|
||||||
|
|
||||||
ExternalPlayerFragment externalPlayerFragment = new ExternalPlayerFragment();
|
ExternalPlayerFragment externalPlayerFragment = new ExternalPlayerFragment();
|
||||||
getFragmentManager().beginTransaction()
|
getChildFragmentManager().beginTransaction()
|
||||||
.replace(R.id.playerFragment, externalPlayerFragment, ExternalPlayerFragment.TAG)
|
.replace(R.id.playerFragment, externalPlayerFragment, ExternalPlayerFragment.TAG)
|
||||||
.commit();
|
.commit();
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ public class AudioPlayerFragment extends Fragment implements
|
||||||
sbPosition.setOnSeekBarChangeListener(this);
|
sbPosition.setOnSeekBarChangeListener(this);
|
||||||
|
|
||||||
pager = root.findViewById(R.id.pager);
|
pager = root.findViewById(R.id.pager);
|
||||||
AudioPlayerPagerAdapter pagerAdapter = new AudioPlayerPagerAdapter(getFragmentManager());
|
AudioPlayerPagerAdapter pagerAdapter = new AudioPlayerPagerAdapter(getChildFragmentManager());
|
||||||
pager.setAdapter(pagerAdapter);
|
pager.setAdapter(pagerAdapter);
|
||||||
// Required for getChildAt(int) in ViewPagerBottomSheetBehavior to return the correct page
|
// Required for getChildAt(int) in ViewPagerBottomSheetBehavior to return the correct page
|
||||||
pager.setOffscreenPageLimit(NUM_CONTENT_FRAGMENTS);
|
pager.setOffscreenPageLimit(NUM_CONTENT_FRAGMENTS);
|
||||||
|
@ -355,12 +355,10 @@ public class AudioPlayerFragment extends Fragment implements
|
||||||
updatePosition(new PlaybackPositionEvent(controller.getPosition(), controller.getDuration()));
|
updatePosition(new PlaybackPositionEvent(controller.getPosition(), controller.getDuration()));
|
||||||
updatePlaybackSpeedButton(media);
|
updatePlaybackSpeedButton(media);
|
||||||
setupOptionsMenu(media);
|
setupOptionsMenu(media);
|
||||||
|
|
||||||
if (media != null) {
|
|
||||||
List<Chapter> chapters = controller.getMedia().getChapters();
|
|
||||||
boolean hasChapters = chapters != null && !chapters.isEmpty();
|
|
||||||
pageIndicator.setDisabledPage(hasChapters ? -1 : 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setHasChapters(boolean hasChapters) {
|
||||||
|
pageIndicator.setDisabledPage(hasChapters ? -1 : 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -128,6 +128,7 @@ public class ChaptersFragment extends Fragment {
|
||||||
disposable = Maybe.create(emitter -> {
|
disposable = Maybe.create(emitter -> {
|
||||||
Playable media = controller.getMedia();
|
Playable media = controller.getMedia();
|
||||||
if (media != null) {
|
if (media != null) {
|
||||||
|
media.loadChapterMarks();
|
||||||
emitter.onSuccess(media);
|
emitter.onSuccess(media);
|
||||||
} else {
|
} else {
|
||||||
emitter.onComplete();
|
emitter.onComplete();
|
||||||
|
@ -146,6 +147,7 @@ public class ChaptersFragment extends Fragment {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
adapter.setMedia(media);
|
adapter.setMedia(media);
|
||||||
|
((AudioPlayerFragment) getParentFragment()).setHasChapters(adapter.getItemCount() > 0);
|
||||||
int positionOfCurrentChapter = getCurrentChapter(media);
|
int positionOfCurrentChapter = getCurrentChapter(media);
|
||||||
updateChapterSelection(positionOfCurrentChapter);
|
updateChapterSelection(positionOfCurrentChapter);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_alignParentTop="true"
|
android:layout_alignParentTop="true"
|
||||||
android:foreground="?android:windowContentOverlay"
|
android:foreground="?android:windowContentOverlay"
|
||||||
android:layout_marginBottom="@dimen/external_player_height"
|
|
||||||
tools:background="@android:color/holo_red_dark" />
|
tools:background="@android:color/holo_red_dark" />
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
|
@ -27,6 +26,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="?android:attr/windowBackground"
|
android:background="?android:attr/windowBackground"
|
||||||
|
android:visibility="gone"
|
||||||
app:layout_behavior="de.danoeh.antennapod.view.LockableBottomSheetBehavior" />
|
app:layout_behavior="de.danoeh.antennapod.view.LockableBottomSheetBehavior" />
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
|
|
|
@ -590,9 +590,6 @@ public final class DBReader {
|
||||||
if (!list.isEmpty()) {
|
if (!list.isEmpty()) {
|
||||||
item = list.get(0);
|
item = list.get(0);
|
||||||
loadAdditionalFeedItemListData(list);
|
loadAdditionalFeedItemListData(list);
|
||||||
if (item.hasChapters()) {
|
|
||||||
loadChaptersOfFeedItem(adapter, item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
|
@ -608,8 +605,7 @@ public final class DBReader {
|
||||||
* than one FeedItem because this method might query the database several times for each item.
|
* than one FeedItem because this method might query the database several times for each item.
|
||||||
*
|
*
|
||||||
* @param itemId The ID of the FeedItem
|
* @param itemId The ID of the FeedItem
|
||||||
* @return The FeedItem or null if the FeedItem could not be found. All FeedComponent-attributes
|
* @return The FeedItem or null if the FeedItem could not be found.
|
||||||
* as well as chapter marks of the FeedItem will also be loaded from the database.
|
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static FeedItem getFeedItem(final long itemId) {
|
public static FeedItem getFeedItem(final long itemId) {
|
||||||
|
|
|
@ -44,8 +44,6 @@ import org.greenrobot.eventbus.EventBus;
|
||||||
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
import org.greenrobot.eventbus.ThreadMode;
|
import org.greenrobot.eventbus.ThreadMode;
|
||||||
|
|
||||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Communicates with the playback service. GUI classes should use this class to
|
* Communicates with the playback service. GUI classes should use this class to
|
||||||
* control playback instead of communicating with the PlaybackService directly.
|
* control playback instead of communicating with the PlaybackService directly.
|
||||||
|
@ -53,18 +51,13 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||||
public class PlaybackController {
|
public class PlaybackController {
|
||||||
|
|
||||||
private static final String TAG = "PlaybackController";
|
private static final String TAG = "PlaybackController";
|
||||||
|
|
||||||
private static final int INVALID_TIME = -1;
|
private static final int INVALID_TIME = -1;
|
||||||
|
|
||||||
private final Activity activity;
|
private final Activity activity;
|
||||||
|
|
||||||
private PlaybackService playbackService;
|
private PlaybackService playbackService;
|
||||||
private Playable media;
|
private Playable media;
|
||||||
private PlayerStatus status = PlayerStatus.STOPPED;
|
private PlayerStatus status = PlayerStatus.STOPPED;
|
||||||
|
|
||||||
private final ScheduledThreadPoolExecutor schedExecutor;
|
|
||||||
private static final int SCHED_EX_POOLSIZE = 1;
|
|
||||||
|
|
||||||
private boolean mediaInfoLoaded = false;
|
private boolean mediaInfoLoaded = false;
|
||||||
private boolean released = false;
|
private boolean released = false;
|
||||||
private boolean initialized = false;
|
private boolean initialized = false;
|
||||||
|
@ -74,15 +67,7 @@ public class PlaybackController {
|
||||||
private Disposable mediaLoader;
|
private Disposable mediaLoader;
|
||||||
|
|
||||||
public PlaybackController(@NonNull Activity activity) {
|
public PlaybackController(@NonNull Activity activity) {
|
||||||
|
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
schedExecutor = new ScheduledThreadPoolExecutor(SCHED_EX_POOLSIZE,
|
|
||||||
r -> {
|
|
||||||
Thread t = new Thread(r);
|
|
||||||
t.setPriority(Thread.MIN_PRIORITY);
|
|
||||||
return t;
|
|
||||||
}, (r, executor) -> Log.w(TAG, "Rejected execution of runnable in schedExecutor")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -155,7 +140,6 @@ public class PlaybackController {
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
schedExecutor.shutdownNow();
|
|
||||||
media = null;
|
media = null;
|
||||||
released = true;
|
released = true;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue