turbo-native-initializer 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6134975dfb64645d0fe32a2dfcaa61efe0719458540d0e294cffc5547646397
4
- data.tar.gz: df7dada5dc6d57ff85e58e2439c86a9e06cc0e4e89fe8a5547509da483493906
3
+ metadata.gz: d89f212990b6d8acf8b1f37073d8b892b7f043bdf4a19d11997fabf620ba4ca1
4
+ data.tar.gz: d2b4ea5ee37d49c0d3eb23d4bb56894407a3ff5d535058ac21c54292439eae45
5
5
  SHA512:
6
- metadata.gz: 2135c55c9a059bba1907bd90f776e352968d74af49cdc8173d8b6f1d92ecbf5b09e566d3626e02d5842a509fb1dea7b3d7dde0d847046da4cb9740186f5e04b4
7
- data.tar.gz: 4c648e53161c6ab00f22787b3dc059cf06d8f259a9eabdd8aad0617e33d56ccac29ca6556f4eaa31fd8eb93fbbf50ad15d2d18e5b9f5fe3d1875369679bae5bc
6
+ metadata.gz: 3002e6b664dd0c92f04c2535707e8008a5c38e6d61e129bf3d376aa586bf2906228323a6947910b7a9d107dbcc2e33403ee1a2de508d444d97d37cea54fa1434
7
+ data.tar.gz: 6884c3e84fef8d9462387a1ba5c787befe6b79053378bf6d21c5e65f68a3d31f117abf94a9eb0fb671581317968c17a3727247598b657b1171bf149316dbe00c
@@ -25,7 +25,6 @@ open class WebFragment : TurboWebFragment(), NavDestination {
25
25
 
26
26
  override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
27
27
  super.onViewCreated(view, savedInstanceState)
28
- setupMenu()
29
28
  viewLifecycleOwner.lifecycle.addObserver(bridgeDelegate)
30
29
  }
31
30
 
@@ -60,8 +59,4 @@ open class WebFragment : TurboWebFragment(), NavDestination {
60
59
  override fun createErrorView(statusCode: Int): View {
61
60
  return layoutInflater.inflate(R.layout.error_web, null)
62
61
  }
63
-
64
- private fun setupMenu() {
65
- toolbarForNavigation()?.inflateMenu(R.menu.web)
66
- }
67
62
  }
@@ -1,6 +1,9 @@
1
1
  package <%= package_name %>.strada
2
2
 
3
3
  import android.util.Log
4
+ import android.view.LayoutInflater
5
+ import android.view.Menu
6
+ import android.view.MenuItem
4
7
  import androidx.appcompat.widget.Toolbar
5
8
  import androidx.fragment.app.Fragment
6
9
  import dev.hotwire.strada.BridgeComponent
@@ -8,6 +11,7 @@ import dev.hotwire.strada.BridgeDelegate
8
11
  import dev.hotwire.strada.Message
9
12
  import <%= package_name %>.R
10
13
  import <%= package_name %>.base.NavDestination
14
+ import <%= package_name %>.databinding.NavButtonComponentBinding
11
15
  import kotlinx.serialization.Serializable
12
16
 
