From a00f7ced6c3d29ee0fd0cd5e7fcb5211e356c8c1 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 1 Jul 2020 11:53:18 +0800 Subject: [PATCH] Add an EditText and a send button in ViewPrivateMessagesActivity. Rewrite the code of fetchUserAvatar in ViewPrivateMessagesActivity. --- app/src/main/AndroidManifest.xml | 3 +- .../Activity/ViewPrivateMessagesActivity.java | 63 ++++++---- ...vateMessagesDetailRecyclerViewAdapter.java | 10 -- .../layout/activity_view_private_messages.xml | 112 +++++++++++++----- app/src/main/res/values/strings.xml | 1 + 5 files changed, 126 insertions(+), 63 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d1ff8e5d..a5f7d9c7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -26,7 +26,8 @@ + android:theme="@style/AppTheme.Slidable" + android:windowSoftInputMode="adjustResize" /> 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 diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PrivateMessagesDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PrivateMessagesDetailRecyclerViewAdapter.java index 270d89ac..4b17a966 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PrivateMessagesDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PrivateMessagesDetailRecyclerViewAdapter.java @@ -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) { diff --git a/app/src/main/res/layout/activity_view_private_messages.xml b/app/src/main/res/layout/activity_view_private_messages.xml index 3819bc4d..b808ede7 100644 --- a/app/src/main/res/layout/activity_view_private_messages.xml +++ b/app/src/main/res/layout/activity_view_private_messages.xml @@ -1,43 +1,97 @@ - + android:orientation="vertical"> - + android:layout_height="0dp" + android:layout_weight="1" + android:id="@+id/coordinator_layout_view_private_messages_activity" + tools:context=".Activity.ViewPrivateMessagesActivity"> - + + + + + + + + + + + android:clipToPadding="false" + app:layout_behavior="@string/appbar_scrolling_view_behavior" /> - + - - - - - + android:layout_height="wrap_content" + android:orientation="vertical" + android:layout_gravity="bottom"> - \ No newline at end of file + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 18faf6b8..020528fd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -762,6 +762,7 @@ Popular Notifications Messages + Message Fetch Gfycat video failed Fetch Redgifs video failed