always show follow requests in main menu (#1809)

* always show follow requests in main menu

* update recyclerview to v1.2.0

* fix bug that shows follow requests info to wrong users
This commit is contained in:
Konrad Pozniak 2021-04-10 20:30:44 +02:00 committed by GitHub
parent 497d0043bf
commit dee6a3a160
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 143 additions and 76 deletions

View file

@ -113,7 +113,7 @@ dependencies {
implementation "androidx.fragment:fragment-ktx:1.2.5" implementation "androidx.fragment:fragment-ktx:1.2.5"
implementation "androidx.browser:browser:1.3.0" implementation "androidx.browser:browser:1.3.0"
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation "androidx.recyclerview:recyclerview:1.1.0" implementation "androidx.recyclerview:recyclerview:1.2.0"
implementation "androidx.exifinterface:exifinterface:1.3.2" implementation "androidx.exifinterface:exifinterface:1.3.2"
implementation "androidx.cardview:cardview:1.0.0" implementation "androidx.cardview:cardview:1.0.0"
implementation "androidx.preference:preference-ktx:1.1.1" implementation "androidx.preference:preference-ktx:1.1.1"

View file

@ -46,6 +46,7 @@ class AccountListActivity : BaseActivity(), HasAndroidInjector {
val type = intent.getSerializableExtra(EXTRA_TYPE) as Type val type = intent.getSerializableExtra(EXTRA_TYPE) as Type
val id: String? = intent.getStringExtra(EXTRA_ID) val id: String? = intent.getStringExtra(EXTRA_ID)
val accountLocked: Boolean = intent.getBooleanExtra(EXTRA_ACCOUNT_LOCKED, false)
setSupportActionBar(binding.includedToolbar.toolbar) setSupportActionBar(binding.includedToolbar.toolbar)
supportActionBar?.apply { supportActionBar?.apply {
@ -64,7 +65,7 @@ class AccountListActivity : BaseActivity(), HasAndroidInjector {
supportFragmentManager supportFragmentManager
.beginTransaction() .beginTransaction()
.replace(R.id.fragment_container, AccountListFragment.newInstance(type, id)) .replace(R.id.fragment_container, AccountListFragment.newInstance(type, id, accountLocked))
.commit() .commit()
} }
@ -73,12 +74,15 @@ class AccountListActivity : BaseActivity(), HasAndroidInjector {
companion object { companion object {
private const val EXTRA_TYPE = "type" private const val EXTRA_TYPE = "type"
private const val EXTRA_ID = "id" private const val EXTRA_ID = "id"
private const val EXTRA_ACCOUNT_LOCKED = "acc_locked"
@JvmStatic @JvmStatic
fun newIntent(context: Context, type: Type, id: String? = null): Intent { @JvmOverloads
fun newIntent(context: Context, type: Type, id: String? = null, accountLocked: Boolean = false): Intent {
return Intent(context, AccountListActivity::class.java).apply { return Intent(context, AccountListActivity::class.java).apply {
putExtra(EXTRA_TYPE, type) putExtra(EXTRA_TYPE, type)
putExtra(EXTRA_ID, id) putExtra(EXTRA_ID, id)
putExtra(EXTRA_ACCOUNT_LOCKED, accountLocked)
} }
} }
} }

View file

@ -181,7 +181,7 @@ class AccountsInListFragment : DialogFragment(), Injectable {
binding.notificationTextView.hide() binding.notificationTextView.hide()
binding.acceptButton.hide() binding.acceptButton.hide()
binding.rejectButton.setOnClickListener { binding.rejectButton.setOnClickListener {
onRemoveFromList(getItem(holder.adapterPosition).id) onRemoveFromList(getItem(holder.bindingAdapterPosition).id)
} }
binding.rejectButton.contentDescription = binding.rejectButton.contentDescription =
binding.root.context.getString(R.string.action_remove_from_list) binding.root.context.getString(R.string.action_remove_from_list)
@ -217,7 +217,7 @@ class AccountsInListFragment : DialogFragment(), Injectable {
binding.notificationTextView.hide() binding.notificationTextView.hide()
binding.acceptButton.hide() binding.acceptButton.hide()
binding.rejectButton.setOnClickListener { binding.rejectButton.setOnClickListener {
val (account, inAList) = getItem(holder.adapterPosition) val (account, inAList) = getItem(holder.bindingAdapterPosition)
if (inAList) { if (inAList) {
onRemoveFromList(account.id) onRemoveFromList(account.id)
} else { } else {

View file

@ -250,9 +250,9 @@ class ListsActivity : BaseActivity(), Injectable, HasAndroidInjector {
override fun onClick(v: View) { override fun onClick(v: View) {
if (v == itemView) { if (v == itemView) {
onListSelected(getItem(adapterPosition).id) onListSelected(getItem(bindingAdapterPosition).id)
} else { } else {
onMore(getItem(adapterPosition), v) onMore(getItem(bindingAdapterPosition), v)
} }
} }
} }

View file

@ -121,6 +121,8 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
private lateinit var glide: RequestManager private lateinit var glide: RequestManager
private var accountLocked: Boolean = false
private val emojiInitCallback = object : InitCallback() { private val emojiInitCallback = object : InitCallback() {
override fun onInitialized() { override fun onInitialized() {
if (!isDestroyed) { if (!isDestroyed) {
@ -399,6 +401,14 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
startActivityWithSlideInAnimation(intent) startActivityWithSlideInAnimation(intent)
} }
}, },
primaryDrawerItem {
nameRes = R.string.action_view_follow_requests
iconicsIcon = GoogleMaterial.Icon.gmd_person_add
onClick = {
val intent = AccountListActivity.newIntent(context, AccountListActivity.Type.FOLLOW_REQUESTS, accountLocked = accountLocked)
startActivityWithSlideInAnimation(intent)
}
},
primaryDrawerItem { primaryDrawerItem {
nameRes = R.string.action_lists nameRes = R.string.action_lists
iconicsIcon = GoogleMaterial.Icon.gmd_list iconicsIcon = GoogleMaterial.Icon.gmd_list
@ -660,22 +670,8 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
accountManager.updateActiveAccount(me) accountManager.updateActiveAccount(me)
NotificationHelper.createNotificationChannelsForAccount(accountManager.activeAccount!!, this) NotificationHelper.createNotificationChannelsForAccount(accountManager.activeAccount!!, this)
// Show follow requests in the menu, if this is a locked account. accountLocked = me.locked
if (me.locked && binding.mainDrawer.getDrawerItem(DRAWER_ITEM_FOLLOW_REQUESTS) == null) {
val followRequestsItem = primaryDrawerItem {
identifier = DRAWER_ITEM_FOLLOW_REQUESTS
nameRes = R.string.action_view_follow_requests
iconicsIcon = GoogleMaterial.Icon.gmd_person_add
onClick = {
val intent = Intent(this@MainActivity, AccountListActivity::class.java)
intent.putExtra("type", AccountListActivity.Type.FOLLOW_REQUESTS)
startActivityWithSlideInAnimation(intent)
}
}
binding.mainDrawer.addItemAtPosition(4, followRequestsItem)
} else if (!me.locked) {
binding.mainDrawer.removeItems(DRAWER_ITEM_FOLLOW_REQUESTS)
}
updateProfiles() updateProfiles()
updateShortcut(this, accountManager.activeAccount!!) updateShortcut(this, accountManager.activeAccount!!)
} }
@ -789,7 +785,6 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
companion object { companion object {
private const val TAG = "MainActivity" // logging tag private const val TAG = "MainActivity" // logging tag
private const val DRAWER_ITEM_ADD_ACCOUNT: Long = -13 private const val DRAWER_ITEM_ADD_ACCOUNT: Long = -13
private const val DRAWER_ITEM_FOLLOW_REQUESTS: Long = 10
private const val DRAWER_ITEM_ANNOUNCEMENTS: Long = 14 private const val DRAWER_ITEM_ANNOUNCEMENTS: Long = 14
const val STATUS_URL = "statusUrl" const val STATUS_URL = "statusUrl"
} }

View file

@ -109,17 +109,17 @@ class TabPreferenceActivity : BaseActivity(), Injectable, ItemInteractionListene
} }
override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean { override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean {
val temp = currentTabs[viewHolder.adapterPosition] val temp = currentTabs[viewHolder.bindingAdapterPosition]
currentTabs[viewHolder.adapterPosition] = currentTabs[target.adapterPosition] currentTabs[viewHolder.bindingAdapterPosition] = currentTabs[target.bindingAdapterPosition]
currentTabs[target.adapterPosition] = temp currentTabs[target.bindingAdapterPosition] = temp
currentTabsAdapter.notifyItemMoved(viewHolder.adapterPosition, target.adapterPosition) currentTabsAdapter.notifyItemMoved(viewHolder.bindingAdapterPosition, target.bindingAdapterPosition)
saveTabs() saveTabs()
return true return true
} }
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
onTabRemoved(viewHolder.adapterPosition) onTabRemoved(viewHolder.bindingAdapterPosition)
} }
override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) { override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {

View file

@ -65,7 +65,7 @@ class AccountFieldEditAdapter : RecyclerView.Adapter<BindingHolder<ItemEditField
holder.binding.accountFieldName.addTextChangedListener(object: TextWatcher { holder.binding.accountFieldName.addTextChangedListener(object: TextWatcher {
override fun afterTextChanged(newText: Editable) { override fun afterTextChanged(newText: Editable) {
fieldData[holder.adapterPosition].first = newText.toString() fieldData[holder.bindingAdapterPosition].first = newText.toString()
} }
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {} override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
@ -75,7 +75,7 @@ class AccountFieldEditAdapter : RecyclerView.Adapter<BindingHolder<ItemEditField
holder.binding.accountFieldValue.addTextChangedListener(object: TextWatcher { holder.binding.accountFieldValue.addTextChangedListener(object: TextWatcher {
override fun afterTextChanged(newText: Editable) { override fun afterTextChanged(newText: Editable) {
fieldData[holder.adapterPosition].second = newText.toString() fieldData[holder.bindingAdapterPosition].second = newText.toString()
} }
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {} override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}

View file

@ -95,7 +95,7 @@ public class BlocksAdapter extends AccountAdapter {
void setupActionListener(final AccountActionListener listener) { void setupActionListener(final AccountActionListener listener) {
unblock.setOnClickListener(v -> { unblock.setOnClickListener(v -> {
int position = getAdapterPosition(); int position = getBindingAdapterPosition();
if (position != RecyclerView.NO_POSITION) { if (position != RecyclerView.NO_POSITION) {
listener.onBlock(false, id, position); listener.onBlock(false, id, position);
} }

View file

@ -51,13 +51,13 @@ class FollowRequestViewHolder(
fun setupActionListener(listener: AccountActionListener, accountId: String) { fun setupActionListener(listener: AccountActionListener, accountId: String) {
binding.acceptButton.setOnClickListener { binding.acceptButton.setOnClickListener {
val position = adapterPosition val position = bindingAdapterPosition
if (position != RecyclerView.NO_POSITION) { if (position != RecyclerView.NO_POSITION) {
listener.onRespondToFollowRequest(true, accountId, position) listener.onRespondToFollowRequest(true, accountId, position)
} }
} }
binding.rejectButton.setOnClickListener { binding.rejectButton.setOnClickListener {
val position = adapterPosition val position = bindingAdapterPosition
if (position != RecyclerView.NO_POSITION) { if (position != RecyclerView.NO_POSITION) {
listener.onRespondToFollowRequest(false, accountId, position) listener.onRespondToFollowRequest(false, accountId, position)
} }

View file

@ -0,0 +1,40 @@
/* Copyright 2020 Tusky Contributors
*
* This file is a part of Tusky.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky.adapter
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.keylesspalace.tusky.R
class FollowRequestsHeaderAdapter(private val instanceName: String, private val accountLocked: Boolean) : RecyclerView.Adapter<HeaderViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HeaderViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_follow_requests_header, parent, false) as TextView
return HeaderViewHolder(view)
}
override fun onBindViewHolder(viewHolder: HeaderViewHolder, position: Int) {
viewHolder.textView.text = viewHolder.textView.context.getString(R.string.follow_requests_info, instanceName)
}
override fun getItemCount() = if (accountLocked) 0 else 1
}
class HeaderViewHolder(var textView: TextView) : RecyclerView.ViewHolder(textView)

View file

@ -122,9 +122,9 @@ public class MutesAdapter extends AccountAdapter {
} }
void setupActionListener(final AccountActionListener listener) { void setupActionListener(final AccountActionListener listener) {
unmute.setOnClickListener(v -> listener.onMute(false, id, getAdapterPosition(), false)); unmute.setOnClickListener(v -> listener.onMute(false, id, getBindingAdapterPosition(), false));
muteNotifications.setOnClickListener( muteNotifications.setOnClickListener(
v -> listener.onMute(true, id, getAdapterPosition(), !notifications)); v -> listener.onMute(true, id, getBindingAdapterPosition(), !notifications));
itemView.setOnClickListener(v -> listener.onViewAccount(id)); itemView.setOnClickListener(v -> listener.onViewAccount(id));
} }
} }

View file

@ -541,8 +541,8 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
} }
contentWarningButton.setOnClickListener(view -> { contentWarningButton.setOnClickListener(view -> {
if (getAdapterPosition() != RecyclerView.NO_POSITION) { if (getBindingAdapterPosition() != RecyclerView.NO_POSITION) {
notificationActionListener.onExpandedChange(!statusViewData.isExpanded(), getAdapterPosition()); notificationActionListener.onExpandedChange(!statusViewData.isExpanded(), getBindingAdapterPosition());
} }
statusContent.setVisibility(statusViewData.isExpanded() ? View.GONE : View.VISIBLE); statusContent.setVisibility(statusViewData.isExpanded() ? View.GONE : View.VISIBLE);
}); });
@ -619,7 +619,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
if (statusViewData.isCollapsible() && (statusViewData.isExpanded() || !hasSpoiler)) { if (statusViewData.isCollapsible() && (statusViewData.isExpanded() || !hasSpoiler)) {
contentCollapseButton.setOnClickListener(view -> { contentCollapseButton.setOnClickListener(view -> {
int position = getAdapterPosition(); int position = getBindingAdapterPosition();
if (position != RecyclerView.NO_POSITION && notificationActionListener != null) { if (position != RecyclerView.NO_POSITION && notificationActionListener != null) {
notificationActionListener.onNotificationContentCollapsedChange(!statusViewData.isCollapsed(), position); notificationActionListener.onNotificationContentCollapsedChange(!statusViewData.isCollapsed(), position);
} }

View file

@ -41,7 +41,7 @@ public final class PlaceholderViewHolder extends RecyclerView.ViewHolder {
loadMoreButton.setEnabled(true); loadMoreButton.setEnabled(true);
loadMoreButton.setOnClickListener(v -> { loadMoreButton.setOnClickListener(v -> {
loadMoreButton.setEnabled(false); loadMoreButton.setEnabled(false);
listener.onLoadMore(getAdapterPosition()); listener.onLoadMore(getBindingAdapterPosition());
}); });
} }

View file

@ -100,7 +100,7 @@ class PollAdapter: RecyclerView.Adapter<BindingHolder<ItemPollBinding>>() {
radioButton.isChecked = option.selected radioButton.isChecked = option.selected
radioButton.setOnClickListener { radioButton.setOnClickListener {
pollOptions.forEachIndexed { index, pollOption -> pollOptions.forEachIndexed { index, pollOption ->
pollOption.selected = index == holder.adapterPosition pollOption.selected = index == holder.bindingAdapterPosition
notifyItemChanged(index) notifyItemChanged(index)
} }
} }
@ -110,7 +110,7 @@ class PollAdapter: RecyclerView.Adapter<BindingHolder<ItemPollBinding>>() {
checkBox.text = EmojiCompat.get().process(emojifiedPollOptionText) checkBox.text = EmojiCompat.get().process(emojifiedPollOptionText)
checkBox.isChecked = option.selected checkBox.isChecked = option.selected
checkBox.setOnCheckedChangeListener { _, isChecked -> checkBox.setOnCheckedChangeListener { _, isChecked ->
pollOptions[holder.adapterPosition].selected = isChecked pollOptions[holder.bindingAdapterPosition].selected = isChecked
} }
} }
} }

View file

@ -113,9 +113,9 @@ public class SavedTootAdapter extends RecyclerView.Adapter {
suppr.setOnClickListener(v -> { suppr.setOnClickListener(v -> {
v.setEnabled(false); v.setEnabled(false);
handler.delete(getAdapterPosition(), item); handler.delete(getBindingAdapterPosition(), item);
}); });
view.setOnClickListener(v -> handler.click(getAdapterPosition(), item)); view.setOnClickListener(v -> handler.click(getBindingAdapterPosition(), item));
} }
} }
} }

View file

@ -217,8 +217,8 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
setContentWarningButtonText(expanded); setContentWarningButtonText(expanded);
contentWarningButton.setOnClickListener(view -> { contentWarningButton.setOnClickListener(view -> {
contentWarningDescription.invalidate(); contentWarningDescription.invalidate();
if (getAdapterPosition() != RecyclerView.NO_POSITION) { if (getBindingAdapterPosition() != RecyclerView.NO_POSITION) {
listener.onExpandedChange(!expanded, getAdapterPosition()); listener.onExpandedChange(!expanded, getBindingAdapterPosition());
} }
setContentWarningButtonText(!expanded); setContentWarningButtonText(!expanded);
@ -513,15 +513,15 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
sensitiveMediaWarning.setVisibility(showingContent ? View.GONE : View.VISIBLE); sensitiveMediaWarning.setVisibility(showingContent ? View.GONE : View.VISIBLE);
sensitiveMediaShow.setVisibility(showingContent ? View.VISIBLE : View.GONE); sensitiveMediaShow.setVisibility(showingContent ? View.VISIBLE : View.GONE);
sensitiveMediaShow.setOnClickListener(v -> { sensitiveMediaShow.setOnClickListener(v -> {
if (getAdapterPosition() != RecyclerView.NO_POSITION) { if (getBindingAdapterPosition() != RecyclerView.NO_POSITION) {
listener.onContentHiddenChange(false, getAdapterPosition()); listener.onContentHiddenChange(false, getBindingAdapterPosition());
} }
v.setVisibility(View.GONE); v.setVisibility(View.GONE);
sensitiveMediaWarning.setVisibility(View.VISIBLE); sensitiveMediaWarning.setVisibility(View.VISIBLE);
}); });
sensitiveMediaWarning.setOnClickListener(v -> { sensitiveMediaWarning.setOnClickListener(v -> {
if (getAdapterPosition() != RecyclerView.NO_POSITION) { if (getBindingAdapterPosition() != RecyclerView.NO_POSITION) {
listener.onContentHiddenChange(true, getAdapterPosition()); listener.onContentHiddenChange(true, getBindingAdapterPosition());
} }
v.setVisibility(View.GONE); v.setVisibility(View.GONE);
sensitiveMediaShow.setVisibility(View.VISIBLE); sensitiveMediaShow.setVisibility(View.VISIBLE);
@ -582,10 +582,10 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
private void setAttachmentClickListener(View view, StatusActionListener listener, private void setAttachmentClickListener(View view, StatusActionListener listener,
int index, Attachment attachment, boolean animateTransition) { int index, Attachment attachment, boolean animateTransition) {
view.setOnClickListener(v -> { view.setOnClickListener(v -> {
int position = getAdapterPosition(); int position = getBindingAdapterPosition();
if (position != RecyclerView.NO_POSITION) { if (position != RecyclerView.NO_POSITION) {
if (sensitiveMediaWarning.getVisibility() == View.VISIBLE) { if (sensitiveMediaWarning.getVisibility() == View.VISIBLE) {
listener.onContentHiddenChange(true, getAdapterPosition()); listener.onContentHiddenChange(true, getBindingAdapterPosition());
} else { } else {
listener.onViewMedia(position, index, animateTransition ? v : null); listener.onViewMedia(position, index, animateTransition ? v : null);
} }
@ -627,7 +627,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
displayName.setOnClickListener(profileButtonClickListener); displayName.setOnClickListener(profileButtonClickListener);
replyButton.setOnClickListener(v -> { replyButton.setOnClickListener(v -> {
int position = getAdapterPosition(); int position = getBindingAdapterPosition();
if (position != RecyclerView.NO_POSITION) { if (position != RecyclerView.NO_POSITION) {
listener.onReply(position); listener.onReply(position);
} }
@ -635,7 +635,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
if (reblogButton != null) { if (reblogButton != null) {
reblogButton.setEventListener((button, buttonState) -> { reblogButton.setEventListener((button, buttonState) -> {
// return true to play animaion // return true to play animaion
int position = getAdapterPosition(); int position = getBindingAdapterPosition();
if (position != RecyclerView.NO_POSITION) { if (position != RecyclerView.NO_POSITION) {
if (statusDisplayOptions.confirmReblogs()) { if (statusDisplayOptions.confirmReblogs()) {
showConfirmReblogDialog(listener, statusContent, buttonState, position); showConfirmReblogDialog(listener, statusContent, buttonState, position);
@ -651,7 +651,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
} }
favouriteButton.setEventListener((button, buttonState) -> { favouriteButton.setEventListener((button, buttonState) -> {
int position = getAdapterPosition(); int position = getBindingAdapterPosition();
if (position != RecyclerView.NO_POSITION) { if (position != RecyclerView.NO_POSITION) {
listener.onFavourite(!buttonState, position); listener.onFavourite(!buttonState, position);
} }
@ -659,7 +659,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
}); });
bookmarkButton.setEventListener((button, buttonState) -> { bookmarkButton.setEventListener((button, buttonState) -> {
int position = getAdapterPosition(); int position = getBindingAdapterPosition();
if (position != RecyclerView.NO_POSITION) { if (position != RecyclerView.NO_POSITION) {
listener.onBookmark(!buttonState, position); listener.onBookmark(!buttonState, position);
} }
@ -667,7 +667,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
}); });
moreButton.setOnClickListener(v -> { moreButton.setOnClickListener(v -> {
int position = getAdapterPosition(); int position = getBindingAdapterPosition();
if (position != RecyclerView.NO_POSITION) { if (position != RecyclerView.NO_POSITION) {
listener.onMore(v, position); listener.onMore(v, position);
} }
@ -677,7 +677,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
* just eat the clicks instead of deferring to the parent listener, but WILL respond to a * just eat the clicks instead of deferring to the parent listener, but WILL respond to a
* listener directly on the TextView, for whatever reason. */ * listener directly on the TextView, for whatever reason. */
View.OnClickListener viewThreadListener = v -> { View.OnClickListener viewThreadListener = v -> {
int position = getAdapterPosition(); int position = getBindingAdapterPosition();
if (position != RecyclerView.NO_POSITION) { if (position != RecyclerView.NO_POSITION) {
listener.onViewThread(position); listener.onViewThread(position);
} }
@ -926,7 +926,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
if (expired || poll.getVoted()) { if (expired || poll.getVoted()) {
// no voting possible // no voting possible
View.OnClickListener viewThreadListener = v -> { View.OnClickListener viewThreadListener = v -> {
int position = getAdapterPosition(); int position = getBindingAdapterPosition();
if (position != RecyclerView.NO_POSITION) { if (position != RecyclerView.NO_POSITION) {
listener.onViewThread(position); listener.onViewThread(position);
} }
@ -958,7 +958,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
pollButton.setOnClickListener(v -> { pollButton.setOnClickListener(v -> {
int position = getAdapterPosition(); int position = getBindingAdapterPosition();
if (position != RecyclerView.NO_POSITION) { if (position != RecyclerView.NO_POSITION) {

View file

@ -72,13 +72,13 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder {
} }
reblogs.setOnClickListener(v -> { reblogs.setOnClickListener(v -> {
int position = getAdapterPosition(); int position = getBindingAdapterPosition();
if (position != RecyclerView.NO_POSITION) { if (position != RecyclerView.NO_POSITION) {
listener.onShowReblogs(position); listener.onShowReblogs(position);
} }
}); });
favourites.setOnClickListener(v -> { favourites.setOnClickListener(v -> {
int position = getAdapterPosition(); int position = getBindingAdapterPosition();
if (position != RecyclerView.NO_POSITION) { if (position != RecyclerView.NO_POSITION) {
listener.onShowFavs(position); listener.onShowFavs(position);
} }

View file

@ -67,7 +67,7 @@ public class StatusViewHolder extends StatusBaseViewHolder {
hideStatusInfo(); hideStatusInfo();
} else { } else {
setRebloggedByDisplayName(rebloggedByDisplayName, status, statusDisplayOptions); setRebloggedByDisplayName(rebloggedByDisplayName, status, statusDisplayOptions);
statusInfo.setOnClickListener(v -> listener.onOpenReblog(getAdapterPosition())); statusInfo.setOnClickListener(v -> listener.onOpenReblog(getBindingAdapterPosition()));
} }
} }
@ -105,7 +105,7 @@ public class StatusViewHolder extends StatusBaseViewHolder {
/* input filter for TextViews have to be set before text */ /* input filter for TextViews have to be set before text */
if (status.isCollapsible() && (status.isExpanded() || TextUtils.isEmpty(status.getSpoilerText()))) { if (status.isCollapsible() && (status.isExpanded() || TextUtils.isEmpty(status.getSpoilerText()))) {
contentCollapseButton.setOnClickListener(view -> { contentCollapseButton.setOnClickListener(view -> {
int position = getAdapterPosition(); int position = getBindingAdapterPosition();
if (position != RecyclerView.NO_POSITION) if (position != RecyclerView.NO_POSITION)
listener.onContentCollapsedChange(!status.isCollapsed(), position); listener.onContentCollapsedChange(!status.isCollapsed(), position);
}); });

View file

@ -98,7 +98,7 @@ class TabAdapter(private var data: List<TabData>,
} }
} }
binding.removeButton.setOnClickListener { binding.removeButton.setOnClickListener {
listener.onTabRemoved(holder.adapterPosition) listener.onTabRemoved(holder.bindingAdapterPosition)
} }
binding.removeButton.isEnabled = removeButtonEnabled binding.removeButton.isEnabled = removeButtonEnabled
ThemeUtils.setDrawableTint( ThemeUtils.setDrawableTint(
@ -131,7 +131,7 @@ class TabAdapter(private var data: List<TabData>,
} else { } else {
chip.setChipIconResource(R.drawable.ic_cancel_24dp) chip.setChipIconResource(R.drawable.ic_cancel_24dp)
chip.setOnClickListener { chip.setOnClickListener {
listener.onChipClicked(tab, holder.adapterPosition, i) listener.onChipClicked(tab, holder.bindingAdapterPosition, i)
} }
} }
} }
@ -141,7 +141,7 @@ class TabAdapter(private var data: List<TabData>,
} }
binding.actionChip.setOnClickListener { binding.actionChip.setOnClickListener {
listener.onActionChipClicked(tab, holder.adapterPosition) listener.onActionChipClicked(tab, holder.bindingAdapterPosition)
} }
} else { } else {

View file

@ -103,7 +103,7 @@ class MediaPreviewAdapter(
progressImageView.layoutParams = layoutParams progressImageView.layoutParams = layoutParams
progressImageView.scaleType = ImageView.ScaleType.CENTER_CROP progressImageView.scaleType = ImageView.ScaleType.CENTER_CROP
progressImageView.setOnClickListener { progressImageView.setOnClickListener {
onMediaClick(adapterPosition, progressImageView) onMediaClick(bindingAdapterPosition, progressImageView)
} }
} }
} }

View file

@ -147,7 +147,7 @@ public class ConversationViewHolder extends StatusBaseViewHolder {
/* input filter for TextViews have to be set before text */ /* input filter for TextViews have to be set before text */
if (collapsible && (expanded || TextUtils.isEmpty(spoilerText))) { if (collapsible && (expanded || TextUtils.isEmpty(spoilerText))) {
contentCollapseButton.setOnClickListener(view -> { contentCollapseButton.setOnClickListener(view -> {
int position = getAdapterPosition(); int position = getBindingAdapterPosition();
if (position != RecyclerView.NO_POSITION) if (position != RecyclerView.NO_POSITION)
listener.onContentCollapsedChange(!collapsed, position); listener.onContentCollapsedChange(!collapsed, position);
}); });

View file

@ -55,7 +55,7 @@ class DraftsAdapter(
binding.draftMediaPreview.layoutManager = LinearLayoutManager(binding.root.context, RecyclerView.HORIZONTAL, false) binding.draftMediaPreview.layoutManager = LinearLayoutManager(binding.root.context, RecyclerView.HORIZONTAL, false)
binding.draftMediaPreview.adapter = DraftMediaAdapter { binding.draftMediaPreview.adapter = DraftMediaAdapter {
getItem(viewHolder.adapterPosition)?.let { draft -> getItem(viewHolder.bindingAdapterPosition)?.let { draft ->
listener.onOpenDraft(draft) listener.onOpenDraft(draft)
} }
} }

View file

@ -24,7 +24,7 @@ class DomainMutesAdapter(
holder.binding.mutedDomain.text = instance holder.binding.mutedDomain.text = instance
holder.binding.mutedDomainUnmute.setOnClickListener { holder.binding.mutedDomainUnmute.setOnClickListener {
actionListener.mute(false, instance, holder.adapterPosition) actionListener.mute(false, instance, holder.bindingAdapterPosition)
} }
} }

View file

@ -173,5 +173,5 @@ class StatusViewHolder(
} }
} }
private fun status() = getStatusForPosition(adapterPosition) private fun status() = getStatusForPosition(bindingAdapterPosition)
} }

View file

@ -21,6 +21,7 @@ import android.view.View
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.ConcatAdapter
import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -31,6 +32,7 @@ import com.keylesspalace.tusky.AccountListActivity.Type
import com.keylesspalace.tusky.BaseActivity import com.keylesspalace.tusky.BaseActivity
import com.keylesspalace.tusky.R import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.adapter.* import com.keylesspalace.tusky.adapter.*
import com.keylesspalace.tusky.db.AccountManager
import com.keylesspalace.tusky.databinding.FragmentAccountListBinding import com.keylesspalace.tusky.databinding.FragmentAccountListBinding
import com.keylesspalace.tusky.di.Injectable import com.keylesspalace.tusky.di.Injectable
import com.keylesspalace.tusky.entity.Account import com.keylesspalace.tusky.entity.Account
@ -56,6 +58,8 @@ class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountAct
@Inject @Inject
lateinit var api: MastodonApi lateinit var api: MastodonApi
@Inject
lateinit var accountManager: AccountManager
private val binding by viewBinding(FragmentAccountListBinding::bind) private val binding by viewBinding(FragmentAccountListBinding::bind)
@ -90,10 +94,17 @@ class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountAct
adapter = when (type) { adapter = when (type) {
Type.BLOCKS -> BlocksAdapter(this, animateAvatar, animateEmojis) Type.BLOCKS -> BlocksAdapter(this, animateAvatar, animateEmojis)
Type.MUTES -> MutesAdapter(this, animateAvatar, animateEmojis) Type.MUTES -> MutesAdapter(this, animateAvatar, animateEmojis)
Type.FOLLOW_REQUESTS -> FollowRequestsAdapter(this, animateAvatar, animateEmojis) Type.FOLLOW_REQUESTS -> {
val headerAdapter = FollowRequestsHeaderAdapter(accountManager.activeAccount!!.domain, arguments?.get(ARG_ACCOUNT_LOCKED) == true)
val followRequestsAdapter = FollowRequestsAdapter(this, animateAvatar, animateEmojis)
binding.recyclerView.adapter = ConcatAdapter(headerAdapter, followRequestsAdapter)
followRequestsAdapter
}
else -> FollowAdapter(this, animateAvatar, animateEmojis) else -> FollowAdapter(this, animateAvatar, animateEmojis)
} }
if (binding.recyclerView.adapter == null) {
binding.recyclerView.adapter = adapter binding.recyclerView.adapter = adapter
}
scrollListener = object : EndlessOnScrollListener(layoutManager) { scrollListener = object : EndlessOnScrollListener(layoutManager) {
override fun onLoadMore(totalItemsCount: Int, view: RecyclerView) { override fun onLoadMore(totalItemsCount: Int, view: RecyclerView) {
@ -361,12 +372,14 @@ class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountAct
private const val TAG = "AccountList" // logging tag private const val TAG = "AccountList" // logging tag
private const val ARG_TYPE = "type" private const val ARG_TYPE = "type"
private const val ARG_ID = "id" private const val ARG_ID = "id"
private const val ARG_ACCOUNT_LOCKED = "acc_locked"
fun newInstance(type: Type, id: String? = null): AccountListFragment { fun newInstance(type: Type, id: String? = null, accountLocked: Boolean = false): AccountListFragment {
return AccountListFragment().apply { return AccountListFragment().apply {
arguments = Bundle(2).apply { arguments = Bundle(2).apply {
putSerializable(ARG_TYPE, type) putSerializable(ARG_TYPE, type)
putString(ARG_ID, id) putString(ARG_ID, id)
putBoolean(ARG_ACCOUNT_LOCKED, accountLocked)
} }
} }
} }

View file

@ -320,7 +320,7 @@ class AccountMediaFragment : Fragment(R.layout.fragment_timeline), RefreshableFr
// saving some allocations // saving some allocations
override fun onClick(v: View?) { override fun onClick(v: View?) {
viewMedia(items, adapterPosition, imageView) viewMedia(items, bindingAdapterPosition, imageView)
} }
} }
} }

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hyphenationFrequency="normal"
android:lineSpacingMultiplier="1.1"
android:paddingStart="16dp"
android:paddingTop="8dp"
android:paddingEnd="16dp"
android:paddingBottom="8dp"
tools:text="@string/follow_requests_info" />

View file

@ -622,6 +622,9 @@
<string name="draft_deleted">Draft deleted</string> <string name="draft_deleted">Draft deleted</string>
<string name="drafts_toot_reply_removed">The Toot you drafted a reply to has been removed</string> <string name="drafts_toot_reply_removed">The Toot you drafted a reply to has been removed</string>
<string name="follow_requests_info">Even though your account is not locked, the %1$s staff thought you might want to review follow requests from these accounts manually.</string>
<string name="action_subscribe_account">Subscribe</string> <string name="action_subscribe_account">Subscribe</string>
<string name="action_unsubscribe_account">Unsubscribe</string> <string name="action_unsubscribe_account">Unsubscribe</string>
</resources> </resources>