Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ArbazMateen committed Jun 16, 2019
1 parent b82b8b1 commit e6d08a7
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 0 additions & 74 deletions dialogs/src/main/java/com/arbazmateen/dialogs/InputDialogs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Int, View>,
private val dialog: AlertDialog) {

fun show() {
dialog.show()
}

/**************************************************************************
** Builder pattern
**************************************************************************/
class Builder(private val context: Context) {

private var layout = 0
private var viewsList: MutableList<Int> = mutableListOf()
private var viewMap: MutableMap<Int, View> = 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<Int, View>, 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<Int>) = apply { viewsList = list as MutableList<Int> }

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()
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions extensions/src/main/java/com/arbazmateen/extensions/Extensions.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.arbazmateen.extensions

import android.animation.ValueAnimator
import android.content.Context
import android.text.Spannable
import android.text.SpannableString
Expand Down Expand Up @@ -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
**************************************************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e6d08a7

Please sign in to comment.