add elements to predefinedStatusesList correctly

Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
sowjanyakch 2024-11-05 22:04:51 +01:00
parent 974da71e52
commit ec01a049c8
No known key found for this signature in database
GPG Key ID: F7AA2A8B65B50220
6 changed files with 35 additions and 17 deletions

View File

@ -16,7 +16,8 @@ import com.nextcloud.talk.models.json.status.predefined.PredefinedStatus
class PredefinedStatusListAdapter( class PredefinedStatusListAdapter(
private val clickListener: PredefinedStatusClickListener, private val clickListener: PredefinedStatusClickListener,
val context: Context val context: Context,
var isBackupStatusAvailable: Boolean
) : RecyclerView.Adapter<PredefinedStatusViewHolder>() { ) : RecyclerView.Adapter<PredefinedStatusViewHolder>() {
internal var list: List<PredefinedStatus> = emptyList() internal var list: List<PredefinedStatus> = emptyList()
@ -26,7 +27,7 @@ class PredefinedStatusListAdapter(
} }
override fun onBindViewHolder(holder: PredefinedStatusViewHolder, position: Int) { override fun onBindViewHolder(holder: PredefinedStatusViewHolder, position: Int) {
holder.bind(list[position], clickListener, context) holder.bind(list[position], clickListener, context, isBackupStatusAvailable)
} }
override fun getItemCount(): Int { override fun getItemCount(): Int {

View File

@ -17,15 +17,19 @@ import com.nextcloud.talk.utils.DisplayUtils
private const val ONE_SECOND_IN_MILLIS = 1000 private const val ONE_SECOND_IN_MILLIS = 1000
@Suppress("DEPRECATION")
class PredefinedStatusViewHolder(private val binding: PredefinedStatusBinding) : RecyclerView.ViewHolder(binding.root) { class PredefinedStatusViewHolder(private val binding: PredefinedStatusBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(status: PredefinedStatus, clickListener: PredefinedStatusClickListener, context: Context) { fun bind(
status: PredefinedStatus,
clickListener: PredefinedStatusClickListener,
context: Context,
isBackupStatusAvailable: Boolean
) {
binding.root.setOnClickListener { clickListener.onClick(status) } binding.root.setOnClickListener { clickListener.onClick(status) }
binding.icon.text = status.icon binding.icon.text = status.icon
binding.name.text = status.message binding.name.text = status.message
binding.resetStatusButton.visibility = if (position == 0) View.VISIBLE else View.GONE
if (status.clearAt == null) { if (status.clearAt == null) {
binding.clearAt.text = context.getString(R.string.dontClear) binding.clearAt.text = context.getString(R.string.dontClear)
} else { } else {
@ -43,5 +47,11 @@ class PredefinedStatusViewHolder(private val binding: PredefinedStatusBinding) :
} }
} }
} }
if (isBackupStatusAvailable) {
binding.resetStatusButton.visibility = if (position == 0) View.VISIBLE else View.GONE
if (position == 0) {
binding.clearAt.text = context.getString(R.string.previously_set)
}
}
} }
} }

View File

@ -94,6 +94,7 @@ class SetStatusDialogFragment :
private lateinit var adapter: PredefinedStatusListAdapter private lateinit var adapter: PredefinedStatusListAdapter
private var clearAt: Long? = null private var clearAt: Long? = null
private lateinit var popup: EmojiPopup private lateinit var popup: EmojiPopup
private var isBackupStatusAvailable = false
@Inject @Inject
lateinit var ncApi: NcApi lateinit var ncApi: NcApi
@ -130,6 +131,7 @@ class SetStatusDialogFragment :
.subscribe(object : Observer<ResponseBody> { .subscribe(object : Observer<ResponseBody> {
override fun onSubscribe(d: Disposable) {} override fun onSubscribe(d: Disposable) {}
@SuppressLint("NotifyDataSetChanged")
override fun onNext(responseBody: ResponseBody) { override fun onNext(responseBody: ResponseBody) {
val predefinedStatusOverall: PredefinedStatusOverall = LoganSquare.parse( val predefinedStatusOverall: PredefinedStatusOverall = LoganSquare.parse(
responseBody.string(), responseBody.string(),
@ -162,18 +164,20 @@ class SetStatusDialogFragment :
override fun onSubscribe(d: Disposable) { override fun onSubscribe(d: Disposable) {
} }
@SuppressLint("NotifyDataSetChanged")
override fun onNext(statusOverall: StatusOverall) { override fun onNext(statusOverall: StatusOverall) {
if (statusOverall.ocs?.meta?.statusCode == 200) { if (statusOverall.ocs?.meta?.statusCode == 200) {
val status = statusOverall.ocs?.data val status = statusOverall.ocs?.data
if (status?.messageIsPredefined == false) { isBackupStatusAvailable = true
val backupPredefinedStatus = PredefinedStatus( val backupPredefinedStatus = PredefinedStatus(
status?.userId!!, status?.userId!!,
status.icon, status.icon,
status.message!!, status.message!!,
ClearAt(type = "period", time = status.clearAt.toString()) ClearAt(type = "period", time = status.clearAt.toString())
) )
adapter.isBackupStatusAvailable = true
predefinedStatusesList.add(0, backupPredefinedStatus) predefinedStatusesList.add(0, backupPredefinedStatus)
} adapter.notifyDataSetChanged()
} }
} }
@ -202,7 +206,7 @@ class SetStatusDialogFragment :
setupCurrentStatus() setupCurrentStatus()
adapter = PredefinedStatusListAdapter(this, requireContext()) adapter = PredefinedStatusListAdapter(this, requireContext(), isBackupStatusAvailable)
adapter.list = predefinedStatusesList adapter.list = predefinedStatusesList
binding.predefinedStatusList.adapter = adapter binding.predefinedStatusList.adapter = adapter

View File

@ -59,6 +59,8 @@
android:textColor="@android:color/holo_red_light" android:textColor="@android:color/holo_red_light"
android:text= "@string/reset_status" android:text= "@string/reset_status"
android:textSize="14sp" android:textSize="14sp"
android:padding="8dp"/> android:padding="8dp"
android:visibility="gone"
tools:visibility="visible"/>
</LinearLayout> </LinearLayout>

View File

@ -827,5 +827,6 @@ How to translate with transifex:
<string name="archived">Archived</string> <string name="archived">Archived</string>
<string name="archive_hint">Once a conversation is archived, it will be hidden by default. Select the filter \'Archived\' to view archived conversations. Direct mentions will still be received.</string> <string name="archive_hint">Once a conversation is archived, it will be hidden by default. Select the filter \'Archived\' to view archived conversations. Direct mentions will still be received.</string>
<string name="unarchive_hint">Once a conversation is unarchived, it will be shown by default again.</string> <string name="unarchive_hint">Once a conversation is unarchived, it will be shown by default again.</string>
<string name="previously_set">Previously set</string>
<string name="conversation_read_only_failed">Failed to set conversation Read-only</string> <string name="conversation_read_only_failed">Failed to set conversation Read-only</string>
</resources> </resources>