diff --git a/app/build.gradle b/app/build.gradle index 0932c06ea7..a1bbf24235 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1637 - versionName "0.16.37" + versionCode 1638 + versionName "0.16.38" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListAdapter.kt b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListAdapter.kt index 96f74009de..b7998da7ea 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListAdapter.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListAdapter.kt @@ -7,8 +7,10 @@ import android.view.ViewGroup import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.google.gson.Gson +import io.realm.Case import io.realm.Realm import io.realm.RealmList +import io.realm.RealmResults import org.ole.planet.myplanet.R import org.ole.planet.myplanet.databinding.AddNoteDialogBinding import org.ole.planet.myplanet.databinding.ChatShareDialogBinding @@ -18,6 +20,7 @@ import org.ole.planet.myplanet.datamanager.DatabaseService import org.ole.planet.myplanet.model.Conversation import org.ole.planet.myplanet.model.RealmChatHistory import org.ole.planet.myplanet.model.RealmMyTeam +import org.ole.planet.myplanet.model.RealmNews import org.ole.planet.myplanet.model.RealmNews.Companion.createNews import org.ole.planet.myplanet.model.RealmUserModel import org.ole.planet.myplanet.service.UserProfileDbHandler @@ -27,49 +30,59 @@ import org.ole.planet.myplanet.ui.team.BaseTeamFragment.Companion.settings import org.ole.planet.myplanet.utilities.Constants.PREFS_NAME import java.util.Date -class ChatHistoryListAdapter(var context: Context, private var chatHistory: List) : - RecyclerView.Adapter() { - private lateinit var rowChatHistoryBinding: RowChatHistoryBinding - private var chatHistoryItemClickListener: ChatHistoryItemClickListener? = null - private var filteredChatHistory: List = chatHistory - private var chatTitle: String? = "" - private lateinit var expandableListAdapter: ExpandableListAdapter - private lateinit var expandableTitleList: List - private lateinit var expandableDetailList: HashMap> - private lateinit var mRealm: Realm - var user: RealmUserModel? = null - - interface ChatHistoryItemClickListener { - fun onChatHistoryItemClicked(conversations: RealmList?, _id: String, _rev: String?) - } +class ChatHistoryListAdapter(var context: Context, private var chatHistory: List, private val fragment: ChatHistoryListFragment) : RecyclerView.Adapter() { + private lateinit var rowChatHistoryBinding: RowChatHistoryBinding + private var chatHistoryItemClickListener: ChatHistoryItemClickListener? = null + private var filteredChatHistory: List = chatHistory + private var chatTitle: String? = "" + private lateinit var expandableListAdapter: ExpandableListAdapter + private lateinit var expandableTitleList: List + private lateinit var expandableDetailList: HashMap> + private lateinit var mRealm: Realm + var user: RealmUserModel? = null + private var newsList: RealmResults? = null + + interface ChatHistoryItemClickListener { + fun onChatHistoryItemClicked(conversations: RealmList?, _id: String, _rev: String?) + } - fun setChatHistoryItemClickListener(listener: ChatHistoryItemClickListener) { - chatHistoryItemClickListener = listener - } + fun setChatHistoryItemClickListener(listener: ChatHistoryItemClickListener) { + chatHistoryItemClickListener = listener + } - fun filter(query: String) { - filteredChatHistory = chatHistory.filter { chat -> - if (chat.conversations != null && chat.conversations?.isNotEmpty() == true) { - chat.conversations?.get(0)?.query?.contains(query, ignoreCase = true) == true - } else { - chat.title?.contains(query, ignoreCase = true) ==true - } + fun filter(query: String) { + filteredChatHistory = chatHistory.filter { chat -> + if (chat.conversations != null && chat.conversations?.isNotEmpty() == true) { + chat.conversations?.get(0)?.query?.contains(query, ignoreCase = true) == true + } else { + chat.title?.contains(query, ignoreCase = true) ==true } - notifyDataSetChanged() } + notifyDataSetChanged() + } - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { rowChatHistoryBinding = RowChatHistoryBinding.inflate(LayoutInflater.from(parent.context), parent, false) mRealm = DatabaseService(context).realmInstance user = UserProfileDbHandler(context).userModel + newsList = mRealm.where(RealmNews::class.java) + .equalTo("docType", "message", Case.INSENSITIVE) + .equalTo("createdOn", user?.planetCode, Case.INSENSITIVE) + .findAll() return ViewHolderChat(rowChatHistoryBinding) } - override fun getItemCount(): Int { - return filteredChatHistory.size - } + override fun getItemCount(): Int { + return filteredChatHistory.size + } - override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { + fun updateChatHistory(newChatHistory: List) { + chatHistory = newChatHistory + filteredChatHistory = newChatHistory + notifyDataSetChanged() + } + + override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { val viewHolderChat = holder as ViewHolderChat if (filteredChatHistory[position].conversations != null && filteredChatHistory[position].conversations?.isNotEmpty() == true) { viewHolderChat.rowChatHistoryBinding.chatTitle.text = filteredChatHistory[position].conversations?.get(0)?.query @@ -90,53 +103,62 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List ) } - viewHolderChat.rowChatHistoryBinding.shareChat.setOnClickListener { - val chatShareDialogBinding = ChatShareDialogBinding.inflate(LayoutInflater.from(context)) - var dialog: AlertDialog? = null - - expandableDetailList = getData() as HashMap> - expandableTitleList = ArrayList(expandableDetailList.keys) - expandableListAdapter = ExpandableListAdapter(context, expandableTitleList, expandableDetailList) - chatShareDialogBinding.listView.setAdapter(expandableListAdapter) - - chatShareDialogBinding.listView.setOnChildClickListener { _, _, groupPosition, childPosition, id -> - if (expandableTitleList[groupPosition] == "share with team/enterprise") { - val teamList = mRealm.where(RealmMyTeam::class.java) - .isEmpty("teamId").notEqualTo("status", "archived") - .equalTo("type", "team").findAll() - - val enterpriseList = mRealm.where(RealmMyTeam::class.java) - .isEmpty("teamId").notEqualTo("status", "archived") - .equalTo("type", "enterprise").findAll() - - if (expandableDetailList[expandableTitleList[groupPosition]]?.get(childPosition) == "teams") { - showGrandChildRecyclerView(teamList, "teams", filteredChatHistory[position]) - } else { - showGrandChildRecyclerView(enterpriseList, "enterprises", filteredChatHistory[position]) - } - } else { - settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) - val sParentcode = settings?.getString("parentCode", "") - val communityName = settings?.getString("communityName", "") - val teamId = "$communityName@$sParentcode" - val community = mRealm.where(RealmMyTeam::class.java).equalTo("_id", teamId).findFirst() - showEditTextAndShareButton(community, "community", filteredChatHistory[position]) + val isInNewsList = newsList?.any { newsItem -> + newsItem.newsId == filteredChatHistory[position]._id + } ?: false + + if (isInNewsList) { + viewHolderChat.rowChatHistoryBinding.shareChat.setImageResource(R.drawable.baseline_check_24) + } else { + viewHolderChat.rowChatHistoryBinding.shareChat.setImageResource(R.drawable.baseline_share_24) + viewHolderChat.rowChatHistoryBinding.shareChat.setOnClickListener { + val chatShareDialogBinding = ChatShareDialogBinding.inflate(LayoutInflater.from(context)) + var dialog: AlertDialog? = null + + expandableDetailList = getData() as HashMap> + expandableTitleList = ArrayList(expandableDetailList.keys) + expandableListAdapter = ExpandableListAdapter(context, expandableTitleList, expandableDetailList) + chatShareDialogBinding.listView.setAdapter(expandableListAdapter) + + chatShareDialogBinding.listView.setOnChildClickListener { _, _, groupPosition, childPosition, _ -> + if (expandableTitleList[groupPosition] == "share with team/enterprise") { + val teamList = mRealm.where(RealmMyTeam::class.java) + .isEmpty("teamId").notEqualTo("status", "archived") + .equalTo("type", "team").findAll() + + val enterpriseList = mRealm.where(RealmMyTeam::class.java) + .isEmpty("teamId").notEqualTo("status", "archived") + .equalTo("type", "enterprise").findAll() + + if (expandableDetailList[expandableTitleList[groupPosition]]?.get(childPosition) == "teams") { + showGrandChildRecyclerView(teamList, "teams", filteredChatHistory[position]) + } else { + showGrandChildRecyclerView(enterpriseList, "enterprises", filteredChatHistory[position]) + } + } else { + settings = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) + val sParentcode = settings?.getString("parentCode", "") + val communityName = settings?.getString("communityName", "") + val teamId = "$communityName@$sParentcode" + val community = mRealm.where(RealmMyTeam::class.java).equalTo("_id", teamId).findFirst() + showEditTextAndShareButton(community, "community", filteredChatHistory[position]) + } + dialog?.dismiss() + false } - dialog?.dismiss() - false - } - val builder = AlertDialog.Builder(context) - builder.setView(chatShareDialogBinding.root) - builder.setPositiveButton(context.getString(R.string.close)) { _, _ -> - dialog?.dismiss() + val builder = AlertDialog.Builder(context) + builder.setView(chatShareDialogBinding.root) + builder.setPositiveButton(context.getString(R.string.close)) { _, _ -> + dialog?.dismiss() + } + dialog = builder.create() + dialog.show() } - dialog = builder.create() - dialog.show() } } - private fun showGrandChildRecyclerView(items: List, section: String, realmChatHistory: RealmChatHistory) { + private fun showGrandChildRecyclerView(items: List, section: String, realmChatHistory: RealmChatHistory) { val grandChildDialogBinding = GrandChildRecyclerviewDialogBinding.inflate(LayoutInflater.from(context)) var dialog: AlertDialog? = null @@ -161,7 +183,7 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List dialog.show() } - private fun showEditTextAndShareButton(team: RealmMyTeam? = null, section: String, chatHistory: RealmChatHistory) { + private fun showEditTextAndShareButton(team: RealmMyTeam? = null, section: String, chatHistory: RealmChatHistory) { val addNoteDialogBinding = AddNoteDialogBinding.inflate(LayoutInflater.from(context)) val builder = AlertDialog.Builder(context) builder.setView(addNoteDialogBinding.root) @@ -187,6 +209,7 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List map["news"] = Gson().toJson(serializedMap) createNews(map, mRealm, user, null) + fragment.refreshChatHistoryList() dialog.dismiss() } builder.setNegativeButton(context.getString(R.string.cancel)) { dialog, _ -> @@ -196,14 +219,14 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List dialog.show() } - private fun serializeConversation(conversation: Conversation): HashMap { + private fun serializeConversation(conversation: Conversation): HashMap { val conversationMap = HashMap() conversationMap["query"] = conversation.query ?: "" conversationMap["response"] = conversation.response ?: "" return conversationMap } - private fun getData(): Map> { + private fun getData(): Map> { val expandableListDetail: MutableMap> = HashMap() val community: MutableList = ArrayList() community.add("community") @@ -214,9 +237,8 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List expandableListDetail["share with community"] = community expandableListDetail["share with team/enterprise"] = teams - return expandableListDetail } - class ViewHolderChat(val rowChatHistoryBinding: RowChatHistoryBinding) : RecyclerView.ViewHolder(rowChatHistoryBinding.root) - } + class ViewHolderChat(val rowChatHistoryBinding: RowChatHistoryBinding) : RecyclerView.ViewHolder(rowChatHistoryBinding.root) +} diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListFragment.kt b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListFragment.kt index eff4d21193..513b67e805 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListFragment.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatHistoryListFragment.kt @@ -67,7 +67,7 @@ class ChatHistoryListFragment : Fragment() { filteredHistoryList.add(model) } } - val adapter = ChatHistoryListAdapter(requireContext(), list) + val adapter = ChatHistoryListAdapter(requireContext(), list, this) adapter.setChatHistoryItemClickListener(object : ChatHistoryListAdapter.ChatHistoryItemClickListener { override fun onChatHistoryItemClicked(conversations: RealmList?, _id: String, _rev:String?) { conversations?.let { sharedViewModel.setSelectedChatHistory(it) } @@ -89,6 +89,16 @@ class ChatHistoryListFragment : Fragment() { override fun afterTextChanged(s: Editable?) {} }) } + + fun refreshChatHistoryList() { + val mRealm = DatabaseService(requireActivity()).realmInstance + val list = mRealm.where(RealmChatHistory::class.java).equalTo("user", user?.name) + .sort("id", Sort.DESCENDING) + .findAll() + + val adapter = fragmentChatHistoryListBinding.recyclerView.adapter as ChatHistoryListAdapter + adapter.updateChatHistory(list) + } } class ChatHistoryListOnBackPressedCallback(private val slidingPaneLayout: SlidingPaneLayout) : diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/news/NewsFragment.kt b/app/src/main/java/org/ole/planet/myplanet/ui/news/NewsFragment.kt index 11471f4dfc..4da9cd7097 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/news/NewsFragment.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/news/NewsFragment.kt @@ -103,7 +103,7 @@ class NewsFragment : BaseNewsFragment() { return@setOnClickListener } fragmentNewsBinding.etMessage.setText("") - val map = HashMap() // Changed to String, String + val map = HashMap() map["message"] = message map["viewInId"] = "${user?.planetCode ?: ""}@${user?.parentCode ?: ""}" map["viewInSection"] = "community" diff --git a/app/src/main/res/drawable/baseline_check_24.xml b/app/src/main/res/drawable/baseline_check_24.xml new file mode 100644 index 0000000000..8907cc0940 --- /dev/null +++ b/app/src/main/res/drawable/baseline_check_24.xml @@ -0,0 +1,12 @@ + + + + + diff --git a/app/src/main/res/layout/row_chat_history.xml b/app/src/main/res/layout/row_chat_history.xml index 112eb601af..0cb4bebdfe 100644 --- a/app/src/main/res/layout/row_chat_history.xml +++ b/app/src/main/res/layout/row_chat_history.xml @@ -40,7 +40,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" - android:layout_marginEnd="@dimen/_4dp" + android:padding="10dp" android:background="?attr/selectableItemBackground" android:contentDescription="@string/share_chat" android:src="@drawable/baseline_share_24"