Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
"java.configuration.updateBuildConfiguration": "interactive",
"java.compile.nullAnalysis.mode": "automatic"
}
8 changes: 4 additions & 4 deletions android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ allprojects {
dependencies {
// …
implementation 'com.contentful.java:java-sdk:10.5.18'
implementation 'com.github.contentful.rich-text-renderer-java:android:2.2.7'
implementation 'com.github.contentful.rich-text-renderer-java:core:2.2.7'
implementation 'com.github.contentful.rich-text-renderer-java:android:2.3.1'
implementation 'com.github.contentful.rich-text-renderer-java:core:2.3.1'
}
```

Expand All @@ -48,12 +48,12 @@ same can be achieved by adding Maven dependencies like so:
<dependency>
<groupId>com.github.contentful.rich-text-renderer-java</groupId>
<artifactId>core</artifactId>
<version>2.2.7</version>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.github.contentful.rich-text-renderer-java</groupId>
<artifactId>android</artifactId>
<version>2.2.7</version>
<version>2.3.1</version>
</dependency>
```

Expand Down
54 changes: 25 additions & 29 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ repositories {
}

android {
compileSdk 33
buildToolsVersion "30.0.3"
namespace "com.contentful.rich.android"
compileSdk 35
buildToolsVersion "35.0.0"

defaultConfig {
minSdkVersion 21
targetSdkVersion 33
targetSdkVersion 35
versionCode 1
versionName "1.0"
}
Expand All @@ -26,8 +27,8 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

testOptions {
Expand All @@ -41,44 +42,39 @@ android {
dependencies {
implementation project(path: ':core')

implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'androidx.appcompat:appcompat:1.7.0-alpha03'
implementation "com.contentful.java:java-sdk:${project.contentful_version}"
implementation 'com.google.code.findbugs:jsr305:3.0.2'
implementation 'androidx.cardview:cardview:1.0.0'

testImplementation 'org.robolectric:robolectric:4.9'
testImplementation 'com.google.truth:truth:0.42'
testImplementation 'org.robolectric:robolectric:4.14.1'
testImplementation 'com.google.truth:truth:1.1.5'
testImplementation 'junit:junit:4.13.2'
}

afterEvaluate {
publishing {
publications {
mavenJava(MavenPublication) {
from components.release
release(MavenPublication) {
groupId = project.group
artifactId = 'android'
version = project.version

artifact bundleReleaseAar

pom {
name = 'Rich Text Renderer Android'
description = 'Android library for rendering Contentful Rich Text'
url = 'https://github.com/contentful/rich-text-renderer-java'

licenses {
license {
name = 'MIT License'
url = 'https://opensource.org/licenses/MIT'
}
}
}
}
}
}
}

if (android.productFlavors.size() > 0) {
android.libraryVariants.all { variant ->
if (variant.name.toLowerCase().contains("debug")) {
return
}

def bundleTask = tasks["bundle${variant.name.capitalize()}"]

artifacts {
archives(bundleTask.archivePath) {
archiveClassifier = variant.flavorName
builtBy bundleTask
name = project.name
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,67 +50,56 @@ public HyperLinkRenderer(@Nonnull AndroidProcessor<View> processor) {
@Nullable
@Override
public View render(@Nonnull AndroidContext context, @Nonnull CDARichNode node) {
final CDARichHyperLink hyperlink = (CDARichHyperLink) node;
if(hyperlink.getContent().get(0) != null) {
final CDARichText richText = (CDARichText) hyperlink.getContent().get(0);
final View result = context.getInflater().inflate(R.layout.rich_text_layout, null);
final TextView content = result.findViewById(R.id.rich_content);
final SpannableStringBuilder textContent = new SpannableStringBuilder(richText.getText());
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View textView) {
HyperLinkRenderer.this.onClick(context, node);
}

@Override
public void updateDrawState(@NonNull TextPaint ds) {
ds.linkColor = Color.parseColor("#0645AD");
super.updateDrawState(ds);
}
};

content.setMovementMethod(LinkMovementMethod.getInstance());
textContent.setSpan(clickableSpan, 0, textContent.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
content.setText(textContent);
return result;
} else {
final CDARichBlock block = (CDARichBlock) node;
final View result = inflateRichLayout(context, node);
final ViewGroup content = result.findViewById(R.id.rich_content);
if (!(node instanceof CDARichHyperLink)) {
return null;
}

TextView lastTextView = null;
for (final CDARichNode childNode : block.getContent()) {
final View childView = processor.process(context, childNode);
final CDARichHyperLink hyperlink = (CDARichHyperLink) node;
final View result = context.getInflater().inflate(R.layout.rich_text_layout, null);
final TextView content = result.findViewById(R.id.rich_content);
final SpannableStringBuilder textContent = new SpannableStringBuilder();

if (childView != null) {
if (childView instanceof TextView) {
final TextView childTextView = (TextView) childView;
if (lastTextView != null) {
lastTextView.setText(
new SpannableStringBuilder(lastTextView.getText()).append(childTextView.getText())
);
if(childTextView.getMovementMethod() != null) {
lastTextView.setMovementMethod(childTextView.getMovementMethod());
}
} else {
lastTextView = childTextView;
content.addView(childView);
}
} else {
if (context.getPath() != null && context.getPath().size() > 1) {
final View indented = context.getInflater().inflate(R.layout.rich_indention_layout, null, false);
((ViewGroup) indented.findViewById(R.id.rich_content)).addView(childView);
content.addView(indented);
} else {
content.addView(childView);
if (hyperlink.getContent() != null && !hyperlink.getContent().isEmpty()) {
for (CDARichNode contentNode : hyperlink.getContent()) {
if (contentNode instanceof CDARichText) {
textContent.append(((CDARichText) contentNode).getText());
} else if (contentNode instanceof CDARichBlock) {
for (CDARichNode blockNode : ((CDARichBlock) contentNode).getContent()) {
if (blockNode instanceof CDARichText) {
textContent.append(((CDARichText) blockNode).getText());
}
}
}
}
}

return result;
if (textContent.length() == 0) {
Object data = hyperlink.getData();
if (data instanceof String) {
textContent.append((String) data);
} else if (data instanceof Map && ((Map<?, ?>) data).containsKey("uri")) {
textContent.append((String) ((Map<?, ?>) data).get("uri"));
}
}

// Create clickable span
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View textView) {
HyperLinkRenderer.this.onClick(context, node);
}

@Override
public void updateDrawState(@NonNull TextPaint ds) {
ds.linkColor = Color.parseColor("#0645AD");
super.updateDrawState(ds);
}
};

content.setMovementMethod(LinkMovementMethod.getInstance());
textContent.setSpan(clickableSpan, 0, textContent.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
content.setText(textContent);
return result;
}

public void onClick(AndroidContext context, CDARichNode node) {
Expand Down
2 changes: 1 addition & 1 deletion android/src/test/java/chars/HeadingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void firstHeadingParsesContentTest() {
final Object[] spans = spannable.getSpans(0, result.length(), Object.class);
assertThat(spans.length).isEqualTo(1);
assertThat(spans[0]).isInstanceOf(AbsoluteSizeSpan.class);
assertThat(((AbsoluteSizeSpan) spans[0]).getSize()).isEqualTo(60);
assertThat(((AbsoluteSizeSpan) spans[0]).getSize()).isEqualTo(72);
}

@Test
Expand Down
30 changes: 14 additions & 16 deletions android_sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
plugins {
id("com.android.application")
id "org.jetbrains.kotlin.android" version "1.8.0"
id "org.jetbrains.kotlin.android" version "1.9.22"
}

repositories {
maven { url 'https://jitpack.io' }
}

android {
compileSdk 33
buildToolsVersion "30.0.3"

namespace "com.contentful.rich.android.sample"
compileSdk 35
buildToolsVersion "35.0.0"

defaultConfig {
applicationId "com.contentful.rich.android.sample"
minSdkVersion 21
targetSdkVersion 33
targetSdkVersion 35
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}

buildFeatures {
viewBinding = true
buildConfig = true
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = "11"
jvmTarget = "17"
}

buildTypes {
Expand All @@ -48,22 +48,20 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

}

dependencies {
implementation project(path: ':android')
implementation project(path: ':core')

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.3"
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1" // Use the latest version available

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.22"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3"
implementation 'androidx.appcompat:appcompat:1.7.0-alpha03'
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.7.0"

implementation "com.contentful.java:java-sdk:${project.contentful_version}"
implementation 'com.google.code.findbugs:jsr305:3.0.2'

implementation 'com.google.android.material:material:1.8.0'
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
}
15 changes: 5 additions & 10 deletions android_sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:tools="http://schemas.android.com/tools"
package="com.contentful.rich.android.sample"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:enableOnBackInvokedCallback="true">

<uses-permission android:name="android.permission.INTERNET" />

Expand All @@ -12,17 +10,14 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning"
>
android:theme="@style/Theme.RichTextRendererSample">
<activity
android:name=".MainActivity"
android:theme="@style/AppTheme.NoActionBar"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Expand Down
Loading