From a341a5a66b4cdbcbde60a99b994e57d6e77f4969 Mon Sep 17 00:00:00 2001 From: Rodion Sviridov Date: Sat, 28 Aug 2021 18:44:31 +0300 Subject: [PATCH] Term start fixed Gradle dependencies updated --- app/app/build.gradle | 23 +++++++++---------- .../mss/viewmodels/ScheduleViewModel.kt | 22 +++++++++++++----- app/build.gradle | 2 +- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/app/app/build.gradle b/app/app/build.gradle index d7c6c73..dc5d18b 100644 --- a/app/app/build.gradle +++ b/app/app/build.gradle @@ -44,19 +44,18 @@ android { } dependencies { - - implementation "org.jetbrains.kotlin:kotlin-stdlib:1.5.0" - implementation 'androidx.core:core-ktx:1.5.0' - implementation 'androidx.appcompat:appcompat:1.3.0' - implementation 'com.google.android.material:material:1.3.0' - implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation "org.jetbrains.kotlin:kotlin-stdlib:1.5.10" + implementation 'androidx.core:core-ktx:1.6.0' + implementation 'androidx.appcompat:appcompat:1.3.1' + implementation 'com.google.android.material:material:1.4.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' testImplementation 'junit:junit:4.13.2' - androidTestImplementation 'androidx.test.ext:junit:1.1.2' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' // Material Components - implementation 'com.google.android.material:material:1.4.0-rc01' + implementation 'com.google.android.material:material:1.5.0-alpha02' // Navigation Component implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5' @@ -70,7 +69,7 @@ dependencies { // Data binding kapt "com.android.databinding:compiler:3.2.0-alpha10" - kapt "androidx.databinding:databinding-common:4.2.1" + kapt "androidx.databinding:databinding-common:7.0.1" // Recyclerview implementation 'androidx.recyclerview:recyclerview:1.2.1' @@ -88,8 +87,8 @@ dependencies { kapt "androidx.hilt:hilt-compiler:1.0.0" // Coroutines - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' // Lifecycle implementation "androidx.lifecycle:lifecycle-extensions:2.2.0" diff --git a/app/app/src/main/java/com/rodyapal/mss/viewmodels/ScheduleViewModel.kt b/app/app/src/main/java/com/rodyapal/mss/viewmodels/ScheduleViewModel.kt index 33a72f9..afd0a87 100644 --- a/app/app/src/main/java/com/rodyapal/mss/viewmodels/ScheduleViewModel.kt +++ b/app/app/src/main/java/com/rodyapal/mss/viewmodels/ScheduleViewModel.kt @@ -20,6 +20,16 @@ class ScheduleViewModel @Inject constructor( application: Application ) : AndroidViewModel(application) { + private val currentTimeInMillis get() = Calendar.getInstance().timeInMillis + + private val firstTermStartInMillis = Calendar.getInstance().apply { + set(Calendar.getInstance().get(Calendar.YEAR), 9, 1, 0, 0) + }.timeInMillis + + private val secondTermStartInMillis = Calendar.getInstance().apply { + set(Calendar.getInstance().get(Calendar.YEAR), 1, 8, 0, 0) + }.timeInMillis + private val DEBUG_TAG = "SCHEDULE_VIEW_MODEL_DEBUG" private val _group: MutableLiveData = MutableLiveData() @@ -40,14 +50,14 @@ class ScheduleViewModel @Inject constructor( } fun getCurrentWeekFromTermStart(): Int = - ((Calendar.getInstance().timeInMillis - Calendar.getInstance().apply { - set(2021, 1, 8, 0, 0) - }.timeInMillis) / (7 * 24 * 3600000)).toInt() + 1 + ((currentTimeInMillis - getTermStart()) / (7 * 24 * 3600000)).toInt() + 1 fun getCurrentDay(): Int = - ((Calendar.getInstance().timeInMillis - Calendar.getInstance().apply { - set(2021, 1, 8, 0, 0) - }.timeInMillis) / (24 * 3600000) % 7).toInt() - 1 + ((currentTimeInMillis - getTermStart()) / (24 * 3600000) % 7).toInt() - 1 + + fun getTermStart(): Long = + if (currentTimeInMillis < secondTermStartInMillis) firstTermStartInMillis + else secondTermStartInMillis /** * @return list of lessons for day based on current week (even or odd) diff --git a/app/build.gradle b/app/build.gradle index 0e6983f..4f01060 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,7 +5,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.2.1' + classpath 'com.android.tools.build:gradle:7.0.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.0" classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5" classpath "com.google.dagger:hilt-android-gradle-plugin:2.28-alpha"