1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 16:40:32 +00:00

Address code review comments

This commit is contained in:
Isira Seneviratne 2024-08-28 18:14:36 +05:30
parent 5fffee2c7d
commit b1add13bfd
3 changed files with 18 additions and 22 deletions

View File

@ -553,28 +553,27 @@ public class MainActivity extends AppCompatActivity {
// In case bottomSheet is not visible on the screen or collapsed we can assume that the user // In case bottomSheet is not visible on the screen or collapsed we can assume that the user
// interacts with a fragment inside fragment_holder so all back presses should be // interacts with a fragment inside fragment_holder so all back presses should be
// handled by it // handled by it
final var fragmentManager = getSupportFragmentManager();
if (bottomSheetHiddenOrCollapsed()) { if (bottomSheetHiddenOrCollapsed()) {
final var fm = getSupportFragmentManager(); final var fragment = fragmentManager.findFragmentById(R.id.fragment_holder);
final var fragment = fm.findFragmentById(R.id.fragment_holder);
// If current fragment implements BackPressable (i.e. can/wanna handle back press) // If current fragment implements BackPressable (i.e. can/wanna handle back press)
// delegate the back press to it // delegate the back press to it
if (fragment instanceof BackPressable backPressable && backPressable.onBackPressed()) { if (fragment instanceof BackPressable backPressable && backPressable.onBackPressed()) {
return; return;
} }
} else { } else {
final var fragmentPlayer = getSupportFragmentManager() final var player = fragmentManager.findFragmentById(R.id.fragment_player_holder);
.findFragmentById(R.id.fragment_player_holder);
// If current fragment implements BackPressable (i.e. can/wanna handle back press) // If current fragment implements BackPressable (i.e. can/wanna handle back press)
// delegate the back press to it // delegate the back press to it
if (fragmentPlayer instanceof BackPressable backPressable if (player instanceof BackPressable backPressable && !backPressable.onBackPressed()) {
&& !backPressable.onBackPressed()) {
BottomSheetBehavior.from(mainBinding.fragmentPlayerHolder) BottomSheetBehavior.from(mainBinding.fragmentPlayerHolder)
.setState(BottomSheetBehavior.STATE_COLLAPSED); .setState(BottomSheetBehavior.STATE_COLLAPSED);
return; return;
} }
} }
if (getSupportFragmentManager().getBackStackEntryCount() == 1) { if (fragmentManager.getBackStackEntryCount() == 1) {
finish(); finish();
} else { } else {
super.onBackPressed(); super.onBackPressed();

View File

@ -73,7 +73,6 @@ import org.schabi.newpipe.error.ReCaptchaActivity;
import org.schabi.newpipe.error.UserAction; import org.schabi.newpipe.error.UserAction;
import org.schabi.newpipe.extractor.Image; import org.schabi.newpipe.extractor.Image;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException; import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException;
import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.stream.AudioStream; import org.schabi.newpipe.extractor.stream.AudioStream;
@ -1011,19 +1010,6 @@ public final class VideoDetailFragment
updateTabLayoutVisibility(); updateTabLayoutVisibility();
} }
public void scrollToComment(final CommentsInfoItem comment) {
final int commentsTabPos = pageAdapter.getItemPositionByTitle(COMMENTS_TAB_TAG);
final var fragment = pageAdapter.getItem(commentsTabPos);
// TODO: Implement the scrolling with Compose.
// unexpand the app bar only if scrolling to the comment succeeded
// if (fragment instanceof CommentsFragment commentsFragment &&
// commentsFragment.scrollToComment(comment)) {
// binding.appBarLayout.setExpanded(false, false);
// binding.viewPager.setCurrentItem(commentsTabPos, false);
// }
}
/*////////////////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////////////////
// Play Utils // Play Utils
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/

View File

@ -27,6 +27,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.flowOf
import my.nanihadesuka.compose.LazyColumnScrollbar import my.nanihadesuka.compose.LazyColumnScrollbar
import org.schabi.newpipe.R import org.schabi.newpipe.R
import org.schabi.newpipe.extractor.Page
import org.schabi.newpipe.extractor.comments.CommentsInfoItem import org.schabi.newpipe.extractor.comments.CommentsInfoItem
import org.schabi.newpipe.extractor.stream.Description import org.schabi.newpipe.extractor.stream.Description
import org.schabi.newpipe.paging.CommentsDisabledException import org.schabi.newpipe.paging.CommentsDisabledException
@ -91,7 +92,17 @@ private class CommentDataProvider : PreviewParameterProvider<PagingData<Comments
override val values = sequenceOf( override val values = sequenceOf(
// Normal view // Normal view
PagingData.from( PagingData.from(
(1..100).map { listOf(
CommentsInfoItem(
commentText = Description(
"Comment 1\n\nThis line should be hidden by default.",
Description.PLAIN_TEXT
),
uploaderName = "Test",
replies = Page(""),
replyCount = 10
)
) + (2..10).map {
CommentsInfoItem( CommentsInfoItem(
commentText = Description("Comment $it", Description.PLAIN_TEXT), commentText = Description("Comment $it", Description.PLAIN_TEXT),
uploaderName = "Test" uploaderName = "Test"