Commit ede577cb by Paktalin

Fixed bug with searchView initialization, tag layout is shown when hasSelection()

parent 50a4eced
......@@ -22,10 +22,11 @@ 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() {
lateinit var searchView: SearchView
var searchView: SearchView? = null
lateinit var vocabularyAdapter: VocabularyAdapter
private var tracker: SelectionTracker<Long>? = null
......@@ -34,6 +35,7 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)
FirestoreManager.vocabularyId = getSavedVocabularyIdFromPreferences(this@MainActivity)
recyclerView.adapter = VocabularyAdapter(VocabSet(mutableListOf()), this@MainActivity)
recyclerView.layoutManager = LockableLayoutManager(this@MainActivity)
setUpSwipeRefresh()
setUpNavigationView()
hideKeyboard()
......@@ -43,7 +45,7 @@ class MainActivity : AppCompatActivity() {
menuInflater.inflate(R.menu.options_menu, menu)
searchView = menu!!.findItem(R.id.search).actionView as SearchView
// extract vocabulary data only after searchView is initialized,
// since it needs to be called in the VocabularyFragment initialization
// since it needs to be called in the VocabularyAdapter initialization
setUpVocabularyAdapter()
return true
}
......@@ -89,7 +91,6 @@ class MainActivity : AppCompatActivity() {
addProgressBar(supportFragmentManager, R.id.container_main)
FirestoreManager().extractVocabularyId({
recyclerView.layoutManager = LockableLayoutManager(this@MainActivity)
FirestoreManager().extractVocabulary { querySnapshot ->
run {
if (querySnapshot != null && !querySnapshot.isEmpty) {
......@@ -138,8 +139,10 @@ class MainActivity : AppCompatActivity() {
super.onSelectionChanged()
if (tracker?.hasSelection()!!) {
Log.d(TAG, "selection ${tracker?.selection?.toList().toString()}")
visible(tagLayout)
} else {
gone(tagLayout)
}
//TODO my implementation
}
})
(recyclerView.adapter as VocabularyAdapter).tracker = tracker
......
......@@ -40,7 +40,7 @@ class VocabularyAdapter(private val vocabulary: VocabSet, private val mainActivi
override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
super.onAttachedToRecyclerView(recyclerView)
this.recyclerView = recyclerView
mainActivity.searchView.setOnQueryTextListener(OnQueryTextListener(this@VocabularyAdapter))
mainActivity.searchView?.setOnQueryTextListener(OnQueryTextListener(this@VocabularyAdapter))
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
......
......@@ -43,4 +43,6 @@
<include layout="@layout/submit" />
<include layout="@layout/tag" />
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tagLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:orientation="vertical">
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:visibility="gone">
<AutoCompleteTextView
android:id="@+id/brand"
android:layout_width="0dp"
android:id="@+id/tag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:hint="@string/enter_tag"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
android:layout_margin="8dp"
android:hint="@string/enter_tag" />
</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