Skip to content

Commit

Permalink
[FEAT] Add primary action floating action button to fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
peterkrauz committed Sep 23, 2020
1 parent 11ec0b1 commit 2526fb2
Show file tree
Hide file tree
Showing 22 changed files with 139 additions and 30 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ dependencies {
implementation Navigation.navigationUi
implementation Navigation.navigationFragment
implementation Firebase.analytics
implementation Android.lifeCycleExtensions

implementation Hilt.android
implementation Hilt.viewModel
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/peterkrauz/grimoire/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import kotlinx.android.synthetic.main.activity_main.*

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Expand All @@ -17,7 +18,7 @@ class MainActivity : AppCompatActivity() {

private fun setupView() {
bottomNavigationView.run {
// setOnNavigationItemReselectedListener { Unit }
setOnNavigationItemReselectedListener { Unit }
setupWithNavController(mainNavFragment.findNavController())
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/menu/bottom_nav_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:id="@+id/homeFragment"
android:id="@+id/arcsFragment"
android:title="@string/arcs"
android:icon="@drawable/ic_arcs_menu" />

Expand Down
14 changes: 8 additions & 6 deletions buildSrc/src/main/java/Deps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ object Kotlin {

object Android {
private object Versions {
const val coreKtxVersion = "1.3.1"
const val appCompatVersion = "1.2.0"
const val constraintLayoutVersion = "2.0.1"
const val coreKtx = "1.3.1"
const val appCompat = "1.2.0"
const val constraintLayout = "2.0.1"
const val lifecycle = "2.2.0"
}

const val coreKtx = "androidx.core:core-ktx:${Versions.coreKtxVersion}"
const val appCompat = "androidx.appcompat:appcompat:${Versions.appCompatVersion}"
const val constraintLayout = "androidx.constraintlayout:constraintlayout:${Versions.constraintLayoutVersion}"
const val coreKtx = "androidx.core:core-ktx:${Versions.coreKtx}"
const val appCompat = "androidx.appcompat:appcompat:${Versions.appCompat}"
const val constraintLayout = "androidx.constraintlayout:constraintlayout:${Versions.constraintLayout}"
const val lifeCycleExtensions = "androidx.lifecycle:lifecycle-extensions:${Versions.lifecycle}"
}

object Jetpack {
Expand Down
2 changes: 2 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ dependencies {
implementation Kotlin.standardLibrary
implementation Navigation.navigationUi
implementation Navigation.navigationFragment

api Material.material
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.peterkrauz.grimoire.common.base

interface BaseViewAction
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.peterkrauz.grimoire.common
package com.peterkrauz.grimoire.common.base

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.peterkrauz.grimoire.common.base

interface BaseViewState
10 changes: 10 additions & 0 deletions common/src/main/res/drawable/ic_add.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M4,6L2,6v14c0,1.1 0.9,2 2,2h14v-2L4,20L4,6zM20,2L8,2c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM19,11h-4v4h-2v-4L9,11L9,9h4L13,5h2v4h4v2z"/>
</vector>
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Empty state messages -->
<string name="arcs_empty_state_msg">It seems you haven\'t\ncreated any Arc yet.</string>
<string name="characters_empty_state_msg">It seems you haven\'t\ncreated any Character yet.</string>
<string name="notes_empty_state_msg">It seems you haven\'t\ncreated any Note yet.</string>
<string name="arcs_empty_state_msg">It seems you haven\'t\ncreated any Arc.\n\n\nClick the button below\nto add one!</string>
<string name="characters_empty_state_msg">It seems you haven\'t\ncreated any Character.\n\n\nClick the button below\nto add one!</string>
<string name="notes_empty_state_msg">It seems you haven\'t\ncreated any Note.\n\n\nClick the button below\nto add one!</string>
</resources>
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
package com.peterkrauz.grimoire.presentation.characters

import android.media.MediaPlayer
import androidx.fragment.app.Fragment
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class CharactersFragment : Fragment(R.layout.fragment_characters)
class CharactersFragment : Fragment(R.layout.fragment_characters) {

private var mediaPlayer: MediaPlayer? = null

override fun onResume() {
super.onResume()
// mediaPlayer = MediaPlayer.create(this, R.raw.arcs_tab_sound).apply {
// setOnCompletionListener { mediaPlayer?.release() }
// }
}

override fun onPause() {
super.onPause()
mediaPlayer?.release()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
app:layout_constraintVertical_bias="0.4"
app:layout_constraintVertical_bias="0.35"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" >
app:layout_constraintEnd_toEndOf="parent">

<ImageView
android:layout_width="190dp"
Expand All @@ -27,8 +27,22 @@
android:text="@string/characters_empty_state_msg"
android:textAppearance="@style/TextAppearance.Grimoire.H2"
android:gravity="center"
android:layout_marginTop="64dp"/>
android:layout_marginTop="64dp" />

</LinearLayout>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="32dp"
android:src="@drawable/ic_add"
android:tint="@color/colorBackground"
android:clickable="true"
android:focusable="true"
app:fabSize="normal"
app:rippleColor="@color/colorBackground"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
package com.peterkrauz.grimoire.presentation.home

import android.media.MediaPlayer
import androidx.fragment.app.Fragment
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class ArcsFragment : Fragment(R.layout.fragment_arcs)
class ArcsFragment : Fragment(R.layout.fragment_arcs) {

private var mediaPlayer: MediaPlayer? = null

override fun onResume() {
super.onResume()
// mediaPlayer = MediaPlayer.create(this, R.raw.arcs_tab_sound).apply {
// setOnCompletionListener { mediaPlayer?.release() }
// }
}

override fun onPause() {
super.onPause()
mediaPlayer?.release()
}
}
20 changes: 17 additions & 3 deletions presentation/home/src/main/res/layout/fragment_arcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
app:layout_constraintVertical_bias="0.4"
app:layout_constraintVertical_bias="0.35"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" >
app:layout_constraintEnd_toEndOf="parent">

<ImageView
android:layout_width="190dp"
Expand All @@ -27,8 +27,22 @@
android:text="@string/arcs_empty_state_msg"
android:textAppearance="@style/TextAppearance.Grimoire.H2"
android:gravity="center"
android:layout_marginTop="64dp"/>
android:layout_marginTop="64dp" />

</LinearLayout>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="32dp"
android:src="@drawable/ic_add"
android:tint="@color/colorBackground"
android:clickable="true"
android:focusable="true"
app:fabSize="normal"
app:rippleColor="@color/colorBackground"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
package com.peterkrauz.grimoire.presentation.notes

import android.media.MediaPlayer
import androidx.fragment.app.Fragment
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class NotesFragment : Fragment(R.layout.fragment_notes)
class NotesFragment : Fragment(R.layout.fragment_notes) {

private var mediaPlayer: MediaPlayer? = null

override fun onResume() {
super.onResume()
// mediaPlayer = MediaPlayer.create(this, R.raw.arcs_tab_sound).apply {
// setOnCompletionListener { mediaPlayer?.release() }
// }
}

override fun onPause() {
super.onPause()
mediaPlayer?.release()
}
}

20 changes: 17 additions & 3 deletions presentation/notes/src/main/res/layout/fragment_notes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
app:layout_constraintVertical_bias="0.4"
app:layout_constraintVertical_bias="0.35"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" >
app:layout_constraintEnd_toEndOf="parent">

<ImageView
android:layout_width="190dp"
Expand All @@ -27,8 +27,22 @@
android:text="@string/notes_empty_state_msg"
android:textAppearance="@style/TextAppearance.Grimoire.H2"
android:gravity="center"
android:layout_marginTop="64dp"/>
android:layout_marginTop="64dp" />

</LinearLayout>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="32dp"
android:src="@drawable/ic_add"
android:tint="@color/colorBackground"
android:clickable="true"
android:focusable="true"
app:fabSize="normal"
app:rippleColor="@color/colorBackground"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 2526fb2

Please sign in to comment.