Skip to content

Commit

Permalink
Merge pull request #4 from Trendyol/dialogs/base-dialog
Browse files Browse the repository at this point in the history
Dialogs Implementation with Info and Agreement Types
  • Loading branch information
bilgehankalkan authored Nov 24, 2019
2 parents 548f969 + 8d3e5b9 commit cbfcb0b
Show file tree
Hide file tree
Showing 34 changed files with 720 additions and 12 deletions.
8 changes: 8 additions & 0 deletions .idea/codeStyles/Project.xml

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

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ UI Components includes several custom views for Android platform to make develop
[Trendyol](https://play.google.com/store/apps/details?id=trendyol.com) Android application, we are using several custom view implementations that can be useful for other apps.

## Components ##
* [Rating Bar](https://github.com/Trendyol/android-ui-components/tree/master/libraries/rating-bar) RatingBarView, easy to use and customizable rating view.
* [Rating Bar](https://github.com/Trendyol/android-ui-components/tree/master/libraries/rating-bar): **RatingBarView**, easy to use and customizable rating view.
* [Dialogs](https://github.com/Trendyol/android-ui-components/tree/master/libraries/dialogs): **Dialogs** is collection of BottomSheetDialogs to present user an info, agreement or list.

License
--------
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.3.60'
repositories {
google()
jcenter()
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
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
Binary file modified images/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/dialogs-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/dialogs-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions libraries/dialogs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
105 changes: 105 additions & 0 deletions libraries/dialogs/README.md
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.
43 changes: 43 additions & 0 deletions libraries/dialogs/build.gradle
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.
21 changes: 21 additions & 0 deletions libraries/dialogs/proguard-rules.pro
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
1 change: 1 addition & 0 deletions libraries/dialogs/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest package="com.trendyol.dialog" />
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() }
}
}
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
}
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
)
}
}
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)
Loading

0 comments on commit cbfcb0b

Please sign in to comment.