Commit 109b10e8 authored by 12people's avatar 12people

Refactor, splitting presenter from service

parent 0cecd9b2
# Built application files
*.apk
*.ap_
# Files for the ART/Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
out/
# Gradle files
.gradle/
build/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
# Android Studio Navigation editor temp files
.navigation/
# Android Studio captures folder
captures/
# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
.idea/caches
.idea/codeStyles
# Keystore files
# Uncomment the following line if you do not want to check your keystore files in.
#*.jks
# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
# Google Services (e.g. APIs or Firebase)
google-services.json
# Freeline
freeline.py
freeline/
freeline_project_description.json
# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md
# hidden system files
.DS_Store
._.DS_Store
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<component name="libraryTable">
<library name="android.arch.lifecycle:common:1.0.3@jar">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/android.arch.lifecycle/common/1.0.3/7d7f60c4783872861222166f6164215f8951c7b1/common-1.0.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/android.arch.lifecycle/common/1.0.3/24f9b26a6d4033cd07da8cb22936c7a75b9e1b29/common-1.0.3-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="android.arch.lifecycle:runtime-1.0.3">
<CLASSES>
<root url="file://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/runtime-1.0.3.aar/c5a29ccbeeedd2e0b91448cc78b41453/res" />
<root url="jar://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/runtime-1.0.3.aar/c5a29ccbeeedd2e0b91448cc78b41453/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/android.arch.lifecycle/runtime/1.0.3/4154878465bd9019f4c4988c668c7d69f2f687b3/runtime-1.0.3-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="com.android.support:animated-vector-drawable-27.0.2">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/animated-vector-drawable-27.0.2.aar/61beff803bd9663da4525c8ba3f5acb5/jars/classes.jar!/" />
<root url="file://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/animated-vector-drawable-27.0.2.aar/61beff803bd9663da4525c8ba3f5acb5/res" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.android.support/animated-vector-drawable/27.0.2/1a380688b78985fe5fe1494d8bf90ceba5f7eee2/animated-vector-drawable-27.0.2-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="com.android.support:appcompat-v7-27.0.2">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/appcompat-v7-27.0.2.aar/f427500fef7859c5bf61f5e36c2503aa/jars/classes.jar!/" />
<root url="file://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/appcompat-v7-27.0.2.aar/f427500fef7859c5bf61f5e36c2503aa/res" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.android.support/appcompat-v7/27.0.2/4ae031a24f432a35efae0d609731c5a34e65696c/appcompat-v7-27.0.2-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="com.android.support:design-27.0.2">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/design-27.0.2.aar/905a7d993ac0692cdc1b7c7ee451d997/jars/classes.jar!/" />
<root url="file://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/design-27.0.2.aar/905a7d993ac0692cdc1b7c7ee451d997/res" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.android.support/design/27.0.2/94d41fc2899844b127c66f2b8ad8a0afa3eb2469/design-27.0.2-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="com.android.support:recyclerview-v7-27.0.2">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/recyclerview-v7-27.0.2.aar/5d23bf8e42d52b8c7d4f244f1cd1786d/jars/classes.jar!/" />
<root url="file://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/recyclerview-v7-27.0.2.aar/5d23bf8e42d52b8c7d4f244f1cd1786d/res" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.android.support/recyclerview-v7/27.0.2/76f4751bc97ce7fa2362dc5a38b39089066a2c99/recyclerview-v7-27.0.2-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="com.android.support:support-annotations:27.0.2@jar">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.android.support/support-annotations/27.0.2/b9ef4342c934a1a8b107506273dc8061662a322/support-annotations-27.0.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.android.support/support-annotations/27.0.2/d66efa1539831c039007b871b00cea0dd4101f2b/support-annotations-27.0.2-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="com.android.support:support-compat-27.0.2">
<CLASSES>
<root url="file://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/support-compat-27.0.2.aar/c3688da49786e42a1ad1f889d18e49d5/res" />
<root url="jar://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/support-compat-27.0.2.aar/c3688da49786e42a1ad1f889d18e49d5/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.android.support/support-compat/27.0.2/80acc64f280831f05960ede2cd87237e8d097ed2/support-compat-27.0.2-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="com.android.support:support-core-ui-27.0.2">
<CLASSES>
<root url="file://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/support-core-ui-27.0.2.aar/f85c7b249bcb8744b9bb046dfde86d11/res" />
<root url="jar://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/support-core-ui-27.0.2.aar/f85c7b249bcb8744b9bb046dfde86d11/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.android.support/support-core-ui/27.0.2/304d1a77fad841db2ed31e95322d4efd5cbf6ffb/support-core-ui-27.0.2-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="com.android.support:support-core-utils-27.0.2">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/support-core-utils-27.0.2.aar/91fbe9d5720def45eedbc09c90f7ea85/jars/classes.jar!/" />
<root url="file://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/support-core-utils-27.0.2.aar/91fbe9d5720def45eedbc09c90f7ea85/res" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.android.support/support-core-utils/27.0.2/800ca6dd3ce3d83aa50249ae273ca5f02f7ddc5f/support-core-utils-27.0.2-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="com.android.support:support-fragment-27.0.2">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/support-fragment-27.0.2.aar/ab357c5758c6060b506ba6c104b91e0f/jars/classes.jar!/" />
<root url="file://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/support-fragment-27.0.2.aar/ab357c5758c6060b506ba6c104b91e0f/res" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.android.support/support-fragment/27.0.2/659085cb974e7ec1f25451d23f11578332ea0d7e/support-fragment-27.0.2-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="com.android.support:support-media-compat-27.0.2">
<CLASSES>
<root url="file://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/support-media-compat-27.0.2.aar/1b0739e65844b73ba76852800e774fca/res" />
<root url="jar://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/support-media-compat-27.0.2.aar/1b0739e65844b73ba76852800e774fca/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.android.support/support-media-compat/27.0.2/d2f239fdf3519cb8e4a7bfb07bffc358d9065a21/support-media-compat-27.0.2-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="com.android.support:support-v4-27.0.2">
<CLASSES>
<root url="file://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/support-v4-27.0.2.aar/6de88659b1707f1c60db793820f338c7/res" />
<root url="jar://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/support-v4-27.0.2.aar/6de88659b1707f1c60db793820f338c7/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.android.support/support-v4/27.0.2/5b8f86fea035328fc9e8c660773037a3401ce25f/support-v4-27.0.2-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="com.android.support:support-vector-drawable-27.0.2">
<CLASSES>
<root url="file://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/support-vector-drawable-27.0.2.aar/88fb5c4f157dbf00e9af3d61c257199a/res" />
<root url="jar://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/support-vector-drawable-27.0.2.aar/88fb5c4f157dbf00e9af3d61c257199a/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.android.support/support-vector-drawable/27.0.2/710838de66b0cc3faf839415bfac47f47be2e55/support-vector-drawable-27.0.2-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="com.android.support:transition-27.0.2">
<CLASSES>
<root url="file://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/transition-27.0.2.aar/07d3a1f8b2a61f7ebd09ca50fa85ef32/res" />
<root url="jar://$USER_HOME$/.gradle/caches/transforms-1/files-1.1/transition-27.0.2.aar/07d3a1f8b2a61f7ebd09ca50fa85ef32/jars/classes.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.android.support/transition/27.0.2/2cb0be3ce3650268977139086cf66f1ffbfeb6ac/transition-27.0.2-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="net.bytebuddy:byte-buddy:1.7.4@jar">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/net.bytebuddy/byte-buddy/1.7.4/d0e77888485e1683057f8399f916eda6049c4acf/byte-buddy-1.7.4.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/net.bytebuddy/byte-buddy/1.7.4/c5c304e6b44947e523c8467c39ad24fef616fab9/byte-buddy-1.7.4-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="net.bytebuddy:byte-buddy-agent:1.7.4@jar">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/net.bytebuddy/byte-buddy-agent/1.7.4/66286677db75148b3c2fb94e72f1c61aceb20e33/byte-buddy-agent-1.7.4.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/net.bytebuddy/byte-buddy-agent/1.7.4/c187323701d5e7e335711f7573170d79c86c25d2/byte-buddy-agent-1.7.4-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="org.jetbrains.kotlin:kotlin-stdlib:1.2.21@jar">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.2.21/d64187eb2d9d1521be3421aa8c6774a8625cdde8/kotlin-stdlib-1.2.21.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.2.21/795e111c612ba96d0175f5705291228ca8167dc8/kotlin-stdlib-1.2.21-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="org.jetbrains.kotlin:kotlin-stdlib-jre7:1.2.21@jar">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jre7/1.2.21/3beb08c67673033183c8652572680587876e64b5/kotlin-stdlib-jre7-1.2.21.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jre7/1.2.21/9daa42242784b01e51fd5d1d7c7081075f090908/kotlin-stdlib-jre7-1.2.21-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="org.mockito:mockito-core:2.10.0@jar">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.mockito/mockito-core/2.10.0/871efe6f2607d8c93dd25b8c1fa09851d4286dd6/mockito-core-2.10.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.mockito/mockito-core/2.10.0/2ba7c7553f07747d8b85ce9b2273e5c03217a0d8/mockito-core-2.10.0-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="org.objenesis:objenesis:2.6@jar">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.objenesis/objenesis/2.6/639033469776fd37c08358c6b92a4761feb2af4b/objenesis-2.6.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.objenesis/objenesis/2.6/96614f514a1031296657bf0dde452dc15e42fcb8/objenesis-2.6-sources.jar!/" />
</SOURCES>
</library>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MavenImportPreferences">
<option name="generalSettings">
<MavenGeneralSettings>
<option name="mavenHome" value="Bundled (Maven 3)" />
</MavenGeneralSettings>
</option>
</component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="5">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
<module fileurl="file://$PROJECT_DIR$/feeel.iml" filepath="$PROJECT_DIR$/feeel.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="XRC" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
This diff is collapsed.
......@@ -23,16 +23,16 @@ android {
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:design:27.1.1'
testImplementation 'junit:junit:4.12'
// testImplementation 'org.mockito:mockito-core:2.10.0'
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.10.0'
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:design:27.0.2'
}
repositories {
......
package com.enjoyingfoss.feeel
import android.os.Parcelable
import com.enjoyingfoss.feeel.data.ExerciseMeta
import com.enjoyingfoss.feeel.data.Workout
import com.enjoyingfoss.feeel.model.ExerciseMeta
import com.enjoyingfoss.feeel.model.Workout
/**
@author Miroslav Mazel
*/
interface WorkoutContract {
interface Presenter {
fun setView(callback: View, savedState: Parcelable?)
fun getSavedState(): Parcelable
fun setView(callback: View, savedState: Parcelable?, audioOn: Boolean)
fun saveState(): Parcelable?
fun disconnect(view: WorkoutContract.View) //todo test that this is always called; OR use weakReference instead
fun skipToPreviousExercise()
......@@ -22,12 +22,14 @@ interface WorkoutContract {
interface View {
fun setExercise(exerciseMeta: ExerciseMeta)
fun setBreak(nextExerciseMeta: ExerciseMeta)
fun finishWorkout()
fun showFinish()
fun setSeconds(seconds: Int) // sets seconds for countdown, both before and during exercise
fun setPaused()
fun setPlaying()
fun close()
}
interface Model {
......
package com.enjoyingfoss.feeel.data
package com.enjoyingfoss.feeel.model
import android.os.Parcel
import android.os.Parcelable
......
package com.enjoyingfoss.feeel.data
package com.enjoyingfoss.feeel.model
import android.os.Parcel
import android.os.Parcelable
......
package com.enjoyingfoss.feeel.data
package com.enjoyingfoss.feeel.model
import android.os.Parcel
import android.os.Parcelable
......@@ -15,8 +15,7 @@ class Workout(val titleResource: Int,
constructor(parcel: Parcel) : this(
parcel.readInt(),
parcel.createTypedArray(ExerciseMeta),
parcel.readInt()) {
}
parcel.readInt())
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeInt(titleResource)
......
package com.enjoyingfoss.feeel
package com.enjoyingfoss.feeel.model
import com.enjoyingfoss.feeel.data.Exercise
import com.enjoyingfoss.feeel.data.ExerciseMeta
import com.enjoyingfoss.feeel.data.Workout
import com.enjoyingfoss.feeel.R
import com.enjoyingfoss.feeel.WorkoutContract
/**
@author Miroslav Mazel
......
package com.enjoyingfoss.feeel.presenter
import android.os.Parcel
import android.os.Parcelable
import com.enjoyingfoss.feeel.WorkoutContract
import com.enjoyingfoss.feeel.model.Workout
/**
@author Miroslav Mazel
*/
internal class WorkoutPresenter(val workout: Workout, vararg callbacks: WorkoutContract.View) : WorkoutTimer.TimerCallback {
// todo add prep for start and for restoring cur exercise
//todo check that proguard handles enums effectively
enum class Stage { EXERCISE, BREAK, END }
class WorkoutPresenterState(val workout: Workout,
val exercisePos: Int,
val timeRemaining: Int,
val isTimerRunning: Boolean,
val stage: Stage) : Parcelable {
constructor(parcel: Parcel) : this(
parcel.readParcelable(Workout::class.java.classLoader),
parcel.readInt(),
parcel.readInt(),
parcel.readByte() != 0.toByte(),
Stage.values()[parcel.readInt()])
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeParcelable(workout, flags)
parcel.writeInt(exercisePos)
parcel.writeInt(timeRemaining)
parcel.writeByte(if (isTimerRunning) 1 else 0)
parcel.writeInt(stage.ordinal)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<WorkoutPresenterState> {
override fun createFromParcel(parcel: Parcel): WorkoutPresenterState {
return WorkoutPresenterState(parcel)
}
override fun newArray(size: Int): Array<WorkoutPresenterState?> {
return arrayOfNulls(size)
}
}
}
private val PREP_LENGTH = 3
private val timer = WorkoutTimer(this, PREP_LENGTH)
private var views = ArrayList<WorkoutContract.View>(2) //todo use WeakReference for views!!!
private var exercisePos = 0
private var stage = Stage.BREAK
private val curExerciseMeta
get() = workout.exerciseMetas[exercisePos]
private val curExerciseLength
get() = curExerciseMeta.duration
private val isFirstExercise: Boolean
get() = exercisePos == 0
private val isLastExercise: Boolean
get() = exercisePos == workout.size - 1
init {
for (view in callbacks) {
views.add(view)
}
renderStage()
timer.start()
}
constructor(savedState: Parcelable, vararg callbacks: WorkoutContract.View) :
this((savedState as WorkoutPresenterState).workout, *callbacks) {
exercisePos = savedState.exercisePos
stage = savedState.stage
for (view in callbacks) {
views.add(view)
}
renderStage()
renderPausePlay()
if (savedState.isTimerRunning) timer.start()
timer.timeRemaining = savedState.timeRemaining
}
//
// Timer
//
override fun onSecondDecrease() {
for (view in views) view.setSeconds(timer.timeRemaining)
}
override fun onTimerZero() { //todo make a test for switching states correctly
when (stage) {
Stage.BREAK -> setUpExerciseStage()
Stage.EXERCISE -> {
if (isLastExercise) setUpEndStage()
else {
exercisePos++
setUpBreakStage()
}
}
}
}
//
// Stages
//
private fun setUpExerciseStage() {
stage = Stage.EXERCISE
renderStage()
timer.timeRemaining = curExerciseLength
renderSeconds()
}
private fun setUpBreakStage() { //todo say what to prepare (e.g. chair, mat, sthing else)!
stage = Stage.BREAK
renderStage()
timer.timeRemaining = workout.breakLength
renderSeconds()
}
private fun setUpEndStage() {
timer.stop()