Skip to content

Commit 9de979c

Browse files
author
Patrick Jackson
committed
add bottomNavigation on Android. iOS project building.
1 parent e335507 commit 9de979c

File tree

25 files changed

+224
-62
lines changed

25 files changed

+224
-62
lines changed

android/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ android {
5252
dependencies {
5353
implementation fileTree(dir: 'libs', include: ['*.jar'])
5454
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
55-
implementation 'androidx.appcompat:appcompat:1.0.2'
56-
implementation 'com.google.android.material:material:1.1.0-alpha07'
55+
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
56+
implementation 'com.google.android.material:material:1.1.0-alpha08'
5757
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
5858
implementation "android.arch.navigation:navigation-fragment-ktx:$ktxVersion"
5959
implementation "android.arch.navigation:navigation-ui-ktx:$ktxVersion"
@@ -79,10 +79,10 @@ dependencies {
7979

8080
kapt 'com.github.bumptech.glide:compiler:4.8.0'
8181
testImplementation 'junit:junit:4.12'
82-
androidTestImplementation 'androidx.test:runner:1.1.1'
83-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
82+
androidTestImplementation 'androidx.test:runner:1.2.0'
83+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
8484

85-
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta1'
85+
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
8686
implementation 'com.google.firebase:firebase-core:16.0.8'
8787
implementation 'com.google.firebase:firebase-auth:16.2.1'
8888
implementation 'com.firebaseui:firebase-ui-auth:4.3.2'
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.jackson.openlibrary
2+
3+
import android.os.Bundle
4+
import android.view.LayoutInflater
5+
import android.view.View
6+
import android.view.ViewGroup
7+
import android.widget.Toast
8+
import androidx.fragment.app.Fragment
9+
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
10+
import com.jackson.openlibrary.store.CompletedFragment
11+
import com.jackson.openlibrary.store.ReadingListFragment
12+
import kotlinx.android.synthetic.main.fragment_bottomsheet.*
13+
import java.lang.IllegalArgumentException
14+
15+
class BottomNavigationDrawerFragment : BottomSheetDialogFragment() {
16+
17+
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
18+
return inflater.inflate(R.layout.fragment_bottomsheet, container, false)
19+
}
20+
21+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
22+
navigation_view.setNavigationItemSelectedListener { menuItem ->
23+
// Bottom Navigation Drawer menu item clicks
24+
25+
val fragment: Fragment = when (menuItem!!.itemId) {
26+
R.id.readingList -> {
27+
fragmentManager?.findFragmentByTag(ReadingListFragment::class.java.name)
28+
?: ReadingListFragment()
29+
}
30+
R.id.completedList -> {
31+
fragmentManager?.findFragmentByTag(CompletedFragment::class.java.name)
32+
?: CompletedFragment()
33+
}
34+
else -> throw IllegalArgumentException()
35+
}
36+
37+
val fragTransaction = fragmentManager?.beginTransaction()
38+
fragTransaction?.replace(R.id.nav_host_fragment, fragment, fragment::class.java.name)
39+
fragTransaction?.commit()
40+
dismiss()
41+
42+
true
43+
}
44+
}
45+
}

android/src/main/java/com/jackson/openlibrary/MainActivity.kt

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ package com.jackson.openlibrary
22

33
import android.os.Bundle
44
import android.os.Handler
5-
import android.view.MenuItem
6-
import android.view.MotionEvent
7-
import android.view.View
8-
import android.view.ViewConfiguration
5+
import android.view.*
96
import androidx.appcompat.app.AppCompatActivity
107
import androidx.fragment.app.Fragment
118
import com.bumptech.glide.annotation.GlideModule
@@ -30,10 +27,43 @@ class MainActivity : AppCompatActivity() {
3027
override fun onCreate(savedInstanceState: Bundle?) {
3128
super.onCreate(savedInstanceState)
3229
setContentView(R.layout.activity_main)
33-
btmNavigation.setOnNavigationItemSelectedListener(::handleBtmNavTap)
34-
btmNavigation.selectedItemId = R.id.toRead
30+
setSupportActionBar(bottom_app_bar)
31+
val fragment = supportFragmentManager.findFragmentByTag(ReadingListFragment::class.java.name)
32+
?: ReadingListFragment()
33+
val fragTransaction = supportFragmentManager.beginTransaction()
34+
fragTransaction.replace(R.id.nav_host_fragment, fragment, fragment::class.java.name)
35+
fragTransaction.commit()
36+
fab.setOnClickListener {
37+
val fragment = supportFragmentManager.findFragmentByTag(SearchFragment::class.java.name)
38+
?: SearchFragment()
39+
val fragTransaction = supportFragmentManager.beginTransaction()
40+
fragTransaction.replace(R.id.nav_host_fragment, fragment, fragment::class.java.name)
41+
fragTransaction.commit()
42+
// bottom_app_bar.performHide()
43+
fab.hide()
44+
}
45+
46+
// btmNavigation.setOnNavigationItemSelectedListener(::handleBtmNavTap)
47+
// btmNavigation.selectedItemId = R.id.toRead
48+
}
49+
50+
override fun onCreateOptionsMenu(menu: Menu): Boolean {
51+
// menuInflater.inflate(R.menu.btm_app_bar_menu, menu)
52+
return true
3553
}
3654

55+
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
56+
when (item!!.itemId) {
57+
android.R.id.home -> {
58+
val bottomNavDrawerFragment = BottomNavigationDrawerFragment()
59+
bottomNavDrawerFragment.show(
60+
supportFragmentManager, bottomNavDrawerFragment.tag)
61+
}
62+
}
63+
64+
return true
65+
}
66+
/*
3767
private fun handleBtmNavTap(it: MenuItem): Boolean {
3868
val fragment: Fragment = when (it.itemId) {
3969
R.id.toRead -> {
@@ -55,6 +85,8 @@ class MainActivity : AppCompatActivity() {
5585
return true
5686
}
5787
88+
*/
89+
5890

5991
override fun onBackPressed() {
6092
val navHostFragment =

android/src/main/java/com/jackson/openlibrary/store/CompletedFragment.kt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
package com.jackson.openlibrary.store
22

3-
import android.graphics.drawable.InsetDrawable
43
import android.os.Bundle
54
import android.view.LayoutInflater
65
import android.view.View
76
import android.view.ViewGroup
8-
import android.widget.LinearLayout
9-
import androidx.recyclerview.widget.DividerItemDecoration
107
import androidx.recyclerview.widget.LinearLayoutManager
11-
import com.jackson.openlibrary.OpenLibraryApp
128
import com.jackson.openlibrary.R
139
import com.willowtreeapps.common.Actions
14-
import com.willowtreeapps.common.BookListItemViewState
1510
import com.willowtreeapps.common.ui.CompletedView
1611
import kotlinx.android.synthetic.main.fragment_completed.*
1712
import kotlinx.android.synthetic.main.fragment_reading_list.loading_spinner
@@ -40,11 +35,6 @@ class CompletedFragment : BaseLibraryViewFragment<CompletedView>(), CoroutineSco
4035
dispatch(Actions.LoadCompleted())
4136
}
4237

43-
override fun onPause() {
44-
super.onPause()
45-
OpenLibraryApp.gameEngine().detachView(this)
46-
}
47-
4838
override fun hideLoading() {
4939
loading_spinner.visibility = View.GONE
5040
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="24dp" android:tint="#FFFFFF"
2+
android:viewportHeight="24.0" android:viewportWidth="24.0"
3+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="#FF000000" android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
5+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="24dp" android:tint="#FFFFFF"
2+
android:viewportHeight="24.0" android:viewportWidth="24.0"
3+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="#FF000000" android:pathData="M3,18h18v-2L3,16v2zM3,13h18v-2L3,11v2zM3,6v2h18L21,6L3,6z"/>
5+
</vector>
Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
3+
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
34
xmlns:app="http://schemas.android.com/apk/res-auto"
45
xmlns:tools="http://schemas.android.com/tools"
56
android:id="@+id/drawer_layout"
67
android:layout_width="match_parent"
78
android:layout_height="match_parent">
89

910

10-
<com.google.android.material.bottomnavigation.BottomNavigationView
11-
android:id="@+id/btmNavigation"
12-
android:background="@color/white"
13-
android:layout_width="match_parent"
14-
android:layout_height="60dp"
15-
app:layout_constraintBottom_toBottomOf="parent"
16-
app:menu="@menu/btm_nav"
17-
/>
18-
1911
<FrameLayout
2012
android:id="@+id/nav_host_fragment"
2113
android:layout_width="match_parent"
2214
android:layout_height="match_parent"
2315
app:layout_constraintBottom_toTopOf="@id/btmNavigation"
24-
app:layout_constraintTop_toTopOf="parent"
25-
/>
26-
</androidx.constraintlayout.widget.ConstraintLayout>
16+
app:layout_constraintTop_toTopOf="parent" />
17+
18+
<com.google.android.material.bottomappbar.BottomAppBar
19+
android:id="@+id/bottom_app_bar"
20+
android:layout_width="match_parent"
21+
android:layout_height="wrap_content"
22+
android:layout_gravity="bottom"
23+
app:backgroundTint="@color/colorPrimary"
24+
app:fabAlignmentMode="center"
25+
app:navigationIcon="@drawable/ic_menu_white_24dp" />
26+
27+
<com.google.android.material.floatingactionbutton.FloatingActionButton
28+
android:id="@+id/fab"
29+
android:layout_width="wrap_content"
30+
android:layout_height="wrap_content"
31+
android:src="@drawable/ic_add_white_24dp"
32+
app:layout_anchor="@id/bottom_app_bar" />
33+
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
xmlns:android="http://schemas.android.com/apk/res/android"
6+
android:layout_width="match_parent"
7+
android:layout_height="wrap_content">
8+
9+
10+
<com.google.android.material.navigation.NavigationView
11+
android:id="@+id/navigation_view"
12+
android:layout_width="match_parent"
13+
android:layout_height="wrap_content"
14+
android:layout_gravity="bottom"
15+
app:layout_constraintEnd_toEndOf="parent"
16+
app:layout_constraintStart_toStartOf="parent"
17+
app:layout_constraintTop_toTopOf="parent"
18+
app:menu="@menu/bottom_nav_drawer_menu"/>
19+
20+
</androidx.constraintlayout.widget.ConstraintLayout>

android/src/main/res/layout/item_list_header.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
android:layout_marginStart="16dp"
1414
app:layout_constraintStart_toStartOf="parent"
1515
app:layout_constraintTop_toTopOf="parent"
16+
app:layout_constraintBottom_toBottomOf="parent"
1617
tools:text="Reading List" />
1718

1819
</androidx.constraintlayout.widget.ConstraintLayout>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto">
4+
<group android:checkableBehavior="none">
5+
<item
6+
android:id="@+id/readingList"
7+
android:icon="@drawable/ic_bookmark_white_24dp"
8+
android:title="@string/to_read_btn"/>
9+
<item
10+
android:id="@+id/completedList"
11+
android:icon="@drawable/ic_library_books_white_24dp"
12+
android:title="@string/completed_btn"/>
13+
14+
</group>
15+
</menu>

0 commit comments

Comments
 (0)