Search in sources :

Example 1 with Relationship

use of com.keylesspalace.tusky.entity.Relationship in project Tusky by Vavassor.

the class AccountActivity method follow.

private void follow(final String id) {
    Callback<Relationship> cb = new Callback<Relationship>() {

        @Override
        public void onResponse(Call<Relationship> call, Response<Relationship> response) {
            if (response.isSuccessful()) {
                Relationship relationship = response.body();
                if (relationship.following) {
                    followState = FollowState.FOLLOWING;
                } else if (relationship.requested) {
                    followState = FollowState.REQUESTED;
                    Snackbar.make(container, R.string.state_follow_requested, Snackbar.LENGTH_LONG).show();
                } else {
                    followState = FollowState.NOT_FOLLOWING;
                    broadcast(TimelineReceiver.Types.UNFOLLOW_ACCOUNT, id);
                }
                updateButtons();
            } else {
                onFollowFailure(id);
            }
        }

        @Override
        public void onFailure(Call<Relationship> call, Throwable t) {
            onFollowFailure(id);
        }
    };
    Assert.expect(followState != FollowState.REQUESTED);
    switch(followState) {
        case NOT_FOLLOWING:
            {
                mastodonAPI.followAccount(id).enqueue(cb);
                break;
            }
        case FOLLOWING:
            {
                mastodonAPI.unfollowAccount(id).enqueue(cb);
                break;
            }
    }
}
Also used : Response(retrofit2.Response) Call(retrofit2.Call) Callback(retrofit2.Callback) Relationship(com.keylesspalace.tusky.entity.Relationship)

Aggregations

Relationship (com.keylesspalace.tusky.entity.Relationship)1 Call (retrofit2.Call)1 Callback (retrofit2.Callback)1 Response (retrofit2.Response)1