Skip to content

Commit cab0d07

Browse files
authored
Merge pull request #222 from caarmen/introduce-compose
Introduce compose in the license screen.
2 parents 10debec + 982df6e commit cab0d07

File tree

11 files changed

+313
-126
lines changed

11 files changed

+313
-126
lines changed

app/build.gradle.kts

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016-2018 Carmen Alvarez
2+
* Copyright (c) 2016-present Carmen Alvarez
33
*
44
* This file is part of Poet Assistant.
55
*
@@ -21,8 +21,9 @@ import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
2121

2222
plugins {
2323
alias(libs.plugins.android.application)
24-
alias(libs.plugins.ksp)
2524
alias(libs.plugins.benmanes)
25+
alias(libs.plugins.kotlin.compose)
26+
alias(libs.plugins.ksp)
2627
id("jacoco")
2728
id("kotlin-kapt")
2829
id("kotlin-android")
@@ -39,6 +40,7 @@ android {
3940
}
4041

4142
buildFeatures {
43+
compose = true
4244
dataBinding = true
4345
buildConfig = true
4446
}
@@ -198,53 +200,62 @@ android.applicationVariants.configureEach {
198200
}
199201

200202
dependencies {
203+
implementation(libs.androidx.activity.compose)
201204
implementation(libs.androidx.appcompat)
202-
implementation(libs.google.material)
203-
implementation(libs.androidx.preference)
205+
implementation(platform(libs.androidx.compose.bom))
206+
implementation(libs.androidx.compose.material3)
207+
implementation(libs.androidx.compose.ui.tooling.preview)
204208
implementation(libs.androidx.constraintlayout)
205-
implementation(libs.rhymer)
206-
implementation(libs.porter.stemmer)
207-
implementation(libs.dagger)
209+
implementation(libs.androidx.preference)
208210
implementation(libs.androidx.room.runtime)
211+
implementation(libs.dagger)
212+
implementation(libs.google.material)
209213
implementation(libs.kotlin)
210-
implementation(libs.kotlinx.coroutines.core)
211214
implementation(libs.kotlinx.coroutines.android)
215+
implementation(libs.kotlinx.coroutines.core)
216+
implementation(libs.porter.stemmer)
217+
implementation(libs.rhymer)
218+
219+
debugImplementation(libs.androidx.compose.ui.tooling)
212220

213221
// We need to explicitly add a couple of api dependencies here, otherwise alpha versions
214222
// of these libs will be pulled in transitively (by a non-alpha databinding dependency...)
223+
api(libs.androidx.collection)
215224
api(libs.androidx.lifecycle.runtime)
216225
api(libs.androidx.lifecycle.viewmodel.ktx)
217-
api(libs.androidx.collection)
218226

219227
ksp(libs.androidx.room.compiler)
220228
ksp(libs.dagger.compiler)
221229

222-
androidTestImplementation(libs.androidx.room.testing)
223-
224-
testImplementation(libs.junit)
225-
testImplementation(libs.androidx.test.ext)
226-
testImplementation(libs.robolectric)
227-
testImplementation(libs.androidx.test.runner)
228-
testImplementation(libs.androidx.test.rules)
229-
testImplementation(libs.androidx.test.espresso.core)
230+
kspTest(libs.dagger.compiler)
231+
testImplementation(platform(libs.androidx.compose.bom))
232+
testImplementation(libs.androidx.arch.core.testing)
230233
testImplementation(libs.androidx.test.espresso.contrib)
234+
testImplementation(libs.androidx.test.espresso.core)
231235
testImplementation(libs.androidx.test.espresso.intents)
236+
testImplementation(libs.androidx.test.ext)
237+
testImplementation(libs.androidx.test.rules)
238+
testImplementation(libs.androidx.test.runner)
239+
testImplementation(libs.androidx.ui.test.junit4.android)
232240
testImplementation(libs.fest.reflect)
233-
testImplementation(libs.androidx.arch.core.testing)
241+
testImplementation(libs.junit)
234242
testImplementation(libs.kotlinx.coroutines.test)
235-
kspTest(libs.dagger.compiler)
243+
testImplementation(libs.robolectric)
236244

237-
androidTestImplementation(libs.fest.reflect)
238-
androidTestImplementation(libs.androidx.test.runner)
239-
androidTestImplementation(libs.androidx.test.rules)
240-
androidTestImplementation(libs.androidx.test.espresso.core)
245+
androidTestImplementation(platform(libs.androidx.compose.bom))
246+
androidTestImplementation(libs.androidx.room.testing)
247+
androidTestImplementation(libs.androidx.test.core)
241248
androidTestImplementation(libs.androidx.test.espresso.contrib)
249+
androidTestImplementation(libs.androidx.test.espresso.core)
242250
androidTestImplementation(libs.androidx.test.espresso.intents)
243-
androidTestImplementation(libs.androidx.test.core)
244251
androidTestImplementation(libs.androidx.test.ext)
252+
androidTestImplementation(libs.androidx.test.rules)
253+
androidTestImplementation(libs.androidx.test.runner)
245254
androidTestImplementation(libs.androidx.test.uiautomator)
246-
androidTestImplementation(libs.robolectric.annotations)
255+
androidTestImplementation(libs.androidx.ui.test.junit4.android)
256+
androidTestImplementation(libs.fest.reflect)
247257
androidTestImplementation(libs.google.test.parameter.injector)
258+
androidTestImplementation(libs.robolectric.annotations)
248259

249260
androidTestUtil(libs.androidx.test.orchesetrator)
250261
}

app/src/androidTest/java/ca/rmen/android/poetassistant/main/IntegrationTest.java

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017 Carmen Alvarez
2+
* Copyright (c) 2017 - present Carmen Alvarez
33
*
44
* This file is part of Poet Assistant.
55
*
@@ -20,30 +20,16 @@
2020
package ca.rmen.android.poetassistant.main;
2121

2222

23-
import android.content.Context;
24-
import androidx.annotation.IdRes;
25-
import androidx.annotation.StringRes;
26-
import androidx.test.filters.LargeTest;
27-
import androidx.test.ext.junit.runners.AndroidJUnit4;
28-
29-
import org.junit.Rule;
30-
import org.junit.Test;
31-
import org.junit.runner.RunWith;
32-
33-
import ca.rmen.android.poetassistant.R;
34-
import ca.rmen.android.poetassistant.main.rules.PoetAssistantActivityTestRule;
35-
36-
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
3723
import static androidx.test.espresso.Espresso.onView;
3824
import static androidx.test.espresso.Espresso.pressBack;
3925
import static androidx.test.espresso.action.ViewActions.click;
40-
import static androidx.test.espresso.action.ViewActions.scrollTo;
4126
import static androidx.test.espresso.assertion.ViewAssertions.matches;
4227
import static androidx.test.espresso.matcher.ViewMatchers.isChecked;
43-
import static androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed;
4428
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
45-
import static androidx.test.espresso.matcher.ViewMatchers.withId;
4629
import static androidx.test.espresso.matcher.ViewMatchers.withText;
30+
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
31+
import static org.hamcrest.Matchers.allOf;
32+
import static org.hamcrest.Matchers.endsWith;
4733
import static ca.rmen.android.poetassistant.main.CustomChecks.checkAllStarredWords;
4834
import static ca.rmen.android.poetassistant.main.CustomChecks.checkClipboard;
4935
import static ca.rmen.android.poetassistant.main.CustomChecks.checkRhymes;
@@ -64,9 +50,18 @@
6450
import static ca.rmen.android.poetassistant.main.TestUiUtils.openMenuItem;
6551
import static ca.rmen.android.poetassistant.main.TestUiUtils.swipeViewPagerLeft;
6652
import static ca.rmen.android.poetassistant.main.TestUiUtils.swipeViewPagerRight;
67-
import static org.hamcrest.Matchers.allOf;
68-
import static org.hamcrest.Matchers.containsString;
69-
import static org.hamcrest.Matchers.endsWith;
53+
54+
import android.content.Context;
55+
56+
import androidx.test.ext.junit.runners.AndroidJUnit4;
57+
import androidx.test.filters.LargeTest;
58+
59+
import org.junit.Rule;
60+
import org.junit.Test;
61+
import org.junit.runner.RunWith;
62+
63+
import ca.rmen.android.poetassistant.R;
64+
import ca.rmen.android.poetassistant.main.rules.PoetAssistantActivityTestRule;
7065

7166
@LargeTest
7267
@RunWith(AndroidJUnit4.class)
@@ -233,33 +228,6 @@ public void themeTest() {
233228
clickPreference(R.string.pref_theme_title);
234229
}
235230

236-
@Test
237-
public void openAboutScreenTest() {
238-
openMenuItem(R.string.action_about);
239-
checkLicense(R.id.tv_poet_assistant_license, R.string.about_license_app, "GNU GENERAL");
240-
checkLicense(R.id.tv_rhymer_license, R.string.about_license_rhyming_dictionary, "Carnegie Mellon University");
241-
checkLicense(R.id.tv_thesaurus_license, R.string.about_license_thesaurus, "WordNet Release 2.1");
242-
checkLicense(R.id.tv_dictionary_license, R.string.about_license_dictionary, "WordNet 3.0");
243-
checkLicense(R.id.tv_google_ngram_dataset_license, R.string.about_license_google_ngram_dataset, "Google Ngram Viewer");
244-
onView(withId(R.id.tv_source_code))
245-
.check(matches(isCompletelyDisplayed()))
246-
.check(matches(withText(R.string.about_projectUrl)));
247-
}
248-
249-
private void checkLicense(@IdRes int linkResId, @StringRes int linkTitle, String licenseContent) {
250-
onView(withId(linkResId))
251-
.check(matches(withText(linkTitle)))
252-
.perform(scrollTo())
253-
.check(matches(isCompletelyDisplayed()))
254-
.perform(click());
255-
256-
onView(withId(R.id.tv_license_text))
257-
.check(matches(isDisplayed()))
258-
.check(matches(withText(containsString(licenseContent))));
259-
pressBack();
260-
261-
}
262-
263231
private void useCleanLayout() {
264232
openMenuItem(R.string.action_settings);
265233
clickPreference(R.string.pref_layout_title);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package ca.rmen.android.poetassistant
2+
3+
4+
@Retention(AnnotationRetention.RUNTIME)
5+
@Target(AnnotationTarget.FUNCTION)
6+
/**
7+
* Add this annotation to functions to exclude from jacoco coverage metrics.
8+
*
9+
* https://github.com/jacoco/jacoco/wiki/FilteringOptions#annotation-based-filtering
10+
*/
11+
annotation class ExcludeFromJacocoGeneratedReport

app/src/main/kotlin/ca/rmen/android/poetassistant/about/LicenseActivity.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016 - 2017 Carmen Alvarez
2+
* Copyright (c) 2016 - present Carmen Alvarez
33
*
44
* This file is part of Poet Assistant.
55
*
@@ -60,9 +60,8 @@ class LicenseActivity : AppCompatActivity() {
6060
it.setTitle(R.string.license_title)
6161
}
6262

63-
val title = intent.getStringExtra(EXTRA_TITLE)
63+
val title = intent.getStringExtra(EXTRA_TITLE)!!
6464
val licenseFile = intent.getStringExtra(EXTRA_LICENSE_TEXT_ASSET_FILE)!!
65-
mBinding.tvTitle.text = title
6665
getInsets(mBinding.licenseContent) { view, insets ->
6766
view.updatePadding(
6867
left = insets.left,
@@ -73,7 +72,14 @@ class LicenseActivity : AppCompatActivity() {
7372
}
7473
val threading = DaggerHelper.getMainScreenComponent(this).getThreading()
7574
threading.execute({ readFile(licenseFile) },
76-
{ mBinding.tvLicenseText.text = it })
75+
{
76+
mBinding.licenseContent.setContent {
77+
LicenseScreen(
78+
title = title,
79+
licenseText = it,
80+
)
81+
}
82+
})
7783
}
7884

7985
@WorkerThread
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright (c) 2025 - present Carmen Alvarez
3+
*
4+
* This file is part of Poet Assistant.
5+
*
6+
* Poet Assistant is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* Poet Assistant is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with Poet Assistant. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
package ca.rmen.android.poetassistant.about
20+
21+
import androidx.compose.foundation.horizontalScroll
22+
import androidx.compose.foundation.layout.Column
23+
import androidx.compose.foundation.layout.padding
24+
import androidx.compose.foundation.rememberScrollState
25+
import androidx.compose.foundation.verticalScroll
26+
import androidx.compose.material3.MaterialTheme
27+
import androidx.compose.material3.Text
28+
import androidx.compose.runtime.Composable
29+
import androidx.compose.ui.Modifier
30+
import androidx.compose.ui.res.stringResource
31+
import androidx.compose.ui.tooling.preview.Preview
32+
import androidx.compose.ui.unit.dp
33+
import ca.rmen.android.poetassistant.ExcludeFromJacocoGeneratedReport
34+
import ca.rmen.android.poetassistant.R
35+
36+
@Composable
37+
fun LicenseScreen(
38+
title: String,
39+
licenseText: String,
40+
modifier: Modifier = Modifier,
41+
) {
42+
val horizontalScrollState = rememberScrollState()
43+
val verticalScrollState = rememberScrollState()
44+
Column(
45+
modifier = modifier
46+
.padding(16.dp)
47+
.horizontalScroll(enabled = true, state = horizontalScrollState)
48+
.verticalScroll(enabled = true, state = verticalScrollState)
49+
) {
50+
Text(
51+
text = title,
52+
style = MaterialTheme.typography.headlineSmall,
53+
modifier = Modifier.padding(bottom = 16.dp),
54+
)
55+
Text(
56+
text = licenseText,
57+
style = MaterialTheme.typography.bodySmall,
58+
)
59+
}
60+
}
61+
62+
@Composable
63+
@ExcludeFromJacocoGeneratedReport
64+
@Preview(showBackground = true, heightDp = 300)
65+
fun LicenseScreenPreview() {
66+
LicenseScreen(
67+
title = stringResource(R.string.about_license_thesaurus), licenseText = """
68+
The app uses the WordNet thesaurus.
69+
70+
The WordNet thesaurus is used in LibreOffice and OpenOffice,
71+
in conjunction with other English-language dictionaries and thesauruses.
72+
73+
The version of the WordNet thesaurus used in this thesaurus library is
74+
found in the LibreOffice repository: https://github.com/LibreOffice/dictionaries/tree/master/en
75+
The thesaurus file is th_en_US_v2.dat.
76+
77+
Multiple license files exist in this folder of the LibreOffice repository:
78+
* README.txt contains a BSD license for the Hunspell en_US dictionary
79+
* license.txt contains a GPL v2 license
80+
* WordNet_license.txt contains a specific license from Princeton University.
81+
82+
To the best of my knowledge, the WordNet_license.txt file is the relevant license
83+
for the thesaurus data used in the thesaurus library. The contents of that license are:
84+
85+
======================================================================
86+
WordNet Release 2.1
87+
88+
This software and database is being provided to you, the LICENSEE, by
89+
Princeton University under the following license. By obtaining, using
90+
and/or copying this software and database, you agree that you have
91+
read, understood, and will comply with these terms and conditions.:
92+
93+
""".trimIndent()
94+
)
95+
96+
}

0 commit comments

Comments
 (0)