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
1473c257
authored
Apr 21, 2019
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved selection logic to mainActivity (temporary) + completed tag layout
parent
12b51fb5
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
23 deletions
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/WordFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/selection_tracker/MySelectionTracker.kt
app/src/main/res/layout/submit.xml
app/src/main/res/layout/tag.xml
app/src/main/java/com/paktalin/vocabularynotebook/ui/activities/MainActivity.kt
View file @
1473c257
...
@@ -18,6 +18,7 @@ import com.paktalin.vocabularynotebook.vocabulary.Sort
...
@@ -18,6 +18,7 @@ import com.paktalin.vocabularynotebook.vocabulary.Sort
import
com.paktalin.vocabularynotebook.vocabulary.VocabSet
import
com.paktalin.vocabularynotebook.vocabulary.VocabSet
import
kotlinx.android.synthetic.main.activity_main.*
import
kotlinx.android.synthetic.main.activity_main.*
import
kotlinx.android.synthetic.main.content_main.*
import
kotlinx.android.synthetic.main.content_main.*
import
kotlinx.android.synthetic.main.tag.*
class
MainActivity
:
AppCompatActivity
()
{
class
MainActivity
:
AppCompatActivity
()
{
...
@@ -119,7 +120,17 @@ class MainActivity : AppCompatActivity() {
...
@@ -119,7 +120,17 @@ class MainActivity : AppCompatActivity() {
private
fun
setUpSelectionTracker
()
{
private
fun
setUpSelectionTracker
()
{
vocabularyAdapter
.
selectionTracker
=
MySelectionTracker
().
apply
{
vocabularyAdapter
.
selectionTracker
=
MySelectionTracker
().
apply
{
init
(
recyclerView
)
init
(
recyclerView
)
addObserver
(
this
@MainActivity
)
addObserver
{
selection
->
run
{
if
(!
selection
.
isEmpty
)
{
// TODO disable popup menu
Log
.
d
(
TAG
,
"selection ${selection.toList()}"
)
visible
(
tagLayout
)
}
else
{
gone
(
tagLayout
)
}
}
}
}
}
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/EditWordFragment.kt
View file @
1473c257
...
@@ -73,7 +73,7 @@ class EditWordFragment : WordFragment() {
...
@@ -73,7 +73,7 @@ class EditWordFragment : WordFragment() {
private
fun
stop
()
{
private
fun
stop
()
{
// set onClickListener from AddWordFragment
// set onClickListener from AddWordFragment
mainActivity
.
btnSubmit
.
setOnClickListener
{
(
mainActivity
.
fragmentAddWord
as
AddWordFragment
).
submitWord
()
}
mainActivity
.
btnSubmit
Word
.
setOnClickListener
{
(
mainActivity
.
fragmentAddWord
as
AddWordFragment
).
submitWord
()
}
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
removeFragment
(
mainActivity
.
supportFragmentManager
,
this
)
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
mainActivity
.
hideKeyboardNotFromActivity
(
mainActivity
)
gone
(
mainActivity
.
btnSubmitLayout
)
gone
(
mainActivity
.
btnSubmitLayout
)
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/fragments/WordFragment.kt
View file @
1473c257
...
@@ -21,8 +21,8 @@ abstract class WordFragment : Fragment() {
...
@@ -21,8 +21,8 @@ abstract class WordFragment : Fragment() {
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
super
.
onActivityCreated
(
savedInstanceState
)
super
.
onActivityCreated
(
savedInstanceState
)
mainActivity
=
activity
as
MainActivity
mainActivity
=
activity
as
MainActivity
mainActivity
.
btnSubmit
.
setOnClickListener
{
submitWord
()
}
mainActivity
.
btnSubmit
Word
.
setOnClickListener
{
submitWord
()
}
mainActivity
.
btnCancel
.
setOnClickListener
{
cancelEditing
()
}
mainActivity
.
btnCancel
Word
.
setOnClickListener
{
cancelEditing
()
}
btnClear
.
setOnClickListener
{
clearFields
()
}
btnClear
.
setOnClickListener
{
clearFields
()
}
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/recycler_view/selection_tracker/MySelectionTracker.kt
View file @
1473c257
package
com.paktalin.vocabularynotebook.ui.recycler_view.selection_tracker
package
com.paktalin.vocabularynotebook.ui.recycler_view.selection_tracker
import
androidx.recyclerview.selection.Selection
import
androidx.recyclerview.selection.SelectionPredicates
import
androidx.recyclerview.selection.SelectionPredicates
import
androidx.recyclerview.selection.SelectionTracker
import
androidx.recyclerview.selection.SelectionTracker
import
androidx.recyclerview.selection.StorageStrategy
import
androidx.recyclerview.selection.StorageStrategy
import
androidx.recyclerview.widget.RecyclerView
import
androidx.recyclerview.widget.RecyclerView
import
com.paktalin.vocabularynotebook.ui.activities.MainActivity
import
com.paktalin.vocabularynotebook.utils.Log
import
com.paktalin.vocabularynotebook.utils.gone
import
com.paktalin.vocabularynotebook.utils.visible
import
kotlinx.android.synthetic.main.tag.*
class
MySelectionTracker
{
class
MySelectionTracker
{
private
var
tracker
:
SelectionTracker
<
Long
>?
=
null
private
var
tracker
:
SelectionTracker
<
Long
>?
=
null
...
@@ -25,17 +21,11 @@ class MySelectionTracker {
...
@@ -25,17 +21,11 @@ class MySelectionTracker {
).
build
()
).
build
()
}
}
fun
addObserver
(
mainActivity
:
MainActivity
)
{
fun
addObserver
(
whenSelectionChanged
:
(
selection
:
Selection
<
Long
>)
->
Unit
)
{
tracker
?.
addObserver
(
object
:
SelectionTracker
.
SelectionObserver
<
Long
>()
{
tracker
?.
addObserver
(
object
:
SelectionTracker
.
SelectionObserver
<
Long
>()
{
override
fun
onSelectionChanged
()
{
override
fun
onSelectionChanged
()
{
super
.
onSelectionChanged
()
super
.
onSelectionChanged
()
if
(
tracker
?.
hasSelection
()
!!
)
{
tracker
?.
selection
?.
let
{
whenSelectionChanged
(
it
)
}
// TODO disable popup menu
Log
.
d
(
TAG
,
"selection ${tracker?.selection?.toList().toString()}"
)
visible
(
mainActivity
.
tagLayout
)
}
else
{
gone
(
mainActivity
.
tagLayout
)
}
}
}
})
})
}
}
...
...
app/src/main/res/layout/submit.xml
View file @
1473c257
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
android:visibility=
"gone"
>
android:visibility=
"gone"
>
<ImageButton
<ImageButton
android:id=
"@+id/btnCancel"
android:id=
"@+id/btnCancel
Word
"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center_vertical"
android:layout_gravity=
"center_vertical"
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
android:layout_weight=
"1"
/>
android:layout_weight=
"1"
/>
<ImageButton
<ImageButton
android:id=
"@+id/btnSubmit"
android:id=
"@+id/btnSubmit
Word
"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center_vertical"
android:layout_gravity=
"center_vertical"
...
...
app/src/main/res/layout/tag.xml
View file @
1473c257
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<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/tagLayout"
android:id=
"@+id/tagLayout"
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:layout_alignParentBottom=
"true"
android:layout_alignParentBottom=
"true"
android:orientation=
"vertical"
android:background=
"@color/colorPrimary"
android:orientation=
"horizontal"
android:visibility=
"gone"
>
android:visibility=
"gone"
>
<ImageButton
android:id=
"@+id/btnCancelTag"
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"
/>
<AutoCompleteTextView
<AutoCompleteTextView
android:id=
"@+id/tag"
android:id=
"@+id/tag"
android:layout_width=
"
match_parent
"
android:layout_width=
"
0dp
"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_margin=
"8dp"
android:layout_marginTop=
"8dp"
android:layout_marginBottom=
"8dp"
android:layout_weight=
"1"
android:hint=
"@string/enter_tag"
/>
android:hint=
"@string/enter_tag"
/>
<ImageButton
android:id=
"@+id/btnSubmitTag"
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>
</LinearLayout>
\ No newline at end of file
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