Skip to content

Commit

Permalink
viewing images leads to a black screen, stfalcon-studio/FrescoImageVi…
Browse files Browse the repository at this point in the history
…ewer#94 this is having the same issue
  • Loading branch information
repineda committed May 26, 2019
1 parent 86b074d commit 28ada57
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 23 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
Binary file modified .idea/caches/gradle_models.ser
Binary file not shown.
7 changes: 6 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.schat"
minSdkVersion 18
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
Expand All @@ -20,6 +20,7 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
//implementation 'com.google.android.material:material:1.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'

Expand All @@ -28,6 +29,10 @@ dependencies {
implementation 'com.google.firebase:firebase-database:17.0.0'
implementation 'com.google.firebase:firebase-storage:17.0.0'

implementation 'com.facebook.fresco:fresco:1.10.0'
// implementation 'com.github.stfalcon:stfalcon-imageviewer:0.1.0'
implementation 'com.github.stfalcon:frescoimageviewer:0.5.0'

implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<activity android:name=".ChatActivity"></activity>
<activity android:name=".PhoneLogin"></activity>
<activity android:name=".User.FindUserActivity" />
Expand Down
24 changes: 22 additions & 2 deletions app/src/main/java/com/example/schat/Chat/MessageAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.schat.R;
import com.google.firebase.database.FirebaseDatabase;
import com.stfalcon.frescoimageviewer.ImageViewer;

import java.util.ArrayList;

public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.MessageViewHolder>
Expand All @@ -30,10 +33,24 @@ public MessageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewT
return rcv;
}
@Override
public void onBindViewHolder(@NonNull MessageViewHolder holder, final int position)
public void onBindViewHolder(@NonNull final MessageViewHolder holder, final int position)
{
holder.message.setText(messageList.get(position).getMessage());
holder.sender.setText(messageList.get(position).getSenderId());

if(messageList.get(holder.getAdapterPosition()).getMediaUrLList().isEmpty())
{
holder.viewMedia.setVisibility(View.GONE);
}

holder.viewMedia.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new ImageViewer.Builder(v.getContext(), messageList.get(holder.getAdapterPosition()).getMediaUrLList())
.setStartPosition(0)
.show();
}
});
}

@Override
Expand All @@ -42,13 +59,16 @@ public void onBindViewHolder(@NonNull MessageViewHolder holder, final int positi
class MessageViewHolder extends RecyclerView.ViewHolder
{
TextView message, sender;
Button viewMedia;
LinearLayout layout;
MessageViewHolder(View view)
{
super(view);
layout = view.findViewById(R.id.sendLayout);
message = view.findViewById(R.id.message);
sender = view.findViewById(R.id.send);
sender = view.findViewById(R.id.sender);

viewMedia = view.findViewById(R.id.viewMedia);
}
}
}
7 changes: 6 additions & 1 deletion app/src/main/java/com/example/schat/Chat/MessageObject.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package com.example.schat.Chat;

import java.util.ArrayList;

public class MessageObject
{
String messageId, senderId, message;
ArrayList<String> mediaUrLList;

public MessageObject(String messageId, String senderId, String message)
public MessageObject(String messageId, String senderId, String message, ArrayList<String> mediaUrLList)
{
this.messageId = messageId;
this.senderId = senderId;
this.message = message;
this.mediaUrLList = mediaUrLList;
}

public String getMessageId() { return messageId; }
public String getSenderId() { return senderId; }
public String getMessage() { return message; }
public ArrayList<String> getMediaUrLList() { return mediaUrLList; }
}
11 changes: 10 additions & 1 deletion app/src/main/java/com/example/schat/ChatActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,21 @@ public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s)
if(dataSnapshot.exists())
{
String text = "", creatorID = "";

ArrayList<String> mediaUrlList = new ArrayList<>();
if(dataSnapshot.child("text").getValue() != null)
text = dataSnapshot.child("text").getValue().toString();
if(dataSnapshot.child("creator").getValue() != null)
creatorID = dataSnapshot.child("creator").getValue().toString();
if(dataSnapshot.child("media").getChildrenCount() > 0)
{
for(DataSnapshot mediaSnapShot : dataSnapshot.child("media").getChildren())
{
mediaUrlList.add(mediaSnapShot.getValue().toString());
}
}

MessageObject mMessage = new MessageObject(dataSnapshot.getKey(), creatorID, text);
MessageObject mMessage = new MessageObject(dataSnapshot.getKey(), creatorID, text, mediaUrlList);
messageList.add(mMessage);
messageListLayoutManager.scrollToPosition(messageList.size()-1);//scrolls down to latest message
messageAdapter.notifyDataSetChanged();
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/example/schat/MainFeedActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.example.schat.Chat.ChatObject;
import com.example.schat.User.FindUserActivity;
import com.example.schat.Chat.ChatListAdapter;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
Expand All @@ -36,6 +37,7 @@ public class MainFeedActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_feed);
Fresco.initialize(this);

// contact search
Button mFindUser = findViewById(R.id.find_user);
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/item_media.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:layout_width="wrap_content"
android:layout_height="100sp"
android:id="@+id/media"
android:src="@mipmap/ic_launcher"/>
app:srcCompat="@mipmap/ic_launcher"/>

</LinearLayout>
39 changes: 23 additions & 16 deletions app/src/main/res/layout/item_message.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/messageList">
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/sendLayout">
android:orientation="vertical">

<EditText
android:layout_weight="0.8"
android:layout_width="0dp"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/message"
android:hint="message..."/>
android:id="@+id/message"/>

<Button
android:layout_weight="0.2"
android:layout_width="0dp"
<TextView

android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/send"/>
android:id="@+id/sender"/>
<View
android:layout_width="match_parent"
android:layout_height="1sp"
android:background="#000000"/>

</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="view Picture(s)"
android:id="@+id/viewMedia"/>

</LinearLayout>
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }

}
}
Expand Down

0 comments on commit 28ada57

Please sign in to comment.