From c1cf8d724f7646f438acd89b1d1b3b3e7bd94133 Mon Sep 17 00:00:00 2001 From: William Brawner Date: Wed, 22 Jul 2020 19:04:11 -0700 Subject: [PATCH] Move shared code to new gradle module --- .idea/gradle.xml | 1 + app/build.gradle | 10 +-- app/src/main/AndroidManifest.xml | 13 ---- .../wbrawner/trainterval/DurationPicker.kt | 9 ++- .../trainterval/TraintervalApplication.kt | 1 + .../activetimer/ActiveTimerFragment.kt | 13 ++-- .../activetimer/ActiveTimerViewModel.kt | 57 +++--------------- .../timerform/TimerFormFragment.kt | 2 +- .../timerform/TimerFormViewModel.kt | 4 +- .../trainterval/timerlist/TimerListAdapter.kt | 4 +- .../timerlist/TimerListFragment.kt | 2 +- .../timerlist/TimerListViewModel.kt | 4 +- app/src/main/res/values/strings.xml | 6 -- build.gradle | 4 +- settings.gradle | 1 + shared/.gitignore | 1 + shared/build.gradle | 43 +++++++++++++ shared/consumer-rules.pro | 0 shared/proguard-rules.pro | 21 +++++++ shared/src/main/AndroidManifest.xml | 4 ++ .../src/main/assets/audio/cool.mp3 | Bin .../src/main/assets/audio/high.mp3 | Bin {app => shared}/src/main/assets/audio/low.mp3 | Bin .../src/main/assets/audio/rest.mp3 | Bin .../src/main/assets/audio/warm.mp3 | Bin .../trainterval/shared}/IntervalDuration.kt | 8 ++- .../trainterval/shared}/IntervalTimer.kt | 3 +- .../trainterval/shared/IntervalTimerState.kt | 44 ++++++++++++++ .../shared}/TraintervalDatabase.kt | 4 +- .../src/main/res/drawable/ic_pause.xml | 0 .../src/main/res/drawable/ic_play_arrow.xml | 0 .../src/main/res/drawable/ic_skip_next.xml | 0 .../main/res/drawable/ic_skip_previous.xml | 0 .../src/main/res/values/colors.xml | 0 shared/src/main/res/values/strings.xml | 8 +++ wear/build.gradle | 3 +- .../wbrawner/trainterval/wear/MainActivity.kt | 16 ++++- wear/src/main/res/values/strings.xml | 3 - 38 files changed, 181 insertions(+), 108 deletions(-) create mode 100644 shared/.gitignore create mode 100644 shared/build.gradle create mode 100644 shared/consumer-rules.pro create mode 100644 shared/proguard-rules.pro create mode 100644 shared/src/main/AndroidManifest.xml rename {app => shared}/src/main/assets/audio/cool.mp3 (100%) rename {app => shared}/src/main/assets/audio/high.mp3 (100%) rename {app => shared}/src/main/assets/audio/low.mp3 (100%) rename {app => shared}/src/main/assets/audio/rest.mp3 (100%) rename {app => shared}/src/main/assets/audio/warm.mp3 (100%) rename {app/src/main/java/com/wbrawner/trainterval => shared/src/main/java/com/wbrawner/trainterval/shared}/IntervalDuration.kt (89%) rename {app/src/main/java/com/wbrawner/trainterval/model => shared/src/main/java/com/wbrawner/trainterval/shared}/IntervalTimer.kt (96%) create mode 100644 shared/src/main/java/com/wbrawner/trainterval/shared/IntervalTimerState.kt rename {app/src/main/java/com/wbrawner/trainterval => shared/src/main/java/com/wbrawner/trainterval/shared}/TraintervalDatabase.kt (61%) rename {app => shared}/src/main/res/drawable/ic_pause.xml (100%) rename {app => shared}/src/main/res/drawable/ic_play_arrow.xml (100%) rename {app => shared}/src/main/res/drawable/ic_skip_next.xml (100%) rename {app => shared}/src/main/res/drawable/ic_skip_previous.xml (100%) rename {app => shared}/src/main/res/values/colors.xml (100%) create mode 100644 shared/src/main/res/values/strings.xml delete mode 100644 wear/src/main/res/values/strings.xml diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 3ced016..2511608 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -11,6 +11,7 @@ diff --git a/app/build.gradle b/app/build.gradle index 118b7af..d3b61d7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -44,12 +44,9 @@ android { } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation project(':shared') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.5' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-reactive:1.3.5' implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.core:core-ktx:1.2.0' @@ -58,12 +55,7 @@ dependencies { implementation 'com.google.android.material:material:1.2.0-alpha05' implementation 'androidx.recyclerview:recyclerview:1.1.0' - def room_version = "2.2.5" - implementation "androidx.room:room-runtime:$room_version" implementation 'androidx.legacy:legacy-support-v4:1.0.0' - kapt "androidx.room:room-compiler:$room_version" - implementation "androidx.room:room-ktx:$room_version" - testImplementation "androidx.room:room-testing:$room_version" def nav_version = "2.2.1" implementation "androidx.navigation:navigation-fragment-ktx:$nav_version" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 847f9f4..7b6947a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,19 +10,6 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> - - - - diff --git a/app/src/main/java/com/wbrawner/trainterval/DurationPicker.kt b/app/src/main/java/com/wbrawner/trainterval/DurationPicker.kt index 87322e3..27d7ee8 100644 --- a/app/src/main/java/com/wbrawner/trainterval/DurationPicker.kt +++ b/app/src/main/java/com/wbrawner/trainterval/DurationPicker.kt @@ -9,6 +9,9 @@ import android.widget.NumberPicker import androidx.annotation.AttrRes import androidx.annotation.StyleRes import androidx.core.math.MathUtils +import com.wbrawner.trainterval.shared.IntervalDuration +import com.wbrawner.trainterval.shared.toIntervalDuration +import com.wbrawner.trainterval.shared.toMillis import java.util.concurrent.TimeUnit private const val MIN_DURATION = 0L @@ -21,11 +24,13 @@ class DurationPicker @JvmOverloads constructor( @StyleRes defStyleRes: Int = 0 ) : FrameLayout(context, attrs, defStyleAttr, defStyleRes) { - private var intervalDuration = IntervalDuration() + private var intervalDuration = + IntervalDuration() var duration: Long get() = intervalDuration.toMillis() set(value) { - intervalDuration = MathUtils.clamp(value, MIN_DURATION, MAX_DURATION).toIntervalDuration() + intervalDuration = + MathUtils.clamp(value, MIN_DURATION, MAX_DURATION).toIntervalDuration() hours.value = intervalDuration.hours.toInt() minutes.value = intervalDuration.minutes.toInt() seconds.value = intervalDuration.seconds.toInt() diff --git a/app/src/main/java/com/wbrawner/trainterval/TraintervalApplication.kt b/app/src/main/java/com/wbrawner/trainterval/TraintervalApplication.kt index 36ad2f1..aefb46f 100644 --- a/app/src/main/java/com/wbrawner/trainterval/TraintervalApplication.kt +++ b/app/src/main/java/com/wbrawner/trainterval/TraintervalApplication.kt @@ -2,6 +2,7 @@ package com.wbrawner.trainterval import android.app.Application import androidx.room.Room +import com.wbrawner.trainterval.shared.TraintervalDatabase import com.wbrawner.trainterval.timerform.TimerFormViewModel import com.wbrawner.trainterval.timerlist.TimerListViewModel import org.koin.android.ext.koin.androidContext diff --git a/app/src/main/java/com/wbrawner/trainterval/activetimer/ActiveTimerFragment.kt b/app/src/main/java/com/wbrawner/trainterval/activetimer/ActiveTimerFragment.kt index 1a760e3..34ac9fc 100644 --- a/app/src/main/java/com/wbrawner/trainterval/activetimer/ActiveTimerFragment.kt +++ b/app/src/main/java/com/wbrawner/trainterval/activetimer/ActiveTimerFragment.kt @@ -16,8 +16,9 @@ import androidx.lifecycle.viewModelScope import androidx.navigation.fragment.findNavController import com.wbrawner.trainterval.Logger import com.wbrawner.trainterval.R -import com.wbrawner.trainterval.model.IntervalTimerDao -import com.wbrawner.trainterval.model.Phase +import com.wbrawner.trainterval.shared.IntervalTimerDao +import com.wbrawner.trainterval.shared.IntervalTimerState +import com.wbrawner.trainterval.shared.Phase import kotlinx.android.synthetic.main.fragment_active_timer.* import kotlinx.coroutines.* import org.koin.android.ext.android.inject @@ -78,9 +79,9 @@ class ActiveTimerFragment : Fragment() { coroutineScope!!.launch { activeTimerViewModel.timerState.observe(viewLifecycleOwner, Observer { state -> when (state) { - is IntervalTimerActiveState.LoadingState -> renderLoading() - is IntervalTimerActiveState.TimerRunningState -> renderTimer(state) - is IntervalTimerActiveState.ExitState -> findNavController().navigateUp() + is IntervalTimerState.LoadingState -> renderLoading() + is IntervalTimerState.TimerRunningState -> renderTimer(state) + is IntervalTimerState.ExitState -> findNavController().navigateUp() } }) activeTimerViewModel.init(logger, timerDao, timerId) @@ -103,7 +104,7 @@ class ActiveTimerFragment : Fragment() { } } - private fun renderTimer(state: IntervalTimerActiveState.TimerRunningState) { + private fun renderTimer(state: IntervalTimerState.TimerRunningState) { progressBar.visibility = View.GONE timerLayout.referencedIds.forEach { view?.findViewById(it)?.visibility = View.VISIBLE diff --git a/app/src/main/java/com/wbrawner/trainterval/activetimer/ActiveTimerViewModel.kt b/app/src/main/java/com/wbrawner/trainterval/activetimer/ActiveTimerViewModel.kt index 99b2399..cb7d306 100644 --- a/app/src/main/java/com/wbrawner/trainterval/activetimer/ActiveTimerViewModel.kt +++ b/app/src/main/java/com/wbrawner/trainterval/activetimer/ActiveTimerViewModel.kt @@ -1,26 +1,22 @@ package com.wbrawner.trainterval.activetimer -import androidx.annotation.ColorRes -import androidx.annotation.DrawableRes -import androidx.annotation.StringRes import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.wbrawner.trainterval.Logger -import com.wbrawner.trainterval.R -import com.wbrawner.trainterval.activetimer.IntervalTimerActiveState.LoadingState -import com.wbrawner.trainterval.activetimer.IntervalTimerActiveState.TimerRunningState -import com.wbrawner.trainterval.model.IntervalTimer -import com.wbrawner.trainterval.model.IntervalTimerDao -import com.wbrawner.trainterval.model.Phase -import com.wbrawner.trainterval.toIntervalDuration +import com.wbrawner.trainterval.shared.IntervalTimer +import com.wbrawner.trainterval.shared.IntervalTimerDao +import com.wbrawner.trainterval.shared.IntervalTimerState +import com.wbrawner.trainterval.shared.IntervalTimerState.LoadingState +import com.wbrawner.trainterval.shared.IntervalTimerState.TimerRunningState +import com.wbrawner.trainterval.shared.Phase import kotlinx.coroutines.Job import kotlinx.coroutines.delay import kotlinx.coroutines.isActive import kotlinx.coroutines.launch class ActiveTimerViewModel : ViewModel() { - val timerState: MutableLiveData = MutableLiveData(LoadingState) + val timerState: MutableLiveData = MutableLiveData(LoadingState) private var timerJob: Job? = null private lateinit var timer: IntervalTimer private lateinit var logger: Logger @@ -201,42 +197,3 @@ class ActiveTimerViewModel : ViewModel() { } } } - -/** - * Used to represent the state while a user has a specific timer open. - */ -sealed class IntervalTimerActiveState { - object LoadingState : IntervalTimerActiveState() - class TimerRunningState( - val timerName: String, - val timeRemaining: String, - val currentSet: Int, - val currentRound: Int, - val soundId: Int?, - @StringRes val phase: Int, - @ColorRes val timerBackground: Int, - @DrawableRes val playPauseIcon: Int - ) : IntervalTimerActiveState() { - constructor( - timer: IntervalTimer, - timeRemaining: Long, - currentSet: Int, - currentRound: Int, - phase: Phase, - timerRunning: Boolean - ) : this( - timerName = timer.name, - phase = phase.stringRes, - timeRemaining = timeRemaining.toIntervalDuration().toString(), - currentSet = currentSet, - currentRound = currentRound, - timerBackground = phase.colorRes, - soundId = if (timerRunning && timeRemaining == timer.durationForPhase(phase)) - phase.ordinal - else null, - playPauseIcon = if (timerRunning) R.drawable.ic_pause else R.drawable.ic_play_arrow - ) - } - - object ExitState : IntervalTimerActiveState() -} diff --git a/app/src/main/java/com/wbrawner/trainterval/timerform/TimerFormFragment.kt b/app/src/main/java/com/wbrawner/trainterval/timerform/TimerFormFragment.kt index b8898e5..00ddec7 100644 --- a/app/src/main/java/com/wbrawner/trainterval/timerform/TimerFormFragment.kt +++ b/app/src/main/java/com/wbrawner/trainterval/timerform/TimerFormFragment.kt @@ -10,7 +10,7 @@ import androidx.fragment.app.Fragment import androidx.lifecycle.Observer import androidx.navigation.fragment.findNavController import com.wbrawner.trainterval.R -import com.wbrawner.trainterval.model.IntervalTimer +import com.wbrawner.trainterval.shared.IntervalTimer import com.wbrawner.trainterval.timerform.IntervalTimerEditState.* import kotlinx.android.synthetic.main.fragment_timer_form.* import kotlinx.coroutines.CoroutineScope diff --git a/app/src/main/java/com/wbrawner/trainterval/timerform/TimerFormViewModel.kt b/app/src/main/java/com/wbrawner/trainterval/timerform/TimerFormViewModel.kt index 18e0433..cbc821f 100644 --- a/app/src/main/java/com/wbrawner/trainterval/timerform/TimerFormViewModel.kt +++ b/app/src/main/java/com/wbrawner/trainterval/timerform/TimerFormViewModel.kt @@ -3,8 +3,8 @@ package com.wbrawner.trainterval.timerform import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import com.wbrawner.trainterval.Logger -import com.wbrawner.trainterval.model.IntervalTimer -import com.wbrawner.trainterval.model.IntervalTimerDao +import com.wbrawner.trainterval.shared.IntervalTimer +import com.wbrawner.trainterval.shared.IntervalTimerDao import com.wbrawner.trainterval.timerform.IntervalTimerEditState.* class TimerFormViewModel( diff --git a/app/src/main/java/com/wbrawner/trainterval/timerlist/TimerListAdapter.kt b/app/src/main/java/com/wbrawner/trainterval/timerlist/TimerListAdapter.kt index b518ed8..f472eb5 100644 --- a/app/src/main/java/com/wbrawner/trainterval/timerlist/TimerListAdapter.kt +++ b/app/src/main/java/com/wbrawner/trainterval/timerlist/TimerListAdapter.kt @@ -8,8 +8,8 @@ import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView import com.wbrawner.trainterval.R -import com.wbrawner.trainterval.model.IntervalTimer -import com.wbrawner.trainterval.toIntervalDuration +import com.wbrawner.trainterval.shared.IntervalTimer +import com.wbrawner.trainterval.shared.toIntervalDuration class TimerListAdapter( private val timerListViewModel: TimerListViewModel diff --git a/app/src/main/java/com/wbrawner/trainterval/timerlist/TimerListFragment.kt b/app/src/main/java/com/wbrawner/trainterval/timerlist/TimerListFragment.kt index 3b9087e..bb7ef89 100644 --- a/app/src/main/java/com/wbrawner/trainterval/timerlist/TimerListFragment.kt +++ b/app/src/main/java/com/wbrawner/trainterval/timerlist/TimerListFragment.kt @@ -12,7 +12,7 @@ import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import com.wbrawner.trainterval.R -import com.wbrawner.trainterval.model.IntervalTimer +import com.wbrawner.trainterval.shared.IntervalTimer import com.wbrawner.trainterval.timerlist.IntervalTimerListState.* import kotlinx.android.synthetic.main.fragment_timer_list.* import org.koin.android.ext.android.inject diff --git a/app/src/main/java/com/wbrawner/trainterval/timerlist/TimerListViewModel.kt b/app/src/main/java/com/wbrawner/trainterval/timerlist/TimerListViewModel.kt index dc46f92..bfeddad 100644 --- a/app/src/main/java/com/wbrawner/trainterval/timerlist/TimerListViewModel.kt +++ b/app/src/main/java/com/wbrawner/trainterval/timerlist/TimerListViewModel.kt @@ -3,8 +3,8 @@ package com.wbrawner.trainterval.timerlist import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import com.wbrawner.trainterval.Logger -import com.wbrawner.trainterval.model.IntervalTimer -import com.wbrawner.trainterval.model.IntervalTimerDao +import com.wbrawner.trainterval.shared.IntervalTimer +import com.wbrawner.trainterval.shared.IntervalTimerDao import com.wbrawner.trainterval.timerlist.IntervalTimerListState.* import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.flow.collect diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 854e71f..27a9b07 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,5 +1,4 @@ - Trainterval Timer Name Timer Description Low Intensity Duration @@ -16,11 +15,6 @@ Skip Next Start Timer Rest Duration - Warm Up - Low Intensity - High Intensity - Rest - Cool Down Items Item Detail Set: %1$d/%2$d diff --git a/build.gradle b/build.gradle index 62befe0..a8d89d4 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,8 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.70' + ext.kotlin_version = '1.3.72' + ext.room_version = '2.2.5' repositories { google() jcenter() @@ -20,7 +21,6 @@ allprojects { repositories { google() jcenter() - } } diff --git a/settings.gradle b/settings.gradle index 07cc2f1..7c6bcd0 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,3 @@ +include ':shared' rootProject.name='Interval Timer' include ':app', ':wear' diff --git a/shared/.gitignore b/shared/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/shared/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/shared/build.gradle b/shared/build.gradle new file mode 100644 index 0000000..4b970ad --- /dev/null +++ b/shared/build.gradle @@ -0,0 +1,43 @@ +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-kapt' + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.1" + + defaultConfig { + minSdkVersion 23 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles "consumer-rules.pro" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: "libs", include: ["*.jar"]) + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5' + api 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.5' + api 'org.jetbrains.kotlinx:kotlinx-coroutines-reactive:1.3.5' + implementation 'androidx.core:core-ktx:1.3.1' + implementation 'androidx.appcompat:appcompat:1.1.0' + kapt "androidx.room:room-compiler:$room_version" + implementation "androidx.room:room-ktx:$room_version" + testImplementation "androidx.room:room-testing:$room_version" + api "androidx.room:room-runtime:$room_version" + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' +} \ No newline at end of file diff --git a/shared/consumer-rules.pro b/shared/consumer-rules.pro new file mode 100644 index 0000000..e69de29 diff --git a/shared/proguard-rules.pro b/shared/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/shared/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/shared/src/main/AndroidManifest.xml b/shared/src/main/AndroidManifest.xml new file mode 100644 index 0000000..d580597 --- /dev/null +++ b/shared/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + / + \ No newline at end of file diff --git a/app/src/main/assets/audio/cool.mp3 b/shared/src/main/assets/audio/cool.mp3 similarity index 100% rename from app/src/main/assets/audio/cool.mp3 rename to shared/src/main/assets/audio/cool.mp3 diff --git a/app/src/main/assets/audio/high.mp3 b/shared/src/main/assets/audio/high.mp3 similarity index 100% rename from app/src/main/assets/audio/high.mp3 rename to shared/src/main/assets/audio/high.mp3 diff --git a/app/src/main/assets/audio/low.mp3 b/shared/src/main/assets/audio/low.mp3 similarity index 100% rename from app/src/main/assets/audio/low.mp3 rename to shared/src/main/assets/audio/low.mp3 diff --git a/app/src/main/assets/audio/rest.mp3 b/shared/src/main/assets/audio/rest.mp3 similarity index 100% rename from app/src/main/assets/audio/rest.mp3 rename to shared/src/main/assets/audio/rest.mp3 diff --git a/app/src/main/assets/audio/warm.mp3 b/shared/src/main/assets/audio/warm.mp3 similarity index 100% rename from app/src/main/assets/audio/warm.mp3 rename to shared/src/main/assets/audio/warm.mp3 diff --git a/app/src/main/java/com/wbrawner/trainterval/IntervalDuration.kt b/shared/src/main/java/com/wbrawner/trainterval/shared/IntervalDuration.kt similarity index 89% rename from app/src/main/java/com/wbrawner/trainterval/IntervalDuration.kt rename to shared/src/main/java/com/wbrawner/trainterval/shared/IntervalDuration.kt index 3ceb27f..ad964d0 100644 --- a/app/src/main/java/com/wbrawner/trainterval/IntervalDuration.kt +++ b/shared/src/main/java/com/wbrawner/trainterval/shared/IntervalDuration.kt @@ -1,4 +1,4 @@ -package com.wbrawner.trainterval +package com.wbrawner.trainterval.shared import java.util.concurrent.TimeUnit @@ -42,5 +42,9 @@ fun Long.toIntervalDuration(): IntervalDuration { seconds -= minutes * SECONDS_IN_MINUTE } - return IntervalDuration(hours, minutes, seconds) + return IntervalDuration( + hours, + minutes, + seconds + ) } \ No newline at end of file diff --git a/app/src/main/java/com/wbrawner/trainterval/model/IntervalTimer.kt b/shared/src/main/java/com/wbrawner/trainterval/shared/IntervalTimer.kt similarity index 96% rename from app/src/main/java/com/wbrawner/trainterval/model/IntervalTimer.kt rename to shared/src/main/java/com/wbrawner/trainterval/shared/IntervalTimer.kt index 0c3494f..ea1e5ec 100644 --- a/app/src/main/java/com/wbrawner/trainterval/model/IntervalTimer.kt +++ b/shared/src/main/java/com/wbrawner/trainterval/shared/IntervalTimer.kt @@ -1,9 +1,8 @@ -package com.wbrawner.trainterval.model +package com.wbrawner.trainterval.shared import androidx.annotation.ColorRes import androidx.annotation.StringRes import androidx.room.* -import com.wbrawner.trainterval.R import kotlinx.coroutines.flow.Flow import java.util.concurrent.TimeUnit diff --git a/shared/src/main/java/com/wbrawner/trainterval/shared/IntervalTimerState.kt b/shared/src/main/java/com/wbrawner/trainterval/shared/IntervalTimerState.kt new file mode 100644 index 0000000..de25d97 --- /dev/null +++ b/shared/src/main/java/com/wbrawner/trainterval/shared/IntervalTimerState.kt @@ -0,0 +1,44 @@ +package com.wbrawner.trainterval.shared + +import androidx.annotation.ColorRes +import androidx.annotation.DrawableRes +import androidx.annotation.StringRes + +/** + * Used to represent the state while a user has a specific timer open. + */ +sealed class IntervalTimerState { + object LoadingState : IntervalTimerState() + class TimerRunningState( + val timerName: String, + val timeRemaining: String, + val currentSet: Int, + val currentRound: Int, + val soundId: Int?, + @StringRes val phase: Int, + @ColorRes val timerBackground: Int, + @DrawableRes val playPauseIcon: Int + ) : IntervalTimerState() { + constructor( + timer: IntervalTimer, + timeRemaining: Long, + currentSet: Int, + currentRound: Int, + phase: Phase, + timerRunning: Boolean + ) : this( + timerName = timer.name, + phase = phase.stringRes, + timeRemaining = timeRemaining.toIntervalDuration().toString(), + currentSet = currentSet, + currentRound = currentRound, + timerBackground = phase.colorRes, + soundId = if (timerRunning && timeRemaining == timer.durationForPhase(phase)) + phase.ordinal + else null, + playPauseIcon = if (timerRunning) R.drawable.ic_pause else R.drawable.ic_play_arrow + ) + } + + object ExitState : IntervalTimerState() +} diff --git a/app/src/main/java/com/wbrawner/trainterval/TraintervalDatabase.kt b/shared/src/main/java/com/wbrawner/trainterval/shared/TraintervalDatabase.kt similarity index 61% rename from app/src/main/java/com/wbrawner/trainterval/TraintervalDatabase.kt rename to shared/src/main/java/com/wbrawner/trainterval/shared/TraintervalDatabase.kt index 81b1c50..dbb838b 100644 --- a/app/src/main/java/com/wbrawner/trainterval/TraintervalDatabase.kt +++ b/shared/src/main/java/com/wbrawner/trainterval/shared/TraintervalDatabase.kt @@ -1,9 +1,7 @@ -package com.wbrawner.trainterval +package com.wbrawner.trainterval.shared import androidx.room.Database import androidx.room.RoomDatabase -import com.wbrawner.trainterval.model.IntervalTimer -import com.wbrawner.trainterval.model.IntervalTimerDao @Database(entities = [IntervalTimer::class], version = 1) abstract class TraintervalDatabase : RoomDatabase() { diff --git a/app/src/main/res/drawable/ic_pause.xml b/shared/src/main/res/drawable/ic_pause.xml similarity index 100% rename from app/src/main/res/drawable/ic_pause.xml rename to shared/src/main/res/drawable/ic_pause.xml diff --git a/app/src/main/res/drawable/ic_play_arrow.xml b/shared/src/main/res/drawable/ic_play_arrow.xml similarity index 100% rename from app/src/main/res/drawable/ic_play_arrow.xml rename to shared/src/main/res/drawable/ic_play_arrow.xml diff --git a/app/src/main/res/drawable/ic_skip_next.xml b/shared/src/main/res/drawable/ic_skip_next.xml similarity index 100% rename from app/src/main/res/drawable/ic_skip_next.xml rename to shared/src/main/res/drawable/ic_skip_next.xml diff --git a/app/src/main/res/drawable/ic_skip_previous.xml b/shared/src/main/res/drawable/ic_skip_previous.xml similarity index 100% rename from app/src/main/res/drawable/ic_skip_previous.xml rename to shared/src/main/res/drawable/ic_skip_previous.xml diff --git a/app/src/main/res/values/colors.xml b/shared/src/main/res/values/colors.xml similarity index 100% rename from app/src/main/res/values/colors.xml rename to shared/src/main/res/values/colors.xml diff --git a/shared/src/main/res/values/strings.xml b/shared/src/main/res/values/strings.xml new file mode 100644 index 0000000..b4ad27d --- /dev/null +++ b/shared/src/main/res/values/strings.xml @@ -0,0 +1,8 @@ + + Trainterval + Warm Up + Low Intensity + High Intensity + Rest + Cool Down + \ No newline at end of file diff --git a/wear/build.gradle b/wear/build.gradle index 925ac28..ab79a64 100644 --- a/wear/build.gradle +++ b/wear/build.gradle @@ -25,10 +25,11 @@ android { } dependencies { - implementation fileTree(dir: "libs", include: ["*.jar"]) + implementation project(':shared') implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation 'androidx.wear:wear:1.0.0' implementation 'com.google.android.support:wearable:2.7.0' + implementation 'com.google.android.gms:play-services-wearable:17.0.0' compileOnly 'com.google.android.wearable:wearable:2.7.0' testImplementation 'junit:junit:4.12' } \ No newline at end of file diff --git a/wear/src/main/java/com/wbrawner/trainterval/wear/MainActivity.kt b/wear/src/main/java/com/wbrawner/trainterval/wear/MainActivity.kt index 6f601ba..eba81dc 100644 --- a/wear/src/main/java/com/wbrawner/trainterval/wear/MainActivity.kt +++ b/wear/src/main/java/com/wbrawner/trainterval/wear/MainActivity.kt @@ -2,12 +2,26 @@ package com.wbrawner.trainterval.wear import android.os.Bundle import android.support.wearable.activity.WearableActivity +import com.google.android.gms.wearable.DataClient +import com.google.android.gms.wearable.DataEventBuffer +import com.google.android.gms.wearable.Wearable import kotlinx.android.synthetic.main.activity_main.* -class MainActivity : WearableActivity() { +class MainActivity : WearableActivity(), DataClient.OnDataChangedListener { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) textView.text = "Hello, Wear OS!" } + + override fun onResume() { + super.onResume() + Wearable.getDataClient(this).addListener(this) + } + + override fun onDataChanged(dataEvents: DataEventBuffer) { + dataEvents.forEach { event -> + event.type + } + } } \ No newline at end of file diff --git a/wear/src/main/res/values/strings.xml b/wear/src/main/res/values/strings.xml deleted file mode 100644 index 62f44b4..0000000 --- a/wear/src/main/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - Trainterval - \ No newline at end of file