Commit 17f05b7a by Paktalin

Removed ScrollView for better performance

parent 17762c4f
......@@ -8,11 +8,9 @@ import android.support.v7.widget.RecyclerView
import android.view.*
import android.widget.LinearLayout
import android.widget.TextView
import com.google.firebase.Timestamp
import com.paktalin.vocabularynotebook.firestoreitems.WordItem
import com.paktalin.vocabularynotebook.ui.fragments.EditWordFragment
import com.paktalin.vocabularynotebook.ui.activities.MainActivity
import com.paktalin.vocabularynotebook.utils.FirestoreManager
import com.paktalin.vocabularynotebook.utils.addFragment
import kotlinx.android.synthetic.main.word_item.view.*
......@@ -75,12 +73,12 @@ class VocabularyAdapter(private val displayedVocabulary: Vocabulary, private val
this.notifyItemRangeChanged(position, displayedVocabulary.size())
}
fun updateAll() {
displayedVocabulary.clear()
fun refresh() {
/*displayedVocabulary.clear()
FirestoreManager().retrieveWordsData { documents ->
displayedVocabulary.addWordsAsDocuments(documents)
this.notifyDataSetChanged()
}
}*/
}
fun addWord(newWord: WordItem) {
......
......@@ -52,7 +52,7 @@ class MainActivity : AppCompatActivity() {
}
private fun refreshVocabulary() {
(recyclerView.adapter as VocabularyAdapter).updateAll()
(recyclerView.adapter as VocabularyAdapter).refresh()
swipeRefresh.isRefreshing = false
}
......@@ -79,7 +79,7 @@ class MainActivity : AppCompatActivity() {
vocabularyFragment = VocabularyFragment()
val arguments = Bundle()
arguments.putString("vocabularyId", vocabularyId)
addFragment(supportFragmentManager, vocabularyFragment, R.id.scrollView, arguments)
addFragment(supportFragmentManager, vocabularyFragment, R.id.swipeRefresh, arguments)
}
private fun hideKeyboard() {
......
......@@ -10,9 +10,11 @@ import android.view.inputmethod.InputMethodManager
import com.paktalin.vocabularynotebook.*
import com.paktalin.vocabularynotebook.firestoreitems.WordItem
import com.paktalin.vocabularynotebook.ui.activities.MainActivity
import com.paktalin.vocabularynotebook.ui.views.LockableLayoutManager
import com.paktalin.vocabularynotebook.utils.*
import kotlinx.android.synthetic.main.fragment_editable_word.*
import kotlinx.android.synthetic.main.content_main.*
import kotlinx.android.synthetic.main.fragment_vocabulary.*
import kotlinx.android.synthetic.main.word_item.view.*
class EditWordFragment : WordFragment() {
......@@ -30,13 +32,13 @@ class EditWordFragment : WordFragment() {
this.container = container
hidePreviousViews()
wordItem = arguments!!["wordItem"] as WordItem
(mainActivity.recyclerView.layoutManager as LockableLayoutManager).isScrollEnabled = false
return super.onCreateView(inflater, container, savedInstanceState)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
setWordItemData()
disableScrolling(mainActivity)
setFocusOnWord()
visible(mainActivity.btnSubmitLayout)
}
......@@ -96,7 +98,7 @@ class EditWordFragment : WordFragment() {
removeFragment(mainActivity.supportFragmentManager, this)
mainActivity.hideKeyboardNotFromActivity(mainActivity)
gone(mainActivity.btnSubmitLayout)
enableScrolling(mainActivity)
(mainActivity.recyclerView.layoutManager as LockableLayoutManager).isScrollEnabled = true
mainActivity.inEditMode = false
}
......
......@@ -38,7 +38,6 @@ class VocabularyFragment : Fragment() {
val emptyList: MutableList<WordItem> = mutableListOf()
recyclerView.adapter = VocabularyAdapter(Vocabulary(emptyList), mainActivity)
val mLayoutManager = LockableLayoutManager(mainActivity)
mLayoutManager.setScrollingEnabled(false)
recyclerView.layoutManager = mLayoutManager
}
......
......@@ -2,15 +2,16 @@ package com.paktalin.vocabularynotebook.ui.views
import android.content.Context
import android.support.v7.widget.LinearLayoutManager
import com.paktalin.vocabularynotebook.ui.fragments.VocabularyFragment
class LockableLayoutManager(context: Context) : LinearLayoutManager(context) {
private var isScrollEnabled = true
fun setScrollingEnabled(flag: Boolean) {
this.isScrollEnabled = flag
}
internal var isScrollEnabled = true
override fun canScrollVertically(): Boolean {
return isScrollEnabled && super.canScrollVertically()
}
companion object {
private val TAG = "VN/" + VocabularyFragment::class.simpleName
}
}
package com.paktalin.vocabularynotebook.ui.views
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.widget.ScrollView
internal class LockableScrollView : ScrollView {
private var isScrollable = true
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
fun setScrollingEnabled(enabled: Boolean) {
isScrollable = enabled
}
override fun onTouchEvent(ev: MotionEvent): Boolean {
return when (ev.action) {
MotionEvent.ACTION_DOWN ->
// if we can scroll pass the event to the superclass
isScrollable && super.onTouchEvent(ev)
else -> super.onTouchEvent(ev)
}
}
override fun onInterceptTouchEvent(ev: MotionEvent): Boolean {
// Don't do anything with intercepted touch events if
// we are not scrollable
return isScrollable && super.onInterceptTouchEvent(ev)
}
}
......@@ -39,14 +39,6 @@ fun fieldsNotEmpty(text1: String, text2: String, toastMessage: String, context:
return true
}
fun disableScrolling(mainActivity: MainActivity) {
mainActivity.scrollView!!.setScrollingEnabled(false)
}
fun enableScrolling(mainActivity: MainActivity) {
mainActivity.scrollView!!.setScrollingEnabled(true)
}
fun shortToast(context: Context, text: String) {
Toast.makeText(context, text, Toast.LENGTH_SHORT).show()
}
......
......@@ -31,7 +31,6 @@
android:layout_height="wrap_content" />
</FrameLayout>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipeRefresh"
android:layout_width="match_parent"
......@@ -45,19 +44,13 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/container_main"
android:paddingBottom="@dimen/small_padding"
android:paddingEnd="@dimen/small_padding"
android:paddingLeft="@dimen/small_padding"
android:paddingRight="@dimen/small_padding"
android:paddingStart="@dimen/small_padding"
android:background="@drawable/sheet_bottom">
<com.paktalin.vocabularynotebook.ui.views.LockableScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:scrollbars="vertical"
android:paddingBottom="@dimen/small_padding"
android:paddingEnd="@dimen/small_padding"
android:paddingLeft="@dimen/small_padding"
android:paddingRight="@dimen/small_padding"
android:paddingStart="@dimen/small_padding">
</com.paktalin.vocabularynotebook.ui.views.LockableScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
<LinearLayout
......
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