Skip to content

Commit e6d08a7

Browse files
committed
changes
1 parent b82b8b1 commit e6d08a7

File tree

6 files changed

+49
-89
lines changed

6 files changed

+49
-89
lines changed

.idea/misc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dialogs/src/main/java/com/arbazmateen/dialogs/InputDialogs.kt

-74
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ package com.arbazmateen.dialogs
22

33
import android.app.AlertDialog
44
import android.content.Context
5-
import android.content.DialogInterface
65
import android.text.InputType
76
import android.view.KeyEvent
87
import android.view.LayoutInflater
9-
import android.view.View
108
import android.view.inputmethod.EditorInfo
119
import android.widget.EditText
1210
import com.google.android.material.textfield.TextInputLayout
@@ -196,75 +194,3 @@ class SingleInputDialog private constructor(private val dialog: AlertDialog) {
196194
}
197195
}
198196
}
199-
200-
/**************************************************************************
201-
** Custom layout dialog
202-
**************************************************************************/
203-
class CustomLayoutDialog private constructor(private val layout: Int,
204-
private val viewMap: MutableMap<Int, View>,
205-
private val dialog: AlertDialog) {
206-
207-
fun show() {
208-
dialog.show()
209-
}
210-
211-
/**************************************************************************
212-
** Builder pattern
213-
**************************************************************************/
214-
class Builder(private val context: Context) {
215-
216-
private var layout = 0
217-
private var viewsList: MutableList<Int> = mutableListOf()
218-
private var viewMap: MutableMap<Int, View> = mutableMapOf()
219-
220-
private var title = ""
221-
private var positiveButtonText = "OK"
222-
private var negativeButtonText = "CANCEL"
223-
224-
private var cancelable = false
225-
226-
private lateinit var dialogBuilder: AlertDialog.Builder
227-
private lateinit var dialog: AlertDialog
228-
229-
private var submitListener: ((viewMap: Map<Int, View>, dialog: DialogInterface) -> Unit)? = null
230-
private var cancelListener: ((dialog: DialogInterface) -> Unit)? = null
231-
232-
233-
fun title(title: String) = apply { this.title = title }
234-
fun cancelable(cancelAble: Boolean) = apply { this.cancelable = cancelAble }
235-
236-
fun setLayout(layout: Int) = apply { this.layout = layout }
237-
fun addView(resId: Int) = apply { viewsList.add(resId) }
238-
fun addViews(vararg resId: Int) = apply { resId.forEach { viewsList.add(it) } }
239-
fun addViews(list: List<Int>) = apply { viewsList = list as MutableList<Int> }
240-
241-
fun build(): CustomLayoutDialog {
242-
initDialog()
243-
return CustomLayoutDialog(layout, viewMap, dialog)
244-
}
245-
246-
private fun initDialog() {
247-
dialogBuilder = AlertDialog.Builder(context)
248-
249-
val view = LayoutInflater.from(context).inflate(R.layout.dialog_single_input, null)
250-
251-
viewsList.forEach {
252-
viewMap[it] = view.findViewById(it)
253-
}
254-
255-
dialogBuilder.setTitle(title).setCancelable(cancelable).setView(view)
256-
257-
dialogBuilder.setPositiveButton(positiveButtonText) { dialog, _ ->
258-
submitListener?.invoke(viewMap, dialog)
259-
}
260-
261-
dialogBuilder.setNegativeButton(negativeButtonText) { dialog, _ ->
262-
cancelListener?.invoke(dialog)
263-
}
264-
265-
dialog = dialogBuilder.create()
266-
}
267-
268-
}
269-
270-
}

extensions/src/main/java/com/arbazmateen/extensions/ActivityExtensions.kt

+9
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ fun Activity.hideKeyboard(view: View) {
3030
imm.hideSoftInputFromWindow(view.windowToken, 0)
3131
}
3232

