Skip to content
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

#75 Add Support for API 21 #78

Merged
merged 1 commit into from
Oct 18, 2023
Merged
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
2 changes: 1 addition & 1 deletion library-noop/flaker-android-okhttp-noop/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
compileSdk = 33

defaultConfig {
minSdk = 24
minSdk = 21

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand Down
2 changes: 1 addition & 1 deletion library-noop/flaker-okhttp-core-noop/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
compileSdk = 33

defaultConfig {
minSdk = 24
minSdk = 21

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand Down
2 changes: 1 addition & 1 deletion library/flaker-android-ktor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
compileSdk = 33

defaultConfig {
minSdk = 24
minSdk = 21

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand Down
2 changes: 1 addition & 1 deletion library/flaker-android-monitor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ android {
}

defaultConfig {
minSdk = 24
minSdk = 21

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand Down
2 changes: 1 addition & 1 deletion library/flaker-android-okhttp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
compileSdk = 33

defaultConfig {
minSdk = 24
minSdk = 21

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.lifecycle.viewModelScope
import io.github.rotbolt.flakedomain.prefs.FlakerPrefs
import io.github.rotbolt.flakedomain.prefs.RetentionPolicy
import io.github.rotbolt.flakerandroidmonitor.FlakerMonitor
import io.github.rotbolt.flakerandroidui.components.lists.NetworkRequestInfo
import io.github.rotbolt.flakerandroidui.components.lists.NetworkRequestUi
import io.github.rotbolt.flakerandroidui.screens.prefs.FlakerPrefsUiDto
import io.github.rotbolt.flakerandroidui.screens.search.SearchUiDto
Expand Down Expand Up @@ -70,11 +71,22 @@ class FlakerViewModel(
networkRequestRepo.observeAll()
.collectLatest { list ->
val uiMapList = list
.map { NetworkRequestUi.NetworkRequestItem(it) }
.sortedByDescending { it.networkRequest.requestTime }
.map {
val sdf = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
val date = Date(it.requestTime)
val formattedTime: String = sdf.format(date)
val info = NetworkRequestInfo(
networkRequest = it,
formattedTime = formattedTime
)
NetworkRequestUi.NetworkRequestItem(info)
}
.sortedByDescending { it.networkRequestInfo.networkRequest.requestTime }
.groupBy {
val dateFormatter = SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH)
val formattedString = dateFormatter.format(Date(it.networkRequest.requestTime))
val formattedString = dateFormatter.format(
Date(it.networkRequestInfo.networkRequest.requestTime)
)
NetworkRequestUi.DateItem(formattedString)
}
_viewStateFlow.emit(_viewStateFlow.value.copy(networkRequests = uiMapList))
Expand Down Expand Up @@ -171,13 +183,13 @@ class FlakerViewModel(
.networkRequests
.flatMap { item -> item.value }
.filter { item ->
item.networkRequest.host.contains(term, ignoreCase = true) ||
item.networkRequest.path.contains(term, ignoreCase = true)
item.networkRequestInfo.networkRequest.host.contains(term, ignoreCase = true) ||
item.networkRequestInfo.networkRequest.path.contains(term, ignoreCase = true)
}
.sortedByDescending { it.networkRequest.requestTime }
.sortedByDescending { it.networkRequestInfo.networkRequest.requestTime }
.groupBy {
val dateFormatter = SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH)
val formattedString = dateFormatter.format(Date(it.networkRequest.requestTime))
val formattedString = dateFormatter.format(Date(it.networkRequestInfo.networkRequest.requestTime))
NetworkRequestUi.DateItem(formattedString)
}
val searchUiDto = _viewStateFlow.value.searchData.copy(filteredContent)
Expand Down
3 changes: 1 addition & 2 deletions library/flaker-android-ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
compileSdk = 33

defaultConfig {
minSdk = 24
minSdk = 21

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand Down Expand Up @@ -55,7 +55,6 @@ dependencies {
implementation(libs.ui.graphics)
implementation(libs.ui.tooling.preview)
implementation(libs.material3)
implementation(libs.kotlinx.datetime)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.espresso.core)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fun NetworkRequestList(modifier: Modifier = Modifier, contentProvider: () -> Net

items(networkRequestList) { item ->
NetworkRequestItem(
networkRequest = item.networkRequest,
networkRequestInfo = item.networkRequestInfo,
modifier = Modifier.padding(horizontal = 16.dp)
)
Spacer(modifier = Modifier.size(8.dp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@ import io.github.rotbolt.flakedomain.networkrequest.NetworkRequest

sealed class NetworkRequestUi {
data class DateItem(val formattedString: String) : NetworkRequestUi()
data class NetworkRequestItem(val networkRequest: NetworkRequest) : NetworkRequestUi()
data class NetworkRequestItem(val networkRequestInfo: NetworkRequestInfo) : NetworkRequestUi()
}

data class NetworkRequestInfo(
val networkRequest: NetworkRequest,
val formattedTime: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.github.rotbolt.flakedomain.networkrequest.NetworkRequest
import io.github.rotbolt.flakerandroidui.components.lists.NetworkRequestInfo
import io.github.rotbolt.flakerandroidui.theme.FlakerAndroidTheme
import io.github.rotbolt.flakerandroidui.theme.statusCodeError
import io.github.rotbolt.flakerandroidui.theme.statusCodeOther
import io.github.rotbolt.flakerandroidui.theme.statusCodeSuccess
import kotlinx.datetime.Instant
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime

@Composable
fun NetworkRequestItem(
modifier: Modifier = Modifier,
networkRequest: NetworkRequest
networkRequestInfo: NetworkRequestInfo
) {
Card(
modifier = modifier
.fillMaxWidth()
.wrapContentHeight(),
shape = RoundedCornerShape(8.dp),
) {
val (networkRequest, formattedTime) = networkRequestInfo

Row(modifier = Modifier.padding(8.dp)) {
Text(
text = networkRequest.responseCode.toString(),
Expand Down Expand Up @@ -87,11 +87,8 @@ fun NetworkRequestItem(
.padding(vertical = 8.dp)
.align(Alignment.Start)
) {
val localTime = Instant.fromEpochMilliseconds(networkRequest.requestTime)
.toLocalDateTime(TimeZone.currentSystemDefault())

Text(
text = localTime.time.toString().substringBefore("."),
text = formattedTime,
modifier = Modifier.align(Alignment.CenterVertically)
)

Expand Down Expand Up @@ -148,7 +145,11 @@ fun NetworkRequestItemPreview() {
isFailedByFlaker = it >= 2,
createdAt = 1692270425000
)
NetworkRequestItem(networkRequest = networkRequest, modifier = Modifier.padding(16.dp))
val networkRequestInfo = NetworkRequestInfo(
networkRequest = networkRequest,
formattedTime = "11:42:40"
)
NetworkRequestItem(networkRequestInfo = networkRequestInfo, modifier = Modifier.padding(16.dp))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/flaker-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
compileSdk = 33

defaultConfig {
minSdk = 24
minSdk = 21

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand Down
2 changes: 1 addition & 1 deletion library/flaker-data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ android {
namespace = "io.github.rotbolt.flakerdata"
compileSdk = 33
defaultConfig {
minSdk = 24
minSdk = 21
targetSdk = 33
consumerProguardFiles("consumer-rules.pro")
}
Expand Down
2 changes: 1 addition & 1 deletion library/flaker-domain/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ android {
namespace = "io.github.rotbolt.flakerdomain"
compileSdk = 33
defaultConfig {
minSdk = 24
minSdk = 21
targetSdk = 33
consumerProguardFiles("consumer-rules.pro")
}
Expand Down
2 changes: 1 addition & 1 deletion library/flaker-ktor-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ android {
namespace = "io.github.rotbolt.flakerktorcore"
compileSdk = 33
defaultConfig {
minSdk = 24
minSdk = 21
targetSdk = 33
consumerProguardFiles("consumer-rules.pro")
}
Expand Down
2 changes: 1 addition & 1 deletion library/flaker-okhttp-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
compileSdk = 33

defaultConfig {
minSdk = 24
minSdk = 21

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
Expand Down
2 changes: 1 addition & 1 deletion sampleapp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {

defaultConfig {
applicationId = "io.github.rotbolt.flakersampleapp"
minSdk = 24
minSdk = 21
targetSdk = 33
versionCode = 1
versionName = "1.0"
Expand Down