Added UPI payment link for indian support

This commit is contained in:
h4h13 2020-02-26 00:47:03 +05:30
parent d1ecdab42b
commit 954dfb6327
7 changed files with 198 additions and 19 deletions

View file

@ -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<SkuDetails>? {
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()
}
}
}

View file

@ -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())
}
}
}

View file

@ -0,0 +1,10 @@
<!-- drawable/currency_inr.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/md_white_1000"
android:pathData="M8,3H18L17,5H13.74C14.22,5.58 14.58,6.26 14.79,7H18L17,9H15C14.75,11.57 12.74,13.63 10.2,13.96V14H9.5L15.5,21H13L7,14V12H9.5V12C11.26,12 12.72,10.7 12.96,9H7L8,7H12.66C12.1,5.82 10.9,5 9.5,5H7L8,3Z" />
</vector>

View file

@ -76,6 +76,12 @@
android:paddingEnd="6dp"
android:scrollbarStyle="outsideOverlay" />
<com.google.android.material.button.MaterialButton
android:id="@+id/upiClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="For indian payment" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View file

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="16dp"
android:paddingTop="16dp"
android:paddingEnd="16dp"
android:paddingBottom="16dp">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/nameContainer"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintEnabled="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:startIconDrawable="@drawable/ic_account_white_24dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/nameText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/my_name"
android:inputType="text|textCapWords"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/amountContainer"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:hintEnabled="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/nameContainer"
app:startIconDrawable="@drawable/ic_currency_inr_white_24dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/amountText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/amount"
android:inputType="numberDecimal"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/noteContainer"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:hintEnabled="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/amountContainer"
app:startIconDrawable="@drawable/ic_edit_white_24dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/noteText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/note"
android:inputType="text|textCapWords"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/start_payment"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/noteContainer" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -839,4 +839,7 @@
<string name="you_will_be_forwarded_to_the_issue_tracker_website">You will be forwarded to the issue tracker website.</string>
<string name="your_account_data_is_only_used_for_authentication">Your account data is only used for authentication.</string>
<string name="amount">Amount</string>
<string name="note">Note(Optional)</string>
<string name="start_payment">Start payment</string>
</resources>

View file

@ -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