Skip to content

Commit

Permalink
Merge pull request #187 from henrikth93/rate-scribe-action-#165
Browse files Browse the repository at this point in the history
Add action for "rate scribe"
  • Loading branch information
andrewtavis authored Oct 13, 2024
2 parents fdfbc3f + adbf6ae commit ddef4e6
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ dependencies {
implementation("androidx.recyclerview:recyclerview:1.3.2")
implementation("androidx.cardview:cardview:1.0.0")
implementation("androidx.viewpager2:viewpager2:1.1.0")
implementation("com.google.android.play:core:1.10.0")

api("joda-time:joda-time:2.10.13")
api("com.github.tibbi:RecyclerView-FastScroller:e7d3e150c4")
Expand Down
53 changes: 50 additions & 3 deletions app/src/main/java/be/scri/fragments/AboutFragment.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package be.scri.fragments

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.activity.addCallback
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
Expand All @@ -14,6 +17,7 @@ import be.scri.activities.MainActivity
import be.scri.databinding.FragmentAboutBinding
import be.scri.helpers.CustomAdapter
import be.scri.models.ItemsViewModel
import com.google.android.play.core.review.ReviewManagerFactory

class AboutFragment : Fragment() {
private lateinit var binding: FragmentAboutBinding
Expand Down Expand Up @@ -104,15 +108,16 @@ class AboutFragment : Fragment() {
),
)

private fun getSecondRecyclerViewData(): List<Any> =
listOf(
private fun getSecondRecyclerViewData(): List<Any> {
val context = requireContext()
return listOf(
ItemsViewModel(
image = R.drawable.star,
text = ItemsViewModel.Text(R.string.app_about_feedback_rate_scribe),
image2 = R.drawable.external_link,
url = null,
activity = null,
action = null,
action = ::rateScribe,
),
ItemsViewModel(
image = R.drawable.bug_report_icon,
Expand Down Expand Up @@ -147,6 +152,7 @@ class AboutFragment : Fragment() {
action = null,
),
)
}

private fun getThirdRecyclerViewData(): List<ItemsViewModel> =
listOf(
Expand Down Expand Up @@ -210,4 +216,45 @@ class AboutFragment : Fragment() {
fragmentTransaction.addToBackStack(null)
fragmentTransaction.commit()
}

private fun getInstallSource(context: Context): String? =
try {
val packageManager = context.packageManager
packageManager.getInstallerPackageName(context.packageName)
} catch (e: Exception) {
null
}

private fun rateScribe() {
val context = requireContext()
var installSource = getInstallSource(context)

if (installSource == "com.android.vending") {
val reviewManager = ReviewManagerFactory.create(context)
val request = reviewManager.requestReviewFlow()

request.addOnCompleteListener { task ->
if (task.isSuccessful) {
val reviewInfo = task.result
val activity = requireActivity()
reviewManager
.launchReviewFlow(activity, reviewInfo)
.addOnCompleteListener { _ ->
}
} else {
Toast.makeText(context, "Failed to launch review flow", Toast.LENGTH_SHORT).show()
}
}
} else if (installSource == "org.fdroid.fdroid") {
val url = "https://f-droid.org/packages/${context.packageName}"
val intent =
Intent(Intent.ACTION_VIEW)
.apply {
data = Uri.parse(url)
}
context.startActivity(intent)
} else {
Toast.makeText(context, "Unknown installation source", Toast.LENGTH_SHORT).show()
}
}
}

0 comments on commit ddef4e6

Please sign in to comment.