Skip to content

Commit

Permalink
v1.0.2 build3
Browse files Browse the repository at this point in the history
  • Loading branch information
15dd committed Jun 1, 2023
1 parent c17deef commit f8c996d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

public class SearchActivity extends AppCompatActivity {
private TextInputEditText editText;
private boolean searchFlag = true;
public static boolean searchFlag = true;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class BookListFragment extends Fragment {
private RecyclerView list;
public int pageindex = 0;//上拉加载数据用,每上拉一次,索引值加1
public int maxindex = 1;
public int maxindex = 1;//总页数
private List<BookListClass> novelList = new ArrayList<>();
private View view;
private LinearLayoutManager layoutManager;
Expand Down Expand Up @@ -92,13 +92,14 @@ private void loadingMore() {
bookListAdapter.setLoadState(bookListAdapter.LOADING);
if (pageindex < maxindex) {
new addBook().start();
return;
} else {
bookListAdapter.setLoadState(bookListAdapter.LOADING_END);
}
bookListAdapter.notifyItemChanged(bookListAdapter.getItemCount() - 1);
}

private BookListAdapter bookListAdapter;

private class addBook extends Thread {

@Override
Expand Down Expand Up @@ -155,8 +156,13 @@ public boolean handleMessage(Message msg) {
bookListAdapter = new BookListAdapter(getContext(), novelList);
list.setAdapter(bookListAdapter);
list.setLayoutManager(layoutManager);
bookListAdapter.setLoadState(bookListAdapter.LOADING_COMPLETE);
bookListAdapter.notifyDataSetChanged();
if (maxindex == 1) {
bookListAdapter.setLoadState(bookListAdapter.LOADING_END);
bookListAdapter.notifyDataSetChanged();
} else {
bookListAdapter.setLoadState(bookListAdapter.LOADING_COMPLETE);
bookListAdapter.notifyDataSetChanged();
}

swipeRefreshLayout.setRefreshing(false);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.cyh128.wenku8reader.R;
import com.cyh128.wenku8reader.activity.ContentsActivity;
import com.cyh128.wenku8reader.activity.SearchActivity;
import com.cyh128.wenku8reader.adapter.BookListAdapter;
import com.cyh128.wenku8reader.classLibrary.BookListClass;
import com.cyh128.wenku8reader.util.Wenku8Spider;
Expand Down Expand Up @@ -83,18 +84,19 @@ private void loadingMore() {
if (pageindex < maxindex && isFiveSecondDone) {
waitFiveSecond();
new addBook().start();
return;
} else if (pageindex < maxindex && !isFiveSecondDone) {
bookListAdapter.setLoadState(bookListAdapter.WAIT_FIVE_SECOND);
bookListAdapter.notifyItemChanged(bookListAdapter.getItemCount() - 1);
canLoadmore = true;
} else {
bookListAdapter.setLoadState(bookListAdapter.LOADING_END);
bookListAdapter.notifyItemChanged(bookListAdapter.getItemCount() - 1);
}
bookListAdapter.notifyItemChanged(bookListAdapter.getItemCount() - 1);
}

private void waitFiveSecond() {
isFiveSecondDone = false;
SearchActivity.searchFlag = false; //下滑操作也会触发搜索小说的5秒等待机制,所以需要将搜索框的搜索也加入限制,即下滑操作或者搜索小说的五秒没过,不允许操作
new CountDownTimer(5500, 1000) {
@Override
public void onTick(long millisUntilFinished) {
Expand All @@ -103,6 +105,7 @@ public void onTick(long millisUntilFinished) {
@Override
public void onFinish() {
isFiveSecondDone = true;
SearchActivity.searchFlag = true;
if (bookListAdapter != null) {
if (bookListAdapter.loadState != bookListAdapter.LOADING_END) {
bookListAdapter.notifyItemRemoved(bookListAdapter.getItemCount());
Expand All @@ -113,7 +116,6 @@ public void onFinish() {
}

private BookListAdapter bookListAdapter;

private class addBook extends Thread {

@Override
Expand Down Expand Up @@ -175,11 +177,16 @@ public boolean handleMessage(Message msg) {
private final Handler firstLaunchHandler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {

bookListAdapter = new BookListAdapter(getContext(), novelList);
list.setAdapter(bookListAdapter);
list.setLayoutManager(layoutManager);
bookListAdapter.setLoadState(bookListAdapter.FIRST_PAGE);
if (maxindex == 1) {
bookListAdapter.setLoadState(bookListAdapter.LOADING_END);
bookListAdapter.notifyDataSetChanged();
} else {
bookListAdapter.setLoadState(bookListAdapter.LOADING_COMPLETE);
bookListAdapter.notifyDataSetChanged();
}

return false;
}
Expand All @@ -188,13 +195,11 @@ public boolean handleMessage(Message msg) {
private final Handler noContentHandler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {

bookListAdapter = new BookListAdapter(getContext(), novelList);
list.setAdapter(bookListAdapter);
list.setLayoutManager(layoutManager);
bookListAdapter.setLoadState(bookListAdapter.NONE);
bookListAdapter.notifyDataSetChanged();

return false;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ private void loadingMore() {
bookListAdapter.setLoadState(bookListAdapter.LOADING);
if (pageindex < maxindex) {
new addBook().start();
return;
} else {
bookListAdapter.setLoadState(bookListAdapter.LOADING_END);
}
bookListAdapter.notifyItemChanged(bookListAdapter.getItemCount() - 1);
}

private BookListAdapter bookListAdapter;

private class addBook extends Thread {

@Override
Expand Down Expand Up @@ -159,8 +160,14 @@ public boolean handleMessage(Message msg) {
bookListAdapter = new BookListAdapter(getContext(), novelList);
list.setAdapter(bookListAdapter);
list.setLayoutManager(layoutManager);
bookListAdapter.setLoadState(bookListAdapter.LOADING_COMPLETE);
bookListAdapter.notifyDataSetChanged();

if (maxindex == 1) {
bookListAdapter.setLoadState(bookListAdapter.LOADING_END);
bookListAdapter.notifyDataSetChanged();
} else {
bookListAdapter.setLoadState(bookListAdapter.LOADING_COMPLETE);
bookListAdapter.notifyDataSetChanged();
}

swipeRefreshLayout.setRefreshing(false);
return true;
Expand Down

0 comments on commit f8c996d

Please sign in to comment.