You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.5 KiB
73 lines
2.5 KiB
package net.pokeranalytics.android.util
|
|
|
|
import android.content.ActivityNotFoundException
|
|
import android.content.Intent
|
|
import android.content.res.Resources
|
|
import android.net.Uri
|
|
import android.widget.Toast
|
|
import androidx.browser.customtabs.CustomTabsIntent
|
|
import androidx.core.content.ContextCompat
|
|
import net.pokeranalytics.android.BuildConfig
|
|
import net.pokeranalytics.android.R
|
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity
|
|
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment
|
|
|
|
|
|
// Sizes
|
|
val Int.dp: Int
|
|
get() = (this / Resources.getSystem().displayMetrics.density).toInt()
|
|
val Int.px: Int
|
|
get() = (this * Resources.getSystem().displayMetrics.density).toInt()
|
|
val Float.dp: Float
|
|
get() = (this / Resources.getSystem().displayMetrics.density)
|
|
val Float.px: Float
|
|
get() = (this * Resources.getSystem().displayMetrics.density)
|
|
|
|
|
|
// Toast
|
|
fun PokerAnalyticsActivity.toast(message: String) {
|
|
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
|
|
}
|
|
fun PokerAnalyticsFragment.toast(message: String) {
|
|
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
|
|
}
|
|
|
|
// Open Play Store for rating
|
|
fun PokerAnalyticsActivity.openPlayStorePage() {
|
|
val uri = Uri.parse("market://details?id=$packageName")
|
|
val goToMarket = Intent(Intent.ACTION_VIEW, uri)
|
|
goToMarket.addFlags(
|
|
Intent.FLAG_ACTIVITY_NO_HISTORY or Intent.FLAG_ACTIVITY_NEW_DOCUMENT or
|
|
Intent.FLAG_ACTIVITY_MULTIPLE_TASK
|
|
)
|
|
try {
|
|
startActivity(goToMarket)
|
|
} catch (e: ActivityNotFoundException) {
|
|
startActivity(
|
|
Intent(
|
|
Intent.ACTION_VIEW, Uri.parse(
|
|
"http://play.google.com/store/apps/details?id=$packageName"
|
|
)
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
// Open email for "Contact us"
|
|
fun PokerAnalyticsActivity.openContactMail(subjectStringRes: Int) {
|
|
val info = "v${BuildConfig.VERSION_NAME}(${BuildConfig.VERSION_CODE}), Android ${android.os.Build.VERSION.SDK_INT}"
|
|
val intent = Intent(Intent.ACTION_SENDTO)
|
|
intent.data = Uri.parse("mailto:${URL.SUPPORT_EMAIL.value}")
|
|
intent.putExtra(Intent.EXTRA_SUBJECT, getString(subjectStringRes))
|
|
intent.putExtra(Intent.EXTRA_EMAIL, URL.SUPPORT_EMAIL.value)
|
|
intent.putExtra(Intent.EXTRA_TEXT, "\n\n$info")
|
|
startActivity(Intent.createChooser(intent, getString(R.string.contact)))
|
|
}
|
|
|
|
// Open custom tab
|
|
fun PokerAnalyticsActivity.openUrl(url: String) {
|
|
val builder: CustomTabsIntent.Builder = CustomTabsIntent.Builder()
|
|
builder.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary))
|
|
val customTabsIntent = builder.build()
|
|
customTabsIntent.launchUrl(this, Uri.parse(url))
|
|
}
|
|
|