Merge pull request #3997 from ByteHamster/more-performance

Some more performance improvements
This commit is contained in:
H. Lehmann 2020-04-03 12:47:20 +02:00 committed by GitHub
commit 69085ae73c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 29 deletions

View File

@ -102,7 +102,7 @@ public class AudioPlayerFragment extends Fragment implements
toolbar.setOnMenuItemClickListener(this);
ExternalPlayerFragment externalPlayerFragment = new ExternalPlayerFragment();
getFragmentManager().beginTransaction()
getChildFragmentManager().beginTransaction()
.replace(R.id.playerFragment, externalPlayerFragment, ExternalPlayerFragment.TAG)
.commit();
@ -127,7 +127,7 @@ public class AudioPlayerFragment extends Fragment implements
sbPosition.setOnSeekBarChangeListener(this);
pager = root.findViewById(R.id.pager);
AudioPlayerPagerAdapter pagerAdapter = new AudioPlayerPagerAdapter(getFragmentManager());
AudioPlayerPagerAdapter pagerAdapter = new AudioPlayerPagerAdapter(getChildFragmentManager());
pager.setAdapter(pagerAdapter);
// Required for getChildAt(int) in ViewPagerBottomSheetBehavior to return the correct page
pager.setOffscreenPageLimit(NUM_CONTENT_FRAGMENTS);
@ -355,12 +355,10 @@ public class AudioPlayerFragment extends Fragment implements
updatePosition(new PlaybackPositionEvent(controller.getPosition(), controller.getDuration()));
updatePlaybackSpeedButton(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

View File

@ -128,6 +128,7 @@ public class ChaptersFragment extends Fragment {
disposable = Maybe.create(emitter -> {
Playable media = controller.getMedia();
if (media != null) {
media.loadChapterMarks();
emitter.onSuccess(media);
} else {
emitter.onComplete();
@ -146,6 +147,7 @@ public class ChaptersFragment extends Fragment {
return;
}
adapter.setMedia(media);
((AudioPlayerFragment) getParentFragment()).setHasChapters(adapter.getItemCount() > 0);
int positionOfCurrentChapter = getCurrentChapter(media);
updateChapterSelection(positionOfCurrentChapter);
}

View File

@ -18,7 +18,6 @@
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:foreground="?android:windowContentOverlay"
android:layout_marginBottom="@dimen/external_player_height"
tools:background="@android:color/holo_red_dark" />
<FrameLayout
@ -27,6 +26,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/windowBackground"
android:visibility="gone"
app:layout_behavior="de.danoeh.antennapod.view.LockableBottomSheetBehavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -590,9 +590,6 @@ public final class DBReader {
if (!list.isEmpty()) {
item = list.get(0);
loadAdditionalFeedItemListData(list);
if (item.hasChapters()) {
loadChaptersOfFeedItem(adapter, 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.
*
* @param itemId The ID of the FeedItem
* @return The FeedItem or null if the FeedItem could not be found. All FeedComponent-attributes
* as well as chapter marks of the FeedItem will also be loaded from the database.
* @return The FeedItem or null if the FeedItem could not be found.
*/
@Nullable
public static FeedItem getFeedItem(final long itemId) {

View File

@ -44,8 +44,6 @@ import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.concurrent.ScheduledThreadPoolExecutor;
/**
* Communicates with the playback service. GUI classes should use this class to
* control playback instead of communicating with the PlaybackService directly.
@ -53,18 +51,13 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
public class PlaybackController {
private static final String TAG = "PlaybackController";
private static final int INVALID_TIME = -1;
private final Activity activity;
private PlaybackService playbackService;
private Playable media;
private PlayerStatus status = PlayerStatus.STOPPED;
private final ScheduledThreadPoolExecutor schedExecutor;
private static final int SCHED_EX_POOLSIZE = 1;
private boolean mediaInfoLoaded = false;
private boolean released = false;
private boolean initialized = false;
@ -74,15 +67,7 @@ public class PlaybackController {
private Disposable mediaLoader;
public PlaybackController(@NonNull 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) {
// ignore
}
schedExecutor.shutdownNow();
media = null;
released = true;