Commit 17f05b7a by Paktalin

Removed ScrollView for better performance

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