Commit c4e730c5 by Paktalin

Word is fixed in edit mode

parent 082f67fb
package com.paktalin.vocabularynotebook
import android.content.Context
import android.support.v7.widget.LinearLayoutManager
class LockableLayoutManager(context: Context) : LinearLayoutManager(context) {
private var isScrollEnabled = true
fun setScrollingEnabled(flag: Boolean) {
this.isScrollEnabled = flag
}
override fun canScrollVertically(): Boolean {
return isScrollEnabled && super.canScrollVertically()
}
}
package com.paktalin.vocabularynotebook
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)
}
}
...@@ -38,6 +38,8 @@ class EditWordFragment : WordFragment() { ...@@ -38,6 +38,8 @@ class EditWordFragment : WordFragment() {
private fun setWordItemData() { private fun setWordItemData() {
word.setText(wordItem.pojo.word) word.setText(wordItem.pojo.word)
translation.setText(wordItem.pojo.translation) translation.setText(wordItem.pojo.translation)
editable_word.setBackgroundColor(resources.getColor(R.color.green_highlight))
disableScrolling()
} }
private fun setFocusOnWord() { private fun setFocusOnWord() {
...@@ -80,6 +82,10 @@ class EditWordFragment : WordFragment() { ...@@ -80,6 +82,10 @@ class EditWordFragment : WordFragment() {
removeFragment(mainActivity.supportFragmentManager, this) removeFragment(mainActivity.supportFragmentManager, this)
} }
private fun disableScrolling() {
mainActivity.scrollView!!.setScrollingEnabled(false)
}
override fun updateRecycleView(wordItem: WordItem) { override fun updateRecycleView(wordItem: WordItem) {
mainActivity.vocabularyFragment.updateWord(wordItem) mainActivity.vocabularyFragment.updateWord(wordItem)
} }
......
...@@ -2,7 +2,6 @@ package com.paktalin.vocabularynotebook.ui.fragments ...@@ -2,7 +2,6 @@ package com.paktalin.vocabularynotebook.ui.fragments
import android.os.Bundle import android.os.Bundle
import android.support.v4.app.Fragment import android.support.v4.app.Fragment
import android.support.v7.widget.LinearLayoutManager
import android.util.Log import android.util.Log
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
...@@ -41,7 +40,8 @@ class VocabularyFragment : Fragment() { ...@@ -41,7 +40,8 @@ class VocabularyFragment : Fragment() {
private fun setEmptyAdapter() { private fun setEmptyAdapter() {
val emptyList: MutableList<WordItem> = mutableListOf() val emptyList: MutableList<WordItem> = mutableListOf()
recyclerView.adapter = VocabularyAdapter(Vocabulary(emptyList), mainActivity) recyclerView.adapter = VocabularyAdapter(Vocabulary(emptyList), mainActivity)
val mLayoutManager = LinearLayoutManager(mainActivity) val mLayoutManager = LockableLayoutManager(mainActivity)
mLayoutManager.setScrollingEnabled(false)
recyclerView.layoutManager = mLayoutManager recyclerView.layoutManager = mLayoutManager
} }
......
...@@ -31,7 +31,8 @@ ...@@ -31,7 +31,8 @@
android:layout_height="wrap_content"/> android:layout_height="wrap_content"/>
</FrameLayout> </FrameLayout>
<ScrollView <com.paktalin.vocabularynotebook.LockableScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_marginEnd="@dimen/small_margin" android:layout_marginEnd="@dimen/small_margin"
...@@ -39,11 +40,10 @@ ...@@ -39,11 +40,10 @@
android:layout_marginRight="@dimen/small_margin" android:layout_marginRight="@dimen/small_margin"
android:layout_marginStart="@dimen/small_margin" android:layout_marginStart="@dimen/small_margin"
android:scrollbars="vertical" android:scrollbars="vertical"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toTopOf="@+id/btnSubmitLayout"
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">
app:layout_constraintVertical_bias="0.0">
<LinearLayout <LinearLayout
android:id="@+id/container_vocabulary" android:id="@+id/container_vocabulary"
...@@ -58,25 +58,40 @@ ...@@ -58,25 +58,40 @@
android:paddingBottom="@dimen/small_padding"> android:paddingBottom="@dimen/small_padding">
</LinearLayout> </LinearLayout>
</ScrollView> </com.paktalin.vocabularynotebook.LockableScrollView>
<FrameLayout <LinearLayout
android:id="@+id/btnSubmitLayout" android:id="@+id/btnSubmitLayout"
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:visibility="gone" android:visibility="gone"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"> app:layout_constraintBottom_toBottomOf="parent">
<ImageButton <ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_close_icon"
android:background="@android:color/transparent"
android:layout_gravity="center_vertical"
android:layout_margin="@dimen/small_margin"
tools:ignore="ContentDescription" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"/>
<ImageButton
android:id="@+id/btnSubmit" android:id="@+id/btnSubmit"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end" android:layout_gravity="center_vertical"
android:layout_margin="@dimen/small_margin" android:layout_margin="@dimen/small_margin"
android:background="@android:color/transparent" android:background="@android:color/transparent"
app:srcCompat="@drawable/ic_done_icon" app:srcCompat="@drawable/ic_done_icon"
tools:ignore="ContentDescription" /> tools:ignore="ContentDescription" />
</FrameLayout> </LinearLayout>
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>
\ No newline at end of file
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
tools:ignore="ContentDescription" /> tools:ignore="ContentDescription" />
<LinearLayout <LinearLayout
android:id="@+id/editable_word"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout <android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/word_item_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
......
...@@ -4,4 +4,5 @@ ...@@ -4,4 +4,5 @@
<color name="colorPrimaryDark">#303F9F</color> <color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color> <color name="colorAccent">#FF4081</color>
<color name="sheet_color">#FAFAFA</color> <color name="sheet_color">#FAFAFA</color>
<color name="green_highlight">#69B578</color>
</resources> </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