decrease delay when scrolling to position

This commit is contained in:
Daniel Gultsch 2018-03-08 16:37:45 +01:00
parent 5e32b4ab17
commit 4227c63e5d
1 changed files with 30 additions and 29 deletions

View File

@ -134,15 +134,14 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
private final PendingItem<Bundle> pendingExtras = new PendingItem<>(); private final PendingItem<Bundle> pendingExtras = new PendingItem<>();
private final PendingItem<Uri> pendingTakePhotoUri = new PendingItem<>(); private final PendingItem<Uri> pendingTakePhotoUri = new PendingItem<>();
private final PendingItem<ScrollState> pendingScrollState = new PendingItem<>(); private final PendingItem<ScrollState> pendingScrollState = new PendingItem<>();
private final PendingItem<Message> pendingMessage = new PendingItem<>();
public Uri mPendingEditorContent = null; public Uri mPendingEditorContent = null;
protected MessageAdapter messageListAdapter; protected MessageAdapter messageListAdapter;
private Conversation conversation; private Conversation conversation;
private FragmentConversationBinding binding; private FragmentConversationBinding binding;
private Toast messageLoaderToast; private Toast messageLoaderToast;
private ConversationsActivity activity; private ConversationsActivity activity;
private boolean reInitRequiredOnStart = true; private boolean reInitRequiredOnStart = true;
private OnClickListener clickToMuc = new OnClickListener() { private OnClickListener clickToMuc = new OnClickListener() {
@Override @Override
@ -258,7 +257,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
} }
} }
}; };
private EditMessage.OnCommitContentListener mEditorContentListener = new EditMessage.OnCommitContentListener() { private EditMessage.OnCommitContentListener mEditorContentListener = new EditMessage.OnCommitContentListener() {
@Override @Override
public boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags, Bundle opts, String[] contentMimeTypes) { public boolean onCommitContent(InputContentInfoCompat inputContentInfo, int flags, Bundle opts, String[] contentMimeTypes) {
@ -328,7 +326,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
} }
} }
}; };
protected OnClickListener clickToDecryptListener = new OnClickListener() { protected OnClickListener clickToDecryptListener = new OnClickListener() {
@Override @Override
@ -407,8 +404,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
private int lastCompletionCursor; private int lastCompletionCursor;
private boolean firstWord = false; private boolean firstWord = false;
private Message mPendingDownloadableMessage; private Message mPendingDownloadableMessage;
private final PendingItem<Message> pendingMessage = new PendingItem<>();
private static ConversationFragment findConversationFragment(Activity activity) { private static ConversationFragment findConversationFragment(Activity activity) {
Fragment fragment = activity.getFragmentManager().findFragmentById(R.id.main_fragment); Fragment fragment = activity.getFragmentManager().findFragmentById(R.id.main_fragment);
@ -474,6 +469,24 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
return getConversation(activity, R.id.main_fragment); return getConversation(activity, R.id.main_fragment);
} }
private static boolean allGranted(int[] grantResults) {
for (int grantResult : grantResults) {
if (grantResult != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
return true;
}
private static String getFirstDenied(int[] grantResults, String[] permissions) {
for (int i = 0; i < grantResults.length; ++i) {
if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
return permissions[i];
}
}
return null;
}
private int getIndexOf(String uuid, List<Message> messages) { private int getIndexOf(String uuid, List<Message> messages) {
if (uuid == null) { if (uuid == null) {
return messages.size() - 1; return messages.size() - 1;
@ -1286,28 +1299,10 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
} else { } else {
res = R.string.no_storage_permission; res = R.string.no_storage_permission;
} }
Toast.makeText(getActivity(),res, Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity(), res, Toast.LENGTH_SHORT).show();
} }
} }
private static boolean allGranted(int[] grantResults) {
for(int grantResult : grantResults) {
if (grantResult != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
return true;
}
private static String getFirstDenied(int[] grantResults, String[] permissions) {
for(int i = 0; i < grantResults.length; ++i) {
if (grantResults[i] == PackageManager.PERMISSION_DENIED) {
return permissions[i];
}
}
return null;
}
public void startDownloadable(Message message) { public void startDownloadable(Message message) {
if (!Config.ONLY_INTERNAL_STORAGE && !hasStoragePermission(REQUEST_START_DOWNLOAD)) { if (!Config.ONLY_INTERNAL_STORAGE && !hasStoragePermission(REQUEST_START_DOWNLOAD)) {
this.mPendingDownloadableMessage = message; this.mPendingDownloadableMessage = message;
@ -1349,11 +1344,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
builder.setTitle(R.string.disable_notifications); builder.setTitle(R.string.disable_notifications);
final int[] durations = getResources().getIntArray(R.array.mute_options_durations); final int[] durations = getResources().getIntArray(R.array.mute_options_durations);
final CharSequence[] labels = new CharSequence[durations.length]; final CharSequence[] labels = new CharSequence[durations.length];
for(int i = 0; i < durations.length; ++i) { for (int i = 0; i < durations.length; ++i) {
if (durations[i] == -1) { if (durations[i] == -1) {
labels[i] = getString(R.string.until_further_notice); labels[i] = getString(R.string.until_further_notice);
} else { } else {
labels[i] = TimeframeUtils.resolve(activity,1000L * durations[i]); labels[i] = TimeframeUtils.resolve(activity, 1000L * durations[i]);
} }
} }
builder.setItems(labels, (dialog, which) -> { builder.setItems(labels, (dialog, which) -> {
@ -1587,7 +1582,8 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
new Handler().post(() -> { new Handler().post(() -> {
int size = messageList.size(); int size = messageList.size();
this.binding.messagesView.setSelection(size - 1); this.binding.messagesView.setSelection(size - 1);
}); } });
}
private void copyUrl(Message message) { private void copyUrl(Message message) {
final String url; final String url;
@ -1819,7 +1815,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
int i = getIndexOf(first.getUuid(), this.messageList); int i = getIndexOf(first.getUuid(), this.messageList);
pos = i < 0 ? bottom : i; pos = i < 0 ? bottom : i;
} }
this.binding.messagesView.post(() -> this.binding.messagesView.setSelection(pos)); setSelection(pos);
} }
} }
@ -1829,6 +1825,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
return true; return true;
} }
private void setSelection(int pos) {
this.binding.messagesView.setSelection(pos);
this.binding.messagesView.post(() -> this.binding.messagesView.setSelection(pos));
}
private boolean scrolledToBottom() { private boolean scrolledToBottom() {
if (this.binding == null) { if (this.binding == null) {
return false; return false;