Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brian/recycler view links fix #27

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ buildscript {

}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:2.2.0'

classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ private static Message getRandomMessage() {
message.setAvatarUrl("https://lh3.googleusercontent.com/-Y86IN-vEObo/AAAAAAAAAAI/AAAAAAAKyAM/6bec6LqLXXA/s0-c-k-no-ns/photo.jpg");
message.setUserId("LP");
message.setSource(MessageSource.EXTERNAL_USER);
message.setDisplayName("FD100F");
} else {
message.setAvatarUrl("https://scontent-lga3-1.xx.fbcdn.net/v/t1.0-9/10989174_799389040149643_722795835011402620_n.jpg?oh=bff552835c414974cc446043ac3c70ca&oe=580717A5");
message.setUserId("MP");
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon May 16 10:54:06 EDT 2016
#Wed Oct 05 12:16:18 PDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
11 changes: 0 additions & 11 deletions local.properties

This file was deleted.

Binary file modified slyce-messaging/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package it.slyce.messaging;

import android.Manifest;
import android.app.Fragment;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.net.Uri;
Expand All @@ -12,11 +10,10 @@
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
Expand Down Expand Up @@ -55,14 +52,16 @@
import it.slyce.messaging.utils.asyncTasks.ReplaceMessagesTask;
import it.slyce.messaging.view.ViewUtils;



/**
* Created by John C. Hunchar on 1/12/16.
*/
public class SlyceMessagingFragment extends Fragment implements OnClickListener {

private static final int START_RELOADING_DATA_AT_SCROLL_VALUE = 5000; // TODO: maybe change this? make it customizable?

private EditText mEntryField;
public EditText mEntryField;
private LinearLayoutManager mLinearLayoutManager;
private List<Message> mMessages;
private List<MessageItem> mMessageItems;
Expand Down Expand Up @@ -227,12 +226,6 @@ public boolean onTouch(View v, MotionEvent event) {
loadMoreMessagesIfNecessary();
startLoadMoreMessagesListener();

if (ContextCompat.checkSelfPermission(getActivity().getApplicationContext(),
Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED ||
ContextCompat.checkSelfPermission(getActivity().getApplicationContext(),
Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED)
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 232);

return rootView;
}

Expand Down Expand Up @@ -434,7 +427,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {

private void sendUserTextMessage() {
String text = ViewUtils.getStringFromEditText(mEntryField);
if (TextUtils.isEmpty(text))
if (text == null || text.replace(" ","").length() <= 0)
return;
mEntryField.setText("");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class MessageViewHolder extends RecyclerView.ViewHolder {
public TextView timestamp;
public ViewGroup avatarContainer;
public CustomSettings customSettings;
public TextView username;

public MessageViewHolder(View itemView, CustomSettings customSettings) {
super(itemView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ public MessageExternalUserTextViewHolder(View itemView, final CustomSettings cus
super(itemView, customSettings);

avatar = (ImageView) itemView.findViewById(R.id.message_scout_text_image_view_avatar);
carrot = (ImageView) itemView.findViewById(R.id.message_scout_text_image_view_carrot);
text = (TextView) itemView.findViewById(R.id.message_scout_text_text_view_text);
timestamp = (TextView) itemView.findViewById(R.id.message_scout_text_text_view_timestamp);
avatarContainer = (ViewGroup) itemView.findViewById(R.id.message_scout_text_image_view_avatar_group);
initials = (TextView) itemView.findViewById(R.id.message_scout_text_text_view_initials);
bubble = (FrameLayout) itemView.findViewById(R.id.message_scout_text_view_group_bubble);
username = (TextView) itemView.findViewById(R.id.username);

Drawable drawable = ContextCompat.getDrawable(itemView.getContext(), R.drawable.shape_rounded_rectangle_white);
// Drawable drawable = itemView.getContext().getDrawable();
drawable.setColorFilter(customSettings.externalBubbleBackgroundColor, PorterDuff.Mode.SRC_ATOP);
bubble.setBackground(drawable);
carrot.setColorFilter(customSettings.externalBubbleBackgroundColor);
text.setTextColor(customSettings.externalBubbleTextColor);
timestamp.setTextColor(customSettings.timestampColor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ public MessageInternalUserViewHolder(View itemView, CustomSettings customSetting
initials = (TextView) itemView.findViewById(R.id.message_user_media_text_view_initials);
timestamp = (TextView) itemView.findViewById(R.id.message_user_media_text_view_timestamp);
avatarContainer = (ViewGroup) itemView.findViewById(R.id.message_user_media_view_group_avatar);
username = (TextView) itemView.findViewById(R.id.username);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@ public MessageInternalUserTextViewHolder(View itemView, CustomSettings customSet
super(itemView, customSettings);

avatar = (ImageView) itemView.findViewById(R.id.message_user_text_image_view_avatar);
carrot = (ImageView) itemView.findViewById(R.id.message_user_text_image_view_carrot);
initials = (TextView) itemView.findViewById(R.id.message_user_text_text_view_initials);
text = (TextView) itemView.findViewById(R.id.message_user_text_text_view_text);
timestamp = (TextView) itemView.findViewById(R.id.message_user_text_text_view_timestamp);
avatarContainer = (ViewGroup) itemView.findViewById(R.id.message_user_text_view_group_avatar);
bubble = (FrameLayout) itemView.findViewById(R.id.message_user_text_view_group_bubble);
username = (TextView) itemView.findViewById(R.id.username);

Drawable drawable = ContextCompat.getDrawable(itemView.getContext(), R.drawable.shape_rounded_rectangle_white);
// Drawable drawable = itemView.getContext().getDrawable();
drawable.setColorFilter(customSettings.localBubbleBackgroundColor, PorterDuff.Mode.SRC_ATOP);
bubble.setBackground(drawable);
carrot.setColorFilter(customSettings.localBubbleBackgroundColor);
text.setTextColor(customSettings.localBubbleTextColor);
timestamp.setTextColor(customSettings.timestampColor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void buildMessageItem(
// Populate views with content
messageMediaViewHolder.timestamp.setText(date != null ? date : "");
messageMediaViewHolder.initials.setText(initials != null ? initials : "");
messageMediaViewHolder.username.setText(message.getDisplayName() != null ? message.getDisplayName() : "");

messageMediaViewHolder.media.setWidthToHeightRatio(widthToHeightRatio);
messageMediaViewHolder.media.setImageUrlToLoadOnLayout(mediaUrl);
Expand Down Expand Up @@ -73,6 +74,7 @@ public void onClick(View view) {
messageMediaViewHolder.avatar.setVisibility(isFirstConsecutiveMessageFromSource && !TextUtils.isEmpty(avatarUrl) ? View.VISIBLE : View.INVISIBLE);
messageMediaViewHolder.avatarContainer.setVisibility(isFirstConsecutiveMessageFromSource ? View.VISIBLE : View.INVISIBLE);
messageMediaViewHolder.initials.setVisibility(isFirstConsecutiveMessageFromSource && TextUtils.isEmpty(avatarUrl) ? View.VISIBLE : View.GONE);
messageMediaViewHolder.username.setVisibility(isFirstConsecutiveMessageFromSource ? View.VISIBLE : View.GONE);
messageMediaViewHolder.media.setVisibility(!TextUtils.isEmpty(mediaUrl) ? View.VISIBLE : View.INVISIBLE);
messageMediaViewHolder.timestamp.setVisibility(isLastConsecutiveMessageFromSource ? View.VISIBLE : View.GONE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public void buildMessageItem(
messageTextViewHolder.initials.setText(initials != null ? initials : "");
messageTextViewHolder.text.setText(text != null ? text : "");
messageTextViewHolder.timestamp.setText(date != null ? date : "");
messageTextViewHolder.username.setText(message.getDisplayName() != null ? message.getDisplayName() : "");


messageTextViewHolder.bubble.setOnLongClickListener(new View.OnLongClickListener() {
@Override
Expand Down Expand Up @@ -75,8 +77,8 @@ public void onClick(View view) {

messageTextViewHolder.avatar.setVisibility(isFirstConsecutiveMessageFromSource && !TextUtils.isEmpty(avatarUrl) ? View.VISIBLE : View.INVISIBLE);
messageTextViewHolder.avatarContainer.setVisibility(isFirstConsecutiveMessageFromSource ? View.VISIBLE : View.INVISIBLE);
messageTextViewHolder.carrot.setVisibility(isFirstConsecutiveMessageFromSource ? View.VISIBLE : View.INVISIBLE);
messageTextViewHolder.initials.setVisibility(isFirstConsecutiveMessageFromSource && TextUtils.isEmpty(avatarUrl) ? View.VISIBLE : View.GONE);
messageTextViewHolder.username.setVisibility(isFirstConsecutiveMessageFromSource ? View.VISIBLE : View.GONE);
messageTextViewHolder.timestamp.setVisibility(isLastConsecutiveMessageFromSource ? View.VISIBLE : View.GONE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* Created by matthewpage on 6/27/16.
*/
public abstract class MessageTextViewHolder extends MessageViewHolder {
public ImageView carrot;
public TextView text;
public FrameLayout bubble;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,7 @@ public static void markMessageItemAtIndexIfFirstOrLastFromSource(int i, List<Mes
}

private static boolean previousMessageIsNotFromSameSource(int i, List<MessageItem> messageItems) {
return i == 0 ||
previousMessageIsSpinner(i, messageItems) ||
previousMessageIsFromAnotherSender(i, messageItems);
}

private static boolean previousMessageIsFromAnotherSender(int i, List<MessageItem> messageItems) {
return messageItems.get(i - 1).getMessageSource() != messageItems.get(i).getMessageSource();
}

private static boolean previousMessageIsSpinner(int i, List<MessageItem> messageItems) {
return isSpinnerMessage(i - 1, messageItems);
return true;
}

private static boolean isTheLastConsecutiveMessageFromSource(int i, List<MessageItem> messageItems) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.os.Build;
import android.text.Layout;
import android.text.Selection;
import android.text.Spannable;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.ClickableSpan;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.TextView;

import it.slyce.messaging.R;
Expand Down Expand Up @@ -69,4 +75,48 @@ private void init(Context context, AttributeSet attrs, int defStyleAttr, int def
}
}
}

@Override
public boolean onTouchEvent(MotionEvent event) {
TextView widget = (TextView) this;
Object text = widget.getText();
if (text instanceof Spanned) {
Spannable buffer = (Spannable) text;

int action = event.getAction();

if (action == MotionEvent.ACTION_UP
|| action == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();

x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();

x += widget.getScrollX();
y += widget.getScrollY();

Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);

ClickableSpan[] link = buffer.getSpans(off, off,
ClickableSpan.class);

if (link.length != 0) {
if (action == MotionEvent.ACTION_UP) {
link[0].onClick(widget);
} else if (action == MotionEvent.ACTION_DOWN) {
Selection.setSelection(buffer,
buffer.getSpanStart(link[0]),
buffer.getSpanEnd(link[0]));
}
return true;
}
}

}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android">

<corners
android:radius="3dp" />
android:radius="6dp" />

<solid
android:color="@color/background_gray"/>
</shape>
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

<corners
android:radius="3dp" />
<corners android:radius="6dp" />
<stroke android:width="1dip" android:color="#d3d3d3"/>
<solid android:color="@color/background_white"/>

<solid
android:color="@color/background_white"/>
</shape>
27 changes: 16 additions & 11 deletions slyce-messaging/src/main/res/layout/item_message_external_text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,28 @@
app:font="museo_sans_500.otf"
tools:text="JF"/>


<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/message_scout_text_image_view_avatar"
android:layout_width="48dp"
android:layout_height="48dp" />

</FrameLayout>

<ImageView
android:id="@+id/message_scout_text_image_view_carrot"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_toLeftOf="@+id/message_scout_text_view_group_bubble"
android:layout_alignTop="@+id/message_scout_text_view_group_bubble"
android:layout_marginRight="-4dp"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
app:srcCompat="@drawable/vd_ic_scout_carrot"
android:tint="@color/background_white"/>
<TextView
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_alignEnd="@+id/message_scout_text_image_view_avatar_group"
android:layout_alignStart="@+id/message_scout_text_image_view_avatar_group"
android:layout_alignLeft="@+id/message_scout_text_image_view_avatar_group"
android:layout_alignRight="@+id/message_scout_text_image_view_avatar_group"
android:layout_height="wrap_content"
android:gravity="center"
android:text="JR40M"
android:textSize="12sp"
android:layout_marginTop="3dp"
android:layout_below="@+id/message_scout_text_image_view_avatar_group"/>


<FrameLayout
android:id="@+id/message_scout_text_view_group_bubble"
Expand Down
Loading