Skip to content

Commit

Permalink
WIP: Bottom Navigation (#43)
Browse files Browse the repository at this point in the history
- Bottom Navigation & Bug Fixes
  • Loading branch information
mazurio authored Oct 23, 2016
1 parent b743a9d commit e22d820
Show file tree
Hide file tree
Showing 39 changed files with 690 additions and 790 deletions.
43 changes: 22 additions & 21 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -83,35 +82,36 @@ 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'

compile 'commons-io:commons-io:2.4'
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;
Expand All @@ -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 {
Expand Down
25 changes: 11 additions & 14 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@
</activity>

<activity
android:name=".ui.DashboardActivity"
android:name=".ui.WorkoutActivity"
android:parentActivityName=".ui.MainActivity"
android:theme="@style/AppTheme.Activity.Dashboard"
android:launchMode="singleTask">

<meta-data
Expand All @@ -56,33 +55,31 @@
</activity>

<activity
android:name=".ui.ProgressActivity"
android:parentActivityName=".ui.MainActivity"
android:theme="@style/AppTheme.Activity.Progress">
android:name=".ui.DashboardActivity"
android:parentActivityName=".ui.WorkoutActivity"
android:launchMode="singleTask">

<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.MainActivity" />
android:value=".ui.WorkoutActivity" />
</activity>

<activity
android:name=".ui.ProgressExerciseActivity"
android:parentActivityName=".ui.ProgressExerciseActivity"
android:theme="@style/AppTheme.Activity.Progress">
android:name=".ui.ProgressActivity"
android:parentActivityName=".ui.MainActivity">

<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.ProgressExerciseActivity" />
android:value=".ui.MainActivity" />
</activity>

<activity
android:name=".ui.SettingsActivity"
android:parentActivityName=".ui.MainActivity"
android:theme="@style/AppTheme.Activity">
android:name=".ui.ProgressExerciseActivity"
android:parentActivityName=".ui.ProgressExerciseActivity">

<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ui.MainActivity" />
android:value=".ui.ProgressExerciseActivity" />
</activity>

<meta-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ class ProgressDialog : BottomSheetDialogFragment() {

layout.level_previous_button.setOnClickListener {
chosenLevel -= 1
updateDialog();
updateDialog()
}

layout.level_next_button.setOnClickListener {
chosenLevel += 1
updateDialog();
updateDialog()
}

layout.level_confirm_button.setOnClickListener {
Expand All @@ -64,12 +64,12 @@ class ProgressDialog : BottomSheetDialogFragment() {
val repositoryRoutine = Repository.repositoryRoutineForToday

Repository.realm.executeTransaction {
repositoryRoutine.exercises.filter { it.exerciseId == exercise.exerciseId }.firstOrNull()?.let {
it.visible == false
repositoryRoutine.exercises.find { it.exerciseId == exercise.exerciseId }?.let {
it.visible = false
}

repositoryRoutine.exercises.filter { it.exerciseId == chosenExercise.exerciseId }.firstOrNull()?.let {
it.visible == true
repositoryRoutine.exercises.find { it.exerciseId == chosenExercise.exerciseId }?.let {
it.visible = true
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/kotlin/com/bodyweight/fitness/stream/Stream.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ object Stream {
}

fun setDrawer(drawerMenuItemId: Int) {
if (!drawerMenuItemId.equals(R.id.action_menu_support_developer)
&& !drawerMenuItemId.equals(R.id.action_menu_settings)) {
currentDrawerId = drawerMenuItemId
}
currentDrawerId = drawerMenuItemId

drawerSubject.onNext(drawerMenuItemId)
}
Expand Down
122 changes: 11 additions & 111 deletions app/src/main/kotlin/com/bodyweight/fitness/ui/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,75 +1,42 @@
package com.bodyweight.fitness.ui

import android.content.Intent
import android.content.SharedPreferences
import android.net.Uri
import android.os.Bundle
import android.support.v4.view.GravityCompat
import android.support.v7.app.ActionBarDrawerToggle
import android.view.Menu

import android.view.MenuItem
import android.view.WindowManager

import com.bodyweight.fitness.Constants
import com.bodyweight.fitness.repository.Repository
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.Stream
import com.bodyweight.fitness.stream.UiEvent
import com.bodyweight.fitness.utils.Preferences

import com.kobakei.ratethisapp.RateThisApp
import com.trello.rxlifecycle.android.ActivityEvent

import com.trello.rxlifecycle.ActivityEvent
import com.trello.rxlifecycle.components.support.RxAppCompatActivity
import com.trello.rxlifecycle.kotlin.bindUntilEvent

import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.view_toolbar.*

class MainActivity : RxAppCompatActivity(), SharedPreferences.OnSharedPreferenceChangeListener {
class MainActivity : RxAppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContentView(R.layout.activity_main)

// requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT

setToolbar()
keepScreenOnWhenAppIsRunning()

val event = ActivityEvent.DESTROY
val fragmentManager = fragmentManager
val fragmentTransaction = fragmentManager.beginTransaction()

Stream.menuObservable
.bindUntilEvent(this, event)
.filter { it == R.id.action_dashboard }
.subscribe {
startActivity(Intent(this, DashboardActivity::class.java))
}
fragmentTransaction.replace(R.id.view_settings, SettingsFragment(), "SettingsFragment")
fragmentTransaction.addToBackStack(null)
fragmentTransaction.commit()

Stream.drawerObservable()
.bindUntilEvent(this, event)
.bindUntilEvent(this, ActivityEvent.DESTROY)
.subscribe {
invalidateOptionsMenu();

when (it) {
R.id.action_menu_support_developer -> {
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) {
Expand All @@ -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()

Expand All @@ -115,8 +56,6 @@ class MainActivity : RxAppCompatActivity(), SharedPreferences.OnSharedPreference
override fun onStop() {
super.onStop()

clearFlagKeepScreenOn()

Repository.realm.close()
}

Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Loading

0 comments on commit e22d820

Please sign in to comment.