修改书籍更新问题

old
zlj 5 years ago
parent 97379e1146
commit 0fa8900c43
  1. 43
      app/src/main/java/com/novel/read/activity/NovelReadActivity.kt
  2. 9
      app/src/main/java/com/novel/read/model/db/dbManage/BookRepository.java

@ -63,7 +63,7 @@ class NovelReadActivity : NovelBaseActivity(), DownloadService.OnDownloadListene
private lateinit var mCategoryAdapter: CategoryAdapter
private val mChapters = ArrayList<TxtChapter>()
private var mCurrentChapter: TxtChapter? = null //当前章节
private lateinit var mCurrentChapter: TxtChapter //当前章节
private var currentChapter = 0
private lateinit var mMarkAdapter: MarkAdapter
private val mMarks = ArrayList<BookSignTable>()
@ -73,7 +73,7 @@ class NovelReadActivity : NovelBaseActivity(), DownloadService.OnDownloadListene
private var mBottomInAnim: Animation? = null
private var mBottomOutAnim: Animation? = null
private var mSettingDialog: ReadSettingDialog? = null
private lateinit var mSettingDialog: ReadSettingDialog
private var isCollected = false // isFromSDCard
private var isNightMode = false
private var isFullScreen = false
@ -133,7 +133,7 @@ class NovelReadActivity : NovelBaseActivity(), DownloadService.OnDownloadListene
//半透明化StatusBar
SystemBarUtils.transparentStatusBar(this)
//隐藏StatusBar
read_pv_page!!.post { this.hideSystemBar() }
read_pv_page.post { this.hideSystemBar() }
read_abl_top_menu.setPadding(0, ScreenUtils.statusBarHeight, 0, 0)
ll_download.setPadding(0, ScreenUtils.statusBarHeight, 0, ScreenUtils.dpToPx(15))
@ -195,9 +195,13 @@ class NovelReadActivity : NovelBaseActivity(), DownloadService.OnDownloadListene
object : PageLoader.OnPageChangeListener {
override fun onChapterChange(pos: Int) {
mCategoryAdapter.setChapter(pos)
mCurrentChapter = mChapters[pos]
currentChapter = pos
var index: Int = pos
if (pos >= mChapters.size) {
index = mChapters.size - 1
}
mCategoryAdapter.setChapter(index)
mCurrentChapter = mChapters[index]
currentChapter = index
}
override fun requestChapters(requestChapters: List<TxtChapter>) {
@ -256,7 +260,7 @@ class NovelReadActivity : NovelBaseActivity(), DownloadService.OnDownloadListene
ll_light.visibility = GONE
rlReadMark.visibility = GONE
toggleMenu(false)
mSettingDialog!!.show()
mSettingDialog.show()
}
read_setting_sb_brightness.setOnSeekBarChangeListener(object :
@ -303,15 +307,13 @@ class NovelReadActivity : NovelBaseActivity(), DownloadService.OnDownloadListene
}
tvAddMark.setOnClickListener {
if (mCurrentChapter != null) {
mMarkAdapter.edit = false
if (BookRepository.getInstance().getSignById(mCurrentChapter!!.chapterId)) {
showToast(getString(R.string.sign_exist))
return@setOnClickListener
}
BookRepository.getInstance().addSign(mBookId, mCurrentChapter!!.chapterId, mCurrentChapter!!.title)
updateMark()
mMarkAdapter.edit = false
if (BookRepository.getInstance().getSignById(mCurrentChapter.chapterId)) {
showToast(getString(R.string.sign_exist))
return@setOnClickListener
}
BookRepository.getInstance().addSign(mBookId, mCurrentChapter.chapterId, mCurrentChapter.title)
updateMark()
}
tvClear.setOnClickListener {
@ -426,8 +428,8 @@ class NovelReadActivity : NovelBaseActivity(), DownloadService.OnDownloadListene
if (read_abl_top_menu.visibility == VISIBLE) {
toggleMenu(true)
return true
} else if (mSettingDialog!!.isShowing) {
mSettingDialog!!.dismiss()
} else if (mSettingDialog.isShowing) {
mSettingDialog.dismiss()
return true
}
return false
@ -500,8 +502,7 @@ class NovelReadActivity : NovelBaseActivity(), DownloadService.OnDownloadListene
// 如果是目录更新的情况,那么就需要存储更新数据
if (mCollBook.isUpdate && isCollected) {
BookRepository.getInstance()
.saveBookChaptersWithAsync(event.result!!.chapterBean, mCollBook)
BookRepository.getInstance().saveBookChaptersWithAsync(chapterBeans, mCollBook)
}
}
}
@ -544,8 +545,8 @@ class NovelReadActivity : NovelBaseActivity(), DownloadService.OnDownloadListene
toggleMenu(true)
return
}
} else if (mSettingDialog!!.isShowing) {
mSettingDialog!!.dismiss()
} else if (mSettingDialog.isShowing) {
mSettingDialog.dismiss()
return
} else if (read_dl_slide.isDrawerOpen(GravityCompat.START)) {
read_dl_slide.closeDrawer(GravityCompat.START)

@ -120,11 +120,18 @@ public class BookRepository {
* @param beans
*/
public void saveBookChaptersWithAsync(List<BookChapterBean> beans, CollBookBean collBookBean) {
LitePal.deleteAll(CollBookBean.class, "bookId=?", collBookBean.getId());
collBookBean.setBookChapters(beans);
collBookBean.saveOrUpdate("bookId=?", collBookBean.getId());
for (int i = 0; i < collBookBean.getBookChapters().size(); i++) {
collBookBean.getBookChapters().get(i).setCollBookBean(collBookBean);
collBookBean.getBookChapters().get(i).saveOrUpdateAsync("bookId=?", collBookBean.getId());
}
LitePal.saveAllAsync(collBookBean.getBookChapters()).listen(new SaveCallback() {
@Override
public void onFinish(boolean success) {
Log.e(TAG, "saveCollBookWithAsync: " + success);
}
});
}
/**

Loading…
Cancel
Save