Lots of work on files preview

This commit is contained in:
Mario Danic 2018-10-09 14:53:54 +02:00
parent 435b73e3f9
commit a788c20b4a
12 changed files with 370 additions and 42 deletions

View File

@ -115,7 +115,7 @@ public class MagicOutcomingTextMessageViewHolder extends MessageHolders.Outcomin
}
Resources resources = NextcloudTalkApplication.getSharedApplication().getResources();
if (message.isGrouped()) {
if (message.isGrouped) {
Drawable bubbleDrawable = DisplayUtils.getMessageSelector(resources.getColor(R.color.colorPrimary),
resources.getColor(R.color.transparent),
resources.getColor(R.color.colorPrimary), R.drawable.shape_grouped_outcoming_message);

View File

@ -0,0 +1,73 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.adapters.messages;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.TextView;
import com.nextcloud.talk.R;
import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.models.json.chat.ChatMessage;
import com.stfalcon.chatkit.messages.MessageHolders;
import com.stfalcon.chatkit.utils.RoundedImageView;
import butterknife.BindView;
import butterknife.ButterKnife;
public class MagicPreviewMessageViewHolder extends MessageHolders.IncomingImageMessageViewHolder<ChatMessage> {
@BindView(R.id.messageText)
TextView messageText;
public MagicPreviewMessageViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
@Override
public void onBind(ChatMessage message) {
super.onBind(message);
if (userAvatar != null) {
if (message.isGrouped) {
userAvatar.setVisibility(View.INVISIBLE);
} else {
userAvatar.setVisibility(View.VISIBLE);
}
}
if (message.isGrouped) {
((RoundedImageView) image).setCorners(R.dimen.message_bubble_corners_radius, R.dimen.message_bubble_corners_radius, 0, 0);
} else if (message.getUser().getId().equals(message.activeUserId)) {
((RoundedImageView) image).setCorners(R.dimen.message_bubble_corners_radius, 0, 0, 0);
} else {
((RoundedImageView) image).setCorners(0, R.dimen.message_bubble_corners_radius, 0, 0);
}
messageText.setText(message.getSelectedIndividualHashMap().get("name"));
image.setOnClickListener(v -> {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(message.getSelectedIndividualHashMap().get("link")));
NextcloudTalkApplication.getSharedApplication().getApplicationContext().startActivity(browserIntent);
});
}
}

View File

@ -72,15 +72,6 @@ public class MagicSystemMessageViewHolder extends MessageHolders.IncomingTextMes
messageString = DisplayUtils.searchAndColor(message.getText(),
messageString, "@" + individualHashMap.get("name"), color);
} else if (individualHashMap.get("type").equals("file")) {
color = context.getResources().getColor(R.color
.colorPrimary);
messageString = DisplayUtils.searchAndColor(message.getText(), messageString, individualHashMap
.get("name"), color);
itemView.setOnClickListener(v -> {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(individualHashMap.get("link")));
context.startActivity(browserIntent);
});
}
}
}

View File

