Skip to content

Commit

Permalink
- Update sample to use viewBinding.
Browse files Browse the repository at this point in the history
- Remove unused dependencies.
  • Loading branch information
bilgehankalkan committed Nov 2, 2022
1 parent e8b0a52 commit 1319f19
Show file tree
Hide file tree
Showing 15 changed files with 264 additions and 319 deletions.
4 changes: 1 addition & 3 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ object Dependencies {
const val constraintLayout = "androidx.constraintlayout:constraintlayout:2.0.4"
const val recyclerView = "androidx.recyclerview:recyclerview:1.2.0"
const val circleIndicator = "com.github.MertNYuksel:CircleIndicator:2a2e973374"
const val glide = "com.github.bumptech.glide:glide:4.11.0"
const val glideCompiler = "com.github.bumptech.glide:compiler:4.11.0"
const val glide = "com.github.bumptech.glide:glide:4.13.2"
const val lifecycleExtensions = "androidx.lifecycle:lifecycle-extensions:2.1.0"
const val lifecycleCompiler = "androidx.lifecycle:lifecycle-compiler:2.1.0"
}
2 changes: 0 additions & 2 deletions libraries/dialogs/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ plugins {
id(Plugins.androidLibrary)
id(Plugins.kotlinAndroid)
id(Plugins.kotlinParcelize)
id(Plugins.kotlinKapt)
id(Plugins.mavenPublish)
}

Expand Down Expand Up @@ -46,5 +45,4 @@ dependencies {
implementation(Dependencies.material)
implementation(Dependencies.constraintLayout)
implementation(Dependencies.lifecycleExtensions)
kapt(Dependencies.lifecycleCompiler)
}
3 changes: 0 additions & 3 deletions libraries/image-slider/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
id(Plugins.androidLibrary)
id(Plugins.kotlinAndroid)
id(Plugins.kotlinKapt)
id(Plugins.mavenPublish)
}

Expand Down Expand Up @@ -40,6 +39,4 @@ dependencies {
implementation(Dependencies.constraintLayout)
implementation(Dependencies.glide)
implementation(projects.libraries.touchDelegator)

kapt(Dependencies.glideCompiler)
}
2 changes: 0 additions & 2 deletions libraries/quantity-picker-view/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
id(Plugins.androidLibrary)
id(Plugins.kotlinAndroid)
id(Plugins.kotlinKapt)
id(Plugins.mavenPublish)
}

Expand Down Expand Up @@ -39,5 +38,4 @@ dependencies {
implementation(Dependencies.material)
implementation(Dependencies.constraintLayout)
implementation(Dependencies.lifecycleExtensions)
kapt(Dependencies.lifecycleCompiler)
}
2 changes: 0 additions & 2 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
id(Plugins.androidApplication)
id(Plugins.kotlinAndroid)
id(Plugins.kotlinKapt)
}

android {
Expand All @@ -27,7 +26,6 @@ android {
}
}

buildFeatures.dataBinding = true
buildFeatures.viewBinding = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,19 @@ package com.trendyol.uicomponents
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.os.Handler
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.trendyol.cardinputview.CardInformation
import com.trendyol.cardinputview.CardInputView
import com.trendyol.cardinputview.CardInputViewState
import com.trendyol.cardinputview.CreditCardType
import com.trendyol.uicomponents.databinding.ActivityCardInputBinding
import com.trendyol.uicomponents.dialogs.infoDialog
import com.trendyol.uicomponents.dialogs.selectionDialog
import java.util.Calendar

