From d65f982dfa2845875f25d208063d622bac3e9837 Mon Sep 17 00:00:00 2001 From: Alexandr Alexeenko Date: Sun, 12 Dec 2021 13:27:25 +0300 Subject: [PATCH 01/13] Move extensions to core package --- .../main/java/by/alexandr7035/gitstat/core/TimeHelper.kt | 4 ++-- .../gitstat/{ => core}/extensions/ApolloClient.kt | 2 +- .../gitstat/{ => core}/extensions/LineChart.kt | 2 +- .../by/alexandr7035/gitstat/{ => core}/extensions/Long.kt | 2 +- .../gitstat/{ => core}/extensions/NavController.kt | 2 +- .../gitstat/{ => core}/extensions/PieChart.kt | 3 +-- .../alexandr7035/gitstat/{ => core}/extensions/String.kt | 2 +- .../alexandr7035/gitstat/{ => core}/extensions/Timber.kt | 2 +- .../alexandr7035/gitstat/{ => core}/extensions/YAxis.kt | 2 +- .../gitstat/core/view/HorizontalRatioBarView.kt | 2 +- .../by/alexandr7035/gitstat/data/DataSyncRepository.kt | 2 +- .../by/alexandr7035/gitstat/data/SyncForegroundService.kt | 2 +- .../remote/mappers/RepositoriesRemoteToCacheMapper.kt | 2 +- .../java/by/alexandr7035/gitstat/view/MainActivity.kt | 2 +- .../gitstat/view/contributions/ContributionsFragment.kt | 2 +- .../contributions_per_year/YearContributionsFragment.kt | 8 ++++---- .../contributions_rate/YearContributionRatesFragment.kt | 6 +++--- .../view/contributions_grid/ContributionsGridFragment.kt | 4 ++-- .../gitstat/view/contributions_grid/DaysAdapter.kt | 2 +- .../gitstat/view/contributions_grid/MonthsAdapter.kt | 2 +- .../by/alexandr7035/gitstat/view/login/LoginFragment.kt | 4 ++-- .../alexandr7035/gitstat/view/profile/ProfileFragment.kt | 2 +- .../view/repositories/ActiveRepositoriesFragment.kt | 2 +- .../view/repositories/ArchivedRepositoriesFragment.kt | 2 +- .../gitstat/view/repositories/ReposOverviewFragment.kt | 2 +- .../view/repositories/RepositoriesListHostFragment.kt | 2 +- .../gitstat/view/repositories/RepositoryPageFragment.kt | 6 +++--- 27 files changed, 37 insertions(+), 38 deletions(-) rename app/src/main/java/by/alexandr7035/gitstat/{ => core}/extensions/ApolloClient.kt (92%) rename app/src/main/java/by/alexandr7035/gitstat/{ => core}/extensions/LineChart.kt (97%) rename app/src/main/java/by/alexandr7035/gitstat/{ => core}/extensions/Long.kt (88%) rename app/src/main/java/by/alexandr7035/gitstat/{ => core}/extensions/NavController.kt (89%) rename app/src/main/java/by/alexandr7035/gitstat/{ => core}/extensions/PieChart.kt (90%) rename app/src/main/java/by/alexandr7035/gitstat/{ => core}/extensions/String.kt (97%) rename app/src/main/java/by/alexandr7035/gitstat/{ => core}/extensions/Timber.kt (68%) rename app/src/main/java/by/alexandr7035/gitstat/{ => core}/extensions/YAxis.kt (93%) diff --git a/app/src/main/java/by/alexandr7035/gitstat/core/TimeHelper.kt b/app/src/main/java/by/alexandr7035/gitstat/core/TimeHelper.kt index 022a869a..14e17185 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/core/TimeHelper.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/core/TimeHelper.kt @@ -1,7 +1,7 @@ package by.alexandr7035.gitstat.core -import by.alexandr7035.gitstat.extensions.getStringDateFromLong -import by.alexandr7035.gitstat.extensions.getUnixDateFromStringFormat +import by.alexandr7035.gitstat.core.extensions.getStringDateFromLong +import by.alexandr7035.gitstat.core.extensions.getUnixDateFromStringFormat import java.text.SimpleDateFormat import java.util.* diff --git a/app/src/main/java/by/alexandr7035/gitstat/extensions/ApolloClient.kt b/app/src/main/java/by/alexandr7035/gitstat/core/extensions/ApolloClient.kt similarity index 92% rename from app/src/main/java/by/alexandr7035/gitstat/extensions/ApolloClient.kt rename to app/src/main/java/by/alexandr7035/gitstat/core/extensions/ApolloClient.kt index 589c0f35..8b4ecdf3 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/extensions/ApolloClient.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/core/extensions/ApolloClient.kt @@ -1,4 +1,4 @@ -package by.alexandr7035.gitstat.extensions +package by.alexandr7035.gitstat.core.extensions import by.alexandr7035.gitstat.core.AppError import by.alexandr7035.gitstat.core.ErrorType diff --git a/app/src/main/java/by/alexandr7035/gitstat/extensions/LineChart.kt b/app/src/main/java/by/alexandr7035/gitstat/core/extensions/LineChart.kt similarity index 97% rename from app/src/main/java/by/alexandr7035/gitstat/extensions/LineChart.kt rename to app/src/main/java/by/alexandr7035/gitstat/core/extensions/LineChart.kt index 3b83bf8c..e2b42ee8 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/extensions/LineChart.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/core/extensions/LineChart.kt @@ -1,4 +1,4 @@ -package by.alexandr7035.gitstat.extensions +package by.alexandr7035.gitstat.core.extensions import by.alexandr7035.gitstat.view.contributions.plots.LinePlotFill import com.github.mikephil.charting.charts.LineChart diff --git a/app/src/main/java/by/alexandr7035/gitstat/extensions/Long.kt b/app/src/main/java/by/alexandr7035/gitstat/core/extensions/Long.kt similarity index 88% rename from app/src/main/java/by/alexandr7035/gitstat/extensions/Long.kt rename to app/src/main/java/by/alexandr7035/gitstat/core/extensions/Long.kt index bb497f13..ba86a5e3 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/extensions/Long.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/core/extensions/Long.kt @@ -1,4 +1,4 @@ -package by.alexandr7035.gitstat.extensions +package by.alexandr7035.gitstat.core.extensions import java.text.SimpleDateFormat import java.util.* diff --git a/app/src/main/java/by/alexandr7035/gitstat/extensions/NavController.kt b/app/src/main/java/by/alexandr7035/gitstat/core/extensions/NavController.kt similarity index 89% rename from app/src/main/java/by/alexandr7035/gitstat/extensions/NavController.kt rename to app/src/main/java/by/alexandr7035/gitstat/core/extensions/NavController.kt index 76e936fb..03f494a7 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/extensions/NavController.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/core/extensions/NavController.kt @@ -1,4 +1,4 @@ -package by.alexandr7035.gitstat.extensions +package by.alexandr7035.gitstat.core.extensions import androidx.navigation.NavController import androidx.navigation.NavDirections diff --git a/app/src/main/java/by/alexandr7035/gitstat/extensions/PieChart.kt b/app/src/main/java/by/alexandr7035/gitstat/core/extensions/PieChart.kt similarity index 90% rename from app/src/main/java/by/alexandr7035/gitstat/extensions/PieChart.kt rename to app/src/main/java/by/alexandr7035/gitstat/core/extensions/PieChart.kt index 17706ce7..40c47a19 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/extensions/PieChart.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/core/extensions/PieChart.kt @@ -1,8 +1,7 @@ -package by.alexandr7035.gitstat.extensions +package by.alexandr7035.gitstat.core.extensions import android.graphics.Color import android.graphics.Typeface -import by.alexandr7035.gitstat.view.repositories.plots.languages_plot.PieDataValueFormatter import com.github.mikephil.charting.charts.PieChart import com.github.mikephil.charting.components.Legend import com.github.mikephil.charting.data.PieData diff --git a/app/src/main/java/by/alexandr7035/gitstat/extensions/String.kt b/app/src/main/java/by/alexandr7035/gitstat/core/extensions/String.kt similarity index 97% rename from app/src/main/java/by/alexandr7035/gitstat/extensions/String.kt rename to app/src/main/java/by/alexandr7035/gitstat/core/extensions/String.kt index 583f41d6..8cb714dc 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/extensions/String.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/core/extensions/String.kt @@ -1,4 +1,4 @@ -package by.alexandr7035.gitstat.extensions +package by.alexandr7035.gitstat.core.extensions import android.graphics.Typeface import android.text.SpannableString diff --git a/app/src/main/java/by/alexandr7035/gitstat/extensions/Timber.kt b/app/src/main/java/by/alexandr7035/gitstat/core/extensions/Timber.kt similarity index 68% rename from app/src/main/java/by/alexandr7035/gitstat/extensions/Timber.kt rename to app/src/main/java/by/alexandr7035/gitstat/core/extensions/Timber.kt index 0f438bbb..f51e2e39 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/extensions/Timber.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/core/extensions/Timber.kt @@ -1,4 +1,4 @@ -package by.alexandr7035.gitstat.extensions +package by.alexandr7035.gitstat.core.extensions import timber.log.Timber diff --git a/app/src/main/java/by/alexandr7035/gitstat/extensions/YAxis.kt b/app/src/main/java/by/alexandr7035/gitstat/core/extensions/YAxis.kt similarity index 93% rename from app/src/main/java/by/alexandr7035/gitstat/extensions/YAxis.kt rename to app/src/main/java/by/alexandr7035/gitstat/core/extensions/YAxis.kt index ca580c88..2595d0cd 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/extensions/YAxis.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/core/extensions/YAxis.kt @@ -1,4 +1,4 @@ -package by.alexandr7035.gitstat.extensions +package by.alexandr7035.gitstat.core.extensions import com.github.mikephil.charting.components.YAxis import kotlin.math.floor diff --git a/app/src/main/java/by/alexandr7035/gitstat/core/view/HorizontalRatioBarView.kt b/app/src/main/java/by/alexandr7035/gitstat/core/view/HorizontalRatioBarView.kt index 7070af7d..69b90ecb 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/core/view/HorizontalRatioBarView.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/core/view/HorizontalRatioBarView.kt @@ -8,7 +8,7 @@ import android.graphics.RectF import android.util.AttributeSet import android.view.View import by.alexandr7035.gitstat.R -import by.alexandr7035.gitstat.extensions.debug +import by.alexandr7035.gitstat.core.extensions.debug import timber.log.Timber diff --git a/app/src/main/java/by/alexandr7035/gitstat/data/DataSyncRepository.kt b/app/src/main/java/by/alexandr7035/gitstat/data/DataSyncRepository.kt index 6c74c703..179efeac 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/data/DataSyncRepository.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/data/DataSyncRepository.kt @@ -6,7 +6,7 @@ import by.alexandr7035.gitstat.core.* import by.alexandr7035.gitstat.data.local.CacheDB import by.alexandr7035.gitstat.data.local.model.* import by.alexandr7035.gitstat.data.remote.mappers.* -import by.alexandr7035.gitstat.extensions.performRequestWithDataResult +import by.alexandr7035.gitstat.core.extensions.performRequestWithDataResult import com.apollographql.apollo3.ApolloClient import timber.log.Timber import java.util.* diff --git a/app/src/main/java/by/alexandr7035/gitstat/data/SyncForegroundService.kt b/app/src/main/java/by/alexandr7035/gitstat/data/SyncForegroundService.kt index 8bf6c074..d928759f 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/data/SyncForegroundService.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/data/SyncForegroundService.kt @@ -10,7 +10,7 @@ import androidx.lifecycle.LifecycleService import androidx.lifecycle.MutableLiveData import by.alexandr7035.gitstat.R import by.alexandr7035.gitstat.core.DataSyncStatus -import by.alexandr7035.gitstat.extensions.debug +import by.alexandr7035.gitstat.core.extensions.debug import by.alexandr7035.gitstat.view.MainActivity import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.* diff --git a/app/src/main/java/by/alexandr7035/gitstat/data/remote/mappers/RepositoriesRemoteToCacheMapper.kt b/app/src/main/java/by/alexandr7035/gitstat/data/remote/mappers/RepositoriesRemoteToCacheMapper.kt index 44f025d7..5ba573b8 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/data/remote/mappers/RepositoriesRemoteToCacheMapper.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/data/remote/mappers/RepositoriesRemoteToCacheMapper.kt @@ -5,7 +5,7 @@ import by.alexandr7035.gitstat.core.Mapper import by.alexandr7035.gitstat.core.TimeHelper import by.alexandr7035.gitstat.data.local.model.RepoLanguage import by.alexandr7035.gitstat.data.local.model.RepositoryEntity -import by.alexandr7035.gitstat.extensions.debug +import by.alexandr7035.gitstat.core.extensions.debug import timber.log.Timber import javax.inject.Inject diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/MainActivity.kt b/app/src/main/java/by/alexandr7035/gitstat/view/MainActivity.kt index beeff613..cef9aaa1 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/MainActivity.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/MainActivity.kt @@ -17,7 +17,7 @@ import by.alexandr7035.gitstat.NavGraphDirections import by.alexandr7035.gitstat.R import by.alexandr7035.gitstat.data.SyncForegroundService import by.alexandr7035.gitstat.databinding.ActivityMainBinding -import by.alexandr7035.gitstat.extensions.navigateSafe +import by.alexandr7035.gitstat.core.extensions.navigateSafe import by.alexandr7035.gitstat.view.datasync.SyncHostFragmentDirections import by.alexandr7035.gitstat.view.login.LoginFragmentDirections import by.alexandr7035.gitstat.view.profile.ProfileViewModel diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/contributions/ContributionsFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/contributions/ContributionsFragment.kt index 3cd63770..8e3f7fe6 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/contributions/ContributionsFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/contributions/ContributionsFragment.kt @@ -11,7 +11,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.viewpager2.widget.ViewPager2 import by.alexandr7035.gitstat.R import by.alexandr7035.gitstat.databinding.FragmentContributionsBinding -import by.alexandr7035.gitstat.extensions.navigateSafe +import by.alexandr7035.gitstat.core.extensions.navigateSafe import by.alexandr7035.gitstat.view.MainActivity import by.alexandr7035.gitstat.view.contributions.plots.contributions_per_year.YearContributionsAdapter import by.alexandr7035.gitstat.view.contributions.plots.contributions_rate.YearContributionRatesAdapter diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/contributions/plots/contributions_per_year/YearContributionsFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/contributions/plots/contributions_per_year/YearContributionsFragment.kt index 7a44a2c3..959e5b35 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/contributions/plots/contributions_per_year/YearContributionsFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/contributions/plots/contributions_per_year/YearContributionsFragment.kt @@ -9,10 +9,10 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels import by.alexandr7035.gitstat.R import by.alexandr7035.gitstat.databinding.ViewPlotContributionsYearBinding -import by.alexandr7035.gitstat.extensions.debug -import by.alexandr7035.gitstat.extensions.setChartData -import by.alexandr7035.gitstat.extensions.setupYAxisValuesForContributions -import by.alexandr7035.gitstat.extensions.setupYearLineChartView +import by.alexandr7035.gitstat.core.extensions.debug +import by.alexandr7035.gitstat.core.extensions.setChartData +import by.alexandr7035.gitstat.core.extensions.setupYAxisValuesForContributions +import by.alexandr7035.gitstat.core.extensions.setupYearLineChartView import by.alexandr7035.gitstat.view.contributions.ContributionsViewModel import by.alexandr7035.gitstat.view.contributions.plots.DateMonthsValueFormatter import by.alexandr7035.gitstat.view.contributions.plots.LinePlotFill diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/contributions/plots/contributions_rate/YearContributionRatesFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/contributions/plots/contributions_rate/YearContributionRatesFragment.kt index 25965793..c98d6001 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/contributions/plots/contributions_rate/YearContributionRatesFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/contributions/plots/contributions_rate/YearContributionRatesFragment.kt @@ -9,9 +9,9 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels import by.alexandr7035.gitstat.R import by.alexandr7035.gitstat.databinding.FragmentYearContributionsRateBinding -import by.alexandr7035.gitstat.extensions.setChartData -import by.alexandr7035.gitstat.extensions.setupYAxisValuesForContributionRate -import by.alexandr7035.gitstat.extensions.setupYearLineChartView +import by.alexandr7035.gitstat.core.extensions.setChartData +import by.alexandr7035.gitstat.core.extensions.setupYAxisValuesForContributionRate +import by.alexandr7035.gitstat.core.extensions.setupYearLineChartView import by.alexandr7035.gitstat.view.contributions.ContributionsViewModel import by.alexandr7035.gitstat.view.contributions.plots.DateMonthsValueFormatter import by.alexandr7035.gitstat.view.contributions.plots.LinePlotFill diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/contributions_grid/ContributionsGridFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/contributions_grid/ContributionsGridFragment.kt index 2be85ccc..17a10547 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/contributions_grid/ContributionsGridFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/contributions_grid/ContributionsGridFragment.kt @@ -14,8 +14,8 @@ import by.alexandr7035.gitstat.data.local.model.ContributionDayEntity import by.alexandr7035.gitstat.data.local.model.ContributionYearWithMonths import by.alexandr7035.gitstat.data.local.model.ContributionsMonthWithDays import by.alexandr7035.gitstat.databinding.FragmentContributionsGridBinding -import by.alexandr7035.gitstat.extensions.debug -import by.alexandr7035.gitstat.extensions.navigateSafe +import by.alexandr7035.gitstat.core.extensions.debug +import by.alexandr7035.gitstat.core.extensions.navigateSafe import com.google.android.material.tabs.TabLayout import dagger.hilt.android.AndroidEntryPoint import timber.log.Timber diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/contributions_grid/DaysAdapter.kt b/app/src/main/java/by/alexandr7035/gitstat/view/contributions_grid/DaysAdapter.kt index cb31fc1d..96787983 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/contributions_grid/DaysAdapter.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/contributions_grid/DaysAdapter.kt @@ -12,7 +12,7 @@ import by.alexandr7035.gitstat.R import by.alexandr7035.gitstat.core.TimeHelper import by.alexandr7035.gitstat.data.local.model.ContributionDayEntity import by.alexandr7035.gitstat.databinding.ViewContributionsGridCellBinding -import by.alexandr7035.gitstat.extensions.debug +import by.alexandr7035.gitstat.core.extensions.debug import timber.log.Timber class DaysAdapter(private val dayClickListener: DayClickListener): RecyclerView.Adapter() { diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/contributions_grid/MonthsAdapter.kt b/app/src/main/java/by/alexandr7035/gitstat/view/contributions_grid/MonthsAdapter.kt index 17f90557..57f89f0c 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/contributions_grid/MonthsAdapter.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/contributions_grid/MonthsAdapter.kt @@ -8,7 +8,7 @@ import androidx.recyclerview.widget.RecyclerView import by.alexandr7035.gitstat.data.local.model.ContributionDayEntity import by.alexandr7035.gitstat.data.local.model.ContributionsMonthWithDays import by.alexandr7035.gitstat.databinding.ViewMonthContributionsGridBinding -import by.alexandr7035.gitstat.extensions.debug +import by.alexandr7035.gitstat.core.extensions.debug import timber.log.Timber import java.text.SimpleDateFormat import java.util.* diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/login/LoginFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/login/LoginFragment.kt index 766c3a65..c17f5dc3 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/login/LoginFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/login/LoginFragment.kt @@ -17,8 +17,8 @@ import by.alexandr7035.gitstat.NavGraphDirections import by.alexandr7035.gitstat.R import by.alexandr7035.gitstat.core.GithubAccessScopes import by.alexandr7035.gitstat.databinding.FragmentLoginBinding -import by.alexandr7035.gitstat.extensions.getClickableSpannable -import by.alexandr7035.gitstat.extensions.navigateSafe +import by.alexandr7035.gitstat.core.extensions.getClickableSpannable +import by.alexandr7035.gitstat.core.extensions.navigateSafe import by.alexandr7035.gitstat.view.MainActivity import com.google.firebase.auth.OAuthCredential import com.google.firebase.auth.OAuthProvider diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/profile/ProfileFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/profile/ProfileFragment.kt index cd00c4de..b0efcb31 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/profile/ProfileFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/profile/ProfileFragment.kt @@ -10,7 +10,7 @@ import androidx.fragment.app.viewModels import androidx.navigation.fragment.findNavController import by.alexandr7035.gitstat.R import by.alexandr7035.gitstat.databinding.FragmentProfileBinding -import by.alexandr7035.gitstat.extensions.navigateSafe +import by.alexandr7035.gitstat.core.extensions.navigateSafe import by.alexandr7035.gitstat.view.MainActivity import com.squareup.picasso.Picasso import dagger.hilt.android.AndroidEntryPoint diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ActiveRepositoriesFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ActiveRepositoriesFragment.kt index 928fc503..8fb94aa1 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ActiveRepositoriesFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ActiveRepositoriesFragment.kt @@ -11,7 +11,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import by.alexandr7035.gitstat.R import by.alexandr7035.gitstat.RepositoriesListGraphDirections import by.alexandr7035.gitstat.databinding.FragmentRepositoriesRecyclerBinding -import by.alexandr7035.gitstat.extensions.navigateSafe +import by.alexandr7035.gitstat.core.extensions.navigateSafe import by.alexandr7035.gitstat.view.repositories.filters.RepositoriesListFiltersHelper import dagger.hilt.android.AndroidEntryPoint diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ArchivedRepositoriesFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ArchivedRepositoriesFragment.kt index 133395d0..00793e5f 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ArchivedRepositoriesFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ArchivedRepositoriesFragment.kt @@ -11,7 +11,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import by.alexandr7035.gitstat.R import by.alexandr7035.gitstat.RepositoriesListGraphDirections import by.alexandr7035.gitstat.databinding.FragmentRepositoriesRecyclerBinding -import by.alexandr7035.gitstat.extensions.navigateSafe +import by.alexandr7035.gitstat.core.extensions.navigateSafe import by.alexandr7035.gitstat.view.repositories.filters.RepositoriesListFiltersHelper import dagger.hilt.android.AndroidEntryPoint diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ReposOverviewFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ReposOverviewFragment.kt index 1cd4a0b0..76bd19e9 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ReposOverviewFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ReposOverviewFragment.kt @@ -8,7 +8,7 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels import androidx.navigation.fragment.findNavController import by.alexandr7035.gitstat.databinding.FragmentReposOverviewBinding -import by.alexandr7035.gitstat.extensions.navigateSafe +import by.alexandr7035.gitstat.core.extensions.navigateSafe import by.alexandr7035.gitstat.view.MainActivity import by.alexandr7035.gitstat.view.repositories.plots.languages_plot.LanguagesPlot import dagger.hilt.android.AndroidEntryPoint diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/repositories/RepositoriesListHostFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/repositories/RepositoriesListHostFragment.kt index 11c49c4f..c5c76886 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/repositories/RepositoriesListHostFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/repositories/RepositoriesListHostFragment.kt @@ -11,7 +11,7 @@ import androidx.navigation.fragment.findNavController import androidx.navigation.navGraphViewModels import by.alexandr7035.gitstat.R import by.alexandr7035.gitstat.databinding.FragmentHostRepositoriesListBinding -import by.alexandr7035.gitstat.extensions.navigateSafe +import by.alexandr7035.gitstat.core.extensions.navigateSafe import com.google.android.material.badge.BadgeDrawable import com.google.android.material.badge.BadgeUtils import com.google.android.material.tabs.TabLayout diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/repositories/RepositoryPageFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/repositories/RepositoryPageFragment.kt index 9017a4a7..0279d235 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/repositories/RepositoryPageFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/repositories/RepositoryPageFragment.kt @@ -17,9 +17,9 @@ import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs import by.alexandr7035.gitstat.R import by.alexandr7035.gitstat.databinding.FragmentRepositoryPageBinding -import by.alexandr7035.gitstat.extensions.debug -import by.alexandr7035.gitstat.extensions.getClickableSpannable -import by.alexandr7035.gitstat.extensions.getStringDateFromLong +import by.alexandr7035.gitstat.core.extensions.debug +import by.alexandr7035.gitstat.core.extensions.getClickableSpannable +import by.alexandr7035.gitstat.core.extensions.getStringDateFromLong import com.google.android.flexbox.FlexboxLayoutManager import dagger.hilt.android.AndroidEntryPoint import timber.log.Timber From f595bd51a6afba4291905caca17d5e044c152ce9 Mon Sep 17 00:00:00 2001 From: Alexandr Alexeenko Date: Sun, 12 Dec 2021 14:07:49 +0300 Subject: [PATCH 02/13] Use by lazy() delegate for navController and viewbinding Closes #203 --- .../alexandr7035/gitstat/view/MainActivity.kt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/MainActivity.kt b/app/src/main/java/by/alexandr7035/gitstat/view/MainActivity.kt index cef9aaa1..12595d34 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/MainActivity.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/MainActivity.kt @@ -12,6 +12,7 @@ import androidx.drawerlayout.widget.DrawerLayout import androidx.navigation.NavController import androidx.navigation.fragment.NavHostFragment import androidx.navigation.ui.setupWithNavController +import androidx.viewbinding.ViewBinding import by.alexandr7035.gitstat.BuildConfig import by.alexandr7035.gitstat.NavGraphDirections import by.alexandr7035.gitstat.R @@ -28,22 +29,22 @@ import de.hdodenhof.circleimageview.CircleImageView @AndroidEntryPoint class MainActivity : AppCompatActivity() { - private lateinit var navController: NavController - private lateinit var binding: ActivityMainBinding - private val viewModel by viewModels() + private val navController: NavController by lazy(LazyThreadSafetyMode.NONE) { + val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment + navHostFragment.navController + } + + private val binding: ActivityMainBinding by lazy(LazyThreadSafetyMode.NONE) { + ActivityMainBinding.inflate(layoutInflater) + } + private val viewModel by viewModels() private val profileViewModel by viewModels() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - - binding = ActivityMainBinding.inflate(layoutInflater) setContentView(binding.root) - // NavController - val hf: NavHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment - navController = hf.navController - // Setting Navigation Controller with the BottomNavigationView ) binding.bottomNavigationView.setupWithNavController(navController) From 763c1ecbe6e9748f3d761e81adbfcf528e6cfa1a Mon Sep 17 00:00:00 2001 From: Alexandr Alexeenko Date: Sun, 12 Dec 2021 14:45:49 +0300 Subject: [PATCH 03/13] Add observeNullSafe() for LiveData Related #203 --- .../gitstat/core/extensions/LiveData.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 app/src/main/java/by/alexandr7035/gitstat/core/extensions/LiveData.kt diff --git a/app/src/main/java/by/alexandr7035/gitstat/core/extensions/LiveData.kt b/app/src/main/java/by/alexandr7035/gitstat/core/extensions/LiveData.kt new file mode 100644 index 00000000..39903102 --- /dev/null +++ b/app/src/main/java/by/alexandr7035/gitstat/core/extensions/LiveData.kt @@ -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 LiveData.observeNullSafe(owner: LifecycleOwner, observer: (t: T) -> Unit) { + this.observe(owner, { + it?.let(observer) + }) +} \ No newline at end of file From e399be2a0136220838eff7198b38783743594ac0 Mon Sep 17 00:00:00 2001 From: Alexandr Alexeenko Date: Sun, 12 Dec 2021 14:46:35 +0300 Subject: [PATCH 04/13] Update code with observeNullSafe() extension Closes #203 --- .../gitstat/data/SyncForegroundService.kt | 3 +- .../alexandr7035/gitstat/view/MainActivity.kt | 75 ++++---- .../contributions/ContributionsFragment.kt | 124 ++++++------ .../YearContributionsFragment.kt | 13 +- .../YearContributionRatesFragment.kt | 7 +- .../ContributionsGridFragment.kt | 21 +- .../gitstat/view/datasync/SyncHostFragment.kt | 3 +- .../gitstat/view/profile/ProfileFragment.kt | 55 +++--- .../ActiveRepositoriesFragment.kt | 5 +- .../ArchivedRepositoriesFragment.kt | 5 +- .../repositories/ReposOverviewFragment.kt | 41 ++-- .../RepositoriesListHostFragment.kt | 7 +- .../repositories/RepositoryPageFragment.kt | 182 +++++++++--------- .../filters/RepositoriesFiltersDialog.kt | 3 +- 14 files changed, 261 insertions(+), 283 deletions(-) diff --git a/app/src/main/java/by/alexandr7035/gitstat/data/SyncForegroundService.kt b/app/src/main/java/by/alexandr7035/gitstat/data/SyncForegroundService.kt index d928759f..b588d6fa 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/data/SyncForegroundService.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/data/SyncForegroundService.kt @@ -11,6 +11,7 @@ import androidx.lifecycle.MutableLiveData import by.alexandr7035.gitstat.R import by.alexandr7035.gitstat.core.DataSyncStatus import by.alexandr7035.gitstat.core.extensions.debug +import by.alexandr7035.gitstat.core.extensions.observeNullSafe import by.alexandr7035.gitstat.view.MainActivity import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.* @@ -48,7 +49,7 @@ class SyncForegroundService: LifecycleService() { stopSelf() } - statusLiveData?.observe(this, { + statusLiveData?.observeNullSafe(this, { Timber.debug("Service: sync status changed $it") val notificationText = when (it) { diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/MainActivity.kt b/app/src/main/java/by/alexandr7035/gitstat/view/MainActivity.kt index 12595d34..e14df1f0 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/MainActivity.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/MainActivity.kt @@ -19,6 +19,7 @@ import by.alexandr7035.gitstat.R import by.alexandr7035.gitstat.data.SyncForegroundService import by.alexandr7035.gitstat.databinding.ActivityMainBinding import by.alexandr7035.gitstat.core.extensions.navigateSafe +import by.alexandr7035.gitstat.core.extensions.observeNullSafe import by.alexandr7035.gitstat.view.datasync.SyncHostFragmentDirections import by.alexandr7035.gitstat.view.login.LoginFragmentDirections import by.alexandr7035.gitstat.view.profile.ProfileViewModel @@ -65,18 +66,16 @@ class MainActivity : AppCompatActivity() { navController.addOnDestinationChangedListener { _, destination, _ -> // Show bottom nav on primary fragments and their dialogs - if (bottomNavVisiblePrimaryDestinations.contains(destination.id) || bottomNavVisibleDialogsDestinations.contains(destination.id)) { + if (bottomNavVisiblePrimaryDestinations.contains(destination.id) || bottomNavVisibleDialogsDestinations.contains(destination.id)) { binding.bottomNavigationView.visibility = View.VISIBLE - } - else { + } else { binding.bottomNavigationView.visibility = View.GONE } // Allow opening drawer only on primary fragments if (bottomNavVisiblePrimaryDestinations.contains(destination.id)) { binding.drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED) - } - else { + } else { binding.drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED) } } @@ -85,8 +84,7 @@ class MainActivity : AppCompatActivity() { if (viewModel.checkIfTokenSaved()) { if (viewModel.checkIfCacheExists()) { navController.navigateSafe(LoginFragmentDirections.actionLoginFragmentToProfileFragment()) - } - else { + } else { startSyncData() } } @@ -98,48 +96,49 @@ class MainActivity : AppCompatActivity() { val syncDateView = binding.drawerNavigationView.getHeaderView(0).findViewById(R.id.syncDate) val resyncBtn = binding.drawerNavigationView.getHeaderView(0).findViewById(R.id.resyncBtn) - profileViewModel.getUserLiveData().observe(this, { - - if (it != null) { + profileViewModel.getUserLiveData().observeNullSafe(this, { - Picasso.get().load(it.avatar_url).into(drawerPictureView) + Picasso.get().load(it.avatar_url).into(drawerPictureView) - // This field can be empty - if (it.name.isEmpty()) { - drawerNameView.visibility = View.GONE - } else { - drawerNameView.visibility = View.VISIBLE - drawerNameView.text = it.name - } + // This field can be empty + if (it.name.isEmpty()) { + drawerNameView.visibility = View.GONE + } else { + drawerNameView.visibility = View.VISIBLE + drawerNameView.text = it.name + } - drawerLoginView.text = getString(R.string.login_string, it.login) + drawerLoginView.text = getString(R.string.login_string, it.login) - // We can also update sync date in drawer - // As livedata triggering means cache may have been updated - syncDateView.text = viewModel.getCacheSyncDate().replace(" ", "\n") - } + // We can also update sync date in drawer + // As livedata triggering means cache may have been updated + syncDateView.text = viewModel.getCacheSyncDate().replace(" ", "\n") }) binding.drawerNavigationView.setNavigationItemSelectedListener { menuItem -> when (menuItem.itemId) { - R.id.item_logout -> { + R.id.item_logout -> { navController.navigateSafe(NavGraphDirections.actionGlobalLogoutConfirmationDialog()) binding.drawerLayout.closeDrawer(GravityCompat.START) } - R.id.item_privacy_policy -> navController.navigateSafe(NavGraphDirections.actionGlobalInfoFragment( - getString(R.string.privacy_policy), - null, - getString(R.string.privacy_policy_full_text) - )) - - R.id.item_about_app -> navController.navigateSafe(NavGraphDirections.actionGlobalInfoFragment( - getString(R.string.about_app), - getString(R.string.app_name_with_version, BuildConfig.VERSION_NAME), - getString(R.string.app_description) - )) + R.id.item_privacy_policy -> navController.navigateSafe( + NavGraphDirections.actionGlobalInfoFragment( + getString(R.string.privacy_policy), + null, + getString(R.string.privacy_policy_full_text) + ) + ) + + R.id.item_about_app -> navController.navigateSafe( + NavGraphDirections.actionGlobalInfoFragment( + getString(R.string.about_app), + getString(R.string.app_name_with_version, BuildConfig.VERSION_NAME), + getString(R.string.app_description) + ) + ) } true @@ -168,8 +167,10 @@ class MainActivity : AppCompatActivity() { fun startLogOut() { viewModel.clearCache() viewModel.clearToken() - navController.navigateSafe(NavGraphDirections - .actionGlobalLoginFragment()) + navController.navigateSafe( + NavGraphDirections + .actionGlobalLoginFragment() + ) } // FIXME diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/contributions/ContributionsFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/contributions/ContributionsFragment.kt index 8e3f7fe6..ad73f691 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/contributions/ContributionsFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/contributions/ContributionsFragment.kt @@ -12,6 +12,7 @@ import androidx.viewpager2.widget.ViewPager2 import by.alexandr7035.gitstat.R import by.alexandr7035.gitstat.databinding.FragmentContributionsBinding import by.alexandr7035.gitstat.core.extensions.navigateSafe +import by.alexandr7035.gitstat.core.extensions.observeNullSafe import by.alexandr7035.gitstat.view.MainActivity import by.alexandr7035.gitstat.view.contributions.plots.contributions_per_year.YearContributionsAdapter import by.alexandr7035.gitstat.view.contributions.plots.contributions_rate.YearContributionRatesAdapter @@ -49,88 +50,75 @@ class ContributionsFragment : Fragment() { binding?.contributionTypesRecycler?.adapter = typesLegendAdapter // Update data - viewModel.getContributionYearsLiveData().observe(viewLifecycleOwner, { years -> + viewModel.getContributionYearsLiveData().observeNullSafe(viewLifecycleOwner, { years -> + if (years.isNotEmpty()) { - if (years != null) { + yearContributionsAdapter.setItems(years) - if (years.isNotEmpty()) { + // Set to last position + binding?.yearsViewPager?.setCurrentItem(years.size - 1, false) + binding?.currentYearView?.text = years[years.size - 1].year.id.toString() - yearContributionsAdapter.setItems(years) + // Change year in card title when viewpager item changes + binding?.yearsViewPager?.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() { + override fun onPageSelected(position: Int) { + super.onPageSelected(position) + Timber.d("Page changed callback") + binding?.currentYearView?.text = years[position].year.id.toString() + } + }) - // Set to last position - binding?.yearsViewPager?.setCurrentItem(years.size - 1, false) - binding?.currentYearView?.text = years[years.size - 1].year.id.toString() + // Attach tablayout + TabLayoutMediator(binding!!.yearsTabLayout, binding!!.yearsViewPager) { tab, position -> + }.attach() - // Change year in card title when viewpager item changes - binding?.yearsViewPager?.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() { - override fun onPageSelected(position: Int) { - super.onPageSelected(position) - Timber.d("Page changed callback") - binding?.currentYearView?.text = years[position].year.id.toString() - } - }) - - // Attach tablayout - TabLayoutMediator(binding!!.yearsTabLayout, binding!!.yearsViewPager) { tab, position -> - }.attach() - - } } }) - viewModel.getContributionDaysLiveData().observe(viewLifecycleOwner, { contributions -> - if (contributions != null) { - val totalContributions = contributions.sumOf { it.count } - binding?.totalContributions?.text = totalContributions.toString() - } + viewModel.getContributionDaysLiveData().observeNullSafe(viewLifecycleOwner, { contributions -> + val totalContributions = contributions.sumOf { it.count } + binding?.totalContributions?.text = totalContributions.toString() }) - viewModel.getContributionYearsWithRatesLiveData().observe(viewLifecycleOwner, { rateYears -> - - if (rateYears != null) { + viewModel.getContributionYearsWithRatesLiveData().observeNullSafe(viewLifecycleOwner, { rateYears -> + if (rateYears.isNotEmpty()) { + yearContributionsRateAdapter.setItems(rateYears) - if (rateYears.isNotEmpty()) { - yearContributionsRateAdapter.setItems(rateYears) + TabLayoutMediator(binding!!.rateTabLayout, binding!!.rateViewPager) { tab, position -> + }.attach() - TabLayoutMediator(binding!!.rateTabLayout, binding!!.rateViewPager) { tab, position -> - }.attach() + // Set to last position + binding?.rateViewPager?.setCurrentItem(rateYears.size - 1, false) - // Set to last position - binding?.rateViewPager?.setCurrentItem(rateYears.size - 1, false) - - // Set total contribution rate in header - binding?.contributionsRate?.text = - viewModel.getLastTotalContributionRateForYear(rateYears[rateYears.size - 1]).toString() - } + // Set total contribution rate in header + binding?.contributionsRate?.text = + viewModel.getLastTotalContributionRateForYear(rateYears[rateYears.size - 1]).toString() } }) - viewModel.getContributionTypesLiveData().observe(viewLifecycleOwner, { typesData -> - - if (typesData != null) { - // Update legend - binding?.contributionTypesRecycler?.suppressLayout(false) - val types = ContributionTypesListToRecyclerItemsMapper.map(typesData, requireContext()) - typesLegendAdapter.setItems(types) - binding?.contributionTypesRecycler?.suppressLayout(true) + viewModel.getContributionTypesLiveData().observeNullSafe(viewLifecycleOwner, { typesData -> + // Update legend + binding?.contributionTypesRecycler?.suppressLayout(false) + val types = ContributionTypesListToRecyclerItemsMapper.map(typesData, requireContext()) + typesLegendAdapter.setItems(types) + binding?.contributionTypesRecycler?.suppressLayout(true) - // Setup ratio bar bar - val values = ArrayList() - val colors = ArrayList() + // Setup ratio bar bar + val values = ArrayList() + val colors = ArrayList() - for (type in types) { - colors.add(type.color) - values.add(type.count.toFloat()) - } - - binding?.typesRatioView?.setValues(values, colors) - binding?.typesRatioView?.invalidate() + for (type in types) { + colors.add(type.color) + values.add(type.count.toFloat()) } + + binding?.typesRatioView?.setValues(values, colors) + binding?.typesRatioView?.invalidate() }) binding?.drawerBtn?.setOnClickListener { @@ -139,18 +127,22 @@ class ContributionsFragment : Fragment() { // Help icon for contribution rate binding?.contributionRateHelpIcon?.setOnClickListener { - findNavController().navigateSafe(ContributionsFragmentDirections.actionGlobalInfoDialogFragment( - getString(R.string.what_is_contribution_rate_title), - getString(R.string.what_is_contribution_rate_text) - )) + findNavController().navigateSafe( + ContributionsFragmentDirections.actionGlobalInfoDialogFragment( + getString(R.string.what_is_contribution_rate_title), + getString(R.string.what_is_contribution_rate_text) + ) + ) } // Help icon for contribution rate binding?.contributionRateDynamicsHelpIcon?.setOnClickListener { - findNavController().navigateSafe(ContributionsFragmentDirections.actionGlobalInfoDialogFragment( - getString(R.string.contribution_rate_dynamics_help_title), - getString(R.string.contribution_rate_dynamics_help_text) - )) + findNavController().navigateSafe( + ContributionsFragmentDirections.actionGlobalInfoDialogFragment( + getString(R.string.contribution_rate_dynamics_help_title), + getString(R.string.contribution_rate_dynamics_help_text) + ) + ) } diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/contributions/plots/contributions_per_year/YearContributionsFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/contributions/plots/contributions_per_year/YearContributionsFragment.kt index 959e5b35..c094773e 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/contributions/plots/contributions_per_year/YearContributionsFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/contributions/plots/contributions_per_year/YearContributionsFragment.kt @@ -8,11 +8,8 @@ import androidx.core.content.ContextCompat import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels import by.alexandr7035.gitstat.R +import by.alexandr7035.gitstat.core.extensions.* import by.alexandr7035.gitstat.databinding.ViewPlotContributionsYearBinding -import by.alexandr7035.gitstat.core.extensions.debug -import by.alexandr7035.gitstat.core.extensions.setChartData -import by.alexandr7035.gitstat.core.extensions.setupYAxisValuesForContributions -import by.alexandr7035.gitstat.core.extensions.setupYearLineChartView import by.alexandr7035.gitstat.view.contributions.ContributionsViewModel import by.alexandr7035.gitstat.view.contributions.plots.DateMonthsValueFormatter import by.alexandr7035.gitstat.view.contributions.plots.LinePlotFill @@ -37,11 +34,9 @@ class YearContributionsFragment: Fragment() { val year = arguments?.getInt("year") - viewModel.getContributionYearsWithDaysLiveData().observe(viewLifecycleOwner, { yearsData -> + viewModel.getContributionYearsWithDaysLiveData().observeNullSafe(viewLifecycleOwner, { yearsData -> - Timber.debug("$year $yearsData") - - if (! yearsData.isNullOrEmpty()) { + if (yearsData.isNotEmpty()) { // FIXME find better solution (obtain certain year from data layer) val yearData = yearsData.findLast { @@ -100,12 +95,10 @@ class YearContributionsFragment: Fragment() { binding?.contributionsChart?.invalidate() } }) - } override fun onDestroyView() { super.onDestroyView() binding = null } - } \ No newline at end of file diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/contributions/plots/contributions_rate/YearContributionRatesFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/contributions/plots/contributions_rate/YearContributionRatesFragment.kt index c98d6001..06c53708 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/contributions/plots/contributions_rate/YearContributionRatesFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/contributions/plots/contributions_rate/YearContributionRatesFragment.kt @@ -8,6 +8,7 @@ import androidx.core.content.ContextCompat import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels import by.alexandr7035.gitstat.R +import by.alexandr7035.gitstat.core.extensions.observeNullSafe import by.alexandr7035.gitstat.databinding.FragmentYearContributionsRateBinding import by.alexandr7035.gitstat.core.extensions.setChartData import by.alexandr7035.gitstat.core.extensions.setupYAxisValuesForContributionRate @@ -36,9 +37,9 @@ class YearContributionRatesFragment : Fragment() { val year = arguments?.getInt("year") // Observe the result - viewModel.getContributionYearsWithRatesLiveData().observe(viewLifecycleOwner, { yearsData -> + viewModel.getContributionYearsWithRatesLiveData().observeNullSafe(viewLifecycleOwner, { yearsData -> - if (! yearsData.isNullOrEmpty()) { + if (yearsData.isNotEmpty()) { // FIXME find better solution (obtain certain year from data layer) val yearData = yearsData.findLast { @@ -93,7 +94,5 @@ class YearContributionRatesFragment : Fragment() { binding?.rateChart?.invalidate() } }) - } - } \ No newline at end of file diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/contributions_grid/ContributionsGridFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/contributions_grid/ContributionsGridFragment.kt index 17a10547..f1a83807 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/contributions_grid/ContributionsGridFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/contributions_grid/ContributionsGridFragment.kt @@ -16,6 +16,7 @@ import by.alexandr7035.gitstat.data.local.model.ContributionsMonthWithDays import by.alexandr7035.gitstat.databinding.FragmentContributionsGridBinding import by.alexandr7035.gitstat.core.extensions.debug import by.alexandr7035.gitstat.core.extensions.navigateSafe +import by.alexandr7035.gitstat.core.extensions.observeNullSafe import com.google.android.material.tabs.TabLayout import dagger.hilt.android.AndroidEntryPoint import timber.log.Timber @@ -48,10 +49,8 @@ class ContributionsGridFragment : Fragment(), DayClickListener { binding?.monthRecycler?.adapter = adapter binding?.monthRecycler?.layoutManager = LinearLayoutManager(requireContext()) - viewModel.getContributionYearsWithMonthsLiveData().observe(viewLifecycleOwner, { years -> - - if (! years.isNullOrEmpty()) { - + viewModel.getContributionYearsWithMonthsLiveData().observeNullSafe(viewLifecycleOwner, { years -> + if (years.isNotEmpty()) { // Add year tabs depending on years list (reversed) for (year in years.reversed()) { val tab = binding?.tabLayout?.newTab() @@ -85,9 +84,7 @@ class ContributionsGridFragment : Fragment(), DayClickListener { // Set initial tab position val initialTab = binding?.tabLayout?.getTabAt(0) initialTab?.select() - } - }) } @@ -138,10 +135,12 @@ class ContributionsGridFragment : Fragment(), DayClickListener { override fun onDayItemClick(contributionDay: ContributionDayEntity) { Timber.debug("click in FRAGMENT $contributionDay") - findNavController().navigateSafe(ContributionsGridFragmentDirections.actionContributionsGridFragmentToContributionDayDialogFragment( - contributionDay.count, - contributionDay.date, - contributionDay.color - )) + findNavController().navigateSafe( + ContributionsGridFragmentDirections.actionContributionsGridFragmentToContributionDayDialogFragment( + contributionDay.count, + contributionDay.date, + contributionDay.color + ) + ) } } \ No newline at end of file diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/datasync/SyncHostFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/datasync/SyncHostFragment.kt index c8286f31..cd6cffb5 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/datasync/SyncHostFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/datasync/SyncHostFragment.kt @@ -9,6 +9,7 @@ import androidx.fragment.app.viewModels import by.alexandr7035.gitstat.BuildConfig import by.alexandr7035.gitstat.R import by.alexandr7035.gitstat.core.DataSyncStatus +import by.alexandr7035.gitstat.core.extensions.observeNullSafe import by.alexandr7035.gitstat.databinding.FragmentSyncHostBinding import by.alexandr7035.gitstat.view.MainActivity import dagger.hilt.android.AndroidEntryPoint @@ -30,7 +31,7 @@ class SyncHostFragment : Fragment() { viewModel.syncData() - viewModel.getSyncStatusLiveData().observe(viewLifecycleOwner, { status -> + viewModel.getSyncStatusLiveData().observeNullSafe(viewLifecycleOwner, { status -> Timber.d("sync status updated $status") when (status) { diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/profile/ProfileFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/profile/ProfileFragment.kt index b0efcb31..775b06fb 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/profile/ProfileFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/profile/ProfileFragment.kt @@ -11,6 +11,7 @@ import androidx.navigation.fragment.findNavController import by.alexandr7035.gitstat.R import by.alexandr7035.gitstat.databinding.FragmentProfileBinding import by.alexandr7035.gitstat.core.extensions.navigateSafe +import by.alexandr7035.gitstat.core.extensions.observeNullSafe import by.alexandr7035.gitstat.view.MainActivity import com.squareup.picasso.Picasso import dagger.hilt.android.AndroidEntryPoint @@ -34,45 +35,41 @@ class ProfileFragment : Fragment() { super.onViewCreated(view, savedInstanceState) // Update profile data - viewModel.getUserLiveData().observe(viewLifecycleOwner, { + viewModel.getUserLiveData().observeNullSafe(viewLifecycleOwner, { Timber.tag("DEBUG_TAG").d("livedata updated $it") - if (it != null) { + Picasso.get().load(it.avatar_url).into(binding!!.profileImageView) - Picasso.get().load(it.avatar_url).into(binding!!.profileImageView) - - // This field can be empty - if (it.name.isEmpty()) { - binding?.nameView?.visibility = View.GONE - } else { - binding?.nameView?.visibility = View.VISIBLE - binding?.nameView?.text = it.name - } - - binding!!.loginView.text = getString(R.string.login_string, it.login) - - binding!!.idView.text = it.id.toString() + // This field can be empty + if (it.name.isEmpty()) { + binding?.nameView?.visibility = View.GONE + } else { + binding?.nameView?.visibility = View.VISIBLE + binding?.nameView?.text = it.name + } - val dateFormat = getString(R.string.profile_date_format) - binding!!.createdView.text = DateFormat.format(dateFormat, it.created_at) - binding!!.updatedView.text = DateFormat.format(dateFormat, it.updated_at) + binding!!.loginView.text = getString(R.string.login_string, it.login) - binding!!.followersView.text = it.followers.toString() + binding!!.idView.text = it.id.toString() - // This field can be empty - if (it.location.isEmpty()) { - binding!!.locationContainer.visibility = View.GONE - } else { - binding!!.locationContainer.visibility = View.VISIBLE - binding!!.locationView.text = it.location - } + val dateFormat = getString(R.string.profile_date_format) + binding!!.createdView.text = DateFormat.format(dateFormat, it.created_at) + binding!!.updatedView.text = DateFormat.format(dateFormat, it.updated_at) - binding!!.totalReposView.text = it.total_repos_count.toString() - binding!!.privateReposView.text = it.private_repos_count.toString() - binding!!.publicReposView.text = it.public_repos_count.toString() + binding!!.followersView.text = it.followers.toString() + // This field can be empty + if (it.location.isEmpty()) { + binding!!.locationContainer.visibility = View.GONE + } else { + binding!!.locationContainer.visibility = View.VISIBLE + binding!!.locationView.text = it.location } + + binding!!.totalReposView.text = it.total_repos_count.toString() + binding!!.privateReposView.text = it.private_repos_count.toString() + binding!!.publicReposView.text = it.public_repos_count.toString() }) binding!!.reposStatDetailedBtn.setOnClickListener { diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ActiveRepositoriesFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ActiveRepositoriesFragment.kt index 8fb94aa1..e2722100 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ActiveRepositoriesFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ActiveRepositoriesFragment.kt @@ -12,6 +12,7 @@ import by.alexandr7035.gitstat.R import by.alexandr7035.gitstat.RepositoriesListGraphDirections import by.alexandr7035.gitstat.databinding.FragmentRepositoriesRecyclerBinding import by.alexandr7035.gitstat.core.extensions.navigateSafe +import by.alexandr7035.gitstat.core.extensions.observeNullSafe import by.alexandr7035.gitstat.view.repositories.filters.RepositoriesListFiltersHelper import dagger.hilt.android.AndroidEntryPoint @@ -36,7 +37,7 @@ class ActiveRepositoriesFragment : Fragment(), RepoClickListener { binding!!.recycler.adapter = adapter binding!!.recycler.layoutManager = LinearLayoutManager(context) - viewModel.getTabRefreshedLiveData().observe(viewLifecycleOwner, { + viewModel.getTabRefreshedLiveData().observeNullSafe(viewLifecycleOwner, { // If current fragment // FIXME find better solution if (it == 0) { @@ -49,7 +50,7 @@ class ActiveRepositoriesFragment : Fragment(), RepoClickListener { override fun onResume() { super.onResume() - viewModel.getActiveRepositoriesLiveData().observe(viewLifecycleOwner, { repos -> + viewModel.getActiveRepositoriesLiveData().observeNullSafe(viewLifecycleOwner, { repos -> val filteredList = RepositoriesListFiltersHelper.getFilteredRepositoriesList( repos, viewModel.getRepositoriesFilters() diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ArchivedRepositoriesFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ArchivedRepositoriesFragment.kt index 00793e5f..762b614f 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ArchivedRepositoriesFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ArchivedRepositoriesFragment.kt @@ -12,6 +12,7 @@ import by.alexandr7035.gitstat.R import by.alexandr7035.gitstat.RepositoriesListGraphDirections import by.alexandr7035.gitstat.databinding.FragmentRepositoriesRecyclerBinding import by.alexandr7035.gitstat.core.extensions.navigateSafe +import by.alexandr7035.gitstat.core.extensions.observeNullSafe import by.alexandr7035.gitstat.view.repositories.filters.RepositoriesListFiltersHelper import dagger.hilt.android.AndroidEntryPoint @@ -37,7 +38,7 @@ class ArchivedRepositoriesFragment : Fragment(), RepoClickListener { binding!!.recycler.adapter = adapter binding!!.recycler.layoutManager = LinearLayoutManager(context) - viewModel.getTabRefreshedLiveData().observe(viewLifecycleOwner, { + viewModel.getTabRefreshedLiveData().observeNullSafe(viewLifecycleOwner, { // If current fragment // FIXME find better solution if (it == 1) { @@ -50,7 +51,7 @@ class ArchivedRepositoriesFragment : Fragment(), RepoClickListener { override fun onResume() { super.onResume() - viewModel.getArchivedRepositoriesLiveData().observe(viewLifecycleOwner, { repos -> + viewModel.getArchivedRepositoriesLiveData().observeNullSafe(viewLifecycleOwner, { repos -> val filteredList = RepositoriesListFiltersHelper.getFilteredRepositoriesList( repos, viewModel.getRepositoriesFilters() diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ReposOverviewFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ReposOverviewFragment.kt index 76bd19e9..84b29e81 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ReposOverviewFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/repositories/ReposOverviewFragment.kt @@ -9,6 +9,7 @@ import androidx.fragment.app.viewModels import androidx.navigation.fragment.findNavController import by.alexandr7035.gitstat.databinding.FragmentReposOverviewBinding import by.alexandr7035.gitstat.core.extensions.navigateSafe +import by.alexandr7035.gitstat.core.extensions.observeNullSafe import by.alexandr7035.gitstat.view.MainActivity import by.alexandr7035.gitstat.view.repositories.plots.languages_plot.LanguagesPlot import dagger.hilt.android.AndroidEntryPoint @@ -35,32 +36,28 @@ class ReposOverviewFragment : Fragment() { plot.setupPlot(binding!!.languagesChart) } - viewModel.getRepositoriesLiveData().observe(viewLifecycleOwner, { repos -> + viewModel.getRepositoriesLiveData().observeNullSafe(viewLifecycleOwner, { repos -> - if (repos != null) { + Timber.tag("DEBUG_TAG").d("repos $repos") - Timber.tag("DEBUG_TAG").d("repos $repos") + binding!!.totalReposCountView.text = repos.size.toString() + binding!!.privateReposCountView.text = repos.filter { it.isPrivate }.size.toString() + binding!!.publicReposCountView.text = repos.filter { !it.isPrivate }.size.toString() - binding!!.totalReposCountView.text = repos.size.toString() - binding!!.privateReposCountView.text = repos.filter { it.isPrivate }.size.toString() - binding!!.publicReposCountView.text = repos.filter { !it.isPrivate }.size.toString() + // Show stup instead of plot if list is empty + if (repos.isNullOrEmpty()) { + binding?.languagesChart?.visibility = View.GONE + binding?.noReposStub?.visibility = View.VISIBLE + } else { + binding?.languagesChart?.visibility = View.VISIBLE + binding?.noReposStub?.visibility = View.GONE - // Show stup instead of plot if list is empty - if (repos.isNullOrEmpty()) { - binding?.languagesChart?.visibility = View.GONE - binding?.noReposStub?.visibility = View.VISIBLE - } else { - binding?.languagesChart?.visibility = View.VISIBLE - binding?.noReposStub?.visibility = View.GONE - - // Populate chart with data - plot.setLanguagesData( - chart = binding!!.languagesChart, - languages = viewModel.getLanguagesForReposList(repos), - totalReposCount = repos.size - ) - - } + // Populate chart with data + plot.setLanguagesData( + chart = binding!!.languagesChart, + languages = viewModel.getLanguagesForReposList(repos), + totalReposCount = repos.size + ) } }) diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/repositories/RepositoriesListHostFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/repositories/RepositoriesListHostFragment.kt index c5c76886..5af8146f 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/repositories/RepositoriesListHostFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/repositories/RepositoriesListHostFragment.kt @@ -12,6 +12,7 @@ import androidx.navigation.navGraphViewModels import by.alexandr7035.gitstat.R import by.alexandr7035.gitstat.databinding.FragmentHostRepositoriesListBinding import by.alexandr7035.gitstat.core.extensions.navigateSafe +import by.alexandr7035.gitstat.core.extensions.observeNullSafe import com.google.android.material.badge.BadgeDrawable import com.google.android.material.badge.BadgeUtils import com.google.android.material.tabs.TabLayout @@ -83,17 +84,17 @@ class RepositoriesListHostFragment : Fragment() { BadgeUtils.attachBadgeDrawable(badge, binding!!.toolbar, R.id.item_filters) // Update counters in the tabs - viewModel.getActiveRepositoriesLiveData().observe(viewLifecycleOwner, { + viewModel.getActiveRepositoriesLiveData().observeNullSafe(viewLifecycleOwner, { val repos = viewModel.getFilteredRepositoriesList(it) (binding!!.tabLayout.getTabAt(0) as TabLayout.Tab).text = "Active (${repos.size})" }) - viewModel.getArchivedRepositoriesLiveData().observe(viewLifecycleOwner, { + viewModel.getArchivedRepositoriesLiveData().observeNullSafe(viewLifecycleOwner, { val repos = viewModel.getFilteredRepositoriesList(it) (binding!!.tabLayout.getTabAt(1) as TabLayout.Tab).text = "Archived (${repos.size})" }) - viewModel.getAllRepositoriesListLiveData().observe(viewLifecycleOwner, { unfilteredRepos -> + viewModel.getAllRepositoriesListLiveData().observeNullSafe(viewLifecycleOwner, { unfilteredRepos -> val filteredRepos = viewModel.getFilteredRepositoriesList(unfilteredRepos) diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/repositories/RepositoryPageFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/repositories/RepositoryPageFragment.kt index 0279d235..f9c4f194 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/repositories/RepositoryPageFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/repositories/RepositoryPageFragment.kt @@ -20,6 +20,7 @@ import by.alexandr7035.gitstat.databinding.FragmentRepositoryPageBinding import by.alexandr7035.gitstat.core.extensions.debug import by.alexandr7035.gitstat.core.extensions.getClickableSpannable import by.alexandr7035.gitstat.core.extensions.getStringDateFromLong +import by.alexandr7035.gitstat.core.extensions.observeNullSafe import com.google.android.flexbox.FlexboxLayoutManager import dagger.hilt.android.AndroidEntryPoint import timber.log.Timber @@ -44,122 +45,116 @@ class RepositoryPageFragment : Fragment() { findNavController().navigateUp() } - viewModel.getRepositoryLiveData(safeArgs.repositoryId).observe(viewLifecycleOwner, { repoData -> - - if (repoData != null) { - - Timber.debug("repo page ${repoData.description}") + viewModel.getRepositoryLiveData(safeArgs.repositoryId).observeNullSafe(viewLifecycleOwner, { repoData -> + binding?.toolbar?.title = repoData.name + binding?.repoName?.text = repoData.nameWithOwner + binding?.language?.text = repoData.primaryLanguage + binding?.stars?.text = repoData.stars.toString() + + binding?.repoDescription?.text = repoData.description + + // Set parent (if fork) + if (repoData.isFork) { + binding?.parentName?.text = HtmlCompat.fromHtml( + getString(R.string.forked_from_template, repoData.parentNameWithOwner), + HtmlCompat.FROM_HTML_MODE_LEGACY + ) + } else { + binding?.parentName?.visibility = View.GONE + } - binding?.toolbar?.title = repoData.name - binding?.repoName?.text = repoData.nameWithOwner - binding?.language?.text = repoData.primaryLanguage - binding?.stars?.text = repoData.stars.toString() + // Set website link if exists + if (repoData.websiteUrl != "") { - binding?.repoDescription?.text = repoData.description + // Make link clickable + val urlText = repoData.websiteUrl - // Set parent (if fork) - if (repoData.isFork) { - binding?.parentName?.text = HtmlCompat.fromHtml( - getString(R.string.forked_from_template, repoData.parentNameWithOwner), - HtmlCompat.FROM_HTML_MODE_LEGACY - ) - } else { - binding?.parentName?.visibility = View.GONE + val clickListener = View.OnClickListener { + Timber.debug("click link") + val webpage: Uri = Uri.parse(urlText) + val intent = Intent(Intent.ACTION_VIEW, webpage) + startActivity(intent) } - // Set website link if exists - if (repoData.websiteUrl != "") { - - // Make link clickable - val urlText = repoData.websiteUrl - - val clickListener = View.OnClickListener { - Timber.debug("click link") - val webpage: Uri = Uri.parse(urlText) - val intent = Intent(Intent.ACTION_VIEW, webpage) - startActivity(intent) - } + val spannableUrl = urlText.getClickableSpannable( + clickListener = clickListener, + clickableText = urlText, + isBold = false, + spannableColor = ContextCompat.getColor(requireContext(), R.color.blue_500) + ) - val spannableUrl = urlText.getClickableSpannable( - clickListener = clickListener, - clickableText = urlText, - isBold = false, - spannableColor = ContextCompat.getColor(requireContext(), R.color.blue_500) - ) - - binding?.websiteUrl?.text = spannableUrl - - binding?.websiteUrl?.apply { - movementMethod = LinkMovementMethod.getInstance() - highlightColor = Color.TRANSPARENT - } + binding?.websiteUrl?.text = spannableUrl - } else { - binding?.websiteUrl?.visibility = View.GONE + binding?.websiteUrl?.apply { + movementMethod = LinkMovementMethod.getInstance() + highlightColor = Color.TRANSPARENT } - // Change mark color depending on repo private/public - when (repoData.isPrivate) { - true -> { - binding?.repoVisibility?.text = getString(R.string.private_start_capital) - binding?.repoVisibility?.setTextColor( - ContextCompat.getColor( - requireContext(), - R.color.white - ) - ) + } else { + binding?.websiteUrl?.visibility = View.GONE + } - binding?.repoVisibility?.background = ContextCompat.getDrawable( + // Change mark color depending on repo private/public + when (repoData.isPrivate) { + true -> { + binding?.repoVisibility?.text = getString(R.string.private_start_capital) + binding?.repoVisibility?.setTextColor( + ContextCompat.getColor( requireContext(), - R.drawable.background_repo_visibilily_private - ) - } - else -> { - binding?.repoVisibility?.text = getString(R.string.public_start_capital) - binding?.repoVisibility?.setTextColor( - ContextCompat.getColor( - requireContext(), - R.color.black - ) + R.color.white ) - binding?.repoVisibility?.background = ContextCompat.getDrawable( + ) + + binding?.repoVisibility?.background = ContextCompat.getDrawable( + requireContext(), + R.drawable.background_repo_visibilily_private + ) + } + else -> { + binding?.repoVisibility?.text = getString(R.string.public_start_capital) + binding?.repoVisibility?.setTextColor( + ContextCompat.getColor( requireContext(), - R.drawable.background_repo_visibilily + R.color.black ) - } + ) + binding?.repoVisibility?.background = ContextCompat.getDrawable( + requireContext(), + R.drawable.background_repo_visibilily + ) } + } - (binding?.languageColorView?.background as GradientDrawable?)?.setColor(Color.parseColor(repoData.primaryLanguageColor)) + (binding?.languageColorView?.background as GradientDrawable?)?.setColor(Color.parseColor(repoData.primaryLanguageColor)) - // Setup topics recycler - val topicsAdapter = RepoTopicsAdapter() - binding?.topicsRecycler?.layoutManager = FlexboxLayoutManager(requireContext()) - binding?.topicsRecycler?.adapter = topicsAdapter - topicsAdapter.setItems(repoData.topics) + // Setup topics recycler + val topicsAdapter = RepoTopicsAdapter() + binding?.topicsRecycler?.layoutManager = FlexboxLayoutManager(requireContext()) + binding?.topicsRecycler?.adapter = topicsAdapter + topicsAdapter.setItems(repoData.topics) - binding?.createdAt?.text = repoData.created_at.getStringDateFromLong("dd.MM.yyyy HH:mm") - binding?.updatedAt?.text = repoData.updated_at.getStringDateFromLong("dd.MM.yyyy HH:mm") - binding?.repoSize?.text = getString(R.string.disk_usage_template, repoData.diskUsageKB) + binding?.createdAt?.text = repoData.created_at.getStringDateFromLong("dd.MM.yyyy HH:mm") + binding?.updatedAt?.text = repoData.updated_at.getStringDateFromLong("dd.MM.yyyy HH:mm") + binding?.repoSize?.text = getString(R.string.disk_usage_template, repoData.diskUsageKB) - // Setup languages bar - val langValues = ArrayList() - val langColors = ArrayList() + // Setup languages bar + val langValues = ArrayList() + val langColors = ArrayList() - repoData.languages.forEach { repoLanguage -> - langValues.add(repoLanguage.size.toFloat()) - langColors.add(Color.parseColor(repoLanguage.color)) - } + repoData.languages.forEach { repoLanguage -> + langValues.add(repoLanguage.size.toFloat()) + langColors.add(Color.parseColor(repoLanguage.color)) + } - binding?.languagesBar?.setValues(langValues, langColors) - binding?.languagesBar?.invalidate() + binding?.languagesBar?.setValues(langValues, langColors) + binding?.languagesBar?.invalidate() - // Setup legend for languages bar (recycler) - val languagesAdapter = RepoLanguagesAdapter() - binding?.languagesRecycler?.layoutManager = FlexboxLayoutManager(requireContext()) - binding?.languagesRecycler?.adapter = languagesAdapter - languagesAdapter.setItems(repoData.languages) - } + // Setup legend for languages bar (recycler) + val languagesAdapter = RepoLanguagesAdapter() + binding?.languagesRecycler?.layoutManager = FlexboxLayoutManager(requireContext()) + binding?.languagesRecycler?.adapter = languagesAdapter + languagesAdapter.setItems(repoData.languages) }) } @@ -167,5 +162,4 @@ class RepositoryPageFragment : Fragment() { super.onDestroyView() binding = null } - } \ No newline at end of file diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/repositories/filters/RepositoriesFiltersDialog.kt b/app/src/main/java/by/alexandr7035/gitstat/view/repositories/filters/RepositoriesFiltersDialog.kt index 4c5364a8..2dfd8768 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/repositories/filters/RepositoriesFiltersDialog.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/repositories/filters/RepositoriesFiltersDialog.kt @@ -6,6 +6,7 @@ import android.view.View import android.view.ViewGroup import androidx.navigation.navGraphViewModels import by.alexandr7035.gitstat.R +import by.alexandr7035.gitstat.core.extensions.observeNullSafe import by.alexandr7035.gitstat.databinding.FiltersDialogBinding import by.alexandr7035.gitstat.view.repositories.RepositoriesViewModel import com.google.android.flexbox.FlexboxLayoutManager @@ -53,7 +54,7 @@ class RepositoriesFiltersDialog : BottomSheetDialogFragment() { // FIXME // Now build langs list depending on ALL the repos of a user // Create different filters for active/archived later - viewModel.getAllRepositoriesListLiveData().observe(viewLifecycleOwner, { repos -> + viewModel.getAllRepositoriesListLiveData().observeNullSafe(viewLifecycleOwner, { repos -> adapter.setItems(viewModel.getLanguagesForReposList(repos)) }) From addba791d1b57807a4dd44714d706dd598a4eb8b Mon Sep 17 00:00:00 2001 From: Alexandr Alexeenko Date: Sun, 12 Dec 2021 20:34:32 +0300 Subject: [PATCH 05/13] Fix crash when cache updates on contribution grid fragment Closes #200 --- .../java/by/alexandr7035/gitstat/data/DataSyncRepository.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/by/alexandr7035/gitstat/data/DataSyncRepository.kt b/app/src/main/java/by/alexandr7035/gitstat/data/DataSyncRepository.kt index 179efeac..4f92b3e5 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/data/DataSyncRepository.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/data/DataSyncRepository.kt @@ -67,13 +67,13 @@ class DataSyncRepository @Inject constructor( // NOTE! DO NOT CHANGE ORDER // LIVEDATA TRIGGERED IMMEDIATELY AFTER SAVING CACHE // AS ONE DATA MAY DEPEND ON THE OTHER, WRONG ORDER MAY CAUSE CRASH - // Years and months must be at the end + // Order must be: days -> months -> years db.getContributionsDao().apply { insertContributionRatesCache(contributionRates) insertContributionDays(contributionDays) insertContributionTypes(contributionTypes) - insertContributionYearsCache(contributionYears) insertContributionMonthsCache(contributionMonths) + insertContributionYearsCache(contributionYears) } syncStatusLiveData?.postValue(DataSyncStatus.SUCCESS) From cdb1219c59a97117afcf493c81ea2ae94c18eb60 Mon Sep 17 00:00:00 2001 From: Alexandr Alexeenko Date: Sun, 12 Dec 2021 21:06:28 +0300 Subject: [PATCH 06/13] Add YearlyMetricsHelper in order to segregate business logic --- .../gitstat/data/ContributionsRepository.kt | 32 ++----------- .../data/helpers/YearlyMetricsHelper.kt | 47 +++++++++++++++++++ .../by/alexandr7035/gitstat/di/AppModule.kt | 12 +++-- 3 files changed, 60 insertions(+), 31 deletions(-) create mode 100644 app/src/main/java/by/alexandr7035/gitstat/data/helpers/YearlyMetricsHelper.kt diff --git a/app/src/main/java/by/alexandr7035/gitstat/data/ContributionsRepository.kt b/app/src/main/java/by/alexandr7035/gitstat/data/ContributionsRepository.kt index 2d9fc033..c7ba8d9d 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/data/ContributionsRepository.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/data/ContributionsRepository.kt @@ -1,18 +1,15 @@ package by.alexandr7035.gitstat.data import androidx.lifecycle.LiveData -import by.alexandr7035.gitstat.core.KeyValueStorage -import by.alexandr7035.gitstat.core.TimeHelper +import by.alexandr7035.gitstat.data.helpers.YearlyMetricsHelper import by.alexandr7035.gitstat.data.local.dao.ContributionsDao import by.alexandr7035.gitstat.data.local.model.* import javax.inject.Inject -import kotlin.math.round class ContributionsRepository @Inject constructor( private val dao: ContributionsDao, - private val timeHelper: TimeHelper, - private val keyValueStorage: KeyValueStorage + private val yearlyMetricsHelper: YearlyMetricsHelper ) { fun getAllContributionsLiveData(): LiveData> { @@ -39,32 +36,11 @@ class ContributionsRepository @Inject constructor( // Simply calculate for previous years // For the current year need to detect last contribution year fun getLastTotalContributionRateForYear(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 - } + return yearlyMetricsHelper.getAnnualContributionRate(yearData) } fun getContributionRateForYear(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 - } + return yearlyMetricsHelper.getEndingTotalContributionRate(yearData) } fun getMaxContributionRateForYear(yearData: ContributionsYearWithRates): Float { diff --git a/app/src/main/java/by/alexandr7035/gitstat/data/helpers/YearlyMetricsHelper.kt b/app/src/main/java/by/alexandr7035/gitstat/data/helpers/YearlyMetricsHelper.kt new file mode 100644 index 00000000..d9731bbc --- /dev/null +++ b/app/src/main/java/by/alexandr7035/gitstat/data/helpers/YearlyMetricsHelper.kt @@ -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 + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/by/alexandr7035/gitstat/di/AppModule.kt b/app/src/main/java/by/alexandr7035/gitstat/di/AppModule.kt index c9267295..c1c7b974 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/di/AppModule.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/di/AppModule.kt @@ -5,6 +5,7 @@ import androidx.room.Room import by.alexandr7035.gitstat.core.KeyValueStorage import by.alexandr7035.gitstat.core.TimeHelper import by.alexandr7035.gitstat.data.* +import by.alexandr7035.gitstat.data.helpers.YearlyMetricsHelper import by.alexandr7035.gitstat.data.local.CacheDB import by.alexandr7035.gitstat.data.local.RoomTypeConverters import by.alexandr7035.gitstat.data.local.dao.ContributionsDao @@ -65,10 +66,9 @@ object AppModule { @Singleton fun provideContributionsRepository( dao: ContributionsDao, - timeHelper: TimeHelper, - keyValueStorage: KeyValueStorage + yearlyMetricsHelper: YearlyMetricsHelper ): ContributionsRepository{ - return ContributionsRepository(dao, timeHelper, keyValueStorage) + return ContributionsRepository(dao, yearlyMetricsHelper) } @@ -175,4 +175,10 @@ object AppModule { fun provideTimeHelper(): TimeHelper { return TimeHelper() } + + @Provides + @Singleton + fun provideYearlyMetricsHelper(keyValueStorage: KeyValueStorage, timeHelper: TimeHelper): YearlyMetricsHelper { + return YearlyMetricsHelper.Impl(timeHelper, keyValueStorage) + } } \ No newline at end of file From 74d8d43064f9b0fc4bee036e543f28a0a34dacc5 Mon Sep 17 00:00:00 2001 From: Alexandr Alexeenko Date: Sun, 12 Dec 2021 22:43:44 +0300 Subject: [PATCH 07/13] Add custom CollapsingTextView --- .../gitstat/core/view/CollapsingTextView.kt | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 app/src/main/java/by/alexandr7035/gitstat/core/view/CollapsingTextView.kt diff --git a/app/src/main/java/by/alexandr7035/gitstat/core/view/CollapsingTextView.kt b/app/src/main/java/by/alexandr7035/gitstat/core/view/CollapsingTextView.kt new file mode 100644 index 00000000..60293310 --- /dev/null +++ b/app/src/main/java/by/alexandr7035/gitstat/core/view/CollapsingTextView.kt @@ -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 + } + } +} \ No newline at end of file From 229aa278ace7cb904e978214a91f4ce137f18f33 Mon Sep 17 00:00:00 2001 From: Alexandr Alexeenko Date: Sun, 12 Dec 2021 22:44:16 +0300 Subject: [PATCH 08/13] Use collapsing textview for repo description Closes #205 --- .../res/drawable/background_clickable_text.xml | 18 ++++++++++++++++++ .../res/layout/fragment_repository_page.xml | 4 +++- app/src/main/res/values/dimens.xml | 4 ++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/drawable/background_clickable_text.xml create mode 100644 app/src/main/res/values/dimens.xml diff --git a/app/src/main/res/drawable/background_clickable_text.xml b/app/src/main/res/drawable/background_clickable_text.xml new file mode 100644 index 00000000..352c3610 --- /dev/null +++ b/app/src/main/res/drawable/background_clickable_text.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_repository_page.xml b/app/src/main/res/layout/fragment_repository_page.xml index 769173c8..ab749b0f 100644 --- a/app/src/main/res/layout/fragment_repository_page.xml +++ b/app/src/main/res/layout/fragment_repository_page.xml @@ -80,8 +80,10 @@ tools:text="Forked from alexandr7035/GitStt" /> - + + 4dp + \ No newline at end of file From f8bd5a90798f954aa55ea112f998676d70b6f552 Mon Sep 17 00:00:00 2001 From: Alexandr Alexeenko Date: Sun, 12 Dec 2021 22:52:50 +0300 Subject: [PATCH 09/13] Remove unused constraint --- app/src/main/res/layout/fragment_repository_page.xml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/src/main/res/layout/fragment_repository_page.xml b/app/src/main/res/layout/fragment_repository_page.xml index ab749b0f..eafe91a4 100644 --- a/app/src/main/res/layout/fragment_repository_page.xml +++ b/app/src/main/res/layout/fragment_repository_page.xml @@ -82,20 +82,18 @@ From 67e519a66e8aadc3311f931ec724a0efdf41cdef Mon Sep 17 00:00:00 2001 From: Alexandr Alexeenko Date: Sun, 12 Dec 2021 23:02:59 +0300 Subject: [PATCH 10/13] Simplify view hierarchy on profile fragment header Related #25 --- app/src/main/res/layout/fragment_profile.xml | 78 +++++++++----------- 1 file changed, 34 insertions(+), 44 deletions(-) diff --git a/app/src/main/res/layout/fragment_profile.xml b/app/src/main/res/layout/fragment_profile.xml index efe8b1b7..9a41bc39 100644 --- a/app/src/main/res/layout/fragment_profile.xml +++ b/app/src/main/res/layout/fragment_profile.xml @@ -133,7 +133,7 @@ - - + + - - - - - - - - - - - - + app:layout_constraintStart_toEndOf="@id/profileImageView" + app:layout_constraintTop_toTopOf="@id/profileImageView" + app:layout_constraintBottom_toTopOf="@id/loginView" + tools:text="Name Name" /> + + - + Date: Mon, 13 Dec 2021 16:32:48 +0300 Subject: [PATCH 11/13] Simplify view hierarchy on profile fragment Related #25 --- .../gitstat/view/profile/ProfileFragment.kt | 15 +- app/src/main/res/layout/fragment_profile.xml | 551 +++++++++--------- app/src/main/res/values/dimens.xml | 3 + 3 files changed, 289 insertions(+), 280 deletions(-) diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/profile/ProfileFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/profile/ProfileFragment.kt index 775b06fb..75c4a9c6 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/profile/ProfileFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/profile/ProfileFragment.kt @@ -5,17 +5,17 @@ import android.text.format.DateFormat import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.core.view.isGone import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels import androidx.navigation.fragment.findNavController import by.alexandr7035.gitstat.R -import by.alexandr7035.gitstat.databinding.FragmentProfileBinding import by.alexandr7035.gitstat.core.extensions.navigateSafe import by.alexandr7035.gitstat.core.extensions.observeNullSafe +import by.alexandr7035.gitstat.databinding.FragmentProfileBinding import by.alexandr7035.gitstat.view.MainActivity import com.squareup.picasso.Picasso import dagger.hilt.android.AndroidEntryPoint -import timber.log.Timber @AndroidEntryPoint @@ -37,8 +37,6 @@ class ProfileFragment : Fragment() { // Update profile data viewModel.getUserLiveData().observeNullSafe(viewLifecycleOwner, { - Timber.tag("DEBUG_TAG").d("livedata updated $it") - Picasso.get().load(it.avatar_url).into(binding!!.profileImageView) // This field can be empty @@ -61,9 +59,9 @@ class ProfileFragment : Fragment() { // This field can be empty if (it.location.isEmpty()) { - binding!!.locationContainer.visibility = View.GONE + setLocationVisibility(false) } else { - binding!!.locationContainer.visibility = View.VISIBLE + setLocationVisibility(true) binding!!.locationView.text = it.location } @@ -82,6 +80,11 @@ class ProfileFragment : Fragment() { } + private fun setLocationVisibility(isVisible: Boolean) { + binding?.locationIcon?.isGone = ! isVisible + binding?.locationLabel?.isGone = ! isVisible + binding?.locationView?.isGone = ! isVisible + } override fun onDestroyView() { super.onDestroyView() diff --git a/app/src/main/res/layout/fragment_profile.xml b/app/src/main/res/layout/fragment_profile.xml index 9a41bc39..0707271f 100644 --- a/app/src/main/res/layout/fragment_profile.xml +++ b/app/src/main/res/layout/fragment_profile.xml @@ -1,7 +1,7 @@ - - + app:layout_constraintTop_toBottomOf="@id/profileSummaryCard"> + - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - + android:layout_marginStart="@dimen/profile_card_field_margin" + app:layout_constraintBottom_toBottomOf="@+id/privateReposLabel" + app:layout_constraintStart_toEndOf="@+id/privateReposLabel" + app:layout_constraintTop_toTopOf="@+id/privateReposLabel" + tools:text="15" /> + + + app:layout_constraintTop_toTopOf="parent" /> - + app:layout_constraintTop_toBottomOf="@id/headerCard"> + + + - - - - - - - - - - - + + - - - - - - - - - - + + + + + - - - - - - - - - - + + - - - - - - - - - - + + + + + + android:layout_marginStart="@dimen/profile_card_label_margin" + android:layout_marginTop="@dimen/profile_fields_vertical_spacing" + android:text="@string/updated" + android:textStyle="bold" + app:layout_constraintStart_toEndOf="@id/updatedDateIcon" + app:layout_constraintTop_toBottomOf="@id/creationDateLabel" /> - + + + - + - + + + - + + - + + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="@id/fragmentTitle" /> + app:layout_constraintTop_toTopOf="parent" /> diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 98107982..541d1a3f 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,4 +1,7 @@ 4dp + 16dp + 8dp + 4dp \ No newline at end of file From baa26a961d91a96e2fc34c8f83d23734e287499e Mon Sep 17 00:00:00 2001 From: Alexandr Alexeenko Date: Mon, 13 Dec 2021 16:57:41 +0300 Subject: [PATCH 12/13] Update app version --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8776a76f..4f2bc85a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,8 +32,8 @@ android { applicationId 'by.alexandr7035.gitstat' minSdkVersion 21 targetSdkVersion 31 - versionCode 2100 - versionName "5.3" + versionCode 2200 + versionName "5.4" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } From 876d5b2b2bdda6cf1fe5d58e16cf855d6a0541fc Mon Sep 17 00:00:00 2001 From: Alexandr Alexeenko Date: Mon, 13 Dec 2021 17:41:03 +0300 Subject: [PATCH 13/13] Fix issue with contribution types bar Do not include zero values Closes 207 --- .../gitstat/view/contributions/ContributionsFragment.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/contributions/ContributionsFragment.kt b/app/src/main/java/by/alexandr7035/gitstat/view/contributions/ContributionsFragment.kt index ad73f691..e10942ce 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/contributions/ContributionsFragment.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/contributions/ContributionsFragment.kt @@ -113,8 +113,10 @@ class ContributionsFragment : Fragment() { val colors = ArrayList() for (type in types) { - colors.add(type.color) - values.add(type.count.toFloat()) + if (type.count > 0) { + colors.add(type.color) + values.add(type.count.toFloat()) + } } binding?.typesRatioView?.setValues(values, colors)