code cleanup, bug fix

This commit is contained in:
nuclearfog 2022-12-27 22:56:06 +01:00
parent e287b31bde
commit d9d15f1efa
No known key found for this signature in database
GPG Key ID: 03488A185C476379
34 changed files with 231 additions and 275 deletions

View File

@ -65,7 +65,7 @@ public class AccountAdapter extends Adapter<AccountHolder> implements OnHolderCl
@Override
public void onItemClick(int position, int type) {
public void onItemClick(int position, int type, int... extras) {
Account account = accounts.get(position);
if (type == OnHolderClickListener.ACCOUNT_SELECT) {
listener.onAccountClick(account);

View File

@ -93,7 +93,7 @@ public class ImageAdapter extends Adapter<ViewHolder> implements OnHolderClickLi
@Override
public void onItemClick(int position, int type) {
public void onItemClick(int position, int type, int... extras) {
switch (type) {
case OnHolderClickListener.IMAGE_CLICK:
itemClickListener.onImageClick(imageLinks.get(position));

View File

@ -113,7 +113,7 @@ public class MessageAdapter extends Adapter<ViewHolder> implements OnItemClickLi
@Override
public void onItemClick(int position, int type) {
public void onItemClick(int position, int type, int... extras) {
Message message = messages.get(position);
if (message != null) {
switch (type) {

View File

@ -181,7 +181,7 @@ public class NotificationAdapter extends Adapter<ViewHolder> implements OnHolder
@Override
public void onItemClick(int position, int type) {
public void onItemClick(int position, int type, int... extras) {
Notification item = items.get(position);
switch (type) {
case OnHolderClickListener.USER_CLICK:

View File

@ -11,17 +11,23 @@ import org.nuclearfog.twidda.database.GlobalSettings;
import org.nuclearfog.twidda.model.Account;
import org.nuclearfog.twidda.model.Poll;
/**
* RecyclerView adapter for poll options
*
* @author nuclearfog
*/
public class OptionsAdapter extends RecyclerView.Adapter<Optionholder> implements OnOptionItemClick {
private Poll.Option[] options;
private Poll.Option[] options = {};
private int totalVotes = 1;
private GlobalSettings settings;
private OnOptionClickListener listener;
private boolean enableVote = false;
private boolean enableVote;
/**
*
*/
public OptionsAdapter(GlobalSettings settings, OnOptionClickListener listener) {
// currently Twitter doesn't support vote over API
enableVote = settings.getLogin().getApiType() != Account.API_TWITTER;
@ -57,15 +63,27 @@ public class OptionsAdapter extends RecyclerView.Adapter<Optionholder> implement
listener.onOptionClick(pos);
}
/**
* set poll information and options
*
* @param poll poll information
*/
public void addAll(Poll poll) {
this.options = poll.getOptions();
totalVotes = poll.voteCount();
notifyDataSetChanged();
}
/**
* Listener for poll options
*/
public interface OnOptionClickListener {
/**
* called on poll option select
*
* @param index index of the poll option
*/
void onOptionClick(int index);
}
}

View File

@ -11,11 +11,9 @@ import androidx.recyclerview.widget.RecyclerView.ViewHolder;
import com.squareup.picasso.Picasso;
import org.nuclearfog.twidda.adapter.holder.CardHolder;
import org.nuclearfog.twidda.adapter.holder.CardHolder.OnItemClickListener;
import org.nuclearfog.twidda.adapter.holder.OnHolderClickListener;
import org.nuclearfog.twidda.adapter.holder.PollHolder;
import org.nuclearfog.twidda.adapter.holder.PollHolder.OnPollOptionClickListener;
import org.nuclearfog.twidda.adapter.holder.PreviewHolder;
import org.nuclearfog.twidda.adapter.holder.PreviewHolder.OnPreviewClickListener;
import org.nuclearfog.twidda.backend.utils.PicassoBuilder;
import org.nuclearfog.twidda.database.GlobalSettings;
import org.nuclearfog.twidda.model.Card;
@ -31,7 +29,9 @@ import java.util.List;
*
* @author nuclearfog
*/
public class PreviewAdapter extends RecyclerView.Adapter<ViewHolder> implements OnItemClickListener, OnPreviewClickListener, OnPollOptionClickListener {
public class PreviewAdapter extends RecyclerView.Adapter<ViewHolder> implements OnHolderClickListener {
private static final int INVALID_ID = -1;
/**
* ID used for media preview
@ -43,8 +43,6 @@ public class PreviewAdapter extends RecyclerView.Adapter<ViewHolder> implements
*/
private static final int ITEM_CARD = 1;
private static final int INVALID_ID = -1;
/**
* ID used for {@link org.nuclearfog.twidda.adapter.holder.PollHolder}
*/
@ -69,18 +67,22 @@ public class PreviewAdapter extends RecyclerView.Adapter<ViewHolder> implements
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
if (viewType == ITEM_PREVIEW) {
PreviewHolder holder = new PreviewHolder(parent, settings, picasso);
holder.setOnPreviewClickListener(this);
return holder;
} else if (viewType == ITEM_CARD) {
CardHolder holder = new CardHolder(parent, settings, picasso);
holder.setOnCardClickListener(this);
return holder;
} else {
PollHolder holder = new PollHolder(parent, settings);
holder.setOnPollOptionClickListener(this);
return holder;
switch (viewType) {
default:
case ITEM_PREVIEW:
PreviewHolder previewHolder = new PreviewHolder(parent, settings, picasso);
previewHolder.setOnPreviewClickListener(this);
return previewHolder;
case ITEM_CARD:
CardHolder cardHolder = new CardHolder(parent, settings, picasso);
cardHolder.setOnCardClickListener(this);
return cardHolder;
case ITEM_POLL:
PollHolder pollHolder = new PollHolder(parent, settings);
pollHolder.setOnPollOptionClickListener(this);
return pollHolder;
}
}
@ -124,36 +126,40 @@ public class PreviewAdapter extends RecyclerView.Adapter<ViewHolder> implements
@Override
public void onCardItemClick(int pos, int type) {
public void onItemClick(int pos, int type, int... extras) {
Object item = items.get(pos);
if (item instanceof Card) {
Card card = (Card) item;
if (type == OnItemClickListener.TYPE_LINK) {
listener.onCardClick(card, OnCardClickListener.TYPE_LINK);
} else if (type == OnItemClickListener.TYPE_IMAGE) {
listener.onCardClick(card, OnCardClickListener.TYPE_IMAGE);
}
switch (type) {
case OnHolderClickListener.PREVIEW_CLICK:
if (item instanceof Media) {
Media media = (Media) item;
listener.onMediaClick(media);
}
break;
case OnHolderClickListener.CARD_LINK:
if (item instanceof Card)
listener.onCardClick((Card) item, OnCardClickListener.TYPE_LINK);
break;
case OnHolderClickListener.CARD_IMAGE:
if (item instanceof Card)
listener.onCardClick((Card) item, OnCardClickListener.TYPE_IMAGE);
break;
case OnHolderClickListener.POLL_ITEM:
if (item instanceof Poll && extras.length == 1) {
Poll poll = (Poll) item;
listener.onPollOptionClick(poll, extras[0]);
}
break;
}
}
@Override
public void onPreviewClick(int pos) {
Object item = items.get(pos);
if (item instanceof Media) {
Media media = (Media) item;
listener.onMediaClick(media);
}
}
@Override
public void onPollOptionClick(int position, int selection) {
Object item = items.get(position);
if (item instanceof Poll) {
Poll poll = (Poll) item;
listener.onPollOptionClick(poll, selection);
}
public boolean onPlaceholderClick(int position) {
return false;
}
/**
@ -201,7 +207,12 @@ public class PreviewAdapter extends RecyclerView.Adapter<ViewHolder> implements
*/
void onMediaClick(Media media);
/**
* called on poll option click
*
* @param poll poll containing the clicked option
* @param selection poll option index
*/
void onPollOptionClick(Poll poll, int selection);
}
}

View File

@ -155,7 +155,7 @@ public class StatusAdapter extends Adapter<ViewHolder> implements OnHolderClickL
@Override
public void onItemClick(int position, int type) {
public void onItemClick(int position, int type, int... extras) {
if (type == OnHolderClickListener.STATUS_CLICK) {
Status status = items.get(position);
if (status != null) {

View File

@ -66,7 +66,7 @@ public class TrendAdapter extends Adapter<ViewHolder> implements OnHolderClickLi
@Override
public void onItemClick(int position, int type) {
public void onItemClick(int position, int type, int... extras) {
itemClickListener.onTrendClick(trends.get(position));
}

View File

@ -130,7 +130,7 @@ public class UserAdapter extends Adapter<ViewHolder> implements OnHolderClickLis
@Override
public void onItemClick(int position, int type) {
public void onItemClick(int position, int type, int... extras) {
switch (type) {
case OnHolderClickListener.USER_CLICK:
User user = users.get(position);

View File

@ -107,7 +107,7 @@ public class UserlistAdapter extends Adapter<ViewHolder> implements OnHolderClic
@Override
public void onItemClick(int position, int type) {
public void onItemClick(int position, int type, int... extras) {
UserList item = userlists.get(position);
if (item != null) {
switch (type) {

View File

@ -48,7 +48,7 @@ public class CardHolder extends ViewHolder implements OnClickListener {
private Picasso picasso;
private GlobalSettings settings;
private OnItemClickListener listener;
private OnHolderClickListener listener;
public CardHolder(ViewGroup parent, GlobalSettings settings, Picasso picasso) {
@ -75,9 +75,9 @@ public class CardHolder extends ViewHolder implements OnClickListener {
int pos = getLayoutPosition();
if (pos != RecyclerView.NO_POSITION && listener != null) {
if (v == linkText) {
listener.onCardItemClick(pos, OnItemClickListener.TYPE_LINK);
listener.onItemClick(pos, OnHolderClickListener.CARD_LINK);
} else if (v == preview) {
listener.onCardItemClick(pos, OnItemClickListener.TYPE_IMAGE);
listener.onItemClick(pos, OnHolderClickListener.CARD_IMAGE);
}
}
}
@ -109,29 +109,7 @@ public class CardHolder extends ViewHolder implements OnClickListener {
/**
* add viewholder click listener
*/
public void setOnCardClickListener(OnItemClickListener listener) {
public void setOnCardClickListener(OnHolderClickListener listener) {
this.listener = listener;
}
/**
* custom viewholder click listener
*/
public interface OnItemClickListener {
/**
* indicates a link click
*/
int TYPE_LINK = 1;
/**
* indicates a click on the image
*/
int TYPE_IMAGE = 2;
/**
* @param pos index of the item
* @param type type of click {@link #TYPE_IMAGE,#TYPE_LINK}
*/
void onCardItemClick(int pos, int type);
}
}

View File

@ -39,13 +39,22 @@ public interface OnHolderClickListener {
int IMAGE_SAVE = 15;
int PREVIEW_CLICK = 16;
int CARD_IMAGE = 17;
int CARD_LINK = 18;
int POLL_ITEM = 19;
/**
* called when an item was clicked
*
* @param position adapter position of the item
* @param type type of click
* @param extras extra information
*/
void onItemClick(int position, int type);
void onItemClick(int position, int type, int... extras);
/**
* called when a placeholder item was clicked

View File

@ -14,16 +14,17 @@ import androidx.recyclerview.widget.RecyclerView.ViewHolder;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.StringTools;
import org.nuclearfog.twidda.database.GlobalSettings;
import org.nuclearfog.twidda.model.Poll;
import java.text.NumberFormat;
/**
* This holder if for a single poll option
*
* @author nuclearfog
*/
public class Optionholder extends ViewHolder implements View.OnClickListener {
private static final NumberFormat NUM_FORMAT = NumberFormat.getIntegerInstance();
private SeekBar count;
private TextView name, votes;
private ImageView checked;
@ -32,10 +33,11 @@ public class Optionholder extends ViewHolder implements View.OnClickListener {
private OnOptionItemClick listener;
private GlobalSettings settings;
/**
*
*/
public Optionholder(ViewGroup parent, GlobalSettings settings) {
super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_option, parent, false));
name = itemView.findViewById(R.id.item_option_name);
checked = itemView.findViewById(R.id.item_option_voted_icon);
count = itemView.findViewById(R.id.item_option_count_bar);
@ -60,12 +62,19 @@ public class Optionholder extends ViewHolder implements View.OnClickListener {
}
}
/**
* set viewholder click listener
*/
public void setOnOptionItemClickListener(OnOptionItemClick listener) {
this.listener = listener;
}
/**
* set viewholder content
*
* @param option poll option content
* @param totalCount total vote count
*/
public void setContent(Poll.Option option, int totalCount) {
if (option.selected())
checked.setImageResource(R.drawable.check);
@ -75,12 +84,19 @@ public class Optionholder extends ViewHolder implements View.OnClickListener {
name.setText(option.getTitle());
count.setMax(totalCount);
count.setProgress(option.getVotes());
votes.setText(NUM_FORMAT.format(option.getVotes()));
votes.setText(StringTools.NUMBER_FORMAT.format(option.getVotes()));
}
/**
* viewholder click listener
*/
public interface OnOptionItemClick {
/**
* called on item click
*
* @param pos adapter position of the item
*/
void onOptionClick(int pos);
}
}

View File

@ -13,24 +13,27 @@ import androidx.recyclerview.widget.RecyclerView.ViewHolder;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.adapter.OptionsAdapter;
import org.nuclearfog.twidda.adapter.OptionsAdapter.OnOptionClickListener;
import org.nuclearfog.twidda.backend.utils.StringTools;
import org.nuclearfog.twidda.database.GlobalSettings;
import org.nuclearfog.twidda.model.Poll;
import java.text.NumberFormat;
/**
* View holder for status polls
*
* @author nuclearfog
*/
public class PollHolder extends ViewHolder implements OnOptionClickListener {
private static final NumberFormat NUM_FORMAT = NumberFormat.getIntegerInstance();
private TextView votesCount;
private OptionsAdapter adapter;
@Nullable
private OnPollOptionClickListener listener;
private OnHolderClickListener listener;
/**
*
*/
public PollHolder(ViewGroup parent, GlobalSettings settings) {
super(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_poll, parent, false));
@ -53,25 +56,25 @@ public class PollHolder extends ViewHolder implements OnOptionClickListener {
public void onOptionClick(int index) {
int pos = getLayoutPosition();
if (pos != RecyclerView.NO_POSITION && listener != null) {
listener.onPollOptionClick(pos, index);
listener.onItemClick(pos, OnHolderClickListener.POLL_ITEM, index);
}
}
/**
* set view content
*
* @param poll poll information
*/
public void setContent(Poll poll) {
votesCount.setText(R.string.poll_total_votes);
votesCount.append(NUM_FORMAT.format(poll.voteCount()));
votesCount.append(StringTools.NUMBER_FORMAT.format(poll.voteCount()));
adapter.addAll(poll);
}
public void setOnPollOptionClickListener(OnPollOptionClickListener listener) {
/**
* set item click lsitener
*/
public void setOnPollOptionClickListener(OnHolderClickListener listener) {
this.listener = listener;
}
public interface OnPollOptionClickListener {
void onPollOptionClick(int position, int selection);
}
}

View File

@ -27,7 +27,7 @@ public class PreviewHolder extends ViewHolder implements OnClickListener {
private Picasso picasso;
private GlobalSettings settings;
private OnPreviewClickListener listener;
private OnHolderClickListener listener;
public PreviewHolder(ViewGroup parent, GlobalSettings settings, Picasso picasso) {
@ -47,7 +47,7 @@ public class PreviewHolder extends ViewHolder implements OnClickListener {
int pos = getLayoutPosition();
if (pos != RecyclerView.NO_POSITION && listener != null) {
if (v == previewImage) {
listener.onPreviewClick(pos);
listener.onItemClick(pos, OnHolderClickListener.PREVIEW_CLICK);
}
}
}
@ -78,20 +78,7 @@ public class PreviewHolder extends ViewHolder implements OnClickListener {
*
* @param listener listener for the holder
*/
public void setOnPreviewClickListener(OnPreviewClickListener listener) {
public void setOnPreviewClickListener(OnHolderClickListener listener) {
this.listener = listener;
}
/**
* holder click lsitener
*/
public interface OnPreviewClickListener {
/**
* called on holder click
*
* @param pos list position of the holder
*/
void onPreviewClick(int pos);
}
}

View File

@ -1,6 +1,5 @@
package org.nuclearfog.twidda.adapter.holder;
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
import android.content.res.Resources;
@ -30,8 +29,6 @@ import org.nuclearfog.twidda.model.Notification;
import org.nuclearfog.twidda.model.Status;
import org.nuclearfog.twidda.model.User;
import java.text.NumberFormat;
import jp.wasabeef.picasso.transformations.RoundedCornersTransformation;
/**
@ -42,8 +39,6 @@ import jp.wasabeef.picasso.transformations.RoundedCornersTransformation;
*/
public class StatusHolder extends ViewHolder implements OnClickListener {
private static final NumberFormat NUM_FORMAT = NumberFormat.getIntegerInstance();
private ImageView profile, rpUser, verifiedIcon, lockedIcon, rtIcon, favIcon, media, location, replyIcon;
private TextView username, screenname, text, repost, favorite, reposter, created, replyname, label;
@ -125,8 +120,8 @@ public class StatusHolder extends ViewHolder implements OnClickListener {
}
username.setText(user.getUsername());
screenname.setText(user.getScreenname());
repost.setText(NUM_FORMAT.format(status.getRepostCount()));
favorite.setText(NUM_FORMAT.format(status.getFavoriteCount()));
repost.setText(StringTools.NUMBER_FORMAT.format(status.getRepostCount()));
favorite.setText(StringTools.NUMBER_FORMAT.format(status.getFavoriteCount()));
created.setText(StringTools.formatCreationTime(itemView.getResources(), status.getTimestamp()));
if (!status.getText().isEmpty()) {
Spanned textSpan = Tagger.makeTextWithLinks(status.getText(), settings.getHighlightColor());

View File

@ -16,11 +16,10 @@ import androidx.recyclerview.widget.RecyclerView.ViewHolder;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.StringTools;
import org.nuclearfog.twidda.database.GlobalSettings;
import org.nuclearfog.twidda.model.Trend;
import java.text.NumberFormat;
/**
* ViewHolder for a trend item
*
@ -29,11 +28,6 @@ import java.text.NumberFormat;
*/
public class TrendHolder extends ViewHolder implements OnClickListener {
/**
* Locale specific number format
*/
private static final NumberFormat NUM_FORMAT = NumberFormat.getIntegerInstance();
private TextView name, rank, vol;
private OnHolderClickListener listener;
@ -82,7 +76,7 @@ public class TrendHolder extends ViewHolder implements OnClickListener {
name.setText(trend.getName());
if (trend.getPopularity() > 0) {
Resources resources = vol.getResources();
String trendVol = NUM_FORMAT.format(trend.getPopularity()) + " " + resources.getString(R.string.trend_range);
String trendVol = StringTools.NUMBER_FORMAT.format(trend.getPopularity()) + resources.getString(R.string.trend_range);
vol.setText(trendVol);
vol.setVisibility(View.VISIBLE);
} else {

View File

@ -22,12 +22,11 @@ import com.squareup.picasso.Transformation;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.StringTools;
import org.nuclearfog.twidda.database.GlobalSettings;
import org.nuclearfog.twidda.model.Notification;
import org.nuclearfog.twidda.model.User;
import java.text.NumberFormat;
import jp.wasabeef.picasso.transformations.RoundedCornersTransformation;
/**
@ -38,11 +37,6 @@ import jp.wasabeef.picasso.transformations.RoundedCornersTransformation;
*/
public class UserHolder extends ViewHolder implements OnClickListener {
/**
* locale specific number formatter
*/
private static final NumberFormat NUM_FORMAT = NumberFormat.getIntegerInstance();
private TextView username, screenname, followingCount, followerCount, label;
private ImageView profileImg, verifyIcon, lockedIcon;
private ImageButton delete;
@ -106,8 +100,8 @@ public class UserHolder extends ViewHolder implements OnClickListener {
public void setContent(User user) {
username.setText(user.getUsername());
screenname.setText(user.getScreenname());
followingCount.setText(NUM_FORMAT.format(user.getFollowing()));
followerCount.setText(NUM_FORMAT.format(user.getFollower()));
followingCount.setText(StringTools.NUMBER_FORMAT.format(user.getFollowing()));
followerCount.setText(StringTools.NUMBER_FORMAT.format(user.getFollower()));
if (user.isVerified()) {
verifyIcon.setVisibility(VISIBLE);
} else {

View File

@ -24,8 +24,6 @@ import org.nuclearfog.twidda.model.Account;
import org.nuclearfog.twidda.model.User;
import org.nuclearfog.twidda.model.UserList;
import java.text.NumberFormat;
import jp.wasabeef.picasso.transformations.RoundedCornersTransformation;
/**
@ -36,8 +34,6 @@ import jp.wasabeef.picasso.transformations.RoundedCornersTransformation;
*/
public class UserlistHolder extends ViewHolder implements OnClickListener {
private static final NumberFormat NUM_FORMAT = NumberFormat.getIntegerInstance();
private ImageView profileImage, userVerified, userLocked, privateIcon, followIcon;
private TextView title, description, username, screenname, date, member, subscriber, followList;
@ -116,8 +112,8 @@ public class UserlistHolder extends ViewHolder implements OnClickListener {
if (enableExtras) {
description.setText(userlist.getDescription());
date.setText(StringTools.formatCreationTime(itemView.getResources(), userlist.getTimestamp()));
member.setText(NUM_FORMAT.format(userlist.getMemberCount()));
subscriber.setText(NUM_FORMAT.format(userlist.getSubscriberCount()));
member.setText(StringTools.NUMBER_FORMAT.format(userlist.getMemberCount()));
subscriber.setText(StringTools.NUMBER_FORMAT.format(userlist.getSubscriberCount()));
}
if (owner != null) {
username.setText(owner.getUsername());

View File

@ -311,7 +311,9 @@ public final class AppStyles {
*/
public static void setSeekBarColor(SeekBar seekBar, GlobalSettings settings) {
seekBar.getProgressDrawable().setColorFilter(new PorterDuffColorFilter(settings.getHighlightColor(), SRC_IN));
seekBar.getThumb().setColorFilter(new PorterDuffColorFilter(settings.getIconColor(), SRC_IN));
if (seekBar.getThumb() != null) {
seekBar.getThumb().setColorFilter(new PorterDuffColorFilter(settings.getIconColor(), SRC_IN));
}
}
/**

View File

@ -8,6 +8,7 @@ import org.nuclearfog.twidda.R;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
@ -30,6 +31,11 @@ import javax.crypto.spec.SecretKeySpec;
*/
public final class StringTools {
/**
* global number formatter
*/
public static final NumberFormat NUMBER_FORMAT = NumberFormat.getIntegerInstance();
/**
* regex pattern used to get user mentions
*/

View File

@ -93,7 +93,6 @@ public class GlobalSettings {
private static final String PROXY_IGNORE = "ignore_proxy_set";
private static final String TREND_LOC = "location";
private static final String TREND_ID = "world_id";
private static final String LINK_PREVIEW = "link_preview";
private static final String ENABLE_LIKE = "like_enable";
private static final String ENABLE_TWITTER_ALT = "twitter_alt_set";
private static final String FILTER_RESULTS = "filter_results";
@ -141,7 +140,6 @@ public class GlobalSettings {
private boolean isProxyAuthSet;
private boolean ignoreProxyWarning;
private boolean toolbarOverlap;
private boolean linkPreview;
private boolean tweetIndicators;
private boolean filterResults;
private boolean enableLike;
@ -459,26 +457,6 @@ public class GlobalSettings {
edit.apply();
}
/**
* check if link preview is enabled
*/
public boolean linkPreviewEnabled() {
return linkPreview;
}
/**
* enable/disable link preview
*
* @param enable true enables link preview
*/
public void setLinkPreview(boolean enable) {
linkPreview = enable;
Editor edit = settings.edit();
edit.putBoolean(LINK_PREVIEW, enable);
edit.apply();
}
/**
* check if search filter is enabled
*
@ -956,7 +934,6 @@ public class GlobalSettings {
loadImage = settings.getBoolean(IMAGE_LOAD, true);
tweetIndicators = settings.getBoolean(TWEET_INDICATOR, true);
toolbarOverlap = settings.getBoolean(PROFILE_OVERLAP, true);
linkPreview = settings.getBoolean(LINK_PREVIEW, false);
filterResults = settings.getBoolean(FILTER_RESULTS, true);
enableLike = settings.getBoolean(ENABLE_LIKE, false);
twitterAlt = settings.getBoolean(ENABLE_TWITTER_ALT, false);

View File

@ -60,6 +60,7 @@ import org.nuclearfog.twidda.backend.async.UserAction;
import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.PicassoBuilder;
import org.nuclearfog.twidda.backend.utils.StringTools;
import org.nuclearfog.twidda.database.GlobalSettings;
import org.nuclearfog.twidda.model.Account;
import org.nuclearfog.twidda.model.Relation;
@ -67,7 +68,6 @@ import org.nuclearfog.twidda.model.User;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog;
import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.OnConfirmListener;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.List;
@ -603,21 +603,20 @@ public class ProfileActivity extends AppCompatActivity implements OnClickListene
*/
public void setUser(User user) {
this.user = user;
NumberFormat formatter = NumberFormat.getIntegerInstance();
Spanned bio = Tagger.makeTextWithLinks(user.getDescription(), settings.getHighlightColor(), this);
following.setText(formatter.format(user.getFollowing()));
follower.setText(formatter.format(user.getFollower()));
Spanned bio = Tagger.makeTextWithLinks(user.getDescription(), settings.getHighlightColor(), this);
following.setText(StringTools.NUMBER_FORMAT.format(user.getFollowing()));
follower.setText(StringTools.NUMBER_FORMAT.format(user.getFollower()));
username.setText(user.getUsername());
screenName.setText(user.getScreenname());
if (user.getStatusCount() >= 0) {
tabIndicator[0].setText(formatter.format(user.getStatusCount()));
tabIndicator[0].setText(StringTools.NUMBER_FORMAT.format(user.getStatusCount()));
} else {
tabIndicator[0].setText("");
}
if (tabIndicator.length > 1) {
if (user.getFavoriteCount() >= 0) {
tabIndicator[1].setText(formatter.format(user.getFavoriteCount()));
tabIndicator[1].setText(StringTools.NUMBER_FORMAT.format(user.getFavoriteCount()));
} else {
tabIndicator[1].setText("");
}

View File

@ -132,7 +132,6 @@ public class SettingsActivity extends AppCompatActivity implements OnClickListen
View user_card = findViewById(R.id.settings_data_card);
SwitchButton toggleImg = findViewById(R.id.toggleImg);
SwitchButton toolbarOverlap = findViewById(R.id.settings_toolbar_ov);
SwitchButton enablePreview = findViewById(R.id.settings_enable_prev);
SwitchButton enableLike = findViewById(R.id.enable_like);
SwitchButton enableTwitterAlt = findViewById(R.id.settings_enable_twitter_alt);
View EnableTwitterAltDescr = findViewById(R.id.settings_enable_twitter_alt_descr);
@ -210,7 +209,6 @@ public class SettingsActivity extends AppCompatActivity implements OnClickListen
colorButtons[COLOR_FAVORITE].setText(R.string.settings_color_fav);
}
toggleImg.setCheckedImmediately(settings.imagesEnabled());
enablePreview.setCheckedImmediately(settings.linkPreviewEnabled());
toolbarOverlap.setCheckedImmediately(settings.toolbarOverlapEnabled());
enableLike.setCheckedImmediately(settings.likeEnabled());
enableTwitterAlt.setCheckedImmediately(settings.twitterAltSet());
@ -233,7 +231,6 @@ public class SettingsActivity extends AppCompatActivity implements OnClickListen
enableLike.setOnCheckedChangeListener(this);
enableTwitterAlt.setOnCheckedChangeListener(this);
enableStatusIcons.setOnCheckedChangeListener(this);
enablePreview.setOnCheckedChangeListener(this);
enableProxy.setOnCheckedChangeListener(this);
enableAuth.setOnCheckedChangeListener(this);
toolbarOverlap.setOnCheckedChangeListener(this);
@ -491,10 +488,6 @@ public class SettingsActivity extends AppCompatActivity implements OnClickListen
else if (c.getId() == R.id.enable_status_indicators) {
settings.enableStatusIndicators(checked);
}
// enable link preview
else if (c.getId() == R.id.settings_enable_prev) {
settings.setLinkPreview(checked);
}
// enable proxy settings
else if (c.getId() == R.id.settings_enable_proxy) {
if (checked) {

View File

@ -58,6 +58,7 @@ import org.nuclearfog.twidda.backend.async.StatusAction;
import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
import org.nuclearfog.twidda.backend.utils.PicassoBuilder;
import org.nuclearfog.twidda.backend.utils.StringTools;
import org.nuclearfog.twidda.database.GlobalSettings;
import org.nuclearfog.twidda.model.Card;
import org.nuclearfog.twidda.model.Location;
@ -70,7 +71,6 @@ import org.nuclearfog.twidda.ui.dialogs.ConfirmDialog.OnConfirmListener;
import org.nuclearfog.twidda.ui.dialogs.MetricsDialog;
import org.nuclearfog.twidda.ui.fragments.StatusFragment;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@ -592,15 +592,23 @@ public class StatusActivity extends AppCompatActivity implements OnClickListener
mediaIntent.putExtra(ImageViewer.IMAGE_DOWNLOAD, true);
startActivity(mediaIntent);
} else if (media.getMediaType() == Media.VIDEO) {
Intent mediaIntent = new Intent(this, VideoViewer.class);
mediaIntent.putExtra(VideoViewer.VIDEO_URI, uri);
mediaIntent.putExtra(VideoViewer.ENABLE_VIDEO_CONTROLS, true);
startActivity(mediaIntent);
if (settings.ignoreProxyWarning()) {
Intent mediaIntent = new Intent(this, VideoViewer.class);
mediaIntent.putExtra(VideoViewer.VIDEO_URI, uri);
mediaIntent.putExtra(VideoViewer.ENABLE_VIDEO_CONTROLS, true);
startActivity(mediaIntent);
} else {
confirmDialog.show(ConfirmDialog.PROXY_CONFIRM);
}
} else if (media.getMediaType() == Media.GIF) {
Intent mediaIntent = new Intent(this, VideoViewer.class);
mediaIntent.putExtra(VideoViewer.VIDEO_URI, uri);
mediaIntent.putExtra(VideoViewer.ENABLE_VIDEO_CONTROLS, false);
startActivity(mediaIntent);
if (settings.ignoreProxyWarning()) {
Intent mediaIntent = new Intent(this, VideoViewer.class);
mediaIntent.putExtra(VideoViewer.VIDEO_URI, uri);
mediaIntent.putExtra(VideoViewer.ENABLE_VIDEO_CONTROLS, false);
startActivity(mediaIntent);
} else {
confirmDialog.show(ConfirmDialog.PROXY_CONFIRM);
}
}
}
@ -664,7 +672,6 @@ public class StatusActivity extends AppCompatActivity implements OnClickListener
Location location = status.getLocation();
invalidateOptionsMenu();
NumberFormat buttonNumber = NumberFormat.getIntegerInstance();
if (status.isReposted()) {
AppStyles.setDrawableColor(rtwButton, settings.getRepostIconColor());
} else {
@ -690,9 +697,9 @@ public class StatusActivity extends AppCompatActivity implements OnClickListener
userName.setText(author.getUsername());
screenName.setText(author.getScreenname());
createdAt.setText(SimpleDateFormat.getDateTimeInstance().format(status.getTimestamp()));
ansButton.setText(buttonNumber.format(status.getReplyCount()));
favButton.setText(buttonNumber.format(status.getFavoriteCount()));
rtwButton.setText(buttonNumber.format(status.getRepostCount()));
ansButton.setText(StringTools.NUMBER_FORMAT.format(status.getReplyCount()));
favButton.setText(StringTools.NUMBER_FORMAT.format(status.getFavoriteCount()));
rtwButton.setText(StringTools.NUMBER_FORMAT.format(status.getRepostCount()));
if (!status.getSource().isEmpty()) {
statusApi.setText(R.string.tweet_sent_from);
statusApi.append(status.getSource());

View File

@ -10,10 +10,9 @@ import androidx.annotation.NonNull;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.backend.utils.AppStyles;
import org.nuclearfog.twidda.backend.utils.StringTools;
import org.nuclearfog.twidda.model.Metrics;
import java.text.NumberFormat;
/**
* Status metrics dialog
*
@ -21,8 +20,6 @@ import java.text.NumberFormat;
*/
public class MetricsDialog extends Dialog {
private static final NumberFormat NUM_FORMAT = NumberFormat.getIntegerInstance();
private TextView views, profileClicks, linkClicks, quotes, videoViews;
private View linkIcon, quoteIcon, videoIcon;
@ -54,10 +51,10 @@ public class MetricsDialog extends Dialog {
*/
public void show(Metrics metrics) {
if (!isShowing()) {
views.setText(NUM_FORMAT.format(metrics.getViews()));
profileClicks.setText(NUM_FORMAT.format(metrics.getProfileClicks()));
views.setText(StringTools.NUMBER_FORMAT.format(metrics.getViews()));
profileClicks.setText(StringTools.NUMBER_FORMAT.format(metrics.getProfileClicks()));
if (metrics.getLinkClicks() > 0) {
linkClicks.setText(NUM_FORMAT.format(metrics.getLinkClicks()));
linkClicks.setText(StringTools.NUMBER_FORMAT.format(metrics.getLinkClicks()));
linkClicks.setVisibility(View.VISIBLE);
linkIcon.setVisibility(View.VISIBLE);
} else {
@ -65,7 +62,7 @@ public class MetricsDialog extends Dialog {
linkIcon.setVisibility(View.GONE);
}
if (metrics.getQuoteCount() > 0) {
quotes.setText(NUM_FORMAT.format(metrics.getQuoteCount()));
quotes.setText(StringTools.NUMBER_FORMAT.format(metrics.getQuoteCount()));
quotes.setVisibility(View.VISIBLE);
quoteIcon.setVisibility(View.VISIBLE);
} else {
@ -73,7 +70,7 @@ public class MetricsDialog extends Dialog {
quoteIcon.setVisibility(View.GONE);
}
if (metrics.getVideoViews() > 0) {
videoViews.setText(NUM_FORMAT.format(metrics.getVideoViews()));
videoViews.setText(StringTools.NUMBER_FORMAT.format(metrics.getVideoViews()));
videoViews.setVisibility(View.VISIBLE);
videoIcon.setVisibility(View.VISIBLE);
} else {

View File

@ -1,9 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20dp"
android:height="20dp"
android:viewportWidth="20"
android:viewportHeight="20">
<path
android:pathData="M8.294,16.998c-0.435,0 -0.847,-0.203 -1.111,-0.553L3.61,11.724c-0.465,-0.613 -0.344,-1.486 0.27,-1.951c0.615,-0.467 1.488,-0.344 1.953,0.27l2.351,3.104l5.911,-9.492c0.407,-0.652 1.267,-0.852 1.921,-0.445c0.653,0.406 0.854,1.266 0.446,1.92L9.478,16.34c-0.242,0.391 -0.661,0.635 -1.12,0.656C8.336,16.998 8.316,16.998 8.294,16.998z"
android:fillColor="#FFFFFF"/>
android:width="20dp"
android:height="20dp"
android:viewportWidth="20"
android:viewportHeight="20">
<path
android:pathData="M8.294,16.998c-0.435,0 -0.847,-0.203 -1.111,-0.553L3.61,11.724c-0.465,-0.613 -0.344,-1.486 0.27,-1.951c0.615,-0.467 1.488,-0.344 1.953,0.27l2.351,3.104l5.911,-9.492c0.407,-0.652 1.267,-0.852 1.921,-0.445c0.653,0.406 0.854,1.266 0.446,1.92L9.478,16.34c-0.242,0.391 -0.661,0.635 -1.12,0.656C8.336,16.998 8.316,16.998 8.294,16.998z"
android:fillColor="#FFFFFF" />
</vector>

View File

@ -1,9 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20dp"
android:height="20dp"
android:viewportWidth="20"
android:viewportHeight="20">
<path
android:pathData="M10,0.4c-5.302,0 -9.6,4.298 -9.6,9.6s4.298,9.6 9.6,9.6c5.301,0 9.6,-4.298 9.6,-9.601C19.6,4.698 15.301,0.4 10,0.4zM10,17.599c-4.197,0 -7.6,-3.402 -7.6,-7.6S5.802,2.4 10,2.4c4.197,0 7.601,3.402 7.601,7.6S14.197,17.599 10,17.599z"
android:fillColor="#FFFFFF"/>
android:width="20dp"
android:height="20dp"
android:viewportWidth="20"
android:viewportHeight="20">
<path
android:pathData="M10,0.4c-5.302,0 -9.6,4.298 -9.6,9.6s4.298,9.6 9.6,9.6c5.301,0 9.6,-4.298 9.6,-9.601C19.6,4.698 15.301,0.4 10,0.4zM10,17.599c-4.197,0 -7.6,-3.402 -7.6,-7.6S5.802,2.4 10,2.4c4.197,0 7.601,3.402 7.601,7.6S14.197,17.599 10,17.599z"
android:fillColor="#FFFFFF" />
</vector>

View File

@ -12,14 +12,15 @@
android:layout_weight="1"
android:textSize="@dimen/item_option_text_size"
android:lines="1"
android:layout_margin="@dimen/item_option_layout_margin"/>
android:layout_margin="@dimen/item_option_layout_margin" />
<SeekBar
android:id="@+id/item_option_count_bar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:layout_margin="@dimen/item_option_layout_margin"/>
android:layout_margin="@dimen/item_option_layout_margin"
android:thumb="@null" />
<TextView
android:id="@+id/item_option_count_text"
@ -29,13 +30,14 @@
android:gravity="end"
android:textSize="@dimen/item_option_text_size"
android:lines="1"
android:layout_margin="@dimen/item_option_layout_margin"/>
android:layout_margin="@dimen/item_option_layout_margin" />
<ImageView
android:id="@+id/item_option_voted_icon"
android:layout_width="@dimen/item_option_icon_size"
android:layout_height="@dimen/item_option_icon_size"
android:src="@drawable/check"
android:layout_margin="@dimen/item_option_layout_margin"/>
android:layout_margin="@dimen/item_option_layout_margin"
android:contentDescription="@string/description_poll_vote_icon" />
</LinearLayout>

View File

@ -1,10 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
style="@style/CardViewStyle">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -15,7 +14,7 @@
android:id="@+id/item_poll_options_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
@ -25,7 +24,7 @@
<TextView
android:id="@+id/item_poll_votes_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content" />
<!--todo add vote button here-->

View File

@ -341,7 +341,7 @@
android:layout_marginEnd="@dimen/settings_switch_margin"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/settings_data_text"
app:layout_constraintBottom_toTopOf="@id/settings_enable_prev"
app:layout_constraintBottom_toTopOf="@id/settings_enable_twitter_alt"
app:layout_constraintEnd_toStartOf="@id/toggleImg_descr" />
<TextView
@ -357,29 +357,6 @@
app:layout_constraintBottom_toBottomOf="@id/toggleImg"
app:layout_constraintEnd_toEndOf="parent" />
<com.kyleduo.switchbutton.SwitchButton
android:id="@+id/settings_enable_prev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/settings_column_margin"
android:layout_marginEnd="@dimen/settings_switch_margin"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toggleImg"
app:layout_constraintBottom_toTopOf="@id/settings_enable_twitter_alt"
app:layout_constraintEnd_toStartOf="@id/settings_enable_prev_descr" />
<TextView
android:id="@+id/settings_enable_prev_descr"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/settings_toggle_media_preview"
android:textSize="@dimen/settings_textsize_small"
app:layout_constraintStart_toEndOf="@id/settings_enable_prev"
app:layout_constraintTop_toTopOf="@id/settings_enable_prev"
app:layout_constraintBottom_toBottomOf="@id/settings_enable_prev"
app:layout_constraintEnd_toEndOf="parent" />
<com.kyleduo.switchbutton.SwitchButton
android:id="@+id/settings_enable_twitter_alt"
android:layout_width="wrap_content"
@ -387,7 +364,7 @@
android:layout_marginBottom="@dimen/settings_column_margin"
android:layout_marginEnd="@dimen/settings_switch_margin"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/settings_enable_prev"
app:layout_constraintTop_toBottomOf="@id/toggleImg"
app:layout_constraintBottom_toTopOf="@id/settings_list_seek"
app:layout_constraintEnd_toStartOf="@id/settings_enable_twitter_alt_descr" />

View File

@ -105,7 +105,7 @@
<string name="confirm_delete_list">Liste löschen?</string>
<string name="confirm_delete_message">Nachricht löschen?</string>
<string name="confirm_unfollow_list">Liste entfolgen?</string>
<string name="trend_range">Posts</string>
<string name="trend_range">\u0020Posts</string>
<string name="error_connection_failed">Verbindung fehlgeschlagen!</string>
<string name="enter_username">Nutzernamen eingeben</string>
<string name="profile_banner">Profilbanner</string>
@ -179,7 +179,6 @@
<string name="button_share">Videolink teilen</string>
<string name="settings_look">Aussehen</string>
<string name="dialog_link_image_preview">Linkvorschau Bild</string>
<string name="settings_toggle_media_preview">Medienvorschau aktivieren</string>
<string name="confirm_remove_account">Account aus der Liste entfernen?</string>
<string name="menu_select_account">Logins</string>
<string name="menu_add_account">Account hinzufügen</string>
@ -250,4 +249,5 @@
<string name="error_empty_text">Text ist leer!</string>
<string name="error_api_access_limited">Fehler! API Zugang wurde von Twitter beschränkt.</string>
<string name="poll_total_votes">"Gesamtstimmen:\u0020"</string>
<string name="description_poll_vote_icon">abgestimmt</string>
</resources>

View File

@ -32,15 +32,11 @@
<dimen name="page_status_button_margin">5dp</dimen>
<dimen name="page_status_button_padding">5sp</dimen>
<dimen name="page_status_button_height">20sp</dimen>
<dimen name="page_status_button_media_width">58sp</dimen>
<dimen name="page_status_button_media_height">36sp</dimen>
<dimen name="page_status_padding_drawable">5dp</dimen>
<dimen name="page_status_textsize_small">12sp</dimen>
<dimen name="page_status_textsize">18sp</dimen>
<dimen name="page_status_textsize_locale">12sp</dimen>
<dimen name="page_status_button_drawable_padding">5dp</dimen>
<dimen name="page_status_cards_list_margin">5dp</dimen>
<dimen name="page_status_cards_list_height">100sp</dimen>
<integer name="page_status_text_max_lines">5</integer>
<!--dimens of page_profile.xml-->

View File

@ -233,14 +233,13 @@
<string name="confirm_delete_list">delete userlist?</string>
<string name="confirm_delete_message">delete message?</string>
<string name="confirm_unfollow_list">unfollow list?</string>
<string name="trend_range">Posts</string>
<string name="trend_range">\u0020Posts</string>
<string name="enter_username">enter username</string>
<string name="profile_banner">Banner Image</string>
<string name="editprofile_add_banner">add banner</string>
<string name="settings_app_information">App source code:</string>
<string name="settings_enable_toolbar_overlap">Collapsed profile layout</string>
<string name="settings_look">Look</string>
<string name="settings_toggle_media_preview">enable media preview</string>
<string name="settings_description_enable_twitter_alt">use nitter.net for links</string>
<string name="item_load_more">load more</string>
<string name="item_image_save">save image</string>
@ -287,5 +286,6 @@
<string name="status_media_preview">Media preview</string>
<string name="status_media_preview_button">Video preview button</string>
<string name="poll_total_votes">Total votes:\u0020</string>
<string name="description_poll_vote_icon">voted</string>
</resources>