Skip to content

Commit

Permalink
Keyboard is removed from fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolasan committed Aug 9, 2024
1 parent 3d2e21c commit 44fe4dc
Show file tree
Hide file tree
Showing 15 changed files with 319 additions and 162 deletions.
8 changes: 8 additions & 0 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 81 additions & 0 deletions .idea/navEditor.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ dependencies {
implementation 'androidx.annotation:annotation:1.7.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test:runner:1.5.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class ConverterFragment : Fragment() {
selectedPanel = topPanel // init before use
setPanelListeners(view)

keyboardView = view.findViewById(R.id.keyboard)
keyboardButtonView = view.findViewById(R.id.keyboard_button)
// keyboardView = view.findViewById(R.id.keyboard)
// keyboardButtonView = view.findViewById(R.id.keyboard_button)


// arguments?.let {
Expand All @@ -52,8 +52,8 @@ class ConverterFragment : Fragment() {
override fun onStart() {
super.onStart()

keyboardFragment = keyboardView.getFragment()
keyboardButtonFragment = keyboardButtonView.getFragment()
// keyboardFragment = keyboardView.getFragment()
// keyboardButtonFragment = keyboardButtonView.getFragment()

(activity as? MainActivity)?.workingUnits?.let { workingUnits ->
restoreTopPanel(workingUnits.topUnit)
Expand All @@ -62,7 +62,7 @@ class ConverterFragment : Fragment() {
displayUnitValues()
}

(activity as? MainActivity)?.updateKeyboard()
// (activity as? MainActivity)?.updateKeyboard()
}

fun selectPanel(new: ImperialUnitPanel, old: ImperialUnitPanel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver
import android.widget.EditText
import android.widget.ListView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.os.bundleOf
import androidx.core.widget.addTextChangedListener
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentContainerView
import androidx.navigation.findNavController
Expand Down Expand Up @@ -77,21 +74,21 @@ class UnitListFragment : Fragment() {
val view = inflater.inflate(R.layout.fragment_list, container, false)
unitsList = view.findViewById(R.id.units_list)
unitsList.adapter = listAdapter
val searchInput = view.findViewById<EditText>(R.id.search_input)
searchInput.addTextChangedListener {
listAdapter.filter.filter(it.toString())
}
searchInput.setOnFocusChangeListener { view, hasFocus ->
if (hasFocus) {
(activity as MainActivity).showKeyboardButton()
}
}

title = view.findViewById(R.id.unit_type_label)
title.text = arguments?.getString("categoryTitle")
// This is moved to another fragment (main activity for tablets ??)
// val searchInput = view.findViewById<EditText>(R.id.search_input)
// searchInput.addTextChangedListener {
// listAdapter.filter.filter(it.toString())
// }
// searchInput.setOnFocusChangeListener { view, hasFocus ->
// if (hasFocus) {
// (activity as MainActivity).showKeyboardButton()
// }
// }
// title = view.findViewById(R.id.unit_type_label)
// title.text = arguments?.getString("categoryTitle")

keyboardView = view.findViewById(R.id.keyboard)
keyboardButtonView = view.findViewById(R.id.keyboard_button)
// keyboardView = view.findViewById(R.id.keyboard)
// keyboardButtonView = view.findViewById(R.id.keyboard_button)

setListeners(view)

Expand All @@ -104,8 +101,8 @@ class UnitListFragment : Fragment() {
override fun onStart() {
super.onStart()

keyboardFragment = keyboardView.getFragment()
keyboardButtonFragment = keyboardButtonView.getFragment()
// keyboardFragment = keyboardView.getFragment()
// keyboardButtonFragment = keyboardButtonView.getFragment()

// (activity as? MainActivity)?.workingUnits?.let { workingUnits ->
// restoreSelectedUnit(workingUnits.topUnit)
Expand All @@ -115,7 +112,7 @@ class UnitListFragment : Fragment() {
// }

//(activity as? MainActivity)?.updateKeyboard()
(activity as? MainActivity)?.showKeyboard()
// (activity as? MainActivity)?.showKeyboard()
}

override fun onResume() {
Expand Down Expand Up @@ -169,20 +166,21 @@ class UnitListFragment : Fragment() {
(activity as MainActivity).onUnitSelected(unit)
}

view.run {
val typeSwitcher: ConstraintLayout = view.findViewById(R.id.unit_type)
typeSwitcher.setOnClickListener { v ->
(activity as MainActivity).showTypeSwitcher()
}
}
// This is replaced by the toolbar
// view.run {
// val typeSwitcher: ConstraintLayout = view.findViewById(R.id.unit_type)
// typeSwitcher.setOnClickListener { v ->
// (activity as MainActivity).showTypeSwitcher()
// }
// }

view.viewTreeObserver.addOnGlobalLayoutListener {
object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
// view.viewTreeObserver.removeOnGlobalLayoutListener(this)
// do whatever
val layout = view.findViewById<FragmentContainerView>(R.id.keyboard)
print(layout.visibility)
// val layout = view.findViewById<FragmentContainerView>(R.id.keyboard)
// print(layout.visibility)
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/res/layout-land/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,29 @@
app:layout_constraintTop_toBottomOf="@id/my_toolbar"
app:navGraph="@navigation/nav_graph" />

<androidx.fragment.app.FragmentContainerView
android:id="@+id/keyboard"
android:name="xyz.neupokoev.forgottenstandards.KeyboardFragment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:elevation="2dp"
android:visibility="visible"
android:layout_margin="6dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:layout="@layout/keyboard_panel"
tools:targetApi="lollipop" />

<androidx.fragment.app.FragmentContainerView
android:id="@+id/keyboard_button"
android:name="xyz.neupokoev.forgottenstandards.KeyboardButtonFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:elevation="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:layout="@layout/keyboard_button_fragment"
tools:targetApi="lollipop" />

</androidx.constraintlayout.widget.ConstraintLayout>
15 changes: 14 additions & 1 deletion app/src/main/res/layout-sw600dp-land/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintWidth_default="percent"
app:layout_constraintWidth_percent="0.4"
tools:layout="@layout/fragment_list" />
tools:layout="@layout/fragment_list_and_keyboard" />

<fragment
android:id="@+id/converter"
Expand All @@ -47,4 +47,17 @@
app:layout_constraintWidth_percent="0.3"
tools:layout="@layout/fragment_converter" />

<androidx.fragment.app.FragmentContainerView
android:id="@+id/keyboard"
android:name="xyz.neupokoev.forgottenstandards.KeyboardFragment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:elevation="2dp"
android:visibility="visible"
android:layout_margin="6dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:layout="@layout/keyboard_panel"
tools:targetApi="lollipop" />

</androidx.constraintlayout.widget.ConstraintLayout>
Loading

0 comments on commit 44fe4dc

Please sign in to comment.