Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ package com.lagradost.cloudstream3.ui.account
import android.app.Activity
import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.os.Bundle
import android.text.Editable
import android.view.LayoutInflater
import android.view.inputmethod.EditorInfo
import android.widget.TextView
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.StringRes
import androidx.appcompat.app.AlertDialog
import androidx.core.view.isGone
Expand Down Expand Up @@ -43,6 +47,38 @@ import com.lagradost.cloudstream3.utils.UIHelper.showInputMethod
import com.lagradost.cloudstream3.utils.UIHelper.showProgress

object AccountHelper {
private fun pickProfileImage(context: Context, callback: (String) -> Unit) {
val activity = context.getActivity() as? ComponentActivity ?: return
var launcher: ActivityResultLauncher<Array<String>>? = null
try {
launcher = activity.activityResultRegistry.register(
Comment thread
fire-light42 marked this conversation as resolved.
Outdated
"profile_image_${System.nanoTime()}",
ActivityResultContracts.OpenDocument()
) { uri ->
activity.window.decorView.post { launcher?.unregister() }
if (uri == null) return@register
try {
context.contentResolver.takePersistableUriPermission(
uri, Intent.FLAG_GRANT_READ_URI_PERMISSION
)
} catch (error: Exception) {
logError(error)
return@register showToast(R.string.edit_profile_image_error_invalid)
}
ImageLoader(context).enqueue(ImageRequest.Builder(context).data(uri)
.allowHardware(false).size(512, 512).listener(
onSuccess = { _, _ -> callback(uri.toString()) },
onError = { _, _ -> showToast(R.string.edit_profile_image_error_invalid) }
).build())
}
launcher.launch(arrayOf("image/png", "image/jpeg"))
Comment thread
fire-light42 marked this conversation as resolved.
Outdated
} catch (error: Exception) {
launcher?.unregister()
logError(error)
showToast(R.string.edit_profile_image_error_invalid, Toast.LENGTH_SHORT)
}
}

fun showAccountEditDialog(
context: Context,
account: DataStoreHelper.Account,
Expand Down Expand Up @@ -166,7 +202,7 @@ object AccountHelper {

canSetPin = true

binding.editProfilePhotoButton.setOnClickListener {
val showProfileImageUrlDialog = { callback: (String) -> Unit ->
val bottomSheetDialog = BottomSheetDialog(context)
val sheetBinding = BottomInputDialogBinding.inflate(LayoutInflater.from(context))
bottomSheetDialog.setContentView(sheetBinding.root)
Expand All @@ -189,8 +225,7 @@ object AccountHelper {
.allowHardware(false)
.listener(
onSuccess = { _, _ ->
currentEditAccount = currentEditAccount.copy(customImage = url)
binding.accountImage.loadImage(url)
callback(url)
Comment thread
fire-light42 marked this conversation as resolved.
Outdated
showToast(
R.string.edit_profile_image_success,
Toast.LENGTH_SHORT
Expand All @@ -216,6 +251,30 @@ object AccountHelper {
}
}
}

binding.editProfilePhotoButton.setOnClickListener {
AlertDialog.Builder(context)
.setTitle(R.string.edit_profile_image_title)
.setItems(arrayOf(
context.getString(R.string.player_load_subtitles),
Comment thread
fire-light42 marked this conversation as resolved.
Outdated
context.getString(R.string.edit_profile_image_hint),
)) { _, selection ->
if (selection == 0) {
pickProfileImage(context) { image ->
if (!dialog.isShowing) return@pickProfileImage
currentEditAccount = currentEditAccount.copy(customImage = image)
binding.accountImage.loadImage(image)
showToast(R.string.edit_profile_image_success, Toast.LENGTH_SHORT)
Comment thread
fire-light42 marked this conversation as resolved.
Outdated
}
} else {
showProfileImageUrlDialog { image ->
currentEditAccount = currentEditAccount.copy(customImage = image)
binding.accountImage.loadImage(image)
}
}
}
.show()
}
}

fun showPinInputDialog(
Expand Down Expand Up @@ -416,4 +475,4 @@ object AccountHelper {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ object DataStoreHelper {
@JsonProperty("lockPin") @SerialName("lockPin") val lockPin: String? = null,
) {
@get:JsonIgnore
val image get() = customImage?.let { UiImage.Image(it) } ?:
val image get() = customImage?.takeUnless { image ->
image.startsWith("content://") && context?.contentResolver?.persistedUriPermissions
Comment thread
fire-light42 marked this conversation as resolved.
?.none { it.uri.toString() == image } != false
}?.let { UiImage.Image(it) } ?:
profileImages.getOrNull(defaultImageIndex)?.let {
UiImage.Drawable(it)
} ?: UiImage.Drawable(profileImages.first())
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/res/layout/account_edit_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
android:contentDescription="@string/preview_background_img_des"
android:focusable="true"
android:foreground="@drawable/outline_drawable_forced_round"
android:nextFocusRight="@id/edit_profile_photo_button"
android:scaleType="centerCrop"
android:src="@drawable/profile_bg_blue" />

Expand All @@ -60,6 +61,11 @@
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:background="@color/skipOpTransparent"
android:contentDescription="@string/edit_profile_image_title"
android:focusable="true"
android:foreground="@drawable/outline_drawable_forced_round"
android:nextFocusLeft="@id/account_image"
android:nextFocusDown="@id/account_name"
android:padding="5dp"
android:src="@drawable/ic_baseline_edit_24" />
</androidx.cardview.widget.CardView>
Expand Down Expand Up @@ -127,4 +133,4 @@
android:text="@string/sort_cancel" />

</RelativeLayout>
</LinearLayout>
</LinearLayout>