convert entity classes to Kotlin data classes (#526)
* convert entity classes to Kotlin data classes * more data classes, code style
This commit is contained in:
parent
bbbe71174a
commit
71954a277e
51 changed files with 604 additions and 785 deletions
|
|
@ -77,7 +77,7 @@ public abstract class AccountAdapter extends RecyclerView.Adapter {
|
|||
}
|
||||
int end = accountList.size();
|
||||
Account last = accountList.get(end - 1);
|
||||
if (last != null && !findAccount(newAccounts, last.id)) {
|
||||
if (last != null && !findAccount(newAccounts, last.getId())) {
|
||||
accountList.addAll(newAccounts);
|
||||
notifyItemRangeInserted(end, newAccounts.size());
|
||||
}
|
||||
|
|
@ -85,7 +85,7 @@ public abstract class AccountAdapter extends RecyclerView.Adapter {
|
|||
|
||||
private static boolean findAccount(List<Account> accounts, String id) {
|
||||
for (Account account : accounts) {
|
||||
if (account.id.equals(id)) {
|
||||
if (account.getId().equals(id)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,14 +28,14 @@ class AccountViewHolder extends RecyclerView.ViewHolder {
|
|||
}
|
||||
|
||||
void setupWithAccount(Account account) {
|
||||
accountId = account.id;
|
||||
accountId = account.getId();
|
||||
String format = username.getContext().getString(R.string.status_username_format);
|
||||
String formattedUsername = String.format(format, account.username);
|
||||
String formattedUsername = String.format(format, account.getUsername());
|
||||
username.setText(formattedUsername);
|
||||
displayName.setText(account.getDisplayName());
|
||||
displayName.setText(account.getName());
|
||||
Context context = avatar.getContext();
|
||||
Picasso.with(context)
|
||||
.load(account.avatar)
|
||||
.load(account.getAvatar())
|
||||
.placeholder(R.drawable.avatar_default)
|
||||
.into(avatar);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,13 +90,13 @@ public class BlocksAdapter extends AccountAdapter {
|
|||
}
|
||||
|
||||
void setupWithAccount(Account account) {
|
||||
id = account.id;
|
||||
displayName.setText(account.getDisplayName());
|
||||
id = account.getId();
|
||||
displayName.setText(account.getName());
|
||||
String format = username.getContext().getString(R.string.status_username_format);
|
||||
String formattedUsername = String.format(format, account.username);
|
||||
String formattedUsername = String.format(format, account.getUsername());
|
||||
username.setText(formattedUsername);
|
||||
Picasso.with(avatar.getContext())
|
||||
.load(account.avatar)
|
||||
.load(account.getAvatar())
|
||||
.placeholder(R.drawable.avatar_default)
|
||||
.into(avatar);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,13 +92,13 @@ public class FollowRequestsAdapter extends AccountAdapter {
|
|||
}
|
||||
|
||||
void setupWithAccount(Account account) {
|
||||
id = account.id;
|
||||
displayName.setText(account.getDisplayName());
|
||||
id = account.getId();
|
||||
displayName.setText(account.getName());
|
||||
String format = username.getContext().getString(R.string.status_username_format);
|
||||
String formattedUsername = String.format(format, account.username);
|
||||
String formattedUsername = String.format(format, account.getUsername());
|
||||
username.setText(formattedUsername);
|
||||
Picasso.with(avatar.getContext())
|
||||
.load(account.avatar)
|
||||
.load(account.getAvatar())
|
||||
.placeholder(R.drawable.avatar_default)
|
||||
.into(avatar);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public class MentionAutoCompleteAdapter extends ArrayAdapter<Account>
|
|||
return new Filter() {
|
||||
@Override
|
||||
public CharSequence convertResultToString(Object resultValue) {
|
||||
return ((Account) resultValue).username;
|
||||
return ((Account) resultValue).getUsername();
|
||||
}
|
||||
|
||||
// This method is invoked in a worker thread.
|
||||
|
|
@ -122,12 +122,12 @@ public class MentionAutoCompleteAdapter extends ArrayAdapter<Account>
|
|||
TextView displayName = view.findViewById(R.id.display_name);
|
||||
ImageView avatar = view.findViewById(R.id.avatar);
|
||||
String format = getContext().getString(R.string.status_username_format);
|
||||
String formattedUsername = String.format(format, account.username);
|
||||
String formattedUsername = String.format(format, account.getUsername());
|
||||
username.setText(formattedUsername);
|
||||
displayName.setText(account.getDisplayName());
|
||||
if (!account.avatar.isEmpty()) {
|
||||
displayName.setText(account.getName());
|
||||
if (!account.getAvatar().isEmpty()) {
|
||||
Picasso.with(context)
|
||||
.load(account.avatar)
|
||||
.load(account.getAvatar())
|
||||
.placeholder(R.drawable.avatar_default)
|
||||
.transform(new RoundedTransformation(7, 0))
|
||||
.into(avatar);
|
||||
|
|
|
|||
|
|
@ -75,13 +75,13 @@ public class MutesAdapter extends AccountAdapter {
|
|||
}
|
||||
|
||||
void setupWithAccount(Account account) {
|
||||
id = account.id;
|
||||
displayName.setText(account.getDisplayName());
|
||||
id = account.getId();
|
||||
displayName.setText(account.getName());
|
||||
String format = username.getContext().getString(R.string.status_username_format);
|
||||
String formattedUsername = String.format(format, account.username);
|
||||
String formattedUsername = String.format(format, account.getUsername());
|
||||
username.setText(formattedUsername);
|
||||
Picasso.with(avatar.getContext())
|
||||
.load(account.avatar)
|
||||
.load(account.getAvatar())
|
||||
.placeholder(R.drawable.avatar_default)
|
||||
.into(avatar);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,21 +143,20 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
|
|||
holder.setCreatedAt(statusViewData.getCreatedAt());
|
||||
|
||||
holder.setAvatars(concreteNotificaton.getStatusViewData().getAvatar(),
|
||||
concreteNotificaton.getAccount().avatar);
|
||||
concreteNotificaton.getAccount().getAvatar());
|
||||
}
|
||||
|
||||
holder.setMessage(concreteNotificaton, statusListener);
|
||||
holder.setupButtons(notificationActionListener,
|
||||
concreteNotificaton.getAccount().id,
|
||||
concreteNotificaton.getAccount().getId(),
|
||||
concreteNotificaton.getId());
|
||||
|
||||
break;
|
||||
}
|
||||
case FOLLOW: {
|
||||
FollowViewHolder holder = (FollowViewHolder) viewHolder;
|
||||
holder.setMessage(concreteNotificaton.getAccount().getDisplayName(),
|
||||
concreteNotificaton.getAccount().username, concreteNotificaton.getAccount().avatar);
|
||||
holder.setupButtons(notificationActionListener, concreteNotificaton.getAccount().id);
|
||||
holder.setMessage(concreteNotificaton.getAccount().getName(),
|
||||
concreteNotificaton.getAccount().getUsername(), concreteNotificaton.getAccount().getAvatar());
|
||||
holder.setupButtons(notificationActionListener, concreteNotificaton.getAccount().getId());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -380,7 +379,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
|
|||
void setMessage(NotificationViewData.Concrete notificationViewData, LinkListener listener) {
|
||||
this.statusViewData = notificationViewData.getStatusViewData();
|
||||
|
||||
String displayName = notificationViewData.getAccount().getDisplayName();
|
||||
String displayName = notificationViewData.getAccount().getName();
|
||||
Notification.Type type = notificationViewData.getType();
|
||||
|
||||
Context context = message.getContext();
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ import com.keylesspalace.tusky.entity.SearchResults;
|
|||
import com.keylesspalace.tusky.interfaces.LinkListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class SearchResultsAdapter extends RecyclerView.Adapter {
|
||||
|
|
@ -91,12 +90,9 @@ public class SearchResultsAdapter extends RecyclerView.Adapter {
|
|||
|
||||
public void updateSearchResults(SearchResults results) {
|
||||
if (results != null) {
|
||||
if (results.accounts != null) {
|
||||
accountList.addAll(Arrays.asList(results.accounts));
|
||||
}
|
||||
if (results.hashtags != null) {
|
||||
hashtagList.addAll(Arrays.asList(results.hashtags));
|
||||
}
|
||||
accountList.addAll(results.getAccounts());
|
||||
hashtagList.addAll(results.getHashtags());
|
||||
|
||||
} else {
|
||||
accountList.clear();
|
||||
hashtagList.clear();
|
||||
|
|
|
|||
|
|
@ -219,12 +219,12 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
|
||||
final String[] urls = new String[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
urls[i] = attachments[i].url;
|
||||
urls[i] = attachments[i].getUrl();
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
String previewUrl = attachments[i].previewUrl;
|
||||
String description = attachments[i].description;
|
||||
String previewUrl = attachments[i].getPreviewUrl();
|
||||
String description = attachments[i].getDescription();
|
||||
|
||||
if(TextUtils.isEmpty(description)) {
|
||||
previews[i].setContentDescription(context.getString(R.string.action_view_media));
|
||||
|
|
@ -243,7 +243,7 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
.into(previews[i]);
|
||||
}
|
||||
|
||||
final Attachment.Type type = attachments[i].type;
|
||||
final Attachment.Type type = attachments[i].getType();
|
||||
if (type == Attachment.Type.VIDEO | type == Attachment.Type.GIFV) {
|
||||
overlays[i].setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
|
|
@ -351,7 +351,7 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
|
||||
// Set the label's text.
|
||||
Context context = itemView.getContext();
|
||||
String labelText = getLabelTypeText(context, attachments[0].type);
|
||||
String labelText = getLabelTypeText(context, attachments[0].getType());
|
||||
if (sensitive) {
|
||||
String sensitiveText = context.getString(R.string.status_sensitive_media_title);
|
||||
labelText += String.format(" (%s)", sensitiveText);
|
||||
|
|
@ -359,7 +359,7 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
mediaLabel.setText(labelText);
|
||||
|
||||
// Set the icon next to the label.
|
||||
int drawableId = getLabelIcon(attachments[0].type);
|
||||
int drawableId = getLabelIcon(attachments[0].getType());
|
||||
Drawable drawable = AppCompatResources.getDrawable(context, drawableId);
|
||||
ThemeUtils.setDrawableTint(context, drawable, android.R.attr.textColorTertiary);
|
||||
mediaLabel.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
|
||||
|
|
@ -368,9 +368,9 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
|
|||
int n = Math.min(attachments.length, Status.MAX_MEDIA_ATTACHMENTS);
|
||||
final String[] urls = new String[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
urls[i] = attachments[i].url;
|
||||
urls[i] = attachments[i].getUrl();
|
||||
}
|
||||
final Attachment.Type type = attachments[0].type;
|
||||
final Attachment.Type type = attachments[0].getType();
|
||||
mediaLabel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import com.keylesspalace.tusky.viewdata.StatusViewData;
|
|||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Date;
|
||||
|
||||
class StatusDetailedViewHolder extends StatusBaseViewHolder {
|
||||
|
|
@ -68,15 +69,15 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder {
|
|||
|
||||
timestampInfo.append(" • ");
|
||||
|
||||
if (app.website != null) {
|
||||
URLSpan span = new CustomURLSpan(app.website);
|
||||
if (app.getWebsite() != null) {
|
||||
URLSpan span = new CustomURLSpan(app.getWebsite());
|
||||
|
||||
SpannableStringBuilder text = new SpannableStringBuilder(app.name);
|
||||
text.setSpan(span, 0, app.name.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
SpannableStringBuilder text = new SpannableStringBuilder(app.getName());
|
||||
text.setSpan(span, 0, app.getName().length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
timestampInfo.append(text);
|
||||
timestampInfo.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
} else {
|
||||
timestampInfo.append(app.name);
|
||||
timestampInfo.append(app.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -85,22 +86,25 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder {
|
|||
void setupWithStatus(final StatusViewData.Concrete status, final StatusActionListener listener,
|
||||
boolean mediaPreviewEnabled) {
|
||||
super.setupWithStatus(status, listener, mediaPreviewEnabled);
|
||||
reblogs.setText(status.getReblogsCount());
|
||||
favourites.setText(status.getFavouritesCount());
|
||||
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance();
|
||||
|
||||
reblogs.setText(numberFormat.format(status.getReblogsCount()));
|
||||
favourites.setText(numberFormat.format(status.getFavouritesCount()));
|
||||
setApplication(status.getApplication());
|
||||
|
||||
if(status.getAttachments().length == 0 && status.getCard() != null && !TextUtils.isEmpty(status.getCard().url)) {
|
||||
if(status.getAttachments().length == 0 && status.getCard() != null && !TextUtils.isEmpty(status.getCard().getUrl())) {
|
||||
final Card card = status.getCard();
|
||||
cardView.setVisibility(View.VISIBLE);
|
||||
cardTitle.setText(card.title);
|
||||
cardDescription.setText(card.description);
|
||||
cardTitle.setText(card.getTitle());
|
||||
cardDescription.setText(card.getDescription());
|
||||
|
||||
cardUrl.setText(card.url);
|
||||
cardUrl.setText(card.getUrl());
|
||||
|
||||
if(card.width > 0 && card.height > 0 && !TextUtils.isEmpty(card.image)) {
|
||||
if(card.getWidth() > 0 && card.getHeight() > 0 && !TextUtils.isEmpty(card.getImage())) {
|
||||
cardImage.setVisibility(View.VISIBLE);
|
||||
|
||||
if(card.width > card.height) {
|
||||
if(card.getWidth() > card.getHeight()) {
|
||||
cardView.setOrientation(LinearLayout.VERTICAL);
|
||||
cardImage.getLayoutParams().height = cardImage.getContext().getResources()
|
||||
.getDimensionPixelSize(R.dimen.card_image_vertical_height);
|
||||
|
|
@ -121,7 +125,7 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder {
|
|||
}
|
||||
|
||||
Picasso.with(cardImage.getContext())
|
||||
.load(card.image)
|
||||
.load(card.getImage())
|
||||
.fit()
|
||||
.centerCrop()
|
||||
.into(cardImage);
|
||||
|
|
@ -134,7 +138,7 @@ class StatusDetailedViewHolder extends StatusBaseViewHolder {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
LinkHelper.openLink(card.url, v.getContext());
|
||||
LinkHelper.openLink(card.getUrl(), v.getContext());
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue