From e6d08a7046f1ffd7dba5162c403615b934f389d6 Mon Sep 17 00:00:00 2001 From: Arbaz Mateen Date: Sun, 16 Jun 2019 22:01:08 +0500 Subject: [PATCH] changes --- .idea/misc.xml | 2 +- .../com/arbazmateen/dialogs/InputDialogs.kt | 74 ------------------- .../extensions/ActivityExtensions.kt | 9 +++ .../extensions/DateTimeExtensions.kt | 29 ++++---- .../com/arbazmateen/extensions/Extensions.kt | 15 ++++ .../extensions/FragmentExtensions.kt | 9 +++ 6 files changed, 49 insertions(+), 89 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 51fa3e5..cc04cd3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -35,7 +35,7 @@ - + diff --git a/dialogs/src/main/java/com/arbazmateen/dialogs/InputDialogs.kt b/dialogs/src/main/java/com/arbazmateen/dialogs/InputDialogs.kt index 5abc3f6..3f6b88a 100644 --- a/dialogs/src/main/java/com/arbazmateen/dialogs/InputDialogs.kt +++ b/dialogs/src/main/java/com/arbazmateen/dialogs/InputDialogs.kt @@ -2,11 +2,9 @@ package com.arbazmateen.dialogs import android.app.AlertDialog import android.content.Context -import android.content.DialogInterface import android.text.InputType import android.view.KeyEvent import android.view.LayoutInflater -import android.view.View import android.view.inputmethod.EditorInfo import android.widget.EditText import com.google.android.material.textfield.TextInputLayout @@ -196,75 +194,3 @@ class SingleInputDialog private constructor(private val dialog: AlertDialog) { } } } - -/************************************************************************** -** Custom layout dialog -**************************************************************************/ -class CustomLayoutDialog private constructor(private val layout: Int, - private val viewMap: MutableMap, - private val dialog: AlertDialog) { - - fun show() { - dialog.show() - } - - /************************************************************************** - ** Builder pattern - **************************************************************************/ - class Builder(private val context: Context) { - - private var layout = 0 - private var viewsList: MutableList = mutableListOf() - private var viewMap: MutableMap = mutableMapOf() - - private var title = "" - private var positiveButtonText = "OK" - private var negativeButtonText = "CANCEL" - - private var cancelable = false - - private lateinit var dialogBuilder: AlertDialog.Builder - private lateinit var dialog: AlertDialog - - private var submitListener: ((viewMap: Map, dialog: DialogInterface) -> Unit)? = null - private var cancelListener: ((dialog: DialogInterface) -> Unit)? = null - - - fun title(title: String) = apply { this.title = title } - fun cancelable(cancelAble: Boolean) = apply { this.cancelable = cancelAble } - - fun setLayout(layout: Int) = apply { this.layout = layout } - fun addView(resId: Int) = apply { viewsList.add(resId) } - fun addViews(vararg resId: Int) = apply { resId.forEach { viewsList.add(it) } } - fun addViews(list: List) = apply { viewsList = list as MutableList } - - fun build(): CustomLayoutDialog { - initDialog() - return CustomLayoutDialog(layout, viewMap, dialog) - } - - private fun initDialog() { - dialogBuilder = AlertDialog.Builder(context) - - val view = LayoutInflater.from(context).inflate(R.layout.dialog_single_input, null) - - viewsList.forEach { - viewMap[it] = view.findViewById(it) - } - - dialogBuilder.setTitle(title).setCancelable(cancelable).setView(view) - - dialogBuilder.setPositiveButton(positiveButtonText) { dialog, _ -> - submitListener?.invoke(viewMap, dialog) - } - - dialogBuilder.setNegativeButton(negativeButtonText) { dialog, _ -> - cancelListener?.invoke(dialog) - } - - dialog = dialogBuilder.create() - } - - } - -} \ No newline at end of file diff --git a/extensions/src/main/java/com/arbazmateen/extensions/ActivityExtensions.kt b/extensions/src/main/java/com/arbazmateen/extensions/ActivityExtensions.kt index e1d85c5..044ddd2 100644 --- a/extensions/src/main/java/com/arbazmateen/extensions/ActivityExtensions.kt +++ b/extensions/src/main/java/com/arbazmateen/extensions/ActivityExtensions.kt @@ -30,6 +30,15 @@ fun Activity.hideKeyboard(view: View) { imm.hideSoftInputFromWindow(view.windowToken, 0) } +fun Activity.showKeyboard() { + val imm = this.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0) +} + +fun Activity.isKeyAvailable(key: String): Boolean { + return (intent != null && intent.extras != null && intent.extras!!.containsKey(key)) +} + fun Activity.getIntValue(key: String, default: Int = 0): Int { if(intent != null && intent.extras != null && intent.extras!!.containsKey(key)) { return intent.extras?.getInt(key) ?: default diff --git a/extensions/src/main/java/com/arbazmateen/extensions/DateTimeExtensions.kt b/extensions/src/main/java/com/arbazmateen/extensions/DateTimeExtensions.kt index cebe96f..aa0263b 100644 --- a/extensions/src/main/java/com/arbazmateen/extensions/DateTimeExtensions.kt +++ b/extensions/src/main/java/com/arbazmateen/extensions/DateTimeExtensions.kt @@ -4,20 +4,21 @@ import java.text.SimpleDateFormat import java.util.* object DateFormat { - val D_MM_YY = "d MM yy" // 4 07 17 - val DD_MM_YY = "dd MM yy" // 04 07 17 - val D_MMM_YY = "d MMM yy" // 4 Jul 17 - val D_MMM_YYYY = "d MMM yyyy" // 4 Jul 2017 - val DD_MM_YYYY = "dd MM yyyy" // 04 07 2017 - val DD_MMM_YY = "dd MMM yy" // 04 Jul 17 - val DD_MMM_YYYY = "dd MMM yyyy" // 04 Jul 2017 - val DD_MMMM_YY = "dd MMMM yy" // 04 July 17 - val DD_MMMM_YYYY = "dd MMMM yyyy" // 04 July 2017 - val EEE_DD_MM_YY = "EEE, dd MM yy" // WED, 04 07 17 - val EEE_DD_MM_YYYY = "EEE, dd MM yyyy" // WED, 04 07 2017 - val EEE_D_MMM_YYYY = "EEE, d MMM yyyy" // WED, 4 Jul 2017 - val EEE_DD_MMM_YYYY = "EEE, dd MMM yyyy" // WED, 04 Jul 2017 - val EEE_DD_MMMM_YYYY = "EEE, dd MMMM yyyy" // WED, 04 July 2017 + const val D_MM_YY = "d MM yy" // 4 07 17 + const val DD_MM_YY = "dd MM yy" // 04 07 17 + const val D_MMM_YY = "d MMM yy" // 4 Jul 17 + const val D_MMM_YYYY = "d MMM yyyy" // 4 Jul 2017 + const val DD_MM_YYYY = "dd MM yyyy" // 04 07 2017 + const val DD_MMM_YY = "dd MMM yy" // 04 Jul 17 + const val DD_MMM_YYYY = "dd MMM yyyy" // 04 Jul 2017 + const val DD_MMMM_YY = "dd MMMM yy" // 04 July 17 + const val DD_MMMM_YYYY = "dd MMMM yyyy" // 04 July 2017 + const val EEE_DD_MM_YY = "EEE, dd MM yy" // WED, 04 07 17 + const val EEE_DD_MM_YYYY = "EEE, dd MM yyyy" // WED, 04 07 2017 + const val EEE_D_MMM_YYYY = "EEE, d MMM yyyy" // WED, 4 Jul 2017 + const val EEE_DD_MMM_YY = "EEE, dd MMM yy" // WED, 04 Jul 17 + const val EEE_DD_MMM_YYYY = "EEE, dd MMM yyyy" // WED, 04 Jul 2017 + const val EEE_DD_MMMM_YYYY = "EEE, dd MMMM yyyy" // WED, 04 July 2017 val SQL_DATE_FORMAT = "yyyy-MM-dd" // 2017-07-17 val SQL_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss" // 2017-07-17 16:05:30 diff --git a/extensions/src/main/java/com/arbazmateen/extensions/Extensions.kt b/extensions/src/main/java/com/arbazmateen/extensions/Extensions.kt index 07ae36e..7f5c2b4 100644 --- a/extensions/src/main/java/com/arbazmateen/extensions/Extensions.kt +++ b/extensions/src/main/java/com/arbazmateen/extensions/Extensions.kt @@ -1,5 +1,6 @@ package com.arbazmateen.extensions +import android.animation.ValueAnimator import android.content.Context import android.text.Spannable import android.text.SpannableString @@ -61,6 +62,20 @@ fun Any.toastShort(context: Context, text: String) { Toast.makeText(context, text, Toast.LENGTH_SHORT).show() } +fun Any.animateIntValue(finalValue: Int, textView: TextView) { + val animator: ValueAnimator = ValueAnimator.ofInt(0, finalValue) + animator.duration = when { + finalValue < 10 -> 250 + finalValue < 100 -> 500 + finalValue < 1000 -> 750 + else -> 1000 + } + animator.addUpdateListener { animation -> + textView.text = animation.animatedValue.toString().toInt().format() + } + animator.start() +} + /************************************************************************** ** EditText Extensions **************************************************************************/ diff --git a/extensions/src/main/java/com/arbazmateen/extensions/FragmentExtensions.kt b/extensions/src/main/java/com/arbazmateen/extensions/FragmentExtensions.kt index 9b78aac..61eea53 100644 --- a/extensions/src/main/java/com/arbazmateen/extensions/FragmentExtensions.kt +++ b/extensions/src/main/java/com/arbazmateen/extensions/FragmentExtensions.kt @@ -33,6 +33,15 @@ fun Fragment.hideKeyboard(context: Context, view: View) { imm.hideSoftInputFromWindow(view.windowToken, 0) } +fun Fragment.showKeyboard(context: Context) { + val imm = context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0) +} + +fun Fragment.isKeyAvailable(key: String): Boolean { + return (arguments != null && arguments!!.containsKey(key)) +} + fun Fragment.getIntValue(key: String, default: Int = 0): Int { if(arguments != null && arguments!!.containsKey(key)) { return arguments?.getInt(key, default) ?: default