Commit 1473c257 by Paktalin

Moved selection logic to mainActivity (temporary) + completed tag layout

parent 12b51fb5
...@@ -18,6 +18,7 @@ import com.paktalin.vocabularynotebook.vocabulary.Sort ...@@ -18,6 +18,7 @@ import com.paktalin.vocabularynotebook.vocabulary.Sort
import com.paktalin.vocabularynotebook.vocabulary.VocabSet import com.paktalin.vocabularynotebook.vocabulary.VocabSet
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.content_main.* import kotlinx.android.synthetic.main.content_main.*
import kotlinx.android.synthetic.main.tag.*
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
...@@ -119,7 +120,17 @@ class MainActivity : AppCompatActivity() { ...@@ -119,7 +120,17 @@ class MainActivity : AppCompatActivity() {
private fun setUpSelectionTracker() { private fun setUpSelectionTracker() {
vocabularyAdapter.selectionTracker = MySelectionTracker().apply { vocabularyAdapter.selectionTracker = MySelectionTracker().apply {
init(recyclerView) init(recyclerView)
addObserver(this@MainActivity) addObserver { selection ->
run {
if (!selection.isEmpty) {
// TODO disable popup menu
Log.d(TAG, "selection ${selection.toList()}")
visible(tagLayout)
} else {
gone(tagLayout)
}
}
}
} }
} }
......
...@@ -73,7 +73,7 @@ class EditWordFragment : WordFragment() { ...@@ -73,7 +73,7 @@ class EditWordFragment : WordFragment() {
private fun stop() { private fun stop() {
// set onClickListener from AddWordFragment // set onClickListener from AddWordFragment
mainActivity.btnSubmit.setOnClickListener { (mainActivity.fragmentAddWord as AddWordFragment).submitWord() } mainActivity.btnSubmitWord.setOnClickListener { (mainActivity.fragmentAddWord as AddWordFragment).submitWord() }
removeFragment(mainActivity.supportFragmentManager, this) removeFragment(mainActivity.supportFragmentManager, this)
mainActivity.hideKeyboardNotFromActivity(mainActivity) mainActivity.hideKeyboardNotFromActivity(mainActivity)
gone(mainActivity.btnSubmitLayout) gone(mainActivity.btnSubmitLayout)
......
...@@ -21,8 +21,8 @@ abstract class WordFragment : Fragment() { ...@@ -21,8 +21,8 @@ abstract class WordFragment : Fragment() {
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState) super.onActivityCreated(savedInstanceState)
mainActivity = activity as MainActivity mainActivity = activity as MainActivity
mainActivity.btnSubmit.setOnClickListener { submitWord() } mainActivity.btnSubmitWord.setOnClickListener { submitWord() }
mainActivity.btnCancel.setOnClickListener { cancelEditing() } mainActivity.btnCancelWord.setOnClickListener { cancelEditing() }
btnClear.setOnClickListener { clearFields() } btnClear.setOnClickListener { clearFields() }
} }
......
package com.paktalin.vocabularynotebook.ui.recycler_view.selection_tracker package com.paktalin.vocabularynotebook.ui.recycler_view.selection_tracker
import androidx.recyclerview.selection.Selection
import androidx.recyclerview.selection.SelectionPredicates import androidx.recyclerview.selection.SelectionPredicates
import androidx.recyclerview.selection.SelectionTracker import androidx.recyclerview.selection.SelectionTracker
import androidx.recyclerview.selection.StorageStrategy import androidx.recyclerview.selection.StorageStrategy
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.paktalin.vocabularynotebook.ui.activities.MainActivity
import com.paktalin.vocabularynotebook.utils.Log
import com.paktalin.vocabularynotebook.utils.gone
import com.paktalin.vocabularynotebook.utils.visible
import kotlinx.android.synthetic.main.tag.*
class MySelectionTracker { class MySelectionTracker {
private var tracker: SelectionTracker<Long>? = null private var tracker: SelectionTracker<Long>? = null
...@@ -25,17 +21,11 @@ class MySelectionTracker { ...@@ -25,17 +21,11 @@ class MySelectionTracker {
).build() ).build()
} }
fun addObserver(mainActivity: MainActivity) { fun addObserver(whenSelectionChanged: (selection: Selection<Long>) -> Unit) {
tracker?.addObserver(object : SelectionTracker.SelectionObserver<Long>() { tracker?.addObserver(object : SelectionTracker.SelectionObserver<Long>() {
override fun onSelectionChanged() { override fun onSelectionChanged() {
super.onSelectionChanged() super.onSelectionChanged()
if (tracker?.hasSelection()!!) { tracker?.selection?.let { whenSelectionChanged(it) }
// TODO disable popup menu
Log.d(TAG, "selection ${tracker?.selection?.toList().toString()}")
visible(mainActivity.tagLayout)
} else {
gone(mainActivity.tagLayout)
}
} }
}) })
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
android:visibility="gone"> android:visibility="gone">
<ImageButton <ImageButton
android:id="@+id/btnCancel" android:id="@+id/btnCancelWord"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
android:layout_weight="1" /> android:layout_weight="1" />
<ImageButton <ImageButton
android:id="@+id/btnSubmit" android:id="@+id/btnSubmitWord"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/tagLayout" android:id="@+id/tagLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:orientation="vertical" android:background="@color/colorPrimary"
android:orientation="horizontal"
android:visibility="gone"> android:visibility="gone">
<ImageButton
android:id="@+id/btnCancelTag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="@dimen/small_margin"
android:background="@android:color/transparent"
app:srcCompat="@drawable/ic_close_brown"
tools:ignore="ContentDescription" />
<AutoCompleteTextView <AutoCompleteTextView
android:id="@+id/tag" android:id="@+id/tag"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="8dp" android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_weight="1"
android:hint="@string/enter_tag" /> android:hint="@string/enter_tag" />
<ImageButton
android:id="@+id/btnSubmitTag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="@dimen/small_margin"
android:background="@android:color/transparent"
app:srcCompat="@drawable/ic_done_brown"
tools:ignore="ContentDescription" />
</LinearLayout> </LinearLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment