search: fix reacting with emojis
This commit is contained in:
parent
41ee259196
commit
2ee70be3e4
@ -1,6 +1,7 @@
|
||||
package com.keylesspalace.tusky.components.search
|
||||
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.paging.PagedList
|
||||
@ -217,6 +218,23 @@ class SearchViewModel @Inject constructor(
|
||||
search(currentQuery)
|
||||
}
|
||||
|
||||
fun setEmojiReactionForStatus(idx: Int, newStatus: Status) {
|
||||
val newPair = Pair(newStatus,
|
||||
ViewDataUtils.statusToViewData(newStatus, alwaysShowSensitiveMedia, alwaysOpenSpoiler)!!)
|
||||
loadedStatuses[idx] = newPair
|
||||
repoResultStatus.value?.refresh?.invoke()
|
||||
}
|
||||
|
||||
fun emojiReact(react: Boolean, emoji: String, statusId: String) {
|
||||
loadedStatuses.indexOfFirst { it.first.id == statusId }.let { idx ->
|
||||
timelineCases.react(emoji, statusId, react)
|
||||
.subscribe(
|
||||
{ newStatus -> setEmojiReactionForStatus(idx, newStatus)},
|
||||
{ Log.d(TAG,"Failed to react with $emoji to ${loadedStatuses[idx].first.id}", it)}
|
||||
)
|
||||
.autoDispose()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "SearchViewModel"
|
||||
|
@ -25,6 +25,7 @@ import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Environment
|
||||
import android.util.Log
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
@ -38,16 +39,15 @@ import androidx.paging.PagedListAdapter
|
||||
import androidx.preference.PreferenceManager
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.keylesspalace.tusky.BaseActivity
|
||||
import com.keylesspalace.tusky.MainActivity
|
||||
import com.keylesspalace.tusky.R
|
||||
import com.keylesspalace.tusky.ViewMediaActivity
|
||||
import com.keylesspalace.tusky.*
|
||||
import com.keylesspalace.tusky.AccountListActivity.Companion.newIntent
|
||||
import com.keylesspalace.tusky.components.compose.ComposeActivity
|
||||
import com.keylesspalace.tusky.components.compose.ComposeActivity.ComposeOptions
|
||||
import com.keylesspalace.tusky.components.report.ReportActivity
|
||||
import com.keylesspalace.tusky.components.search.adapter.SearchStatusesAdapter
|
||||
import com.keylesspalace.tusky.db.AccountEntity
|
||||
import com.keylesspalace.tusky.entity.Attachment
|
||||
import com.keylesspalace.tusky.entity.EmojiReaction
|
||||
import com.keylesspalace.tusky.entity.Status
|
||||
import com.keylesspalace.tusky.entity.Status.Mention
|
||||
import com.keylesspalace.tusky.interfaces.AccountSelectionListener
|
||||
@ -466,4 +466,36 @@ class SearchStatusesFragment : SearchFragment<Pair<Status, StatusViewData.Concre
|
||||
}
|
||||
}
|
||||
|
||||
override fun onEmojiReact(react: Boolean, emoji: String, statusId: String) {
|
||||
viewModel.emojiReact(react, emoji, statusId)
|
||||
}
|
||||
|
||||
override fun onEmojiReactMenu(view: View, reaction: EmojiReaction, statusId: String) {
|
||||
val context = requireContext()
|
||||
val popup = PopupMenu(context, view)
|
||||
|
||||
popup.inflate(R.menu.emoji_reaction_more)
|
||||
popup.menu.findItem(R.id.emoji_react).isVisible = !reaction.me
|
||||
popup.menu.findItem(R.id.emoji_unreact).isVisible = reaction.me
|
||||
|
||||
popup.setOnMenuItemClickListener { item: MenuItem ->
|
||||
when (item.itemId) {
|
||||
R.id.emoji_react -> {
|
||||
onEmojiReact(true, reaction.name, statusId)
|
||||
return@setOnMenuItemClickListener true
|
||||
}
|
||||
R.id.emoji_unreact -> {
|
||||
onEmojiReact(false, reaction.name, statusId)
|
||||
return@setOnMenuItemClickListener true
|
||||
}
|
||||
R.id.emoji_reacted_by -> {
|
||||
val intent = newIntent(context, AccountListActivity.Type.REACTED, statusId, reaction.name)
|
||||
(requireActivity() as BaseActivity).startActivityWithSlideInAnimation(intent)
|
||||
return@setOnMenuItemClickListener true
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
popup.show()
|
||||
}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ public interface StatusActionListener extends LinkListener {
|
||||
void onVoteInPoll(int position, @NonNull List<Integer> choices);
|
||||
|
||||
default void onMute(int position, boolean isMuted) {}
|
||||
default void onEmojiReact(final boolean react, final String emoji, final String statusId) {};
|
||||
default void onEmojiReactMenu(@NonNull View view, final EmojiReaction emoji, final String statusId) {};
|
||||
default void onEmojiReact(@NonNull final boolean react, @NonNull final String emoji, @NonNull final String statusId) {};
|
||||
default void onEmojiReactMenu(@NonNull View view, @NonNull final EmojiReaction emoji, @NonNull final String statusId) {};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user