Skip to content

Commit

Permalink
Merge pull request #221 from JohannesPtaszyk/release/2024.8.0
Browse files Browse the repository at this point in the history
Release/2024.8.0
  • Loading branch information
JohannesPtaszyk authored Aug 16, 2024
2 parents 71c8d2b + ac56e5e commit 0ad6c47
Show file tree
Hide file tree
Showing 25 changed files with 334 additions and 154 deletions.
33 changes: 33 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: JohannesPtaszyk

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: JohannesPtaszyk

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
2 changes: 1 addition & 1 deletion .github/workflows/debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
distribution: zulu

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
uses: gradle/actions/setup-gradle@v4

- name: Assemble Debug APK
run: ./gradlew assembleDebug
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: gradle/actions/wrapper-validation@v3
- uses: gradle/actions/wrapper-validation@v4
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
distribution: zulu

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
uses: gradle/actions/setup-gradle@v4

- name: Bundle Release AAB
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
distribution: zulu

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
uses: gradle/actions/setup-gradle@v4

- name: Bundle Release AAB
env:
Expand Down
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ dependencies {
implementation(libs.google.oss.licenses)
implementation(libs.hilt.android)
implementation(libs.kermit)
implementation(libs.kermit.crashlytics)
implementation(libs.androidx.dataStore)

testImplementation(projects.core.test)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package dev.pott.abonity.app

import android.app.Application
import co.touchlab.kermit.ExperimentalKermitApi
import co.touchlab.kermit.LogcatWriter
import co.touchlab.kermit.Logger
import co.touchlab.kermit.crashlytics.CrashlyticsLogWriter
import dagger.hilt.android.HiltAndroidApp
import javax.inject.Inject

Expand All @@ -12,8 +14,9 @@ class AbonityApplication : Application() {
@Inject
lateinit var trackingServiceManager: TrackingServiceManager

@OptIn(ExperimentalKermitApi::class)
override fun onCreate() {
Logger.setLogWriters(LogcatWriter())
Logger.setLogWriters(LogcatWriter(), CrashlyticsLogWriter())
super.onCreate()
trackingServiceManager.init()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ class PaymentInfoCalculator @Inject constructor(private val clock: Clock) {
val price = paymentInfo.price
return when (val paymentType = paymentInfo.type) {
PaymentType.OneTime -> {
if (isFirstPaymentInCurrentPeriod(
paymentInfo.firstPayment,
targetPeriod,
)
) {
if (isFirstPaymentInCurrentPeriod(paymentInfo.firstPayment, targetPeriod)) {
paymentInfo.price
} else {
Price.free(paymentInfo.price.currency)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,22 @@ class GetSubscriptionsWithFilterUseCase @Inject constructor(
@Dispatcher(DEFAULT) private val defaultDispatcher: CoroutineDispatcher,
) {

private val subscriptionsWithCurrencyFilterItemsFlow = getSubscription().map { subscriptions ->
private val paymentPeriodFlow = settingsRepository.getSettingsFlow().map { it.period }

private val subscriptionsWithCurrencyFilterItemsFlow = combine(
getSubscription(),
paymentPeriodFlow,
) { subscriptions, period ->
val totalPrices = calculator.getTotalPricesForPeriod(
subscriptions.map { it.subscription.paymentInfo },
PaymentPeriod.MONTHS,
period,
)
val currencyFilterItems = totalPrices
.map { SubscriptionFilterItem.Currency(it) }
.sortedByDescending { it.price.value }
subscriptions to currencyFilterItems
}

private val paymentPeriodFlow = settingsRepository.getSettingsFlow().map { it.period }

operator fun invoke(
selectedFilterItemsFlow: Flow<List<SubscriptionFilterItem>>,
): Flow<SubscriptionsWithFilter> =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package dev.pott.abonity.core.domain.subscription.usecase

import dev.pott.abonity.common.injection.Dispatcher
import dev.pott.abonity.common.injection.Dispatcher.Type.DEFAULT
import dev.pott.abonity.core.domain.settings.SettingsRepository
import dev.pott.abonity.core.domain.subscription.PaymentInfoCalculator
import dev.pott.abonity.core.domain.subscription.SubscriptionRepository
import dev.pott.abonity.core.domain.subscription.getLastDayOfCurrentPeriod
import dev.pott.abonity.core.entity.subscription.PaymentPeriod
import dev.pott.abonity.core.entity.subscription.PaymentType
import dev.pott.abonity.core.entity.subscription.Subscription
import dev.pott.abonity.core.entity.subscription.UpcomingPayment
import dev.pott.abonity.core.entity.subscription.UpcomingPayments
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.flowOn
import kotlinx.datetime.Clock
import kotlinx.datetime.TimeZone
import kotlinx.datetime.todayIn
import javax.inject.Inject

class GetUpcomingPaymentsUseCase @Inject constructor(
private val clock: Clock,
private val subscriptionRepository: SubscriptionRepository,
private val settingsRepository: SettingsRepository,
private val infoCalculator: PaymentInfoCalculator,
@Dispatcher(DEFAULT) private val defaultDispatcher: CoroutineDispatcher,
) {

operator fun invoke(): Flow<UpcomingPayments> =
combine(
subscriptionRepository.getSubscriptionsFlow(),
settingsRepository.getSettingsFlow(),
) { subscriptions, settings ->
val period = settings.period
val today = clock.todayIn(TimeZone.currentSystemDefault())
val lastDayOfCurrentPeriod = today.getLastDayOfCurrentPeriod(settings.period)
val payments = subscriptions
.map { subscription -> getUpcomingPayments(subscription, period) }
.flatten()
.filter { it.date in today..lastDayOfCurrentPeriod }
.groupBy { it.date }
.toSortedMap()
UpcomingPayments(payments, subscriptions.isNotEmpty(), settings.period)
}.flowOn(defaultDispatcher)

private fun getUpcomingPayments(
subscription: Subscription,
period: PaymentPeriod,
): List<UpcomingPayment> {
val payments = when (val type = subscription.paymentInfo.type) {
PaymentType.OneTime -> {
listOf(subscription.paymentInfo.firstPayment)
}

is PaymentType.Periodic -> {
infoCalculator.getPaymentDatesForCurrentPeriod(
subscription.paymentInfo.firstPayment,
period,
type,
).ifEmpty { listOf(infoCalculator.getNextDateByType(type)) }
}
}
return payments.map { UpcomingPayment(subscription, it) }
}
}

This file was deleted.

Loading

0 comments on commit 0ad6c47

Please sign in to comment.