Skip to content

Commit

Permalink
Task/support button in block (#4)
Browse files Browse the repository at this point in the history
* Add button child view

* Update gradle version
  • Loading branch information
nailshaykhraziev authored Sep 9, 2021
1 parent 8e35027 commit e83afad
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
3 changes: 1 addition & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
classpath 'com.android.tools.build:gradle:7.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${project.kotlin_version}"
}
}

apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'kotlin-android'

task sourcesJar(type: Jar) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.text.Spanned
import android.text.method.LinkMovementMethod
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import com.contentful.java.cda.rich.CDARichBlock
import com.contentful.java.cda.rich.CDARichHyperLink
Expand Down Expand Up @@ -34,20 +35,30 @@ open class BlockRenderer(
viewGroup: ViewGroup
) {
var lastTextView: TextView? = null
var lastButton: Button? = null
content.forEach { childNode ->
val childView = processor.process(context, childNode)
if (childView != null) {
when {
childView is Button -> {
lastButton = childView
viewGroup.addView(childView)
}
childView is TextView -> {
lastTextView?.let {
it.text = SpannableStringBuilder(it.text).append(childView.text)
} ?: run {
lastTextView = childView
if (lastButton != null) {
viewGroup.addView(childView)
lastButton = null
} else {
lastTextView?.let {
it.text = SpannableStringBuilder(it.text).append(childView.text)
} ?: run {
lastTextView = childView
viewGroup.addView(childView)
}
}
}
childNode is CDARichHyperLink -> {
getDataUrl(childNode.data)?.let { data->
getDataUrl(childNode.data)?.let { data ->
val childLayout = childView.findViewById<ViewGroup>(R.id.rich_content)
if (childLayout.childCount > 0) {
val childTextView = childLayout.getChildAt(0) as TextView
Expand Down
3 changes: 1 addition & 2 deletions android_sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
classpath 'com.android.tools.build:gradle:7.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${project.kotlin_version}"
}
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.github.dcendents.android-maven'

repositories {
maven { url 'https://jitpack.io' }
Expand Down
7 changes: 0 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
buildscript {
dependencies {
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}
}

plugins {
id("base")
}

apply plugin: "java"
apply plugin: "maven"

allprojects {
group = "com.github.contentful.rich"
Expand Down
1 change: 0 additions & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
id("java-library")
id("com.github.dcendents.android-maven")
}

repositories {
Expand Down
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Aug 28 10:20:17 CEST 2019
#Thu Sep 09 17:54:13 MSK 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
1 change: 0 additions & 1 deletion html/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
id("java-library")
id("com.github.dcendents.android-maven")
}

repositories {
Expand Down

0 comments on commit e83afad

Please sign in to comment.