-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #206 from alexandr7035/develop
Release v5.4 - Improve UI performance - Fix crash on contributions grid update - Fix UI bugs - Refactoring
- Loading branch information
Showing
39 changed files
with
757 additions
and
680 deletions.
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
2 changes: 1 addition & 1 deletion
2
...dr7035/gitstat/extensions/ApolloClient.kt → ...5/gitstat/core/extensions/ApolloClient.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
2 changes: 1 addition & 1 deletion
2
...xandr7035/gitstat/extensions/LineChart.kt → ...7035/gitstat/core/extensions/LineChart.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
15 changes: 15 additions & 0 deletions
15
app/src/main/java/by/alexandr7035/gitstat/core/extensions/LiveData.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,15 @@ | ||
package by.alexandr7035.gitstat.core.extensions | ||
|
||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.lifecycle.LiveData | ||
|
||
// Sometimes we may receive nulls in livedata observers | ||
// For example, when room cache tables are cleared before saving updated data | ||
// So we just skip null updates to avoid null checks | ||
// | ||
// See https://proandroiddev.com/nonnull-livedata-with-kotlin-extension-26963ffd0333 | ||
fun <T> LiveData<T>.observeNullSafe(owner: LifecycleOwner, observer: (t: T) -> Unit) { | ||
this.observe(owner, { | ||
it?.let(observer) | ||
}) | ||
} |
2 changes: 1 addition & 1 deletion
2
...y/alexandr7035/gitstat/extensions/Long.kt → ...xandr7035/gitstat/core/extensions/Long.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
2 changes: 1 addition & 1 deletion
2
...r7035/gitstat/extensions/NavController.kt → .../gitstat/core/extensions/NavController.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
3 changes: 1 addition & 2 deletions
3
...exandr7035/gitstat/extensions/PieChart.kt → ...r7035/gitstat/core/extensions/PieChart.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
2 changes: 1 addition & 1 deletion
2
...alexandr7035/gitstat/extensions/String.kt → ...ndr7035/gitstat/core/extensions/String.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
2 changes: 1 addition & 1 deletion
2
...alexandr7035/gitstat/extensions/Timber.kt → ...ndr7035/gitstat/core/extensions/Timber.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
2 changes: 1 addition & 1 deletion
2
.../alexandr7035/gitstat/extensions/YAxis.kt → ...andr7035/gitstat/core/extensions/YAxis.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
32 changes: 32 additions & 0 deletions
32
app/src/main/java/by/alexandr7035/gitstat/core/view/CollapsingTextView.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,32 @@ | ||
package by.alexandr7035.gitstat.core.view | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.View | ||
import androidx.appcompat.widget.AppCompatTextView | ||
|
||
class CollapsingTextView(context: Context, attrs: AttributeSet): AppCompatTextView(context, attrs), View.OnClickListener { | ||
private var predefinedMaxLines = 0 | ||
|
||
init { | ||
predefinedMaxLines = maxLines | ||
|
||
// If want to collapse on clicks directly on the view | ||
// Otherwise use toggle() method | ||
if (isClickable) { | ||
super.setOnClickListener(this) | ||
} | ||
} | ||
|
||
override fun onClick(p0: View?) { | ||
toggle() | ||
} | ||
|
||
fun toggle() { | ||
maxLines = if (maxLines == predefinedMaxLines) { | ||
Int.MAX_VALUE | ||
} else { | ||
predefinedMaxLines | ||
} | ||
} | ||
} |
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
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
47 changes: 47 additions & 0 deletions
47
app/src/main/java/by/alexandr7035/gitstat/data/helpers/YearlyMetricsHelper.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,47 @@ | ||
package by.alexandr7035.gitstat.data.helpers | ||
|
||
import by.alexandr7035.gitstat.core.KeyValueStorage | ||
import by.alexandr7035.gitstat.core.TimeHelper | ||
import by.alexandr7035.gitstat.data.local.model.ContributionsYearWithDays | ||
import by.alexandr7035.gitstat.data.local.model.ContributionsYearWithRates | ||
import javax.inject.Inject | ||
import kotlin.math.round | ||
|
||
interface YearlyMetricsHelper { | ||
// Contribution rate for certain year | ||
fun getAnnualContributionRate(yearData: ContributionsYearWithRates): Float | ||
|
||
// Value of total (not annual) contribution rate by the end of specified year | ||
fun getEndingTotalContributionRate(yearData: ContributionsYearWithDays): Float | ||
|
||
|
||
class Impl @Inject constructor(private val timeHelper: TimeHelper, private val keyValueStorage: KeyValueStorage): YearlyMetricsHelper { | ||
override fun getAnnualContributionRate(yearData: ContributionsYearWithRates): Float { | ||
return if (yearData.year.id == timeHelper.getCurrentYearForUnixDate(System.currentTimeMillis())) { | ||
val lastCacheSyncDate = keyValueStorage.getLastCacheSyncDate() | ||
yearData.contributionRates.findLast { it.date == timeHelper.getBeginningOfDayForUnixDate(lastCacheSyncDate) }?.rate ?: 0F | ||
} else { | ||
yearData.contributionRates[yearData.contributionRates.size - 1].rate | ||
} | ||
} | ||
|
||
override fun getEndingTotalContributionRate(yearData: ContributionsYearWithDays): Float { | ||
val contributionsCount = yearData.contributionDays.sumOf { it.count } | ||
|
||
return if (yearData.year.id == timeHelper.getCurrentYearForUnixDate(System.currentTimeMillis())) { | ||
// Get last contribution day | ||
val lastCacheSyncDate = keyValueStorage.getLastCacheSyncDate() | ||
val lastContributedDay = yearData.contributionDays.findLast { | ||
it.date == timeHelper.getBeginningOfDayForUnixDate(lastCacheSyncDate) | ||
} | ||
val lastContributedDayPosition = yearData.contributionDays.lastIndexOf(lastContributedDay) | ||
// Slice of days from the beginning of the year to last contribution date | ||
val contributionDays = yearData.contributionDays.slice(0..lastContributedDayPosition) | ||
|
||
round(contributionsCount.toFloat() / contributionDays.size.toFloat() * 100) / 100F | ||
} else { | ||
round(contributionsCount.toFloat() / yearData.contributionDays.size.toFloat() * 100) / 100F | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.