-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve OSS licenses screen #1018
base: main
Are you sure you want to change the base?
Improve OSS licenses screen #1018
Conversation
import kotlinx.collections.immutable.PersistentList | ||
import kotlinx.collections.immutable.persistentListOf | ||
|
||
data class License( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you put sources to appropriate modules?
I think
UI will be feature/about,
Repository's implementation and api will be core/data,
This(License) will be core/model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's make sense.
OssLicenseRepositoryImpl
is still in the app module since limitation of Google's license plugin.
Except that, placing to appropriate modules. 🙇
@AppAndroidOssLicenseConfig | ||
fun provideOssLicenseRepositoryProvider( | ||
@ApplicationContext context: Context, | ||
): OssLicenseRepository = OssLicenseRepositoryImpl(context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are using Default〜 prefix for the concrete class 🙏
import okio.source | ||
import javax.inject.Inject | ||
|
||
class OssLicenseRepositoryImpl @Inject constructor( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about moving the logic to DefaultOssLicenseDataSource to simplify the app's implementation? I think this is similar to an API, since both handle data parsing. Therefore, I suggest transferring the code to DefaultOssLicenseDataSource.
class DefaultOssLicenseDataSource @Inject constructor(
private val context: Context,
) : OssLicenseDataSource {
override suspend fun licenseFlow(): OssLicense {
return withContext(context = Dispatchers.IO) {
val details = readLicensesFile().toRowList()
val metadata = readLicensesMetaFile().toRowList().parseToLibraryItem(
details = details,
)
val groupList = metadata.distinctBy { it.name }.groupByCategory()
.map {
OssLicenseGroup(
title = it.key,
licenses = it.value,
)
}.toPersistentList()
OssLicense(groupList)
}
}
private fun List<License>.groupByCategory(): Map<String, List<License>> {
val categoryList = listOf(
"Android Support",
"Android Datastore",
"Android ",
"Compose UI",
"Compose Material3",
"Compose ",
"AndroidX lifecycle",
"AndroidX ",
"Kotlin",
"Dagger",
"Firebase",
"Ktorfit",
"okhttp",
"ktor",
)
return groupBy { license ->
categoryList.firstOrNull {
license.name.startsWith(
prefix = it,
ignoreCase = true,
)
} ?: "etc"
}
}
private fun readLicensesMetaFile(): BufferedSource {
return context.resources.openRawResource(raw.third_party_license_metadata)
.source()
.buffer()
}
private fun readLicensesFile(): BufferedSource {
return context.resources.openRawResource(raw.third_party_licenses)
.source()
.buffer()
}
private fun List<String>.parseToLibraryItem(details: List<String>): List<License> {
return mapIndexed { index, value ->
val (position, name) = value.split(' ', limit = 2)
val (offset, length) = position.split(':').map { it.toInt() }
val id = name.replace(' ', '-')
License(
name = name,
id = id,
offset = offset,
length = length,
detail = details[index],
)
}
}
private fun BufferedSource.toRowList(): List<String> {
val list: MutableList<String> = mutableListOf()
while (true) {
val line = readUtf8Line() ?: break
list.add(line)
}
return list
}
}
Hi @fumiya-kume! Codes seem to be unformatted. To resolve this issue, please run |
Could you add a screenshot test for this screen? This is because all other screens have one, and this PR causes our test coverage to shrink. 🙇 |
Snapshot diff report
|
@@ -33,7 +33,7 @@ jobs: | |||
workflow: UnitTest.yml | |||
branch: main | |||
|
|||
- run: ./gradlew compareRoborazziDebug compareRoborazziDevDebug --stacktrace -Pscreenshot | |||
- run: ./gradlew compareRoborazziDebug compareRoborazziDevRelease --stacktrace -Pscreenshot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What problem are you experiencing with compareRoborazziDevDebug? 👀
Issue
Overview (Required)
TODO
Links
Screenshot (Optional if screenshot test is present or unrelated to UI)
Movie (Optional)
licensescreen.mp4