Commit ddbdaae8 by Paktalin

Added options menu to WordItemInfoActivity

parent cd16c2cd
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="WizardSettings">
<option name="children">
<map>
<entry key="vectorWizard">
<value>
<PersistentState>
<option name="children">
<map>
<entry key="vectorAssetStep">
<value>
<PersistentState>
<option name="values">
<map>
<entry key="assetSourceType" value="FILE" />
<entry key="outputName" value="ic_edit_icon" />
<entry key="sourceFile" value="C:\Users\litak\Desktop\edit_icon.svg" />
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
</component>
</project>
\ No newline at end of file
......@@ -9,6 +9,9 @@ android {
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}
buildTypes {
release {
......
......@@ -32,8 +32,8 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>,
holder.tvWord.text = wordItem.pojo!!.word
holder.tvTranslation.text = wordItem.pojo!!.translation
holder.itemView.setOnClickListener { openWordItemInfo(wordItem) }
holder.itemView.setOnLongClickListener { deleteWordItem(position);true }
holder.btnPopupMenu.setOnClickListener { showPopupMenu(holder.btnPopupMenu) }
holder.btnPopupMenu.setOnClickListener { showPopupMenu(holder.btnPopupMenu, position) }
//todo set click listener to menu
}
override fun getItemCount(): Int {
......@@ -52,10 +52,13 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>,
context.startActivity(intentWordItemInfo)
}
private fun showPopupMenu(v: View) {
private fun showPopupMenu(v: View, position: Int) {
val popup = PopupMenu(context, 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()
}
......
......@@ -2,7 +2,7 @@ package com.paktalin.vocabularynotebook.activities
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.Menu
import com.paktalin.vocabularynotebook.R
import com.paktalin.vocabularynotebook.WordItem
import kotlinx.android.synthetic.main.activity_word_info.*
......@@ -15,10 +15,16 @@ class WordItemInfoActivity: AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_word_info)
wordItem = intent.getSerializableExtra("wordItem") as WordItem
updateUi()
setData()
}
private fun updateUi() {
override fun onCreateOptionsMenu(menu: Menu): Boolean {
val inflater = menuInflater
inflater.inflate(R.menu.word_item_info_menu, menu)
return true
}
private fun setData() {
tvWord.text = wordItem.pojo!!.word
tvTranslation.text = wordItem.pojo!!.translation
}
......
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
</vector>
......@@ -10,14 +10,14 @@
<TextView
android:id="@+id/tvWord"
android:layout_width="wrap_content"
android:layout_width="92dp"
android:layout_height="wrap_content"
android:text="word"
android:textSize="22sp" />
<TextView
android:id="@+id/tvTranslation"
android:layout_width="wrap_content"
android:layout_width="145dp"
android:layout_height="wrap_content"
android:text="translation"
android:textSize="22sp" />
......@@ -26,7 +26,8 @@
android:id="@+id/btnContextMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@android:drawable/ic_menu_edit" />
android:background="@android:color/transparent"
app:srcCompat="@drawable/ic_delete_icon" />
</TableRow>
</TableLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:title="Delete"
android:id="@+id/item_delete"
android:icon="@drawable/ic_delete_icon"
app:showAsAction="ifRoom"/>
<item android:title="Edit"
android:id="@+id/item_edit"
android:icon="@drawable/ic_edit_icon"
app:showAsAction="ifRoom"/>
</menu>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:title="Item" />
<item android:title="Item2" />
<item android:title="Delete"
android:id="@+id/item_delete"
android:icon="@drawable/ic_delete_icon"
app:showAsAction="always"/>
</menu>
\ 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