-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
193b5bb
commit 4f7c25b
Showing
37 changed files
with
222 additions
and
194 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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...lerts-kotlin/src/main/AndroidManifest.xml → alerts/src/main/AndroidManifest.xml
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
2 changes: 1 addition & 1 deletion
2
...m/kevicsalazar/appkit_alerts/BaseAlert.kt → ...n/kotlin/pe/startapps/alerts/BaseAlert.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
2 changes: 1 addition & 1 deletion
2
...vicsalazar/appkit_alerts/DownloadAlert.kt → ...tlin/pe/startapps/alerts/DownloadAlert.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
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
112 changes: 112 additions & 0 deletions
112
alerts/src/main/kotlin/pe/startapps/alerts/StandardAlert.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,112 @@ | ||
package pe.startapps.alerts | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import android.view.View | ||
import android.view.animation.AnimationUtils | ||
import kotlinx.android.synthetic.main.alert_standard.* | ||
import pe.startapps.alerts.ext.AlertType | ||
import pe.startapps.alerts.ext.InputType | ||
|
||
/** | ||
* @author Kevin Salazar | ||
* @link kevicsalazar.com | ||
*/ | ||
class StandardAlert(context: Context, val type: AlertType) : BaseAlert(context) { | ||
|
||
var titleText: String? = null | ||
var contentText: String? = null | ||
var iconResId: Int? = null | ||
var hintText: String? = null | ||
var inputType = InputType.Text | ||
|
||
private var cancelText: String? = null | ||
private var confirmText: String? = null | ||
|
||
private var mOnCancel: ((StandardAlert) -> Unit)? = null | ||
private var mOnConfirm: ((StandardAlert) -> Unit)? = null | ||
private var mOnConfirmWithText: ((StandardAlert, String) -> Unit)? = null | ||
|
||
override val layout: Int get() = R.layout.alert_standard | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
update() | ||
|
||
when (type) { | ||
AlertType.Normal -> btnConfirm.setBackgroundResource(R.drawable.bg_btn_confirm) | ||
AlertType.Warning -> btnConfirm.setBackgroundResource(R.drawable.bg_btn_warning) | ||
AlertType.InputText -> { | ||
etInput.hint = hintText | ||
etInput.inputType = inputType.value | ||
etInput.visibility = View.VISIBLE | ||
} | ||
AlertType.Progress -> { | ||
progressBar.visibility = View.VISIBLE | ||
ivIcon.visibility = View.GONE | ||
btnCancel.visibility = View.GONE | ||
btnConfirm.visibility = View.GONE | ||
} | ||
} | ||
|
||
} | ||
|
||
fun update() { | ||
|
||
titleText?.let { | ||
tvTitle.text = it | ||
tvTitle.visibility = View.VISIBLE | ||
} | ||
|
||
contentText?.let { | ||
tvContent.text = it | ||
tvContent.visibility = View.VISIBLE | ||
} | ||
|
||
cancelText?.let { | ||
btnCancel.text = it | ||
btnCancel.visibility = View.VISIBLE | ||
btnCancel.setOnClickListener { | ||
mOnCancel?.invoke(this@StandardAlert) ?: this@StandardAlert.dismiss() | ||
} | ||
} | ||
|
||
confirmText?.let { | ||
btnConfirm.text = it | ||
btnConfirm.visibility = View.VISIBLE | ||
btnConfirm.setOnClickListener { | ||
mOnConfirm?.invoke(this@StandardAlert) ?: mOnConfirmWithText?.let { | ||
if (etInput.text.isNullOrBlank()) { | ||
val shake = AnimationUtils.loadAnimation(context, R.anim.shake) | ||
etInput.startAnimation(shake) | ||
} else { | ||
mOnConfirmWithText?.invoke(this@StandardAlert, etInput.text.toString()) | ||
} | ||
} ?: this@StandardAlert.dismiss() | ||
} | ||
} | ||
|
||
iconResId?.let { | ||
ivIcon.setImageResource(it) | ||
ivIcon.visibility = View.VISIBLE | ||
} | ||
|
||
} | ||
|
||
fun cancelButton(cancelText: String, listener: ((StandardAlert) -> Unit)? = null) { | ||
this.cancelText = cancelText | ||
this.mOnCancel = listener | ||
} | ||
|
||
fun confirmButton(confirmText: String, listener: ((StandardAlert) -> Unit)? = null) { | ||
this.confirmText = confirmText | ||
this.mOnConfirm = listener | ||
} | ||
|
||
fun confirmButtonWithText(confirmText: String, listener: ((StandardAlert, String) -> Unit)? = null) { | ||
this.confirmText = confirmText | ||
this.mOnConfirmWithText = listener | ||
} | ||
|
||
} |
32 changes: 19 additions & 13 deletions
32
.../kevicsalazar/appkit_alerts/ext/Alerts.kt → .../kotlin/pe/startapps/alerts/ext/Alerts.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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Oops, something went wrong.