mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-31 21:37:11 +01:00
Show all the messages in ViewPrivateMessagesActivity.
This commit is contained in:
parent
04f16d5664
commit
a888ae8435
@ -295,4 +295,4 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||||||
fab.setBackgroundTintList(ColorStateList.valueOf(customThemeWrapper.getColorPrimaryLightTheme()));
|
fab.setBackgroundTintList(ColorStateList.valueOf(customThemeWrapper.getColorPrimaryLightTheme()));
|
||||||
fab.setImageTintList(ColorStateList.valueOf(customThemeWrapper.getFABIconColor()));
|
fab.setImageTintList(ColorStateList.valueOf(customThemeWrapper.getFABIconColor()));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,9 +4,11 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
@ -17,14 +19,13 @@ import com.google.android.material.appbar.CollapsingToolbarLayout;
|
|||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
import com.r0adkll.slidr.Slidr;
|
import com.r0adkll.slidr.Slidr;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
|
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
|
||||||
|
import ml.docilealligator.infinityforreddit.Adapter.PrivateMessagesDetailRecyclerViewAdapter;
|
||||||
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
|
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
|
||||||
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
@ -36,8 +37,7 @@ import retrofit2.Retrofit;
|
|||||||
|
|
||||||
public class ViewPrivateMessagesActivity extends BaseActivity implements ActivityToolbarInterface {
|
public class ViewPrivateMessagesActivity extends BaseActivity implements ActivityToolbarInterface {
|
||||||
|
|
||||||
public static final String EXTRA_PRIVATE_MESSAGES = "EPM";
|
public static final String EXTRA_PRIVATE_MESSAGE = "EPM";
|
||||||
public static final String EXTRA_SENDER_USERNAME = "ESU";
|
|
||||||
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
|
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
|
||||||
private static final String ACCESS_TOKEN_STATE = "ATS";
|
private static final String ACCESS_TOKEN_STATE = "ATS";
|
||||||
@BindView(R.id.coordinator_layout_view_private_messages_activity)
|
@BindView(R.id.coordinator_layout_view_private_messages_activity)
|
||||||
@ -63,7 +63,8 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
|
|||||||
@Inject
|
@Inject
|
||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
private LinearLayoutManager mLinearLayoutManager;
|
private LinearLayoutManager mLinearLayoutManager;
|
||||||
private ArrayList<Message> privateMessages;
|
private PrivateMessagesDetailRecyclerViewAdapter mAdapter;
|
||||||
|
private Message privateMessage;
|
||||||
private boolean mNullAccessToken = false;
|
private boolean mNullAccessToken = false;
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
|
|
||||||
@ -96,6 +97,7 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
|
|||||||
|
|
||||||
int navBarHeight = getNavBarHeight();
|
int navBarHeight = getNavBarHeight();
|
||||||
if (navBarHeight > 0) {
|
if (navBarHeight > 0) {
|
||||||
|
mRecyclerView.setPadding(0, 0, 0, navBarHeight);
|
||||||
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mFab.getLayoutParams();
|
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mFab.getLayoutParams();
|
||||||
params.bottomMargin = navBarHeight;
|
params.bottomMargin = navBarHeight;
|
||||||
mFab.setLayoutParams(params);
|
mFab.setLayoutParams(params);
|
||||||
@ -104,9 +106,11 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
|
|||||||
}
|
}
|
||||||
|
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
privateMessages = intent.getParcelableArrayListExtra(EXTRA_PRIVATE_MESSAGES);
|
privateMessage = intent.getParcelableExtra(EXTRA_PRIVATE_MESSAGE);
|
||||||
|
|
||||||
mToolbar.setTitle(intent.getStringExtra(EXTRA_SENDER_USERNAME));
|
if (privateMessage != null) {
|
||||||
|
mToolbar.setTitle(privateMessage.getTitle());
|
||||||
|
}
|
||||||
setSupportActionBar(mToolbar);
|
setSupportActionBar(mToolbar);
|
||||||
setToolbarGoToTop(mToolbar);
|
setToolbarGoToTop(mToolbar);
|
||||||
|
|
||||||
@ -136,7 +140,22 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void bindView() {
|
private void bindView() {
|
||||||
|
mAdapter = new PrivateMessagesDetailRecyclerViewAdapter(this, privateMessage, mCustomThemeWrapper);
|
||||||
|
mLinearLayoutManager = new LinearLayoutManager(this);
|
||||||
|
mLinearLayoutManager.setReverseLayout(true);
|
||||||
|
mLinearLayoutManager.setStackFromEnd(true);
|
||||||
|
mRecyclerView.setLayoutManager(mLinearLayoutManager);
|
||||||
|
mRecyclerView.setAdapter(mAdapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||||
|
if (item.getItemId() == android.R.id.home) {
|
||||||
|
finish();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -102,8 +102,13 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl
|
|||||||
)
|
)
|
||||||
.build();
|
.build();
|
||||||
mAccessToken = accessToken;
|
mAccessToken = accessToken;
|
||||||
mMessageType = where.equals(FetchMessages.WHERE_MESSAGES) ?
|
if (where.equals(FetchMessages.WHERE_MESSAGES)) {
|
||||||
FetchMessages.MESSAGE_TYPE_PRIVATE_MESSAGE : FetchMessages.MESSAGE_TYPE_NOTIFICATION;
|
mMessageType = FetchMessages.MESSAGE_TYPE_PRIVATE_MESSAGE;
|
||||||
|
} else if (where.equals(FetchMessages.WHERE_MESSAGES_DETAIL)) {
|
||||||
|
mMessageType = FetchMessages.MESSAGE_TYPE_PRIVATE_MESSAGE_DETAIL;
|
||||||
|
} else {
|
||||||
|
mMessageType = FetchMessages.MESSAGE_TYPE_NOTIFICATION;
|
||||||
|
}
|
||||||
|
|
||||||
mColorAccent = customThemeWrapper.getColorAccent();
|
mColorAccent = customThemeWrapper.getColorAccent();
|
||||||
mMessageBackgroundColor = customThemeWrapper.getCardViewBackgroundColor();
|
mMessageBackgroundColor = customThemeWrapper.getCardViewBackgroundColor();
|
||||||
@ -149,15 +154,15 @@ public class MessageRecyclerViewAdapter extends PagedListAdapter<Message, Recycl
|
|||||||
mMarkwon.setMarkdown(((DataViewHolder) holder).contentCustomMarkwonView, message.getBody());
|
mMarkwon.setMarkdown(((DataViewHolder) holder).contentCustomMarkwonView, message.getBody());
|
||||||
|
|
||||||
((DataViewHolder) holder).itemView.setOnClickListener(view -> {
|
((DataViewHolder) holder).itemView.setOnClickListener(view -> {
|
||||||
if (message.getContext() != null && !message.getContext().equals("")) {
|
if (mMessageType == FetchMessages.MESSAGE_TYPE_NOTIFICATION
|
||||||
|
&& message.getContext() != null && !message.getContext().equals("")) {
|
||||||
Uri uri = LinkResolverActivity.getRedditUriByPath(message.getContext());
|
Uri uri = LinkResolverActivity.getRedditUriByPath(message.getContext());
|
||||||
Intent intent = new Intent(mContext, LinkResolverActivity.class);
|
Intent intent = new Intent(mContext, LinkResolverActivity.class);
|
||||||
intent.setData(uri);
|
intent.setData(uri);
|
||||||
mContext.startActivity(intent);
|
mContext.startActivity(intent);
|
||||||
} else if (mMessageType == FetchMessages.MESSAGE_TYPE_PRIVATE_MESSAGE) {
|
} else if (mMessageType == FetchMessages.MESSAGE_TYPE_PRIVATE_MESSAGE) {
|
||||||
Intent intent = new Intent(mContext, ViewPrivateMessagesActivity.class);
|
Intent intent = new Intent(mContext, ViewPrivateMessagesActivity.class);
|
||||||
intent.putExtra(ViewPrivateMessagesActivity.EXTRA_SENDER_USERNAME, message.getAuthor());
|
intent.putExtra(ViewPrivateMessagesActivity.EXTRA_PRIVATE_MESSAGE, message);
|
||||||
intent.putExtra(ViewPrivateMessagesActivity.EXTRA_PRIVATE_MESSAGES, message.getReplies());
|
|
||||||
mContext.startActivity(intent);
|
mContext.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,164 @@
|
|||||||
|
package ml.docilealligator.infinityforreddit.Adapter;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.text.style.SuperscriptSpan;
|
||||||
|
import android.text.util.Linkify;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import butterknife.BindView;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
import io.noties.markwon.AbstractMarkwonPlugin;
|
||||||
|
import io.noties.markwon.Markwon;
|
||||||
|
import io.noties.markwon.MarkwonConfiguration;
|
||||||
|
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
|
||||||
|
import io.noties.markwon.linkify.LinkifyPlugin;
|
||||||
|
import io.noties.markwon.simple.ext.SimpleExtPlugin;
|
||||||
|
import ml.docilealligator.infinityforreddit.Activity.LinkResolverActivity;
|
||||||
|
import ml.docilealligator.infinityforreddit.Activity.ViewUserDetailActivity;
|
||||||
|
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
|
||||||
|
import ml.docilealligator.infinityforreddit.Message;
|
||||||
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
|
|
||||||
|
public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
private Message mMessage;
|
||||||
|
private Context mContext;
|
||||||
|
private Markwon mMarkwon;
|
||||||
|
private int mMessageBackgroundColor;
|
||||||
|
private int mUsernameColor;
|
||||||
|
private int mPrimaryTextColor;
|
||||||
|
private int mSecondaryTextColor;
|
||||||
|
private int mUnreadMessageBackgroundColor;
|
||||||
|
|
||||||
|
public PrivateMessagesDetailRecyclerViewAdapter(Context context, Message message, CustomThemeWrapper customThemeWrapper) {
|
||||||
|
mMessage = message;
|
||||||
|
mContext = context;
|
||||||
|
mMarkwon = Markwon.builder(mContext)
|
||||||
|
.usePlugin(new AbstractMarkwonPlugin() {
|
||||||
|
@Override
|
||||||
|
public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) {
|
||||||
|
builder.linkResolver((view, link) -> {
|
||||||
|
Intent intent = new Intent(mContext, LinkResolverActivity.class);
|
||||||
|
Uri uri = Uri.parse(link);
|
||||||
|
if (uri.getScheme() == null && uri.getHost() == null) {
|
||||||
|
intent.setData(LinkResolverActivity.getRedditUriByPath(link));
|
||||||
|
} else {
|
||||||
|
intent.setData(uri);
|
||||||
|
}
|
||||||
|
mContext.startActivity(intent);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.usePlugin(StrikethroughPlugin.create())
|
||||||
|
.usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS))
|
||||||
|
.usePlugin(SimpleExtPlugin.create(plugin ->
|
||||||
|
plugin.addExtension(1, '^', (configuration, props) -> {
|
||||||
|
return new SuperscriptSpan();
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.build();
|
||||||
|
mMessageBackgroundColor = customThemeWrapper.getCardViewBackgroundColor();
|
||||||
|
mUsernameColor = customThemeWrapper.getUsername();
|
||||||
|
mPrimaryTextColor = customThemeWrapper.getPrimaryTextColor();
|
||||||
|
mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor();
|
||||||
|
mUnreadMessageBackgroundColor = customThemeWrapper.getUnreadMessageBackgroundColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
return new DataViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_message, parent, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||||
|
if (holder instanceof DataViewHolder) {
|
||||||
|
Message message;
|
||||||
|
if (holder.getAdapterPosition() == 0) {
|
||||||
|
message = mMessage;
|
||||||
|
} else {
|
||||||
|
message = mMessage.getReplies().get(holder.getAdapterPosition() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message != null) {
|
||||||
|
if (message.isNew()) {
|
||||||
|
((DataViewHolder) holder).itemView.setBackgroundColor(
|
||||||
|
mUnreadMessageBackgroundColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
((DataViewHolder) holder).authorTextView.setText(message.getAuthor());
|
||||||
|
String subject = message.getSubject().substring(0, 1).toUpperCase() + message.getSubject().substring(1);
|
||||||
|
((DataViewHolder) holder).subjectTextView.setText(subject);
|
||||||
|
mMarkwon.setMarkdown(((DataViewHolder) holder).contentCustomMarkwonView, message.getBody());
|
||||||
|
|
||||||
|
((DataViewHolder) holder).authorTextView.setOnClickListener(view -> {
|
||||||
|
Intent intent = new Intent(mContext, ViewUserDetailActivity.class);
|
||||||
|
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, message.getAuthor());
|
||||||
|
mContext.startActivity(intent);
|
||||||
|
});
|
||||||
|
|
||||||
|
((DataViewHolder) holder).contentCustomMarkwonView.setOnClickListener(view -> ((DataViewHolder) holder).itemView.performClick());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
if (mMessage == null) {
|
||||||
|
return 0;
|
||||||
|
} else if (mMessage.getReplies() == null) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 1 + mMessage.getReplies().size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(Message message) {
|
||||||
|
mMessage = message;
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addReply(Message reply) {
|
||||||
|
int currentSize = getItemCount();
|
||||||
|
|
||||||
|
if (mMessage != null) {
|
||||||
|
mMessage.addReply(reply);
|
||||||
|
} else {
|
||||||
|
mMessage = reply;
|
||||||
|
}
|
||||||
|
|
||||||
|
notifyItemInserted(currentSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
class DataViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
@BindView(R.id.author_text_view_item_message)
|
||||||
|
TextView authorTextView;
|
||||||
|
@BindView(R.id.subject_text_view_item_message)
|
||||||
|
TextView subjectTextView;
|
||||||
|
@BindView(R.id.title_text_view_item_message)
|
||||||
|
TextView titleTextView;
|
||||||
|
@BindView(R.id.content_custom_markwon_view_item_message)
|
||||||
|
TextView contentCustomMarkwonView;
|
||||||
|
|
||||||
|
DataViewHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
ButterKnife.bind(this, itemView);
|
||||||
|
|
||||||
|
titleTextView.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
itemView.setBackgroundColor(mMessageBackgroundColor);
|
||||||
|
authorTextView.setTextColor(mUsernameColor);
|
||||||
|
subjectTextView.setTextColor(mPrimaryTextColor);
|
||||||
|
titleTextView.setTextColor(mPrimaryTextColor);
|
||||||
|
contentCustomMarkwonView.setTextColor(mSecondaryTextColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -30,8 +30,10 @@ public class FetchMessages {
|
|||||||
public static final String WHERE_SENT = "sent";
|
public static final String WHERE_SENT = "sent";
|
||||||
public static final String WHERE_COMMENTS = "comments";
|
public static final String WHERE_COMMENTS = "comments";
|
||||||
public static final String WHERE_MESSAGES = "messages";
|
public static final String WHERE_MESSAGES = "messages";
|
||||||
|
public static final String WHERE_MESSAGES_DETAIL = "messages_detail";
|
||||||
public static final int MESSAGE_TYPE_NOTIFICATION = 0;
|
public static final int MESSAGE_TYPE_NOTIFICATION = 0;
|
||||||
public static final int MESSAGE_TYPE_PRIVATE_MESSAGE = 1;
|
public static final int MESSAGE_TYPE_PRIVATE_MESSAGE = 1;
|
||||||
|
public static final int MESSAGE_TYPE_PRIVATE_MESSAGE_DETAIL = 2;
|
||||||
|
|
||||||
static void fetchInbox(Retrofit oauthRetrofit, Locale locale, String accessToken, String where,
|
static void fetchInbox(Retrofit oauthRetrofit, Locale locale, String accessToken, String where,
|
||||||
String after, int messageType, FetchMessagesListener fetchMessagesListener) {
|
String after, int messageType, FetchMessagesListener fetchMessagesListener) {
|
||||||
|
@ -176,6 +176,13 @@ public class Message implements Parcelable {
|
|||||||
this.replies = replies;
|
this.replies = replies;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addReply(Message reply) {
|
||||||
|
if (replies == null) {
|
||||||
|
replies = new ArrayList<>();
|
||||||
|
}
|
||||||
|
replies.add(reply);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int describeContents() {
|
public int describeContents() {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -46,7 +46,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="bottom|end"
|
android:layout_gravity="bottom|end"
|
||||||
android:layout_margin="@dimen/fab_margin"
|
android:layout_margin="@dimen/fab_margin"
|
||||||
app:srcCompat="@drawable/ic_add_day_night_24dp"
|
app:srcCompat="@drawable/ic_add_day_night_24dp" />
|
||||||
app:tint="@android:color/white" />
|
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
Loading…
Reference in New Issue
Block a user