Add a bunch of "old" methods to be able to still use java code
This commit is contained in:
parent
4af160853d
commit
4f865ec95f
4 changed files with 148 additions and 43 deletions
|
@ -23,4 +23,8 @@ class EventHub @Inject constructor() {
|
||||||
sharedEventFlow.emit(event)
|
sharedEventFlow.emit(event)
|
||||||
eventsSubject.onNext(event)
|
eventsSubject.onNext(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun dispatchOld(event: Event) {
|
||||||
|
eventsSubject.onNext(event)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -417,17 +417,17 @@ public class NotificationsFragment extends SFragment implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReblog(final boolean reblog, final int position) {
|
public void onReblog(final boolean reblog, final int position) {
|
||||||
// final Notification notification = notifications.get(position).asRight();
|
final Notification notification = notifications.get(position).asRight();
|
||||||
// final Status status = notification.getStatus();
|
final Status status = notification.getStatus();
|
||||||
// Objects.requireNonNull(status, "Reblog on notification without status");
|
Objects.requireNonNull(status, "Reblog on notification without status");
|
||||||
// timelineCases.reblog(status.getId(), reblog)
|
timelineCases.reblogOld(status.getId(), reblog)
|
||||||
// .observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
// .to(autoDisposable(from(this)))
|
.to(autoDisposable(from(this)))
|
||||||
// .subscribe(
|
.subscribe(
|
||||||
// (newStatus) -> setReblogForStatus(status.getId(), reblog),
|
(newStatus) -> setReblogForStatus(status.getId(), reblog),
|
||||||
// (t) -> Log.d(getClass().getSimpleName(),
|
(t) -> Log.d(getClass().getSimpleName(),
|
||||||
// "Failed to reblog status: " + status.getId(), t)
|
"Failed to reblog status: " + status.getId(), t)
|
||||||
// );
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setReblogForStatus(String statusId, boolean reblog) {
|
private void setReblogForStatus(String statusId, boolean reblog) {
|
||||||
|
@ -436,17 +436,17 @@ public class NotificationsFragment extends SFragment implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFavourite(final boolean favourite, final int position) {
|
public void onFavourite(final boolean favourite, final int position) {
|
||||||
// final Notification notification = notifications.get(position).asRight();
|
final Notification notification = notifications.get(position).asRight();
|
||||||
// final Status status = notification.getStatus();
|
final Status status = notification.getStatus();
|
||||||
//
|
|
||||||
// timelineCases.favourite(status.getId(), favourite)
|
timelineCases.favouriteOld(status.getId(), favourite)
|
||||||
// .observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
// .to(autoDisposable(from(this)))
|
.to(autoDisposable(from(this)))
|
||||||
// .subscribe(
|
.subscribe(
|
||||||
// (newStatus) -> setFavouriteForStatus(status.getId(), favourite),
|
(newStatus) -> setFavouriteForStatus(status.getId(), favourite),
|
||||||
// (t) -> Log.d(getClass().getSimpleName(),
|
(t) -> Log.d(getClass().getSimpleName(),
|
||||||
// "Failed to favourite status: " + status.getId(), t)
|
"Failed to favourite status: " + status.getId(), t)
|
||||||
// );
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setFavouriteForStatus(String statusId, boolean favourite) {
|
private void setFavouriteForStatus(String statusId, boolean favourite) {
|
||||||
|
@ -455,17 +455,17 @@ public class NotificationsFragment extends SFragment implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBookmark(final boolean bookmark, final int position) {
|
public void onBookmark(final boolean bookmark, final int position) {
|
||||||
// final Notification notification = notifications.get(position).asRight();
|
final Notification notification = notifications.get(position).asRight();
|
||||||
// final Status status = notification.getStatus();
|
final Status status = notification.getStatus();
|
||||||
//
|
|
||||||
// timelineCases.bookmark(status.getActionableId(), bookmark)
|
timelineCases.bookmarkOld(status.getActionableId(), bookmark)
|
||||||
// .observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
// .to(autoDisposable(from(this)))
|
.to(autoDisposable(from(this)))
|
||||||
// .subscribe(
|
.subscribe(
|
||||||
// (newStatus) -> setBookmarkForStatus(status.getId(), bookmark),
|
(newStatus) -> setBookmarkForStatus(status.getId(), bookmark),
|
||||||
// (t) -> Log.d(getClass().getSimpleName(),
|
(t) -> Log.d(getClass().getSimpleName(),
|
||||||
// "Failed to bookmark status: " + status.getId(), t)
|
"Failed to bookmark status: " + status.getId(), t)
|
||||||
// );
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setBookmarkForStatus(String statusId, boolean bookmark) {
|
private void setBookmarkForStatus(String statusId, boolean bookmark) {
|
||||||
|
@ -473,16 +473,16 @@ public class NotificationsFragment extends SFragment implements
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onVoteInPoll(int position, @NonNull List<Integer> choices) {
|
public void onVoteInPoll(int position, @NonNull List<Integer> choices) {
|
||||||
// final Notification notification = notifications.get(position).asRight();
|
final Notification notification = notifications.get(position).asRight();
|
||||||
// final Status status = notification.getStatus().getActionableStatus();
|
final Status status = notification.getStatus().getActionableStatus();
|
||||||
// timelineCases.voteInPoll(status.getId(), status.getPoll().getId(), choices)
|
timelineCases.voteInPollOld(status.getId(), status.getPoll().getId(), choices)
|
||||||
// .observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
// .to(autoDisposable(from(this)))
|
.to(autoDisposable(from(this)))
|
||||||
// .subscribe(
|
.subscribe(
|
||||||
// (newPoll) -> setVoteForPoll(status, newPoll),
|
(newPoll) -> setVoteForPoll(status, newPoll),
|
||||||
// (t) -> Log.d(TAG,
|
(t) -> Log.d(TAG,
|
||||||
// "Failed to vote in poll: " + status.getId(), t)
|
"Failed to vote in poll: " + status.getId(), t)
|
||||||
// );
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -290,6 +290,36 @@ interface MastodonApi {
|
||||||
@Path("id") statusId: String
|
@Path("id") statusId: String
|
||||||
): NetworkResult<Status>
|
): NetworkResult<Status>
|
||||||
|
|
||||||
|
@POST("api/v1/statuses/{id}/reblog")
|
||||||
|
fun reblogStatusOld(
|
||||||
|
@Path("id") statusId: String
|
||||||
|
): Single<Status>
|
||||||
|
|
||||||
|
@POST("api/v1/statuses/{id}/unreblog")
|
||||||
|
fun unreblogStatusOld(
|
||||||
|
@Path("id") statusId: String
|
||||||
|
): Single<Status>
|
||||||
|
|
||||||
|
@POST("api/v1/statuses/{id}/favourite")
|
||||||
|
fun favouriteStatusOld(
|
||||||
|
@Path("id") statusId: String
|
||||||
|
): Single<Status>
|
||||||
|
|
||||||
|
@POST("api/v1/statuses/{id}/unfavourite")
|
||||||
|
fun unfavouriteStatusOld(
|
||||||
|
@Path("id") statusId: String
|
||||||
|
): Single<Status>
|
||||||
|
|
||||||
|
@POST("api/v1/statuses/{id}/bookmark")
|
||||||
|
fun bookmarkStatusOld(
|
||||||
|
@Path("id") statusId: String
|
||||||
|
): Single<Status>
|
||||||
|
|
||||||
|
@POST("api/v1/statuses/{id}/unbookmark")
|
||||||
|
fun unbookmarkStatusOld(
|
||||||
|
@Path("id") statusId: String
|
||||||
|
): Single<Status>
|
||||||
|
|
||||||
@POST("api/v1/statuses/{id}/pin")
|
@POST("api/v1/statuses/{id}/pin")
|
||||||
suspend fun pinStatus(
|
suspend fun pinStatus(
|
||||||
@Path("id") statusId: String
|
@Path("id") statusId: String
|
||||||
|
@ -310,6 +340,16 @@ interface MastodonApi {
|
||||||
@Path("id") statusId: String
|
@Path("id") statusId: String
|
||||||
): NetworkResult<Status>
|
): NetworkResult<Status>
|
||||||
|
|
||||||
|
@POST("api/v1/statuses/{id}/mute")
|
||||||
|
fun muteConversationOld(
|
||||||
|
@Path("id") statusId: String
|
||||||
|
): Single<Status>
|
||||||
|
|
||||||
|
@POST("api/v1/statuses/{id}/unmute")
|
||||||
|
fun unmuteConversationOld(
|
||||||
|
@Path("id") statusId: String
|
||||||
|
): Single<Status>
|
||||||
|
|
||||||
@GET("api/v1/scheduled_statuses")
|
@GET("api/v1/scheduled_statuses")
|
||||||
fun scheduledStatuses(
|
fun scheduledStatuses(
|
||||||
@Query("limit") limit: Int? = null,
|
@Query("limit") limit: Int? = null,
|
||||||
|
@ -681,6 +721,13 @@ interface MastodonApi {
|
||||||
@Field("choices[]") choices: List<Int>
|
@Field("choices[]") choices: List<Int>
|
||||||
): NetworkResult<Poll>
|
): NetworkResult<Poll>
|
||||||
|
|
||||||
|
@FormUrlEncoded
|
||||||
|
@POST("api/v1/polls/{id}/votes")
|
||||||
|
fun voteInPollOld(
|
||||||
|
@Path("id") id: String,
|
||||||
|
@Field("choices[]") choices: List<Int>
|
||||||
|
): Single<Poll>
|
||||||
|
|
||||||
@GET("api/v1/announcements")
|
@GET("api/v1/announcements")
|
||||||
suspend fun listAnnouncements(
|
suspend fun listAnnouncements(
|
||||||
@Query("with_dismissed") withDismissed: Boolean = true
|
@Query("with_dismissed") withDismissed: Boolean = true
|
||||||
|
|
|
@ -88,6 +88,50 @@ class TimelineCases @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun reblogOld(statusId: String, reblog: Boolean): Single<Status> {
|
||||||
|
val call = if (reblog) {
|
||||||
|
mastodonApi.reblogStatusOld(statusId)
|
||||||
|
} else {
|
||||||
|
mastodonApi.unreblogStatusOld(statusId)
|
||||||
|
}
|
||||||
|
return call.doAfterSuccess {
|
||||||
|
eventHub.dispatchOld(ReblogEvent(statusId, reblog))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun favouriteOld(statusId: String, favourite: Boolean): Single<Status> {
|
||||||
|
val call = if (favourite) {
|
||||||
|
mastodonApi.favouriteStatusOld(statusId)
|
||||||
|
} else {
|
||||||
|
mastodonApi.unfavouriteStatusOld(statusId)
|
||||||
|
}
|
||||||
|
return call.doAfterSuccess {
|
||||||
|
eventHub.dispatchOld(FavoriteEvent(statusId, favourite))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bookmarkOld(statusId: String, bookmark: Boolean): Single<Status> {
|
||||||
|
val call = if (bookmark) {
|
||||||
|
mastodonApi.bookmarkStatusOld(statusId)
|
||||||
|
} else {
|
||||||
|
mastodonApi.unbookmarkStatusOld(statusId)
|
||||||
|
}
|
||||||
|
return call.doAfterSuccess {
|
||||||
|
eventHub.dispatchOld(BookmarkEvent(statusId, bookmark))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun muteConversationOld(statusId: String, mute: Boolean): Single<Status> {
|
||||||
|
val call = if (mute) {
|
||||||
|
mastodonApi.muteConversationOld(statusId)
|
||||||
|
} else {
|
||||||
|
mastodonApi.unmuteConversationOld(statusId)
|
||||||
|
}
|
||||||
|
return call.doAfterSuccess {
|
||||||
|
eventHub.dispatchOld(MuteConversationEvent(statusId, mute))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun mute(statusId: String, notifications: Boolean, duration: Int?) {
|
suspend fun mute(statusId: String, notifications: Boolean, duration: Int?) {
|
||||||
try {
|
try {
|
||||||
mastodonApi.muteAccount(statusId, notifications, duration)
|
mastodonApi.muteAccount(statusId, notifications, duration)
|
||||||
|
@ -136,6 +180,16 @@ class TimelineCases @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun voteInPollOld(statusId: String, pollId: String, choices: List<Int>): Single<Poll> {
|
||||||
|
if (choices.isEmpty()) {
|
||||||
|
return Single.error(IllegalStateException())
|
||||||
|
}
|
||||||
|
|
||||||
|
return mastodonApi.voteInPollOld(pollId, choices).doAfterSuccess {
|
||||||
|
eventHub.dispatchOld(PollVoteEvent(statusId, it))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun acceptFollowRequest(accountId: String): Single<Relationship> {
|
fun acceptFollowRequest(accountId: String): Single<Relationship> {
|
||||||
return mastodonApi.authorizeFollowRequest(accountId)
|
return mastodonApi.authorizeFollowRequest(accountId)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue