feat: 变更文本显示为 string value,删除一些无用的代码引用

pull/1894/head
谢意帆 3 years ago
parent 1c8a0fd000
commit ac27c115e4
  1. 9
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  2. 25
      app/src/main/java/io/legado/app/ui/book/remote/RemoteBookActivity.kt
  3. 7
      app/src/main/java/io/legado/app/ui/book/remote/RemoteBookAdapter.kt
  4. 13
      app/src/main/java/io/legado/app/ui/book/remote/RemoteBookViewModel.kt
  5. 5
      app/src/main/res/layout/item_remote_book.xml
  6. 2
      app/src/main/res/menu/book_info.xml
  7. 2
      app/src/main/res/menu/main_bookshelf.xml
  8. 7
      app/src/main/res/values/strings.xml

@ -204,12 +204,11 @@ class BookInfoActivity :
R.id.menu_upload -> {
launch {
val uri = Uri.parse(viewModel.bookData.value?.bookUrl.toString())
// val doc = DocumentFile.fromTreeUri(appCtx,uri)
if (RemoteBookWebDav.upload(uri))
toastOnUi(getString(R.string.upload_book_success))
else
toastOnUi(getString(R.string.upload_book_fail))
// if (uri.isContentScheme()){
// uri.path
// }
RemoteBookWebDav.upload(uri)
}
}
}

@ -4,12 +4,15 @@ import android.annotation.SuppressLint
import android.os.Bundle
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.databinding.ActivityRemoteBookBinding
import io.legado.app.utils.toastOnUi
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.launch
/**
@ -28,42 +31,34 @@ class RemoteBookActivity : VMBaseActivity<ActivityRemoteBookBinding,RemoteBookVi
// initEvent()
initData()
// toastOnUi("远程书籍")
onFinally()
}
private fun initView() {
binding.recyclerView.layoutManager = LinearLayoutManager(this)
binding.recyclerView.adapter = adapter
// binding.layTop.setBackgroundColor(backgroundColor)
// binding.recyclerView.layoutManager = LinearLayoutManager(this)
// binding.recyclerView.adapter = adapter
// binding.selectActionBar.setMainActionText(R.string.add_to_shelf)
// binding.selectActionBar.inflateMenu(R.menu.import_book_sel)
// binding.selectActionBar.setOnMenuItemClickListener(this)
// binding.selectActionBar.setCallBack(this)
}
private fun initData() {
// viewModel.getRemoteBooks().observe(this, {
// adapter.submitList(it)
// })
binding.refreshProgressBar.isAutoLoading = true
viewModel.loadRemoteBookList()
launch {
viewModel.dataFlow.collect { remoteBooks ->
viewModel.dataFlow.conflate().collect { remoteBooks ->
adapter.setItems(remoteBooks)
}
binding.refreshProgressBar.isAutoLoading = false
}
// toastOnUi("1")
}
private fun onFinally() {
}
@SuppressLint("NotifyDataSetChanged")
override fun addToBookshelf(remoteBook: RemoteBook) {
viewModel.addToBookshelf(remoteBook){
toastOnUi(getString(R.string.download_book_fail))
adapter.notifyDataSetChanged()
}
}

@ -5,12 +5,8 @@ import android.view.ViewGroup
import cn.hutool.core.date.LocalDateTimeUtil
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.data.entities.Book
import io.legado.app.databinding.ItemRemoteBookBinding
import io.legado.app.utils.ConvertUtils
import io.legado.app.utils.FileUtils
import io.legado.app.utils.toastOnUi
import splitties.init.appCtx
/**
@ -38,6 +34,7 @@ class RemoteBookAdapter (context: Context, val callBack: CallBack) :
payloads: MutableList<Any>
) {
binding.run {
//Todo:需要判断书籍是否已经加入书架,来改变“下载”按钮的文本,暂时还没有比较好的方案
tvName.text = item.filename.substringBeforeLast(".")
tvContentType.text = item.contentType
tvSize.text = ConvertUtils.formatFileSize(item.size)
@ -48,9 +45,7 @@ class RemoteBookAdapter (context: Context, val callBack: CallBack) :
override fun registerListener(holder: ItemViewHolder, binding: ItemRemoteBookBinding) {
binding.btnDownload.setOnClickListener {
getItem(holder.layoutPosition)?.let {
context.toastOnUi("开始加入")
callBack.addToBookshelf(it)
context.toastOnUi("加入成功")
}
}

@ -2,30 +2,21 @@ package io.legado.app.ui.book.remote
import android.app.Application
import android.net.Uri
import android.util.Log
import androidx.lifecycle.MutableLiveData
import io.legado.app.base.BaseViewModel
import io.legado.app.constant.PreferKey
import io.legado.app.lib.webdav.Authorization
import io.legado.app.lib.webdav.WebDav
import io.legado.app.model.localBook.LocalBook
import io.legado.app.ui.book.remote.manager.RemoteBookWebDav
import io.legado.app.utils.FileUtils
import io.legado.app.utils.externalFiles
import io.legado.app.utils.getPrefString
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.flowOn
import splitties.init.appCtx
import java.io.File
import java.nio.charset.Charset
import java.util.*
class RemoteBookViewModel(application: Application): BaseViewModel(application){
private val remoteBookFolderName = "book_remote"
private var dataCallback : DataCallback? = null
var isRemoteBookLiveData = MutableLiveData<Boolean>()
var dataFlowStart: (() -> Unit)? = null
private var authorization: Authorization? = null
val dataFlow = callbackFlow<List<RemoteBook>> {

@ -55,7 +55,7 @@
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:text=""
android:text="@string/separator"
android:textColor="@color/tv_text_summary"
android:textSize="11sp" />
@ -102,7 +102,8 @@
android:id="@+id/btn_download"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="加入书架">
tools:text="加入书架"
android:text="@string/nb_file_add_shelf">
</Button>
</LinearLayout>

@ -16,7 +16,7 @@
<item
android:id="@+id/menu_upload"
android:title="上传到云"
android:title="@string/upload_to_remote"
app:showAsAction="never" />
<item

@ -13,7 +13,7 @@
<item
android:id="@+id/menu_remote"
android:icon="@drawable/ic_add"
android:title="远程书籍"
android:title="@string/add_remote_book"
app:showAsAction="always" />
<item

@ -6,6 +6,13 @@
<string name="tip_perm_request_storage">Legado needs storage access to find and read books. please go "App Settings" to allow "Storage permission".</string>
<!--Other-->
<string name="upload_book_success" translatable="false">Upload Success</string>
<string name="upload_book_fail" translatable="false">Upload Fail</string>
<string name="download_book_success" translatable="false">Download Success</string>
<string name="download_book_fail" translatable="false">Download Fail</string>
<string name="separator" translatable="false"></string>
<string name="upload_to_remote" translatable="false">Upload</string>
<string name="add_remote_book" translatable="false">Add Remote</string>
<string name="menu_backup">Home</string>
<string name="menu_restore">Restore</string>
<string name="menu_import_old">Import Legado data</string>

Loading…
Cancel
Save