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
import com.paktalin.vocabularynotebook.vocabulary.VocabSet
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.content_main.*
import kotlinx.android.synthetic.main.tag.*
class MainActivity : AppCompatActivity() {
......@@ -119,7 +120,17 @@ class MainActivity : AppCompatActivity() {
private fun setUpSelectionTracker() {
vocabularyAdapter.selectionTracker = MySelectionTracker().apply {
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() {
private fun stop() {
// set onClickListener from AddWordFragment
mainActivity.btnSubmit.setOnClickListener { (mainActivity.fragmentAddWord as AddWordFragment).submitWord() }
mainActivity.btnSubmitWord.setOnClickListener { (mainActivity.fragmentAddWord as AddWordFragment).submitWord() }
removeFragment(mainActivity.supportFragmentManager, this)
mainActivity.hideKeyboardNotFromActivity(mainActivity)
gone(mainActivity.btnSubmitLayout)
......
......@@ -21,8 +21,8 @@ abstract class WordFragment : Fragment() {
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
mainActivity = activity as MainActivity
mainActivity.btnSubmit.setOnClickListener { submitWord() }
mainActivity.btnCancel.setOnClickListener { cancelEditing() }
mainActivity.btnSubmitWord.setOnClickListener { submitWord() }
mainActivity.btnCancelWord.setOnClickListener { cancelEditing() }
btnClear.setOnClickListener { clearFields() }
}
......
package com.paktalin.vocabularynotebook.ui.recycler_view.selection_tracker
import androidx.recyclerview.selection.Selection
import androidx.recyclerview.selection.SelectionPredicates
import androidx.recyclerview.selection.SelectionTracker
import androidx.recyclerview.selection.StorageStrategy
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 {
private var tracker: SelectionTracker<Long>? = null
......@@ -25,17 +21,11 @@ class MySelectionTracker {
).build()
}
fun addObserver(mainActivity: MainActivity) {
fun addObserver(whenSelectionChanged: (selection: Selection<Long>) -> Unit) {
tracker?.addObserver(object : SelectionTracker.SelectionObserver<Long>() {
override fun onSelectionChanged() {
super.onSelectionChanged()
if (tracker?.hasSelection()!!) {
// TODO disable popup menu
Log.d(TAG, "selection ${tracker?.selection?.toList().toString()}")
visible(mainActivity.tagLayout)
} else {
gone(mainActivity.tagLayout)
}
tracker?.selection?.let { whenSelectionChanged(it) }
}
})
}
......
......@@ -11,7 +11,7 @@
android:visibility="gone">
<ImageButton
android:id="@+id/btnCancel"
android:id="@+id/btnCancelWord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
......@@ -26,7 +26,7 @@
android:layout_weight="1" />
<ImageButton
android:id="@+id/btnSubmit"
android:id="@+id/btnSubmitWord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
......
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:background="@color/colorPrimary"
android:orientation="horizontal"
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
android:id="@+id/tag"
android:layout_width="match_parent"
android:layout_width="0dp"
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" />
<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>
\ 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