convert entity classes to Kotlin data classes (#526)

* convert entity classes to Kotlin data classes

* more data classes, code style
main
Konrad Pozniak 6 years ago committed by GitHub
parent 5998f3b375
commit 5de7b21007
  1. 3
      app/build.gradle
  2. 2
      app/src/main/java/com/keylesspalace/tusky/AboutActivity.java
  3. 47
      app/src/main/java/com/keylesspalace/tusky/AccountActivity.java
  4. 10
      app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java
  5. 5
      app/src/main/java/com/keylesspalace/tusky/MainActivity.java
  6. 2
      app/src/main/java/com/keylesspalace/tusky/NotificationPullJobCreator.java
  7. 4
      app/src/main/java/com/keylesspalace/tusky/ReportActivity.java
  8. 2
      app/src/main/java/com/keylesspalace/tusky/SearchActivity.java
  9. 4
      app/src/main/java/com/keylesspalace/tusky/adapter/AccountAdapter.java
  10. 8
      app/src/main/java/com/keylesspalace/tusky/adapter/AccountViewHolder.java
  11. 8
      app/src/main/java/com/keylesspalace/tusky/adapter/BlocksAdapter.java
  12. 8
      app/src/main/java/com/keylesspalace/tusky/adapter/FollowRequestsAdapter.java
  13. 10
      app/src/main/java/com/keylesspalace/tusky/adapter/MentionAutoCompleteAdapter.java
  14. 8
      app/src/main/java/com/keylesspalace/tusky/adapter/MutesAdapter.java
  15. 13
      app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java
  16. 10
      app/src/main/java/com/keylesspalace/tusky/adapter/SearchResultsAdapter.java
  17. 16
      app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java
  18. 34
      app/src/main/java/com/keylesspalace/tusky/adapter/StatusDetailedViewHolder.java
  19. 2
      app/src/main/java/com/keylesspalace/tusky/db/AccountManager.kt
  20. 11
      app/src/main/java/com/keylesspalace/tusky/entity/AccessToken.kt
  21. 130
      app/src/main/java/com/keylesspalace/tusky/entity/Account.java
  22. 69
      app/src/main/java/com/keylesspalace/tusky/entity/Account.kt
  23. 15
      app/src/main/java/com/keylesspalace/tusky/entity/AppCredentials.kt
  24. 79
      app/src/main/java/com/keylesspalace/tusky/entity/Attachment.java
  25. 57
      app/src/main/java/com/keylesspalace/tusky/entity/Attachment.kt
  26. 92
      app/src/main/java/com/keylesspalace/tusky/entity/Card.java
  27. 43
      app/src/main/java/com/keylesspalace/tusky/entity/Card.kt
  28. 41
      app/src/main/java/com/keylesspalace/tusky/entity/Notification.kt
  29. 11
      app/src/main/java/com/keylesspalace/tusky/entity/Profile.kt
  30. 27
      app/src/main/java/com/keylesspalace/tusky/entity/Relationship.kt
  31. 13
      app/src/main/java/com/keylesspalace/tusky/entity/SearchResults.kt
  32. 189
      app/src/main/java/com/keylesspalace/tusky/entity/Status.java
  33. 142
      app/src/main/java/com/keylesspalace/tusky/entity/Status.kt
  34. 11
      app/src/main/java/com/keylesspalace/tusky/entity/StatusContext.kt
  35. 3
      app/src/main/java/com/keylesspalace/tusky/fragment/AccountMediaFragment.kt
  36. 38
      app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java
  37. 28
      app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.java
  38. 30
      app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java
  39. 22
      app/src/main/java/com/keylesspalace/tusky/fragment/ViewThreadFragment.java
  40. 6
      app/src/main/java/com/keylesspalace/tusky/util/LinkHelper.java
  41. 28
      app/src/main/java/com/keylesspalace/tusky/util/NotificationHelper.java
  42. 50
      app/src/main/java/com/keylesspalace/tusky/util/ViewDataUtils.java
  43. 18
      app/src/main/java/com/keylesspalace/tusky/viewdata/StatusViewData.java
  44. 6
      app/src/main/res/values-ar/strings.xml
  45. 6
      app/src/main/res/values-ca/strings.xml
  46. 6
      app/src/main/res/values-de/strings.xml
  47. 6
      app/src/main/res/values-fr/strings.xml
  48. 6
      app/src/main/res/values-pl/strings.xml
  49. 6
      app/src/main/res/values-pt-rBR/strings.xml
  50. 6
      app/src/main/res/values-ru/strings.xml
  51. 6
      app/src/main/res/values/strings.xml

@ -33,6 +33,9 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
androidExtensions {
experimental = true
}
}
ext.supportLibraryVersion = '27.0.2'

