diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 25a901c78..68ca73cbb 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -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) } } } diff --git a/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookActivity.kt index c9a7f5f56..0ebcd901e 100644 --- a/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookActivity.kt @@ -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 + 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() } } diff --git a/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookAdapter.kt index 010c15029..36dd38f86 100644 --- a/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookAdapter.kt @@ -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 ) { 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("加入成功") } } diff --git a/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookViewModel.kt index 34493aec3..44f4071b6 100644 --- a/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/remote/RemoteBookViewModel.kt @@ -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() var dataFlowStart: (() -> Unit)? = null - private var authorization: Authorization? = null val dataFlow = callbackFlow> { diff --git a/app/src/main/res/layout/item_remote_book.xml b/app/src/main/res/layout/item_remote_book.xml index ca84c2e51..ef032b4e3 100644 --- a/app/src/main/res/layout/item_remote_book.xml +++ b/app/src/main/res/layout/item_remote_book.xml @@ -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"> diff --git a/app/src/main/res/menu/book_info.xml b/app/src/main/res/menu/book_info.xml index 675763611..80633d3cb 100644 --- a/app/src/main/res/menu/book_info.xml +++ b/app/src/main/res/menu/book_info.xml @@ -16,7 +16,7 @@ Legado needs storage access to find and read books. please go "App Settings" to allow "Storage permission". + Upload Success + Upload Fail + Download Success + Download Fail + + Upload + Add Remote Home Restore Import Legado data