pull/35/head
kunfei 5 years ago
parent cab4193ea1
commit 3efd936357
  1. 4
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  2. 2
      app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt
  3. 29
      app/src/main/java/io/legado/app/utils/ACache.kt

@ -126,7 +126,7 @@ data class BookSource(
try { try {
if (it.startsWith("<js>", false)) { if (it.startsWith("<js>", false)) {
val aCache = ACache.get(App.INSTANCE, "explore") val aCache = ACache.get(App.INSTANCE, "explore")
a = aCache.getAsString(bookSourceUrl) ?: "" a = aCache?.getAsString(bookSourceUrl) ?: ""
if (a.isBlank()) { if (a.isBlank()) {
val bindings = SimpleBindings() val bindings = SimpleBindings()
bindings["baseUrl"] = bookSourceUrl bindings["baseUrl"] = bookSourceUrl
@ -135,7 +135,7 @@ data class BookSource(
it.substring(4, it.lastIndexOf("<")), it.substring(4, it.lastIndexOf("<")),
bindings bindings
).toString() ).toString()
aCache.put(bookSourceUrl, a) aCache?.put(bookSourceUrl, a)
} }
} }
val b = a.split("(&&|\n)+".toRegex()) val b = a.split("(&&|\n)+".toRegex())

@ -48,7 +48,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca
R.id.menu_edit -> callBack.editSource(item.bookSourceUrl) R.id.menu_edit -> callBack.editSource(item.bookSourceUrl)
R.id.menu_top -> callBack.toTop(item) R.id.menu_top -> callBack.toTop(item)
R.id.menu_refresh -> { R.id.menu_refresh -> {
ACache.get(context, "explore").remove(item.bookSourceUrl) ACache.get(context, "explore")?.remove(item.bookSourceUrl)
notifyItemChanged(holder.layoutPosition) notifyItemChanged(holder.layoutPosition)
} }
} }

@ -336,7 +336,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
* @param value 保存的bitmap数据 * @param value 保存的bitmap数据
*/ */
fun put(key: String, value: Bitmap) { fun put(key: String, value: Bitmap) {
put(key, Utils.Bitmap2Bytes(value)) put(key, Utils.bitmap2Bytes(value))
} }
/** /**
@ -347,7 +347,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
* @param saveTime 保存的时间单位 * @param saveTime 保存的时间单位
*/ */
fun put(key: String, value: Bitmap, saveTime: Int) { fun put(key: String, value: Bitmap, saveTime: Int) {
put(key, Utils.Bitmap2Bytes(value), saveTime) put(key, Utils.bitmap2Bytes(value), saveTime)
} }
/** /**
@ -358,7 +358,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
fun getAsBitmap(key: String): Bitmap? { fun getAsBitmap(key: String): Bitmap? {
return if (getAsBinary(key) == null) { return if (getAsBinary(key) == null) {
null null
} else Utils.Bytes2Bimap(getAsBinary(key)!!) } else Utils.bytes2Bitmap(getAsBinary(key)!!)
} }
// ======================================= // =======================================
@ -395,7 +395,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
return if (getAsBinary(key) == null) { return if (getAsBinary(key) == null) {
null null
} else Utils.bitmap2Drawable( } else Utils.bitmap2Drawable(
Utils.Bytes2Bimap( Utils.bytes2Bitmap(
getAsBinary(key)!! getAsBinary(key)!!
) )
) )
@ -486,16 +486,17 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
fun newByteArrayWithDateInfo(second: Int, data2: ByteArray): ByteArray { fun newByteArrayWithDateInfo(second: Int, data2: ByteArray): ByteArray {
val data1 = createDateInfo(second).toByteArray() val data1 = createDateInfo(second).toByteArray()
val retdata = ByteArray(data1.size + data2.size) val retData = ByteArray(data1.size + data2.size)
System.arraycopy(data1, 0, retdata, 0, data1.size) System.arraycopy(data1, 0, retData, 0, data1.size)
System.arraycopy(data2, 0, retdata, data1.size, data2.size) System.arraycopy(data2, 0, retData, data1.size, data2.size)
return retdata return retData
} }
fun clearDateInfo(strInfo: String?): String? { fun clearDateInfo(strInfo: String?): String? {
var strInfo = strInfo strInfo?.let {
if (strInfo != null && hasDateInfo(strInfo.toByteArray())) { if (hasDateInfo(strInfo.toByteArray())) {
strInfo = strInfo.substring(strInfo.indexOf(mSeparator) + 1) return strInfo.substring(strInfo.indexOf(mSeparator) + 1)
}
} }
return strInfo return strInfo
} }
@ -559,7 +560,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
/* /*
* Bitmap byte[] * Bitmap byte[]
*/ */
fun Bitmap2Bytes(bm: Bitmap): ByteArray { fun bitmap2Bytes(bm: Bitmap): ByteArray {
val baos = ByteArrayOutputStream() val baos = ByteArrayOutputStream()
bm.compress(Bitmap.CompressFormat.PNG, 100, baos) bm.compress(Bitmap.CompressFormat.PNG, 100, baos)
return baos.toByteArray() return baos.toByteArray()
@ -568,8 +569,8 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int)
/* /*
* byte[] Bitmap * byte[] Bitmap
*/ */
fun Bytes2Bimap(b: ByteArray): Bitmap? { fun bytes2Bitmap(b: ByteArray): Bitmap? {
return if (b.size == 0) { return if (b.isEmpty()) {
null null
} else BitmapFactory.decodeByteArray(b, 0, b.size) } else BitmapFactory.decodeByteArray(b, 0, b.size)
} }

Loading…
Cancel
Save