mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-01 05:47:10 +01:00
Sending private messages
This commit is contained in:
parent
9626500586
commit
3e17e3364d
@ -5,6 +5,7 @@ import android.content.SharedPreferences;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
@ -27,6 +28,7 @@ import org.greenrobot.eventbus.EventBus;
|
|||||||
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -46,14 +48,15 @@ import eu.toldi.infinityforlemmy.customviews.LinearLayoutManagerBugFixed;
|
|||||||
import eu.toldi.infinityforlemmy.events.PassPrivateMessageEvent;
|
import eu.toldi.infinityforlemmy.events.PassPrivateMessageEvent;
|
||||||
import eu.toldi.infinityforlemmy.events.PassPrivateMessageIndexEvent;
|
import eu.toldi.infinityforlemmy.events.PassPrivateMessageIndexEvent;
|
||||||
import eu.toldi.infinityforlemmy.events.RepliedToPrivateMessageEvent;
|
import eu.toldi.infinityforlemmy.events.RepliedToPrivateMessageEvent;
|
||||||
import eu.toldi.infinityforlemmy.message.Message;
|
|
||||||
import eu.toldi.infinityforlemmy.message.ReadMessage;
|
import eu.toldi.infinityforlemmy.message.ReadMessage;
|
||||||
import eu.toldi.infinityforlemmy.message.ReplyMessage;
|
import eu.toldi.infinityforlemmy.privatemessage.LemmyPrivateMessageAPI;
|
||||||
|
import eu.toldi.infinityforlemmy.privatemessage.PrivateMessage;
|
||||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
public class ViewPrivateMessagesActivity extends BaseActivity implements ActivityToolbarInterface {
|
public class ViewPrivateMessagesActivity extends BaseActivity implements ActivityToolbarInterface {
|
||||||
|
|
||||||
|
public static final String EXTRA_PRIVATE_MESSAGE = "EPM";
|
||||||
public static final String EXTRA_PRIVATE_MESSAGE_INDEX = "EPM";
|
public static final String EXTRA_PRIVATE_MESSAGE_INDEX = "EPM";
|
||||||
public static final String EXTRA_MESSAGE_POSITION = "EMP";
|
public static final String EXTRA_MESSAGE_POSITION = "EMP";
|
||||||
private static final String USER_AVATAR_STATE = "UAS";
|
private static final String USER_AVATAR_STATE = "UAS";
|
||||||
@ -91,14 +94,19 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
|
|||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
@Inject
|
@Inject
|
||||||
Executor mExecutor;
|
Executor mExecutor;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
LemmyPrivateMessageAPI mLemmyPrivateMessageAPI;
|
||||||
private LinearLayoutManagerBugFixed mLinearLayoutManager;
|
private LinearLayoutManagerBugFixed mLinearLayoutManager;
|
||||||
private PrivateMessagesDetailRecyclerViewAdapter mAdapter;
|
private PrivateMessagesDetailRecyclerViewAdapter mAdapter;
|
||||||
@State
|
@State
|
||||||
Message privateMessage;
|
PrivateMessage privateMessage;
|
||||||
@State
|
@State
|
||||||
Message replyTo;
|
PrivateMessage replyTo;
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
|
|
||||||
|
private String mAccountQualifiedName;
|
||||||
private String mUserAvatar;
|
private String mUserAvatar;
|
||||||
private ArrayList<ProvideUserAvatarCallback> mProvideUserAvatarCallbacks;
|
private ArrayList<ProvideUserAvatarCallback> mProvideUserAvatarCallbacks;
|
||||||
private boolean isLoadingUserAvatar = false;
|
private boolean isLoadingUserAvatar = false;
|
||||||
@ -128,6 +136,11 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
|
|||||||
addOnOffsetChangedListener(mAppBarLayout);
|
addOnOffsetChangedListener(mAppBarLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Intent intent = getIntent();
|
||||||
|
privateMessage = intent.getParcelableExtra(EXTRA_PRIVATE_MESSAGE);
|
||||||
|
|
||||||
|
Log.i("ViewPrivate", "privateMessage: " + privateMessage);
|
||||||
|
|
||||||
setSupportActionBar(mToolbar);
|
setSupportActionBar(mToolbar);
|
||||||
setToolbarGoToTop(mToolbar);
|
setToolbarGoToTop(mToolbar);
|
||||||
|
|
||||||
@ -135,6 +148,7 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
|
|||||||
|
|
||||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
|
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mUserAvatar = savedInstanceState.getString(USER_AVATAR_STATE);
|
mUserAvatar = savedInstanceState.getString(USER_AVATAR_STATE);
|
||||||
@ -144,36 +158,37 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
|
|||||||
bindView();
|
bindView();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (privateMessage != null) {
|
||||||
|
bindView();
|
||||||
|
}
|
||||||
EventBus.getDefault().post(new PassPrivateMessageIndexEvent(getIntent().getIntExtra(EXTRA_PRIVATE_MESSAGE_INDEX, -1)));
|
EventBus.getDefault().post(new PassPrivateMessageIndexEvent(getIntent().getIntExtra(EXTRA_PRIVATE_MESSAGE_INDEX, -1)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindView() {
|
private void bindView() {
|
||||||
if (privateMessage != null) {
|
if (privateMessage != null) {
|
||||||
if (privateMessage.getAuthor().equals(mAccountName)) {
|
if (privateMessage.getCreatorQualifiedName().equals(mAccountQualifiedName)) {
|
||||||
setTitle(privateMessage.getDestination());
|
setTitle(privateMessage.getRecipientName());
|
||||||
mToolbar.setOnClickListener(view -> {
|
mToolbar.setOnClickListener(view -> {
|
||||||
if (privateMessage.isDestinationDeleted()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Intent intent = new Intent(this, ViewUserDetailActivity.class);
|
Intent intent = new Intent(this, ViewUserDetailActivity.class);
|
||||||
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, privateMessage.getDestination());
|
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, privateMessage.getRecipientName());
|
||||||
|
intent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, privateMessage.getRecipientQualifiedName());
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
setTitle(privateMessage.getAuthor());
|
setTitle(privateMessage.getCreatorName());
|
||||||
mToolbar.setOnClickListener(view -> {
|
mToolbar.setOnClickListener(view -> {
|
||||||
if (privateMessage.isAuthorDeleted()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Intent intent = new Intent(this, ViewUserDetailActivity.class);
|
Intent intent = new Intent(this, ViewUserDetailActivity.class);
|
||||||
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, privateMessage.getAuthor());
|
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, privateMessage.getCreatorName());
|
||||||
|
intent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, privateMessage.getCreatorQualifiedName());
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mAdapter = new PrivateMessagesDetailRecyclerViewAdapter(this, mSharedPreferences,
|
mAdapter = new PrivateMessagesDetailRecyclerViewAdapter(this, mSharedPreferences,
|
||||||
getResources().getConfiguration().locale, privateMessage, mAccountName, mCustomThemeWrapper);
|
getResources().getConfiguration().locale, privateMessage, mAccountQualifiedName, mCustomThemeWrapper);
|
||||||
mLinearLayoutManager = new LinearLayoutManagerBugFixed(this);
|
mLinearLayoutManager = new LinearLayoutManagerBugFixed(this);
|
||||||
mLinearLayoutManager.setStackFromEnd(true);
|
mLinearLayoutManager.setStackFromEnd(true);
|
||||||
mRecyclerView.setLayoutManager(mLinearLayoutManager);
|
mRecyclerView.setLayoutManager(mLinearLayoutManager);
|
||||||
@ -184,45 +199,40 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
|
|||||||
if (!mEditText.getText().toString().equals("")) {
|
if (!mEditText.getText().toString().equals("")) {
|
||||||
//Send Message
|
//Send Message
|
||||||
if (privateMessage != null) {
|
if (privateMessage != null) {
|
||||||
ArrayList<Message> replies = privateMessage.getReplies();
|
List<PrivateMessage> replies = privateMessage.getReplies();
|
||||||
if (replyTo == null) {
|
if (replyTo == null) {
|
||||||
replyTo = privateMessage;
|
replyTo = privateMessage;
|
||||||
}
|
}
|
||||||
isSendingMessage = true;
|
isSendingMessage = true;
|
||||||
mSendImageView.setColorFilter(mSecondaryTextColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
mSendImageView.setColorFilter(mSecondaryTextColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||||
ReplyMessage.replyMessage(mEditText.getText().toString(), replyTo.getFullname(),
|
|
||||||
getResources().getConfiguration().locale, mOauthRetrofit, mAccessToken,
|
|
||||||
new ReplyMessage.ReplyMessageListener() {
|
|
||||||
@Override
|
|
||||||
public void replyMessageSuccess(Message message) {
|
|
||||||
if (mAdapter != null) {
|
|
||||||
mAdapter.addReply(message);
|
|
||||||
}
|
|
||||||
goToBottom();
|
|
||||||
mEditText.setText("");
|
|
||||||
mSendImageView.setColorFilter(mSendMessageIconColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
|
||||||
isSendingMessage = false;
|
|
||||||
EventBus.getDefault().post(new RepliedToPrivateMessageEvent(message, getIntent().getIntExtra(EXTRA_MESSAGE_POSITION, -1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
mLemmyPrivateMessageAPI.sendPrivateMessage(mAccessToken, replyTo.getCreatorId(), mEditText.getText().toString(), new LemmyPrivateMessageAPI.PrivateMessageSentListener() {
|
||||||
public void replyMessageFailed(String errorMessage) {
|
|
||||||
if (errorMessage != null && !errorMessage.equals("")) {
|
@Override
|
||||||
Snackbar.make(mCoordinatorLayout, errorMessage, Snackbar.LENGTH_LONG).show();
|
public void onPrivateMessageSentSuccess(@NonNull PrivateMessage privateMessage) {
|
||||||
} else {
|
if (mAdapter != null) {
|
||||||
Snackbar.make(mCoordinatorLayout, R.string.reply_message_failed, Snackbar.LENGTH_LONG).show();
|
mAdapter.addReply(privateMessage);
|
||||||
}
|
}
|
||||||
mSendImageView.setColorFilter(mSendMessageIconColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
goToBottom();
|
||||||
isSendingMessage = false;
|
mEditText.setText("");
|
||||||
}
|
isSendingMessage = false;
|
||||||
});
|
EventBus.getDefault().post(new RepliedToPrivateMessageEvent(privateMessage, getIntent().getIntExtra(EXTRA_MESSAGE_POSITION, -1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPrivateMessageSentError() {
|
||||||
|
Snackbar.make(mCoordinatorLayout, R.string.reply_message_failed, Snackbar.LENGTH_LONG).show();
|
||||||
|
mSendImageView.setColorFilter(mSendMessageIconColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||||
|
isSendingMessage = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
StringBuilder fullnames = new StringBuilder();
|
StringBuilder fullnames = new StringBuilder();
|
||||||
if (privateMessage.isNew()) {
|
|
||||||
fullnames.append(privateMessage.getFullname()).append(",");
|
|
||||||
}
|
|
||||||
if (replies != null && !replies.isEmpty()) {
|
if (replies != null && !replies.isEmpty()) {
|
||||||
for (Message m : replies) {
|
for (PrivateMessage m : replies) {
|
||||||
if (m.isNew()) {
|
if (!m.getRead()) {
|
||||||
fullnames.append(m).append(",");
|
fullnames.append(m).append(",");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ public class PrivateMessageRecycleViewAdapter extends PagedListAdapter<PrivateMe
|
|||||||
PrivateMessage message = getItem(holder.getBindingAdapterPosition());
|
PrivateMessage message = getItem(holder.getBindingAdapterPosition());
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
|
|
||||||
if (message.getRead()) {
|
if (!message.getRead()) {
|
||||||
if (markAllMessagesAsRead) {
|
if (markAllMessagesAsRead) {
|
||||||
message.setRead(true);
|
message.setRead(true);
|
||||||
} else {
|
} else {
|
||||||
@ -171,8 +171,7 @@ public class PrivateMessageRecycleViewAdapter extends PagedListAdapter<PrivateMe
|
|||||||
holder.itemView.setOnClickListener(view -> {
|
holder.itemView.setOnClickListener(view -> {
|
||||||
|
|
||||||
Intent intent = new Intent(mActivity, ViewPrivateMessagesActivity.class);
|
Intent intent = new Intent(mActivity, ViewPrivateMessagesActivity.class);
|
||||||
intent.putExtra(ViewPrivateMessagesActivity.EXTRA_PRIVATE_MESSAGE_INDEX, holder.getBindingAdapterPosition());
|
intent.putExtra(ViewPrivateMessagesActivity.EXTRA_PRIVATE_MESSAGE, message);
|
||||||
intent.putExtra(ViewPrivateMessagesActivity.EXTRA_MESSAGE_POSITION, holder.getBindingAdapterPosition());
|
|
||||||
mActivity.startActivity(intent);
|
mActivity.startActivity(intent);
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,34 +27,35 @@ import java.util.Locale;
|
|||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import io.noties.markwon.AbstractMarkwonPlugin;
|
|
||||||
import io.noties.markwon.Markwon;
|
|
||||||
import io.noties.markwon.MarkwonConfiguration;
|
|
||||||
import io.noties.markwon.core.MarkwonTheme;
|
|
||||||
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
|
|
||||||
import io.noties.markwon.inlineparser.BangInlineProcessor;
|
|
||||||
import io.noties.markwon.inlineparser.HtmlInlineProcessor;
|
|
||||||
import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin;
|
|
||||||
import io.noties.markwon.linkify.LinkifyPlugin;
|
|
||||||
import io.noties.markwon.movement.MovementMethodPlugin;
|
|
||||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
|
||||||
import eu.toldi.infinityforlemmy.R;
|
import eu.toldi.infinityforlemmy.R;
|
||||||
import eu.toldi.infinityforlemmy.activities.LinkResolverActivity;
|
import eu.toldi.infinityforlemmy.activities.LinkResolverActivity;
|
||||||
import eu.toldi.infinityforlemmy.activities.ViewPrivateMessagesActivity;
|
import eu.toldi.infinityforlemmy.activities.ViewPrivateMessagesActivity;
|
||||||
import eu.toldi.infinityforlemmy.activities.ViewUserDetailActivity;
|
import eu.toldi.infinityforlemmy.activities.ViewUserDetailActivity;
|
||||||
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
import eu.toldi.infinityforlemmy.customtheme.CustomThemeWrapper;
|
||||||
|
import eu.toldi.infinityforlemmy.markdown.ClickableGlideImagesPlugin;
|
||||||
import eu.toldi.infinityforlemmy.markdown.RedditHeadingPlugin;
|
import eu.toldi.infinityforlemmy.markdown.RedditHeadingPlugin;
|
||||||
import eu.toldi.infinityforlemmy.markdown.SpoilerAwareMovementMethod;
|
import eu.toldi.infinityforlemmy.markdown.SpoilerAwareMovementMethod;
|
||||||
import eu.toldi.infinityforlemmy.markdown.SpoilerParserPlugin;
|
import eu.toldi.infinityforlemmy.markdown.SpoilerParserPlugin;
|
||||||
import eu.toldi.infinityforlemmy.markdown.SuperscriptPlugin;
|
import eu.toldi.infinityforlemmy.markdown.SuperscriptPlugin;
|
||||||
import eu.toldi.infinityforlemmy.message.Message;
|
import eu.toldi.infinityforlemmy.privatemessage.PrivateMessage;
|
||||||
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
|
||||||
import eu.toldi.infinityforlemmy.utils.Utils;
|
import eu.toldi.infinityforlemmy.utils.Utils;
|
||||||
|
import io.noties.markwon.AbstractMarkwonPlugin;
|
||||||
|
import io.noties.markwon.Markwon;
|
||||||
|
import io.noties.markwon.MarkwonConfiguration;
|
||||||
|
import io.noties.markwon.core.MarkwonTheme;
|
||||||
|
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
|
||||||
|
import io.noties.markwon.image.glide.GlideImagesPlugin;
|
||||||
|
import io.noties.markwon.inlineparser.HtmlInlineProcessor;
|
||||||
|
import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin;
|
||||||
|
import io.noties.markwon.linkify.LinkifyPlugin;
|
||||||
|
import io.noties.markwon.movement.MovementMethodPlugin;
|
||||||
|
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||||
|
|
||||||
public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
private static final int VIEW_TYPE_MESSAGE_SENT = 0;
|
private static final int VIEW_TYPE_MESSAGE_SENT = 0;
|
||||||
private static final int VIEW_TYPE_MESSAGE_RECEIVED = 1;
|
private static final int VIEW_TYPE_MESSAGE_RECEIVED = 1;
|
||||||
private Message mMessage;
|
private PrivateMessage mMessage;
|
||||||
private ViewPrivateMessagesActivity mViewPrivateMessagesActivity;
|
private ViewPrivateMessagesActivity mViewPrivateMessagesActivity;
|
||||||
private RequestManager mGlide;
|
private RequestManager mGlide;
|
||||||
private Locale mLocale;
|
private Locale mLocale;
|
||||||
@ -70,7 +71,7 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt
|
|||||||
|
|
||||||
public PrivateMessagesDetailRecyclerViewAdapter(ViewPrivateMessagesActivity viewPrivateMessagesActivity,
|
public PrivateMessagesDetailRecyclerViewAdapter(ViewPrivateMessagesActivity viewPrivateMessagesActivity,
|
||||||
SharedPreferences sharedPreferences, Locale locale,
|
SharedPreferences sharedPreferences, Locale locale,
|
||||||
Message message, String accountName,
|
PrivateMessage message, String accountName,
|
||||||
CustomThemeWrapper customThemeWrapper) {
|
CustomThemeWrapper customThemeWrapper) {
|
||||||
mMessage = message;
|
mMessage = message;
|
||||||
mViewPrivateMessagesActivity = viewPrivateMessagesActivity;
|
mViewPrivateMessagesActivity = viewPrivateMessagesActivity;
|
||||||
@ -83,7 +84,6 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt
|
|||||||
mMarkwon = Markwon.builder(viewPrivateMessagesActivity)
|
mMarkwon = Markwon.builder(viewPrivateMessagesActivity)
|
||||||
.usePlugin(MarkwonInlineParserPlugin.create(plugin -> {
|
.usePlugin(MarkwonInlineParserPlugin.create(plugin -> {
|
||||||
plugin.excludeInlineProcessor(HtmlInlineProcessor.class);
|
plugin.excludeInlineProcessor(HtmlInlineProcessor.class);
|
||||||
plugin.excludeInlineProcessor(BangInlineProcessor.class);
|
|
||||||
}))
|
}))
|
||||||
.usePlugin(new AbstractMarkwonPlugin() {
|
.usePlugin(new AbstractMarkwonPlugin() {
|
||||||
@Override
|
@Override
|
||||||
@ -108,6 +108,8 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt
|
|||||||
builder.linkColor(customThemeWrapper.getLinkColor());
|
builder.linkColor(customThemeWrapper.getLinkColor());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.usePlugin(GlideImagesPlugin.create(viewPrivateMessagesActivity))
|
||||||
|
.usePlugin(ClickableGlideImagesPlugin.create(viewPrivateMessagesActivity))
|
||||||
.usePlugin(SuperscriptPlugin.create())
|
.usePlugin(SuperscriptPlugin.create())
|
||||||
.usePlugin(StrikethroughPlugin.create())
|
.usePlugin(StrikethroughPlugin.create())
|
||||||
.usePlugin(SpoilerParserPlugin.create(commentColor, commentColor | 0xFF000000))
|
.usePlugin(SpoilerParserPlugin.create(commentColor, commentColor | 0xFF000000))
|
||||||
@ -127,9 +129,9 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt
|
|||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
if (position == 0) {
|
if (position == 0) {
|
||||||
return mMessage.getAuthor().equals(mAccountName) ? VIEW_TYPE_MESSAGE_SENT : VIEW_TYPE_MESSAGE_RECEIVED;
|
return mMessage.getCreatorQualifiedName().equals(mAccountName) ? VIEW_TYPE_MESSAGE_SENT : VIEW_TYPE_MESSAGE_RECEIVED;
|
||||||
} else {
|
} else {
|
||||||
return mMessage.getReplies().get(position - 1).getAuthor().equals(mAccountName) ? VIEW_TYPE_MESSAGE_SENT : VIEW_TYPE_MESSAGE_RECEIVED;
|
return mMessage.getReplies().get(position - 1).getCreatorQualifiedName().equals(mAccountName) ? VIEW_TYPE_MESSAGE_SENT : VIEW_TYPE_MESSAGE_RECEIVED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +147,7 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||||
Message message;
|
PrivateMessage message;
|
||||||
if (holder.getBindingAdapterPosition() == 0) {
|
if (holder.getBindingAdapterPosition() == 0) {
|
||||||
message = mMessage;
|
message = mMessage;
|
||||||
} else {
|
} else {
|
||||||
@ -153,12 +155,12 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt
|
|||||||
}
|
}
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
if (holder instanceof MessageViewHolder) {
|
if (holder instanceof MessageViewHolder) {
|
||||||
mMarkwon.setMarkdown(((MessageViewHolder) holder).messageTextView, message.getBody());
|
mMarkwon.setMarkdown(((MessageViewHolder) holder).messageTextView, message.getContent());
|
||||||
|
|
||||||
if (mShowElapsedTime) {
|
if (mShowElapsedTime) {
|
||||||
((MessageViewHolder) holder).timeTextView.setText(Utils.getElapsedTime(mViewPrivateMessagesActivity, message.getTimeUTC()));
|
((MessageViewHolder) holder).timeTextView.setText(Utils.getElapsedTime(mViewPrivateMessagesActivity, message.getPublished()));
|
||||||
} else {
|
} else {
|
||||||
((MessageViewHolder) holder).timeTextView.setText(Utils.getFormattedTime(mLocale, message.getTimeUTC(), mTimeFormatPattern));
|
((MessageViewHolder) holder).timeTextView.setText(Utils.getFormattedTime(mLocale, message.getPublished(), mTimeFormatPattern));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,26 +168,33 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt
|
|||||||
((SentMessageViewHolder) holder).messageTextView.setBackground(Utils.getTintedDrawable(mViewPrivateMessagesActivity,
|
((SentMessageViewHolder) holder).messageTextView.setBackground(Utils.getTintedDrawable(mViewPrivateMessagesActivity,
|
||||||
R.drawable.private_message_ballon, mSentMessageBackgroundColor));
|
R.drawable.private_message_ballon, mSentMessageBackgroundColor));
|
||||||
} else if (holder instanceof ReceivedMessageViewHolder) {
|
} else if (holder instanceof ReceivedMessageViewHolder) {
|
||||||
mViewPrivateMessagesActivity.fetchUserAvatar(message.getAuthor(), userAvatarUrl -> {
|
if (!message.getCreatorAvatar().equals("")) {
|
||||||
if (userAvatarUrl == null || userAvatarUrl.equals("")) {
|
mGlide.load(message.getCreatorAvatar())
|
||||||
mGlide.load(R.drawable.subreddit_default_icon)
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.into(((ReceivedMessageViewHolder) holder).userAvatarImageView);
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
||||||
} else {
|
.into(((ReceivedMessageViewHolder) holder).userAvatarImageView);
|
||||||
mGlide.load(userAvatarUrl)
|
} else {
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
mViewPrivateMessagesActivity.fetchUserAvatar(message.getCreatorQualifiedName(), userAvatarUrl -> {
|
||||||
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
if (userAvatarUrl == null || userAvatarUrl.equals("")) {
|
||||||
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
.into(((ReceivedMessageViewHolder) holder).userAvatarImageView);
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
}
|
.into(((ReceivedMessageViewHolder) holder).userAvatarImageView);
|
||||||
});
|
} else {
|
||||||
|
mGlide.load(userAvatarUrl)
|
||||||
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
|
||||||
|
.error(mGlide.load(R.drawable.subreddit_default_icon)
|
||||||
|
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
|
||||||
|
.into(((ReceivedMessageViewHolder) holder).userAvatarImageView);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
((ReceivedMessageViewHolder) holder).userAvatarImageView.setOnClickListener(view -> {
|
((ReceivedMessageViewHolder) holder).userAvatarImageView.setOnClickListener(view -> {
|
||||||
if (message.isAuthorDeleted()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Intent intent = new Intent(mViewPrivateMessagesActivity, ViewUserDetailActivity.class);
|
Intent intent = new Intent(mViewPrivateMessagesActivity, ViewUserDetailActivity.class);
|
||||||
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, message.getAuthor());
|
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, message.getCreatorName());
|
||||||
|
intent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, message.getCreatorQualifiedName());
|
||||||
mViewPrivateMessagesActivity.startActivity(intent);
|
mViewPrivateMessagesActivity.startActivity(intent);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -207,12 +216,12 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMessage(Message message) {
|
public void setMessage(PrivateMessage message) {
|
||||||
mMessage = message;
|
mMessage = message;
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addReply(Message reply) {
|
public void addReply(PrivateMessage reply) {
|
||||||
int currentSize = getItemCount();
|
int currentSize = getItemCount();
|
||||||
|
|
||||||
if (mMessage != null) {
|
if (mMessage != null) {
|
||||||
@ -273,7 +282,7 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt
|
|||||||
copyImageView.setColorFilter(mSecondaryTextColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
copyImageView.setColorFilter(mSecondaryTextColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||||
|
|
||||||
copyImageView.setOnClickListener(view -> {
|
copyImageView.setOnClickListener(view -> {
|
||||||
Message message;
|
PrivateMessage message;
|
||||||
if (getBindingAdapterPosition() == 0) {
|
if (getBindingAdapterPosition() == 0) {
|
||||||
message = mMessage;
|
message = mMessage;
|
||||||
} else {
|
} else {
|
||||||
@ -282,7 +291,7 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt
|
|||||||
if (message != null) {
|
if (message != null) {
|
||||||
ClipboardManager clipboard = (ClipboardManager) mViewPrivateMessagesActivity.getSystemService(Context.CLIPBOARD_SERVICE);
|
ClipboardManager clipboard = (ClipboardManager) mViewPrivateMessagesActivity.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
if (clipboard != null) {
|
if (clipboard != null) {
|
||||||
ClipData clip = ClipData.newPlainText("simple text", message.getBody());
|
ClipData clip = ClipData.newPlainText("simple text", message.getContent());
|
||||||
clipboard.setPrimaryClip(clip);
|
clipboard.setPrimaryClip(clip);
|
||||||
if (android.os.Build.VERSION.SDK_INT < 33) {
|
if (android.os.Build.VERSION.SDK_INT < 33) {
|
||||||
Toast.makeText(mViewPrivateMessagesActivity, R.string.copy_success, Toast.LENGTH_SHORT).show();
|
Toast.makeText(mViewPrivateMessagesActivity, R.string.copy_success, Toast.LENGTH_SHORT).show();
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package eu.toldi.infinityforlemmy.events;
|
package eu.toldi.infinityforlemmy.events;
|
||||||
|
|
||||||
import eu.toldi.infinityforlemmy.message.Message;
|
import eu.toldi.infinityforlemmy.privatemessage.PrivateMessage;
|
||||||
|
|
||||||
public class RepliedToPrivateMessageEvent {
|
public class RepliedToPrivateMessageEvent {
|
||||||
public Message newReply;
|
public PrivateMessage newReply;
|
||||||
public int messagePosition;
|
public int messagePosition;
|
||||||
|
|
||||||
public RepliedToPrivateMessageEvent(Message newReply, int messagePosition) {
|
public RepliedToPrivateMessageEvent(PrivateMessage newReply, int messagePosition) {
|
||||||
this.newReply = newReply;
|
this.newReply = newReply;
|
||||||
this.messagePosition = messagePosition;
|
this.messagePosition = messagePosition;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
package eu.toldi.infinityforlemmy.utils;
|
package eu.toldi.infinityforlemmy.utils;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
public class LemmyUtils {
|
public class LemmyUtils {
|
||||||
public static String actorID2FullName(String url) {
|
public static String actorID2FullName(String url) {
|
||||||
String[] splitURL = url.split("/");
|
String[] splitURL = url.split("/");
|
||||||
@ -21,4 +30,25 @@ public class LemmyUtils {
|
|||||||
String domain = splitQualifiedName[1];
|
String domain = splitQualifiedName[1];
|
||||||
return "https://" + domain + "/u/" + userName;
|
return "https://" + domain + "/u/" + userName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Long dateStringToMills(String dateStr) {
|
||||||
|
long postTimeMillis = 0;
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||||
|
postTimeMillis = ZonedDateTime.parse(dateStr,
|
||||||
|
DateTimeFormatter.ISO_DATE_TIME.withZone(ZoneId.of("Z"))).toInstant().toEpochMilli();
|
||||||
|
} else {
|
||||||
|
dateStr = dateStr.substring(0, dateStr.lastIndexOf(".") + 4) + 'Z';
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.getDefault());
|
||||||
|
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
try {
|
||||||
|
Date date = sdf.parse(dateStr);
|
||||||
|
if (date != null) {
|
||||||
|
postTimeMillis = date.getTime();
|
||||||
|
}
|
||||||
|
} catch (ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return postTimeMillis;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package eu.toldi.infinityforlemmy.privatemessage
|
|||||||
|
|
||||||
import eu.toldi.infinityforlemmy.RetrofitHolder
|
import eu.toldi.infinityforlemmy.RetrofitHolder
|
||||||
import eu.toldi.infinityforlemmy.apis.LemmyAPI
|
import eu.toldi.infinityforlemmy.apis.LemmyAPI
|
||||||
|
import eu.toldi.infinityforlemmy.dto.PrivateMessageDTO
|
||||||
import eu.toldi.infinityforlemmy.dto.PrivateMessageReadDTO
|
import eu.toldi.infinityforlemmy.dto.PrivateMessageReadDTO
|
||||||
import eu.toldi.infinityforlemmy.utils.LemmyUtils
|
import eu.toldi.infinityforlemmy.utils.LemmyUtils
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
@ -71,6 +72,45 @@ class LemmyPrivateMessageAPI(val retrofitHolder: RetrofitHolder) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun sendPrivateMessage(
|
||||||
|
auth: String,
|
||||||
|
recipientId: Int,
|
||||||
|
content: String,
|
||||||
|
listener: PrivateMessageSentListener
|
||||||
|
) {
|
||||||
|
val api = retrofitHolder.retrofit.create(LemmyAPI::class.java)
|
||||||
|
|
||||||
|
api.privateMessageSend(PrivateMessageDTO(recipientId, content, auth)).enqueue(
|
||||||
|
object : retrofit2.Callback<String> {
|
||||||
|
override fun onResponse(
|
||||||
|
call: retrofit2.Call<String>,
|
||||||
|
response: retrofit2.Response<String>
|
||||||
|
) {
|
||||||
|
if (response.isSuccessful) {
|
||||||
|
listener.onPrivateMessageSentSuccess(
|
||||||
|
parsePrivateMessage(
|
||||||
|
JSONObject(response.body()!!).getJSONObject(
|
||||||
|
"private_message_view"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
listener.onPrivateMessageSentError()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onFailure(call: retrofit2.Call<String>, t: Throwable) {
|
||||||
|
listener.onPrivateMessageSentError()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PrivateMessageSentListener {
|
||||||
|
fun onPrivateMessageSentSuccess(privateMessage: PrivateMessage)
|
||||||
|
fun onPrivateMessageSentError()
|
||||||
|
}
|
||||||
|
|
||||||
interface PrivateMessageMarkedAsReadListener {
|
interface PrivateMessageMarkedAsReadListener {
|
||||||
fun onPrivateMessageMarkedAsReadSuccess()
|
fun onPrivateMessageMarkedAsReadSuccess()
|
||||||
fun onPrivateMessageMarkedAsReadError()
|
fun onPrivateMessageMarkedAsReadError()
|
||||||
@ -87,6 +127,7 @@ class LemmyPrivateMessageAPI(val retrofitHolder: RetrofitHolder) {
|
|||||||
val privateMessage = jsonObject.getJSONObject("private_message")
|
val privateMessage = jsonObject.getJSONObject("private_message")
|
||||||
val creator = jsonObject.getJSONObject("creator")
|
val creator = jsonObject.getJSONObject("creator")
|
||||||
val recipient = jsonObject.getJSONObject("recipient")
|
val recipient = jsonObject.getJSONObject("recipient")
|
||||||
|
val updated = privateMessage.optString("updated", "")
|
||||||
|
|
||||||
return PrivateMessage(
|
return PrivateMessage(
|
||||||
id = privateMessage.getInt("id"),
|
id = privateMessage.getInt("id"),
|
||||||
@ -95,8 +136,12 @@ class LemmyPrivateMessageAPI(val retrofitHolder: RetrofitHolder) {
|
|||||||
content = privateMessage.getString("content"),
|
content = privateMessage.getString("content"),
|
||||||
deleted = privateMessage.getBoolean("deleted"),
|
deleted = privateMessage.getBoolean("deleted"),
|
||||||
read = privateMessage.getBoolean("read"),
|
read = privateMessage.getBoolean("read"),
|
||||||
published = privateMessage.getString("published"),
|
published = LemmyUtils.dateStringToMills(privateMessage.getString("published")),
|
||||||
updated = privateMessage.optString("updated", ""),
|
updated = if (updated == "") {
|
||||||
|
null
|
||||||
|
} else {
|
||||||
|
LemmyUtils.dateStringToMills(updated)
|
||||||
|
},
|
||||||
creatorName = creator.getString("name"),
|
creatorName = creator.getString("name"),
|
||||||
creatorAvatar = creator.optString("avatar", ""),
|
creatorAvatar = creator.optString("avatar", ""),
|
||||||
creatorQualifiedName = LemmyUtils.actorID2FullName(creator.getString("actor_id")),
|
creatorQualifiedName = LemmyUtils.actorID2FullName(creator.getString("actor_id")),
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package eu.toldi.infinityforlemmy.privatemessage
|
package eu.toldi.infinityforlemmy.privatemessage
|
||||||
|
|
||||||
|
import android.os.Parcel
|
||||||
|
import android.os.Parcelable
|
||||||
|
|
||||||
data class PrivateMessage(
|
data class PrivateMessage(
|
||||||
val id: Int,
|
val id: Int,
|
||||||
val creatorId: Int,
|
val creatorId: Int,
|
||||||
@ -7,12 +10,67 @@ data class PrivateMessage(
|
|||||||
val content: String,
|
val content: String,
|
||||||
val deleted: Boolean,
|
val deleted: Boolean,
|
||||||
var read: Boolean,
|
var read: Boolean,
|
||||||
val published: String,
|
val published: Long,
|
||||||
val updated: String,
|
val updated: Long?,
|
||||||
val creatorName: String,
|
val creatorName: String,
|
||||||
val creatorAvatar: String,
|
val creatorAvatar: String,
|
||||||
val creatorQualifiedName: String,
|
val creatorQualifiedName: String,
|
||||||
val recipientName: String,
|
val recipientName: String,
|
||||||
val recipientAvatar: String,
|
val recipientAvatar: String,
|
||||||
val recipientQualifiedName: String
|
val recipientQualifiedName: String
|
||||||
)
|
) : Parcelable {
|
||||||
|
fun addReply(reply: PrivateMessage) {
|
||||||
|
replies.add(reply)
|
||||||
|
}
|
||||||
|
|
||||||
|
val replies = mutableListOf<PrivateMessage>()
|
||||||
|
|
||||||
|
constructor(parcel: Parcel) : this(
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readInt(),
|
||||||
|
parcel.readString()!!,
|
||||||
|
parcel.readByte() != 0.toByte(),
|
||||||
|
parcel.readByte() != 0.toByte(),
|
||||||
|
parcel.readLong(),
|
||||||
|
parcel.readValue(Long::class.java.classLoader) as? Long,
|
||||||
|
parcel.readString()!!,
|
||||||
|
parcel.readString()!!,
|
||||||
|
parcel.readString()!!,
|
||||||
|
parcel.readString()!!,
|
||||||
|
parcel.readString()!!,
|
||||||
|
parcel.readString()!!
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun writeToParcel(parcel: Parcel, flags: Int) {
|
||||||
|
parcel.writeInt(id)
|
||||||
|
parcel.writeInt(creatorId)
|
||||||
|
parcel.writeInt(recipientId)
|
||||||
|
parcel.writeString(content)
|
||||||
|
parcel.writeByte(if (deleted) 1 else 0)
|
||||||
|
parcel.writeByte(if (read) 1 else 0)
|
||||||
|
parcel.writeLong(published)
|
||||||
|
parcel.writeValue(updated)
|
||||||
|
parcel.writeString(creatorName)
|
||||||
|
parcel.writeString(creatorAvatar)
|
||||||
|
parcel.writeString(creatorQualifiedName)
|
||||||
|
parcel.writeString(recipientName)
|
||||||
|
parcel.writeString(recipientAvatar)
|
||||||
|
parcel.writeString(recipientQualifiedName)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun describeContents(): Int {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object CREATOR : Parcelable.Creator<PrivateMessage> {
|
||||||
|
override fun createFromParcel(parcel: Parcel): PrivateMessage {
|
||||||
|
return PrivateMessage(parcel)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun newArray(size: Int): Array<PrivateMessage?> {
|
||||||
|
return arrayOfNulls(size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -16,7 +16,7 @@ class PrivateMessageDataSource(
|
|||||||
PageKeyedDataSource<Int, PrivateMessage>() {
|
PageKeyedDataSource<Int, PrivateMessage>() {
|
||||||
|
|
||||||
|
|
||||||
val paginationNetworkStateLiveData: MutableLiveData<NetworkState>
|
val paginationNetworkStateLiveData: MutableLiveData<NetworkState> = MutableLiveData()
|
||||||
val initialLoadStateLiveData: MutableLiveData<NetworkState>
|
val initialLoadStateLiveData: MutableLiveData<NetworkState>
|
||||||
private val hasPostLiveData: MutableLiveData<Boolean>
|
private val hasPostLiveData: MutableLiveData<Boolean>
|
||||||
private var params: LoadParams<Int>? = null
|
private var params: LoadParams<Int>? = null
|
||||||
@ -24,7 +24,6 @@ class PrivateMessageDataSource(
|
|||||||
private val page = 1
|
private val page = 1
|
||||||
|
|
||||||
init {
|
init {
|
||||||
paginationNetworkStateLiveData = MutableLiveData()
|
|
||||||
initialLoadStateLiveData = MutableLiveData()
|
initialLoadStateLiveData = MutableLiveData()
|
||||||
hasPostLiveData = MutableLiveData()
|
hasPostLiveData = MutableLiveData()
|
||||||
}
|
}
|
||||||
@ -49,7 +48,7 @@ class PrivateMessageDataSource(
|
|||||||
if (privateMessages.isEmpty()) {
|
if (privateMessages.isEmpty()) {
|
||||||
callback.onResult(ArrayList(), null, null)
|
callback.onResult(ArrayList(), null, null)
|
||||||
} else {
|
} else {
|
||||||
callback.onResult(privateMessages, null, page + 1)
|
callback.onResult(privateMessages, null, 2)
|
||||||
}
|
}
|
||||||
initialLoadStateLiveData.postValue(NetworkState.LOADED)
|
initialLoadStateLiveData.postValue(NetworkState.LOADED)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user