Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add action for "rate scribe" #187

Merged
merged 8 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
}
}