Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrated the project to Kotlin #33

Open
wants to merge 5 commits into
base: dev/kotlin
Choose a base branch
from

Conversation

2307vivek
Copy link

Summary

Migrated the whole project to use Kotlin as the primary language. This results in reduction of the codebase size, along with improved code readability.

Resolves #32

Build Dialogs with Kotlin DSL

Building dialogs is easier than ever with kotlin dsl.

Animated Material Dialog

val animatedMaterialDialog = materialDialog(this) {
    title = "Delete"
    message = "Are you sure you want to delete this file?"
    isCancelable = false
    setPositiveButton("Delete", R.drawable.ic_delete) { dialog, which ->
        Toast.makeText(applicationContext, "Deleted!", Toast.LENGTH_SHORT).show()
        dialog.dismiss()
    }
    setNegativeButton("Cancel", R.drawable.ic_close) { dialog, which ->
        Toast.makeText(applicationContext, "Cancelled!", Toast.LENGTH_SHORT).show()
        dialog.dismiss()
    }
    setAnimation("delete_anim.json")
}

Animated BottomSheetMaterialDialog

val animatedBottomSheetDialog = bottomSheetMaterialDialog(this) {
    title = "Delete"
    message = "Are you sure you want to delete this file?"
    isCancelable = false
    setPositiveButton("Delete", R.drawable.ic_delete) { dialog, which ->
        Toast.makeText(applicationContext, "Deleted!", Toast.LENGTH_SHORT).show()
        dialog.dismiss()
    }
    setNegativeButton("Cancel", R.drawable.ic_close) { dialog, which ->
        Toast.makeText(applicationContext, "Cancelled!", Toast.LENGTH_SHORT).show()
        dialog.dismiss()
    }
    setAnimation("delete_anim.json")
}

@PatilShreyas
Copy link
Owner

Thanks, @2307vivek for this PR 😃

@2307vivek
Copy link
Author

2307vivek commented Oct 1, 2020

Thanks, @2307vivek for this PR

@PatilShreyas My pleasure. 😀

*/
fun materialDialog(
activity: Activity,
block: MaterialDialog.Builder.() -> Unit
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can call it builder instead of block.

*/
fun bottomSheetMaterialDialog(
activity: Activity,
block: BottomSheetMaterialDialog.Builder.() -> Unit
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Comment on lines +75 to +83
class Builder(private val activity: Activity) : DialogBuilder() {

/**
* Build the {@link BottomSheetMaterialDialog}.
*/
fun build(): BottomSheetMaterialDialog =
BottomSheetMaterialDialog(activity, title, message, isCancelable, mPositiveButton, mNegativeButton, animationResId, mAnimationFile)
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will hide builder pattern from Java. Right?

Comment on lines 18 to 37
// /**
// * @param title Sets the Title of Dialog.
// */
// fun setTitle(title: String) {
// mTitle = title
// }
//
// /**
// * @param message Sets the Message of Dialog.
// */
// fun setMessage(message: String) {
// mMessage = message
// }
//
// /**
// * @param isCancelable Sets cancelable property of Dialog.
// */
// fun isCancelable(isCancelable: Boolean) {
// cancelable = isCancelable
// }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's purpose of this?

Comment on lines +75 to +83
class Builder(private val activity: Activity) : DialogBuilder() {

/**
* Build the {@link BottomSheetMaterialDialog}.
*/
fun build(): BottomSheetMaterialDialog =
BottomSheetMaterialDialog(activity, title, message, isCancelable, mPositiveButton, mNegativeButton, animationResId, mAnimationFile)
}
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will hide builder pattern from Java. Right?

You cannot create a Dialog with builder pattern with my changes, but we need something to build the MaterialDialog class. The Builder class just collects data and builds the MaterialDialog class in the materialDialog() dsl function.

*/
fun materialDialog(
activity: Activity,
block: MaterialDialog.Builder.() -> Unit
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can call it builder instead of block.

Sure, calling it builder will make more sense.

Comment on lines 18 to 37
// /**
// * @param title Sets the Title of Dialog.
// */
// fun setTitle(title: String) {
// mTitle = title
// }
//
// /**
// * @param message Sets the Message of Dialog.
// */
// fun setMessage(message: String) {
// mMessage = message
// }
//
// /**
// * @param isCancelable Sets cancelable property of Dialog.
// */
// fun isCancelable(isCancelable: Boolean) {
// cancelable = isCancelable
// }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's purpose of this?

It can be safely deleted, I wrote that methods before the class was finalised.

Copy link
Owner

@PatilShreyas PatilShreyas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍🏻

@PatilShreyas PatilShreyas changed the base branch from master to dev/kotlin April 23, 2021 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrating project to the Kotlin
2 participants