Skip to content

Commit

Permalink
fixed a bug where new donations are not acknowledged
Browse files Browse the repository at this point in the history
  • Loading branch information
kevintresuelo committed Apr 27, 2020
1 parent 69a5361 commit 31a13f2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ import android.view.ViewGroup
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.kevintresuelo.novus.UpdateChecker
import com.kevintresuelo.treble.BuildConfig
import com.kevintresuelo.treble.R
import com.kevintresuelo.treble.billing.viewmodels.BillingViewModel
import com.kevintresuelo.treble.databinding.DialogContributorsListBinding
import com.kevintresuelo.treble.databinding.FragmentAboutBinding
import com.kevintresuelo.treble.donate.DonateDialogFragment
Expand Down Expand Up @@ -231,7 +233,8 @@ class AboutFragment : Fragment() {
* Opens the donation dialog
*/
binding.faLlOthersDonate.setOnClickListener {
DonateDialogFragment().show(parentFragmentManager, DonateDialogFragment.TAG)
val billingViewModel = ViewModelProvider(this).get(BillingViewModel::class.java)
DonateDialogFragment(billingViewModel).show(parentFragmentManager, DonateDialogFragment.TAG)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ import android.view.animation.Transformation
import androidx.core.view.isVisible
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import com.kevintresuelo.adnoto.RatePrompter
import com.kevintresuelo.treble.R
import com.kevintresuelo.treble.billing.viewmodels.BillingViewModel
import com.kevintresuelo.treble.checker.*
import com.kevintresuelo.treble.databinding.FragmentCheckerBinding
import com.kevintresuelo.treble.donate.DonateDialogFragment
Expand All @@ -52,6 +54,7 @@ class CheckerFragment : Fragment() {
*/
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_checker, container, false)


/**
* Notifies the host activity that this fragment has options menu.
*/
Expand All @@ -62,14 +65,20 @@ class CheckerFragment : Fragment() {
*/
RatePrompter(context, 3)

/**
* Checks for new purchases of the user
*/
val billingViewModel = ViewModelProvider(this).get(BillingViewModel::class.java)
billingViewModel.queryPurchases()

/**
* Shows the Donate CardView if the user has opened the app thrice
* already, and hasn't dismissed the card yet.
*/
val prefsFileKey = "prompt_donate"
val hasDismissedKey = "donate_card_dismissed"
val timesAppOpenedKey = "donate_card_times_app_opened"

val sharedPreferences = activity?.getSharedPreferences(prefsFileKey, Context.MODE_PRIVATE)
sharedPreferences?.let { sharedPrefs ->
val isDonateCardAlreadyDismissed = sharedPrefs.getBoolean(hasDismissedKey, false)
Expand All @@ -78,7 +87,7 @@ class CheckerFragment : Fragment() {
if (timesAppOpened >= 3) {
binding.fcMcvStatusDonate.visibility = View.VISIBLE
binding.fcMbStatusDonateAction1.setOnClickListener {
DonateDialogFragment().show(parentFragmentManager, DonateDialogFragment.TAG)
DonateDialogFragment(billingViewModel).show(parentFragmentManager, DonateDialogFragment.TAG)
sharedPrefs.edit()?.putBoolean(hasDismissedKey, true)?.apply()
binding.fcMcvStatusDonate.visibility = View.GONE
}
Expand Down

0 comments on commit 31a13f2

Please sign in to comment.