diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/SupportDevelopmentActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/SupportDevelopmentActivity.kt index 20e50ebd..010b1808 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/SupportDevelopmentActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/SupportDevelopmentActivity.kt @@ -18,24 +18,22 @@ import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.util.ATHUtil +import code.name.monkey.appthemehelper.util.MaterialUtil import code.name.monkey.appthemehelper.util.TintHelper import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper import code.name.monkey.retromusic.BuildConfig import code.name.monkey.retromusic.R import code.name.monkey.retromusic.activities.base.AbsBaseActivity +import code.name.monkey.retromusic.dialogs.UpiPaymentBottomSheetDialogFragment import code.name.monkey.retromusic.extensions.textColorPrimary import code.name.monkey.retromusic.extensions.textColorSecondary import com.anjlab.android.iab.v3.BillingProcessor import com.anjlab.android.iab.v3.SkuDetails import com.anjlab.android.iab.v3.TransactionDetails import kotlinx.android.synthetic.main.activity_about.toolbar -import kotlinx.android.synthetic.main.activity_donation.donation -import kotlinx.android.synthetic.main.activity_donation.progress -import kotlinx.android.synthetic.main.activity_donation.progressContainer -import kotlinx.android.synthetic.main.activity_donation.recyclerView +import kotlinx.android.synthetic.main.activity_donation.* import java.lang.ref.WeakReference -import java.util.ArrayList -import java.util.Arrays +import java.util.* class SupportDevelopmentActivity : AbsBaseActivity(), BillingProcessor.IBillingHandler { @@ -58,7 +56,7 @@ class SupportDevelopmentActivity : AbsBaseActivity(), BillingProcessor.IBillingH fun donate(i: Int) { val ids = resources.getStringArray(DONATION_PRODUCT_IDS) - billingProcessor!!.purchase(this, ids[i]) + billingProcessor?.purchase(this, ids[i]) } override fun onCreate(savedInstanceState: Bundle?) { @@ -75,6 +73,14 @@ class SupportDevelopmentActivity : AbsBaseActivity(), BillingProcessor.IBillingH billingProcessor = BillingProcessor(this, BuildConfig.GOOGLE_PLAY_LICENSING_KEY, this) TintHelper.setTint(progress, ThemeStore.accentColor(this)) donation.setTextColor(ThemeStore.accentColor(this)) + + MaterialUtil.setTint(upiClick) + upiClick.setOnClickListener { + UpiPaymentBottomSheetDialogFragment().show( + supportFragmentManager, + UpiPaymentBottomSheetDialogFragment.TAG + ) + } } private fun setupToolbar() { @@ -120,12 +126,8 @@ class SupportDevelopmentActivity : AbsBaseActivity(), BillingProcessor.IBillingH } override fun onDestroy() { - if (billingProcessor != null) { - billingProcessor!!.release() - } - if (skuDetailsLoadAsyncTask != null) { - skuDetailsLoadAsyncTask!!.cancel(true) - } + billingProcessor?.release() + skuDetailsLoadAsyncTask?.cancel(true) super.onDestroy() } } @@ -148,7 +150,8 @@ private class SkuDetailsLoadAsyncTask internal constructor(supportDevelopmentAct override fun doInBackground(vararg params: Void): List? { val dialog = weakReference.get() if (dialog != null) { - val ids = dialog.resources.getStringArray(SupportDevelopmentActivity.DONATION_PRODUCT_IDS) + val ids = + dialog.resources.getStringArray(SupportDevelopmentActivity.DONATION_PRODUCT_IDS) return dialog.billingProcessor!!.getPurchaseListingDetails(ArrayList(Arrays.asList(*ids))) } cancel(false) @@ -220,7 +223,8 @@ class SkuDetailsAdapter( donationsDialog, android.R.attr.textColorHint ) else textColorPrimary(donationsDialog) - val contentTextColor = if (purchased) titleTextColor else textColorSecondary(donationsDialog) + val contentTextColor = + if (purchased) titleTextColor else textColorSecondary(donationsDialog) viewHolder.title.setTextColor(titleTextColor) viewHolder.text.setTextColor(contentTextColor) @@ -250,8 +254,9 @@ class SkuDetailsAdapter( private val LAYOUT_RES_ID = R.layout.item_donation_option private fun strikeThrough(textView: TextView, strikeThrough: Boolean) { - textView.paintFlags = if (strikeThrough) textView.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG - else textView.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv() + textView.paintFlags = + if (strikeThrough) textView.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG + else textView.paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv() } } } diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/UpiPaymentBottomSheetDialogFragment.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/UpiPaymentBottomSheetDialogFragment.kt new file mode 100644 index 00000000..3455374c --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/UpiPaymentBottomSheetDialogFragment.kt @@ -0,0 +1,64 @@ +package code.name.monkey.retromusic.dialogs + +import android.content.Intent +import android.net.Uri +import android.os.Bundle +import android.text.TextUtils +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import code.name.monkey.appthemehelper.util.MaterialUtil +import code.name.monkey.retromusic.R +import com.google.android.material.bottomsheet.BottomSheetDialogFragment +import kotlinx.android.synthetic.main.fragment_upi_payment_dialog.* + +class UpiPaymentBottomSheetDialogFragment : BottomSheetDialogFragment() { + companion object { + const val TAG: String = "UpiPaymentBottomSheetDialogFragment" + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_upi_payment_dialog, container, false) + } + + private fun upi(name: String, amount: String, note: String) { + val currentTime = System.currentTimeMillis() / 1000 + val transactionId = "${currentTime}UPI" + val upi = + "upi://pay?pa=retromusic@ybl&pn=$name&mc=0000&tid=$transactionId&tr=$transactionId&tn=$note&am=$amount&cu=INR&refUrl=refurl".replace( + " ", + "+" + ) + val intent = Intent(); + intent.action = Intent.ACTION_VIEW; + intent.data = Uri.parse(upi); + val chooser = Intent.createChooser(intent, "Pay with..."); + startActivityForResult(chooser, 1, null) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + MaterialUtil.setTint(submit) + submit.setOnClickListener { + val name = nameText.text.toString() + if (TextUtils.isEmpty(name)) { + nameContainer.error = "Name is empty" + return@setOnClickListener + } else { + nameContainer.error = null + } + val amount = amountText.text.toString() + if (TextUtils.isEmpty(amount)) { + amountContainer.error = "Amount is empty" + return@setOnClickListener + } else { + amountContainer.error = null + } + upi(name, amount, noteText.text.toString()) + } + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_currency_inr_white_24dp.xml b/app/src/main/res/drawable/ic_currency_inr_white_24dp.xml new file mode 100644 index 00000000..3fa26770 --- /dev/null +++ b/app/src/main/res/drawable/ic_currency_inr_white_24dp.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_donation.xml b/app/src/main/res/layout/activity_donation.xml index 0bb2697c..c89f85d8 100644 --- a/app/src/main/res/layout/activity_donation.xml +++ b/app/src/main/res/layout/activity_donation.xml @@ -76,6 +76,12 @@ android:paddingEnd="6dp" android:scrollbarStyle="outsideOverlay" /> + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_upi_payment_dialog.xml b/app/src/main/res/layout/fragment_upi_payment_dialog.xml new file mode 100644 index 00000000..88aee347 --- /dev/null +++ b/app/src/main/res/layout/fragment_upi_payment_dialog.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 27cbb817..0b962047 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -839,4 +839,7 @@ You will be forwarded to the issue tracker website. Your account data is only used for authentication. + Amount + Note(Optional) + Start payment diff --git a/appthemehelper/src/main/java/code/name/monkey/appthemehelper/util/MaterialUtil.kt b/appthemehelper/src/main/java/code/name/monkey/appthemehelper/util/MaterialUtil.kt index 2fd17295..53c2be80 100644 --- a/appthemehelper/src/main/java/code/name/monkey/appthemehelper/util/MaterialUtil.kt +++ b/appthemehelper/src/main/java/code/name/monkey/appthemehelper/util/MaterialUtil.kt @@ -19,7 +19,12 @@ object MaterialUtil { val context = button.context val colorState = ColorStateList.valueOf(color) val textColor = - ColorStateList.valueOf(MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(color))) + ColorStateList.valueOf( + MaterialValueHelper.getPrimaryTextColor( + context, + ColorUtil.isColorLight(color) + ) + ) if (background) { @@ -56,7 +61,12 @@ object MaterialUtil { val context = temp.context val colorState = ColorStateList.valueOf(color) val textColor = - ColorStateList.valueOf(MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(color))) + ColorStateList.valueOf( + MaterialValueHelper.getPrimaryTextColor( + context, + ColorUtil.isColorLight(color) + ) + ) if (background) { temp.backgroundTintList = colorState