Skip to content

Commit

Permalink
Merge branch 'master' into 4456-team-list-ui-inconsistency
Browse files Browse the repository at this point in the history
  • Loading branch information
dogi authored Sep 24, 2024
2 parents 7e6c290 + 904d4a4 commit d51ba4e
Show file tree
Hide file tree
Showing 26 changed files with 174 additions and 210 deletions.
39 changes: 25 additions & 14 deletions app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatAdapter.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package org.ole.planet.myplanet.ui.chat

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.os.Handler
import android.os.Looper
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import io.realm.RealmList
import org.ole.planet.myplanet.R
import org.ole.planet.myplanet.databinding.ItemAiResponseMessageBinding
import org.ole.planet.myplanet.databinding.ItemUserMessageBinding
import org.ole.planet.myplanet.model.Conversation

class ChatAdapter(private val chatList: ArrayList<String>, val context: Context, private val recyclerView: RecyclerView) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private lateinit var textUserMessageBinding: ItemUserMessageBinding
Expand All @@ -30,28 +31,37 @@ class ChatAdapter(private val chatList: ArrayList<String>, val context: Context,
this.chatItemClickListener = listener
}

class QueryViewHolder(private val textUserMessageBinding: ItemUserMessageBinding) : RecyclerView.ViewHolder(textUserMessageBinding.root) {
class QueryViewHolder(private val textUserMessageBinding: ItemUserMessageBinding, private val copyToClipboard: (String) -> Unit) : RecyclerView.ViewHolder(textUserMessageBinding.root) {
fun bind(query: String) {
textUserMessageBinding.textGchatMessageMe.text = query

textUserMessageBinding.textGchatMessageMe.setOnLongClickListener {
copyToClipboard(query)
true
}
}
}

class ResponseViewHolder(private val textAiMessageBinding: ItemAiResponseMessageBinding, val context: Context) : RecyclerView.ViewHolder(textAiMessageBinding.root) {
class ResponseViewHolder(private val textAiMessageBinding: ItemAiResponseMessageBinding, private val copyToClipboard: (String) -> Unit, val context: Context) : RecyclerView.ViewHolder(textAiMessageBinding.root) {
fun bind(response: String, responseSource: Int) {
if(responseSource == RESPONSE_SOURCE_NETWORK){
if (responseSource == RESPONSE_SOURCE_NETWORK) {
val typingDelayMillis = 10L
val typingAnimationDurationMillis = response.length * typingDelayMillis
textAiMessageBinding.textGchatMessageOther.text = context.getString(R.string.empty_text)
Handler(Looper.getMainLooper()).postDelayed({
animateTyping(response)
}, typingAnimationDurationMillis)
} else if(responseSource == RESPONSE_SOURCE_SHARED_VIEW_MODEL){
} else if (responseSource == RESPONSE_SOURCE_SHARED_VIEW_MODEL) {
if (response.isNotEmpty()) {
textAiMessageBinding.textGchatMessageOther.text = response
} else{
textAiMessageBinding.textGchatMessageOther.visibility = View.GONE
}
}
textAiMessageBinding.textGchatMessageOther.setOnLongClickListener {
copyToClipboard(response)
true
}
}

private fun animateTyping(response: String) {
Expand All @@ -69,6 +79,13 @@ class ChatAdapter(private val chatList: ArrayList<String>, val context: Context,
}
}

private fun copyToClipboard(text: String) {
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
val clip = ClipData.newPlainText("copied Text", text)
clipboard.setPrimaryClip(clip)
Toast.makeText(context, context.getString(R.string.copied_to_clipboard), Toast.LENGTH_SHORT).show()
}

fun addQuery(query: String) {
chatList.add(query)
notifyItemInserted(chatList.size - 1)
Expand Down Expand Up @@ -102,11 +119,11 @@ class ChatAdapter(private val chatList: ArrayList<String>, val context: Context,
return when (viewType) {
viewTypeQuery -> {
textUserMessageBinding = ItemUserMessageBinding.inflate(LayoutInflater.from(context), parent, false)
QueryViewHolder(textUserMessageBinding)
QueryViewHolder(textUserMessageBinding, this::copyToClipboard)
}
viewTypeResponse -> {
textAiMessageBinding = ItemAiResponseMessageBinding.inflate(LayoutInflater.from(context), parent, false)
ResponseViewHolder(textAiMessageBinding, context)
ResponseViewHolder(textAiMessageBinding, this::copyToClipboard, context)
}
else -> throw IllegalArgumentException("Invalid view type")
}
Expand Down Expand Up @@ -138,11 +155,5 @@ class ChatAdapter(private val chatList: ArrayList<String>, val context: Context,
const val RESPONSE_SOURCE_SHARED_VIEW_MODEL = 1
const val RESPONSE_SOURCE_NETWORK = 2
const val RESPONSE_SOURCE_UNKNOWN = 0

private var chatHistoryItemClickListener: ChatHistoryListAdapter.ChatHistoryItemClickListener? = null

fun clickListener(conversations: String?, newsId: String?, newsRev: String?) {
chatHistoryItemClickListener?.onChatHistoryItemClicked(conversations as RealmList<Conversation>?, newsId ?: "", newsRev ?: "")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import io.realm.Realm
import io.realm.Sort
import org.json.JSONObject
import org.ole.planet.myplanet.R
import org.ole.planet.myplanet.R.array.status_options
import org.ole.planet.myplanet.callback.OnHomeItemClickListener
import org.ole.planet.myplanet.databinding.FragmentNotificationBinding
import org.ole.planet.myplanet.datamanager.DatabaseService
Expand All @@ -24,6 +25,7 @@ import org.ole.planet.myplanet.model.RealmTeamTask
import org.ole.planet.myplanet.ui.dashboard.DashboardActivity
import org.ole.planet.myplanet.ui.resources.ResourcesFragment
import org.ole.planet.myplanet.ui.team.TeamDetailFragment
import java.util.ArrayList

class NotificationFragment : Fragment() {
private lateinit var fragmentNotificationBinding: FragmentNotificationBinding
Expand Down Expand Up @@ -54,27 +56,29 @@ class NotificationFragment : Fragment() {

val notifications = loadNotifications(userId, "all")

val spinnerAdapter = ArrayAdapter.createFromResource(requireContext(), R.array.status_options, android.R.layout.simple_spinner_item)
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
fragmentNotificationBinding.status?.adapter = spinnerAdapter
fragmentNotificationBinding.status?.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
val options = resources.getStringArray(status_options)
val optionsList: MutableList<String?> = ArrayList(listOf(*options))
val spinnerAdapter = ArrayAdapter(requireContext(), R.layout.spinner_item, optionsList)
spinnerAdapter.setDropDownViewResource(R.layout.spinner_item)
fragmentNotificationBinding.status.adapter = spinnerAdapter
fragmentNotificationBinding.status.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>, view: View?, position: Int, id: Long) {
val selectedOption = parent.getItemAtPosition(position).toString().lowercase()
val filteredNotifications = loadNotifications(userId, selectedOption)
adapter.updateNotifications(filteredNotifications)

if (filteredNotifications.isEmpty()) {
fragmentNotificationBinding.emptyData?.visibility = View.VISIBLE
fragmentNotificationBinding.emptyData.visibility = View.VISIBLE
} else {
fragmentNotificationBinding.emptyData?.visibility = View.GONE
fragmentNotificationBinding.emptyData.visibility = View.GONE
}
}

override fun onNothingSelected(parent: AdapterView<*>) {}
}

if (notifications.isEmpty()) {
fragmentNotificationBinding.emptyData?.visibility = View.VISIBLE
fragmentNotificationBinding.emptyData.visibility = View.VISIBLE
}

adapter = AdapterNotification(notifications,
Expand All @@ -87,7 +91,7 @@ class NotificationFragment : Fragment() {
fragmentNotificationBinding.rvNotifications.adapter = adapter
fragmentNotificationBinding.rvNotifications.layoutManager = LinearLayoutManager(requireContext())

fragmentNotificationBinding.btnMarkAllAsRead?.setOnClickListener {
fragmentNotificationBinding.btnMarkAllAsRead.setOnClickListener {
markAllAsRead()
}

Expand Down Expand Up @@ -162,14 +166,14 @@ class NotificationFragment : Fragment() {
.findAll()
.forEach { it.isRead = true }
}
adapter.updateNotifications(loadNotifications(userId, fragmentNotificationBinding.status?.selectedItem.toString().lowercase()))
adapter.updateNotifications(loadNotifications(userId, fragmentNotificationBinding.status.selectedItem.toString().lowercase()))
updateMarkAllAsReadButtonVisibility()
updateUnreadCount()
}

private fun updateMarkAllAsReadButtonVisibility() {
val unreadCount = getUnreadNotificationsSize()
fragmentNotificationBinding.btnMarkAllAsRead?.visibility = if (unreadCount > 0) View.VISIBLE else View.GONE
fragmentNotificationBinding.btnMarkAllAsRead.visibility = if (unreadCount > 0) View.VISIBLE else View.GONE
}

private fun getUnreadNotificationsSize(): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class AdapterReports(private val context: Context, private var list: RealmResult

reportListItemBinding.delete.setOnClickListener {
report?._id?.let { reportId ->
val builder = AlertDialog.Builder(context)
val builder = AlertDialog.Builder(context, R.style.AlertDialogTheme)
builder.setTitle("Delete Report")
.setMessage(R.string.delete_record)
.setPositiveButton(R.string.ok) { _, _ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -121,7 +120,7 @@ class FeedbackDetailActivity : AppCompatActivity() {

inner class RvFeedbackAdapter(private val replyList: List<FeedbackReply>?, var context: Context) : RecyclerView.Adapter<ReplyViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ReplyViewHolder {
rowFeedbackReplyBinding = RowFeedbackReplyBinding.inflate(LayoutInflater.from(context), parent, false)
rowFeedbackReplyBinding = RowFeedbackReplyBinding.inflate(layoutInflater, parent, false)
return ReplyViewHolder(rowFeedbackReplyBinding)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import android.widget.ListView
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.ContextCompat
import com.google.gson.JsonArray
import com.google.gson.JsonObject
import fisk.chipcloud.ChipCloud
Expand Down Expand Up @@ -192,6 +193,9 @@ class EditAchievementFragment : BaseContainerFragment(), DatePickerDialog.OnDate
alertAddAttachmentBinding.btnAddResources.setOnClickListener {
showResourceListDialog(prevList)
}
val tintColor = ContextCompat.getColorStateList(requireContext(), R.color.daynight_textColor)
alertAddAttachmentBinding.etDesc.backgroundTintList = tintColor
alertAddAttachmentBinding.etTitle.backgroundTintList = tintColor
val alertAddAttachmentView: View = alertAddAttachmentBinding.root
AlertDialog.Builder(requireActivity(), R.style.AlertDialogTheme)
.setTitle(R.string.add_achievement)
Expand Down
47 changes: 0 additions & 47 deletions app/src/main/res/layout-night/fragment_notification.xml

This file was deleted.

Loading

0 comments on commit d51ba4e

Please sign in to comment.