@ -72,7 +72,7 @@ public class AboutActivity extends BaseActivity {
if (response.isSuccessful()) {
List<Account> accountList = response.body();
if (!accountList.isEmpty()) {
String id = accountList.get(0).id;
String id = accountList.get(0).getId();
getPrivatePreferences().edit()
.putString("appAccountId", id)
.apply();

@ -58,6 +58,7 @@ import com.keylesspalace.tusky.util.ThemeUtils;
import com.pkmmte.view.CircularImageView;
import com.squareup.picasso.Picasso;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -285,20 +286,20 @@ public final class AccountActivity extends BaseActivity implements ActionButtonA
TextView note = findViewById(R.id.account_note);
String usernameFormatted = String.format(
getString(R.string.status_username_format), account.username);
getString(R.string.status_username_format), account.getUsername());
username.setText(usernameFormatted);
displayName.setText(account.getDisplayName());
displayName.setText(account.getName());
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(account.getDisplayName());
getSupportActionBar().setTitle(account.getName());
String subtitle = String.format(getString(R.string.status_username_format),
account.username);
account.getUsername());
getSupportActionBar().setSubtitle(subtitle);
}
LinkHelper.setClickableText(note, account.note, null, new LinkListener() {
LinkHelper.setClickableText(note, account.getNote(), null, new LinkListener() {
@Override
public void onViewTag(String tag) {
Intent intent = new Intent(AccountActivity.this, ViewTagActivity.class);
@ -314,24 +315,26 @@ public final class AccountActivity extends BaseActivity implements ActionButtonA
}
});
if (account.locked) {
if (account.getLocked()) {
accountLockedView.setVisibility(View.VISIBLE);
} else {
accountLockedView.setVisibility(View.GONE);
}
Picasso.with(this)
.load(account.avatar)
.load(account.getAvatar())
.placeholder(R.drawable.avatar_default)
.into(avatar);
Picasso.with(this)
.load(account.header)
.load(account.getHeader())
.placeholder(R.drawable.account_header_default)
.into(header);
long followersCount = Long.parseLong(account.followersCount);
long followingCount = Long.parseLong(account.followingCount);
long statusesCount = Long.parseLong(account.statusesCount);
NumberFormat numberFormat = NumberFormat.getNumberInstance();
String followersCount = numberFormat.format(account.getFollowersCount());
String followingCount = numberFormat.format(account.getFollowingCount());
String statusesCount = numberFormat.format(account.getStatusesCount());
followersTextView.setText(getString(R.string.title_x_followers, followersCount));
followingTextView.setText(getString(R.string.title_x_following, followingCount));
statusesTextView.setText(getString(R.string.title_x_statuses, statusesCount));
@ -368,17 +371,17 @@ public final class AccountActivity extends BaseActivity implements ActionButtonA
}
private void onObtainRelationshipsSuccess(Relationship relation) {
if (relation.following) {
if (relation.getFollowing()) {
followState = FollowState.FOLLOWING;
} else if (relation.requested) {
} else if (relation.getRequested()) {
followState = FollowState.REQUESTED;
} else {
followState = FollowState.NOT_FOLLOWING;
}
this.blocking = relation.blocking;
this.muting = relation.muting;
this.blocking = relation.getBlocking();
this.muting = relation.getMuting();
if (relation.followedBy) {
if (relation.getFollowedBy()) {
followsYouView.setVisibility(View.VISIBLE);
} else {
followsYouView.setVisibility(View.GONE);
@ -497,9 +500,9 @@ public final class AccountActivity extends BaseActivity implements ActionButtonA
@NonNull Response<Relationship> response) {
Relationship relationship = response.body();
if (response.isSuccessful() && relationship != null) {
if (relationship.following) {
if (relationship.getFollowing()) {
followState = FollowState.FOLLOWING;
} else if (relationship.requested) {
} else if (relationship.getRequested()) {
followState = FollowState.REQUESTED;
Snackbar.make(container, R.string.state_follow_requested,
Snackbar.LENGTH_LONG).show();
@ -563,7 +566,7 @@ public final class AccountActivity extends BaseActivity implements ActionButtonA
Relationship relationship = response.body();
if (response.isSuccessful() && relationship != null) {
broadcast(TimelineReceiver.Types.BLOCK_ACCOUNT, id);
blocking = relationship.blocking;
blocking = relationship.getBlocking();
updateButtons();
} else {
onBlockFailure(id);
@ -597,7 +600,7 @@ public final class AccountActivity extends BaseActivity implements ActionButtonA
Relationship relationship = response.body();
if (response.isSuccessful() && relationship != null) {
broadcast(TimelineReceiver.Types.MUTE_ACCOUNT, id);
muting = relationship.muting;
muting = relationship.getMuting();
updateButtons();
} else {
onMuteFailure(id);
@ -630,7 +633,7 @@ public final class AccountActivity extends BaseActivity implements ActionButtonA
return false;
}
Intent intent = new ComposeActivity.IntentBuilder()
.mentionedUsernames(Collections.singleton(loadedAccount.username))
.mentionedUsernames(Collections.singleton(loadedAccount.getUsername()))
.build(this);
startActivity(intent);
return true;
@ -657,7 +660,7 @@ public final class AccountActivity extends BaseActivity implements ActionButtonA
// If the account isn't loaded yet, eat the input.
return false;
}
LinkHelper.openLink(loadedAccount.url, this);
LinkHelper.openLink(loadedAccount.getUrl(), this);
return true;
}
case R.id.action_follow: {

@ -1259,7 +1259,7 @@ public final class ComposeActivity extends BaseActivity
public void onResponse(@NonNull Call<Attachment> call, @NonNull Response<Attachment> response) {
Attachment attachment = response.body();
if (response.isSuccessful() && attachment != null) {
item.description = attachment.description;
item.description = attachment.getDescription();
dialog.dismiss();
} else {
showFailedCaptionMessage();
@ -1412,17 +1412,17 @@ public final class ComposeActivity extends BaseActivity
}
private void onUploadSuccess(final QueuedMedia item, Attachment media) {
item.id = media.id;
item.id = media.getId();
item.preview.setProgress(-1);
item.readyStage = QueuedMedia.ReadyStage.UPLOADED;
/* Add the upload URL to the text field. Also, keep a reference to the span so if the user
* chooses to remove the media, the URL is also automatically removed. */
item.uploadUrl = new URLSpan(media.textUrl);
int end = 1 + media.textUrl.length();
item.uploadUrl = new URLSpan(media.getTextUrl());
int end = 1 + media.getTextUrl().length();
SpannableStringBuilder builder = new SpannableStringBuilder();
builder.append(' ');
builder.append(media.textUrl);
builder.append(media.getTextUrl());
builder.setSpan(item.uploadUrl, 1, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
int cursorStart = textEditor.getSelectionStart();
int cursorEnd = textEditor.getSelectionEnd();

@ -488,7 +488,7 @@ public class MainActivity extends BaseActivity implements ActionButtonActivity {
ImageView background = headerResult.getHeaderBackgroundView();
Picasso.with(MainActivity.this)
.load(me.header)
.load(me.getHeader())
.placeholder(R.drawable.account_header_default)
.into(background);
@ -499,7 +499,7 @@ public class MainActivity extends BaseActivity implements ActionButtonActivity {
NotificationHelper.createNotificationChannelsForAccount(am.getActiveAccount(), this);
// Show follow requests in the menu, if this is a locked account.
if (me.locked && drawer.getDrawerItem(DRAWER_ITEM_FOLLOW_REQUESTS) == null) {
if (me.getLocked() && drawer.getDrawerItem(DRAWER_ITEM_FOLLOW_REQUESTS) == null) {
PrimaryDrawerItem followRequestsItem = new PrimaryDrawerItem()
.withIdentifier(DRAWER_ITEM_FOLLOW_REQUESTS)
.withName(R.string.action_view_follow_requests)
@ -533,6 +533,7 @@ public class MainActivity extends BaseActivity implements ActionButtonActivity {
.withNameShown(true)
.withIdentifier(acc.getId())
.withEmail(acc.getFullName()));
}
}

@ -138,7 +138,7 @@ public final class NotificationPullJobCreator implements JobCreator {
for(Notification notification: notificationList){
BigInteger currentId = new BigInteger(notification.id);
BigInteger currentId = new BigInteger(notification.getId());
if(isBiggerThan(currentId, newestId)) {
newestId = currentId;

@ -168,9 +168,9 @@ public class ReportActivity extends BaseActivity {
List<Status> statusList = response.body();
List<ReportAdapter.ReportStatus> itemList = new ArrayList<>();
for (Status status : statusList) {
if (status.reblog == null) {
if (status.getReblog() == null) {
ReportAdapter.ReportStatus item = new ReportAdapter.ReportStatus(
status.id, status.content, false);
status.getId(), status.getContent(), false);
itemList.add(item);
}
}

@ -163,7 +163,7 @@ public class SearchActivity extends BaseActivity implements SearchView.OnQueryTe
public void onResponse(@NonNull Call<SearchResults> call, @NonNull Response<SearchResults> response) {
if (response.isSuccessful()) {
SearchResults results = response.body();
if (results.accounts != null && results.accounts.length > 0 || results.hashtags != null && results.hashtags.length > 0) {
if (results != null && (results.getAccounts().size() > 0 || results.getHashtags().size() > 0)) {
adapter.updateSearchResults(results);
hideFeedback();
} else {

@ -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());
}

@ -109,7 +109,7 @@ class AccountManager {
activeAccount?.let{
it.accountId = account.id
it.username = account.username
it.displayName = account.getDisplayName()
it.displayName = account.name
it.profilePictureUrl = account.avatar
Log.d(TAG, "updateActiveAccount: saving account with id "+it.id)

@ -13,11 +13,10 @@
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky.entity;
package com.keylesspalace.tusky.entity
import com.google.gson.annotations.SerializedName;
import com.google.gson.annotations.SerializedName
public class AccessToken {
@SerializedName("access_token")
public String accessToken;
}
data class AccessToken(
@SerializedName("access_token") val accessToken: String
)

@ -1,130 +0,0 @@
/* Copyright 2017 Andrew Dawson
*
* This file is a part of Tusky.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky.entity;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.Spanned;
import com.google.gson.annotations.SerializedName;
import com.keylesspalace.tusky.util.HtmlUtils;
public class Account implements Parcelable {
public String id;
@SerializedName("username")
public String localUsername;
@SerializedName("acct")
public String username;
@SerializedName("display_name")
public String displayName;
public Spanned note;
public String url;
public String avatar;
public String header;
public boolean locked;
@SerializedName("followers_count")
public String followersCount;
@SerializedName("following_count")
public String followingCount;
@SerializedName("statuses_count")
public String statusesCount;
@Override
public int hashCode() {
return id.hashCode();
}
@Override
public boolean equals(Object other) {
if (this.id == null) {
return this == other;
} else if (!(other instanceof Account)) {
return false;
}
Account account = (Account) other;
return account.id.equals(this.id);
}
public String getDisplayName() {
if (displayName.length() == 0) {
return localUsername;
}
return displayName;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(id);
dest.writeString(localUsername);
dest.writeString(username);
dest.writeString(displayName);
dest.writeString(HtmlUtils.toHtml(note));
dest.writeString(url);
dest.writeString(avatar);
dest.writeString(header);
dest.writeBooleanArray(new boolean[] { locked });
dest.writeString(followersCount);
dest.writeString(followingCount);
dest.writeString(statusesCount);
}
public Account() {}
protected Account(Parcel in) {
id = in.readString();
localUsername = in.readString();
username = in.readString();
displayName = in.readString();
note = HtmlUtils.fromHtml(in.readString());
url = in.readString();
avatar = in.readString();
header = in.readString();
boolean[] lockedArray = new boolean[1];
in.readBooleanArray(lockedArray);
locked = lockedArray[0];
followersCount = in.readString();
followingCount = in.readString();
statusesCount = in.readString();
}
public static final Creator<Account> CREATOR = new Creator<Account>() {
@Override
public Account createFromParcel(Parcel source) {
return new Account(source);
}
@Override
public Account[] newArray(int size) {
return new Account[size];
}
};
}

@ -0,0 +1,69 @@
/* Copyright 2017 Andrew Dawson
*
* This file is a part of Tusky.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky.entity
import android.os.Parcel
import android.os.Parcelable
import android.text.Spanned
import com.google.gson.annotations.SerializedName
import com.keylesspalace.tusky.util.HtmlUtils
import kotlinx.android.parcel.Parceler
import kotlinx.android.parcel.Parcelize
import kotlinx.android.parcel.WriteWith
@Parcelize
data class Account(
val id: String,
@SerializedName("username") val localUsername: String,
@SerializedName("acct") val username: String,
@SerializedName("display_name") val displayName: String,
val note: @WriteWith<SpannedParceler>() Spanned,
val url: String,
val avatar: String,
val header: String,
val locked: Boolean = false,
@SerializedName("followers_count") val followersCount: Int,
@SerializedName("following_count") val followingCount: Int,
@SerializedName("statuses_count") val statusesCount: Int
) : Parcelable {
val name: String
get() = if (displayName.isEmpty()) {
localUsername
} else displayName
override fun hashCode(): Int {
return id.hashCode()
}
override fun equals(other: Any?): Boolean {
if (other !is Account) {
return false
}
val account = other as Account?
return account?.id == this.id
}
object SpannedParceler : Parceler<Spanned> {
override fun create(parcel: Parcel) = HtmlUtils.fromHtml(parcel.readString())
override fun Spanned.write(parcel: Parcel, flags: Int) {
parcel.writeString(HtmlUtils.toHtml(this))
}
}
}

@ -13,14 +13,11 @@
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky.entity;
package com.keylesspalace.tusky.entity
import com.google.gson.annotations.SerializedName;
import com.google.gson.annotations.SerializedName
public class AppCredentials {
@SerializedName("client_id")
public String clientId;
@SerializedName("client_secret")
public String clientSecret;
}
data class AppCredentials(
@SerializedName("client_id") val clientId: String,
@SerializedName("client_secret") val clientSecret: String
)

@ -1,79 +0,0 @@
/* Copyright 2017 Andrew Dawson
*
* This file is a part of Tusky.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky.entity;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
public class Attachment {
public String id;
public String url;
@SerializedName("preview_url")
public String previewUrl;
@SerializedName("text_url")
public String textUrl;
public Type type;
public String description;
public static class Meta {
public MediaProperties original;
public MediaProperties small;
}
public static class MediaProperties {
public int width;
public int height;
public float aspect;
}
@JsonAdapter(MediaTypeDeserializer.class)
public enum Type {
@SerializedName("image")
IMAGE,
@SerializedName("gifv")
GIFV,
@SerializedName("video")
VIDEO,
@SerializedName("unknown")
UNKNOWN
}
static class MediaTypeDeserializer implements JsonDeserializer<Type> {
@Override
public Type deserialize(JsonElement json, java.lang.reflect.Type classOfT, JsonDeserializationContext context)
throws JsonParseException {
switch(json.toString()) {
case "\"image\"":
return Type.IMAGE;
case "\"gifv\"":
return Type.GIFV;
case "\"video\"":
return Type.VIDEO;
default:
return Type.UNKNOWN;
}
}
}
}

@ -0,0 +1,57 @@
/* Copyright 2017 Andrew Dawson
*
* This file is a part of Tusky.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky.entity
import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import com.google.gson.JsonParseException
import com.google.gson.annotations.JsonAdapter
import com.google.gson.annotations.SerializedName
data class Attachment(
var id: String,
var url: String,
@SerializedName("preview_url") val previewUrl: String,
@SerializedName("text_url") val textUrl: String?,
var type: Type,
var description: String?
) {
@JsonAdapter(MediaTypeDeserializer::class)
enum class Type {
@SerializedName("image")
IMAGE,
@SerializedName("gifv")
GIFV,
@SerializedName("video")
VIDEO,
@SerializedName("unknown")
UNKNOWN
}
class MediaTypeDeserializer : JsonDeserializer<Type> {
@Throws(JsonParseException::class)
override fun deserialize(json: JsonElement, classOfT: java.lang.reflect.Type, context: JsonDeserializationContext): Type {
return when (json.toString()) {
"\"image\"" -> Type.IMAGE
"\"gifv\"" -> Type.GIFV
"\"video\"" -> Type.VIDEO
else -> Type.UNKNOWN
}
}
}
}

@ -1,92 +0,0 @@
/* Copyright 2017 Andrew Dawson
*
* This file is a part of Tusky.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
* License, or (at your option) any later version.
*
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky.entity;
import android.os.Parcel;
import android.os.Parcelable;
public class Card implements Parcelable {
public String url;
public String title;
public String description;
public String image;
public String type;
public int width;
public int height;
@Override
public int hashCode() {
return url.hashCode();
}
@Override
public boolean equals(Object other) {
if (this.url == null) {
return this == other;
} else if (!(other instanceof Card)) {
return false;
}
Card account = (Card) other;
return account.url.equals(this.url);
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(url);
dest.writeString(title);
dest.writeString(description);
dest.writeString(image);
dest.writeString(type);
dest.writeInt(width);
dest.writeInt(height);
}
public Card() {}
private Card(Parcel in) {
url = in.readString();
title = in.readString();
description = in.readString();
image = in.readString();
type = in.readString();
width = in.readInt();
height = in.readInt();
}
public static final Creator<Card> CREATOR = new Creator<Card>() {
@Override
public Card createFromParcel(Parcel source) {
return new Card(source);
}
@Override
public Card[] newArray(int size) {
return new Card[size];
}
};
}

@ -13,21 +13,32 @@
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky.entity;
package com.keylesspalace.tusky.entity
import android.os.Parcelable
import kotlinx.android.parcel.Parcelize
@Parcelize
data class Card(
val url: String,
val title: String,
val description: String,
val image: String,
val type: String,
val width: Int,
val height: Int
) : Parcelable {
override fun hashCode(): Int {
return url.hashCode()
}
override fun equals(other: Any?): Boolean {
if (other !is Card) {
return false
}
val account = other as Card?
return account?.url == this.url
}
import com.google.gson.annotations.SerializedName;
public class Relationship {
public String id;
public boolean following;
@SerializedName("followed_by")
public boolean followedBy;
public boolean blocking;
public boolean muting;
public boolean requested;
}

@ -13,12 +13,17 @@
* You should have received a copy of the GNU General Public License along with Tusky; if not,
* see <http://www.gnu.org/licenses>. */
package com.keylesspalace.tusky.entity;
package com.keylesspalace.tusky.entity
import com.google.gson.annotations.SerializedName;
import com.google.gson.annotations.SerializedName
public class Notification {
public enum Type {
data class Notification(
val type: Type,
val id: String,
val account: Account,
val status: Status?) {
enum class Type {
@SerializedName("mention")
MENTION,
@SerializedName("reblog")
@ -26,30 +31,18 @@ public class Notification {
@SerializedName("favourite")
FAVOURITE,
@SerializedName("follow")
FOLLOW,
FOLLOW
}