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