Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
likorn
/
vocabulary_notebook
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
17f05b7a
authored
Nov 12, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed ScrollView for better performance
parent
17762c4f
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
18 additions
and
70 deletions
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/MainActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/EditWordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/VocabularyFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/views/LockableLayoutManager.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/views/LockableScrollView.kt
app/src/main/java/com/paktalin/vocabularynotebook/utils/ActivityUtil.kt
app/src/main/res/layout/content_main.xml
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
View file @
17f05b7a
...
...
@@ -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
)
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/MainActivity.kt
View file @
17f05b7a
...
...
@@ -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
.
s
crollView
,
arguments
)
addFragment
(
supportFragmentManager
,
vocabularyFragment
,
R
.
id
.
s
wipeRefresh
,
arguments
)
}
private
fun
hideKeyboard
()
{
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/EditWordFragment.kt
View file @
17f05b7a
...
...
@@ -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
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/VocabularyFragment.kt
View file @
17f05b7a
...
...
@@ -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
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/views/LockableLayoutManager.kt
View file @
17f05b7a
...
...
@@ -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
}
}
app/src/main/java/com/paktalin/vocabularynotebook/ui/views/LockableScrollView.kt
deleted
100644 → 0
View file @
17762c4f
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
)
}
}
app/src/main/java/com/paktalin/vocabularynotebook/utils/ActivityUtil.kt
View file @
17f05b7a
...
...
@@ -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
()
}
...
...
app/src/main/res/layout/content_main.xml
View file @
17f05b7a
...
...
@@ -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: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:paddingStart=
"@dimen/small_padding"
android:background=
"@drawable/sheet_bottom"
>
</android.support.v4.widget.SwipeRefreshLayout>
<LinearLayout
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment