Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
kevicsalazar committed Jan 21, 2018
1 parent 193b5bb commit 4f7c25b
Show file tree
Hide file tree
Showing 37 changed files with 222 additions and 194 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.xml

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

2 changes: 1 addition & 1 deletion .idea/markdown-navigator/profiles_settings.xml

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

12 changes: 1 addition & 11 deletions .idea/misc.xml

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

5 changes: 4 additions & 1 deletion .idea/modules.xml

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

File renamed without changes.
16 changes: 8 additions & 8 deletions appkit-alerts-kotlin/build.gradle → alerts/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

group = 'com.github.kevicsalazar'
group = 'pe.startapps'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 27
buildToolsVersion "27.0.2"

defaultConfig {
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0.1"
targetSdkVersion 27
versionCode 110
versionName "1.1.0"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
Expand All @@ -28,6 +28,6 @@ android {
}

dependencies {
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'org.jetbrains.kotlin:kotlin-stdlib:1.0.6'
compile 'com.android.support:appcompat-v7:27.0.2'
compile 'org.jetbrains.kotlin:kotlin-stdlib:1.2.20'
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kevicsalazar.appkit_alerts">
package="pe.startapps.alerts">

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kevicsalazar.appkit_alerts
package pe.startapps.alerts

import android.app.Dialog
import android.content.Context
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kevicsalazar.appkit_alerts
package pe.startapps.alerts

import android.content.Context
import android.os.Bundle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kevicsalazar.appkit_alerts
package pe.startapps.alerts

import android.content.Context
import android.os.Bundle
Expand Down Expand Up @@ -29,12 +29,10 @@ class SelectorAlert(context: Context) : BaseAlert(context) {
tvTitle.visibility = View.VISIBLE
}

val aa: ArrayAdapter<String>
aa = ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, itemList)
listview.adapter = aa
listview.adapter = ArrayAdapter(context, android.R.layout.simple_list_item_1, itemList)

onItemClick?.let {
listview.setOnItemClickListener { adapterView, view, i, l ->
listview.setOnItemClickListener { _, _, i, _ ->
onItemClick!!.invoke(i)
this@SelectorAlert.dismiss()
}
Expand Down
112 changes: 112 additions & 0 deletions alerts/src/main/kotlin/pe/startapps/alerts/StandardAlert.kt
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
}

}
Original file line number Diff line number Diff line change
@@ -1,49 +1,55 @@
package com.kevicsalazar.appkit_alerts.ext
package pe.startapps.alerts.ext

import android.content.Context
import android.support.v4.app.Fragment
import com.kevicsalazar.appkit_alerts.DownloadAlert
import com.kevicsalazar.appkit_alerts.SelectorAlert
import com.kevicsalazar.appkit_alerts.StandardAlert
import pe.startapps.alerts.DownloadAlert
import pe.startapps.alerts.SelectorAlert
import pe.startapps.alerts.StandardAlert

/**
* @author Kevin Salazar
* @link kevicsalazar.com
*/

fun Context.Alert(title: String? = null, content: String? = null, type: AlertType = AlertType.Normal, init: (StandardAlert.() -> Unit)? = null) = StandardAlert(this, type).apply {
fun Context.alert(title: String? = null, content: String? = null, type: AlertType = AlertType.Normal, init: (StandardAlert.() -> Unit)? = null) = StandardAlert(this, type).apply {
this.titleText = title
this.contentText = content
if (init != null) init()
}

fun Context.InputTextAlert(title: String? = null, hint: String, inputType: InputType = InputType.Text, init: (StandardAlert.() -> Unit)? = null) = StandardAlert(this, AlertType.InputText).apply {
fun Context.progressAlert(title: String? = null, content: String? = null, init: (StandardAlert.() -> Unit)? = null) = StandardAlert(this, AlertType.Progress).apply {
this.titleText = title
this.contentText = content
if (init != null) init()
}

fun Context.inputTextAlert(title: String? = null, hint: String, inputType: InputType = InputType.Text, init: (StandardAlert.() -> Unit)? = null) = StandardAlert(this, AlertType.InputText).apply {
this.titleText = title
this.hintText = hint
this.inputType = inputType
if (init != null) init()
}

fun Context.SelectorAlert(title: String? = null, itemList: List<String>, onItemClick: (Int) -> Unit) = SelectorAlert(this).apply {
fun Context.selectorAlert(title: String? = null, itemList: List<String>, onItemClick: (Int) -> Unit) = SelectorAlert(this).apply {
this.titleText = title
this.itemList = itemList
this.onItemClick = onItemClick
}

fun Context.DownloadAlert(title: String? = null, content: String? = null) = DownloadAlert(this).apply {
fun Context.downloadAlert(title: String? = null, content: String? = null) = DownloadAlert(this).apply {
this.titleText = title
this.contentText = content
}

fun Fragment.Alert(title: String, content: String, type: AlertType = AlertType.Normal, init: (StandardAlert.() -> Unit)? = null) = context.Alert(title, content, type, init)
fun Fragment.Alert(title: String, content: String, type: AlertType = AlertType.Normal, init: (StandardAlert.() -> Unit)? = null) = context?.alert(title, content, type, init)

fun Fragment.InputTextAlert(title: String? = null, hint: String, inputType: InputType = InputType.Text, init: (StandardAlert.() -> Unit)? = null) = context.InputTextAlert(title, hint, inputType, init)
fun Fragment.InputTextAlert(title: String? = null, hint: String, inputType: InputType = InputType.Text, init: (StandardAlert.() -> Unit)? = null) = context?.inputTextAlert(title, hint, inputType, init)

fun Fragment.SelectorAlert(title: String? = null, itemList: List<String>, onItemClick: (Int) -> Unit) = context.SelectorAlert(title, itemList, onItemClick)
fun Fragment.SelectorAlert(title: String? = null, itemList: List<String>, onItemClick: (Int) -> Unit) = context?.selectorAlert(title, itemList, onItemClick)

fun Fragment.DownloadAlert(title: String? = null, content: String? = null) = context.DownloadAlert(title, content)
fun Fragment.DownloadAlert(title: String? = null, content: String? = null) = context?.downloadAlert(title, content)

enum class AlertType() {
enum class AlertType {

Normal,
Warning,
Expand Down
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.
14 changes: 7 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 27
buildToolsVersion "27.0.2"
defaultConfig {
applicationId "com.kevicsalazar.sample.appkit_alerts"
applicationId "pe.startapps.sample.alerts"
minSdkVersion 14
targetSdkVersion 25
targetSdkVersion 27
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
Expand All @@ -25,7 +25,7 @@ android {
}

dependencies {
compile project(':appkit-alerts-kotlin')
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'org.jetbrains.kotlin:kotlin-stdlib:1.0.6'
compile project(':alerts')
compile 'com.android.support:appcompat-v7:27.0.2'
compile 'org.jetbrains.kotlin:kotlin-stdlib:1.2.20'
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kevicsalazar.sample.appkit_alerts">
package="pe.startapps.sample.alerts">

<application
android:allowBackup="true"
Expand Down
Loading

0 comments on commit 4f7c25b

Please sign in to comment.