-
Notifications
You must be signed in to change notification settings - Fork 18
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 Trendyol/dialogs/base-dialog
Dialogs Implementation with Info and Agreement Types
- Loading branch information
Showing
34 changed files
with
720 additions
and
12 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
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,6 +1,6 @@ | ||
#Sat Nov 09 18:10:43 EET 2019 | ||
#Thu Nov 21 16:27:22 EET 2019 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
/build |
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,105 @@ | ||
|
||
<img src="https://raw.githubusercontent.com/Trendyol/android-ui-components/master/images/dialogs-1.png" width="240"/><img src="https://raw.githubusercontent.com/Trendyol/android-ui-components/master/images/dialogs-2.png" width="240"/> | ||
|
||
[![](https://jitpack.io/v/Trendyol/android-ui-components.svg)](https://jitpack.io/#Trendyol/android-ui-components) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) | ||
|
||
## Dialogs | ||
Dialogs is a bunch of BottomSheetDialogs to use in app to show user an information, agreement or list. | ||
|
||
# Installation | ||
- To implement **Dialogs** to your Android project via Gradle, you need to add JitPack repository to your root build.gradle. | ||
```gradle | ||
allprojects { | ||
repositories { ... maven { url 'https://jitpack.io' } }} | ||
``` | ||
- After adding JitPack repository, you can add **Dialogs** dependency to your app level build.gradle. | ||
```gradle | ||
dependencies { | ||
implementation "com.trendyol.ui-components:dialogs:$dialogsVersion"} | ||
``` | ||
:warning: To use **Dialogs**, you have to enable dataBinding from your main project, and implement material library into app level `build.gradle`. | ||
:warning: **Dialogs** can only usable via Kotlin. | ||
|
||
# Usage | ||
You can configure your dialog with given extensions with Kotlin DSL syntax. | ||
|
||
To show the dialog you just need to call `show(FragmentManager)` function. | ||
|
||
* Info Dialog: | ||
|
||
Simple dialog to show information, error or text. | ||
|
||
| Field | Type | Description | Default Value | | ||
| ------------- |-------------|-------------| ------------- | | ||
| `title` | String |Title of the dialog | "" | | ||
| `showCloseButton` | Boolean | Close button visibility | false | | ||
| `closeButtonListener` | (Dialog) -> Unit |Listener for close button. When clicked, dialog will dismiss and listener vill be invoked with dialog. | { } | | ||
| `content` | CharSequence | Content of a dialog | "" | | ||
| `showContentAsHtml` | Boolean | If you provided `content` as Html and set this flag as true, content will be parsed as HTML. | false | | ||
| `contentImage` | Int | Drawable resource id of an visual, will be shown on top of `content` | 0 | | ||
|
||
Sample usage: | ||
```kotlin | ||
infoDialog { | ||
title = "Info Title" | ||
showCloseButton = true | ||
closeButtonListener = { onInfoDialogClosed(it) } | ||
content = SpannableString.valueOf(getSpannableString()) | ||
contentImage = android.R.drawable.btn_plus | ||
}.show(supportFragmentManager) | ||
``` | ||
|
||
* Agreement Dialog: | ||
|
||
Dialog with buttons on bottom. You can show 2 buttons at the bottom or just one button. | ||
All arguments plus these arguments will be applicable to show agreement dialogs. | ||
|
||
| Field | Type | Description | Default Value | | ||
| ------------- |-------------|-------------| ------------- | | ||
| `rightButtonText` | String | Text of the right button. Will not be shown if given string is empty. | "" | | ||
| `leftButtonText` | String | Text of the left button. Will not be shown if given string is empty. | "" | | ||
| `rightButtonClickListener` | (Dialog) -> Unit | Listener for right button's click events. Will be invoked with dialog instance. | { } | | ||
| `leftButtonClickListener` | (Dialog) -> Unit | Listener for left button's click events. Will be invoked with dialog instance. | { } | | ||
|
||
Sample usage: | ||
```kotlin | ||
agreementDialog { | ||
title = "Agreement Dialog Title" | ||
leftButtonText = "Cancel" | ||
rightButtonText = "Agree" | ||
content = getHtmlString() | ||
showContentAsHtml = true | ||
rightButtonClickListener = { | ||
it.dismiss() | ||
onRightButtonClicked() | ||
} | ||
leftButtonClickListener = { | ||
it.dismiss() | ||
} | ||
}.showDialog(supportFragmentManager) | ||
``` | ||
# TODOs | ||
* Implement ListDialog. | ||
* Implement SelectionDialog | ||
* Implement search line. | ||
* Implement multiple selectable type. | ||
* Provide theme for more styling. | ||
* Update builder for Java. | ||
|
||
# Contributors | ||
This library is maintained mainly by Trendyol Android Team members but also other Android lovers contributes. | ||
|
||
# License | ||
Copyright 2019 Trendyol.com | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. |
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,43 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'kotlin-android-extensions' | ||
apply plugin: 'kotlin-kapt' | ||
apply plugin: 'com.github.dcendents.android-maven' | ||
|
||
group="com.trendyol.ui-components" | ||
version="1.0.0" | ||
|
||
android { | ||
compileSdkVersion 29 | ||
buildToolsVersion "29.0.2" | ||
|
||
defaultConfig { | ||
minSdkVersion 17 | ||
targetSdkVersion 29 | ||
versionCode 1 | ||
versionName "1.0" | ||
vectorDrawables.useSupportLibrary = true | ||
|
||
consumerProguardFiles 'consumer-rules.pro' | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
dataBinding { | ||
enabled true | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
implementation 'androidx.appcompat:appcompat:1.1.0' | ||
implementation 'androidx.core:core-ktx:1.1.0' | ||
implementation 'com.google.android.material:material:1.0.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' | ||
} |
Empty file.
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,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
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 @@ | ||
<manifest package="com.trendyol.dialog" /> |
42 changes: 42 additions & 0 deletions
42
libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/BaseBottomSheetDialog.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,42 @@ | ||
package com.trendyol.uicomponents.dialogs | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.annotation.LayoutRes | ||
import androidx.databinding.DataBindingUtil | ||
import androidx.databinding.ViewDataBinding | ||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment | ||
import com.trendyol.dialog.R | ||
|
||
abstract class BaseBottomSheetDialog<DB : ViewDataBinding> : BottomSheetDialogFragment() { | ||
|
||
protected lateinit var binding: DB | ||
|
||
@LayoutRes | ||
abstract fun getLayoutResId(): Int | ||
|
||
abstract fun setUpView() | ||
|
||
abstract fun setViewState() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setStyle(STYLE_NO_FRAME, R.style.BottomSheetDialogStyle) | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
binding = DataBindingUtil.inflate(inflater, getLayoutResId(), container, false) | ||
return binding.root | ||
} | ||
|
||
override fun onActivityCreated(savedInstanceState: Bundle?) { | ||
super.onActivityCreated(savedInstanceState) | ||
setUpView().also { setViewState() } | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/BindingAdapters.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,21 @@ | ||
package com.trendyol.uicomponents.dialogs | ||
|
||
import android.view.View | ||
import androidx.annotation.DrawableRes | ||
import androidx.appcompat.widget.AppCompatImageView | ||
import androidx.databinding.BindingAdapter | ||
|
||
@BindingAdapter("drawableResource") | ||
internal fun AppCompatImageView.setDrawableResource(@DrawableRes drawableResId: Int?) { | ||
if (drawableResId != null) { | ||
visibility = View.VISIBLE | ||
setImageResource(drawableResId) | ||
} else { | ||
visibility = View.GONE | ||
} | ||
} | ||
|
||
@BindingAdapter("isVisible") | ||
internal fun View.setVisibility(isVisible: Boolean) { | ||
visibility = if (isVisible) View.VISIBLE else View.GONE | ||
} |
56 changes: 56 additions & 0 deletions
56
libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/Builder.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,56 @@ | ||
package com.trendyol.uicomponents.dialogs | ||
|
||
import android.text.SpannableString | ||
import androidx.annotation.DrawableRes | ||
|
||
open class Builder internal constructor() { | ||
|
||
var title: String = "" | ||
var showCloseButton: Boolean = false | ||
var closeButtonListener: ((DialogFragment) -> Unit)? = null | ||
} | ||
|
||
open class InfoDialogBuilder internal constructor() : Builder() { | ||
|
||
var content: CharSequence = SpannableString("") | ||
@DrawableRes | ||
var contentImage: Int = 0 | ||
var showContentAsHtml: Boolean = false | ||
|
||
internal fun buildInfoDialog(block: InfoDialogBuilder.() -> Unit): DialogFragment { | ||
return InfoDialogBuilder().apply(block).let { | ||
DialogFragment( | ||
title = it.title, | ||
showCloseButton = it.showCloseButton, | ||
closeButtonListener = it.closeButtonListener ?: { }, | ||
content = SpannableString(it.content), | ||
contentImage = it.contentImage, | ||
showContentAsHtml = it.showContentAsHtml | ||
) | ||
} | ||
} | ||
} | ||
|
||
class AgreementDialogBuilder internal constructor() : InfoDialogBuilder() { | ||
|
||
var rightButtonText: String = "" | ||
var leftButtonText: String = "" | ||
var rightButtonClickListener: ((DialogFragment) -> Unit)? = null | ||
var leftButtonClickListener: ((DialogFragment) -> Unit)? = null | ||
|
||
internal fun buildAgreementDialog(block: AgreementDialogBuilder.() -> Unit): DialogFragment = | ||
AgreementDialogBuilder().apply(block).let { | ||
DialogFragment( | ||
title = it.title, | ||
showCloseButton = it.showCloseButton, | ||
closeButtonListener = it.closeButtonListener, | ||
content = SpannableString(it.content), | ||
showContentAsHtml = it.showContentAsHtml, | ||
contentImage = it.contentImage, | ||
rightButtonText = it.rightButtonText, | ||
leftButtonText = it.leftButtonText, | ||
rightButtonClickListener = it.rightButtonClickListener, | ||
leftButtonClickListener = it.leftButtonClickListener | ||
) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
libraries/dialogs/src/main/java/com/trendyol/uicomponents/dialogs/BuilderExtensions.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,7 @@ | ||
package com.trendyol.uicomponents.dialogs | ||
|
||
fun infoDialog(block: InfoDialogBuilder.() -> Unit): DialogFragment = | ||
InfoDialogBuilder().buildInfoDialog(block) | ||
|
||
fun agreementDialog(block: AgreementDialogBuilder.() -> Unit): DialogFragment = | ||
AgreementDialogBuilder().buildAgreementDialog(block) |
Oops, something went wrong.