Don't re-compress avatars before storing in DB
This commit is contained in:
parent
8354490940
commit
928f97dc97
@ -46,15 +46,15 @@ android {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
implementation 'androidx.core:core-ktx:1.5.0'
|
implementation 'androidx.core:core-ktx:1.6.0'
|
||||||
implementation 'androidx.appcompat:appcompat:1.3.0'
|
implementation 'androidx.appcompat:appcompat:1.3.1'
|
||||||
implementation "androidx.fragment:fragment-ktx:1.3.4"
|
implementation "androidx.fragment:fragment-ktx:1.3.6"
|
||||||
implementation "androidx.preference:preference-ktx:1.1.1"
|
implementation "androidx.preference:preference-ktx:1.1.1"
|
||||||
implementation 'com.google.android.material:material:1.3.0'
|
implementation 'com.google.android.material:material:1.4.0'
|
||||||
|
|
||||||
implementation 'net.i2p.crypto:eddsa:0.3.0'
|
implementation 'net.i2p.crypto:eddsa:0.3.0'
|
||||||
implementation "org.whispersystems:curve25519-android:0.5.0"
|
implementation "org.whispersystems:curve25519-android:0.5.0"
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
|
||||||
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
|
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
|
||||||
implementation 'com.github.bumptech.glide:glide:4.12.0'
|
implementation 'com.github.bumptech.glide:glide:4.12.0'
|
||||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
|
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
|
||||||
|
@ -9,6 +9,7 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import com.bumptech.glide.Glide
|
||||||
import sushi.hardcore.aira.databinding.FragmentCreateIdentityBinding
|
import sushi.hardcore.aira.databinding.FragmentCreateIdentityBinding
|
||||||
import sushi.hardcore.aira.utils.AvatarPicker
|
import sushi.hardcore.aira.utils.AvatarPicker
|
||||||
|
|
||||||
@ -25,11 +26,9 @@ class CreateIdentityFragment(private val activity: AppCompatActivity) : Fragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val avatarPicker = AvatarPicker(activity) { picker, avatar ->
|
private val avatarPicker = AvatarPicker(activity) { avatar ->
|
||||||
picker.setOnAvatarCompressed { compressedAvatar ->
|
AIRADatabase.setIdentityAvatar(Constants.getDatabaseFolder(activity), avatar)
|
||||||
AIRADatabase.setIdentityAvatar(Constants.getDatabaseFolder(activity), compressedAvatar)
|
Glide.with(this).load(avatar).circleCrop().into(binding.avatar)
|
||||||
}
|
|
||||||
avatar.circleCrop().into(binding.avatar)
|
|
||||||
}
|
}
|
||||||
private lateinit var binding: FragmentCreateIdentityBinding
|
private lateinit var binding: FragmentCreateIdentityBinding
|
||||||
|
|
||||||
|
@ -29,11 +29,9 @@ class SettingsActivity: AppCompatActivity() {
|
|||||||
class MySettingsFragment(private val activity: AppCompatActivity): PreferenceFragmentCompat() {
|
class MySettingsFragment(private val activity: AppCompatActivity): PreferenceFragmentCompat() {
|
||||||
private lateinit var databaseFolder: String
|
private lateinit var databaseFolder: String
|
||||||
private lateinit var airaService: AIRAService
|
private lateinit var airaService: AIRAService
|
||||||
private val avatarPicker = AvatarPicker(activity) { picker, avatar ->
|
private val avatarPicker = AvatarPicker(activity) { avatar ->
|
||||||
if (::airaService.isInitialized) {
|
if (::airaService.isInitialized) {
|
||||||
picker.setOnAvatarCompressed { compressedAvatar ->
|
airaService.changeAvatar(avatar)
|
||||||
airaService.changeAvatar(compressedAvatar)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
displayAvatar(avatar)
|
displayAvatar(avatar)
|
||||||
}
|
}
|
||||||
@ -174,19 +172,20 @@ class SettingsActivity: AppCompatActivity() {
|
|||||||
if (avatar == null) {
|
if (avatar == null) {
|
||||||
identityAvatarPreference.setIcon(R.drawable.ic_face)
|
identityAvatarPreference.setIcon(R.drawable.ic_face)
|
||||||
} else {
|
} else {
|
||||||
displayAvatar(Glide.with(this).load(avatar))
|
Glide
|
||||||
|
.with(this)
|
||||||
|
.load(avatar)
|
||||||
|
.apply(RequestOptions().override(90)) //reduce image to be the same size as other icons
|
||||||
|
.circleCrop()
|
||||||
|
.into(object : CustomTarget<Drawable>() {
|
||||||
|
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
|
||||||
|
identityAvatarPreference.icon = resource
|
||||||
|
}
|
||||||
|
override fun onLoadCleared(placeholder: Drawable?) {}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun displayAvatar(glideBuilder: RequestBuilder<Drawable>) {
|
|
||||||
glideBuilder.apply(RequestOptions().override(90)).circleCrop().into(object : CustomTarget<Drawable>() {
|
|
||||||
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
|
|
||||||
identityAvatarPreference.icon = resource
|
|
||||||
}
|
|
||||||
override fun onLoadCleared(placeholder: Drawable?) {}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun changePassword(isIdentityProtected: Boolean, oldPasswordEditText: EditText, newPassword: ByteArray?) {
|
private fun changePassword(isIdentityProtected: Boolean, oldPasswordEditText: EditText, newPassword: ByteArray?) {
|
||||||
val oldPassword = if (isIdentityProtected) {
|
val oldPassword = if (isIdentityProtected) {
|
||||||
oldPasswordEditText.text.toString().toByteArray()
|
oldPasswordEditText.text.toString().toByteArray()
|
||||||
|
@ -1,26 +1,17 @@
|
|||||||
package sushi.hardcore.aira.utils
|
package sushi.hardcore.aira.utils
|
||||||
|
|
||||||
import android.graphics.Bitmap
|
|
||||||
import android.graphics.drawable.Drawable
|
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.result.ActivityResultLauncher
|
import androidx.activity.result.ActivityResultLauncher
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.graphics.drawable.toBitmap
|
|
||||||
import com.bumptech.glide.Glide
|
|
||||||
import com.bumptech.glide.RequestBuilder
|
|
||||||
import com.bumptech.glide.request.target.CustomTarget
|
|
||||||
import com.bumptech.glide.request.transition.Transition
|
|
||||||
import sushi.hardcore.aira.Constants
|
import sushi.hardcore.aira.Constants
|
||||||
import sushi.hardcore.aira.R
|
import sushi.hardcore.aira.R
|
||||||
import java.io.ByteArrayOutputStream
|
|
||||||
|
|
||||||
class AvatarPicker(
|
class AvatarPicker(
|
||||||
private val activity: AppCompatActivity,
|
private val activity: AppCompatActivity,
|
||||||
private val onAvatarPicked: (AvatarPicker, RequestBuilder<Drawable>) -> Unit,
|
private val onAvatarPicked: (ByteArray) -> Unit,
|
||||||
) {
|
) {
|
||||||
private lateinit var picker: ActivityResultLauncher<String>
|
private lateinit var picker: ActivityResultLauncher<String>
|
||||||
private lateinit var avatar: RequestBuilder<Drawable>
|
|
||||||
fun register() {
|
fun register() {
|
||||||
picker = activity.registerForActivityResult(ActivityResultContracts.GetContent()) { uri ->
|
picker = activity.registerForActivityResult(ActivityResultContracts.GetContent()) { uri ->
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
@ -30,26 +21,13 @@ class AvatarPicker(
|
|||||||
if (image.size > Constants.MAX_AVATAR_SIZE) {
|
if (image.size > Constants.MAX_AVATAR_SIZE) {
|
||||||
Toast.makeText(activity, R.string.avatar_too_large, Toast.LENGTH_SHORT).show()
|
Toast.makeText(activity, R.string.avatar_too_large, Toast.LENGTH_SHORT).show()
|
||||||
} else {
|
} else {
|
||||||
avatar = Glide.with(activity).load(image).centerCrop()
|
onAvatarPicked(image)
|
||||||
onAvatarPicked(this, avatar)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setOnAvatarCompressed(onCompressed: (ByteArray) -> Unit) {
|
|
||||||
avatar.into(object: CustomTarget<Drawable>() {
|
|
||||||
override fun onResourceReady(resource: Drawable, transition: Transition<in Drawable>?) {
|
|
||||||
val avatar = ByteArrayOutputStream()
|
|
||||||
if (resource.toBitmap().compress(Bitmap.CompressFormat.PNG, 100, avatar)) {
|
|
||||||
onCompressed(avatar.toByteArray())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
override fun onLoadCleared(placeholder: Drawable?) {}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fun launch() {
|
fun launch() {
|
||||||
picker.launch("image/*")
|
picker.launch("image/*")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user