class CardInputViewActivity : AppCompatActivity() {

private val cardInputView by lazy { findViewById<CardInputView>(R.id.card_input_view) }
private val textCardNumber by lazy { findViewById<TextView>(R.id.text_card_number) }
private val textCvv by lazy { findViewById<TextView>(R.id.text_cvv) }
private val buttonValidate by lazy { findViewById<Button>(R.id.button_validate) }
private val buttonValidateAndGet by lazy { findViewById<Button>(R.id.button_validate_and_get) }
private val buttonReset by lazy { findViewById<Button>(R.id.button_reset) }
private val buttonClearErrors by lazy { findViewById<Button>(R.id.button_clear_errors) }

private lateinit var binding: ActivityCardInputBinding
private val months =
listOf("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12")
private val years by lazy {
Expand All @@ -36,25 +25,26 @@ class CardInputViewActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_card_input)
binding = ActivityCardInputBinding.inflate(layoutInflater)
setContentView(binding.root)

with(cardInputView) {
with(binding.cardInputView) {
setSupportedCardTypes(
CreditCardType.MASTER_CARD,
CreditCardType.VISA,
CreditCardType.AMERICAN_EXPRESS
)
onCardNumberChanged = { cardNumber ->
if (cardNumber.length <= 1) {
cardInputView.setCardTypeLogoDrawable(getCardTypeLogoUrl(cardNumber))
binding.cardInputView.setCardTypeLogoDrawable(getCardTypeLogoUrl(cardNumber))
}
if (cardNumber.length >= 6) {
cardInputView.setCardBankLogoDrawable(getCardTypeLogoUrl(cardNumber)) // dummy setting
binding.cardInputView.setCardBankLogoDrawable(getCardTypeLogoUrl(cardNumber)) // dummy setting
}
textCardNumber.text = cardNumber
binding.textCardNumber.text = cardNumber
}
onCvvChanged = { cvv ->
textCvv.text = cvv
binding.textCvv.text = cvv
}
onCvvInfoClicked = {
Toast.makeText(
Expand All @@ -65,18 +55,18 @@ class CardInputViewActivity : AppCompatActivity() {
}
onCardNumberComplete = { isValid ->
val color = if (isValid) Color.BLUE else Color.RED
textCardNumber.setTextColor(color)
binding.textCardNumber.setTextColor(color)
showMonthSelectionDialog()
}
onCvvComplete = { isValid ->
val color = if (isValid) Color.BLUE else Color.RED
textCvv.setTextColor(color)
if (isValid) buttonValidate.performClick()
binding.textCvv.setTextColor(color)
if (isValid) binding.buttonValidate.performClick()
}

cardNumberInputErrorListener = {
Handler().postDelayed({
cardInputView.clearErrors()
binding.cardInputView.postDelayed({
binding.cardInputView.clearErrors()
}, 5000)
}

Expand All @@ -86,13 +76,13 @@ class CardInputViewActivity : AppCompatActivity() {
focusToCardNumberField()
}

buttonValidate.setOnClickListener { cardInputView.validate() }
buttonValidateAndGet.setOnClickListener {
val result = cardInputView.validateAndGet()
binding.buttonValidate.setOnClickListener { binding.cardInputView.validate() }
binding.buttonValidateAndGet.setOnClickListener {
val result = binding.cardInputView.validateAndGet()
if (result != null) showCardInformationDialog(result)
}
buttonReset.setOnClickListener { cardInputView.reset() }
buttonClearErrors.setOnClickListener { cardInputView.clearErrors() }
binding.buttonReset.setOnClickListener { binding.cardInputView.reset() }
binding.buttonClearErrors.setOnClickListener { binding.cardInputView.clearErrors() }
}

private fun showCardInformationDialog(cardInformation: CardInformation) {
Expand All @@ -102,7 +92,7 @@ class CardInputViewActivity : AppCompatActivity() {
"Expiry: ${cardInformation.expiryMonth}/${cardInformation.expiryYear}\n\n" +
"Cvv: ${cardInformation.cvv}"
showCloseButton = true
closeButtonListener = { cardInputView.reset() }
closeButtonListener = { binding.cardInputView.reset() }
}.showDialog(supportFragmentManager)
}

Expand All @@ -112,7 +102,7 @@ class CardInputViewActivity : AppCompatActivity() {
items = months.map { false to it }
onItemSelectedListener = { dialog, position ->
dialog.dismiss()
cardInputView.setSelectedMonth(months[position])
binding.cardInputView.setSelectedMonth(months[position])
showYearSelectionDialog()
}
}.showDialog(supportFragmentManager)
Expand All @@ -124,8 +114,8 @@ class CardInputViewActivity : AppCompatActivity() {
items = years.map { false to it }
onItemSelectedListener = { dialog, position ->
dialog.dismiss()
cardInputView.setSelectedYear(years[position])
cardInputView.focusToCvvField()
binding.cardInputView.setSelectedYear(years[position])
binding.cardInputView.focusToCvvField()
}
}.showDialog(supportFragmentManager)
}
Expand Down
47 changes: 29 additions & 18 deletions sample/src/main/java/com/trendyol/uicomponents/DialogsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,38 @@ import android.os.Bundle
import android.text.SpannableString
import android.text.SpannableStringBuilder
import android.webkit.WebViewClient
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.text.bold
import androidx.core.text.color
import com.trendyol.uicomponents.dialogs.*
import com.trendyol.uicomponents.databinding.ActivityDialogsBinding
import com.trendyol.uicomponents.dialogs.DialogFragment
import com.trendyol.uicomponents.dialogs.ItemDivider
import com.trendyol.uicomponents.dialogs.TextPosition
import com.trendyol.uicomponents.dialogs.WebViewContent
import com.trendyol.uicomponents.dialogs.agreementDialog
import com.trendyol.uicomponents.dialogs.infoDialog
import com.trendyol.uicomponents.dialogs.infoListDialog
import com.trendyol.uicomponents.dialogs.selectionDialog

class DialogsActivity : AppCompatActivity() {

private val buttonInfoDialog by lazy { findViewById<Button>(R.id.button_info_dialog) }
private val buttonAgreementDialog by lazy { findViewById<Button>(R.id.button_agreement_dialog) }
private val buttonSelectionDialog by lazy { findViewById<Button>(R.id.button_selection_dialog) }
private val buttonSelectionWithSearchDialog by lazy { findViewById<Button>(R.id.button_selection_with_search_dialog) }
private val buttonInfoDialogWithWebView by lazy { findViewById<Button>(R.id.button_info_dialog_webview) }
private val buttonInfoListDialog by lazy { findViewById<Button>(R.id.button_info_list_dialog) }
private lateinit var binding: ActivityDialogsBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_dialogs)

buttonInfoDialog.setOnClickListener { showInfoDialog() }
buttonAgreementDialog.setOnClickListener { showAgreementDialog() }
buttonSelectionDialog.setOnClickListener { showSelectionDialog() }
buttonSelectionWithSearchDialog.setOnClickListener { showSelectionWithSearchDialog() }
buttonInfoDialogWithWebView.setOnClickListener { showInfoDialogWithWebView() }
buttonInfoListDialog.setOnClickListener { showInfoListDialog() }
binding = ActivityDialogsBinding.inflate(layoutInflater)
setContentView(binding.root)

with(binding) {
buttonInfoDialog.setOnClickListener { showInfoDialog() }
buttonAgreementDialog.setOnClickListener { showAgreementDialog() }
buttonSelectionDialog.setOnClickListener { showSelectionDialog() }
buttonSelectionWithSearchDialog.setOnClickListener { showSelectionWithSearchDialog() }
buttonInfoDialogWebview.setOnClickListener { showInfoDialogWithWebView() }
buttonInfoListDialog.setOnClickListener { showInfoListDialog() }
}
}

private val infoDialogClosed: (DialogFragment) -> Unit = { showToast("Info dialog closed.") }
Expand Down Expand Up @@ -143,8 +148,14 @@ class DialogsActivity : AppCompatActivity() {
closeButtonListener = infoDialogClosed
cornerRadius = 0F
infoListItems = getInfoListItems()
itemDividers = listOf(
ItemDivider.MarginDivider(56, listOf(ItemDivider.MarginDivider.MarginDirection.TOP, ItemDivider.MarginDivider.MarginDirection.BOTTOM)),
itemDividers = listOf(
ItemDivider.MarginDivider(
56,
listOf(
ItemDivider.MarginDivider.MarginDirection.TOP,
ItemDivider.MarginDivider.MarginDirection.BOTTOM
)
),
ItemDivider.DrawableDivider(
R.drawable.shape_info_list_dialog_divider
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.trendyol.uicomponents

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.trendyol.uicomponents.databinding.ActivityFitOptionMessageBinding

class FitOptionMessageViewActivity : AppCompatActivity() {
Expand All @@ -11,10 +10,8 @@ class FitOptionMessageViewActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(
this,
R.layout.activity_fit_option_message
)
binding = ActivityFitOptionMessageBinding.inflate(layoutInflater)
setContentView(binding.root)

// setting a custom animation
/*binding.fitOptionMessage.revealAnimationProvider = { imageView, textView ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.trendyol.uicomponents
import android.os.Bundle
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.trendyol.uicomponents.databinding.ActivityImageSliderBinding
import com.trendyol.uicomponents.imageslider.ImageSliderViewState

Expand All @@ -14,7 +13,8 @@ class ImageSliderActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_image_slider)
binding = ActivityImageSliderBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.imageSliderView.setActivityInstance(this)
binding.imageSliderView.setViewState(
ImageSliderViewState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@ package com.trendyol.uicomponents

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.trendyol.uicomponents.databinding.ActivityPhoneNumberBinding
import com.trendyol.uicomponents.phonenumber.PhoneNumberTextInputEditTextViewState

class PhoneNumberActivity : AppCompatActivity() {

private lateinit var binding: ActivityPhoneNumberBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
DataBindingUtil.setContentView<ActivityPhoneNumberBinding>(
this,
R.layout.activity_phone_number
).apply {
viewState = PhoneNumberTextInputEditTextViewState(maskable = true, maskCharacter = '*')
executePendingBindings()
editTextPhoneDot.setText("0555●●●●●55")
editTextPhoneStar.setText("0555*****55")
binding = ActivityPhoneNumberBinding.inflate(layoutInflater)
setContentView(binding.root)

with(binding.editTextPhoneDot) {
setMaskCharacter('')
setMaskable(true)
setText("0555●●●●●55")
}
with(binding.editTextPhoneStar) {
viewState = PhoneNumberTextInputEditTextViewState(maskable = true, maskCharacter = '*')
setText("0555*****55")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.trendyol.uicomponents

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.trendyol.suggestioninputview.Rule
import com.trendyol.suggestioninputview.SuggestionInputItem
import com.trendyol.suggestioninputview.SuggestionItemType
Expand All @@ -14,10 +13,8 @@ class SuggestionInputViewActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(
this,
R.layout.activity_suggestion_input
)
binding = ActivitySuggestionInputBinding.inflate(layoutInflater)
setContentView(binding.root)

val rule1 = Rule.Builder()
.smallerThan("50")
Expand All @@ -34,8 +31,7 @@ class SuggestionInputViewActivity : AppCompatActivity() {
}

private fun onLoadClicked() {
binding.shouldShowError = true
binding.executePendingBindings()
binding.suggestionInputView.shouldShowSelectableItemError(true)
}

private fun onSuggestionItemClicked(suggestionInputItem: SuggestionInputItem) {
Expand Down
Loading

0 comments on commit 1319f19

Please sign in to comment.