Skip to content

Commit a731e33

Browse files
author
Patrick Jackson
committed
add toolbar to activity and logic to hide/show. also keyboard hide/show logic
1 parent 5af0cd8 commit a731e33

File tree

9 files changed

+125
-36
lines changed

9 files changed

+125
-36
lines changed

android/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<activity
1616
android:name=".MainActivity"
1717
android:label="@string/app_name"
18+
android:windowSoftInputMode="adjustPan"
1819
android:theme="@style/LibraryAppTheme">
1920
<intent-filter>
2021
<action android:name="android.intent.action.MAIN" />

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@ package com.jackson.openlibrary
22

33
import android.os.Bundle
44
import android.os.Handler
5+
import android.util.Log
56
import android.view.*
67
import androidx.appcompat.app.AppCompatActivity
8+
import androidx.core.content.ContextCompat
9+
import androidx.navigation.findNavController
10+
import androidx.navigation.ui.AppBarConfiguration
11+
import androidx.navigation.ui.setupWithNavController
712
import com.bumptech.glide.annotation.GlideModule
813
import com.bumptech.glide.module.AppGlideModule
914
import com.willowtreeapps.common.ui.UiActions
@@ -20,14 +25,45 @@ class MainActivity : AppCompatActivity() {
2025
fun onBackPressed(): Boolean
2126
}
2227

28+
data class Test(var name: String)
29+
val map: MutableMap<String, Test>? = mutableMapOf<String, Test>("test" to Test(""))
30+
2331
override fun onCreate(savedInstanceState: Bundle?) {
2432
super.onCreate(savedInstanceState)
2533
setContentView(R.layout.activity_main)
34+
val navController = findNavController(R.id.nav_host_fragment)
35+
val appBarConfiguration = AppBarConfiguration(navController.graph)
36+
toolbar.setupWithNavController(navController, appBarConfiguration)
2637
setSupportActionBar(bottom_app_bar)
2738
fab.setOnClickListener {
2839
OpenLibraryApp.dispatch(UiActions.SearchBtnTapped())
2940
fab.hide()
3041
}
42+
toolbar.visibility = View.GONE
43+
44+
Log.d("test", map.toString())
45+
map?.get("test")?.name = "updated"
46+
Log.d("test", map.toString())
47+
navController.addOnDestinationChangedListener { controller, destination, args ->
48+
when(destination.id) {
49+
R.id.readingListFragment -> {
50+
toolbar.visibility = View.GONE
51+
toolbar.hideKeyboard()
52+
}
53+
R.id.completedListFragment -> {
54+
toolbar.visibility = View.GONE
55+
toolbar.hideKeyboard()
56+
}
57+
R.id.searchFragment -> {
58+
toolbar.visibility = View.GONE
59+
toolbar.showKeyboard()
60+
}
61+
R.id.detailsFragment -> {
62+
toolbar.visibility = View.VISIBLE
63+
toolbar.hideKeyboard()
64+
}
65+
}
66+
}
3167
}
3268

3369
override fun onOptionsItemSelected(item: MenuItem?): Boolean {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ package com.jackson.openlibrary
33
import android.animation.Animator
44
import android.animation.AnimatorListenerAdapter
55
import android.animation.AnimatorSet
6+
import android.content.Context
67
import android.content.res.Resources
8+
import android.view.View
9+
import android.view.inputmethod.InputMethodManager
710
import com.bumptech.glide.load.DataSource
811
import com.bumptech.glide.load.engine.GlideException
912
import com.bumptech.glide.request.RequestListener
@@ -42,4 +45,14 @@ fun <T: Any> GlideRequest<T>.onComplete(after: () -> Unit): GlideRequest<T> {
4245
}
4346

4447

48+
fun View.showKeyboard() {
49+
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
50+
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY)
51+
}
52+
53+
54+
fun View.hideKeyboard() {
55+
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
56+
imm.hideSoftInputFromWindow(windowToken, 0)
57+
}
4558

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

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

3+
import android.content.Context
34
import android.os.Bundle
45
import android.text.Editable
56
import android.text.TextWatcher
67
import android.view.LayoutInflater
78
import android.view.View
89
import android.view.ViewGroup
10+
import android.view.inputmethod.InputMethodManager
911
import androidx.recyclerview.widget.LinearLayoutManager
1012
import com.jackson.openlibrary.R
11-
import com.willowtreeapps.common.ui.UiActions
13+
import com.jackson.openlibrary.showKeyboard
1214
import com.willowtreeapps.common.external.rootDispatch
1315
import com.willowtreeapps.common.ui.BookListItemViewState
1416
import com.willowtreeapps.common.ui.SearchView
15-
import kotlinx.android.synthetic.main.fragment_search.*
17+
import com.willowtreeapps.common.ui.UiActions
1618
import kotlinx.android.synthetic.main.fragment_reading_list.loading_spinner
1719
import kotlinx.android.synthetic.main.fragment_reading_list.txt_error
20+
import kotlinx.android.synthetic.main.fragment_search.*
1821
import java.util.*
1922

