Maintain RecyclerView position when showing and hiding the keyboard in ViewPrivateMessagesActivity.

This commit is contained in:
Alex Ning 2020-07-02 11:13:10 +08:00
parent 2fbc4d02c8
commit 1958ad77e3
2 changed files with 14 additions and 14 deletions

View File

@ -24,16 +24,15 @@
android:usesCleartextTraffic="true" android:usesCleartextTraffic="true"
tools:replace="android:label"> tools:replace="android:label">
<activity android:name=".Activity.ViewPrivateMessagesActivity"
android:parentActivityName=".Activity.MainActivity"
android:theme="@style/AppTheme.Slidable"
android:windowSoftInputMode="adjustResize" />
<service <service
android:name=".Service.DownloadRedditVideoService" android:name=".Service.DownloadRedditVideoService"
android:enabled="true" android:enabled="true"
android:exported="false" /> android:exported="false" />
<activity android:name=".Activity.ViewPrivateMessagesActivity"
android:parentActivityName=".Activity.MainActivity"
android:theme="@style/AppTheme.Slidable"
android:windowSoftInputMode="adjustResize" />
<activity <activity
android:name=".Activity.ViewImgurMediaActivity" android:name=".Activity.ViewImgurMediaActivity"
android:configChanges="orientation|screenSize|layoutDirection" android:configChanges="orientation|screenSize|layoutDirection"

View File

@ -93,8 +93,8 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
private String mAccessToken; private String mAccessToken;
private String mAccountName; private String mAccountName;
private String mUserAvatar; private String mUserAvatar;
private ArrayList<ProvideUserAvatarCallback> provideUserAvatarCallbacks; private ArrayList<ProvideUserAvatarCallback> mProvideUserAvatarCallbacks;
private LoadUserDataAsyncTask loadUserDataAsyncTask; private LoadUserDataAsyncTask mLoadUserDataAsyncTask;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -127,7 +127,7 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
setSupportActionBar(mToolbar); setSupportActionBar(mToolbar);
setToolbarGoToTop(mToolbar); setToolbarGoToTop(mToolbar);
provideUserAvatarCallbacks = new ArrayList<>(); mProvideUserAvatarCallbacks = new ArrayList<>();
if (savedInstanceState != null) { if (savedInstanceState != null) {
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE); mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
@ -160,6 +160,7 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
private void bindView() { private void bindView() {
mAdapter = new PrivateMessagesDetailRecyclerViewAdapter(this, privateMessage, mAccountName, mCustomThemeWrapper); mAdapter = new PrivateMessagesDetailRecyclerViewAdapter(this, privateMessage, mAccountName, mCustomThemeWrapper);
mLinearLayoutManager = new LinearLayoutManager(this); mLinearLayoutManager = new LinearLayoutManager(this);
mLinearLayoutManager.setStackFromEnd(true);
mRecyclerView.setLayoutManager(mLinearLayoutManager); mRecyclerView.setLayoutManager(mLinearLayoutManager);
mRecyclerView.setAdapter(mAdapter); mRecyclerView.setAdapter(mAdapter);
goToBottom(); goToBottom();
@ -229,16 +230,16 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
public void fetchUserAvatar(String username, ProvideUserAvatarCallback provideUserAvatarCallback) { public void fetchUserAvatar(String username, ProvideUserAvatarCallback provideUserAvatarCallback) {
if (mUserAvatar == null) { if (mUserAvatar == null) {
provideUserAvatarCallbacks.add(provideUserAvatarCallback); mProvideUserAvatarCallbacks.add(provideUserAvatarCallback);
if (loadUserDataAsyncTask == null) { if (mLoadUserDataAsyncTask == null) {
loadUserDataAsyncTask = new LoadUserDataAsyncTask(mRedditDataRoomDatabase.userDao(), username, mRetrofit, iconImageUrl -> { mLoadUserDataAsyncTask = new LoadUserDataAsyncTask(mRedditDataRoomDatabase.userDao(), username, mRetrofit, iconImageUrl -> {
mUserAvatar = iconImageUrl; mUserAvatar = iconImageUrl;
for (ProvideUserAvatarCallback provideUserAvatarCallbackInArrayList : provideUserAvatarCallbacks) { for (ProvideUserAvatarCallback provideUserAvatarCallbackInArrayList : mProvideUserAvatarCallbacks) {
provideUserAvatarCallbackInArrayList.fetchAvatarSuccess(iconImageUrl); provideUserAvatarCallbackInArrayList.fetchAvatarSuccess(iconImageUrl);
} }
provideUserAvatarCallbacks.clear(); mProvideUserAvatarCallbacks.clear();
}); });
loadUserDataAsyncTask.execute(); mLoadUserDataAsyncTask.execute();
} }
} else { } else {
provideUserAvatarCallback.fetchAvatarSuccess(mUserAvatar); provideUserAvatarCallback.fetchAvatarSuccess(mUserAvatar);