@ -61,6 +61,7 @@ import com.nextcloud.talk.R;
import com.nextcloud.talk.activities.MagicCallActivity;
import com.nextcloud.talk.adapters.messages.MagicIncomingTextMessageViewHolder;
import com.nextcloud.talk.adapters.messages.MagicOutcomingTextMessageViewHolder;
import com.nextcloud.talk.adapters.messages.MagicPreviewMessageViewHolder;
import com.nextcloud.talk.adapters.messages.MagicSystemMessageViewHolder;
import com.nextcloud.talk.api.NcApi;
import com.nextcloud.talk.application.NextcloudTalkApplication;
@ -95,6 +96,7 @@ import com.stfalcon.chatkit.messages.MessageInput;
import com.stfalcon.chatkit.messages.MessagesList;
import com.stfalcon.chatkit.messages.MessagesListAdapter;
import com.stfalcon.chatkit.utils.DateFormatter;
import com.stfalcon.chatkit.utils.RoundedImageView;
import com.webianks.library.PopupBubble;
import org.parceler.Parcels;
@ -308,6 +310,9 @@ public class ChatController extends BaseController implements MessagesListAdapte
messageHolders.setIncomingTextConfig(MagicIncomingTextMessageViewHolder.class, R.layout.item_custom_incoming_text_message);
messageHolders.setOutcomingTextConfig(MagicOutcomingTextMessageViewHolder.class, R.layout.item_custom_outcoming_text_message);
messageHolders.setIncomingImageConfig(MagicPreviewMessageViewHolder.class, R.layout.item_custom_incoming_preview_message);
messageHolders.setOutcomingImageConfig(MagicPreviewMessageViewHolder.class, R.layout.item_custom_outcoming_preview_message);
messageHolders.registerContentType(CONTENT_TYPE_SYSTEM_MESSAGE, MagicSystemMessageViewHolder.class,
R.layout.item_system_message, MagicSystemMessageViewHolder.class, R.layout.item_system_message,
this);
@ -315,28 +320,37 @@ public class ChatController extends BaseController implements MessagesListAdapte
adapter = new MessagesListAdapter<>(conversationUser.getUserId(), messageHolders, new ImageLoader() {
@Override
public void loadImage(ImageView imageView, String url) {
GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.load(url)
.centerInside()
.override(imageView.getMeasuredWidth(), imageView.getMeasuredHeight())
.apply(RequestOptions.bitmapTransform(new CircleCrop()))
.listener(new RequestListener<Bitmap>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
TextDrawable drawable = TextDrawable.builder().beginConfig().bold()
.endConfig().buildRound("?", getResources().getColor(R.color.nc_grey));
imageView.setImageDrawable(drawable);
return true;
}
if (!(imageView instanceof RoundedImageView)) {
GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.load(url)
.centerInside()
.override(imageView.getMeasuredWidth(), imageView.getMeasuredHeight())
.apply(RequestOptions.bitmapTransform(new CircleCrop()))
.listener(new RequestListener<Bitmap>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
TextDrawable drawable = TextDrawable.builder().beginConfig().bold()
.endConfig().buildRound("?", getResources().getColor(R.color.nc_grey));
imageView.setImageDrawable(drawable);
return true;
}
@Override
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
})
.into(imageView);
@Override
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
})
.into(imageView);
} else {
GlideApp.with(NextcloudTalkApplication.getSharedApplication().getApplicationContext())
.asBitmap()
.diskCacheStrategy(DiskCacheStrategy.NONE)
.override(480, 480)
.load(url)
.into(imageView);
}
}
});
} else {

View File

@ -19,10 +19,13 @@
*/
package com.nextcloud.talk.models.json.chat;
import android.util.Log;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonIgnore;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.nextcloud.talk.R;
import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.nextcloud.talk.models.json.converters.EnumSystemMessageTypeConverter;
import com.nextcloud.talk.utils.ApiUtils;
import com.stfalcon.chatkit.commons.models.IMessage;
@ -33,13 +36,34 @@ import org.parceler.Parcel;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import androidx.annotation.Nullable;
import lombok.Data;
@Parcel
@Data
@JsonObject
public class ChatMessage implements IMessage, MessageContentType {
public class ChatMessage implements IMessage, MessageContentType, MessageContentType.Image {
@Nullable
@Override
public String getImageUrl() {
if (messageParameters != null && messageParameters.size() > 0) {
for (String key : messageParameters.keySet()) {
Map<String, String> individualHashMap = messageParameters.get(key);
if (individualHashMap.get("type").equals("file")) {
selectedIndividualHashMap = individualHashMap;
return String.format(Locale.getDefault(),
"%s/index.php/core/preview?fileId=%s&x=%d&y=%d&forceIcon=1",
baseUrl, individualHashMap.get("id"), 480, 480);
}
}
}
return null;
}
public enum SystemMessageType {
DUMMY,
@ -85,11 +109,21 @@ public class ChatMessage implements IMessage, MessageContentType {
SystemMessageType systemMessageType;
@JsonIgnore
boolean isGrouped;
public boolean isGrouped;
@JsonIgnore
String activeUserId;
public String activeUserId;
@JsonIgnore
public Map<String, String> selectedIndividualHashMap;
public Map<String, String> getSelectedIndividualHashMap() {
return selectedIndividualHashMap;
}
public void setSelectedIndividualHashMap(Map<String, String> selectedIndividualHashMap) {
this.selectedIndividualHashMap = selectedIndividualHashMap;
}
public String getBaseUrl() {
return baseUrl;
}

View File

@ -163,7 +163,7 @@ public class PushUtils {
return -1;
}
public String generateSHA512Hash(String pushToken) {
private String generateSHA512Hash(String pushToken) {
MessageDigest messageDigest = null;
try {
messageDigest = MessageDigest.getInstance("SHA-512");
@ -175,7 +175,7 @@ public class PushUtils {
return "";
}
public String bytesToHex(byte[] bytes) {
private String bytesToHex(byte[] bytes) {
StringBuilder result = new StringBuilder();
for (byte individualByte : bytes) {
result.append(Integer.toString((individualByte & 0xff) + 0x100, 16)

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Nextcloud Talk application
~
~ @author Mario Danic
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:topLeftRadius="0dp"
android:bottomRightRadius="@dimen/message_bubble_corners_radius"
android:bottomLeftRadius="@dimen/message_bubble_corners_radius"
android:topRightRadius="0dp" />
<solid android:color="@color/white_two" />
</shape>

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Nextcloud Talk application
~
~ @author Mario Danic
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:topLeftRadius="6dp"
android:bottomRightRadius="6dp"
android:bottomLeftRadius="@dimen/message_bubble_corners_radius"
android:topRightRadius="0dp" />
<solid android:color="@color/colorPrimary" />
</shape>

View File

@ -92,6 +92,10 @@
app:outcomingTextLinkColor="@color/nc_outcoming_text_default"
app:outcomingTextSize="@dimen/chat_text_size"
app:outcomingTimeTextSize="12sp"
app:outcomingImageTimeTextSize="12sp"
app:incomingImageTimeTextSize="12sp"
app:outcomingImageTimeTextColor="@color/white60"
app:incomingImageTimeTextColor="@color/warm_grey_four"
app:textAutoLink="all"/>
<com.webianks.library.PopupBubble

View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Nextcloud Talk application
~
~ @author Mario Danic
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp">
<com.stfalcon.chatkit.utils.ShapeImageView
android:id="@id/messageUserAvatar"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_marginEnd="8dp" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/messageUserAvatar"
android:background="@drawable/shape_preview_text_incoming_message">
<com.stfalcon.chatkit.utils.RoundedImageView
android:id="@id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/image"
android:layout_alignStart="@+id/image"
android:layout_alignEnd="@id/image"
android:layout_margin="8dp">
<com.kevalpatel2106.emoticongifkeyboard.widget.EmoticonTextView
android:id="@id/messageText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/dark_grey_two"
android:textIsSelectable="true"
android:textSize="14sp" />
<View
android:id="@id/imageOverlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@id/messageTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/messageText"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>

View File

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Nextcloud Talk application
~
~ @author Mario Danic
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="2dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:background="@drawable/shape_preview_text_outcoming_message">
<com.stfalcon.chatkit.utils.RoundedImageView
android:id="@id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/image"
android:layout_alignStart="@+id/image"
android:layout_alignEnd="@id/image"
android:layout_margin="8dp">
<com.kevalpatel2106.emoticongifkeyboard.widget.EmoticonTextView
android:id="@id/messageText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/nc_outcoming_text_default"
android:textIsSelectable="true"
android:textSize="14sp" />
<View
android:id="@id/imageOverlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@id/messageTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/messageText"
android:layout_alignParentEnd="true"
android:textColor="@color/white60"/>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>

View File

@ -35,8 +35,7 @@
android:id="@id/attachmentButtonSpace"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_toEndOf="@id/attachmentButton"
android:layout_toRightOf="@id/attachmentButton"/>
android:layout_toEndOf="@id/attachmentButton"/>
<com.kevalpatel2106.emoticongifkeyboard.widget.EmoticonEditText
android:id="@id/messageInput"
@ -44,8 +43,6 @@
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@id/attachmentButtonSpace"
android:layout_toLeftOf="@id/sendButtonSpace"
android:layout_toRightOf="@id/attachmentButtonSpace"
android:layout_toStartOf="@id/sendButtonSpace"
android:inputType="textAutoCorrect|textAutoComplete|textMultiLine|textCapSentences"/>
@ -53,7 +50,6 @@
android:id="@id/sendButtonSpace"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_toLeftOf="@id/messageSendButton"
android:layout_toStartOf="@id/messageSendButton"/>
<ImageButton
@ -61,7 +57,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
</merge>