mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-06 14:27:24 +00:00
add elements to predefinedStatusesList correctly
Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
parent
974da71e52
commit
ec01a049c8
@ -16,7 +16,8 @@ import com.nextcloud.talk.models.json.status.predefined.PredefinedStatus
|
||||
|
||||
class PredefinedStatusListAdapter(
|
||||
private val clickListener: PredefinedStatusClickListener,
|
||||
val context: Context
|
||||
val context: Context,
|
||||
var isBackupStatusAvailable: Boolean
|
||||
) : RecyclerView.Adapter<PredefinedStatusViewHolder>() {
|
||||
internal var list: List<PredefinedStatus> = emptyList()
|
||||
|
||||
@ -26,7 +27,7 @@ class PredefinedStatusListAdapter(
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: PredefinedStatusViewHolder, position: Int) {
|
||||
holder.bind(list[position], clickListener, context)
|
||||
holder.bind(list[position], clickListener, context, isBackupStatusAvailable)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
|
@ -17,15 +17,19 @@ import com.nextcloud.talk.utils.DisplayUtils
|
||||
|
||||
private const val ONE_SECOND_IN_MILLIS = 1000
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
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.icon.text = status.icon
|
||||
binding.name.text = status.message
|
||||
|
||||
binding.resetStatusButton.visibility = if (position == 0) View.VISIBLE else View.GONE
|
||||
|
||||
if (status.clearAt == null) {
|
||||
binding.clearAt.text = context.getString(R.string.dontClear)
|
||||
} 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,6 +94,7 @@ class SetStatusDialogFragment :
|
||||
private lateinit var adapter: PredefinedStatusListAdapter
|
||||
private var clearAt: Long? = null
|
||||
private lateinit var popup: EmojiPopup
|
||||
private var isBackupStatusAvailable = false
|
||||
|
||||
@Inject
|
||||
lateinit var ncApi: NcApi
|
||||
@ -130,6 +131,7 @@ class SetStatusDialogFragment :
|
||||
.subscribe(object : Observer<ResponseBody> {
|
||||
override fun onSubscribe(d: Disposable) {}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
override fun onNext(responseBody: ResponseBody) {
|
||||
val predefinedStatusOverall: PredefinedStatusOverall = LoganSquare.parse(
|
||||
responseBody.string(),
|
||||
@ -162,18 +164,20 @@ class SetStatusDialogFragment :
|
||||
override fun onSubscribe(d: Disposable) {
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
override fun onNext(statusOverall: StatusOverall) {
|
||||
if (statusOverall.ocs?.meta?.statusCode == 200) {
|
||||
val status = statusOverall.ocs?.data
|
||||
if (status?.messageIsPredefined == false) {
|
||||
val backupPredefinedStatus = PredefinedStatus(
|
||||
status?.userId!!,
|
||||
status.icon,
|
||||
status.message!!,
|
||||
ClearAt(type = "period", time = status.clearAt.toString())
|
||||
)
|
||||
predefinedStatusesList.add(0, backupPredefinedStatus)
|
||||
}
|
||||
isBackupStatusAvailable = true
|
||||
val backupPredefinedStatus = PredefinedStatus(
|
||||
status?.userId!!,
|
||||
status.icon,
|
||||
status.message!!,
|
||||
ClearAt(type = "period", time = status.clearAt.toString())
|
||||
)
|
||||
adapter.isBackupStatusAvailable = true
|
||||
predefinedStatusesList.add(0, backupPredefinedStatus)
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,7 +206,7 @@ class SetStatusDialogFragment :
|
||||
|
||||
setupCurrentStatus()
|
||||
|
||||
adapter = PredefinedStatusListAdapter(this, requireContext())
|
||||
adapter = PredefinedStatusListAdapter(this, requireContext(), isBackupStatusAvailable)
|
||||
adapter.list = predefinedStatusesList
|
||||
|
||||
binding.predefinedStatusList.adapter = adapter
|
||||
|
@ -274,7 +274,7 @@ object CapabilitiesUtil {
|
||||
user.capabilities?.userStatusCapability?.enabled == true &&
|
||||
user.capabilities?.userStatusCapability?.supportsEmoji == true
|
||||
|
||||
fun isRestoreStatusAvailable(user: User): Boolean {
|
||||
fun isRestoreStatusAvailable(user: User): Boolean {
|
||||
return user.capabilities?.userStatusCapability?.restore == true
|
||||
}
|
||||
|
||||
|
@ -59,6 +59,8 @@
|
||||
android:textColor="@android:color/holo_red_light"
|
||||
android:text= "@string/reset_status"
|
||||
android:textSize="14sp"
|
||||
android:padding="8dp"/>
|
||||
android:padding="8dp"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -827,5 +827,6 @@ How to translate with transifex:
|
||||
<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="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>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user