Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Scroll to top feature in comments view #11654

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
Expand All @@ -28,6 +29,7 @@ public class CommentsFragment extends BaseListInfoFragment<CommentsInfoItem, Com
private final CompositeDisposable disposables = new CompositeDisposable();

private TextView emptyStateDesc;
private Button scrollToTopButton;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scrollToTopButton is not referenced anywhere other than the initViews method. You should remove the field and make it a local variable instead.


public static CommentsFragment getInstance(final int serviceId, final String url,
final String name) {
Expand All @@ -45,6 +47,9 @@ protected void initViews(final View rootView, final Bundle savedInstanceState) {
super.initViews(rootView, savedInstanceState);

emptyStateDesc = rootView.findViewById(R.id.empty_state_desc);
scrollToTopButton = rootView.findViewById(R.id.scrollToTopButton);

scrollToTopButton.setOnClickListener(v -> itemsList.scrollToPosition(0));
}

/*//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -120,4 +125,5 @@ public boolean scrollToComment(final CommentsInfoItem comment) {
itemsList.scrollToPosition(position);
return true;
}

}
11 changes: 11 additions & 0 deletions app/src/main/res/layout/fragment_comments.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,15 @@
android:background="?attr/toolbar_shadow"
android:visibility="gone" />

<Button
android:id="@+id/scrollToTopButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:onClick="onClick"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The onClick attribute is redundant since you're using setOnClickListener to listen for click events.

android:text="@string/scroll_to_top" />

</RelativeLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -857,4 +857,5 @@
<string name="show_more">Show more</string>
<string name="show_less">Show less</string>
<string name="import_settings_vulnerable_format">The settings in the export being imported use a vulnerable format that was deprecated since NewPipe 0.27.0. Make sure the export being imported is from a trusted source, and prefer using only exports obtained from NewPipe 0.27.0 or newer in the future. Support for importing settings in this vulnerable format will soon be removed completely, and then old versions of NewPipe will not be able to import settings of exports from new versions anymore.</string>
<string name="scroll_to_top">Scroll to top</string>
</resources>
Loading