Commit c8b88113 by Paktalin

WordInfoFragment is opened when a list item is clicked

parent c53a7d01
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.READ_CONTACTS" />
<application <application
android:name=".VocabularyApplication" android:name=".app_setup.VocabularyApplication"
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".ui.WordItemInfoActivity" />
</application> </application>
</manifest> </manifest>
\ No newline at end of file
package com.paktalin.vocabularynotebook
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.FirebaseFirestoreSettings
object ConfiguredFirestore {
val instance: FirebaseFirestore
get() {
val firestore = FirebaseFirestore.getInstance()
val settings = FirebaseFirestoreSettings.Builder()
.setTimestampsInSnapshotsEnabled(true)
.build()
firestore.firestoreSettings = settings
return firestore
}
}
...@@ -2,6 +2,7 @@ package com.paktalin.vocabularynotebook ...@@ -2,6 +2,7 @@ package com.paktalin.vocabularynotebook
import android.util.Log import android.util.Log
import com.google.firebase.auth.FirebaseUser import com.google.firebase.auth.FirebaseUser
import com.paktalin.vocabularynotebook.app_setup.ConfiguredFirestore
import com.paktalin.vocabularynotebook.ui.LogInActivity import com.paktalin.vocabularynotebook.ui.LogInActivity
import com.paktalin.vocabularynotebook.pojo.UserPojo import com.paktalin.vocabularynotebook.pojo.UserPojo
import com.paktalin.vocabularynotebook.pojo.VocabularyPojo import com.paktalin.vocabularynotebook.pojo.VocabularyPojo
......
package com.paktalin.vocabularynotebook package com.paktalin.vocabularynotebook
import android.app.Activity import android.app.Activity
import android.content.Intent import android.os.Bundle
import android.support.v7.widget.PopupMenu import android.support.v7.widget.PopupMenu
import android.support.v7.widget.RecyclerView import android.support.v7.widget.RecyclerView
import android.util.Log import android.util.Log
import android.view.* import android.view.*
import android.widget.ImageButton
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.TextView import android.widget.TextView
import com.paktalin.vocabularynotebook.ui.MainActivity import com.paktalin.vocabularynotebook.ui.MainActivity
import com.paktalin.vocabularynotebook.ui.WordInfoFragment import com.paktalin.vocabularynotebook.ui.WordInfoFragment
import com.paktalin.vocabularynotebook.ui.WordItemInfoActivity
class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private val context: Activity) : RecyclerView.Adapter<VocabularyAdapter.ViewHolder>() { class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private val activity: Activity) : RecyclerView.Adapter<VocabularyAdapter.ViewHolder>() {
private lateinit var recyclerView: RecyclerView private lateinit var recyclerView: RecyclerView
...@@ -39,17 +37,15 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va ...@@ -39,17 +37,15 @@ class VocabularyAdapter(private val wordItems: MutableList<WordItem>, private va
override fun getItemCount(): Int { return wordItems.size } override fun getItemCount(): Int { return wordItems.size }
private fun openWordItemInfo(wordItem: WordItem) { private fun openWordItemInfo(wordItem: WordItem) {
/* val intentWordItemInfo = Intent(context, WordItemInfoActivity::class.java) val wordInfoFragment = WordInfoFragment()
intentWordItemInfo.putExtra("wordItem", wordItem) val arguments = Bundle()
context.startActivity(intentWordItemInfo)*/ arguments.putSerializable("wordItem", wordItem)
wordInfoFragment.arguments = arguments
Log.d(TAG, "starting transaction") (activity as MainActivity).supportFragmentManager.beginTransaction().add(R.id.content, wordInfoFragment).commit()
//todo start word info fragment
/*(context as MainActivity).supportFragmentManager.beginTransaction().add(R.id.for_fragment, WordInfoFragment()).commit()*/
} }
private fun showPopupMenu(v: View, position: Int) { private fun showPopupMenu(v: View, position: Int) {
val popup = PopupMenu(context, v) val popup = PopupMenu(activity, v)
val inflater = popup.menuInflater val inflater = popup.menuInflater
inflater.inflate(R.menu.word_item_menu, popup.menu) inflater.inflate(R.menu.word_item_menu, popup.menu)
popup.setOnMenuItemClickListener { popup.setOnMenuItemClickListener {
......
package com.paktalin.vocabularynotebook package com.paktalin.vocabularynotebook
import android.util.Log import android.util.Log
import com.paktalin.vocabularynotebook.app_setup.ConfiguredFirestore
import java.io.Serializable import java.io.Serializable
......
package com.paktalin.vocabularynotebook; package com.paktalin.vocabularynotebook.app_setup;
import android.app.Application; import android.app.Application;
......
...@@ -13,7 +13,7 @@ import android.view.WindowManager ...@@ -13,7 +13,7 @@ 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.ConfiguredFirestore import com.paktalin.vocabularynotebook.app_setup.ConfiguredFirestore
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
......
...@@ -11,7 +11,7 @@ import android.view.ViewGroup ...@@ -11,7 +11,7 @@ import android.view.ViewGroup
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.ImageButton import android.widget.ImageButton
import android.widget.Toast import android.widget.Toast
import com.paktalin.vocabularynotebook.ConfiguredFirestore import com.paktalin.vocabularynotebook.app_setup.ConfiguredFirestore
import com.paktalin.vocabularynotebook.R import com.paktalin.vocabularynotebook.R
import com.paktalin.vocabularynotebook.WordItem import com.paktalin.vocabularynotebook.WordItem
import kotlinx.android.synthetic.main.fragment_new_word.* import kotlinx.android.synthetic.main.fragment_new_word.*
......
...@@ -9,6 +9,7 @@ import android.view.ViewGroup ...@@ -9,6 +9,7 @@ import android.view.ViewGroup
import com.google.firebase.auth.FirebaseAuth import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.firestore.DocumentSnapshot import com.google.firebase.firestore.DocumentSnapshot
import com.paktalin.vocabularynotebook.* import com.paktalin.vocabularynotebook.*
import com.paktalin.vocabularynotebook.app_setup.ConfiguredFirestore
import kotlinx.android.synthetic.main.fragment_vocabulary.* import kotlinx.android.synthetic.main.fragment_vocabulary.*
class VocabularyFragment : Fragment() { class VocabularyFragment : Fragment() {
......
...@@ -7,12 +7,26 @@ import android.view.LayoutInflater ...@@ -7,12 +7,26 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import com.paktalin.vocabularynotebook.R import com.paktalin.vocabularynotebook.R
import com.paktalin.vocabularynotebook.WordItem
import kotlinx.android.synthetic.main.activity_word_info.*
class WordInfoFragment : Fragment() { class WordInfoFragment : Fragment() {
private lateinit var wordItem:WordItem
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
Log.d("TTT", "onCreateView") wordItem = arguments!!["wordItem"] as WordItem
return inflater.inflate(R.layout.activity_word_info, container, false) return inflater.inflate(R.layout.activity_word_info, container, false)
} }
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
setData()
}
private fun setData() {
etWord.text = wordItem.pojo!!.word
etTranslation.text = wordItem.pojo!!.translation
}
} }
\ No newline at end of file
package com.paktalin.vocabularynotebook.ui
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.Menu
import android.view.MenuItem
import com.paktalin.vocabularynotebook.R
import com.paktalin.vocabularynotebook.WordItem
import kotlinx.android.synthetic.main.activity_word_info.*
class WordItemInfoActivity: AppCompatActivity() {
private lateinit var wordItem: WordItem
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_word_info)
wordItem = intent.getSerializableExtra("wordItem") as WordItem
setData()
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
val inflater = menuInflater
inflater.inflate(R.menu.word_item_info_menu, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item!!.itemId) {
R.id.item_delete -> {
wordItem.delete()
cancel()
}
R.id.item_edit -> {
//todo edit item
}
}
return true
}
private fun setData() {
etWord.text = wordItem.pojo!!.word
etTranslation.text = wordItem.pojo!!.translation
}
private fun cancel() {
val intentMainActivity = Intent(this, MainActivity::class.java)
startActivity(intentMainActivity)
}
companion object { private val TAG = "VN/" + WordItemInfoActivity::class.java.simpleName }
}
\ No newline at end of file
...@@ -7,6 +7,11 @@ ...@@ -7,6 +7,11 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:openDrawer="start"> tools:openDrawer="start">
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/notebook_sheet" /> <include layout="@layout/notebook_sheet" />
<include <include
...@@ -14,6 +19,8 @@ ...@@ -14,6 +19,8 @@
layout="@layout/progress" layout="@layout/progress"
android:visibility="gone" /> android:visibility="gone" />
</FrameLayout>
<android.support.design.widget.NavigationView <android.support.design.widget.NavigationView
android:id="@+id/navigationView" android:id="@+id/navigationView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="250dp" android:layout_width="250dp"
android:layout_height="180dp" android:layout_height="180dp"
android:layout_gravity="center"> android:background="@android:color/white"
android:layout_gravity="center"
>
<TextView <TextView
android:id="@+id/etWord" android:id="@+id/etWord"
......
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