33+
fun Activity.showKeyboard() {
34+
val imm = this.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
35+
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0)
36+
}
37+
38+
fun Activity.isKeyAvailable(key: String): Boolean {
39+
return (intent != null && intent.extras != null && intent.extras!!.containsKey(key))
40+
}
41+
3342
fun Activity.getIntValue(key: String, default: Int = 0): Int {
3443
if(intent != null && intent.extras != null && intent.extras!!.containsKey(key)) {
3544
return intent.extras?.getInt(key) ?: default

extensions/src/main/java/com/arbazmateen/extensions/DateTimeExtensions.kt

+15-14
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@ import java.text.SimpleDateFormat
44
import java.util.*
55

66
object DateFormat {
7-
val D_MM_YY = "d MM yy" // 4 07 17
8-
val DD_MM_YY = "dd MM yy" // 04 07 17
9-
val D_MMM_YY = "d MMM yy" // 4 Jul 17
10-
val D_MMM_YYYY = "d MMM yyyy" // 4 Jul 2017
11-
val DD_MM_YYYY = "dd MM yyyy" // 04 07 2017
12-
val DD_MMM_YY = "dd MMM yy" // 04 Jul 17
13-
val DD_MMM_YYYY = "dd MMM yyyy" // 04 Jul 2017
14-
val DD_MMMM_YY = "dd MMMM yy" // 04 July 17
15-
val DD_MMMM_YYYY = "dd MMMM yyyy" // 04 July 2017
16-
val EEE_DD_MM_YY = "EEE, dd MM yy" // WED, 04 07 17
17-
val EEE_DD_MM_YYYY = "EEE, dd MM yyyy" // WED, 04 07 2017
18-
val EEE_D_MMM_YYYY = "EEE, d MMM yyyy" // WED, 4 Jul 2017
19-
val EEE_DD_MMM_YYYY = "EEE, dd MMM yyyy" // WED, 04 Jul 2017
20-
val EEE_DD_MMMM_YYYY = "EEE, dd MMMM yyyy" // WED, 04 July 2017
7+
const val D_MM_YY = "d MM yy" // 4 07 17
8+
const val DD_MM_YY = "dd MM yy" // 04 07 17
9+
const val D_MMM_YY = "d MMM yy" // 4 Jul 17
10+
const val D_MMM_YYYY = "d MMM yyyy" // 4 Jul 2017
11+
const val DD_MM_YYYY = "dd MM yyyy" // 04 07 2017
12+
const val DD_MMM_YY = "dd MMM yy" // 04 Jul 17
13+
const val DD_MMM_YYYY = "dd MMM yyyy" // 04 Jul 2017
14+
const val DD_MMMM_YY = "dd MMMM yy" // 04 July 17
15+
const val DD_MMMM_YYYY = "dd MMMM yyyy" // 04 July 2017
16+
const val EEE_DD_MM_YY = "EEE, dd MM yy" // WED, 04 07 17
17+
const val EEE_DD_MM_YYYY = "EEE, dd MM yyyy" // WED, 04 07 2017
18+
const val EEE_D_MMM_YYYY = "EEE, d MMM yyyy" // WED, 4 Jul 2017
19+
const val EEE_DD_MMM_YY = "EEE, dd MMM yy" // WED, 04 Jul 17
20+
const val EEE_DD_MMM_YYYY = "EEE, dd MMM yyyy" // WED, 04 Jul 2017
21+
const val EEE_DD_MMMM_YYYY = "EEE, dd MMMM yyyy" // WED, 04 July 2017
2122

2223
val SQL_DATE_FORMAT = "yyyy-MM-dd" // 2017-07-17
2324
val SQL_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss" // 2017-07-17 16:05:30

extensions/src/main/java/com/arbazmateen/extensions/Extensions.kt

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.arbazmateen.extensions
22

3+
import android.animation.ValueAnimator
34
import android.content.Context
45
import android.text.Spannable
56
import android.text.SpannableString
@@ -61,6 +62,20 @@ fun Any.toastShort(context: Context, text: String) {
6162
Toast.makeText(context, text, Toast.LENGTH_SHORT).show()
6263
}
6364

65+
fun Any.animateIntValue(finalValue: Int, textView: TextView) {
66+
val animator: ValueAnimator = ValueAnimator.ofInt(0, finalValue)
67+
animator.duration = when {
68+
finalValue < 10 -> 250
69+
finalValue < 100 -> 500
70+
finalValue < 1000 -> 750
71+
else -> 1000
72+
}
73+
animator.addUpdateListener { animation ->
74+
textView.text = animation.animatedValue.toString().toInt().format()
75+
}
76+
animator.start()
77+
}
78+
6479
/**************************************************************************
6580
** EditText Extensions
6681
**************************************************************************/

extensions/src/main/java/com/arbazmateen/extensions/FragmentExtensions.kt

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ fun Fragment.hideKeyboard(context: Context, view: View) {
3333
imm.hideSoftInputFromWindow(view.windowToken, 0)
3434
}
3535

36+
fun Fragment.showKeyboard(context: Context) {
37+
val imm = context.getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
38+
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0)
39+
}
40+
41+
fun Fragment.isKeyAvailable(key: String): Boolean {
42+
return (arguments != null && arguments!!.containsKey(key))
43+
}
44+
3645
fun Fragment.getIntValue(key: String, default: Int = 0): Int {
3746
if(arguments != null && arguments!!.containsKey(key)) {
3847
return arguments?.getInt(key, default) ?: default

0 commit comments

Comments
 (0)