Improved scrollToEnd and thumbnail bitmap for chat view

This commit is contained in:
Sylvain Berfini 2015-05-18 11:02:44 +02:00
parent 617beb7db6
commit b6771b24dc
3 changed files with 6 additions and 11 deletions

View file

@ -187,6 +187,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:divider="@android:color/transparent" android:divider="@android:color/transparent"
android:stackFromBottom="true" android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
android:cacheColorHint="@color/transparent" android:cacheColorHint="@color/transparent"
android:dividerHeight="1dp" android:dividerHeight="1dp"
android:layout_above="@id/remoteComposing" android:layout_above="@id/remoteComposing"

View file

@ -210,7 +210,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
LinphoneAddress from = cr.getPeerAddress(); LinphoneAddress from = cr.getPeerAddress();
if (from.asStringUriOnly().equals(sipUri)) { if (from.asStringUriOnly().equals(sipUri)) {
invalidate(); invalidate();
scrollToEnd();
} }
} }
@ -507,9 +506,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
} }
invalidate(); invalidate();
Log.i("Sent message current status: " + message.getStatus()); Log.i("Sent message current status: " + message.getStatus());
scrollToEnd();
} else if (!isNetworkReachable && LinphoneActivity.isInstanciated()) { } else if (!isNetworkReachable && LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().displayCustomToast(getString(R.string.error_network_unreachable), Toast.LENGTH_LONG); LinphoneActivity.instance().displayCustomToast(getString(R.string.error_network_unreachable), Toast.LENGTH_LONG);
} }
@ -618,6 +615,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
private void invalidate() { private void invalidate() {
adapter.refreshHistory(); adapter.refreshHistory();
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
chatRoom.markAsRead();
} }
private void resendMessage(int id) { private void resendMessage(int id) {
@ -635,11 +633,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
} }
} }
private void scrollToEnd() {
messagesList.smoothScrollToPosition(messagesList.getCount());
chatRoom.markAsRead();
}
private void copyTextMessageToClipboard(int id) { private void copyTextMessageToClipboard(int id) {
String msg = LinphoneActivity.instance().getChatStorage().getTextMessageForId(chatRoom, id); String msg = LinphoneActivity.instance().getChatStorage().getTextMessageForId(chatRoom, id);
if (msg != null) { if (msg != null) {

View file

@ -39,6 +39,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.media.ThumbnailUtils;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.provider.MediaStore; import android.provider.MediaStore;
@ -343,7 +344,7 @@ public class BubbleChat {
if (path.startsWith("content")) { if (path.startsWith("content")) {
try { try {
bm = MediaStore.Images.Media.getBitmap(mContext.getContentResolver(), Uri.parse(path)); bm = MediaStore.Images.Media.getBitmap(mContext.getContentResolver(), Uri.parse(path));
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Log.e(e); Log.e(e);
} catch (IOException e) { } catch (IOException e) {
@ -356,9 +357,9 @@ public class BubbleChat {
if (bm != null) { if (bm != null) {
if (bm.getWidth() >= bm.getHeight() && bm.getWidth() > SIZE_MAX) { if (bm.getWidth() >= bm.getHeight() && bm.getWidth() > SIZE_MAX) {
bm = Bitmap.createScaledBitmap(bm, SIZE_MAX, (SIZE_MAX * bm.getHeight()) / bm.getWidth(), false); bm = ThumbnailUtils.extractThumbnail(bm, SIZE_MAX, (SIZE_MAX * bm.getHeight()) / bm.getWidth());
} else if (bm.getHeight() >= bm.getWidth() && bm.getHeight() > SIZE_MAX) { } else if (bm.getHeight() >= bm.getWidth() && bm.getHeight() > SIZE_MAX) {
bm = Bitmap.createScaledBitmap(bm, (SIZE_MAX * bm.getWidth()) / bm.getHeight(), SIZE_MAX, false); bm = ThumbnailUtils.extractThumbnail(bm, (SIZE_MAX * bm.getWidth()) / bm.getHeight(), SIZE_MAX);
} }
} }
return bm; return bm;