23+
2024
class SearchFragment : BaseLibraryViewFragment<SearchView>(), SearchView {
2125
private val adapter = BooksAdapter()
2226

@@ -29,6 +33,9 @@ class SearchFragment : BaseLibraryViewFragment<SearchView>(), SearchView {
2933
}
3034

3135
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
36+
txt_search.requestFocus()
37+
txt_search.showKeyboard()
38+
3239
searchRecycler.adapter = adapter
3340
searchRecycler.layoutManager = LinearLayoutManager(context)
3441
val ignoreNextTextChange = savedInstanceState != null
@@ -67,4 +74,5 @@ class SearchFragment : BaseLibraryViewFragment<SearchView>(), SearchView {
6774
override fun showError(msg: String) {
6875
txt_error.text = msg
6976
}
77+
7078
}

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,31 @@
77
android:layout_width="match_parent"
88
android:layout_height="match_parent">
99

10-
<FrameLayout
10+
11+
<RelativeLayout
1112
android:layout_width="match_parent"
1213
android:layout_height="match_parent"
13-
app:layout_constraintBottom_toTopOf="@id/btmNavigation"
14-
app:layout_constraintTop_toTopOf="parent"
14+
android:layout_gravity="bottom"
15+
app:layout_anchorGravity="bottom"
1516
>
16-
<fragment
17+
<androidx.appcompat.widget.Toolbar
18+
android:id="@+id/toolbar"
19+
style="@style/Toolbar"
20+
android:layout_width="match_parent"
21+
android:background="@color/colorPrimary"
22+
android:layout_alignParentTop="true"
23+
android:layout_height="?attr/actionBarSize"/>
24+
25+
<fragment
1726
android:id="@+id/nav_host_fragment"
1827
android:name="androidx.navigation.fragment.NavHostFragment"
1928
android:layout_width="match_parent"
2029
android:layout_height="match_parent"
30+
android:layout_below="@id/toolbar"
2131
app:navGraph="@navigation/nav_graph"
2232
app:defaultNavHost="true" />
2333

24-
</FrameLayout>
34+
</RelativeLayout>
2535

2636

2737
<com.google.android.material.bottomappbar.BottomAppBar
@@ -38,5 +48,6 @@
3848
android:layout_width="wrap_content"
3949
android:layout_height="wrap_content"
4050
android:src="@drawable/ic_add_white_24dp"
51+
app:tint="@color/white"
4152
app:layout_anchor="@id/bottom_app_bar" />
4253
</androidx.coordinatorlayout.widget.CoordinatorLayout>

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,10 @@
66
android:layout_height="match_parent"
77
android:layout_width="match_parent"
88
>
9-
<androidx.appcompat.widget.Toolbar
10-
android:id="@+id/toolbar"
11-
app:layout_constraintTop_toTopOf="parent"
12-
app:layout_constraintStart_toStartOf="parent"
13-
app:layout_constraintEnd_toEndOf="parent"
14-
android:layout_width="match_parent"
15-
app:navigationIcon="@drawable/ic_arrow_back_black_24dp"
16-
app:background="@color/colorPrimary"
17-
android:layout_height="56dp"/>
18-
199
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
2010
xmlns:app="http://schemas.android.com/apk/res-auto"
2111
xmlns:tools="http://schemas.android.com/tools"
22-
app:layout_constraintTop_toBottomOf="@id/toolbar"
12+
app:layout_constraintTop_toTopOf="parent"
2313
android:layout_width="match_parent"
2414
android:layout_height="match_parent"
2515
android:background="@color/white">
@@ -34,7 +24,7 @@
3424
android:id="@+id/imgBook"
3525
android:layout_width="match_parent"
3626
android:layout_height="500dp"
37-
app:layout_constraintTop_toBottomOf="parent"
27+
app:layout_constraintTop_toBottomOf="@id/toolbar"
3828
tools:src="@drawable/ic_library_books_white_24dp" />
3929

4030
<TextView
@@ -71,7 +61,12 @@
7161
app:layout_constraintTop_toBottomOf="@+id/txtTitle"
7262
tools:text="James Barr" />
7363

74-
64+
<androidx.appcompat.widget.Toolbar
65+
android:id="@+id/toolbar"
66+
android:layout_width="match_parent"
67+
android:layout_height="45dp"
68+
app:layout_constraintTop_toTopOf="parent"
69+
app:navigationIcon="@drawable/ic_arrow_back_black_24dp" />
7570

7671
<com.google.android.material.button.MaterialButton
7772
android:id="@+id/btnToRead"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
android:layout_marginTop="45dp"
1818
android:layout_marginEnd="16dp"
1919
android:hint="@string/search_hint"
20+
app:colorControlNormal="@color/il__gray90"
2021
app:layout_constraintTop_toTopOf="parent" />
2122

2223
<TextView

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,31 @@
1313
<ImageView
1414
android:id="@+id/ivBookCover"
1515
android:layout_width="56dp"
16-
android:layout_height="56dp"
16+
android:layout_height="90dp"
1717
android:layout_margin="8dp"
1818
tools:src="@drawable/ic_arrow_back_black_24dp"/>
1919

2020
<TextView
2121
android:id="@+id/tvTitle"
22+
style="@style/BookItemTitle"
2223
android:layout_width="wrap_content"
2324
android:layout_height="wrap_content"
2425
android:layout_margin="8dp"
25-
android:layout_toRightOf="@+id/ivBookCover"
26+
android:layout_toEndOf="@+id/ivBookCover"
2627
android:text="Title"
27-
android:textSize="24dp" />
28+
/>
2829

2930
<TextView
3031
android:id="@+id/tvAuthor"
32+
style="@style/Subtitle1"
3133
android:layout_width="wrap_content"
3234
android:layout_height="wrap_content"
33-
android:layout_marginLeft="8dp"
34-
android:layout_toRightOf="@+id/ivBookCover"
35+
android:layout_marginStart="8dp"
36+
android:layout_toEndOf="@+id/ivBookCover"
3537
android:layout_below="@+id/tvTitle"
3638
android:layout_marginBottom="16dp"
3739
android:text="Author"
38-
android:textSize="12dp" />
40+
/>
3941

4042
<View
4143
android:layout_width="match_parent"

android/src/main/res/values/styles.xml

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,38 @@
22

33
<!-- Base application theme. -->
44
<!--<style name="AppTheme" parent="Theme.MaterialComponents.NoActionBar">-->
5-
<style name="LibraryAppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
5+
<style name="LibraryAppTheme" parent="Theme.MaterialComponents.NoActionBar">
66
<!-- Customize your theme here. -->
77
<item name="colorPrimary">@color/colorPrimary</item>
88
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
99
<item name="colorAccent">@color/colorAccent</item>
1010
<item name="colorOnPrimary">@android:color/white</item>
11-
<item name="colorControlHighlight">@color/black</item>
12-
<item name="android:actionBarStyle">@style/ThemeActionBar</item>
13-
<item name="actionBarStyle">@style/ThemeActionBar</item>
1411
<item name="android:buttonStyle">@style/ChoiceButton</item>
12+
<item name="colorControlNormal">@color/white</item>
13+
<item name="colorControlHighlight">@color/white</item>
14+
<!-- <item name="colorControlActivated">@color/white</item>-->
15+
16+
<item name="android:textColorHint">@color/il__gray90</item>
17+
<item name="android:editTextColor">#295055</item>
18+
<item name="android:textColorPrimary">#295055</item>
19+
<item name="android:textColorSecondary">#295055</item>
20+
<item name="android:textColorTertiary">#295055</item>
21+
<item name="android:textColorPrimaryInverse">#295055</item>
22+
<item name="android:textColorSecondaryInverse">#295055</item>
23+
<item name="android:textColorTertiaryInverse">#295055</item>
24+
<item name="toolbarNavigationButtonStyle">@style/Toolbar.Button.Navigation.Tinted</item>
25+
</style>
26+
27+
28+
<style name="Toolbar" >
29+
<item name="android:titleTextColor">@color/white</item>
30+
<item name="titleTextColor">@color/white</item>
31+
<item name="android:buttonTint">@color/white</item>
32+
<item name="elevation">0dp</item>
1533
</style>
1634

17-
<style name="LibraryAppTheme.TransparentTheme">
18-
</style>
19-
20-
<style name="ThemeActionBar" parent="Widget.AppCompat.ActionBar.Solid">
21-
<item name="elevation">0dp</item>
35+
<style name="Toolbar.Button.Navigation.Tinted" parent="Widget.AppCompat.Toolbar.Button.Navigation">
36+
<item name="android:tint">@color/white</item>
2237
</style>
2338

2439
<style name="ListTitle">
@@ -31,7 +46,7 @@
3146
</style>
3247

3348
<style name="SubTitle">
34-
<item name="android:textColor">?attr/colorOnPrimary</item>
49+
<item name="android:textColor">@color/black</item>
3550
<item name="android:textSize">@dimen/txt_subtitle_size</item>
3651
</style>
3752

@@ -57,6 +72,13 @@
5772
</style>
5873

5974

75+
<style name="BookItemTitle" parent="H6">
76+
</style>
77+
78+
<style name="BookItemSubtitle" parent="SubTitle">
79+
<item name="android:textColor">@color/il__gray90</item>
80+
</style>
81+
6082
<style name="H1">
6183
<item name="android:textSize">96sp</item>
6284
<item name="android:letterSpacing">-0.16</item>

0 commit comments

Comments
 (0)