|
|
|
|
@ -1,10 +1,12 @@ |
|
|
|
|
package net.pokeranalytics.android.util |
|
|
|
|
|
|
|
|
|
import android.content.ActivityNotFoundException |
|
|
|
|
import android.content.Context |
|
|
|
|
import android.content.Intent |
|
|
|
|
import android.content.res.Resources |
|
|
|
|
import android.net.Uri |
|
|
|
|
import android.widget.Toast |
|
|
|
|
import androidx.appcompat.app.AlertDialog |
|
|
|
|
import androidx.browser.customtabs.CustomTabsIntent |
|
|
|
|
import androidx.core.content.ContextCompat |
|
|
|
|
import net.pokeranalytics.android.BuildConfig |
|
|
|
|
@ -28,6 +30,7 @@ val Float.px: Float |
|
|
|
|
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() |
|
|
|
|
} |
|
|
|
|
@ -71,3 +74,28 @@ fun PokerAnalyticsActivity.openUrl(url: String) { |
|
|
|
|
val customTabsIntent = builder.build() |
|
|
|
|
customTabsIntent.launchUrl(this, Uri.parse(url)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Display Alert Dialog |
|
|
|
|
fun PokerAnalyticsActivity.showAlertDialog(title: Int? = null, message: Int? = null) { |
|
|
|
|
showAlertDialog(this, title, message) |
|
|
|
|
} |
|
|
|
|
fun PokerAnalyticsFragment.showAlertDialog(title: Int? = null, message: Int? = null) { |
|
|
|
|
context?.let { |
|
|
|
|
showAlertDialog(it, title, message) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create and show an alert dialog |
|
|
|
|
*/ |
|
|
|
|
fun showAlertDialog(context: Context, title: Int? = null, message: Int? = null) { |
|
|
|
|
val builder = AlertDialog.Builder(context) |
|
|
|
|
title?.let { |
|
|
|
|
builder.setTitle(title) |
|
|
|
|
} |
|
|
|
|
message?.let { |
|
|
|
|
builder.setMessage(message) |
|
|
|
|
} |
|
|
|
|
builder.setPositiveButton(R.string.ok, null) |
|
|
|
|
builder.show() |
|
|
|
|
} |