mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-25 10:28:22 +01:00
Inbox Read all button function
This commit adds functionality for the read all option in the InboxActivity
This commit is contained in:
parent
0178569f14
commit
465abd4498
@ -47,7 +47,6 @@ import eu.toldi.infinityforlemmy.R;
|
||||
import eu.toldi.infinityforlemmy.RecyclerViewContentScrollingInterface;
|
||||
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||
import eu.toldi.infinityforlemmy.RetrofitHolder;
|
||||
import eu.toldi.infinityforlemmy.apis.RedditAPI;
|
||||
import eu.toldi.infinityforlemmy.asynctasks.SwitchAccount;
|
||||
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||
import eu.toldi.infinityforlemmy.customviews.slidr.Slidr;
|
||||
@ -58,12 +57,9 @@ import eu.toldi.infinityforlemmy.events.SwitchAccountEvent;
|
||||
import eu.toldi.infinityforlemmy.fragments.InboxFragment;
|
||||
import eu.toldi.infinityforlemmy.message.CommentInteraction;
|
||||
import eu.toldi.infinityforlemmy.message.FetchMessage;
|
||||
import eu.toldi.infinityforlemmy.utils.APIUtils;
|
||||
import eu.toldi.infinityforlemmy.message.ReadMessage;
|
||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class InboxActivity extends BaseActivity implements ActivityToolbarInterface, RecyclerViewContentScrollingInterface {
|
||||
|
||||
@ -305,31 +301,21 @@ public class InboxActivity extends BaseActivity implements ActivityToolbarInterf
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.action_read_all_messages_inbox_activity) {
|
||||
if (mAccessToken != null) {
|
||||
Toast.makeText(this, R.string.please_wait, Toast.LENGTH_SHORT).show();
|
||||
mRetrofit.getRetrofit().create(RedditAPI.class).readAllMessages(APIUtils.getOAuthHeader(mAccessToken))
|
||||
.enqueue(new Callback<>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
Toast.makeText(InboxActivity.this, R.string.read_all_messages_success, Toast.LENGTH_SHORT).show();
|
||||
if (sectionsPagerAdapter != null) {
|
||||
sectionsPagerAdapter.readAllMessages();
|
||||
}
|
||||
EventBus.getDefault().post(new ChangeInboxCountEvent(0));
|
||||
} else {
|
||||
if (response.code() == 429) {
|
||||
Toast.makeText(InboxActivity.this, R.string.read_all_messages_time_limit, Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
Toast.makeText(InboxActivity.this, R.string.read_all_messages_failed, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
ReadMessage.readAllMessages(mRetrofit.getRetrofit(), mAccessToken, new ReadMessage.ReadMessageListener() {
|
||||
@Override
|
||||
public void readSuccess() {
|
||||
Toast.makeText(InboxActivity.this, R.string.read_all_messages_success, Toast.LENGTH_SHORT).show();
|
||||
if (sectionsPagerAdapter != null) {
|
||||
sectionsPagerAdapter.readAllMessages();
|
||||
}
|
||||
EventBus.getDefault().post(new ChangeInboxCountEvent(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||
Toast.makeText(InboxActivity.this, R.string.read_all_messages_failed, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void readFailed() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (item.getItemId() == android.R.id.home) {
|
||||
finish();
|
||||
|
@ -5,6 +5,7 @@ import androidx.annotation.NonNull;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
import eu.toldi.infinityforlemmy.dto.AccountLoginDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.AuthDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.CommentDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.CommentVoteDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.DeleteCommentDTO;
|
||||
@ -61,6 +62,10 @@ public interface LemmyAPI {
|
||||
@POST("api/v3/comment/mark_as_read")
|
||||
Call<String> commentMarkAsRead(@Body ReadCommentDTO params);
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST("api/v3/user/mark_all_as_read")
|
||||
Call<String> userMarkAllAsRead(@Body AuthDTO params);
|
||||
|
||||
@GET("api/v3/community")
|
||||
Call<String> communityInfo(@Query("name") String name, @Query("auth") String access_token);
|
||||
|
||||
|
14
app/src/main/java/eu/toldi/infinityforlemmy/dto/AuthDTO.java
Normal file
14
app/src/main/java/eu/toldi/infinityforlemmy/dto/AuthDTO.java
Normal file
@ -0,0 +1,14 @@
|
||||
package eu.toldi.infinityforlemmy.dto;
|
||||
|
||||
public class AuthDTO {
|
||||
|
||||
private String auth;
|
||||
|
||||
public AuthDTO(String auth) {
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public String getAuth() {
|
||||
return auth;
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package eu.toldi.infinityforlemmy.message;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||
import eu.toldi.infinityforlemmy.dto.AuthDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.ReadCommentDTO;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
@ -30,6 +31,26 @@ public class ReadMessage {
|
||||
});
|
||||
}
|
||||
|
||||
public static void readAllMessages(Retrofit retrofit, String accessToken,
|
||||
ReadMessageListener readMessageListener) {
|
||||
retrofit.create(LemmyAPI.class).userMarkAllAsRead(new AuthDTO(accessToken))
|
||||
.enqueue(new Callback<String>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
|
||||
if (response.isSuccessful()) {
|
||||
readMessageListener.readSuccess();
|
||||
} else {
|
||||
readMessageListener.readFailed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
|
||||
readMessageListener.readFailed();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public interface ReadMessageListener {
|
||||
void readSuccess();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user