From e22d8208e04a0494b401fd6b7b574780fb054260 Mon Sep 17 00:00:00 2001 From: Damian Mazurkiewicz Date: Sun, 23 Oct 2016 17:25:11 +0100 Subject: [PATCH] WIP: Bottom Navigation (#43) - Bottom Navigation & Bug Fixes --- app/build.gradle | 43 ++-- app/src/main/AndroidManifest.xml | 25 +-- .../fitness/dialog/ProgressDialog.kt | 12 +- .../com/bodyweight/fitness/stream/Stream.kt | 5 +- .../com/bodyweight/fitness/ui/MainActivity.kt | 122 +---------- .../bodyweight/fitness/ui/ProgressActivity.kt | 2 +- ...ettingsActivity.kt => SettingsFragment.kt} | 33 --- .../bodyweight/fitness/ui/WorkoutActivity.kt | 139 ++++++++++++ .../fitness/view/ContentViewPresenter.kt | 21 +- .../fitness/view/HeaderViewPresenter.kt | 57 ----- .../fitness/view/HomeViewPresenter.kt | 32 ++- .../fitness/view/ToolbarViewPresenter.kt | 57 +---- .../view/{ => workout}/ActionViewPresenter.kt | 41 +--- .../{ => workout}/NavigationViewPresenter.kt | 4 +- .../{ => workout}/PreviewViewPresenter.kt | 4 +- .../{ => workout}/RepsLoggerViewPresenter.kt | 4 +- .../view/{ => workout}/TimerViewPresenter.kt | 11 +- app/src/main/res/drawable/action_settings.xml | 22 ++ app/src/main/res/layout-port/view_timer.xml | 12 +- .../main/res/layout/activity_dashboard.xml | 31 ++- app/src/main/res/layout/activity_main.xml | 37 ++-- .../main/res/layout/activity_main_header.xml | 39 ---- app/src/main/res/layout/activity_progress.xml | 68 +++--- .../res/layout/activity_progress_exercise.xml | 198 ++++++++++-------- app/src/main/res/layout/activity_workout.xml | 32 +++ app/src/main/res/layout/view_action.xml | 4 +- app/src/main/res/layout/view_home.xml | 58 +++++ app/src/main/res/layout/view_home_support.xml | 57 +++++ app/src/main/res/layout/view_timer.xml | 12 +- app/src/main/res/layout/view_toolbar.xml | 72 ++----- app/src/main/res/layout/view_workout.xml | 7 +- app/src/main/res/menu/menu_drawer.xml | 34 --- app/src/main/res/values-v21/styles.xml | 80 +------ app/src/main/res/values/colors.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- app/src/main/res/values/styles.xml | 67 ++---- app/src/main/res/xml/tabs.xml | 17 ++ app/src/pro/res/layout/view_home_support.xml | 15 ++ build.gradle | 2 +- 39 files changed, 690 insertions(+), 790 deletions(-) rename app/src/main/kotlin/com/bodyweight/fitness/ui/{SettingsActivity.kt => SettingsFragment.kt} (55%) create mode 100644 app/src/main/kotlin/com/bodyweight/fitness/ui/WorkoutActivity.kt delete mode 100644 app/src/main/kotlin/com/bodyweight/fitness/view/HeaderViewPresenter.kt rename app/src/main/kotlin/com/bodyweight/fitness/view/{ => workout}/ActionViewPresenter.kt (82%) rename app/src/main/kotlin/com/bodyweight/fitness/view/{ => workout}/NavigationViewPresenter.kt (94%) rename app/src/main/kotlin/com/bodyweight/fitness/view/{ => workout}/PreviewViewPresenter.kt (91%) rename app/src/main/kotlin/com/bodyweight/fitness/view/{ => workout}/RepsLoggerViewPresenter.kt (97%) rename app/src/main/kotlin/com/bodyweight/fitness/view/{ => workout}/TimerViewPresenter.kt (97%) create mode 100644 app/src/main/res/drawable/action_settings.xml delete mode 100644 app/src/main/res/layout/activity_main_header.xml create mode 100644 app/src/main/res/layout/activity_workout.xml create mode 100644 app/src/main/res/layout/view_home_support.xml delete mode 100644 app/src/main/res/menu/menu_drawer.xml create mode 100644 app/src/main/res/xml/tabs.xml create mode 100644 app/src/pro/res/layout/view_home_support.xml diff --git a/app/build.gradle b/app/build.gradle index 9eafb5f7..c3a7c554 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,16 +8,15 @@ apply plugin: 'io.fabric' android { dexOptions { - incremental false maxProcessCount 4 } - compileSdkVersion 23 + compileSdkVersion 25 buildToolsVersion '23.0.3' defaultConfig { applicationId 'com.bodyweight.fitness' minSdkVersion 16 - targetSdkVersion 23 + targetSdkVersion 25 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } compileOptions { @@ -40,14 +39,14 @@ android { productFlavors { pro { applicationId 'com.bodyweight.fitness.pro' - versionCode 135 - versionName "1.3.5" + versionCode 136 + versionName "1.3.6" } free { applicationId 'com.bodyweight.fitness.free' - versionCode 135 - versionName "1.3.5" + versionCode 136 + versionName "1.3.6" } } buildTypes { @@ -83,15 +82,15 @@ dependencies { testCompile 'org.jetbrains.spek:spek:1.0.9' testCompile 'org.mockito:mockito-all:2.0.2-beta' - androidTestCompile 'com.android.support:support-annotations:23.3.0' + androidTestCompile "com.android.support:support-annotations:$support_version" androidTestCompile 'com.android.support.test:runner:0.5' androidTestCompile 'com.android.support.test:rules:0.5' androidTestCompile "com.android.support.test.espresso:espresso-core:2.2.2" - compile 'com.android.support:support-v4:23.3.0' - compile 'com.android.support:recyclerview-v7:23.3.0' - compile 'com.android.support:cardview-v7:23.3.0' - compile 'com.android.support:design:23.3.0' + compile "com.android.support:support-v4:$support_version" + compile "com.android.support:recyclerview-v7:$support_version" + compile "com.android.support:cardview-v7:$support_version" + compile "com.android.support:design:$support_version" compile 'com.google.code.gson:gson:2.4' @@ -99,19 +98,20 @@ dependencies { compile 'net.danlew:android.joda:2.9.3' compile 'com.netflix.rxjava:rxjava-core:0.20.7' - compile 'io.reactivex:rxandroid:1.2.0' - compile 'io.reactivex:rxjava:1.1.5' + compile 'io.reactivex:rxandroid:1.2.1' + compile 'io.reactivex:rxjava:1.2.1' - compile 'com.trello:rxlifecycle:0.6.1' - compile 'com.trello:rxlifecycle-components:0.6.1' - compile 'com.trello:rxlifecycle-kotlin:0.6.1' + compile 'com.trello:rxlifecycle:0.8.0' + compile 'com.trello:rxlifecycle-components:0.8.0' + compile 'com.trello:rxlifecycle-kotlin:0.8.0' - compile 'com.robinhood.spark:spark:1.1.0' + compile 'com.robinhood.spark:spark:1.1.2' - compile 'com.github.johnkil.android-robototextview:robototextview:2.5.0' + compile 'com.roughike:bottom-bar:2.0.2' + compile 'com.github.johnkil.android-robototextview:robototextview:2.5.1' compile 'com.gordonwong:material-sheet-fab:1.2.1' compile 'io.github.kobakei:ratethisapp:1.0.3' - compile 'com.github.paolorotolo:appintro:4.0.0' + compile 'com.github.paolorotolo:appintro:4.1.0' compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') { transitive = true; @@ -122,7 +122,8 @@ dependencies { } buildscript { - ext.kotlin_version = '1.0.1-2' + ext.support_version = '25.0.0' + ext.kotlin_version = '1.0.4' repositories { mavenCentral() maven { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6846746f..ffd15fa6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -45,9 +45,8 @@ + android:name=".ui.DashboardActivity" + android:parentActivityName=".ui.WorkoutActivity" + android:launchMode="singleTask"> + android:value=".ui.WorkoutActivity" /> + android:name=".ui.ProgressActivity" + android:parentActivityName=".ui.MainActivity"> + android:value=".ui.MainActivity" /> + android:name=".ui.ProgressExerciseActivity" + android:parentActivityName=".ui.ProgressExerciseActivity"> + android:value=".ui.ProgressExerciseActivity" /> { - startActivity(Intent(Intent.ACTION_VIEW).apply { - data = Uri.parse(Constants.googlePlayUrl) - }) - } - - R.id.action_menu_settings -> { - startActivity(Intent(applicationContext, SettingsActivity::class.java)) - } - - else -> { - navigation_view.setCheckedItem(it) - } - } + invalidateOptionsMenu() } if (!Preferences.introductionShown) { @@ -79,32 +46,6 @@ class MainActivity : RxAppCompatActivity(), SharedPreferences.OnSharedPreference } } - override fun onResume() { - super.onResume() - - keepScreenOnWhenAppIsRunning() - - UiEvent.dialogObservable - .bindUntilEvent(this, ActivityEvent.PAUSE) - .subscribe { - if (it.dialogType === DialogType.MainActivityLogWorkout) { - val bundle = Bundle() - bundle.putString(Constants.exerciseId, it.exerciseId) - - val logWorkoutDialog = LogWorkoutDialog() - logWorkoutDialog.arguments = bundle - logWorkoutDialog.show(supportFragmentManager, "logWorkoutDialog") - } else if (it.dialogType === DialogType.Progress) { - val bundle = Bundle() - bundle.putString(Constants.exerciseId, it.exerciseId) - - val progressDialog = ProgressDialog() - progressDialog.arguments = bundle - progressDialog.show(supportFragmentManager, "progressDialog") - } - } - } - override fun onStart() { super.onStart() @@ -115,8 +56,6 @@ class MainActivity : RxAppCompatActivity(), SharedPreferences.OnSharedPreference override fun onStop() { super.onStop() - clearFlagKeepScreenOn() - Repository.realm.close() } @@ -130,60 +69,21 @@ class MainActivity : RxAppCompatActivity(), SharedPreferences.OnSharedPreference menu?.clear() when (Stream.currentDrawerId) { - R.id.action_menu_workout -> menuInflater.inflate(R.menu.menu_workout, menu) R.id.action_menu_workout_log -> menuInflater.inflate(R.menu.menu_log_workout, menu) } return super.onPrepareOptionsMenu(menu) } - override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) { - keepScreenOnWhenAppIsRunning() - } - private fun setToolbar() { setSupportActionBar(toolbar) supportActionBar?.let { it.elevation = 0f - it.setHomeButtonEnabled(true) - it.setDisplayHomeAsUpEnabled(true) - } - - val actionBarDrawerToggle = ActionBarDrawerToggle( - this, - drawer_layout, - toolbar, - R.string.navigation_drawer_open, - R.string.navigation_drawer_close) - - drawer_layout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START) - drawer_layout.addDrawerListener(actionBarDrawerToggle) - - actionBarDrawerToggle.syncState() - - navigation_view.setNavigationItemSelectedListener { item -> - drawer_layout.closeDrawers() - - Stream.setDrawer(item.itemId) - - if (item.itemId == R.id.action_menu_support_developer || item.itemId == R.id.action_menu_settings) { - return@setNavigationItemSelectedListener false - } else { - return@setNavigationItemSelectedListener true - } } - } - private fun keepScreenOnWhenAppIsRunning() { - if (Preferences.keepScreenOnWhenAppIsRunning()) { - window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) - } else { - clearFlagKeepScreenOn() + bottomBar.setOnTabSelectListener { + Stream.setDrawer(it) } } - - private fun clearFlagKeepScreenOn() { - window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) - } } diff --git a/app/src/main/kotlin/com/bodyweight/fitness/ui/ProgressActivity.kt b/app/src/main/kotlin/com/bodyweight/fitness/ui/ProgressActivity.kt index 3c7c3d8f..cb08a79a 100644 --- a/app/src/main/kotlin/com/bodyweight/fitness/ui/ProgressActivity.kt +++ b/app/src/main/kotlin/com/bodyweight/fitness/ui/ProgressActivity.kt @@ -59,7 +59,7 @@ class ProgressActivity : RxAppCompatActivity() { } tablayout.setupWithViewPager(view_progress_pager) - tablayout.setOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { + tablayout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { override fun onTabSelected(tab: TabLayout.Tab) { view_progress_pager.setCurrentItem(tab.position, true) } diff --git a/app/src/main/kotlin/com/bodyweight/fitness/ui/SettingsActivity.kt b/app/src/main/kotlin/com/bodyweight/fitness/ui/SettingsFragment.kt similarity index 55% rename from app/src/main/kotlin/com/bodyweight/fitness/ui/SettingsActivity.kt rename to app/src/main/kotlin/com/bodyweight/fitness/ui/SettingsFragment.kt index 39fa4cac..81bb499c 100644 --- a/app/src/main/kotlin/com/bodyweight/fitness/ui/SettingsActivity.kt +++ b/app/src/main/kotlin/com/bodyweight/fitness/ui/SettingsFragment.kt @@ -4,43 +4,10 @@ import android.content.SharedPreferences import android.os.Bundle import android.preference.ListPreference import android.preference.PreferenceFragment -import android.support.v7.app.ActionBar -import android.support.v7.app.AppCompatActivity -import android.view.MenuItem import com.bodyweight.fitness.Constants import com.bodyweight.fitness.R -class SettingsActivity : AppCompatActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - supportActionBar?.let { - it.setTitle(R.string.action_settings) - it.elevation = 0f - it.displayOptions = ActionBar.DISPLAY_SHOW_HOME or ActionBar.DISPLAY_HOME_AS_UP or ActionBar.DISPLAY_SHOW_TITLE - it.setHomeButtonEnabled(true) - it.setDisplayHomeAsUpEnabled(true) - } - - if (fragmentManager.findFragmentById(android.R.id.content) == null) { - fragmentManager.beginTransaction().add(android.R.id.content, SettingsFragment()).commit() - } - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - when (item.itemId) { - android.R.id.home -> { - onBackPressed() - - return true - } - } - - return super.onOptionsItemSelected(item) - } -} - class SettingsFragment : PreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/kotlin/com/bodyweight/fitness/ui/WorkoutActivity.kt b/app/src/main/kotlin/com/bodyweight/fitness/ui/WorkoutActivity.kt new file mode 100644 index 00000000..6ac15b95 --- /dev/null +++ b/app/src/main/kotlin/com/bodyweight/fitness/ui/WorkoutActivity.kt @@ -0,0 +1,139 @@ +package com.bodyweight.fitness.ui + +import android.content.Context +import android.content.Intent +import android.content.SharedPreferences +import android.os.Bundle +import android.support.v7.app.ActionBar +import android.view.Menu +import android.view.MenuItem +import android.view.WindowManager +import com.bodyweight.fitness.Constants + +import com.bodyweight.fitness.R +import com.bodyweight.fitness.dialog.LogWorkoutDialog +import com.bodyweight.fitness.dialog.ProgressDialog +import com.bodyweight.fitness.model.DialogType +import com.bodyweight.fitness.stream.RoutineStream +import com.bodyweight.fitness.stream.Stream +import com.bodyweight.fitness.stream.UiEvent +import com.bodyweight.fitness.utils.Preferences + +import com.trello.rxlifecycle.android.ActivityEvent +import com.trello.rxlifecycle.components.support.RxAppCompatActivity +import com.trello.rxlifecycle.kotlin.bindUntilEvent + +import kotlinx.android.synthetic.main.activity_dashboard.* + +class WorkoutActivity : RxAppCompatActivity(), SharedPreferences.OnSharedPreferenceChangeListener { + companion object { + fun start(context: Context) { + context.startActivity(Intent(context, WorkoutActivity::class.java)) + } + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + setContentView(R.layout.activity_workout) + setToolbar() + + keepScreenOnWhenAppIsRunning() + + Stream.menuObservable + .bindUntilEvent(this, ActivityEvent.DESTROY) + .filter { it == R.id.action_dashboard } + .subscribe { + startActivity(Intent(this, DashboardActivity::class.java)) + } + + RoutineStream.exerciseObservable().bindUntilEvent(this, ActivityEvent.DESTROY).subscribe { exercise -> + supportActionBar?.let { toolbar -> + toolbar.title = exercise.title + + exercise.section?.let { + toolbar.subtitle = it.title + " " + exercise.description + } + } + } + } + + override fun onResume() { + super.onResume() + + keepScreenOnWhenAppIsRunning() + + UiEvent.dialogObservable + .bindUntilEvent(this, ActivityEvent.PAUSE) + .subscribe { + if (it.dialogType === DialogType.MainActivityLogWorkout) { + val bundle = Bundle() + bundle.putString(Constants.exerciseId, it.exerciseId) + + val logWorkoutDialog = LogWorkoutDialog() + logWorkoutDialog.arguments = bundle + logWorkoutDialog.show(supportFragmentManager, "logWorkoutDialog") + } else if (it.dialogType === DialogType.Progress) { + val bundle = Bundle() + bundle.putString(Constants.exerciseId, it.exerciseId) + + val progressDialog = ProgressDialog() + progressDialog.arguments = bundle + progressDialog.show(supportFragmentManager, "progressDialog") + } + } + } + + override fun onStop() { + super.onStop() + + clearFlagKeepScreenOn() + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + Stream.setMenu(item.itemId) + + when (item.itemId) { + android.R.id.home -> { + supportFinishAfterTransition() + + return true + } + } + + return super.onOptionsItemSelected(item) + } + + override fun onPrepareOptionsMenu(menu: Menu?): Boolean { + menuInflater.inflate(R.menu.menu_workout, menu) + + return super.onPrepareOptionsMenu(menu) + } + + override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) { + keepScreenOnWhenAppIsRunning() + } + + private fun setToolbar() { + setSupportActionBar(toolbar) + + supportActionBar?.let { + it.elevation = 0f + it.displayOptions = ActionBar.DISPLAY_SHOW_HOME or ActionBar.DISPLAY_HOME_AS_UP or ActionBar.DISPLAY_SHOW_TITLE + it.setHomeButtonEnabled(true) + it.setDisplayHomeAsUpEnabled(true) + } + } + + private fun keepScreenOnWhenAppIsRunning() { + if (Preferences.keepScreenOnWhenAppIsRunning()) { + window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + } else { + clearFlagKeepScreenOn() + } + } + + private fun clearFlagKeepScreenOn() { + window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) + } +} diff --git a/app/src/main/kotlin/com/bodyweight/fitness/view/ContentViewPresenter.kt b/app/src/main/kotlin/com/bodyweight/fitness/view/ContentViewPresenter.kt index 36d56fb5..078c8ec7 100644 --- a/app/src/main/kotlin/com/bodyweight/fitness/view/ContentViewPresenter.kt +++ b/app/src/main/kotlin/com/bodyweight/fitness/view/ContentViewPresenter.kt @@ -17,11 +17,6 @@ class ContentPresenter : AbstractPresenter() { Stream.drawerObservable() .bindToLifecycle(view) - .filter { - it.equals(R.id.action_menu_home) - || it.equals(R.id.action_menu_workout) - || it.equals(R.id.action_menu_workout_log) - } .subscribe { setContent(it) } @@ -38,8 +33,8 @@ class ContentPresenter : AbstractPresenter() { when (id) { R.id.action_menu_home -> view.showHome() - R.id.action_menu_workout -> view.showWorkout() R.id.action_menu_workout_log -> view.showCalendar() + R.id.action_menu_settings -> view.showSettings() } } } @@ -53,19 +48,19 @@ open class ContentView : AbstractView { fun showHome() { view_home.setVisible() - view_workout.setGone() view_calendar.setGone() + view_settings.setGone() } - fun showWorkout() { + fun showCalendar() { view_home.setGone() - view_workout.setVisible() - view_calendar.setGone() + view_calendar.setVisible() + view_settings.setGone() } - fun showCalendar() { + fun showSettings() { view_home.setGone() - view_workout.setGone() - view_calendar.setVisible() + view_calendar.setGone() + view_settings.setVisible() } } \ No newline at end of file diff --git a/app/src/main/kotlin/com/bodyweight/fitness/view/HeaderViewPresenter.kt b/app/src/main/kotlin/com/bodyweight/fitness/view/HeaderViewPresenter.kt deleted file mode 100644 index 8c7b0ac2..00000000 --- a/app/src/main/kotlin/com/bodyweight/fitness/view/HeaderViewPresenter.kt +++ /dev/null @@ -1,57 +0,0 @@ -package com.bodyweight.fitness.view - -import android.content.Context -import android.util.AttributeSet -import com.bodyweight.fitness.extension.debug - -import com.bodyweight.fitness.model.Routine -import com.bodyweight.fitness.stream.RoutineStream - -import com.trello.rxlifecycle.kotlin.bindToLifecycle -import kotlinx.android.synthetic.main.activity_main_header.view.* - -open class HeaderPresenter : AbstractPresenter() { - override fun bindView(view: AbstractView) { - super.bindView(view) - - debug("HeaderPresenter = bindView") - - /** - * We do not use bindView here as Navigation Drawer lifecycle is absolutely fucked. - */ - RoutineStream.routineObservable() - .subscribe { - setText(it) - debug("HeaderPresenter: Set title = " + it.title) - } - } - - override fun restoreView(view: AbstractView) { - super.restoreView(view) - - debug("HeaderPresenter = restoreView") - - setText(RoutineStream.routine) - } - - override fun getView(): HeaderView { - return (mView as HeaderView) - } - - fun setText(routine: Routine) { - getView().setText(routine.title, routine.subtitle) - } -} - -open class HeaderView : AbstractView { - override var presenter: AbstractPresenter = HeaderPresenter() - - constructor(context: Context) : super(context) - constructor(context: Context, attrs: AttributeSet) : super(context, attrs) - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) - - open fun setText(title: String, subtitle: String) { - routine_title.text = title - routine_subtitle.text = subtitle - } -} \ No newline at end of file diff --git a/app/src/main/kotlin/com/bodyweight/fitness/view/HomeViewPresenter.kt b/app/src/main/kotlin/com/bodyweight/fitness/view/HomeViewPresenter.kt index 714d68b7..533afa8f 100644 --- a/app/src/main/kotlin/com/bodyweight/fitness/view/HomeViewPresenter.kt +++ b/app/src/main/kotlin/com/bodyweight/fitness/view/HomeViewPresenter.kt @@ -2,6 +2,7 @@ package com.bodyweight.fitness.view import android.content.Context import android.content.Intent +import android.net.Uri import android.text.format.DateUtils import android.util.AttributeSet @@ -12,11 +13,13 @@ import com.bodyweight.fitness.repository.Repository import com.bodyweight.fitness.stream.RoutineStream import com.bodyweight.fitness.stream.Stream import com.bodyweight.fitness.ui.ProgressActivity +import com.bodyweight.fitness.ui.WorkoutActivity import com.trello.rxlifecycle.kotlin.bindToLifecycle import kotlinx.android.synthetic.main.view_home.view.* import kotlinx.android.synthetic.main.view_home_category.view.* +import kotlinx.android.synthetic.main.view_home_support.view.* import org.joda.time.DateTime @@ -102,7 +105,7 @@ class HomeViewPresenter : AbstractPresenter() { return "Go to Workout" } - return "Start Working Out" + return "Start Workout" } private fun getPreviousWorkoutLabel(): String { @@ -157,7 +160,7 @@ class HomeViewPresenter : AbstractPresenter() { } fun startWorkout() { - Stream.setDrawer(R.id.action_menu_workout) + WorkoutActivity.start(context()) } fun todaysWorkoutLog() { @@ -166,6 +169,23 @@ class HomeViewPresenter : AbstractPresenter() { context().startActivity(Intent(context(), ProgressActivity::class.java) .putExtra(Constants.primaryKeyRoutineId, routineId)) } + + fun supportDeveloper() { + context().startActivity(Intent(Intent.ACTION_VIEW).apply { + data = Uri.parse(Constants.googlePlayUrl) + }) + } + + fun sendEmail() { + context().startActivity(Intent.createChooser(Intent( + Intent.ACTION_SENDTO, + Uri.fromParts("mailto", "damian@mazur.io", null) + ).apply { + putExtra(Intent.EXTRA_SUBJECT, "Bodyweight Fitness App for Android - Feedback") + putExtra(Intent.EXTRA_TEXT, "") + putExtra(Intent.EXTRA_EMAIL, "damian@mazur.io") + }, "Send Email")) + } } open class HomeView : AbstractView { @@ -185,6 +205,14 @@ open class HomeView : AbstractView { todays_workout_log.setOnClickListener { (presenter as HomeViewPresenter).todaysWorkoutLog() } + + support_developer.setOnClickListener { + (presenter as HomeViewPresenter).supportDeveloper() + } + + send_email.setOnClickListener { + (presenter as HomeViewPresenter).sendEmail() + } } fun setStartWorkoutButtonTitle(title: String) { diff --git a/app/src/main/kotlin/com/bodyweight/fitness/view/ToolbarViewPresenter.kt b/app/src/main/kotlin/com/bodyweight/fitness/view/ToolbarViewPresenter.kt index 75efd004..345412de 100644 --- a/app/src/main/kotlin/com/bodyweight/fitness/view/ToolbarViewPresenter.kt +++ b/app/src/main/kotlin/com/bodyweight/fitness/view/ToolbarViewPresenter.kt @@ -10,7 +10,6 @@ import android.widget.Toast import com.bodyweight.fitness.R import com.bodyweight.fitness.adapter.ToolbarSpinnerAdapter import com.bodyweight.fitness.model.CalendarDay -import com.bodyweight.fitness.model.Exercise import com.bodyweight.fitness.setGone import com.bodyweight.fitness.setVisible import com.bodyweight.fitness.stream.RoutineStream @@ -27,13 +26,6 @@ class ToolbarPresenter : AbstractPresenter() { override fun bindView(view: AbstractView) { super.bindView(view) - RoutineStream.exerciseObservable() - .bindToLifecycle(view) - .filter { Stream.currentDrawerId.equals(R.id.action_menu_workout) } - .subscribe { - setToolbarForWorkout(it) - } - Stream.calendarDayObservable() .bindToLifecycle(view) .filter { Stream.currentDrawerId.equals(R.id.action_menu_workout_log) } @@ -43,11 +35,6 @@ class ToolbarPresenter : AbstractPresenter() { Stream.drawerObservable() .bindToLifecycle(view) - .filter { - it.equals(R.id.action_menu_home) - || it.equals(R.id.action_menu_workout) - || it.equals(R.id.action_menu_workout_log) - } .subscribe { setToolbar() } @@ -65,13 +52,13 @@ class ToolbarPresenter : AbstractPresenter() { setToolbarForHome() } - R.id.action_menu_workout -> { - setToolbarForWorkout(RoutineStream.exercise) - } - R.id.action_menu_workout_log -> { setToolbarForWorkoutLog(Stream.currentCalendarDay) } + + R.id.action_menu_settings -> { + setToolbarForSettings() + } } } @@ -112,14 +99,6 @@ class ToolbarPresenter : AbstractPresenter() { } } - private fun setToolbarForWorkout(exercise: Exercise) { - val view: ToolbarView = (mView as ToolbarView) - - view.setTitle(exercise.title) - view.setSubtitle(exercise.section!!.title) - view.setDescription(exercise.description) - } - private fun setToolbarForWorkoutLog(calendarDay: CalendarDay?) { if (calendarDay == null) { setDateTimeSingleTitle(DateTime()) @@ -128,6 +107,11 @@ class ToolbarPresenter : AbstractPresenter() { } } + private fun setToolbarForSettings() { + val view: ToolbarView = (mView as ToolbarView) + view.setSingleTitle("Settings") + } + private fun setDateTimeSingleTitle(dateTime: DateTime) { val view: ToolbarView = (mView as ToolbarView) @@ -144,7 +128,6 @@ class ToolbarView : AbstractView { fun setSpinner(title: String, subtitle: String) { toolbar_spinner_layout.setVisible() - toolbar_layout.setGone() toolbar_spinner_title.text = title toolbar_spinner_subtitle.text = subtitle @@ -155,30 +138,8 @@ class ToolbarView : AbstractView { fun setSingleTitle(text: String) { toolbar_spinner_layout.setGone() - toolbar_layout.setGone() toolbar.title = text toolbar.subtitle = "" } - - fun setTitle(text: String) { - toolbar_spinner_layout.setGone() - toolbar_layout.setVisible() - - toolbar_exercise_title.text = text - } - - fun setSubtitle(text: String) { - toolbar_spinner_layout.setGone() - toolbar_layout.setVisible() - - toolbar_section_title.text = text - } - - fun setDescription(text: String) { - toolbar_spinner_layout.setGone() - toolbar_layout.setVisible() - - toolbar_exercise_description.text = text - } } \ No newline at end of file diff --git a/app/src/main/kotlin/com/bodyweight/fitness/view/ActionViewPresenter.kt b/app/src/main/kotlin/com/bodyweight/fitness/view/workout/ActionViewPresenter.kt similarity index 82% rename from app/src/main/kotlin/com/bodyweight/fitness/view/ActionViewPresenter.kt rename to app/src/main/kotlin/com/bodyweight/fitness/view/workout/ActionViewPresenter.kt index 44764307..a38207ee 100644 --- a/app/src/main/kotlin/com/bodyweight/fitness/view/ActionViewPresenter.kt +++ b/app/src/main/kotlin/com/bodyweight/fitness/view/workout/ActionViewPresenter.kt @@ -1,4 +1,4 @@ -package com.bodyweight.fitness.view +package com.bodyweight.fitness.view.workout import android.content.ActivityNotFoundException import android.content.Context @@ -17,6 +17,8 @@ import com.bodyweight.fitness.model.DialogType import com.bodyweight.fitness.repository.Repository import com.bodyweight.fitness.stream.* import com.bodyweight.fitness.ui.ProgressActivity +import com.bodyweight.fitness.view.AbstractPresenter +import com.bodyweight.fitness.view.AbstractView import com.bodyweight.fitness.view.widget.ActionButton import com.gordonwong.materialsheetfab.MaterialSheetFab @@ -43,21 +45,6 @@ class ActionPresenter : AbstractPresenter() { } } - Stream.drawerObservable() - .bindToLifecycle(view) - .filter { - it.equals(R.id.action_menu_home) - || it.equals(R.id.action_menu_workout) - || it.equals(R.id.action_menu_workout_log) - } - .subscribe { - if (it == R.id.action_menu_workout) { - view.showActionButtons() - } else { - view.hideActionButtons() - } - } - Stream.loggedSecondsObservable .bindToLifecycle(view) .subscribe { @@ -75,18 +62,6 @@ class ActionPresenter : AbstractPresenter() { } } - override fun restoreView(view: AbstractView) { - super.restoreView(view) - - val view = (mView as ActionView) - - if (Stream.currentDrawerId == R.id.action_menu_workout) { - view.showActionButtons() - } else { - view.hideActionButtons() - } - } - fun logWorkout() { UiEvent.showDialog(DialogType.MainActivityLogWorkout, RoutineStream.exercise.exerciseId) } @@ -176,16 +151,6 @@ open class ActionView : AbstractView { } } - fun showActionButtons() { - action_view_log_workout_button.visibility = View.VISIBLE - action_view_action_button.visibility = View.VISIBLE - } - - fun hideActionButtons() { - action_view_log_workout_button.visibility = View.GONE - action_view_action_button.visibility = View.GONE - } - fun showActionSheetChooseProgression() { action_view_action_sheet_choose_progression.visibility = View.VISIBLE } diff --git a/app/src/main/kotlin/com/bodyweight/fitness/view/NavigationViewPresenter.kt b/app/src/main/kotlin/com/bodyweight/fitness/view/workout/NavigationViewPresenter.kt similarity index 94% rename from app/src/main/kotlin/com/bodyweight/fitness/view/NavigationViewPresenter.kt rename to app/src/main/kotlin/com/bodyweight/fitness/view/workout/NavigationViewPresenter.kt index f5ddb87c..6aefb800 100644 --- a/app/src/main/kotlin/com/bodyweight/fitness/view/NavigationViewPresenter.kt +++ b/app/src/main/kotlin/com/bodyweight/fitness/view/workout/NavigationViewPresenter.kt @@ -1,4 +1,4 @@ -package com.bodyweight.fitness.view +package com.bodyweight.fitness.view.workout import android.content.Context import android.util.AttributeSet @@ -7,6 +7,8 @@ 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.view.AbstractPresenter +import com.bodyweight.fitness.view.AbstractView import com.trello.rxlifecycle.kotlin.bindToLifecycle import kotlinx.android.synthetic.main.view_timer.view.* diff --git a/app/src/main/kotlin/com/bodyweight/fitness/view/PreviewViewPresenter.kt b/app/src/main/kotlin/com/bodyweight/fitness/view/workout/PreviewViewPresenter.kt similarity index 91% rename from app/src/main/kotlin/com/bodyweight/fitness/view/PreviewViewPresenter.kt rename to app/src/main/kotlin/com/bodyweight/fitness/view/workout/PreviewViewPresenter.kt index 18fc8d09..ad78ee46 100644 --- a/app/src/main/kotlin/com/bodyweight/fitness/view/PreviewViewPresenter.kt +++ b/app/src/main/kotlin/com/bodyweight/fitness/view/workout/PreviewViewPresenter.kt @@ -1,4 +1,4 @@ -package com.bodyweight.fitness.view +package com.bodyweight.fitness.view.workout import android.content.Context import android.net.Uri @@ -8,6 +8,8 @@ import com.bodyweight.fitness.setInvisible import com.bodyweight.fitness.setVisible import com.bodyweight.fitness.stream.RoutineStream +import com.bodyweight.fitness.view.AbstractPresenter +import com.bodyweight.fitness.view.AbstractView import com.trello.rxlifecycle.kotlin.bindToLifecycle import kotlinx.android.synthetic.main.view_workout.view.* diff --git a/app/src/main/kotlin/com/bodyweight/fitness/view/RepsLoggerViewPresenter.kt b/app/src/main/kotlin/com/bodyweight/fitness/view/workout/RepsLoggerViewPresenter.kt similarity index 97% rename from app/src/main/kotlin/com/bodyweight/fitness/view/RepsLoggerViewPresenter.kt rename to app/src/main/kotlin/com/bodyweight/fitness/view/workout/RepsLoggerViewPresenter.kt index 1726aabe..5dd03e21 100644 --- a/app/src/main/kotlin/com/bodyweight/fitness/view/RepsLoggerViewPresenter.kt +++ b/app/src/main/kotlin/com/bodyweight/fitness/view/workout/RepsLoggerViewPresenter.kt @@ -1,4 +1,4 @@ -package com.bodyweight.fitness.view +package com.bodyweight.fitness.view.workout import android.content.Context import android.util.AttributeSet @@ -9,6 +9,8 @@ import com.bodyweight.fitness.repository.Repository 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 import com.trello.rxlifecycle.kotlin.bindToLifecycle import kotlinx.android.synthetic.main.view_timer.view.* diff --git a/app/src/main/kotlin/com/bodyweight/fitness/view/TimerViewPresenter.kt b/app/src/main/kotlin/com/bodyweight/fitness/view/workout/TimerViewPresenter.kt similarity index 97% rename from app/src/main/kotlin/com/bodyweight/fitness/view/TimerViewPresenter.kt rename to app/src/main/kotlin/com/bodyweight/fitness/view/workout/TimerViewPresenter.kt index 71f809a2..d5af76e0 100644 --- a/app/src/main/kotlin/com/bodyweight/fitness/view/TimerViewPresenter.kt +++ b/app/src/main/kotlin/com/bodyweight/fitness/view/workout/TimerViewPresenter.kt @@ -1,4 +1,4 @@ -package com.bodyweight.fitness.view +package com.bodyweight.fitness.view.workout import android.app.TimePickerDialog import android.content.Context @@ -13,6 +13,8 @@ import com.bodyweight.fitness.repository.Repository 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 import com.trello.rxlifecycle.kotlin.bindToLifecycle import kotlinx.android.synthetic.main.view_timer.view.* @@ -34,13 +36,6 @@ class TimerPresenter : AbstractPresenter() { override fun bindView(view: AbstractView) { super.bindView(view) - Stream.drawerObservable() - .bindToLifecycle(view) - .filter { !it.equals(R.id.action_menu_workout) } - .subscribe { - pauseTimer() - } - RoutineStream.exerciseObservable() .bindToLifecycle(view) .subscribe { diff --git a/app/src/main/res/drawable/action_settings.xml b/app/src/main/res/drawable/action_settings.xml new file mode 100644 index 00000000..00c06266 --- /dev/null +++ b/app/src/main/res/drawable/action_settings.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout-port/view_timer.xml b/app/src/main/res/layout-port/view_timer.xml index efc64802..cf836b51 100644 --- a/app/src/main/res/layout-port/view_timer.xml +++ b/app/src/main/res/layout-port/view_timer.xml @@ -1,5 +1,5 @@ - - - + - - + - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_dashboard.xml b/app/src/main/res/layout/activity_dashboard.xml index 57ff4ffc..8f7d2333 100644 --- a/app/src/main/res/layout/activity_dashboard.xml +++ b/app/src/main/res/layout/activity_dashboard.xml @@ -1,27 +1,26 @@ - + android:fitsSystemWindows="false" + android:background="@color/primary"> - - - - + android:layout_height="wrap_content" + android:background="@color/primary" + android:layout_alignParentTop="true" + app:navigationIcon="@drawable/action_close" + app:theme="@style/AppTheme.Toolbar" + android:fitsSystemWindows="true"/> - \ No newline at end of file + android:layout_alignParentBottom="true" + android:layout_below="@+id/toolbar" + android:background="#E0E0E0" /> + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index e04b240e..8315bab3 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,7 +1,7 @@ - @@ -10,6 +10,8 @@ android:id="@+id/content_view" android:layout_width="match_parent" android:layout_height="match_parent" + android:layout_alignParentTop="true" + android:layout_above="@+id/bottomBar" android:background="@color/primary" android:fitsSystemWindows="true"> @@ -22,26 +24,27 @@ android:layout_height="match_parent" android:layout_below="@+id/view_toolbar" /> - - - + - - \ No newline at end of file + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main_header.xml b/app/src/main/res/layout/activity_main_header.xml deleted file mode 100644 index 5b64e297..00000000 --- a/app/src/main/res/layout/activity_main_header.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/activity_progress.xml b/app/src/main/res/layout/activity_progress.xml index 4c1c0735..d3f935c9 100644 --- a/app/src/main/res/layout/activity_progress.xml +++ b/app/src/main/res/layout/activity_progress.xml @@ -1,37 +1,51 @@ - + android:fitsSystemWindows="false" + android:background="@color/primary"> - + android:layout_height="match_parent" + android:layout_alignParentTop="true" + android:layout_alignParentBottom="true" + android:fitsSystemWindows="true"> - - - - + android:layout_alignParentTop="true" + android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" + app:elevation="0dp"> - - \ No newline at end of file + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_progress_exercise.xml b/app/src/main/res/layout/activity_progress_exercise.xml index 6e44d683..57174a15 100644 --- a/app/src/main/res/layout/activity_progress_exercise.xml +++ b/app/src/main/res/layout/activity_progress_exercise.xml @@ -4,101 +4,57 @@ android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="#F5F5F7"> + android:fitsSystemWindows="false" + android:background="@color/primary"> - + android:layout_height="match_parent" + android:fitsSystemWindows="true"> - - + android:layout_height="wrap_content" + android:layout_alignParentTop="true" + android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" + app:elevation="0dp"> - + + - - - + android:layout_height="match_parent" + android:layout_alignParentBottom="true" + android:layout_below="@+id/barlayout" + android:background="#F5F5F7"> - + android:layout_height="wrap_content"> - + android:layout_height="50dp" + android:background="@color/primary" /> - - - - - - - - - - - + android:orientation="vertical"> - + android:layout_height="wrap_content" + android:layout_margin="8dp" + app:cardBackgroundColor="@color/card_background"> + + + + + - - + android:layout_height="match_parent" + android:orientation="vertical" + android:paddingTop="16dp" + android:paddingLeft="16dp" + android:paddingRight="16dp" + android:paddingBottom="16dp" + android:layout_gravity="center"> + + + + + + + + + + + - - - + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_workout.xml b/app/src/main/res/layout/activity_workout.xml new file mode 100644 index 00000000..1b790a2b --- /dev/null +++ b/app/src/main/res/layout/activity_workout.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/view_action.xml b/app/src/main/res/layout/view_action.xml index dd620f45..e60e540e 100644 --- a/app/src/main/res/layout/view_action.xml +++ b/app/src/main/res/layout/view_action.xml @@ -1,5 +1,5 @@ - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/view_home.xml b/app/src/main/res/layout/view_home.xml index ae0e419d..c8f26b31 100644 --- a/app/src/main/res/layout/view_home.xml +++ b/app/src/main/res/layout/view_home.xml @@ -93,6 +93,8 @@ + + + + + + + + + + + + + + + + +