Skip to content

Commit

Permalink
Merge pull request #120 from serguun42/app
Browse files Browse the repository at this point in the history
Term start fixed for app
  • Loading branch information
serguun42 authored Aug 28, 2021
2 parents 9ac8277 + a341a5a commit 248fc80
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
23 changes: 11 additions & 12 deletions app/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Group> = MutableLiveData()
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 248fc80

Please sign in to comment.