|
|
|
|
@ -1,7 +1,14 @@ |
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
@ -17,13 +24,49 @@ 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() { |
|
|
|
|
val info = "${BuildConfig.VERSION_NAME}(${BuildConfig.VERSION_CODE}), ${android.os.Build.VERSION.SDK_INT}" |
|
|
|
|
val intent = Intent(Intent.ACTION_SENDTO) |
|
|
|
|
intent.data = Uri.parse("mailto:$SUPPORT_EMAIL") |
|
|
|
|
intent.putExtra(Intent.EXTRA_EMAIL, SUPPORT_EMAIL) |
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, "<br/><br/>$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)) |
|
|
|
|
} |
|
|
|
|
|