mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-06 18:57:26 +01:00
Show inbox count on navigation drawer
This commit is contained in:
parent
d4b107bc79
commit
f7185445e1
@ -1076,20 +1076,29 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
||||
|
||||
private void loadUserData() {
|
||||
if (!mFetchUserInfoSuccess) {
|
||||
FetchUserData.fetchUserData(mRedditDataRoomDatabase, mRetrofit.getRetrofit(), mAccessToken,
|
||||
mAccountName, new FetchUserData.FetchUserDataListener() {
|
||||
FetchUserData.fetchUnreadCount(mRetrofit.getRetrofit(), mAccessToken, new FetchUserData.FetchUserUnreadCountListener() {
|
||||
@Override
|
||||
public void onFetchUserDataSuccess(UserData userData, int inboxCount) {
|
||||
public void onFetchUserUnreadCountSuccess(int inboxCount) {
|
||||
MainActivity.this.inboxCount = inboxCount;
|
||||
mAccountName = userData.getName();
|
||||
mFetchUserInfoSuccess = true;
|
||||
if (adapter != null) {
|
||||
adapter.setInboxCount(inboxCount);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchUserDataFailed() {
|
||||
public void onFetchUserUnreadCountFailed() {
|
||||
}
|
||||
});
|
||||
FetchUserData.fetchUserData(mRedditDataRoomDatabase, mRetrofit.getRetrofit(), mAccessToken,
|
||||
mAccountName, new FetchUserData.FetchUserDataListener() {
|
||||
@Override
|
||||
public void onFetchUserDataSuccess(UserData userData, int inboxCount) {
|
||||
mAccountName = userData.getName();
|
||||
mFetchUserInfoSuccess = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFetchUserDataFailed() {
|
||||
mFetchUserInfoSuccess = false;
|
||||
}
|
||||
});
|
||||
|
@ -1,5 +1,7 @@
|
||||
package eu.toldi.infinityforlemmy.apis;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
import eu.toldi.infinityforlemmy.dto.AccountLoginDTO;
|
||||
@ -15,6 +17,7 @@ import eu.toldi.infinityforlemmy.dto.ReadPostDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.SaveCommentDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.SavePostDTO;
|
||||
import eu.toldi.infinityforlemmy.dto.SubmitPostDTO;
|
||||
import eu.toldi.infinityforlemmy.message.MessageCount;
|
||||
import okhttp3.MultipartBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Response;
|
||||
@ -45,6 +48,9 @@ public interface LemmyAPI {
|
||||
@GET("api/v3/private_message/list")
|
||||
Call<String> privateMessageList(@Query("page") Integer page, @Query("limit") Integer limit, @Query("unread_only") boolean unread_only, @Query("auth") String access_token);
|
||||
|
||||
@GET("api/v3/user/unread_count")
|
||||
Call<MessageCount> userUnreadCount(@NonNull @Query("auth") String access_token);
|
||||
|
||||
@GET("api/v3/community")
|
||||
Call<String> communityInfo(@Query("name") String name, @Query("auth") String access_token);
|
||||
|
||||
|
@ -0,0 +1,38 @@
|
||||
package eu.toldi.infinityforlemmy.message;
|
||||
|
||||
public class MessageCount {
|
||||
|
||||
/*
|
||||
Example:
|
||||
{
|
||||
"replies": 1,
|
||||
"mentions": 0,
|
||||
"private_messages": 0
|
||||
}
|
||||
*/
|
||||
public int replies;
|
||||
public int mentions;
|
||||
public int private_messages;
|
||||
|
||||
public MessageCount(int replies, int mentions, int private_messages) {
|
||||
this.replies = replies;
|
||||
this.mentions = mentions;
|
||||
this.private_messages = private_messages;
|
||||
}
|
||||
|
||||
public int getReplies() {
|
||||
return replies;
|
||||
}
|
||||
|
||||
public int getMentions() {
|
||||
return mentions;
|
||||
}
|
||||
|
||||
public int getPrivate_messages() {
|
||||
return private_messages;
|
||||
}
|
||||
|
||||
public int getSum() {
|
||||
return replies + mentions + private_messages;
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ import java.util.ArrayList;
|
||||
import eu.toldi.infinityforlemmy.RedditDataRoomDatabase;
|
||||
import eu.toldi.infinityforlemmy.SortType;
|
||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
|
||||
import eu.toldi.infinityforlemmy.message.MessageCount;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Retrofit;
|
||||
@ -85,6 +86,33 @@ public class FetchUserData {
|
||||
});
|
||||
}
|
||||
|
||||
public static void fetchUnreadCount(Retrofit retrofit, String accessToken, FetchUserUnreadCountListener fetchUserUnreadCountListener) {
|
||||
LemmyAPI api = retrofit.create(LemmyAPI.class);
|
||||
|
||||
Call<MessageCount> userUnreadCount = api.userUnreadCount(accessToken);
|
||||
userUnreadCount.enqueue(new Callback<>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<MessageCount> call, @NonNull retrofit2.Response<MessageCount> response) {
|
||||
if (response.isSuccessful() && response.body() != null) {
|
||||
fetchUserUnreadCountListener.onFetchUserUnreadCountSuccess(response.body().getSum());
|
||||
} else {
|
||||
fetchUserUnreadCountListener.onFetchUserUnreadCountFailed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<MessageCount> call, @NonNull Throwable t) {
|
||||
fetchUserUnreadCountListener.onFetchUserUnreadCountFailed();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public interface FetchUserUnreadCountListener {
|
||||
void onFetchUserUnreadCountSuccess(int unreadCount);
|
||||
|
||||
void onFetchUserUnreadCountFailed();
|
||||
}
|
||||
|
||||
public interface FetchUserDataListener {
|
||||
void onFetchUserDataSuccess(UserData userData, int inboxCount);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user