-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [feat] Implement new Settings UI with contribute and support options
* Upgrade Kotlin version to 1.9.0, and Hilt version respectively * Add Coil for image loading
- Loading branch information
1 parent
e0ebd30
commit b3cda05
Showing
36 changed files
with
901 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
app/src/main/java/dev/arkbuilders/arkmemo/ui/dialogs/DonateDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package dev.arkbuilders.arkmemo.ui.dialogs | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.DialogFragment | ||
import androidx.fragment.app.activityViewModels | ||
import coil.load | ||
import dev.arkbuilders.arkmemo.R | ||
import dev.arkbuilders.arkmemo.databinding.DialogDonateQrBinding | ||
import dev.arkbuilders.arkmemo.ui.viewmodels.QRViewModel | ||
import dev.arkbuilders.arkmemo.ui.views.toast | ||
import dev.arkbuilders.arkmemo.utils.copyToClipboard | ||
|
||
|
||
class DonateDialog(private val walletAddress: String, | ||
private val onPositiveClick: (() -> Unit)? = null, | ||
private val onCloseClicked: (() -> Unit)? = null, | ||
): DialogFragment() { | ||
|
||
companion object { | ||
val TAG: String = DonateDialog::class.java.name | ||
} | ||
private lateinit var binding: DialogDonateQrBinding | ||
private val qrViewModel: QRViewModel by activityViewModels() | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle?, | ||
): View { | ||
binding = DialogDonateQrBinding.inflate(inflater) | ||
initViews() | ||
return binding.root | ||
} | ||
|
||
private fun initViews() { | ||
|
||
dialog?.setCanceledOnTouchOutside(false) | ||
|
||
binding.ivClose.setOnClickListener { | ||
onCloseClicked?.invoke() | ||
dismiss() | ||
} | ||
|
||
binding.layoutDownloadQr.setOnClickListener { | ||
onPositiveClick?.invoke() | ||
dismiss() | ||
} | ||
|
||
binding.tvAddress.text = walletAddress | ||
binding.layoutCopy.setOnClickListener { | ||
context?.copyToClipboard(getString(R.string.setting_donate_wallet_clipboard_label), | ||
walletAddress) | ||
} | ||
|
||
initQRImage() | ||
} | ||
|
||
private fun initQRImage() { | ||
qrViewModel.generateQRCode(walletAddress) { bitmap -> | ||
binding.ivQr.load(bitmap) | ||
binding.layoutDownloadQr.setOnClickListener { | ||
qrViewModel.saveQRCodeImage(walletAddress, bitmap) { path -> | ||
context?.let { ctx -> | ||
toast(ctx, getString(R.string.toast_save_qr_success, path)) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, | ||
ViewGroup.LayoutParams.WRAP_CONTENT) | ||
} | ||
|
||
override fun getTheme(): Int { | ||
return R.style.MemoDialog | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
app/src/main/java/dev/arkbuilders/arkmemo/ui/viewmodels/QRViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package dev.arkbuilders.arkmemo.ui.viewmodels | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import android.graphics.Bitmap | ||
import android.graphics.Color | ||
import androidmads.library.qrgenearator.QRGContents | ||
import androidmads.library.qrgenearator.QRGEncoder | ||
import androidmads.library.qrgenearator.QRGSaver | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dev.arkbuilders.arkmemo.di.IO_DISPATCHER | ||
import dev.arkbuilders.arkmemo.utils.dp2Px | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.withContext | ||
import java.io.File | ||
import javax.inject.Inject | ||
import javax.inject.Named | ||
|
||
|
||
@SuppressLint("StaticFieldLeak") | ||
@HiltViewModel | ||
class QRViewModel @Inject constructor( | ||
@Named(IO_DISPATCHER) private val iODispatcher: CoroutineDispatcher, | ||
@ApplicationContext private val context: Context, | ||
) : ViewModel() { | ||
|
||
fun generateQRCode(text: String, onSuccess: (bitmap: Bitmap) -> Unit) { | ||
viewModelScope.launch(iODispatcher) { | ||
// Initializing the QR Encoder with your value to be encoded, type you required and Dimension | ||
val qrgEncoder = QRGEncoder(text, null, QRGContents.Type.TEXT, 300.dp2Px()) | ||
qrgEncoder.colorBlack = Color.BLACK | ||
qrgEncoder.colorWhite = Color.WHITE | ||
withContext(Dispatchers.Main) { | ||
onSuccess.invoke(qrgEncoder.getBitmap(0)) | ||
} | ||
} | ||
} | ||
|
||
fun saveQRCodeImage(text: String, bitmap: Bitmap, onSuccess: (path: String) -> Unit) { | ||
viewModelScope.launch { | ||
// Save with location, value, bitmap returned and type of Image(JPG/PNG). | ||
val qrgSaver = QRGSaver() | ||
|
||
val savePath = (context.getExternalFilesDir(null)?.path + "/images/").apply { | ||
File(this).mkdirs() | ||
} | ||
|
||
val isSuccess = qrgSaver.save( | ||
savePath, | ||
text, | ||
bitmap, | ||
QRGContents.ImageType.IMAGE_JPEG | ||
) | ||
|
||
if (isSuccess) { | ||
onSuccess.invoke(savePath) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
app/src/main/java/dev/arkbuilders/arkmemo/ui/views/SupportTextView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package dev.arkbuilders.arkmemo.ui.views | ||
|
||
import android.content.Context | ||
import android.content.res.TypedArray | ||
import android.util.AttributeSet | ||
import android.view.LayoutInflater | ||
import androidx.constraintlayout.widget.ConstraintLayout | ||
import androidx.core.content.ContextCompat | ||
import dev.arkbuilders.arkmemo.R | ||
import dev.arkbuilders.arkmemo.databinding.LayoutSupportTextBinding | ||
import dev.arkbuilders.arkmemo.utils.gone | ||
|
||
class SupportTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : | ||
ConstraintLayout(context, attrs) { | ||
init { | ||
val binding = LayoutSupportTextBinding.inflate(LayoutInflater.from(context), this, true) | ||
val typedArray: TypedArray = | ||
context.obtainStyledAttributes(attrs, R.styleable.SupportTextView) | ||
val textResId = typedArray.getText(R.styleable.SupportTextView_support_text) | ||
val iconResId = typedArray.getResourceId(R.styleable.SupportTextView_support_icon, 0) | ||
val logoResId = typedArray.getResourceId(R.styleable.SupportTextView_support_logo, 0) | ||
val enabled = typedArray.getBoolean(R.styleable.SupportTextView_support_enabled, true) | ||
textResId?.let { | ||
binding.tvText.text = textResId | ||
binding.ivLogoText.gone() | ||
} ?: let { | ||
binding.tvText.gone() | ||
binding.ivIcon.gone() | ||
binding.ivLogoText.setImageResource(logoResId) | ||
} | ||
|
||
if (iconResId != 0) { | ||
binding.ivIcon.setImageResource(iconResId) | ||
} else { | ||
binding.ivIcon.gone() | ||
} | ||
|
||
if (!enabled) { | ||
binding.tvText.setTextColor(ContextCompat.getColor(context, R.color.gray_400)) | ||
binding.tvText.isEnabled = false | ||
} | ||
|
||
typedArray.recycle() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
app/src/main/java/dev/arkbuilders/arkmemo/ui/views/WebLinkTextView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package dev.arkbuilders.arkmemo.ui.views | ||
|
||
import android.content.Context | ||
import android.content.res.TypedArray | ||
import android.util.AttributeSet | ||
import android.view.LayoutInflater | ||
import androidx.constraintlayout.widget.ConstraintLayout | ||
import dev.arkbuilders.arkmemo.R | ||
import dev.arkbuilders.arkmemo.databinding.LayoutWebLinkTextBinding | ||
import dev.arkbuilders.arkmemo.utils.gone | ||
|
||
class WebLinkTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : | ||
ConstraintLayout(context, attrs) { | ||
|
||
init { | ||
val binding = LayoutWebLinkTextBinding.inflate(LayoutInflater.from(context), this, true) | ||
val typedArray: TypedArray = | ||
context.obtainStyledAttributes(attrs, R.styleable.WebLinkTextView) | ||
val textResId = typedArray.getText(R.styleable.WebLinkTextView_web_link_text) | ||
val iconResId = typedArray.getResourceId(R.styleable.WebLinkTextView_web_link_icon, 0) | ||
textResId?.let { | ||
binding.tvText.text = textResId | ||
} | ||
|
||
if (iconResId != 0) { | ||
binding.ivIcon.setImageResource(iconResId) | ||
} else { | ||
binding.ivIcon.gone() | ||
} | ||
|
||
typedArray.recycle() | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/dev/arkbuilders/arkmemo/utils/ContextExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package dev.arkbuilders.arkmemo.utils | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.net.Uri | ||
|
||
fun Context.openLink(url: String) { | ||
startActivity( | ||
Intent(Intent.ACTION_VIEW).setData(Uri.parse(url))) | ||
} |
Oops, something went wrong.