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
bf2888fe
authored
Sep 11, 2018
by
Paktalin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WordInfo can be closed. WordItem can be deleted from WordInfo
parent
93464da6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
26 deletions
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/VocabularyFragment.kt
app/src/main/java/com/paktalin/vocabularynotebook/ui/WordInfoFragment.kt
app/src/main/res/layout/activity_word_info.xml
app/src/main/java/com/paktalin/vocabularynotebook/VocabularyAdapter.kt
View file @
bf2888fe
...
@@ -44,22 +44,10 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
...
@@ -44,22 +44,10 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
(
activity
as
MainActivity
).
supportFragmentManager
.
beginTransaction
().
add
(
R
.
id
.
content
,
wordInfoFragment
).
commit
()
(
activity
as
MainActivity
).
supportFragmentManager
.
beginTransaction
().
add
(
R
.
id
.
content
,
wordInfoFragment
).
commit
()
}
}
private
fun
showPopupMenu
(
v
:
View
,
position
:
Int
)
{
fun
deleteWordItem
(
wordItem
:
WordItem
)
{
val
popup
=
PopupMenu
(
activity
,
v
)
wordItem
.
delete
()
val
inflater
=
popup
.
menuInflater
val
position
=
wordItems
.
indexOf
(
wordItem
)
inflater
.
inflate
(
R
.
menu
.
word_item_menu
,
popup
.
menu
)
wordItems
.
remove
(
wordItem
)
popup
.
setOnMenuItemClickListener
{
if
(
it
.
itemId
==
R
.
id
.
item_delete
)
{
deleteWordItem
(
position
)
}
true
}
popup
.
show
()
}
private
fun
deleteWordItem
(
position
:
Int
)
{
wordItems
[
position
].
delete
()
wordItems
.
removeAt
(
position
)
recyclerView
.
removeViewAt
(
position
)
recyclerView
.
removeViewAt
(
position
)
this
.
notifyItemRemoved
(
position
)
this
.
notifyItemRemoved
(
position
)
this
.
notifyItemRangeChanged
(
position
,
wordItems
.
size
)
this
.
notifyItemRangeChanged
(
position
,
wordItems
.
size
)
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/MainActivity.kt
View file @
bf2888fe
...
@@ -13,17 +13,20 @@ import android.view.WindowManager
...
@@ -13,17 +13,20 @@ import android.view.WindowManager
import
android.app.Activity
import
android.app.Activity
import
android.view.View
import
android.view.View
import
android.view.inputmethod.InputMethodManager
import
android.view.inputmethod.InputMethodManager
import
com.paktalin.vocabularynotebook.WordItem
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
import
com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
class
MainActivity
:
AppCompatActivity
()
{
class
MainActivity
:
AppCompatActivity
()
{
lateinit
var
vocabularyId
:
String
lateinit
var
vocabularyId
:
String
lateinit
var
vocabularyFragment
:
VocabularyFragment
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_main
)
setContentView
(
R
.
layout
.
activity_main
)
hideKeyboard
()
hideKeyboard
()
setUpNavigationView
()
setUpNavigationView
()
vocabularyFragment
=
supportFragmentManager
.
findFragmentById
(
R
.
id
.
fragment_vocabulary
)
as
VocabularyFragment
extractVocabularyData
()
extractVocabularyData
()
}
}
...
@@ -56,8 +59,7 @@ class MainActivity : AppCompatActivity() {
...
@@ -56,8 +59,7 @@ class MainActivity : AppCompatActivity() {
//todo represent specific vocabulary instead of the first one
//todo represent specific vocabulary instead of the first one
val
vocabulary
=
db
.
collection
(
"vocabularies"
).
document
(
vocabularies
[
0
].
id
)
val
vocabulary
=
db
.
collection
(
"vocabularies"
).
document
(
vocabularies
[
0
].
id
)
vocabularyId
=
vocabulary
.
id
vocabularyId
=
vocabulary
.
id
(
supportFragmentManager
.
findFragmentById
(
R
.
id
.
fragment_vocabulary
)
as
VocabularyFragment
)
vocabularyFragment
.
retrieveWordsData
(
vocabularyId
)
.
retrieveWordsData
(
vocabularyId
)
}
}
}
}
...
@@ -74,5 +76,9 @@ class MainActivity : AppCompatActivity() {
...
@@ -74,5 +76,9 @@ class MainActivity : AppCompatActivity() {
imm
.
hideSoftInputFromWindow
(
view
.
windowToken
,
0
)
imm
.
hideSoftInputFromWindow
(
view
.
windowToken
,
0
)
}
}
fun
deleteWordItem
(
wordItem
:
WordItem
)
{
vocabularyFragment
.
deleteWordItem
(
wordItem
)
}
companion
object
{
private
val
TAG
=
"VN/"
+
MainActivity
::
class
.
simpleName
}
companion
object
{
private
val
TAG
=
"VN/"
+
MainActivity
::
class
.
simpleName
}
}
}
\ No newline at end of file
app/src/main/java/com/paktalin/vocabularynotebook/ui/VocabularyFragment.kt
View file @
bf2888fe
...
@@ -60,6 +60,10 @@ class VocabularyFragment : Fragment() {
...
@@ -60,6 +60,10 @@ class VocabularyFragment : Fragment() {
recyclerView
.
adapter
=
adapter
recyclerView
.
adapter
=
adapter
}
}
fun
deleteWordItem
(
wordItem
:
WordItem
)
{
(
recyclerView
.
adapter
as
VocabularyAdapter
).
deleteWordItem
(
wordItem
)
}
fun
addWordItem
(
newWordItem
:
WordItem
)
{
fun
addWordItem
(
newWordItem
:
WordItem
)
{
(
recyclerView
.
adapter
as
VocabularyAdapter
).
addWordItem
(
newWordItem
)
(
recyclerView
.
adapter
as
VocabularyAdapter
).
addWordItem
(
newWordItem
)
}
}
...
...
app/src/main/java/com/paktalin/vocabularynotebook/ui/WordInfoFragment.kt
View file @
bf2888fe
...
@@ -2,7 +2,6 @@ package com.paktalin.vocabularynotebook.ui
...
@@ -2,7 +2,6 @@ package com.paktalin.vocabularynotebook.ui
import
android.os.Bundle
import
android.os.Bundle
import
android.support.v4.app.Fragment
import
android.support.v4.app.Fragment
import
android.util.Log
import
android.view.LayoutInflater
import
android.view.LayoutInflater
import
android.view.View
import
android.view.View
import
android.view.ViewGroup
import
android.view.ViewGroup
...
@@ -22,6 +21,8 @@ class WordInfoFragment : Fragment() {
...
@@ -22,6 +21,8 @@ class WordInfoFragment : Fragment() {
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
override
fun
onActivityCreated
(
savedInstanceState
:
Bundle
?)
{
super
.
onActivityCreated
(
savedInstanceState
)
super
.
onActivityCreated
(
savedInstanceState
)
setData
()
setData
()
btnClose
.
setOnClickListener
{
closeFragment
()
}
btnDelete
.
setOnClickListener
{
deleteItem
()
}
}
}
private
fun
setData
()
{
private
fun
setData
()
{
...
@@ -29,4 +30,13 @@ class WordInfoFragment : Fragment() {
...
@@ -29,4 +30,13 @@ class WordInfoFragment : Fragment() {
etTranslation
.
text
=
wordItem
.
pojo
!!
.
translation
etTranslation
.
text
=
wordItem
.
pojo
!!
.
translation
}
}
private
fun
closeFragment
()
{
activity
!!
.
supportFragmentManager
.
beginTransaction
().
remove
(
this
).
commit
()
}
private
fun
deleteItem
()
{
(
activity
as
MainActivity
).
deleteWordItem
(
wordItem
)
closeFragment
()
}
}
}
\ No newline at end of file
app/src/main/res/layout/activity_word_info.xml
View file @
bf2888fe
...
@@ -2,11 +2,11 @@
...
@@ -2,11 +2,11 @@
<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"
android:layout_width=
"250dp"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_height=
"180dp"
android:layout_width=
"300dp"
android:layout_height=
"200dp"
android:background=
"@android:color/white"
android:background=
"@android:color/white"
android:layout_gravity=
"center"
android:layout_gravity=
"center"
>
>
<TextView
<TextView
android:id=
"@+id/etWord"
android:id=
"@+id/etWord"
...
@@ -15,9 +15,8 @@
...
@@ -15,9 +15,8 @@
android:layout_marginLeft=
"8dp"
android:layout_marginLeft=
"8dp"
android:layout_marginStart=
"8dp"
android:layout_marginStart=
"8dp"
android:layout_marginTop=
"8dp"
android:layout_marginTop=
"8dp"
android:text=
"Word"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_to
TopOf=
"parent
"
/>
app:layout_constraintTop_to
BottomOf=
"@+id/toolBar
"
/>
<TextView
<TextView
android:id=
"@+id/etTranslation"
android:id=
"@+id/etTranslation"
...
@@ -26,8 +25,35 @@
...
@@ -26,8 +25,35 @@
android:layout_marginLeft=
"8dp"
android:layout_marginLeft=
"8dp"
android:layout_marginStart=
"8dp"
android:layout_marginStart=
"8dp"
android:layout_marginTop=
"8dp"
android:layout_marginTop=
"8dp"
android:text=
"Translation"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/etWord"
/>
app:layout_constraintTop_toBottomOf=
"@+id/etWord"
/>
<RelativeLayout
android:id=
"@+id/toolBar"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
android:background=
"@color/colorPrimary"
>
<ImageButton
android:id=
"@+id/btnClose"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_alignParentEnd=
"true"
android:background=
"@android:color/transparent"
app:srcCompat=
"@drawable/ic_cancel_icon"
tools:ignore=
"ContentDescription"
android:layout_alignParentRight=
"true"
/>
<ImageButton
android:id=
"@+id/btnDelete"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
app:srcCompat=
"@drawable/ic_delete_icon"
tools:ignore=
"ContentDescription"
android:background=
"@android:color/transparent"
android:layout_toLeftOf=
"@+id/btnClose"
/>
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
\ 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