From 9411c907a02fde455357a52e2dbf6ccae9074328 Mon Sep 17 00:00:00 2001 From: fengyuecanzhu <1021300691@qq.com> Date: Sun, 16 May 2021 14:15:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xyz/fycz/myreader/common/APPCONST.java | 4 --- .../ui/activity/BookDetailedActivity.java | 32 ++++++++++++------- .../ui/activity/BookInfoEditActivity.java | 3 +- .../ui/activity/BookstoreActivity.java | 2 +- .../myreader/ui/activity/CatalogActivity.java | 3 +- .../myreader/ui/activity/MainActivity.java | 3 +- .../myreader/ui/activity/ReadActivity.java | 7 ++-- .../ui/adapter/BookcaseDetailedAdapter.java | 5 +-- .../ui/adapter/BookcaseDragAdapter.java | 5 +-- 9 files changed, 37 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/xyz/fycz/myreader/common/APPCONST.java b/app/src/main/java/xyz/fycz/myreader/common/APPCONST.java index 8392c3b..b4f0ff3 100644 --- a/app/src/main/java/xyz/fycz/myreader/common/APPCONST.java +++ b/app/src/main/java/xyz/fycz/myreader/common/APPCONST.java @@ -47,12 +47,8 @@ public class APPCONST { public static final String THIRD_SOURCE = "ThirdSource"; public static final String DATA_KEY = "data_key"; - public static final String BOOK = "book"; - public static final String TITLE = "title"; public static final String FIND_CRAWLER = "findCrawler"; public static final String CHAPTER_PAGE = "chapter_page"; - public static final String SETTING = "setting"; - public static final String SEARCH_BOOK_BEAN = "SearchBookBean"; public static final String SOURCE_INDEX = "sourceIndex"; public static final String FONT = "font"; public static final String BOOK_SOURCE = "bookSource"; diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/BookDetailedActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/BookDetailedActivity.java index 848dee4..dafac65 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/BookDetailedActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/BookDetailedActivity.java @@ -156,16 +156,10 @@ public class BookDetailedActivity extends BaseActivity { super.initData(savedInstanceState); mBookService = BookService.getInstance(); mChapterService = ChapterService.getInstance(); - aBooks = (ArrayList) BitIntentDataManager.getInstance().getData(getIntent()); - sourceIndex = getIntent().getIntExtra(APPCONST.SOURCE_INDEX, 0); - if (aBooks != null) { - mBook = aBooks.get(sourceIndex); - } else { - mBook = (Book) getIntent().getSerializableExtra(APPCONST.BOOK); - } - if (mBook == null) { + if (!initBook()){ ToastUtils.showError("无法获取书籍!"); finish(); + return; } isCollected = isBookCollected(); if (isCollected) { @@ -183,6 +177,21 @@ public class BookDetailedActivity extends BaseActivity { mReadCrawler = ReadCrawlerUtil.getReadCrawler(mBook.getSource()); } + private boolean initBook() { + Object obj = BitIntentDataManager.getInstance().getData(getIntent()); + sourceIndex = getIntent().getIntExtra(APPCONST.SOURCE_INDEX, 0); + if (obj == null) { + return false; + } + if (obj instanceof Book) { + mBook = (Book) obj; + } else if (obj instanceof List) { + aBooks = (ArrayList) obj; + mBook = aBooks.get(sourceIndex); + } + return mBook != null; + } + private void initTagList() { tagList.clear(); String type = mBook.getType(); @@ -376,8 +385,7 @@ public class BookDetailedActivity extends BaseActivity { */ public void goToMoreChapter() { Intent intent = new Intent(this, CatalogActivity.class); - intent.putExtra(APPCONST.BOOK, mBook); - //BitIntentDataManager.getInstance().putData(intent, mBook); + BitIntentDataManager.getInstance().putData(intent, mBook); startActivityForResult(intent, APPCONST.REQUEST_CHAPTER_PAGE); } @@ -560,7 +568,7 @@ public class BookDetailedActivity extends BaseActivity { mBookService.addBook(mBook); } Intent intent = new Intent(this, ReadActivity.class); - intent.putExtra(APPCONST.BOOK, mBook); + BitIntentDataManager.getInstance().putData(intent, mBook); intent.putExtra("isCollected", isCollected); startActivityForResult(intent, APPCONST.REQUEST_READ); } @@ -628,7 +636,7 @@ public class BookDetailedActivity extends BaseActivity { break; case R.id.action_edit: Intent editIntent = new Intent(this, BookInfoEditActivity.class); - editIntent.putExtra(APPCONST.BOOK, mBook); + BitIntentDataManager.getInstance().putData(editIntent, mBook); startActivityForResult(editIntent, APPCONST.REQUEST_EDIT_BOOK); break; case R.id.action_reload: //重新加载 diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/BookInfoEditActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/BookInfoEditActivity.java index 31dc37e..6d47afe 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/BookInfoEditActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/BookInfoEditActivity.java @@ -11,6 +11,7 @@ import androidx.appcompat.widget.Toolbar; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.App; import xyz.fycz.myreader.base.BaseActivity; +import xyz.fycz.myreader.base.BitIntentDataManager; import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.databinding.ActivityBookInfoEditBinding; import xyz.fycz.myreader.greendao.entity.Book; @@ -54,7 +55,7 @@ public class BookInfoEditActivity extends BaseActivity { @Override protected void initData(Bundle savedInstanceState) { super.initData(savedInstanceState); - mBook = (Book) getIntent().getSerializableExtra(APPCONST.BOOK); + mBook = (Book) BitIntentDataManager.getInstance().getData(getIntent()); if (mBook == null) { ToastUtils.showError("未读取到书籍信息"); finish(); diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/BookstoreActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/BookstoreActivity.java index 1317eab..9e75a69 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/BookstoreActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/BookstoreActivity.java @@ -362,7 +362,7 @@ public class BookstoreActivity extends BaseActivity { */ private void goToBookDetail(Book book) { Intent intent = new Intent(this, BookDetailedActivity.class); - intent.putExtra(APPCONST.BOOK, book); + BitIntentDataManager.getInstance().putData(intent, book); BookstoreActivity.this.startActivity(intent); } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/CatalogActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/CatalogActivity.java index c6aa433..81895c9 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/CatalogActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/CatalogActivity.java @@ -10,6 +10,7 @@ import androidx.appcompat.widget.Toolbar; import xyz.fycz.myreader.R; import xyz.fycz.myreader.base.BaseActivity; +import xyz.fycz.myreader.base.BitIntentDataManager; import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.databinding.ActivityCatalogBinding; import xyz.fycz.myreader.greendao.entity.Book; @@ -48,7 +49,7 @@ public class CatalogActivity extends BaseActivity { @Override protected void initData(Bundle savedInstanceState) { super.initData(savedInstanceState); - mBook = (Book) getIntent().getSerializableExtra(APPCONST.BOOK); + mBook = (Book) BitIntentDataManager.getInstance().getData(getIntent()); } diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/MainActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/MainActivity.java index 524e324..e93ea31 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/MainActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/MainActivity.java @@ -31,6 +31,7 @@ import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.App; import xyz.fycz.myreader.application.SysManager; import xyz.fycz.myreader.base.BaseActivity; +import xyz.fycz.myreader.base.BitIntentDataManager; import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.databinding.ActivityMainBinding; import xyz.fycz.myreader.entity.SharedBook; @@ -363,7 +364,7 @@ public class MainActivity extends BaseActivity { if (sharedBook != null && !StringHelper.isEmpty(sharedBook.getChapterUrl())) { Book book = SharedBook.sharedBookToBook(sharedBook); Intent intent = new Intent(this, BookDetailedActivity.class); - intent.putExtra(APPCONST.BOOK, book); + BitIntentDataManager.getInstance().putData(intent, book); startActivity(intent); } else { ToastUtils.showError("书籍加载失败"); diff --git a/app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java b/app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java index d57421c..27c3d43 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/activity/ReadActivity.java @@ -54,6 +54,7 @@ import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.App; import xyz.fycz.myreader.application.SysManager; import xyz.fycz.myreader.base.BaseActivity; +import xyz.fycz.myreader.base.BitIntentDataManager; import xyz.fycz.myreader.base.observer.MyObserver; import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.common.URLCONST; @@ -480,8 +481,8 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe mBook = bookTem; toggleMenu(true); Intent intent = new Intent(this, ReadActivity.class) - .putExtra(APPCONST.BOOK, mBook) .putExtra("hasChangeSource", true); + BitIntentDataManager.getInstance().putData(intent, mBook); if (!isCollected) { intent.putExtra("isCollected", false); } @@ -536,7 +537,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe //跳转 mHandler.postDelayed(() -> { Intent intent = new Intent(this, CatalogActivity.class); - intent.putExtra(APPCONST.BOOK, mBook); + BitIntentDataManager.getInstance().putData(intent, mBook); this.startActivityForResult(intent, APPCONST.REQUEST_CHAPTER_PAGE); }, mBottomOutAnim.getDuration()); }); @@ -909,7 +910,7 @@ public class ReadActivity extends BaseActivity implements ColorPickerDialogListe addLocalBook(path); } else { //路径为空,说明不是直接打开txt文件 - mBook = (Book) getIntent().getSerializableExtra(APPCONST.BOOK); + mBook = (Book) BitIntentDataManager.getInstance().getData(getIntent()); //mBook为空,说明是从快捷方式启动 if (mBook == null) { String bookId = SharedPreUtils.getInstance().getString(getString(R.string.lastRead), ""); diff --git a/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseDetailedAdapter.java b/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseDetailedAdapter.java index 32d4da3..19dcb99 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseDetailedAdapter.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseDetailedAdapter.java @@ -15,6 +15,7 @@ import java.util.ArrayList; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.App; +import xyz.fycz.myreader.base.BitIntentDataManager; import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.ui.activity.ReadActivity; import xyz.fycz.myreader.ui.dialog.DialogCreator; @@ -128,13 +129,13 @@ public class BookcaseDetailedAdapter extends BookcaseAdapter { } viewHolder.llBookRead.setOnClickListener(v -> { Intent intent = new Intent(mContext, ReadActivity.class); - intent.putExtra(APPCONST.BOOK, book); + BitIntentDataManager.getInstance().putData(intent, book); mBookService.updateEntity(book); mContext.startActivity(intent); }); viewHolder.ivBookImg.setOnClickListener(v -> { Intent intent = new Intent(mContext, BookDetailedActivity.class); - intent.putExtra(APPCONST.BOOK, book); + BitIntentDataManager.getInstance().putData(intent, book); mContext.startActivity(intent); }); viewHolder.llBookRead.setOnLongClickListener(v -> { diff --git a/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseDragAdapter.java b/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseDragAdapter.java index e767908..a80f7d2 100644 --- a/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseDragAdapter.java +++ b/app/src/main/java/xyz/fycz/myreader/ui/adapter/BookcaseDragAdapter.java @@ -13,6 +13,7 @@ import java.util.ArrayList; import xyz.fycz.myreader.R; import xyz.fycz.myreader.application.App; +import xyz.fycz.myreader.base.BitIntentDataManager; import xyz.fycz.myreader.common.APPCONST; import xyz.fycz.myreader.ui.activity.ReadActivity; import xyz.fycz.myreader.ui.dialog.DialogCreator; @@ -110,7 +111,7 @@ public class BookcaseDragAdapter extends BookcaseAdapter { } viewHolder.ivBookImg.setOnClickListener(v -> { Intent intent = new Intent(mContext, ReadActivity.class); - intent.putExtra(APPCONST.BOOK, book); + BitIntentDataManager.getInstance().putData(intent, book); mBookService.updateEntity(book); mContext.startActivity(intent); }); @@ -122,7 +123,7 @@ public class BookcaseDragAdapter extends BookcaseAdapter { switch (which) { case 0: Intent intent = new Intent(mContext, BookDetailedActivity.class); - intent.putExtra(APPCONST.BOOK, book); + BitIntentDataManager.getInstance().putData(intent, book); mContext.startActivity(intent); break; case 1: