feat: 优化

pull/219/head
kunfei 5 years ago
parent 408720e25b
commit 606324e943
  1. 5
      app/src/main/java/io/legado/app/help/ImageLoader.kt
  2. 31
      app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt

@ -7,6 +7,8 @@ import android.net.Uri
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.RequestBuilder import com.bumptech.glide.RequestBuilder
import io.legado.app.utils.isAbsUrl
import io.legado.app.utils.isContentPath
import java.io.File import java.io.File
object ImageLoader { object ImageLoader {
@ -14,7 +16,8 @@ object ImageLoader {
fun load(context: Context, path: String?): RequestBuilder<Drawable> { fun load(context: Context, path: String?): RequestBuilder<Drawable> {
return when { return when {
path.isNullOrEmpty() -> Glide.with(context).load(path) 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 { else -> try {
Glide.with(context).load(File(path)) Glide.with(context).load(File(path))
} catch (e: Exception) { } catch (e: Exception) {

@ -1,6 +1,7 @@
package io.legado.app.ui.book.info.edit package io.legado.app.ui.book.info.edit
import android.app.Activity import android.app.Activity
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
@ -16,6 +17,9 @@ import org.jetbrains.anko.sdk27.listeners.onClick
class BookInfoEditActivity : class BookInfoEditActivity :
VMBaseActivity<BookInfoEditViewModel>(R.layout.activity_book_info_edit), VMBaseActivity<BookInfoEditViewModel>(R.layout.activity_book_info_edit),
ChangeCoverDialog.CallBack { ChangeCoverDialog.CallBack {
private val resultSelectCover = 132
override val viewModel: BookInfoEditViewModel override val viewModel: BookInfoEditViewModel
get() = getViewModel(BookInfoEditViewModel::class.java) get() = getViewModel(BookInfoEditViewModel::class.java)
@ -47,6 +51,13 @@ class BookInfoEditActivity :
ChangeCoverDialog.show(supportFragmentManager, it.name, it.author) 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) { 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) { override fun coverChangeTo(coverUrl: String) {
viewModel.book?.customCoverUrl = coverUrl viewModel.book?.customCoverUrl = coverUrl
tie_cover_url.setText(coverUrl) tie_cover_url.setText(coverUrl)
upCover() 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())
}
}
}
}
}
} }
Loading…
Cancel
Save