Commit bf2888fe by Paktalin

WordInfo can be closed. WordItem can be deleted from WordInfo

parent 93464da6
......@@ -44,22 +44,10 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
(activity as MainActivity).supportFragmentManager.beginTransaction().add(R.id.content, wordInfoFragment).commit()
}
private fun showPopupMenu(v: View, position: Int) {
val popup = PopupMenu(activity, v)
val inflater = popup.menuInflater
inflater.inflate(R.menu.word_item_menu, popup.menu)
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)
fun deleteWordItem(wordItem: WordItem) {
wordItem.delete()
val position = wordItems.indexOf(wordItem)
wordItems.remove(wordItem)
recyclerView.removeViewAt(position)
this.notifyItemRemoved(position)
this.notifyItemRangeChanged(position, wordItems.size)
......
......@@ -13,17 +13,20 @@ import android.view.WindowManager
import android.app.Activity
import android.view.View
import android.view.inputmethod.InputMethodManager
import com.paktalin.vocabularynotebook.WordItem
import com.paktalin.vocabularynotebook.appsetup.ConfiguredFirestore
class MainActivity : AppCompatActivity() {
lateinit var vocabularyId: String
lateinit var vocabularyFragment: VocabularyFragment
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
hideKeyboard()
setUpNavigationView()
vocabularyFragment = supportFragmentManager.findFragmentById(R.id.fragment_vocabulary) as VocabularyFragment
extractVocabularyData()
}
......@@ -56,8 +59,7 @@ class MainActivity : AppCompatActivity() {
//todo represent specific vocabulary instead of the first one
val vocabulary = db.collection("vocabularies").document(vocabularies[0].id)
vocabularyId = vocabulary.id
(supportFragmentManager.findFragmentById(R.id.fragment_vocabulary) as VocabularyFragment)
.retrieveWordsData(vocabularyId)
vocabularyFragment.retrieveWordsData(vocabularyId)
}
}
......@@ -74,5 +76,9 @@ class MainActivity : AppCompatActivity() {
imm.hideSoftInputFromWindow(view.windowToken, 0)
}
fun deleteWordItem(wordItem: WordItem) {
vocabularyFragment.deleteWordItem(wordItem)
}
companion object { private val TAG = "VN/" + MainActivity::class.simpleName }
}
\ No newline at end of file
......@@ -60,6 +60,10 @@ class VocabularyFragment : Fragment() {
recyclerView.adapter = adapter
}
fun deleteWordItem(wordItem: WordItem) {
(recyclerView.adapter as VocabularyAdapter).deleteWordItem(wordItem)
}
fun addWordItem(newWordItem: WordItem) {
(recyclerView.adapter as VocabularyAdapter).addWordItem(newWordItem)
}
......
......@@ -2,7 +2,6 @@ package com.paktalin.vocabularynotebook.ui
import android.os.Bundle
import android.support.v4.app.Fragment
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
......@@ -22,6 +21,8 @@ class WordInfoFragment : Fragment() {
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
setData()
btnClose.setOnClickListener { closeFragment() }
btnDelete.setOnClickListener { deleteItem() }
}
private fun setData() {
......@@ -29,4 +30,13 @@ class WordInfoFragment : Fragment() {
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
......@@ -2,11 +2,11 @@
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="250dp"
android:layout_height="180dp"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="300dp"
android:layout_height="200dp"
android:background="@android:color/white"
android:layout_gravity="center"
>
android:layout_gravity="center">
<TextView
android:id="@+id/etWord"
......@@ -15,9 +15,8 @@
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Word"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toBottomOf="@+id/toolBar" />
<TextView
android:id="@+id/etTranslation"
......@@ -26,8 +25,35 @@
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Translation"
app:layout_constraintStart_toStartOf="parent"
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>
\ No newline at end of file
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