@ -9,13 +9,11 @@ import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Color
import android.net.Uri
import android.net.Uri
import android.text.SpannableStringBuilder
import android.util.TypedValue
import android.util.TypedValue
import android.view.View
import android.view.View
import android.view.inputmethod.InputMethodManager
import android.view.inputmethod.InputMethodManager
import android.widget.ImageView
import android.widget.*
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.SearchView
import androidx.appcompat.widget.SearchView
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat
@ -84,7 +82,11 @@ fun BaseActivity.openContactMail(subjectStringRes: Int, filePath: String? = null
filePath ?. let {
filePath ?. let {
val databaseFile = File ( it )
val databaseFile = File ( it )
val contentUri = FileProvider . getUriForFile ( this , " net.pokeranalytics.android.fileprovider " , databaseFile )
val contentUri = FileProvider . getUriForFile (
this ,
" net.pokeranalytics.android.fileprovider " ,
databaseFile
)
if ( contentUri != null ) {
if ( contentUri != null ) {
emailIntent . addFlags ( Intent . FLAG _GRANT _READ _URI _PERMISSION )
emailIntent . addFlags ( Intent . FLAG _GRANT _READ _URI _PERMISSION )
emailIntent . setDataAndType ( contentUri , contentResolver . getType ( contentUri ) )
emailIntent . setDataAndType ( contentUri , contentResolver . getType ( contentUri ) )
@ -107,7 +109,12 @@ fun Context.openUrl(url: String) {
}
}
// Open custom tab
// Open custom tab
fun Context . areYouSure ( title : Int ? = null , message : Int ? = null , positiveTitle : Int ? = null , proceed : ( ) -> Unit ) {
fun Context . areYouSure (
title : Int ? = null ,
message : Int ? = null ,
positiveTitle : Int ? = null ,
proceed : ( ) -> Unit
) {
val builder : android . app . AlertDialog . Builder = android . app . AlertDialog . Builder ( this )
val builder : android . app . AlertDialog . Builder = android . app . AlertDialog . Builder ( this )
@ -123,22 +130,7 @@ fun Context.areYouSure(title: Int? = null, message: Int? = null, positiveTitle:
builder . setNegativeButton ( R . string . cancel ) { _ , _ ->
builder . setNegativeButton ( R . string . cancel ) { _ , _ ->
// nothing
// nothing
}
}
// builder.setItems(
// arrayOf<CharSequence>(
// getString(R.string.yes),
// getString(R.string.cancel)
// )
// ) { _, index ->
// // The 'which' argument contains the index position
// // of the selected item
// when (index) {
// 0 -> proceed()
// 1 -> {} // nothing
// }
// }
builder . create ( ) . show ( )
builder . create ( ) . show ( )
}
}
// Display Alert Dialog
// Display Alert Dialog
@ -146,17 +138,52 @@ fun Activity.showAlertDialog(title: Int? = null, message: Int? = null) {
showAlertDialog ( this , title , message )
showAlertDialog ( this , title , message )
}
}
fun Fragment . showAlertDialog ( title : Int ? = null , messageResId : Int ? = null , message : String ? = null ) {
fun Fragment . showAlertDialog (
title : Int ? = null ,
messageResId : Int ? = null ,
message : String ? = null
) {
context ?. let {
context ?. let {
showAlertDialog ( it , title , messageResId , message )
showAlertDialog ( it , title , messageResId , message )
}
}
}
}
fun showEditTextAlertDialog (
context : Context , inputType : Int , title : Int ? = null , messageResId : Int ? = null , message : String ? = null ,
editTextText : String ? = null , positiveAction : ( ( String ) -> Unit ) ? = null
) {
val builder = AlertDialog . Builder ( context )
title ?. let {
builder . setTitle ( title )
}
messageResId ?. let {
builder . setMessage ( messageResId )
}
message ?. let {
builder . setMessage ( it )
}
val editText = EditText ( context )
editTextText ?. let {
editText . text = SpannableStringBuilder ( it )
}
editText . setTextColor ( ContextCompat . getColor ( context , R . color . white ) )
editText . inputType = inputType
builder . setView ( editText )
builder . setPositiveButton ( net . pokeranalytics . android . R . string . ok ) { _ , _ ->
positiveAction ?. invoke ( editText . text . toString ( ) )
}
builder . show ( )
}
/ * *
/ * *
* Create and show an alert dialog
* Create and show an alert dialog
* /
* /
fun showAlertDialog (
fun showAlertDialog (
context : Context , title : Int ? = null , messageResId : Int ? = null , message : String ? = null , cancelButtonTitle : Int ? = null , showCancelButton : Boolean = false ,
context : Context , title : Int ? = null , messageResId : Int ? = null , message : String ? = null ,
cancelButtonTitle : Int ? = null , showCancelButton : Boolean = false ,
positiveAction : ( ( ) -> Unit ) ? = null , negativeAction : ( ( ) -> Unit ) ? = null
positiveAction : ( ( ) -> Unit ) ? = null , negativeAction : ( ( ) -> Unit ) ? = null
) {
) {
val builder = AlertDialog . Builder ( context )
val builder = AlertDialog . Builder ( context )
@ -216,7 +243,7 @@ fun SearchView.removeMargins() {
searchEditFrame ?. layoutParams = layoutParams
searchEditFrame ?. layoutParams = layoutParams
}
}
fun View . toByteArray ( ) : ByteArray {
fun View . toByteArray ( ) : ByteArray {
return this . convertToBitmap ( ) . toByteArray ( )
return this . convertToBitmap ( ) . toByteArray ( )
}
}
@ -233,11 +260,11 @@ fun View.convertToBitmap(): Bitmap {
return b
return b
}
}
fun ImageView . toByteArray ( ) : ByteArray {
fun ImageView . toByteArray ( ) : ByteArray {
return this . drawable . toBitmap ( ) . toByteArray ( )
return this . drawable . toBitmap ( ) . toByteArray ( )
}
}
fun Bitmap . toByteArray ( ) : ByteArray {
fun Bitmap . toByteArray ( ) : ByteArray {
val baos = ByteArrayOutputStream ( )
val baos = ByteArrayOutputStream ( )
this . compress ( Bitmap . CompressFormat . PNG , 100 , baos )
this . compress ( Bitmap . CompressFormat . PNG , 100 , baos )
return baos . toByteArray ( )
return baos . toByteArray ( )