feat: 优化代码

pull/98/head
kunfei 5 years ago
parent b029c6f865
commit 109784233c
  1. 1
      app/src/main/java/io/legado/app/constant/EventBus.kt
  2. 2
      app/src/main/java/io/legado/app/help/BookHelp.kt
  3. 6
      app/src/main/java/io/legado/app/ui/download/DownloadActivity.kt

@ -21,4 +21,5 @@ object EventBus {
const val WEB_SERVICE_STOP = "webServiceStop"
const val UP_DOWNLOAD = "upDownload"
const val UP_TABS = "upTabs"
const val SAVE_CONTENT = "saveContent"
}

@ -4,6 +4,7 @@ import android.net.Uri
import androidx.documentfile.provider.DocumentFile
import com.github.houbb.opencc4j.util.ZhConverterUtil
import io.legado.app.App
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
@ -68,6 +69,7 @@ object BookHelp {
subDirs = *arrayOf(cacheFolderName, bookFolderName(book))
).writeText(content)
}
postEvent(EventBus.SAVE_CONTENT, bookChapter)
}
fun getChapterFiles(book: Book): List<String> {

@ -11,6 +11,7 @@ import io.legado.app.R
import io.legado.app.base.BaseActivity
import io.legado.app.constant.EventBus
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.help.BookHelp
import io.legado.app.service.help.Download
import io.legado.app.utils.applyTint
@ -93,11 +94,14 @@ class DownloadActivity : BaseActivity(R.layout.activity_download) {
if (it) {
menu?.findItem(R.id.menu_download)?.setIcon(R.drawable.ic_stop_black_24dp)
menu?.applyTint(this)
adapter.notifyItemRangeChanged(0, adapter.itemCount, true)
adapter.notifyItemRangeChanged(0, adapter.getActualItemCount(), true)
} else {
menu?.findItem(R.id.menu_download)?.setIcon(R.drawable.ic_play_24dp)
menu?.applyTint(this)
}
}
observeEvent<BookChapter>(EventBus.SAVE_CONTENT) {
adapter.cacheChapters[it.bookUrl]?.add(it.url)
}
}
}
Loading…
Cancel
Save