13
17
  class NavButtonComponent(
@@ -15,6 +19,8 @@ class NavButtonComponent(
15
19
  private val delegate: BridgeDelegate<NavDestination>
16
20
  ) : BridgeComponent<NavDestination>(name, delegate) {
17
21
 
22
+ private val navButtonItemId = 10
23
+ private var navButtonMenuItem: MenuItem? = null
18
24
  private val fragment: Fragment
19
25
  get() = delegate.destination.fragment
20
26
  private val toolbar: Toolbar?
@@ -34,26 +40,27 @@ class NavButtonComponent(
34
40
  }
35
41
 
36
42
  private fun showToolbarButton(data: MessageData) {
37
- val toolbar = toolbar ?: return
43
+ val menu = toolbar?.menu ?: return
44
+ val inflater = LayoutInflater.from(fragment.requireContext())
45
+ val binding = NavButtonComponentBinding.inflate(inflater)
46
+ val order = 999 // Show as the right-most button
38
47
 
39
- toolbar.menu.findItem(R.id.nav_button)?.apply {
40
- isVisible = true
41
- title = data.title
48
+ binding.navButton.apply {
49
+ text = data.title
50
+ setOnClickListener {
51
+ performAction()
52
+ }
42
53
  }
43
54
 
44
- toolbar.setOnMenuItemClickListener {
45
- when (it.itemId) {
46
- R.id.nav_button -> {
47
- performClick()
48
- true
49
- }
50
- else -> false
51
- }
55
+ menu.removeItem(navButtonItemId)
56
+ navButtonMenuItem = menu.add(Menu.NONE, navButtonItemId, order, data.title).apply {
57
+ actionView = binding.root
58
+ setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
52
59
  }
53
60
  }
54
61
 
55
- private fun performClick() {
56
- replyTo("connect")
62
+ private fun performAction(): Boolean {
63
+ return replyTo("connect")
57
64
  }
58
65
 
59
66
  @Serializable
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+ android:layout_width="wrap_content"
4
+ android:layout_height="match_parent"
5
+ android:layout_gravity="end|center_vertical"
6
+ android:paddingEnd="16dp">
7
+
8
+ <com.google.android.material.button.MaterialButton
9
+ style="@style/Widget.Material3.Button.TextButton"
10
+ android:id="@+id/nav_button"
11
+ android:layout_width="wrap_content"
12
+ android:layout_height="48dp"
13
+ android:minWidth="0dip" />
14
+ </FrameLayout>
@@ -22,7 +22,6 @@ open class WebFragment : TurboWebFragment(), NavDestination {
22
22
 
23
23
  override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
24
24
  super.onViewCreated(view, savedInstanceState)
25
- setupMenu()
26
25
  viewLifecycleOwner.lifecycle.addObserver(bridgeDelegate)
27
26
  }
28
27
 
@@ -50,8 +49,4 @@ open class WebFragment : TurboWebFragment(), NavDestination {
50
49
  override fun createErrorView(statusCode: Int): View {
51
50
  return layoutInflater.inflate(R.layout.error_web, null)
52
51
  }
53
-
54
- private fun setupMenu() {
55
- toolbarForNavigation()?.inflateMenu(R.menu.web)
56
- }
57
52
  }
@@ -1,6 +1,9 @@
1
1
  package <%= package_name %>.strada
2
2
 
3
3
  import android.util.Log
4
+ import android.view.LayoutInflater
5
+ import android.view.Menu
6
+ import android.view.MenuItem
4
7
  import androidx.appcompat.widget.Toolbar
5
8
  import androidx.fragment.app.Fragment
6
9
  import dev.hotwire.strada.BridgeComponent
@@ -8,6 +11,7 @@ import dev.hotwire.strada.BridgeDelegate
8
11
  import dev.hotwire.strada.Message
9
12
  import <%= package_name %>.R
10
13
  import <%= package_name %>.base.NavDestination
14
+ import <%= package_name %>.databinding.NavButtonComponentBinding
11
15
  import kotlinx.serialization.Serializable
12
16
 
13
17
  class NavButtonComponent(
@@ -15,6 +19,8 @@ class NavButtonComponent(
15
19
  private val delegate: BridgeDelegate<NavDestination>
16
20
  ) : BridgeComponent<NavDestination>(name, delegate) {
17
21
 
22
+ private val navButtonItemId = 10
23
+ private var navButtonMenuItem: MenuItem? = null
18
24
  private val fragment: Fragment
19
25
  get() = delegate.destination.fragment
20
26
  private val toolbar: Toolbar?
@@ -34,26 +40,27 @@ class NavButtonComponent(
34
40
  }
35
41
 
36
42
  private fun showToolbarButton(data: MessageData) {
37
- val toolbar = toolbar ?: return
43
+ val menu = toolbar?.menu ?: return
44
+ val inflater = LayoutInflater.from(fragment.requireContext())
45
+ val binding = NavButtonComponentBinding.inflate(inflater)
46
+ val order = 999 // Show as the right-most button
38
47
 
39
- toolbar.menu.findItem(R.id.nav_button)?.apply {
40
- isVisible = true
41
- title = data.title
48
+ binding.navButton.apply {
49
+ text = data.title
50
+ setOnClickListener {
51
+ performAction()
52
+ }
42
53
  }
43
54
 
44
- toolbar.setOnMenuItemClickListener {
45
- when (it.itemId) {
46
- R.id.nav_button -> {
47
- performClick()
48
- true
49
- }
50
- else -> false
51
- }
55
+ menu.removeItem(navButtonItemId)
56
+ navButtonMenuItem = menu.add(Menu.NONE, navButtonItemId, order, data.title).apply {
57
+ actionView = binding.root
58
+ setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
52
59
  }
53
60
  }
54
61
 
55
- private fun performClick() {
56
- replyTo("connect")
62
+ private fun performAction(): Boolean {
63
+ return replyTo("connect")
57
64
  }
58
65
 
59
66
  @Serializable
@@ -0,0 +1,14 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+ android:layout_width="wrap_content"
4
+ android:layout_height="match_parent"
5
+ android:layout_gravity="end|center_vertical"
6
+ android:paddingEnd="16dp">
7
+
8
+ <com.google.android.material.button.MaterialButton
9
+ style="@style/Widget.Material3.Button.TextButton"
10
+ android:id="@+id/nav_button"
11
+ android:layout_width="wrap_content"
12
+ android:layout_height="48dp"
13
+ android:minWidth="0dip" />
14
+ </FrameLayout>
@@ -1,3 +1,3 @@
1
1
  module TurboNativeInitializer
2
- VERSION = "0.0.13"
2
+ VERSION = "0.0.14"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo-native-initializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nixon
@@ -77,7 +77,7 @@ files:
77
77
  - lib/turbo_native_initializer/templates/android_stack/base/app/src/main/res/layout/fragment_web_home.xml
78
78
  - lib/turbo_native_initializer/templates/android_stack/base/app/src/main/res/layout/menu_component_adapter_row.xml
79
79
  - lib/turbo_native_initializer/templates/android_stack/base/app/src/main/res/layout/menu_component_bottom_sheet.xml
80
- - lib/turbo_native_initializer/templates/android_stack/base/app/src/main/res/menu/web.xml
80
+ - lib/turbo_native_initializer/templates/android_stack/base/app/src/main/res/layout/nav_button_component.xml
81
81
  - lib/turbo_native_initializer/templates/android_stack/base/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
82
82
  - lib/turbo_native_initializer/templates/android_stack/base/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
83
83
  - lib/turbo_native_initializer/templates/android_stack/base/app/src/main/res/mipmap-xhdpi/ic_launcher.png
@@ -136,8 +136,8 @@ files:
136
136
  - lib/turbo_native_initializer/templates/android_tabs/base/app/src/main/res/layout/fragment_web_home.xml
137
137
  - lib/turbo_native_initializer/templates/android_tabs/base/app/src/main/res/layout/menu_component_adapter_row.xml
138
138
  - lib/turbo_native_initializer/templates/android_tabs/base/app/src/main/res/layout/menu_component_bottom_sheet.xml
139
+ - lib/turbo_native_initializer/templates/android_tabs/base/app/src/main/res/layout/nav_button_component.xml
139
140
  - lib/turbo_native_initializer/templates/android_tabs/base/app/src/main/res/menu/bottom_navigation_menu.xml
140
- - lib/turbo_native_initializer/templates/android_tabs/base/app/src/main/res/menu/web.xml
141
141
  - lib/turbo_native_initializer/templates/android_tabs/base/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
142
142
  - lib/turbo_native_initializer/templates/android_tabs/base/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
143
143
  - lib/turbo_native_initializer/templates/android_tabs/base/app/src/main/res/mipmap-xhdpi/ic_launcher.png
@@ -1,9 +0,0 @@
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
- <item
5
- android:id="@+id/nav_button"
6
- android:orderInCategory="999"
7
- android:visible="false"
8
- app:showAsAction="always" />
9
- </menu>
@@ -1,9 +0,0 @@
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
- <item
5
- android:id="@+id/nav_button"
6
- android:orderInCategory="999"
7
- android:visible="false"
8
- app:showAsAction="always" />
9
- </menu>