Add an EditText and a send button in ViewPrivateMessagesActivity. Rewrite the code of fetchUserAvatar in ViewPrivateMessagesActivity.

This commit is contained in:
Alex Ning 2020-07-01 11:53:18 +08:00
parent bde545b75f
commit a00f7ced6c
5 changed files with 126 additions and 63 deletions

View File

@ -26,7 +26,8 @@
<activity android:name=".Activity.ViewPrivateMessagesActivity"
android:parentActivityName=".Activity.MainActivity"
android:theme="@style/AppTheme.Slidable" />
android:theme="@style/AppTheme.Slidable"
android:windowSoftInputMode="adjustResize" />
<service
android:name=".Service.DownloadRedditVideoService"

View File

@ -2,11 +2,14 @@ package ml.docilealligator.infinityforreddit.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
@ -20,6 +23,8 @@ import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.appbar.CollapsingToolbarLayout;
import com.r0adkll.slidr.Slidr;
import java.util.ArrayList;
import javax.inject.Inject;
import javax.inject.Named;
@ -44,6 +49,8 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
private static final String ACCESS_TOKEN_STATE = "ATS";
private static final String ACCOUNT_NAME_STATE = "ANS";
private static final String USER_AVATAR_STATE = "UAS";
@BindView(R.id.linear_layout_view_private_messages_activity)
LinearLayout mLinearLayout;
@BindView(R.id.coordinator_layout_view_private_messages_activity)
CoordinatorLayout mCoordinatorLayout;
@BindView(R.id.collapsing_toolbar_layout_view_private_messages_activity)
@ -54,10 +61,19 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
Toolbar mToolbar;
@BindView(R.id.recycler_view_view_private_messages)
RecyclerView mRecyclerView;
@BindView(R.id.edit_text_divider_view_private_messages_activity)
View mDivider;
@BindView(R.id.edit_text_view_private_messages_activity)
EditText mEditText;
@BindView(R.id.send_image_view_view_private_messages_activity)
ImageView mSendImageView;
@Inject
@Named("oauth")
Retrofit mOauthRetrofit;
@Inject
@Named("no_oauth")
Retrofit mRetrofit;
@Inject
RedditDataRoomDatabase mRedditDataRoomDatabase;
@Inject
@Named("default")
@ -71,11 +87,15 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
private String mAccessToken;
private String mAccountName;
private String mUserAvatar;
private ArrayList<ProvideUserAvatarCallback> provideUserAvatarCallbacks;
private LoadUserDataAsyncTask loadUserDataAsyncTask;
@Override
protected void onCreate(Bundle savedInstanceState) {
((Infinity) getApplication()).getAppComponent().inject(this);
setImmersiveModeNotApplicable();
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_private_messages);
@ -88,22 +108,8 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
Slidr.attach(this);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Window window = getWindow();
if (isChangeStatusBarIconColor()) {
addOnOffsetChangedListener(mAppBarLayout);
}
if (isImmersiveInterface()) {
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
adjustToolbar(mToolbar);
int navBarHeight = getNavBarHeight();
if (navBarHeight > 0) {
mRecyclerView.setPadding(0, 0, 0, navBarHeight);
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
addOnOffsetChangedListener(mAppBarLayout);
}
Intent intent = getIntent();
@ -115,6 +121,8 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
setSupportActionBar(mToolbar);
setToolbarGoToTop(mToolbar);
provideUserAvatarCallbacks = new ArrayList<>();
if (savedInstanceState != null) {
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
@ -152,10 +160,17 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
public void fetchUserAvatar(String username, ProvideUserAvatarCallback provideUserAvatarCallback) {
if (mUserAvatar == null) {
new LoadUserDataAsyncTask(mRedditDataRoomDatabase.userDao(), username, mOauthRetrofit, iconImageUrl -> {
mUserAvatar = iconImageUrl;
provideUserAvatarCallback.fetchAvatarSuccess(iconImageUrl);
}).execute();
provideUserAvatarCallbacks.add(provideUserAvatarCallback);
if (loadUserDataAsyncTask == null) {
loadUserDataAsyncTask = new LoadUserDataAsyncTask(mRedditDataRoomDatabase.userDao(), username, mRetrofit, iconImageUrl -> {
mUserAvatar = iconImageUrl;
for (ProvideUserAvatarCallback provideUserAvatarCallbackInArrayList : provideUserAvatarCallbacks) {
provideUserAvatarCallbackInArrayList.fetchAvatarSuccess(iconImageUrl);
}
provideUserAvatarCallbacks.clear();
});
loadUserDataAsyncTask.execute();
}
} else {
provideUserAvatarCallback.fetchAvatarSuccess(mUserAvatar);
}
@ -196,8 +211,10 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
@Override
protected void applyCustomTheme() {
mCoordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
mLinearLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
applyAppBarLayoutAndToolbarTheme(mAppBarLayout, mToolbar);
mDivider.setBackgroundColor(mCustomThemeWrapper.getDividerColor());
mSendImageView.setColorFilter(Color.parseColor("#4185F4"), android.graphics.PorterDuff.Mode.SRC_IN);
}
@Override

View File

@ -5,7 +5,6 @@ import android.graphics.Color;
import android.net.Uri;
import android.text.style.SuperscriptSpan;
import android.text.util.Linkify;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -122,7 +121,6 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt
((MessageViewHolder) holder).messageTextView.setOnClickListener(view -> ((MessageViewHolder) holder).itemView.performClick());
((MessageViewHolder) holder).messageTextView.setOnClickListener(view -> {
Log.i("asfasdf", "asdf " + ((MessageViewHolder) holder).timeTextView.getHeight());
if (((MessageViewHolder) holder).timeTextView.getVisibility() != View.VISIBLE) {
((MessageViewHolder) holder).timeTextView.setVisibility(View.VISIBLE);
mViewPrivateMessagesActivity.delayTransition();
@ -130,13 +128,6 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt
((MessageViewHolder) holder).timeTextView.setVisibility(View.GONE);
mViewPrivateMessagesActivity.delayTransition();
}
/*if (((MessageViewHolder) holder).timeTextView.getHeight() == 0) {
((MessageViewHolder) holder).timeTextView.getLayoutParams().height = ConstraintLayout.LayoutParams.WRAP_CONTENT;
mViewPrivateMessagesActivity.delayTransition();
} else {
mViewPrivateMessagesActivity.delayTransition();
((MessageViewHolder) holder).timeTextView.getLayoutParams().height = 0;
}*/
});
((MessageViewHolder) holder).timeTextView.setText(Utils.getElapsedTime(mViewPrivateMessagesActivity, message.getTimeUTC()));
@ -202,7 +193,6 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt
super.onViewRecycled(holder);
if (holder instanceof MessageViewHolder) {
((MessageViewHolder) holder).messageTextView.setBackground(null);
//((MessageViewHolder) holder).timeTextView.getLayoutParams().height = 0;
((MessageViewHolder) holder).timeTextView.setVisibility(View.GONE);
}
if (holder instanceof ReceivedMessageViewHolder) {

View File

@ -1,43 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linear_layout_view_private_messages_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/coordinator_layout_view_private_messages_activity"
tools:context=".Activity.ViewPrivateMessagesActivity">
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar_layout_view_private_messages_activity"
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/coordinator_layout_view_private_messages_activity"
tools:context=".Activity.ViewPrivateMessagesActivity">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout_view_private_messages_activity"
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar_layout_view_private_messages_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout_view_private_messages_activity"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways"
app:titleEnabled="false"
app:toolbarId="@+id/toolbar_view_private_messages_activity">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_view_private_messages_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:navigationIcon="?attr/homeAsUpIndicator" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_view_private_messages"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|enterAlways"
app:titleEnabled="false"
app:toolbarId="@+id/toolbar_view_private_messages_activity">
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar_view_private_messages_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:navigationIcon="?attr/homeAsUpIndicator" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view_view_private_messages"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom">
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<View
android:id="@+id/edit_text_divider_view_private_messages_activity"
android:layout_width="match_parent"
android:layout_height="1dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@+id/edit_text_view_private_messages_activity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="16dp"
android:hint="@string/message"
android:inputType="textMultiLine"
android:textSize="?attr/font_default"
android:background="#00000000"
android:textColor="?attr/primaryTextColor"
android:fontFamily="?attr/font_family"
android:maxLines="3" />
<ImageView
android:id="@+id/send_image_view_view_private_messages_activity"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_gravity="center_vertical"
android:scaleType="center"
android:src="@drawable/ic_send_black_24dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackgroundBorderless" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@ -762,6 +762,7 @@
<string name="popular">Popular</string>
<string name="notifications">Notifications</string>
<string name="messages">Messages</string>
<string name="message">Message</string>
<string name="fetch_gfycat_video_failed">Fetch Gfycat video failed</string>
<string name="fetch_redgifs_video_failed">Fetch Redgifs video failed</string>