Commit 50a4eced by Paktalin

Added MyItemKeyProvider and moved submit layout to a separate xml file

parent daa4eff2
......@@ -35,7 +35,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -11,10 +11,10 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SearchView
import androidx.recyclerview.selection.SelectionPredicates
import androidx.recyclerview.selection.SelectionTracker
import androidx.recyclerview.selection.StableIdKeyProvider
import androidx.recyclerview.selection.StorageStrategy
import com.paktalin.vocabularynotebook.R
import com.paktalin.vocabularynotebook.ui.recycler_view.MyItemDetailsLookup
import com.paktalin.vocabularynotebook.ui.recycler_view.MyItemKeyProvider
import com.paktalin.vocabularynotebook.ui.recycler_view.VocabularyAdapter
import com.paktalin.vocabularynotebook.ui.views.LockableLayoutManager
import com.paktalin.vocabularynotebook.utils.*
......@@ -33,6 +33,7 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
FirestoreManager.vocabularyId = getSavedVocabularyIdFromPreferences(this@MainActivity)
recyclerView.adapter = VocabularyAdapter(VocabSet(mutableListOf()), this@MainActivity)
setUpSwipeRefresh()
setUpNavigationView()
hideKeyboard()
......@@ -85,6 +86,7 @@ class MainActivity : AppCompatActivity() {
}
private fun setUpVocabularyAdapter() {
addProgressBar(supportFragmentManager, R.id.container_main)
FirestoreManager().extractVocabularyId({
recyclerView.layoutManager = LockableLayoutManager(this@MainActivity)
......@@ -123,7 +125,7 @@ class MainActivity : AppCompatActivity() {
tracker = SelectionTracker.Builder<Long>(
"mySelection",
recyclerView,
StableIdKeyProvider(recyclerView),
MyItemKeyProvider(recyclerView),
MyItemDetailsLookup(recyclerView),
StorageStrategy.createLongStorage()
).withSelectionPredicate(
......
......@@ -4,9 +4,11 @@ import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import com.paktalin.vocabularynotebook.firestoreitems.WordPojo
import com.paktalin.vocabularynotebook.utils.*
import kotlinx.android.synthetic.main.content_main.*
import com.paktalin.vocabularynotebook.utils.gone
import com.paktalin.vocabularynotebook.utils.invisible
import com.paktalin.vocabularynotebook.utils.visible
import kotlinx.android.synthetic.main.fragment_editable_word.*
import kotlinx.android.synthetic.main.submit.*
class AddWordFragment : WordFragment() {
private var wordEmpty: Boolean = true
......
......@@ -13,6 +13,7 @@ import com.paktalin.vocabularynotebook.utils.removeFragment
import com.paktalin.vocabularynotebook.utils.visible
import kotlinx.android.synthetic.main.content_main.*
import kotlinx.android.synthetic.main.fragment_editable_word.*
import kotlinx.android.synthetic.main.submit.*
import kotlinx.android.synthetic.main.word_item.view.*
class EditWordFragment : WordFragment() {
......
package com.paktalin.vocabularynotebook.ui.fragments
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.paktalin.vocabularynotebook.R
import com.paktalin.vocabularynotebook.ui.activities.MainActivity
import com.paktalin.vocabularynotebook.utils.FirestoreManager
import com.paktalin.vocabularynotebook.utils.gone
import kotlinx.android.synthetic.main.fragment_editable_word.*
import kotlinx.android.synthetic.main.content_main.*
import kotlinx.android.synthetic.main.submit.*
abstract class WordFragment : Fragment() {
protected lateinit var mainActivity: MainActivity
......
package com.paktalin.vocabularynotebook.ui.recycler_view
import androidx.recyclerview.selection.ItemKeyProvider
import androidx.recyclerview.widget.RecyclerView
class MyItemKeyProvider(private val recyclerView: RecyclerView) : ItemKeyProvider<Long>(ItemKeyProvider.SCOPE_MAPPED) {
override fun getKey(position: Int): Long? {
return recyclerView.adapter?.getItemId(position)
}
override fun getPosition(key: Long): Int {
val viewHolder = recyclerView.findViewHolderForItemId(key)
return viewHolder?.layoutPosition ?: RecyclerView.NO_POSITION
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent">
......@@ -43,39 +41,6 @@
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/btnSubmitLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:orientation="horizontal"
android:visibility="gone"
android:layout_alignParentBottom="true">
<ImageButton
android:id="@+id/btnCancel"
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" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<ImageButton
android:id="@+id/btnSubmit"
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>
<include layout="@layout/submit" />
</RelativeLayout>
\ No newline at end of file
<?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/btnSubmitLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/colorPrimary"
android:orientation="horizontal"
android:visibility="gone">
<ImageButton
android:id="@+id/btnCancel"
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" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<ImageButton
android:id="@+id/btnSubmit"
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
......@@ -6,18 +6,17 @@
android:background="@color/colorPrimary"
android:orientation="vertical">
<Spinner
android:id="@+id/spinner2"
android:layout_width="match_parent"
<AutoCompleteTextView
android:id="@+id/brand"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="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
......@@ -22,4 +22,5 @@
<string name="toast_enter_username_password">Please, enter username and password</string>
<string name="toast_invalid_username">Please, create a username using letters a–z, numbers 0–9 and characters -_.</string>
<string name="toast_select_words_to_tag">Select words to tag</string>
<string name="enter_tag">Enter tag</string>
</resources>
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