-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from mncinnovation/dev
Extension, alert dialog, snackbar
- Loading branch information
Showing
14 changed files
with
488 additions
and
46 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,97 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:id="@+id/container" | ||
android:background="@color/white" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
android:orientation="vertical" | ||
android:gravity="center" | ||
android:layout_height="match_parent" | ||
android:background="@color/white"> | ||
|
||
<TextView | ||
android:id="@+id/tvMain" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_centerInParent="true" | ||
android:text="Main" | ||
/> | ||
</RelativeLayout> | ||
android:layout_centerHorizontal="true" | ||
android:layout_marginTop="@dimen/margin_large" | ||
android:text="Main" /> | ||
<Button | ||
android:id="@+id/btnShowSnackbar" | ||
style="@style/TextAppearance.AppCompat.Button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/tvMain" | ||
android:layout_centerHorizontal="true" | ||
android:layout_marginTop="@dimen/margin_large" | ||
android:padding="@dimen/padding_large" | ||
android:text="Show snackbar" | ||
android:textSize="@dimen/body2_font_size" | ||
android:textStyle="bold" /> | ||
|
||
<Button | ||
android:id="@+id/btnOpenAppSetting" | ||
style="@style/TextAppearance.AppCompat.Button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/tvMain" | ||
android:layout_centerHorizontal="true" | ||
android:layout_marginTop="@dimen/margin_large" | ||
android:padding="@dimen/padding_large" | ||
android:text="Open App Setting" | ||
android:textSize="@dimen/body2_font_size" | ||
android:textStyle="bold" /> | ||
|
||
<Button | ||
android:id="@+id/btnOpenLocationSetting" | ||
style="@style/TextAppearance.AppCompat.Button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/btnOpenAppSetting" | ||
android:layout_centerHorizontal="true" | ||
android:layout_marginTop="@dimen/margin_large" | ||
android:padding="@dimen/padding_large" | ||
android:text="Open Location Setting" | ||
android:textSize="@dimen/body2_font_size" | ||
android:textStyle="bold" /> | ||
|
||
<Button | ||
android:id="@+id/btnShowAppCompatAlertAction" | ||
style="@style/TextAppearance.AppCompat.Button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/btnOpenLocationSetting" | ||
android:layout_centerHorizontal="true" | ||
android:layout_marginTop="@dimen/margin_large" | ||
android:padding="@dimen/padding_large" | ||
android:text="Show Alert" | ||
android:textSize="@dimen/body2_font_size" | ||
android:textStyle="bold" /> | ||
|
||
<Button | ||
android:id="@+id/btnShowInputName" | ||
style="@style/TextAppearance.AppCompat.Button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/btnShowAppCompatAlertAction" | ||
android:layout_centerHorizontal="true" | ||
android:layout_marginTop="@dimen/margin_large" | ||
android:padding="@dimen/padding_large" | ||
android:text="Show Dialog Input Name" | ||
android:textSize="@dimen/body2_font_size" | ||
android:textStyle="bold" /> | ||
|
||
<Button | ||
android:id="@+id/btnShowDatePicker" | ||
style="@style/TextAppearance.AppCompat.Button" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@id/btnShowInputName" | ||
android:layout_centerHorizontal="true" | ||
android:layout_marginTop="@dimen/margin_large" | ||
android:padding="@dimen/padding_large" | ||
android:text="Show Date Picker" | ||
android:textSize="@dimen/body2_font_size" | ||
android:textStyle="bold" /> | ||
|
||
|
||
</LinearLayout> |
137 changes: 137 additions & 0 deletions
137
core/src/main/java/com/mncgroup/core/util/ext/AlertDialogs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package com.mncgroup.core.util.ext | ||
|
||
import android.app.DatePickerDialog | ||
import android.content.Context | ||
import android.content.DialogInterface | ||
import androidx.appcompat.app.AlertDialog | ||
import androidx.core.content.ContextCompat | ||
import com.google.android.material.textfield.TextInputLayout | ||
import com.mncgroup.core.R | ||
|
||
fun Context.showAppCompatAlert( | ||
messageToShow: String, | ||
title: String? = getString(R.string.label_attention) | ||
): AlertDialog = showAppCompatAlert(messageToShow, title) {} | ||
|
||
fun Context.showAppCompatAlert( | ||
messageToShow: String, | ||
title: String? = getString(R.string.label_attention), | ||
actionTitle: String? = getString(R.string.ok), | ||
actionListener: () -> Unit | ||
): AlertDialog = this.let { context -> | ||
val builder = AlertDialog.Builder(context) | ||
builder.apply { | ||
setMessage(messageToShow) | ||
setTitle(title) | ||
setPositiveButton(actionTitle) { dialogInterface, i -> | ||
dialogInterface.dismiss() | ||
actionListener() | ||
} | ||
} | ||
builder.create() | ||
builder.show() | ||
} | ||
|
||
fun Context.showAppCompatAlertAction( | ||
messageToShow: String, | ||
title: String? = getString(R.string.label_attention), | ||
actionTitle: String? = getString(R.string.ok), | ||
dismissTitle: String? = getString(R.string.cancel), | ||
actionListener: () -> Unit | ||
): AlertDialog = | ||
showAppCompatAlertAction(messageToShow, title, actionTitle, dismissTitle, actionListener) {} | ||
|
||
fun Context.showAppCompatAlertAction( | ||
messageToShow: String, | ||
title: String? = getString(R.string.label_attention), | ||
actionTitle: String? = getString(R.string.ok), | ||
dismissTitle: String? = getString(R.string.cancel), | ||
actionListener: () -> Unit, dismissListener: () -> Unit | ||
): AlertDialog = this.let { context -> | ||
val builder = AlertDialog.Builder(context) | ||
builder.apply { | ||
setMessage(messageToShow) | ||
setTitle(title) | ||
setPositiveButton(actionTitle) { dialogInterface, i -> | ||
dialogInterface.dismiss() | ||
actionListener() | ||
} | ||
|
||
setNegativeButton(dismissTitle) { dialogInterface, i -> | ||
dialogInterface.dismiss() | ||
dismissListener() | ||
} | ||
} | ||
builder.create() | ||
builder.show().apply { | ||
getButton(DialogInterface.BUTTON_NEGATIVE)?.setTextColor( | ||
ContextCompat.getColor( | ||
context, | ||
R.color.dust | ||
) | ||
) | ||
} | ||
} | ||
|
||
fun Context.showAppCompatAlertInputAction( | ||
messageToShow: String? = null, | ||
title: String? = null, | ||
actionTitle: String? = getString(R.string.title_submit), | ||
negativeTitle: String? = getString(R.string.cancel), | ||
textHint: String? = null, cancelable: Boolean = false, | ||
actionListener: (input: String) -> Unit | ||
): AlertDialog = showAppCompatAlertInputAction(messageToShow, title, actionTitle, negativeTitle, textHint, cancelable, actionListener, {}) | ||
|
||
fun Context.showAppCompatAlertInputAction( | ||
messageToShow: String? = null, | ||
title: String? = null, | ||
actionTitle: String? = getString(R.string.title_submit), | ||
negativeTitle: String? = getString(R.string.cancel), | ||
textHint: String? = null, cancelable: Boolean = false, | ||
actionListener: (input: String) -> Unit, | ||
dismissListener: () -> Unit = {} | ||
): AlertDialog = this.let { context -> | ||
val builder = AlertDialog.Builder(context) | ||
builder.apply { | ||
if (title != null) { | ||
this.setTitle(title) | ||
} | ||
if (messageToShow != null) { | ||
this.setMessage(messageToShow) | ||
} | ||
val layoutInflater = | ||
getSystemService(Context.LAYOUT_INFLATER_SERVICE) as android.view.LayoutInflater | ||
val textInput = layoutInflater.inflate(R.layout.dialog_input, null) as TextInputLayout | ||
textInput.hint = textHint | ||
|
||
builder.setView(textInput) | ||
|
||
setCancelable(cancelable) | ||
|
||
negativeTitle?.let { | ||
setNegativeButton(it) { p0, p1 -> | ||
p0.dismiss() | ||
dismissListener() | ||
} | ||
} | ||
|
||
setPositiveButton(actionTitle) { p0, p1 -> | ||
p0.dismiss() | ||
actionListener(textInput.editText?.text.toString()) | ||
} | ||
|
||
setOnCancelListener { | ||
it.dismiss() | ||
dismissListener() | ||
} | ||
}.create() | ||
|
||
builder.show().apply { | ||
getButton(DialogInterface.BUTTON_NEGATIVE)?.setTextColor( | ||
ContextCompat.getColor( | ||
context, | ||
R.color.dust | ||
) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.