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:
Konrad Pozniak 2018-03-03 13:24:03 +01:00 committed by GitHub
commit 71954a277e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
51 changed files with 608 additions and 789 deletions

View file

@ -25,7 +25,6 @@ import android.support.v4.widget.SwipeRefreshLayout
import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.RecyclerView
import android.util.Log
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -213,7 +212,7 @@ class AccountMediaFragment : BaseFragment() {
intent.putExtra("url", urls[currentIndex])
startActivity(intent)
}
Attachment.Type.UNKNOWN, null -> {
Attachment.Type.UNKNOWN -> {
}/* Intentionally do nothing. This case is here is to handle when new attachment
* types are added to the API before code is added here to handle them. So, the
* best fallback is to just show the preview and ignore requests to view them. */

View file

@ -262,21 +262,21 @@ public class NotificationsFragment extends SFragment implements
@Override
public void onReply(int position) {
super.reply(notifications.get(position).getAsRight().status);
super.reply(notifications.get(position).getAsRight().getStatus());
}
@Override
public void onReblog(final boolean reblog, final int position) {
final Notification notification = notifications.get(position).getAsRight();
final Status status = notification.status;
final Status status = notification.getStatus();
reblogWithCallback(status, reblog, new Callback<Status>() {
@Override
public void onResponse(@NonNull Call<Status> call, @NonNull retrofit2.Response<Status> response) {
if (response.isSuccessful()) {
status.reblogged = reblog;
status.setReblogged(reblog);
if (status.reblog != null) {
status.reblog.reblogged = reblog;
if (status.getReblog() != null) {
status.getReblog().setReblogged(reblog);
}
NotificationViewData.Concrete viewdata = (NotificationViewData.Concrete)notifications.getPairedItem(position);
@ -296,7 +296,7 @@ public class NotificationsFragment extends SFragment implements
@Override
public void onFailure(@NonNull Call<Status> call, @NonNull Throwable t) {
Log.d(getClass().getSimpleName(), "Failed to reblog status: " + status.id, t);
Log.d(getClass().getSimpleName(), "Failed to reblog status: " + status.getId(), t);
}
});
}
@ -305,15 +305,15 @@ public class NotificationsFragment extends SFragment implements
@Override
public void onFavourite(final boolean favourite, final int position) {
final Notification notification = notifications.get(position).getAsRight();
final Status status = notification.status;
final Status status = notification.getStatus();
favouriteWithCallback(status, favourite, new Callback<Status>() {
@Override
public void onResponse(@NonNull Call<Status> call, @NonNull retrofit2.Response<Status> response) {
if (response.isSuccessful()) {
status.favourited = favourite;
status.setFavourited(favourite);
if (status.reblog != null) {
status.reblog.favourited = favourite;
if (status.getReblog() != null) {
status.getReblog().setFavourited(favourite);
}
NotificationViewData.Concrete viewdata = (NotificationViewData.Concrete)notifications.getPairedItem(position);
@ -334,7 +334,7 @@ public class NotificationsFragment extends SFragment implements
@Override
public void onFailure(@NonNull Call<Status> call, @NonNull Throwable t) {
Log.d(getClass().getSimpleName(), "Failed to favourite status: " + status.id, t);
Log.d(getClass().getSimpleName(), "Failed to favourite status: " + status.getId(), t);
}
});
}
@ -342,7 +342,7 @@ public class NotificationsFragment extends SFragment implements
@Override
public void onMore(View view, int position) {
Notification notification = notifications.get(position).getAsRight();
super.more(notification.status, view, position);
super.more(notification.getStatus(), view, position);
}
@Override
@ -354,13 +354,13 @@ public class NotificationsFragment extends SFragment implements
@Override
public void onViewThread(int position) {
Notification notification = notifications.get(position).getAsRight();
super.viewThread(notification.status);
super.viewThread(notification.getStatus());
}
@Override
public void onOpenReblog(int position) {
Notification notification = notifications.get(position).getAsRight();
onViewAccount(notification.account.id);
onViewAccount(notification.getAccount().getId());
}
@Override
@ -401,7 +401,7 @@ public class NotificationsFragment extends SFragment implements
Log.e(TAG, "Failed to load more, invalid placeholder position: " + position);
return;
}
sendFetchNotificationsRequest(previous.id, next.id, FetchEnd.MIDDLE, position);
sendFetchNotificationsRequest(previous.getId(), next.getId(), FetchEnd.MIDDLE, position);
NotificationViewData notificationViewData =
new NotificationViewData.Placeholder(true);
notifications.setPairedItem(position, notificationViewData);
@ -425,8 +425,8 @@ public class NotificationsFragment extends SFragment implements
public void onViewStatusForNotificationId(String notificationId) {
for (Either<Placeholder, Notification> either : notifications) {
Notification notification = either.getAsRightOrNull();
if (notification != null && notification.id.equals(notificationId)) {
super.viewThread(notification.status);
if (notification != null && notification.getId().equals(notificationId)) {
super.viewThread(notification.getStatus());
return;
}
}
@ -462,7 +462,7 @@ public class NotificationsFragment extends SFragment implements
while (iterator.hasNext()) {
Either<Placeholder, Notification> notification = iterator.next();
Notification maybeNotification = notification.getAsRightOrNull();
if (maybeNotification != null && maybeNotification.account.id.equals(accountId)) {
if (maybeNotification != null && maybeNotification.getAccount().getId().equals(accountId)) {
iterator.remove();
}
}
@ -590,7 +590,7 @@ public class NotificationsFragment extends SFragment implements
BigInteger lastNoti = new BigInteger(account.getLastNotificationId());
for (Notification noti: notifications) {
BigInteger a = new BigInteger(noti.id);
BigInteger a = new BigInteger(noti.getId());
if(isBiggerThan(a, lastNoti)) {
lastNoti = a;
}

View file

@ -98,12 +98,12 @@ public abstract class SFragment extends BaseFragment implements AdapterItemRemov
String inReplyToId = status.getActionableId();
Status actionableStatus = status.getActionableStatus();
Status.Visibility replyVisibility = actionableStatus.getVisibility();
String contentWarning = actionableStatus.spoilerText;
Status.Mention[] mentions = actionableStatus.mentions;
String contentWarning = actionableStatus.getSpoilerText();
Status.Mention[] mentions = actionableStatus.getMentions();
List<String> mentionedUsernames = new ArrayList<>();
mentionedUsernames.add(actionableStatus.account.username);
mentionedUsernames.add(actionableStatus.getAccount().getUsername());
for (Status.Mention mention : mentions) {
mentionedUsernames.add(mention.username);
mentionedUsernames.add(mention.getUsername());
}
mentionedUsernames.remove(loggedInUsername);
Intent intent = new ComposeActivity.IntentBuilder()
@ -111,8 +111,8 @@ public abstract class SFragment extends BaseFragment implements AdapterItemRemov
.replyVisibility(replyVisibility)
.contentWarning(contentWarning)
.mentionedUsernames(mentionedUsernames)
.repyingStatusAuthor(actionableStatus.account.localUsername)
.replyingStatusContent(actionableStatus.content.toString())
.repyingStatusAuthor(actionableStatus.getAccount().getLocalUsername())
.replyingStatusContent(actionableStatus.getContent().toString())
.build(getContext());
startActivityForResult(intent, COMPOSE_RESULT);
}
@ -146,7 +146,7 @@ public abstract class SFragment extends BaseFragment implements AdapterItemRemov
protected void openReblog(@Nullable final Status status) {
if (status == null) return;
viewAccount(status.account.id);
viewAccount(status.getAccount().getId());
}
private void mute(String id) {
@ -195,10 +195,10 @@ public abstract class SFragment extends BaseFragment implements AdapterItemRemov
protected void more(final Status status, View view, final int position) {
final String id = status.getActionableId();
final String accountId = status.getActionableStatus().account.id;
final String accountUsename = status.getActionableStatus().account.username;
final Spanned content = status.getActionableStatus().content;
final String statusUrl = status.getActionableStatus().url;
final String accountId = status.getActionableStatus().getAccount().getId();
final String accountUsename = status.getActionableStatus().getAccount().getUsername();
final Spanned content = status.getActionableStatus().getContent();
final String statusUrl = status.getActionableStatus().getUrl();
PopupMenu popup = new PopupMenu(getContext(), view);
// Give a different menu depending on whether this is the user's own toot or not.
if (loggedInAccountId == null || !loggedInAccountId.equals(accountId)) {
@ -213,9 +213,9 @@ public abstract class SFragment extends BaseFragment implements AdapterItemRemov
switch (item.getItemId()) {
case R.id.status_share_content: {
StringBuilder sb = new StringBuilder();
sb.append(status.account.username);
sb.append(status.getAccount().getUsername());
sb.append(" - ");
sb.append(status.content.toString());
sb.append(status.getContent().toString());
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
@ -301,7 +301,7 @@ public abstract class SFragment extends BaseFragment implements AdapterItemRemov
protected void viewThread(Status status) {
Intent intent = new Intent(getContext(), ViewThreadActivity.class);
intent.putExtra("id", status.getActionableId());
intent.putExtra("url", status.getActionableStatus().url);
intent.putExtra("url", status.getActionableStatus().getUrl());
startActivity(intent);
}

View file

@ -310,10 +310,10 @@ public class TimelineFragment extends SFragment implements
public void onResponse(@NonNull Call<Status> call, @NonNull Response<Status> response) {
if (response.isSuccessful()) {
status.reblogged = reblog;
status.setReblogged(reblog);
if (status.reblog != null) {
status.reblog.reblogged = reblog;
if (status.getReblog() != null) {
status.getReblog().setReblogged(reblog);
}
Pair<StatusViewData.Concrete, Integer> actual =
@ -331,7 +331,7 @@ public class TimelineFragment extends SFragment implements
@Override
public void onFailure(@NonNull Call<Status> call, @NonNull Throwable t) {
Log.d(TAG, "Failed to reblog status " + status.id, t);
Log.d(TAG, "Failed to reblog status " + status.getId(), t);
}
});
}
@ -345,10 +345,10 @@ public class TimelineFragment extends SFragment implements
public void onResponse(@NonNull Call<Status> call, @NonNull Response<Status> response) {
if (response.isSuccessful()) {
status.favourited = favourite;
status.setFavourited(favourite);
if (status.reblog != null) {
status.reblog.favourited = favourite;
if (status.getReblog() != null) {
status.getReblog().setFavourited(favourite);
}
Pair<StatusViewData.Concrete, Integer> actual =
@ -366,7 +366,7 @@ public class TimelineFragment extends SFragment implements
@Override
public void onFailure(@NonNull Call<Status> call, @NonNull Throwable t) {
Log.d(TAG, "Failed to favourite status " + status.id, t);
Log.d(TAG, "Failed to favourite status " + status.getId(), t);
}
});
}
@ -409,7 +409,7 @@ public class TimelineFragment extends SFragment implements
Log.e(TAG, "Failed to load more at " + position + ", wrong placeholder position");
return;
}
sendFetchTimelineRequest(fromStatus.id, toStatus.id, FetchEnd.MIDDLE, position);
sendFetchTimelineRequest(fromStatus.getId(), toStatus.getId(), FetchEnd.MIDDLE, position);
StatusViewData newViewData = new StatusViewData.Placeholder(true);
statuses.setPairedItem(position, newViewData);
@ -499,7 +499,7 @@ public class TimelineFragment extends SFragment implements
Iterator<Either<Placeholder, Status>> iterator = statuses.iterator();
while (iterator.hasNext()) {
Status status = iterator.next().getAsRightOrNull();
if (status != null && status.account.id.equals(accountId)) {
if (status != null && status.getAccount().getId().equals(accountId)) {
iterator.remove();
}
}
@ -682,8 +682,8 @@ public class TimelineFragment extends SFragment implements
Iterator<Status> it = statuses.iterator();
while (it.hasNext()) {
Status status = it.next();
if ((status.inReplyToId != null && filterRemoveReplies)
|| (status.reblog != null && filterRemoveReblogs)) {
if ((status.getInReplyToId() != null && filterRemoveReplies)
|| (status.getReblog() != null && filterRemoveReblogs)) {
it.remove();
}
}
@ -733,7 +733,7 @@ public class TimelineFragment extends SFragment implements
Status last = statuses.get(end - 1).getAsRightOrNull();
// I was about to replace findStatus with indexOf but it is incorrect to compare value
// types by ID anyway and we should change equals() for Status, I think, so this makes sense
if (last != null && !findStatus(newStatuses, last.id)) {
if (last != null && !findStatus(newStatuses, last.getId())) {
statuses.addAll(listStatusList(newStatuses));
List<StatusViewData> newViewDatas = statuses.getPairedCopy()
.subList(statuses.size() - newStatuses.size(), statuses.size());
@ -775,7 +775,7 @@ public class TimelineFragment extends SFragment implements
private static boolean findStatus(List<Status> statuses, String id) {
for (Status status : statuses) {
if (status.id.equals(id)) {
if (status.getId().equals(id)) {
return true;
}
}
@ -794,7 +794,7 @@ public class TimelineFragment extends SFragment implements
// Unlikely, but data could change between the request and response
if ((someOldViewData instanceof StatusViewData.Placeholder) ||
!((StatusViewData.Concrete) someOldViewData).getId().equals(status.id)) {
!((StatusViewData.Concrete) someOldViewData).getId().equals(status.getId())) {
// try to find the status we need to update
int foundPos = statuses.indexOf(Either.<Placeholder, Status>right(status));
if (foundPos < 0) return null; // okay, it's hopeless, give up

View file

@ -163,10 +163,10 @@ public class ViewThreadFragment extends SFragment implements
@Override
public void onResponse(@NonNull Call<Status> call, @NonNull Response<Status> response) {
if (response.isSuccessful()) {
status.reblogged = reblog;
status.setReblogged(reblog);
if (status.reblog != null) {
status.reblog.reblogged = reblog;
if (status.getReblog() != null) {
status.getReblog().setReblogged(reblog);
}
StatusViewData.Concrete viewdata = statuses.getPairedItem(position);
@ -183,7 +183,7 @@ public class ViewThreadFragment extends SFragment implements
@Override
public void onFailure(@NonNull Call<Status> call, @NonNull Throwable t) {
Log.d(getClass().getSimpleName(), "Failed to reblog status: " + status.id);
Log.d(getClass().getSimpleName(), "Failed to reblog status: " + status.getId());
t.printStackTrace();
}
});
@ -196,10 +196,10 @@ public class ViewThreadFragment extends SFragment implements
@Override
public void onResponse(@NonNull Call<Status> call, @NonNull Response<Status> response) {
if (response.isSuccessful()) {
status.favourited = favourite;
status.setFavourited(favourite);
if (status.reblog != null) {
status.reblog.favourited = favourite;
if (status.getReblog() != null) {
status.getReblog().setFavourited(favourite);
}
StatusViewData.Concrete viewdata = statuses.getPairedItem(position);
@ -216,7 +216,7 @@ public class ViewThreadFragment extends SFragment implements
@Override
public void onFailure(@NonNull Call<Status> call, @NonNull Throwable t) {
Log.d(getClass().getSimpleName(), "Failed to favourite status: " + status.id);
Log.d(getClass().getSimpleName(), "Failed to favourite status: " + status.getId());
t.printStackTrace();
}
});
@ -236,7 +236,7 @@ public class ViewThreadFragment extends SFragment implements
@Override
public void onViewThread(int position) {
Status status = statuses.get(position);
if (thisThreadsStatusId.equals(status.id)) {
if (thisThreadsStatusId.equals(status.getId())) {
// If already viewing this thread, don't reopen it.
return;
}
@ -304,7 +304,7 @@ public class ViewThreadFragment extends SFragment implements
Iterator<Status> iterator = statuses.iterator();
while (iterator.hasNext()) {
Status s = iterator.next();
if (s.account.id.equals(accountId)) {
if (s.getAccount().getId().equals(accountId)) {
iterator.remove();
}
}
@ -347,7 +347,7 @@ public class ViewThreadFragment extends SFragment implements
StatusContext context = response.body();
if (response.isSuccessful() && context != null) {
swipeRefreshLayout.setRefreshing(false);
setContext(context.ancestors, context.descendants);
setContext(context.getAncestors(), context.getDescendants());
} else {
onThreadRequestFailure(id);
}