11package com .zjy .pdfview ;
22
3+ import static android .view .ViewGroup .LayoutParams .MATCH_PARENT ;
4+ import static android .view .ViewGroup .LayoutParams .WRAP_CONTENT ;
5+ import static com .zjy .pdfview .constants .Constants .DOWNLOAD_ACTION ;
6+ import static com .zjy .pdfview .download .DownloadService .DOWNLOAD_URL_KEY ;
7+
38import android .content .Context ;
49import android .content .Intent ;
510import android .content .IntentFilter ;
1217import android .text .TextUtils ;
1318import android .util .AttributeSet ;
1419import android .view .LayoutInflater ;
15- import android .view .View ;
1620import android .view .ViewGroup ;
1721import android .widget .FrameLayout ;
1822
1923import androidx .annotation .NonNull ;
2024import androidx .annotation .Nullable ;
2125import androidx .annotation .RequiresApi ;
22- import androidx .constraintlayout .widget .ConstraintLayout ;
23- import androidx .constraintlayout .widget .ConstraintSet ;
2426import androidx .recyclerview .widget .RecyclerView ;
2527
2628import com .zjy .pdfview .adapter .PdfPageAdapter ;
4143import java .util .ArrayList ;
4244import java .util .List ;
4345
44- import static android .view .ViewGroup .LayoutParams .MATCH_PARENT ;
45- import static android .view .ViewGroup .LayoutParams .WRAP_CONTENT ;
46- import static com .zjy .pdfview .constants .Constants .DOWNLOAD_ACTION ;
47- import static com .zjy .pdfview .download .DownloadService .DOWNLOAD_URL_KEY ;
48-
4946/**
5047 * Date: 2021/1/27
5148 * Author: Yang
@@ -144,12 +141,9 @@ public void onPageSelected(int position, boolean isBottom) {
144141 });
145142 contentRv .setLayoutManager (pageLayoutManager );
146143
147- loadingLayout .setLoadLayoutListener (new PdfLoadingLayout .LoadLayoutListener () {
148- @ Override
149- public void clickRetry () {
150- if (!TextUtils .isEmpty (pdfUrl )) {
151- loadPdf (pdfUrl );
152- }
144+ loadingLayout .setLoadLayoutListener (() -> {
145+ if (!TextUtils .isEmpty (pdfUrl )) {
146+ loadPdf (pdfUrl );
153147 }
154148 });
155149
@@ -159,19 +153,17 @@ public void clickRetry() {
159153
160154 getOperateView ().addOperateListener (this );
161155
162- scrollSlider .setScrollSlideListener (new ScrollSlider .ScrollSlideListener () {
163- @ Override
164- public boolean scrolling (int scrollY ) {
165- int pageItemHeight = contentRv .getHeight () / pageCount ;
166- int scrollIndex = (int ) scrollY / pageItemHeight ;
167- if (scrollIndex >= 0 && scrollIndex < pageLayoutManager .getItemCount ()) {
168- scrollSlider .setTranslationY (scrollY - scrollY % pageItemHeight );
169- currentIndex = scrollIndex ;
170- pageLayoutManager .scrollToPosition (currentIndex );
171- getOperateView ().setPageIndexText (generatePageIndexText ());
172- }
173- return true ;
156+ scrollSlider .setScrollSlideListener (scrollY -> {
157+ if (pageCount == 0 ) return true ;
158+ int pageItemHeight = contentRv .getHeight () / pageCount ;
159+ int scrollIndex = scrollY / pageItemHeight ;
160+ if (scrollIndex >= 0 && scrollIndex < pageLayoutManager .getItemCount ()) {
161+ scrollSlider .setTranslationY (scrollY - scrollY % pageItemHeight );
162+ currentIndex = scrollIndex ;
163+ pageLayoutManager .scrollToPosition (currentIndex );
164+ getOperateView ().setPageIndexText (generatePageIndexText ());
174165 }
166+ return true ;
175167 });
176168 }
177169
@@ -342,6 +334,8 @@ protected Boolean doInBackground(Void... voids) {
342334 @ Override
343335 protected void onPostExecute (Boolean result ) {
344336 super .onPostExecute (result );
337+ scrollSlider .setVisibility (pageCount == 0 ? GONE : VISIBLE );
338+
345339 if (result ) {
346340 getOperateView ().setPageIndexText (generatePageIndexText ());
347341 pageAdapter .notifyDataSetChanged ();
0 commit comments