-
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
Open
fumiya-kume
wants to merge
48
commits into
DroidKaigi:main
Choose a base branch
from
fumiya-kume:kuu/improve-oss-licenses-screen
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
47ec25d
Add feature/licenses module
fumiya-kume 830e3b0
Merge branch 'main' into kuu/improve-oss-licenses-screen
fumiya-kume aa0e419
Add empty oss license screen
fumiya-kume f537b83
Add empty oss license ViewModel
fumiya-kume fde39dc
Combine screen and ViewModel
fumiya-kume 15c6b3b
Setup basis of license screen
fumiya-kume 810acb4
Remove feature/lincenses
fumiya-kume 2a326c1
Remove feature/licenses relational file
fumiya-kume b717b7d
Move classes
fumiya-kume 6ddec12
Add logic to load the licenses data
fumiya-kume e4e55ff
Add Scaffold for OSS licenses screen
fumiya-kume 71db515
Add UI implementation
fumiya-kume d2794b9
Add license detail implementation
fumiya-kume 54e8302
Fix code format
fumiya-kume 8cea72a
Add OssLicense screen
fumiya-kume 0294a88
Add OssDetailLicense screen
fumiya-kume bde016a
Merge branch 'main' into kuu/improve-oss-licenses-screen
fumiya-kume dc641f3
Move License to core/model module
fumiya-kume c18fb1d
Oss screen move to feature / about
fumiya-kume 1ae5174
Fix code format
fumiya-kume 753f9a7
Update DI config with using the optional binding
fumiya-kume c605ed3
Delete unnecessary Dagger module
fumiya-kume 35316a8
Rename unintentional method name for the navigation
fumiya-kume c7a3413
Remove un-necessary method
fumiya-kume be4982d
Cleanup fake class
fumiya-kume a7c4a4c
Cleanup duplicate logic for id of license
fumiya-kume 6afe1e6
Using multi language support feature for the screen title
fumiya-kume 1d0da32
Update library grouping logic
fumiya-kume 6207404
Fix code format
fumiya-kume 3793f2e
Merge branch 'main' into kuu/improve-oss-licenses-screen
fumiya-kume 2c4d86f
Rename default implementation for Repository
fumiya-kume b172de9
Update DI config for OssLicenseDataSource
fumiya-kume 5e5c12e
Refactoring DataFlow
fumiya-kume 65ffeeb
Fix logic
fumiya-kume 6e246d2
Remove duplicated libraries
fumiya-kume 723baf9
Refactoring
fumiya-kume aaad120
Remove unnecessary code
fumiya-kume 0aae559
Merge branch 'main' into kuu/improve-oss-licenses-screen
fumiya-kume 4ba7ae4
Merge branch 'main' into kuu/improve-oss-licenses-screen
fumiya-kume c0c4f4d
Fix visibility
fumiya-kume 1819113
Fix visibility
fumiya-kume 2e08ce5
Merge branch 'main' into kuu/improve-oss-licenses-screen
fumiya-kume a2e5eb3
Merge branch 'main' into kuu/improve-oss-licenses-screen
fumiya-kume 4183d96
Add screenshot testing for oss license screen
fumiya-kume d94c87e
Add screenshot testing for oss license detail screen
fumiya-kume a26cc92
revert comment out
fumiya-kume 1255554
Try to update the build variant when CI
fumiya-kume ecd9b9f
Revert variant change
fumiya-kume File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...d/src/main/java/io/github/droidkaigi/confsched2023/license/DefaultOssLicenseDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package io.github.droidkaigi.confsched2023.license | ||
|
||
import android.content.Context | ||
import io.github.droidkaigi.confsched2023.R | ||
import io.github.droidkaigi.confsched2023.data.osslicense.OssLicenseDataSource | ||
import io.github.droidkaigi.confsched2023.model.License | ||
import io.github.droidkaigi.confsched2023.model.OssLicenseGroup | ||
import io.github.droidkaigi.confsched2023.ui.Inject | ||
import kotlinx.collections.immutable.toPersistentList | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import okio.BufferedSource | ||
import okio.buffer | ||
import okio.source | ||
|
||
public class DefaultOssLicenseDataSource @Inject constructor( | ||
private val context: Context, | ||
) : OssLicenseDataSource { | ||
|
||
override suspend fun license(): List<OssLicenseGroup> { | ||
return withContext(context = Dispatchers.IO) { | ||
readLicenses() | ||
.groupByCategory() | ||
.map { | ||
OssLicenseGroup( | ||
title = it.key, | ||
licenses = it.value, | ||
) | ||
} | ||
.toPersistentList() | ||
} | ||
} | ||
|
||
private fun readLicenses(): List<License> { | ||
val licenseData = readLicensesFile().toRowList() | ||
return readLicensesMetaFile().toRowList() | ||
.map { | ||
val (position, name) = it.split(' ', limit = 2) | ||
val (offset, length) = position.split(':').map { it.toInt() } | ||
|
||
val id = name.replace(' ', '-') | ||
val licensesText = kotlin.runCatching { | ||
licenseData.subList(offset, offset + length).joinToString() | ||
}.getOrNull() ?: "" | ||
|
||
License( | ||
id = id, | ||
name = name, | ||
licensesText = licensesText, | ||
) | ||
} | ||
.distinctBy { it.id } | ||
} | ||
|
||
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(R.raw.third_party_license_metadata) | ||
.source() | ||
.buffer() | ||
} | ||
|
||
private fun readLicensesFile(): BufferedSource { | ||
return context.resources.openRawResource(R.raw.third_party_licenses) | ||
.source() | ||
.buffer() | ||
} | ||
|
||
private fun BufferedSource.toRowList(): List<String> { | ||
val list: MutableList<String> = mutableListOf() | ||
while (true) { | ||
val line = readUtf8Line() ?: break | ||
list.add(line) | ||
} | ||
return list | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...n/kotlin/io/github/droidkaigi/confsched2023/data/osslicense/OssLicenseRepositoryModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.github.droidkaigi.confsched2023.data.osslicense | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import io.github.droidkaigi.confsched2023.model.OssLicenseRepository | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
public class OssLicenseRepositoryModule { | ||
@Provides | ||
@Singleton | ||
public fun provideOssLicenseRepository( | ||
ossLicenseDataSource: OssLicenseDataSource, | ||
): OssLicenseRepository { | ||
return DefaultOssLicenseRepository( | ||
ossLicenseDataSource, | ||
) | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
.../kotlin/io/github/droidkaigi/confsched2023/data/osslicense/DefaultOssLicenseRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.github.droidkaigi.confsched2023.data.osslicense | ||
|
||
import io.github.droidkaigi.confsched2023.model.OssLicenseGroup | ||
import io.github.droidkaigi.confsched2023.model.OssLicenseRepository | ||
import io.github.droidkaigi.confsched2023.ui.Inject | ||
import kotlinx.collections.immutable.PersistentList | ||
import kotlinx.collections.immutable.persistentListOf | ||
import kotlinx.collections.immutable.toPersistentList | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.onStart | ||
|
||
public class DefaultOssLicenseRepository @Inject constructor( | ||
private val ossLicenseDataSource: OssLicenseDataSource, | ||
) : OssLicenseRepository { | ||
|
||
private val ossLicenseStateFlow = | ||
MutableStateFlow<PersistentList<OssLicenseGroup>>(persistentListOf()) | ||
|
||
override fun licenseData(): Flow<PersistentList<OssLicenseGroup>> { | ||
return ossLicenseStateFlow.onStart { | ||
val ossLicenseData = ossLicenseDataSource.license().toPersistentList() | ||
ossLicenseStateFlow.emit(ossLicenseData) | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...monMain/kotlin/io/github/droidkaigi/confsched2023/data/osslicense/OssLicenseDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.github.droidkaigi.confsched2023.data.osslicense | ||
|
||
import io.github.droidkaigi.confsched2023.model.OssLicenseGroup | ||
|
||
public interface OssLicenseDataSource { | ||
public suspend fun license(): List<OssLicenseGroup> | ||
} |
12 changes: 12 additions & 0 deletions
12
core/model/src/commonMain/kotlin/io/github/droidkaigi/confsched2023/model/License.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.github.droidkaigi.confsched2023.model | ||
|
||
data class License( | ||
val id: String, | ||
val name: String, | ||
val licensesText: String, | ||
) | ||
|
||
data class OssLicenseGroup( | ||
val title: String, | ||
val licenses: List<License>, | ||
) |
8 changes: 8 additions & 0 deletions
8
...el/src/commonMain/kotlin/io/github/droidkaigi/confsched2023/model/OssLicenseRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.github.droidkaigi.confsched2023.model | ||
|
||
import kotlinx.collections.immutable.PersistentList | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
public interface OssLicenseRepository { | ||
public fun licenseData(): Flow<PersistentList<OssLicenseGroup>> | ||
} |
49 changes: 49 additions & 0 deletions
49
...main/java/io/github/droidkaigi/confsched2023/testing/robot/OssLicenseDetailScreenRobot.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.github.droidkaigi.confsched2023.testing.robot | ||
|
||
import androidx.compose.ui.test.isRoot | ||
import androidx.compose.ui.test.junit4.AndroidComposeTestRule | ||
import com.github.takahirom.roborazzi.captureRoboImage | ||
import io.github.droidkaigi.confsched2023.about.OssLicenseDetailScreen | ||
import io.github.droidkaigi.confsched2023.designsystem.theme.KaigiTheme | ||
import io.github.droidkaigi.confsched2023.testing.RobotTestRule | ||
import io.github.droidkaigi.confsched2023.testing.coroutines.runTestWithLogging | ||
import kotlinx.coroutines.test.TestDispatcher | ||
import javax.inject.Inject | ||
import kotlin.time.Duration.Companion.seconds | ||
|
||
class OssLicenseDetailScreenRobot @Inject constructor( | ||
private val testDispatcher: TestDispatcher, | ||
) { | ||
@Inject lateinit var robotTestRule: RobotTestRule | ||
private lateinit var composeTestRule: AndroidComposeTestRule<*, *> | ||
operator fun invoke( | ||
block: OssLicenseDetailScreenRobot.() -> Unit, | ||
) { | ||
runTestWithLogging(timeout = 30.seconds) { | ||
this@OssLicenseDetailScreenRobot.composeTestRule = robotTestRule.composeTestRule | ||
block() | ||
} | ||
} | ||
|
||
fun setupOssLicenseDetailScreenContent() { | ||
composeTestRule.setContent { | ||
KaigiTheme { | ||
OssLicenseDetailScreen( | ||
onUpClick = {}, | ||
) | ||
} | ||
} | ||
waitUntilIdle() | ||
} | ||
|
||
fun checkScreenCapture() { | ||
composeTestRule | ||
.onNode(isRoot()) | ||
.captureRoboImage() | ||
} | ||
|
||
fun waitUntilIdle() { | ||
composeTestRule.waitForIdle() | ||
testDispatcher.scheduler.advanceUntilIdle() | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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? 👀