From 606324e943e530ec5132980e674e91c0f26d9ddc Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 10 May 2020 16:32:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/ImageLoader.kt | 5 ++- .../ui/book/info/edit/BookInfoEditActivity.kt | 31 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/help/ImageLoader.kt b/app/src/main/java/io/legado/app/help/ImageLoader.kt index 3d4272e9e..49b315a3f 100644 --- a/app/src/main/java/io/legado/app/help/ImageLoader.kt +++ b/app/src/main/java/io/legado/app/help/ImageLoader.kt @@ -7,6 +7,8 @@ import android.net.Uri import androidx.annotation.DrawableRes import com.bumptech.glide.Glide import com.bumptech.glide.RequestBuilder +import io.legado.app.utils.isAbsUrl +import io.legado.app.utils.isContentPath import java.io.File object ImageLoader { @@ -14,7 +16,8 @@ object ImageLoader { fun load(context: Context, path: String?): RequestBuilder { return when { path.isNullOrEmpty() -> Glide.with(context).load(path) - path.startsWith("http", true) -> Glide.with(context).load(path) + path.isAbsUrl() -> Glide.with(context).load(path) + path.isContentPath() -> Glide.with(context).load(Uri.parse(path)) else -> try { Glide.with(context).load(File(path)) } catch (e: Exception) { diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt index 969b1ee45..e0b76ce1f 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt @@ -1,6 +1,7 @@ package io.legado.app.ui.book.info.edit import android.app.Activity +import android.content.Intent import android.os.Bundle import android.view.Menu import android.view.MenuItem @@ -16,6 +17,9 @@ import org.jetbrains.anko.sdk27.listeners.onClick class BookInfoEditActivity : VMBaseActivity(R.layout.activity_book_info_edit), ChangeCoverDialog.CallBack { + + private val resultSelectCover = 132 + override val viewModel: BookInfoEditViewModel get() = getViewModel(BookInfoEditViewModel::class.java) @@ -47,6 +51,13 @@ class BookInfoEditActivity : ChangeCoverDialog.show(supportFragmentManager, it.name, it.author) } } + tv_select_cover.onClick { + selectImage() + } + tv_refresh_cover.onClick { + tie_cover_url.setText(viewModel.book?.customCoverUrl) + upCover() + } } private fun upView(book: Book) { @@ -77,9 +88,29 @@ class BookInfoEditActivity : } } + private fun selectImage() { + val intent = Intent(Intent.ACTION_GET_CONTENT) + intent.addCategory(Intent.CATEGORY_OPENABLE) + intent.type = "image/*" + startActivityForResult(intent, resultSelectCover) + } + override fun coverChangeTo(coverUrl: String) { viewModel.book?.customCoverUrl = coverUrl tie_cover_url.setText(coverUrl) upCover() } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + when (requestCode) { + resultSelectCover -> { + if (resultCode == Activity.RESULT_OK) { + data?.data?.let { uri -> + coverChangeTo(uri.toString()) + } + } + } + } + } } \ No newline at end of file