Improved image saving
This commit is contained in:
parent
e015741470
commit
7db515bb16
3 changed files with 13 additions and 28 deletions
|
@ -153,29 +153,29 @@ class UserInfoActivity : AbsBaseActivity() {
|
||||||
isFromMemoryCache: Boolean,
|
isFromMemoryCache: Boolean,
|
||||||
isFirstResource: Boolean
|
isFirstResource: Boolean
|
||||||
): Boolean {
|
): Boolean {
|
||||||
resource?.let { saveBannerImage(it) }
|
resource?.let { saveImage(it, USER_BANNER) }
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.into(bannerImage)
|
.into(bannerImage)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveBannerImage(bitmap: Bitmap) {
|
private fun saveImage(bitmap: Bitmap, fileName: String) {
|
||||||
CoroutineScope(Dispatchers.IO).launch() {
|
CoroutineScope(Dispatchers.IO).launch() {
|
||||||
val appDir = applicationContext.filesDir
|
val appDir = applicationContext.filesDir
|
||||||
val file = File(appDir, USER_BANNER)
|
val file = File(appDir, fileName)
|
||||||
var successful = false
|
var successful = false
|
||||||
try {
|
try {
|
||||||
val os = BufferedOutputStream(FileOutputStream(file))
|
val os = BufferedOutputStream(FileOutputStream(file))
|
||||||
successful = ImageUtil.resizeBitmap(bitmap, 2048)
|
successful = ImageUtil.resizeBitmap(bitmap, 2048)
|
||||||
.compress(Bitmap.CompressFormat.WEBP, 100, os)
|
.compress(Bitmap.CompressFormat.WEBP, 100, os)
|
||||||
os.close()
|
withContext(Dispatchers.IO) { os.close() }
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
if (successful) {
|
if (successful) {
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
Toast.makeText(this@UserInfoActivity, "Done", Toast.LENGTH_SHORT).show()
|
Toast.makeText(this@UserInfoActivity, "Updated", Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,33 +203,13 @@ class UserInfoActivity : AbsBaseActivity() {
|
||||||
isFromMemoryCache: Boolean,
|
isFromMemoryCache: Boolean,
|
||||||
isFirstResource: Boolean
|
isFirstResource: Boolean
|
||||||
): Boolean {
|
): Boolean {
|
||||||
resource?.let { saveImage(it) }
|
resource?.let { saveImage(it, USER_PROFILE) }
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.into(userImage)
|
.into(userImage)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveImage(bitmap: Bitmap) {
|
|
||||||
CoroutineScope(Dispatchers.IO).launch() {
|
|
||||||
val appDir = applicationContext.filesDir
|
|
||||||
val file = File(appDir, USER_PROFILE)
|
|
||||||
var successful = false
|
|
||||||
try {
|
|
||||||
val os = BufferedOutputStream(FileOutputStream(file))
|
|
||||||
successful = ImageUtil.resizeBitmap(bitmap, 2048)
|
|
||||||
.compress(Bitmap.CompressFormat.WEBP, 100, os)
|
|
||||||
os.close()
|
|
||||||
} catch (e: IOException) {
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
|
||||||
if (successful) {
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
Toast.makeText(this@UserInfoActivity, "Done", Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val PICK_IMAGE_REQUEST = 9002
|
private const val PICK_IMAGE_REQUEST = 9002
|
||||||
|
|
|
@ -45,11 +45,13 @@
|
||||||
<item>@string/dark_theme_name</item>
|
<item>@string/dark_theme_name</item>
|
||||||
<item>@string/follow_system</item>
|
<item>@string/follow_system</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="pref_general_theme_list_values">
|
<string-array name="pref_general_theme_list_values">
|
||||||
<item>light</item>
|
<item>light</item>
|
||||||
<item>dark</item>
|
<item>dark</item>
|
||||||
<item>auto</item>
|
<item>auto</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="pref_grid_style_list_titles">
|
<string-array name="pref_grid_style_list_titles">
|
||||||
<item>@string/normal_style</item>
|
<item>@string/normal_style</item>
|
||||||
<item>@string/card_style</item>
|
<item>@string/card_style</item>
|
||||||
|
@ -82,6 +84,7 @@
|
||||||
<item>@string/card_color_style</item>
|
<item>@string/card_color_style</item>
|
||||||
<item>@string/card_style</item>
|
<item>@string/card_style</item>
|
||||||
<item>@string/tiny_card_style</item>
|
<item>@string/tiny_card_style</item>
|
||||||
|
<item>@string/card_square</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="pref_home_grid_style_list_values">
|
<string-array name="pref_home_grid_style_list_values">
|
||||||
|
@ -89,6 +92,7 @@
|
||||||
<item>1</item>
|
<item>1</item>
|
||||||
<item>2</item>
|
<item>2</item>
|
||||||
<item>3</item>
|
<item>3</item>
|
||||||
|
<item>4</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<array name="pref_home_grid_style_layout">
|
<array name="pref_home_grid_style_layout">
|
||||||
|
@ -96,16 +100,15 @@
|
||||||
<item>@layout/item_artist_square</item>
|
<item>@layout/item_artist_square</item>
|
||||||
<item>@layout/item_album_card</item>
|
<item>@layout/item_album_card</item>
|
||||||
<item>@layout/item_artist_card</item>
|
<item>@layout/item_artist_card</item>
|
||||||
|
<item>@layout/item_image</item>
|
||||||
</array>
|
</array>
|
||||||
|
|
||||||
|
|
||||||
<array name="pref_auto_download_images_values">
|
<array name="pref_auto_download_images_values">
|
||||||
<item>always</item>
|
<item>always</item>
|
||||||
<item>only_wifi</item>
|
<item>only_wifi</item>
|
||||||
<item>never</item>
|
<item>never</item>
|
||||||
</array>
|
</array>
|
||||||
|
|
||||||
|
|
||||||
<string-array name="pref_playlists_last_added_interval_titles">
|
<string-array name="pref_playlists_last_added_interval_titles">
|
||||||
<item>@string/today</item>
|
<item>@string/today</item>
|
||||||
<item>@string/this_week</item>
|
<item>@string/this_week</item>
|
||||||
|
|
|
@ -164,6 +164,8 @@
|
||||||
|
|
||||||
<string name="card_style">Card</string>
|
<string name="card_style">Card</string>
|
||||||
|
|
||||||
|
<string name="card_square">Square Card</string>
|
||||||
|
|
||||||
<string name="carousal">Carousel</string>
|
<string name="carousal">Carousel</string>
|
||||||
|
|
||||||
<string name="carousal_effect_on_now_playing_screen">Carousel effect on the now playing screen</string>
|
<string name="carousal_effect_on_now_playing_screen">Carousel effect on the now playing screen</string>
|
||||||
|
|
Loading…
Reference in a new issue