Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chat: mark shared (fixes #3734) #3735

Merged
merged 4 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -38,6 +41,7 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List
private lateinit var expandableDetailList: HashMap<String, List<String>>
private lateinit var mRealm: Realm
var user: RealmUserModel? = null
private var newsList: RealmResults<RealmNews>? = null

interface ChatHistoryItemClickListener {
fun onChatHistoryItemClicked(conversations: RealmList<Conversation>?, _id: String, _rev: String?)
Expand All @@ -59,10 +63,14 @@ class ChatHistoryListAdapter(var context: Context, private var chatHistory: List
}

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
return ViewHolderChat(rowChatHistoryBinding)
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 {
Expand Down Expand Up @@ -90,49 +98,58 @@ 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<String, List<String>>
expandableTitleList = ArrayList<String>(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<String, List<String>>
expandableTitleList = ArrayList<String>(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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class NewsFragment : BaseNewsFragment() {
return@setOnClickListener
}
fragmentNewsBinding.etMessage.setText("")
val map = HashMap<String?, String>() // Changed to String, String
val map = HashMap<String?, String>()
map["message"] = message
map["viewInId"] = "${user?.planetCode ?: ""}@${user?.parentCode ?: ""}"
map["viewInSection"] = "community"
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/baseline_check_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorPrimary"
android:viewportWidth="24"
android:viewportHeight="24">

<path
android:fillColor="@android:color/white"
android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z" />

</vector>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/row_chat_history.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down