mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-01-31 19:34:55 +01:00
bug fix, code cleanup
This commit is contained in:
parent
3c2b5a8fe0
commit
b7efc8e6fc
@ -45,9 +45,7 @@ public class AccountAdapter extends Adapter<AccountHolder> implements OnHolderCl
|
||||
@NonNull
|
||||
@Override
|
||||
public AccountHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
AccountHolder holder = new AccountHolder(parent, settings, picasso);
|
||||
holder.setOnAccountClickListener(this);
|
||||
return holder;
|
||||
return new AccountHolder(parent, settings, picasso, this);
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,10 +40,7 @@ public class IconAdapter extends Adapter<IconHolder> implements OnHolderClickLis
|
||||
@NonNull
|
||||
@Override
|
||||
public IconHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
IconHolder holder = new IconHolder(parent, settings);
|
||||
if (listener != null)
|
||||
holder.addOnHolderClickListener(this);
|
||||
return holder;
|
||||
return new IconHolder(parent, settings, this);
|
||||
}
|
||||
|
||||
|
||||
|
@ -87,13 +87,9 @@ public class MessageAdapter extends Adapter<ViewHolder> implements OnItemClickLi
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
if (viewType == TYPE_MESSAGE) {
|
||||
MessageHolder holder = new MessageHolder(parent, settings, picasso);
|
||||
holder.setOnMessageClickListener(this);
|
||||
return holder;
|
||||
return new MessageHolder(parent, settings, picasso, this);
|
||||
} else {
|
||||
PlaceHolder placeHolder = new PlaceHolder(parent, settings, false);
|
||||
placeHolder.setOnHolderClickListener(this);
|
||||
return placeHolder;
|
||||
return new PlaceHolder(parent, settings, false, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,17 +73,11 @@ public class NotificationAdapter extends Adapter<ViewHolder> implements OnHolder
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
if (viewType == TYPE_STATUS) {
|
||||
StatusHolder holder = new StatusHolder(parent, settings, picasso);
|
||||
holder.setOnStatusClickListener(this);
|
||||
return holder;
|
||||
return new StatusHolder(parent, settings, picasso, this);
|
||||
} else if (viewType == TYPE_USER) {
|
||||
UserHolder holder = new UserHolder(parent, settings, picasso);
|
||||
holder.setOnUserClickListener(this);
|
||||
return holder;
|
||||
return new UserHolder(parent, settings, picasso, this, false);
|
||||
} else {
|
||||
PlaceHolder placeHolder = new PlaceHolder(parent, settings, false);
|
||||
placeHolder.setOnHolderClickListener(this);
|
||||
return placeHolder;
|
||||
return new PlaceHolder(parent, settings, false, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,10 +39,7 @@ public class OptionsAdapter extends RecyclerView.Adapter<Optionholder> implement
|
||||
@NonNull
|
||||
@Override
|
||||
public Optionholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
Optionholder holder = new Optionholder(parent, settings);
|
||||
if (enableVote)
|
||||
holder.setOnOptionItemClickListener(this);
|
||||
return holder;
|
||||
return new Optionholder(parent, settings, this);
|
||||
}
|
||||
|
||||
|
||||
@ -60,8 +57,10 @@ public class OptionsAdapter extends RecyclerView.Adapter<Optionholder> implement
|
||||
|
||||
@Override
|
||||
public void onItemClick(int pos, int type, int... extras) {
|
||||
if (type == OnHolderClickListener.POLL_OPTION) {
|
||||
listener.onOptionClick(pos);
|
||||
if (enableVote) {
|
||||
if (type == OnHolderClickListener.POLL_OPTION) {
|
||||
listener.onOptionClick(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,19 +68,13 @@ public class PreviewAdapter extends RecyclerView.Adapter<ViewHolder> implements
|
||||
switch (viewType) {
|
||||
default:
|
||||
case ITEM_PREVIEW:
|
||||
PreviewHolder previewHolder = new PreviewHolder(parent, settings, picasso);
|
||||
previewHolder.setOnPreviewClickListener(this);
|
||||
return previewHolder;
|
||||
return new PreviewHolder(parent, settings, picasso, this);
|
||||
|
||||
case ITEM_CARD:
|
||||
CardHolder cardHolder = new CardHolder(parent, settings, picasso);
|
||||
cardHolder.setOnCardClickListener(this);
|
||||
return cardHolder;
|
||||
return new CardHolder(parent, settings, picasso, this);
|
||||
|
||||
case ITEM_POLL:
|
||||
PollHolder pollHolder = new PollHolder(parent, settings);
|
||||
pollHolder.setOnPollOptionClickListener(this);
|
||||
return pollHolder;
|
||||
return new PollHolder(parent, settings, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,13 +96,9 @@ public class StatusAdapter extends Adapter<ViewHolder> implements OnHolderClickL
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
if (viewType == VIEW_STATUS) {
|
||||
StatusHolder vh = new StatusHolder(parent, settings, picasso);
|
||||
vh.setOnStatusClickListener(this);
|
||||
return vh;
|
||||
return new StatusHolder(parent, settings, picasso, this);
|
||||
} else {
|
||||
PlaceHolder placeHolder = new PlaceHolder(parent, settings, false);
|
||||
placeHolder.setOnHolderClickListener(this);
|
||||
return placeHolder;
|
||||
return new PlaceHolder(parent, settings, false, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,9 +51,7 @@ public class TrendAdapter extends Adapter<ViewHolder> implements OnHolderClickLi
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
TrendHolder vh = new TrendHolder(parent, settings);
|
||||
vh.setOnTrendClickListener(this);
|
||||
return vh;
|
||||
return new TrendHolder(parent, settings, this);
|
||||
}
|
||||
|
||||
|
||||
|
@ -92,14 +92,9 @@ public class UserAdapter extends Adapter<ViewHolder> implements OnHolderClickLis
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
if (viewType == ITEM_USER) {
|
||||
UserHolder vh = new UserHolder(parent, settings, picasso);
|
||||
vh.setDeleteButton(enableDelete);
|
||||
vh.setOnUserClickListener(this);
|
||||
return vh;
|
||||
return new UserHolder(parent, settings, picasso, this, enableDelete);
|
||||
} else {
|
||||
PlaceHolder placeHolder = new PlaceHolder(parent, settings, false);
|
||||
placeHolder.setOnHolderClickListener(this);
|
||||
return placeHolder;
|
||||
return new PlaceHolder(parent, settings, false, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,9 +84,7 @@ public class UserlistAdapter extends Adapter<ViewHolder> implements OnHolderClic
|
||||
if (viewType == ITEM_LIST) {
|
||||
return new UserlistHolder(parent, settings, picasso, this);
|
||||
} else {
|
||||
PlaceHolder placeHolder = new PlaceHolder(parent, settings, false);
|
||||
placeHolder.setOnHolderClickListener(this);
|
||||
return placeHolder;
|
||||
return new PlaceHolder(parent, settings, false, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,16 +40,17 @@ public class AccountHolder extends ViewHolder implements OnClickListener {
|
||||
private ImageButton remove;
|
||||
private TextView username, screenname, date;
|
||||
|
||||
private OnHolderClickListener listener;
|
||||
private GlobalSettings settings;
|
||||
private Picasso picasso;
|
||||
|
||||
private OnHolderClickListener listener;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public AccountHolder(ViewGroup parent, GlobalSettings settings, Picasso picasso) {
|
||||
public AccountHolder(ViewGroup parent, GlobalSettings settings, Picasso picasso, OnHolderClickListener listener) {
|
||||
super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_account, parent, false));
|
||||
this.settings = settings;
|
||||
this.picasso = picasso;
|
||||
this.listener = listener;
|
||||
|
||||
CardView background = (CardView) itemView;
|
||||
ViewGroup container = itemView.findViewById(R.id.item_account_container);
|
||||
username = itemView.findViewById(R.id.item_account_username);
|
||||
@ -60,8 +61,6 @@ public class AccountHolder extends ViewHolder implements OnClickListener {
|
||||
|
||||
AppStyles.setTheme(container, Color.TRANSPARENT);
|
||||
background.setCardBackgroundColor(settings.getCardColor());
|
||||
this.settings = settings;
|
||||
this.picasso = picasso;
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
remove.setOnClickListener(this);
|
||||
@ -71,7 +70,7 @@ public class AccountHolder extends ViewHolder implements OnClickListener {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int position = getLayoutPosition();
|
||||
if (position != NO_POSITION && listener != null) {
|
||||
if (position != NO_POSITION) {
|
||||
if (v == itemView) {
|
||||
listener.onItemClick(position, OnHolderClickListener.ACCOUNT_SELECT);
|
||||
} else if (v == remove) {
|
||||
@ -115,11 +114,4 @@ public class AccountHolder extends ViewHolder implements OnClickListener {
|
||||
screenname.append(" @" + host);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set item click listener
|
||||
*/
|
||||
public void setOnAccountClickListener(OnHolderClickListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
}
|
@ -53,10 +53,11 @@ public class CardHolder extends ViewHolder implements OnClickListener {
|
||||
private OnHolderClickListener listener;
|
||||
|
||||
|
||||
public CardHolder(ViewGroup parent, GlobalSettings settings, Picasso picasso) {
|
||||
public CardHolder(ViewGroup parent, GlobalSettings settings, Picasso picasso, OnHolderClickListener listener) {
|
||||
super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_card, parent, false));
|
||||
this.picasso = picasso;
|
||||
this.settings = settings;
|
||||
this.listener = listener;
|
||||
|
||||
linkText = itemView.findViewById(R.id.link_preview_text);
|
||||
preview = itemView.findViewById(R.id.link_preview_image);
|
||||
@ -75,7 +76,7 @@ public class CardHolder extends ViewHolder implements OnClickListener {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int pos = getLayoutPosition();
|
||||
if (pos != RecyclerView.NO_POSITION && listener != null) {
|
||||
if (pos != RecyclerView.NO_POSITION) {
|
||||
if (v == linkText) {
|
||||
listener.onItemClick(pos, OnHolderClickListener.CARD_LINK);
|
||||
} else if (v == preview) {
|
||||
@ -109,11 +110,4 @@ public class CardHolder extends ViewHolder implements OnClickListener {
|
||||
preview.setImageDrawable(new ColorDrawable(EMPTY_COLOR));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add viewholder click listener
|
||||
*/
|
||||
public void setOnCardClickListener(OnHolderClickListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
}
|
@ -8,7 +8,6 @@ import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
|
||||
|
||||
import org.nuclearfog.twidda.R;
|
||||
@ -49,26 +48,25 @@ public class IconHolder extends ViewHolder implements OnClickListener {
|
||||
private ImageButton button;
|
||||
|
||||
private GlobalSettings settings;
|
||||
@Nullable
|
||||
private OnHolderClickListener listener;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public IconHolder(ViewGroup parent, GlobalSettings settings) {
|
||||
|
||||
public IconHolder(ViewGroup parent, GlobalSettings settings, OnHolderClickListener listener) {
|
||||
super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_attachment, parent, false));
|
||||
this.settings = settings;
|
||||
this.listener = listener;
|
||||
|
||||
button = itemView.findViewById(R.id.item_status_media);
|
||||
itemView.getLayoutParams().width = parent.getMeasuredHeight();
|
||||
itemView.getLayoutParams().height = parent.getMeasuredHeight();
|
||||
button.setOnClickListener(this);
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int position = getLayoutPosition();
|
||||
if (position != NO_POSITION && listener != null) {
|
||||
if (position != NO_POSITION) {
|
||||
if (v == button) {
|
||||
listener.onItemClick(position, OnHolderClickListener.NO_TYPE);
|
||||
}
|
||||
@ -108,11 +106,4 @@ public class IconHolder extends ViewHolder implements OnClickListener {
|
||||
}
|
||||
button.setColorFilter(settings.getIconColor());
|
||||
}
|
||||
|
||||
/**
|
||||
* add listener
|
||||
*/
|
||||
public void addOnHolderClickListener(OnHolderClickListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
}
|
@ -47,17 +47,18 @@ public class MessageHolder extends ViewHolder implements OnClickListener, OnTagC
|
||||
private ImageView profile, verifiedIcon, lockedIcon;
|
||||
private Button answer, delete;
|
||||
|
||||
private OnItemClickListener listener;
|
||||
private GlobalSettings settings;
|
||||
private Picasso picasso;
|
||||
private IconAdapter adapter;
|
||||
|
||||
private OnItemClickListener listener;
|
||||
|
||||
/**
|
||||
* @param parent Parent view from adapter
|
||||
*/
|
||||
public MessageHolder(ViewGroup parent, GlobalSettings settings, Picasso picasso) {
|
||||
public MessageHolder(ViewGroup parent, GlobalSettings settings, Picasso picasso, OnItemClickListener listener) {
|
||||
super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_message, parent, false));
|
||||
this.settings = settings;
|
||||
this.picasso = picasso;
|
||||
this.listener = listener;
|
||||
|
||||
CardView background = (CardView) itemView;
|
||||
ViewGroup container = itemView.findViewById(R.id.item_message_container);
|
||||
RecyclerView attachments = itemView.findViewById(R.id.item_message_attachment_list);
|
||||
@ -79,8 +80,6 @@ public class MessageHolder extends ViewHolder implements OnClickListener, OnTagC
|
||||
adapter.addOnMediaClickListener(this);
|
||||
attachments.setLayoutManager(new LinearLayoutManager(parent.getContext(), HORIZONTAL, false));
|
||||
attachments.setAdapter(adapter);
|
||||
this.settings = settings;
|
||||
this.picasso = picasso;
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
profile.setOnClickListener(this);
|
||||
@ -92,7 +91,7 @@ public class MessageHolder extends ViewHolder implements OnClickListener, OnTagC
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int position = getLayoutPosition();
|
||||
if (position != NO_POSITION && listener != null) {
|
||||
if (position != NO_POSITION) {
|
||||
if (v == itemView) {
|
||||
listener.onItemClick(position, OnItemClickListener.MESSAGE_VIEW);
|
||||
} else if (v == answer) {
|
||||
@ -161,13 +160,6 @@ public class MessageHolder extends ViewHolder implements OnClickListener, OnTagC
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set item click listener
|
||||
*/
|
||||
public void setOnMessageClickListener(OnItemClickListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* item click listener
|
||||
* todo find a replace for this listener class
|
||||
|
@ -3,16 +3,13 @@ package org.nuclearfog.twidda.adapter.holder;
|
||||
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.View.OnTouchListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
|
||||
|
||||
import org.nuclearfog.twidda.R;
|
||||
@ -26,21 +23,21 @@ import org.nuclearfog.twidda.model.Poll;
|
||||
*
|
||||
* @author nuclearfog
|
||||
*/
|
||||
public class Optionholder extends ViewHolder implements OnClickListener, OnTouchListener {
|
||||
public class Optionholder extends ViewHolder implements OnClickListener {
|
||||
|
||||
private SeekBar voteProgress;
|
||||
private TextView name, votes;
|
||||
private ImageView checked;
|
||||
|
||||
@Nullable
|
||||
private OnHolderClickListener listener;
|
||||
private GlobalSettings settings;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public Optionholder(ViewGroup parent, GlobalSettings settings) {
|
||||
|
||||
public Optionholder(ViewGroup parent, GlobalSettings settings, OnHolderClickListener listener) {
|
||||
super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_option, parent, false));
|
||||
this.settings = settings;
|
||||
this.listener = listener;
|
||||
|
||||
name = itemView.findViewById(R.id.item_option_name);
|
||||
checked = itemView.findViewById(R.id.item_option_voted_icon);
|
||||
voteProgress = itemView.findViewById(R.id.item_option_count_bar);
|
||||
@ -51,7 +48,6 @@ public class Optionholder extends ViewHolder implements OnClickListener, OnTouch
|
||||
AppStyles.setSeekBarColor(voteProgress, settings);
|
||||
|
||||
checked.setOnClickListener(this);
|
||||
voteProgress.setOnTouchListener(this);
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@ -59,26 +55,13 @@ public class Optionholder extends ViewHolder implements OnClickListener, OnTouch
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int position = getLayoutPosition();
|
||||
if (position != NO_POSITION && listener != null) {
|
||||
if (position != NO_POSITION) {
|
||||
if (v == checked) {
|
||||
listener.onItemClick(position, OnHolderClickListener.POLL_OPTION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
return v == voteProgress;
|
||||
}
|
||||
|
||||
/**
|
||||
* set viewholder click listener
|
||||
*/
|
||||
public void setOnOptionItemClickListener(OnHolderClickListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* set viewholder content
|
||||
*
|
||||
|
@ -34,18 +34,20 @@ public class PlaceHolder extends ViewHolder implements OnClickListener {
|
||||
* @param parent Parent view from adapter
|
||||
* @param horizontal true if placeholder orientation is horizontal
|
||||
*/
|
||||
public PlaceHolder(ViewGroup parent, GlobalSettings settings, boolean horizontal) {
|
||||
public PlaceHolder(ViewGroup parent, GlobalSettings settings, boolean horizontal, OnHolderClickListener listener) {
|
||||
super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_placeholder, parent, false));
|
||||
// get views
|
||||
this.listener = listener;
|
||||
|
||||
CardView background = (CardView) itemView;
|
||||
loadCircle = itemView.findViewById(R.id.placeholder_loading);
|
||||
loadBtn = itemView.findViewById(R.id.placeholder_button);
|
||||
// theme views
|
||||
|
||||
background.setCardBackgroundColor(settings.getCardColor());
|
||||
loadBtn.setTextColor(settings.getFontColor());
|
||||
loadBtn.setTypeface(settings.getTypeFace());
|
||||
AppStyles.setButtonColor(loadBtn, settings.getFontColor());
|
||||
AppStyles.setProgressColor(loadCircle, settings.getHighlightColor());
|
||||
|
||||
// enable extra views
|
||||
if (horizontal) {
|
||||
loadBtn.setVisibility(View.INVISIBLE);
|
||||
@ -61,7 +63,7 @@ public class PlaceHolder extends ViewHolder implements OnClickListener {
|
||||
public void onClick(View v) {
|
||||
if (v == loadBtn) {
|
||||
int position = getLayoutPosition();
|
||||
if (position != NO_POSITION && listener != null) {
|
||||
if (position != NO_POSITION) {
|
||||
boolean enableLoading = listener.onPlaceholderClick(position);
|
||||
setLoading(enableLoading);
|
||||
}
|
||||
@ -82,11 +84,4 @@ public class PlaceHolder extends ViewHolder implements OnClickListener {
|
||||
loadBtn.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set click listener for this item
|
||||
*/
|
||||
public void setOnHolderClickListener(OnHolderClickListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@ -27,15 +26,14 @@ public class PollHolder extends ViewHolder implements OnOptionClickListener {
|
||||
private TextView votesCount;
|
||||
|
||||
private OptionsAdapter adapter;
|
||||
|
||||
@Nullable
|
||||
private OnHolderClickListener listener;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public PollHolder(ViewGroup parent, GlobalSettings settings) {
|
||||
public PollHolder(ViewGroup parent, GlobalSettings settings, OnHolderClickListener listener) {
|
||||
super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_poll, parent, false));
|
||||
this.listener = listener;
|
||||
|
||||
CardView cardBackground = (CardView) itemView;
|
||||
RecyclerView optionsList = itemView.findViewById(R.id.item_poll_options_list);
|
||||
@ -55,7 +53,7 @@ public class PollHolder extends ViewHolder implements OnOptionClickListener {
|
||||
@Override
|
||||
public void onOptionClick(int index) {
|
||||
int pos = getLayoutPosition();
|
||||
if (pos != RecyclerView.NO_POSITION && listener != null) {
|
||||
if (pos != RecyclerView.NO_POSITION) {
|
||||
listener.onItemClick(pos, OnHolderClickListener.POLL_ITEM, index);
|
||||
}
|
||||
}
|
||||
@ -74,11 +72,4 @@ public class PollHolder extends ViewHolder implements OnOptionClickListener {
|
||||
votesCount.append(StringTools.NUMBER_FORMAT.format(poll.voteCount()));
|
||||
adapter.addAll(poll);
|
||||
}
|
||||
|
||||
/**
|
||||
* set item click lsitener
|
||||
*/
|
||||
public void setOnPollOptionClickListener(OnHolderClickListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
}
|
@ -37,10 +37,11 @@ public class PreviewHolder extends ViewHolder implements OnClickListener {
|
||||
private OnHolderClickListener listener;
|
||||
|
||||
|
||||
public PreviewHolder(ViewGroup parent, GlobalSettings settings, Picasso picasso) {
|
||||
public PreviewHolder(ViewGroup parent, GlobalSettings settings, Picasso picasso, OnHolderClickListener listener) {
|
||||
super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_preview, parent, false));
|
||||
this.picasso = picasso;
|
||||
this.settings = settings;
|
||||
this.listener = listener;
|
||||
|
||||
previewImage = itemView.findViewById(R.id.item_preview_image);
|
||||
playIcon = itemView.findViewById(R.id.item_preview_play);
|
||||
@ -52,7 +53,7 @@ public class PreviewHolder extends ViewHolder implements OnClickListener {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int pos = getLayoutPosition();
|
||||
if (pos != RecyclerView.NO_POSITION && listener != null) {
|
||||
if (pos != RecyclerView.NO_POSITION) {
|
||||
if (v == previewImage) {
|
||||
listener.onItemClick(pos, OnHolderClickListener.PREVIEW_CLICK);
|
||||
}
|
||||
@ -78,14 +79,4 @@ public class PreviewHolder extends ViewHolder implements OnClickListener {
|
||||
playIcon.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set holder click lsitener
|
||||
*
|
||||
* @param listener listener for the holder
|
||||
*/
|
||||
public void setOnPreviewClickListener(OnHolderClickListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
}
|
@ -13,7 +13,6 @@ import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@ -50,16 +49,15 @@ public class StatusHolder extends ViewHolder implements OnClickListener {
|
||||
private GlobalSettings settings;
|
||||
private Picasso picasso;
|
||||
private IconAdapter adapter;
|
||||
|
||||
@Nullable
|
||||
private OnHolderClickListener listener;
|
||||
|
||||
/**
|
||||
* @param parent Parent view from adapter
|
||||
* @param settings app settings to set theme
|
||||
*/
|
||||
public StatusHolder(ViewGroup parent, GlobalSettings settings, Picasso picasso) {
|
||||
|
||||
public StatusHolder(ViewGroup parent, GlobalSettings settings, Picasso picasso, OnHolderClickListener listener) {
|
||||
super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_status, parent, false));
|
||||
this.settings = settings;
|
||||
this.picasso = picasso;
|
||||
this.listener = listener;
|
||||
|
||||
CardView cardLayout = (CardView) itemView;
|
||||
ViewGroup container = itemView.findViewById(R.id.item_status_container);
|
||||
label = itemView.findViewById(R.id.item_status_label);
|
||||
@ -83,8 +81,6 @@ public class StatusHolder extends ViewHolder implements OnClickListener {
|
||||
iconList.setLayoutManager(new LinearLayoutManager(parent.getContext(), HORIZONTAL, false));
|
||||
adapter = new IconAdapter(settings);
|
||||
iconList.setAdapter(adapter);
|
||||
this.settings = settings;
|
||||
this.picasso = picasso;
|
||||
|
||||
if (settings.likeEnabled()) {
|
||||
favIcon.setImageResource(R.drawable.like);
|
||||
@ -102,7 +98,7 @@ public class StatusHolder extends ViewHolder implements OnClickListener {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int position = getLayoutPosition();
|
||||
if (position != NO_POSITION && listener != null) {
|
||||
if (position != NO_POSITION) {
|
||||
if (v == itemView) {
|
||||
listener.onItemClick(position, OnHolderClickListener.STATUS_CLICK);
|
||||
} else if (v == label) {
|
||||
@ -236,11 +232,4 @@ public class StatusHolder extends ViewHolder implements OnClickListener {
|
||||
label.setCompoundDrawablesWithIntrinsicBounds(iconRes, 0, 0, 0);
|
||||
AppStyles.setDrawableColor(label, settings.getIconColor());
|
||||
}
|
||||
|
||||
/**
|
||||
* set item click listener
|
||||
*/
|
||||
public void setOnStatusClickListener(OnHolderClickListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
}
|
@ -32,11 +32,11 @@ public class TrendHolder extends ViewHolder implements OnClickListener {
|
||||
|
||||
private OnHolderClickListener listener;
|
||||
|
||||
/**
|
||||
* @param parent Parent view from adapter
|
||||
*/
|
||||
public TrendHolder(ViewGroup parent, GlobalSettings settings) {
|
||||
|
||||
public TrendHolder(ViewGroup parent, GlobalSettings settings, OnHolderClickListener listener) {
|
||||
super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_trend, parent, false));
|
||||
this.listener = listener;
|
||||
|
||||
CardView background = (CardView) itemView;
|
||||
ViewGroup container = itemView.findViewById(R.id.item_trend_container);
|
||||
rank = itemView.findViewById(R.id.item_trend_rank);
|
||||
@ -53,19 +53,12 @@ public class TrendHolder extends ViewHolder implements OnClickListener {
|
||||
public void onClick(View v) {
|
||||
if (v == itemView) {
|
||||
int position = getLayoutPosition();
|
||||
if (position != NO_POSITION && listener != null) {
|
||||
if (position != NO_POSITION) {
|
||||
listener.onItemClick(position, OnHolderClickListener.NO_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set item click listener
|
||||
*/
|
||||
public void setOnTrendClickListener(OnHolderClickListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* set view content
|
||||
*
|
||||
|
@ -46,11 +46,13 @@ public class UserHolder extends ViewHolder implements OnClickListener {
|
||||
|
||||
private OnHolderClickListener listener;
|
||||
|
||||
/**
|
||||
* @param parent Parent view from adapter
|
||||
*/
|
||||
public UserHolder(ViewGroup parent, GlobalSettings settings, Picasso picasso) {
|
||||
|
||||
public UserHolder(ViewGroup parent, GlobalSettings settings, Picasso picasso, OnHolderClickListener listener, boolean enableDelete) {
|
||||
super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_user, parent, false));
|
||||
this.settings = settings;
|
||||
this.picasso = picasso;
|
||||
this.listener = listener;
|
||||
|
||||
CardView background = (CardView) itemView;
|
||||
ViewGroup container = itemView.findViewById(R.id.item_user_container);
|
||||
label = itemView.findViewById(R.id.item_user_label);
|
||||
@ -65,8 +67,11 @@ public class UserHolder extends ViewHolder implements OnClickListener {
|
||||
|
||||
AppStyles.setTheme(container, Color.TRANSPARENT);
|
||||
background.setCardBackgroundColor(settings.getCardColor());
|
||||
this.settings = settings;
|
||||
this.picasso = picasso;
|
||||
if (enableDelete) {
|
||||
delete.setVisibility(VISIBLE);
|
||||
} else {
|
||||
delete.setVisibility(GONE);
|
||||
}
|
||||
|
||||
itemView.setOnClickListener(this);
|
||||
delete.setOnClickListener(this);
|
||||
@ -76,7 +81,7 @@ public class UserHolder extends ViewHolder implements OnClickListener {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
int position = getLayoutPosition();
|
||||
if (listener != null && position != NO_POSITION) {
|
||||
if (position != NO_POSITION) {
|
||||
if (v == itemView) {
|
||||
listener.onItemClick(position, OnHolderClickListener.USER_CLICK);
|
||||
} else if (v == delete) {
|
||||
@ -85,13 +90,6 @@ public class UserHolder extends ViewHolder implements OnClickListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* set item click listener
|
||||
*/
|
||||
public void setOnUserClickListener(OnHolderClickListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* set user information
|
||||
*
|
||||
@ -153,17 +151,4 @@ public class UserHolder extends ViewHolder implements OnClickListener {
|
||||
label.setCompoundDrawablesWithIntrinsicBounds(iconRes, 0, 0, 0);
|
||||
label.setText(text);
|
||||
}
|
||||
|
||||
/**
|
||||
* enable/disable delete button
|
||||
*
|
||||
* @param enable true to enable delete button
|
||||
*/
|
||||
public void setDeleteButton(boolean enable) {
|
||||
if (enable) {
|
||||
delete.setVisibility(VISIBLE);
|
||||
} else {
|
||||
delete.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
}
|
@ -1123,11 +1123,12 @@ public class Twitter implements Connection {
|
||||
else
|
||||
array = new JSONArray(body.string());
|
||||
long homeId = settings.getLogin().getId();
|
||||
String host = settings.getLogin().getHostname();
|
||||
List<Status> tweets = new ArrayList<>(array.length() + 1);
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
try {
|
||||
JSONObject tweetJson = array.getJSONObject(i);
|
||||
tweets.add(new TweetV1(tweetJson, homeId));
|
||||
tweets.add(new TweetV1(tweetJson, host, homeId));
|
||||
} catch (JSONException e) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
Log.w("tweet", e);
|
||||
@ -1177,9 +1178,10 @@ public class Twitter implements Connection {
|
||||
MediaV2Map mediaMap = new MediaV2Map(json);
|
||||
PollV2Map pollMap = new PollV2Map(json);
|
||||
LocationV2Map locationMap = new LocationV2Map(json);
|
||||
String host = settings.getLogin().getHostname();
|
||||
for (int i = 0; i < data.length(); i++) {
|
||||
try {
|
||||
Status item = new TweetV2(data.getJSONObject(i), userMap, mediaMap, pollMap, locationMap, null);
|
||||
Status item = new TweetV2(data.getJSONObject(i), userMap, mediaMap, pollMap, locationMap, host, null);
|
||||
tweets.add(item);
|
||||
} catch (JSONException e) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
@ -1218,7 +1220,9 @@ public class Twitter implements Connection {
|
||||
ResponseBody body = response.body();
|
||||
if (body != null && response.code() == 200) {
|
||||
JSONObject json = new JSONObject(body.string());
|
||||
TweetV1 result = new TweetV1(json, settings.getLogin().getId());
|
||||
String host = settings.getLogin().getHostname();
|
||||
long currentId = settings.getLogin().getId();
|
||||
TweetV1 result = new TweetV1(json, host, currentId);
|
||||
// fix: embedded tweet information doesn't match with the parent tweet
|
||||
// re-downloading embedded tweet information
|
||||
if (result.getEmbeddedStatus() != null) {
|
||||
@ -1269,7 +1273,8 @@ public class Twitter implements Connection {
|
||||
MediaV2Map mediaMap = new MediaV2Map(json);
|
||||
PollV2Map pollMap = new PollV2Map(json);
|
||||
LocationV2Map locationMap = new LocationV2Map(json);
|
||||
return new TweetV2(json, userMap, mediaMap, pollMap, locationMap, statusCompat);
|
||||
String host = settings.getLogin().getHostname();
|
||||
return new TweetV2(json, userMap, mediaMap, pollMap, locationMap, host, statusCompat);
|
||||
}
|
||||
throw new TwitterException(response);
|
||||
} catch (IOException | JSONException err) {
|
||||
|
@ -56,6 +56,7 @@ public class TweetV1 implements Status {
|
||||
private String userMentions;
|
||||
private String text;
|
||||
private String source;
|
||||
private String host;
|
||||
|
||||
private long replyUserId;
|
||||
private long replyTweetId;
|
||||
@ -66,7 +67,7 @@ public class TweetV1 implements Status {
|
||||
* @param twitterId ID of the current user
|
||||
* @throws JSONException if values are missing
|
||||
*/
|
||||
public TweetV1(JSONObject json, long twitterId) throws JSONException {
|
||||
public TweetV1(JSONObject json, String host, long twitterId) throws JSONException {
|
||||
JSONObject locationJson = json.optJSONObject("place");
|
||||
JSONObject currentUserJson = json.optJSONObject("current_user_retweet");
|
||||
JSONObject embeddedTweetJson = json.optJSONObject("retweeted_status");
|
||||
@ -87,13 +88,14 @@ public class TweetV1 implements Status {
|
||||
timestamp = StringTools.getTime(json.optString("created_at", ""), StringTools.TIME_TWITTER_V1);
|
||||
userMentions = StringTools.getUserMentions(textStr, author.getScreenname());
|
||||
source = Jsoup.parse(sourceStr).text();
|
||||
this.host = host;
|
||||
// add reply name
|
||||
if (!replyNameStr.isEmpty() && !replyNameStr.equals("null")) {
|
||||
replyName = '@' + replyNameStr;
|
||||
}
|
||||
// add embedded tweet
|
||||
if (embeddedTweetJson != null) {
|
||||
embeddedTweet = new TweetV1(embeddedTweetJson, twitterId);
|
||||
embeddedTweet = new TweetV1(embeddedTweetJson, host, twitterId);
|
||||
}
|
||||
// add location
|
||||
if (locationJson != null) {
|
||||
@ -271,7 +273,7 @@ public class TweetV1 implements Status {
|
||||
@Override
|
||||
public String getUrl() {
|
||||
if (author.getScreenname().length() > 1) {
|
||||
return "https://twitter.com/" + author.getScreenname().substring(1) + "/status/" + id;
|
||||
return host + '/' + author.getScreenname().substring(1) + "/status/" + id;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ public class MediaV2 implements Media {
|
||||
|
||||
case TYPE_GIF:
|
||||
variants = mediaItem.getJSONArray("variants");
|
||||
for (int i = 0 ; i < variants.length() ; i++) {
|
||||
for (int i = 0; i < variants.length(); i++) {
|
||||
JSONObject gifVariant = variants.getJSONObject(i);
|
||||
if (MIME_V_MP4.equals(gifVariant.getString("content_type"))) {
|
||||
url = gifVariant.getString("url");
|
||||
|
@ -59,6 +59,7 @@ public class TweetV2 implements Status {
|
||||
private String source;
|
||||
private String mentions;
|
||||
private String replyName = "";
|
||||
private String host;
|
||||
private Location location;
|
||||
|
||||
private boolean retweeted;
|
||||
@ -83,7 +84,7 @@ public class TweetV2 implements Status {
|
||||
* @param locationMap map containing location instances
|
||||
* @param tweetCompat tweet v1.1 object
|
||||
*/
|
||||
public TweetV2(JSONObject json, @NonNull UserV2Map userMap, @Nullable MediaV2Map mediaMap, @Nullable PollV2Map pollMap, @Nullable LocationV2Map locationMap, @Nullable Status tweetCompat) throws JSONException {
|
||||
public TweetV2(JSONObject json, @NonNull UserV2Map userMap, @Nullable MediaV2Map mediaMap, @Nullable PollV2Map pollMap, @Nullable LocationV2Map locationMap, String host, @Nullable Status tweetCompat) throws JSONException {
|
||||
if (json.has("data"))
|
||||
json = json.getJSONObject("data");
|
||||
JSONObject publicMetrics = json.getJSONObject("public_metrics");
|
||||
@ -124,6 +125,7 @@ public class TweetV2 implements Status {
|
||||
source = json.optString("source", "");
|
||||
sensitive = json.optBoolean("possibly_sensitive", false);
|
||||
mentions = author.getScreenname() + ' ';
|
||||
this.host = host;
|
||||
// add media
|
||||
if (attachments != null) {
|
||||
JSONArray mediaKeys = attachments.optJSONArray("media_keys");
|
||||
@ -344,7 +346,7 @@ public class TweetV2 implements Status {
|
||||
@Override
|
||||
public String getUrl() {
|
||||
if (author.getScreenname().length() > 1) {
|
||||
return "https://twitter.com/" + author.getScreenname().substring(1) + "/status/" + id;
|
||||
return host + '/' + author.getScreenname().substring(1) + "/status/" + id;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
@ -1313,13 +1313,14 @@ public class AppDatabase {
|
||||
else
|
||||
register &= ~FAVORITE_MASK;
|
||||
|
||||
ContentValues statusUpdate = new ContentValues(6);
|
||||
ContentValues statusUpdate = new ContentValues(7);
|
||||
statusUpdate.put(StatusTable.TEXT, status.getText());
|
||||
statusUpdate.put(StatusTable.REPOST, status.getRepostCount());
|
||||
statusUpdate.put(StatusTable.FAVORITE, status.getFavoriteCount());
|
||||
statusUpdate.put(StatusTable.REPLY, status.getReplyCount());
|
||||
statusUpdate.put(StatusTable.REPLYNAME, status.getReplyName());
|
||||
statusUpdate.put(StatusTable.SOURCE, status.getSource());
|
||||
statusUpdate.put(StatusTable.URL, status.getUrl());
|
||||
|
||||
ContentValues userUpdate = new ContentValues(9);
|
||||
userUpdate.put(UserTable.USERNAME, user.getUsername());
|
||||
|
Loading…
x
Reference in New Issue
Block a user