Save manga page image
parent
ac935eb203
commit
013a734136
@ -0,0 +1,54 @@
|
|||||||
|
package org.koitharu.kotatsu.utils
|
||||||
|
|
||||||
|
import android.content.ContentResolver
|
||||||
|
import android.content.ContentValues
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
|
import android.provider.MediaStore
|
||||||
|
import android.webkit.MimeTypeMap
|
||||||
|
import org.koitharu.kotatsu.BuildConfig
|
||||||
|
import java.io.OutputStream
|
||||||
|
|
||||||
|
object MediaStoreCompat {
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun insertImage(
|
||||||
|
resolver: ContentResolver,
|
||||||
|
fileName: String,
|
||||||
|
block: (OutputStream) -> Unit
|
||||||
|
): Uri? {
|
||||||
|
val name = fileName.substringBeforeLast('.')
|
||||||
|
val cv = ContentValues(7)
|
||||||
|
cv.put(MediaStore.Images.Media.DISPLAY_NAME, name)
|
||||||
|
cv.put(MediaStore.Images.Media.TITLE, name)
|
||||||
|
cv.put(
|
||||||
|
MediaStore.Images.Media.MIME_TYPE,
|
||||||
|
MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileName.substringAfterLast('.'))
|
||||||
|
)
|
||||||
|
cv.put(MediaStore.Images.Media.DATE_ADDED, System.currentTimeMillis())
|
||||||
|
cv.put(MediaStore.Images.Media.DATE_MODIFIED, System.currentTimeMillis())
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
cv.put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis())
|
||||||
|
cv.put(MediaStore.Images.Media.IS_PENDING, 1)
|
||||||
|
}
|
||||||
|
var uri: Uri? = null
|
||||||
|
try {
|
||||||
|
uri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, cv)
|
||||||
|
resolver.openOutputStream(uri!!)?.use(block)
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
cv.clear()
|
||||||
|
cv.put(MediaStore.Images.Media.IS_PENDING, 0)
|
||||||
|
resolver.update(uri, cv, null, null)
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
if (BuildConfig.DEBUG) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
uri?.let {
|
||||||
|
resolver.delete(it, null, null)
|
||||||
|
}
|
||||||
|
uri = null
|
||||||
|
}
|
||||||
|
return uri
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package org.koitharu.kotatsu.utils.ext
|
||||||
|
|
||||||
|
import okhttp3.Response
|
||||||
|
|
||||||
|
val Response.mimeType: String?
|
||||||
|
get() = body?.contentType()?.run { "$type/$subtype" }
|
||||||
|
|
||||||
|
val Response.contentDisposition: String?
|
||||||
|
get() = header("Content-Disposition")
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
<vector
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:tint="?attr/colorControlNormal"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#000"
|
||||||
|
android:pathData="M14,2L20,8V20A2,2 0 0,1 18,22H6A2,2 0 0,1 4,20V4A2,2 0 0,1 6,2H14M18,20V9H13V4H6V20H18M17,13V19H7L12,14L14,16M10,10.5A1.5,1.5 0 0,1 8.5,12A1.5,1.5 0 0,1 7,10.5A1.5,1.5 0 0,1 8.5,9A1.5,1.5 0 0,1 10,10.5Z" />
|
||||||
|
</vector>
|
||||||
Loading…
Reference in New Issue