Skip to content

Commit

Permalink
Starting Stretching (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
mazurio authored Dec 28, 2016
1 parent ea9b21b commit 2d21e09
Show file tree
Hide file tree
Showing 39 changed files with 928 additions and 11 deletions.
5 changes: 5 additions & 0 deletions app/src/main/kotlin/com/bodyweight/fitness/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ object Constants {
val preferencesTimerKey = "PREFERENCE_TIMER_KEY_"
val preferencesNumberOfRepsKey = "PREFERENCE_NUMBER_OF_REPS_KEY_"
val preferencesIntroductionShown = "PREFERENCE_INTRODUCTION_SHOWN"
val preferencesShowRestTimer = "PREFERENCE_SHOW_REST_TIMER"
val preferencesRestTimerDefaultSeconds = "PREFERENCE_REST_TIMER_DEFAULT_SECONDS"
val preferencesShowRestTimerAfterWarmup = "PREFERENCE_SHOW_REST_TIMER_WARMUP_EXERCISES"
val preferencesShowRestTimerAfterBodylineDrills = "PREFERENCE_SHOW_REST_TIMER_BODYLINE_DRILLS"
val preferencesShowRestTimerAfterFlexibilityExercises = "PREFERENCE_SHOW_REST_TIMER_FLEXIBILITY_ROUTINES"
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,32 @@ class ToolbarSpinnerAdapter : BaseAdapter() {
val routines: List<SpinnerRoutine>

init {
if (RoutineStream.routine.routineId == "routine0") {
val routineId = RoutineStream.routine.routineId

if (routineId == "routine0") {
routines = listOf(
SpinnerRoutine(0, "Bodyweight Fitness", "Recommended Routine"),
SpinnerRoutine(1, "Starting Stretching", "Flexibility Routine"),
SpinnerRoutine(2, "Molding Mobility", "Flexibility Routine")
)
} else if (routineId == "e73593f4-ee17-4b9b-912a-87fa3625f63d") {
routines = listOf(
SpinnerRoutine(2, "Molding Mobility", "Flexibility Routine"),
SpinnerRoutine(0, "Bodyweight Fitness", "Recommended Routine"),
SpinnerRoutine(1, "Molding Mobility", "Flexibility Routine"))
SpinnerRoutine(1, "Starting Stretching", "Flexibility Routine")
)
} else if (routineId == "d8a722a0-fae2-4e7e-a751-430348c659fe") {
routines = listOf(
SpinnerRoutine(1, "Starting Stretching", "Flexibility Routine"),
SpinnerRoutine(0, "Bodyweight Fitness", "Recommended Routine"),
SpinnerRoutine(2, "Molding Mobility", "Flexibility Routine")
)
} else {
routines = listOf(
SpinnerRoutine(1, "Molding Mobility", "Flexibility Routine"),
SpinnerRoutine(0, "Bodyweight Fitness", "Recommended Routine"))
SpinnerRoutine(0, "Bodyweight Fitness", "Recommended Routine"),
SpinnerRoutine(1, "Starting Stretching", "Flexibility Routine"),
SpinnerRoutine(2, "Molding Mobility", "Flexibility Routine")
)
}
}

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/kotlin/com/bodyweight/fitness/model/Routine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Routine(JSONRoutine: JSONRoutine) : Serializable {
var routineId: String = "routine0"
var title: String = ""
var subtitle: String = ""
var shortDescription: String = ""
var url: String = ""

val categories = ArrayList<Category>()
val sections = ArrayList<Section>()
Expand All @@ -24,6 +26,8 @@ class Routine(JSONRoutine: JSONRoutine) : Serializable {
routineId = JSONRoutine.routineId
title = JSONRoutine.title
subtitle = JSONRoutine.subtitle
shortDescription = JSONRoutine.shortDescription
url = JSONRoutine.url

var currentCategory: Category? = null
var currentSection: Section? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class JSONRoutine {
var routineId: String = ""
var title: String = ""
var subtitle: String = ""
var shortDescription: String = ""
var url: String = ""
var routine = ArrayList<JSONLinkedRoutine>()

val size: Int by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ object RoutineStream {
var routine: Routine =
if (Preferences.defaultRoutine == "routine0") {
JsonRoutineLoader().getRoutine(R.raw.bodyweight_fitness_recommended_routine)
} else if(Preferences.defaultRoutine == "d8a722a0-fae2-4e7e-a751-430348c659fe") {
JsonRoutineLoader().getRoutine(R.raw.starting_stretching_flexibility_routine)
} else {
JsonRoutineLoader().getRoutine(R.raw.molding_mobility_flexibility_routine)
}
Expand Down Expand Up @@ -72,6 +74,9 @@ object RoutineStream {
routine = JsonRoutineLoader().getRoutine(R.raw.bodyweight_fitness_recommended_routine)
}
1 -> {
routine = JsonRoutineLoader().getRoutine(R.raw.starting_stretching_flexibility_routine)
}
2 -> {
routine = JsonRoutineLoader().getRoutine(R.raw.molding_mobility_flexibility_routine)
}
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/kotlin/com/bodyweight/fitness/stream/Stream.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ object Stream {

private val menuSubject = PublishSubject.create<Int>()
private val drawerSubject = PublishSubject.create<Int>()
private val restTimerSubject = PublishSubject.create<Int>()
private val loggedSecondsSubject = PublishSubject.create<Int>()
private val loggedSetRepsSubject = PublishSubject.create<SetReps>()

Expand All @@ -46,6 +47,7 @@ object Stream {
* Observables that should be re-emitted should be functions rather than values.
*/
val menuObservable: Observable<Int> get() = menuSubject
val restTimerObservable: Observable<Int> get() = restTimerSubject
val loggedSecondsObservable: Observable<Int> get() = loggedSecondsSubject
val loggedSetRepsObservable: Observable<SetReps> get() = loggedSetRepsSubject

Expand Down Expand Up @@ -78,6 +80,10 @@ object Stream {
menuSubject.onNext(toolbarMenuItemId)
}

fun setRestTimer() {
restTimerSubject.onNext(0)
}

fun setDrawer(drawerMenuItemId: Int) {
currentDrawerId = drawerMenuItemId

Expand Down
65 changes: 65 additions & 0 deletions app/src/main/kotlin/com/bodyweight/fitness/utils/Preferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,71 @@ object Preferences {
.commit()
}

var showRestTimer: Boolean
get() {
return getSharedPreferences()
.getBoolean(Constants.preferencesShowRestTimer, true)
}

set(value) {
getSharedPreferences()
.edit()
.putBoolean(Constants.preferencesShowRestTimer, value)
.commit()
}

var showRestTimerAfterWarmup: Boolean
get() {
return getSharedPreferences()
.getBoolean(Constants.preferencesShowRestTimerAfterWarmup, false)
}

set(value) {
getSharedPreferences()
.edit()
.putBoolean(Constants.preferencesShowRestTimerAfterWarmup, value)
.commit()
}

var showRestTimerAfterBodylineDrills: Boolean
get() {
return getSharedPreferences()
.getBoolean(Constants.preferencesShowRestTimerAfterBodylineDrills, true)
}

set(value) {
getSharedPreferences()
.edit()
.putBoolean(Constants.preferencesShowRestTimerAfterBodylineDrills, value)
.commit()
}

var showRestTimerAfterFlexibilityExercises: Boolean
get() {
return getSharedPreferences()
.getBoolean(Constants.preferencesShowRestTimerAfterFlexibilityExercises, false)
}

set(value) {
getSharedPreferences()
.edit()
.putBoolean(Constants.preferencesShowRestTimerAfterFlexibilityExercises, value)
.commit()
}

var restTimerDefaultSeconds: Int
get() {
return getSharedPreferences()
.getString(Constants.preferencesRestTimerDefaultSeconds, "60").toInt()
}

set(value) {
getSharedPreferences()
.edit()
.putString(Constants.preferencesRestTimerDefaultSeconds, value.toString())
.commit()
}

val weightMeasurementUnit: WeightMeasurementUnit
get() {
val value = getSharedPreferences().getString(Constants.preferencesWeightMeasurementUnitsKey, "kg")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.util.AttributeSet
import com.bodyweight.fitness.*
import com.bodyweight.fitness.model.RepositoryCategory
import com.bodyweight.fitness.model.RepositoryRoutine
import com.bodyweight.fitness.model.Routine
import com.bodyweight.fitness.repository.Repository
import com.bodyweight.fitness.stream.RoutineStream
import com.bodyweight.fitness.stream.Stream
Expand Down Expand Up @@ -45,11 +46,21 @@ class HomeViewPresenter : AbstractPresenter() {
RoutineStream.routineObservable()
.bindToLifecycle(view)
.subscribe {
updateShortDescription(it)
updateTodaysProgress()
updateStatistics()
}
}

fun updateShortDescription(routine: Routine) {
val view = (getView() as HomeView)

view.setShortDescription(
title = routine.title,
shortDescription = routine.shortDescription,
url = routine.url)
}

fun updateTodaysProgress() {
val view = (getView() as HomeView)

Expand Down Expand Up @@ -186,6 +197,14 @@ class HomeViewPresenter : AbstractPresenter() {
putExtra(Intent.EXTRA_EMAIL, "[email protected]")
}, "Send Email"))
}

fun readMoreAboutRoutine() {
val routine = RoutineStream.routine

context().startActivity(Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse(routine.url)
})
}
}

open class HomeView : AbstractView {
Expand Down Expand Up @@ -213,6 +232,15 @@ open class HomeView : AbstractView {
send_email.setOnClickListener {
(presenter as HomeViewPresenter).sendEmail()
}

read_more_about_routine.setOnClickListener {
(presenter as HomeViewPresenter).readMoreAboutRoutine()
}
}

fun setShortDescription(title: String, shortDescription: String, url: String) {
routine_title.text = title
short_description.text = shortDescription
}

fun setStartWorkoutButtonTitle(title: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class ProgressGeneralViewPresenter : AbstractPresenter() {
val layout = parent.inflate(R.layout.activity_progress_general_exercise)

layout.exercise_title.text = exercise.title
layout.category_title.text = exercise.category?.title
layout.category_title.text = exercise.category?.title + " - " + exercise.section?.title

parent.addView(layout)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package com.bodyweight.fitness.view.workout

import android.content.Context
import android.util.AttributeSet
import android.view.View

import com.bodyweight.fitness.setGone
import com.bodyweight.fitness.setInvisible
import com.bodyweight.fitness.setVisible
import com.bodyweight.fitness.stream.RoutineStream
import com.bodyweight.fitness.stream.Stream
import com.bodyweight.fitness.utils.Preferences
import com.bodyweight.fitness.view.AbstractPresenter
import com.bodyweight.fitness.view.AbstractView

Expand All @@ -25,6 +28,29 @@ class NavigationPresenter : AbstractPresenter() {
view.showTimerOrRepsLogger(it.isTimedSet)
view.showPreviousNextButtons(it.isPrevious, it.isNext)
}


Stream.restTimerObservable
.bindToLifecycle(view)
.subscribe {
restoreView(view)
}

Stream.loggedSetRepsObservable
.bindToLifecycle(view)
.subscribe {
val view = (view as NavigationView)

showRestTimer(view)
}

Stream.loggedSecondsObservable
.bindToLifecycle(view)
.subscribe {
val view = (view as NavigationView)

showRestTimer(view)
}
}

override fun restoreView(view: AbstractView) {
Expand All @@ -38,6 +64,30 @@ class NavigationPresenter : AbstractPresenter() {
view.showPreviousNextButtons(exercise.isPrevious, exercise.isNext)
}

fun showRestTimer(view: NavigationView) {
if (Preferences.showRestTimer) {
val section = RoutineStream.exercise.section!!

if (section.sectionId == "section0") {
if (Preferences.showRestTimerAfterWarmup) {
view.showRestTimer()
}
} else if (section.sectionId == "section1") {
if (Preferences.showRestTimerAfterBodylineDrills) {
view.showRestTimer()
}
} else {
if (RoutineStream.routine.routineId != "routine0") {
if (Preferences.showRestTimerAfterFlexibilityExercises) {
view.showRestTimer()
}
} else {
view.showRestTimer()
}
}
}
}

fun previousExercise() {
if (RoutineStream.exercise.isPrevious) {
RoutineStream.exercise = RoutineStream.exercise.previous!!
Expand Down Expand Up @@ -68,13 +118,25 @@ open class NavigationView : AbstractView {
}
}

fun showRestTimer() {
rest_timer_view.setVisible()
timer_view.setGone()
reps_logger_view.setGone()
}

fun showTimerOrRepsLogger(isTimed: Boolean) {
if (isTimed) {
timer_view.setVisible()
reps_logger_view.setGone()
if (!RestTimerShared.isPlaying) {
if (isTimed) {
rest_timer_view.setGone()
timer_view.setVisible()
reps_logger_view.setGone()
} else {
rest_timer_view.setGone()
timer_view.setGone()
reps_logger_view.setVisible()
}
} else {
timer_view.setGone()
reps_logger_view.setVisible()
showRestTimer()
}
}

Expand Down
Loading

0 comments on commit 2d21e09

Please sign in to comment.