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

Fix part of #116 #149

Merged
merged 3 commits into from
Apr 10, 2021
Merged
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
90 changes: 44 additions & 46 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,74 +27,72 @@ android {

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])

// Language lib
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.4.21'

// Support
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.firebase:firebase-storage:19.2.2'
testImplementation 'junit:junit:4.13.1'
implementation 'com.airbnb.android:lottie:3.6.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.firebaseui:firebase-ui-firestore:6.2.1'
implementation 'com.google.firebase:firebase-database:19.7.0'
implementation 'com.google.android.material:material:1.3.0'

//Android Jetpack Navigation
implementation "androidx.navigation:navigation-fragment:2.3.4"
implementation "androidx.navigation:navigation-ui:2.3.4"

// Custom View
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation 'com.ismaeldivita.chipnavigation:chip-navigation-bar:1.3.4'
implementation 'com.github.TalbotGooday:AvatarView:0.0.2'
implementation 'com.github.cachapa:ExpandableLayout:2.9.2'

// Firebase core
implementation platform('com.google.firebase:firebase-bom:26.1.0')
implementation 'com.squareup.picasso:picasso:2.71828'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.google.android.gms:play-services-base:17.6.0'
implementation 'com.google.android.libraries.places:places:2.4.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.google.android.gms:play-services-location:18.0.0'
// FirebaseUI for Firebase Realtime Database
implementation 'com.firebaseui:firebase-ui-database:6.3.0'
implementation 'com.google.firebase:firebase-storage'
implementation 'com.google.firebase:firebase-database'
implementation 'com.google.firebase:firebase-core'
implementation 'com.google.firebase:firebase-firestore'
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-auth'
implementation 'com.firebase:firebase-client-android:2.3.1'

// FirebaseUI for Cloud Firestore
// Firebase UI
implementation 'com.firebaseui:firebase-ui-firestore:6.2.1'
implementation 'com.firebaseui:firebase-ui-database:6.3.0'
implementation 'com.firebaseui:firebase-ui-firestore:6.2.1'

// FirebaseUI for Firebase Auth
implementation 'com.firebaseui:firebase-ui-auth:6.2.1'

// FirebaseUI for Cloud Storage
implementation 'com.firebaseui:firebase-ui-storage:6.2.1'

implementation 'com.google.firebase:firebase-core:18.0.2'
implementation 'com.google.firebase:firebase-firestore:22.1.2'
implementation 'com.google.firebase:firebase-analytics:18.0.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.google.firebase:firebase-auth:20.0.3'
// Play services
implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation 'com.google.firebase:firebase-database:19.7.0'

implementation 'com.firebase:firebase-client-android:2.3.1'

//Android Jetpack Navigation
implementation "androidx.navigation:navigation-fragment:2.3.4"
implementation "androidx.navigation:navigation-ui:2.3.4"
implementation 'com.google.android.gms:play-services-base:17.6.0'
implementation 'com.google.android.libraries.places:places:2.4.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-location:18.0.0'

//Glide
// Network loading
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation 'com.android.volley:volley:1.2.0'
implementation 'io.github.ponnamkarthik:richlinkpreview:1.0.9'
implementation 'org.jsoup:jsoup:1.10.2'

//custom Bottom nav bar
implementation 'com.ismaeldivita.chipnavigation:chip-navigation-bar:1.3.4'
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.4.21'
implementation 'com.airbnb.android:lottie:3.6.1'

//App Intro
implementation 'com.github.AppIntro:AppIntro:6.1.0'

//EasyPref
implementation 'com.pixplicity.easyprefs:library:1.9.0'

//Animatoo Library
implementation 'com.github.mohammadatif:Animatoo:master'
//Volley
implementation 'com.android.volley:volley:1.2.0'

implementation 'io.github.ponnamkarthik:richlinkpreview:1.0.9'
implementation 'org.jsoup:jsoup:1.10.2'

// Testing
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation 'androidx.test:runner:1.3.0'
}
4 changes: 1 addition & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cswala.cswala">

<uses-permission android:name="android.permission.INTERNET"/>

<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".utils.MyApplication"
android:allowBackup="true"
Expand All @@ -12,7 +11,6 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".Activities.ResetPassword"></activity>
<activity android:name=".Activities.Register" />
<activity android:name=".Activities.LoginWithEmail" />
Expand Down
56 changes: 56 additions & 0 deletions app/src/main/java/com/cswala/cswala/Adapters/MessageAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.cswala.cswala.Adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import com.cswala.cswala.R;
import com.cswala.cswala.Models.Message;
import com.cswala.cswala.utils.MessageListener;
import com.cswala.cswala.viewholders.MessageHolder;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.firebase.database.DatabaseError;

public class MessageAdapter extends FirebaseRecyclerAdapter<Message, MessageHolder> {

private final MessageListener messageListener;
private final String uId;
private final Context context;

public MessageAdapter(@NonNull FirebaseRecyclerOptions<Message> options, MessageListener messageListener, String uId, Context context) {
super(options);
this.messageListener = messageListener;
this.uId = uId;
this.context = context;
}

@Override
protected void onBindViewHolder(@NonNull MessageHolder holder, int position, @NonNull Message model) {
holder.bind(model, uId);
}

@Override
public void onError(@NonNull DatabaseError error) {
super.onError(error);
}

@Override
public void onDataChanged() {
super.onDataChanged();
messageListener.onMessageReceived();
}



@NonNull
@Override
public MessageHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.message_item_view, parent, false);
return new MessageHolder(view, context);
}
}
162 changes: 158 additions & 4 deletions app/src/main/java/com/cswala/cswala/Fragments/CommunityFragment.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,177 @@
package com.cswala.cswala.Fragments;

import android.content.Context;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageButton;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.cswala.cswala.R;
import com.cswala.cswala.Adapters.MessageAdapter;
import com.cswala.cswala.observer.ScrollToBottomObserver;
import com.cswala.cswala.Models.Message;
import com.cswala.cswala.utils.MessageListener;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.android.material.snackbar.Snackbar;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;

import java.util.Date;


public class CommunityFragment extends Fragment {

private EditText msgInput;
private AppCompatImageButton sendBtn;
private MessageAdapter adapter;
private FirebaseDatabase database;
private FirebaseAuth auth;
private RecyclerView chatRv;
private LinearLayout sendMsgContainer;
private FrameLayout progContainer;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

return inflater.inflate(R.layout.fragment_community, container, false);
}

@Override
public void onViewCreated(@NonNull final View view, @Nullable Bundle savedInstanceState) {
chatRv = view.findViewById(R.id.chat_rv);
msgInput = view.findViewById(R.id.msg_input);
sendBtn = view.findViewById(R.id.send_btn);
sendMsgContainer = view.findViewById(R.id.send_msg_container);
progContainer = view.findViewById(R.id.prog_container);

MessageListener messageListener = new MessageListener() {
@Override
public void onMessageReceived() {
progContainer.setVisibility(View.GONE);
}

@Override
public void onError(DatabaseError error) {
Snackbar.make(view, "Some error occurred", Snackbar.LENGTH_SHORT).show();
}
};

database = FirebaseDatabase.getInstance();
auth = FirebaseAuth.getInstance();

// chatRv.setVisibility(View.GONE);
// sendMsgContainer.setVisibility(View.GONE);
progContainer.setVisibility(View.VISIBLE);

Query query = database
.getReference()
.child("chats")
.limitToLast(50);

FirebaseRecyclerOptions<Message> options =
new FirebaseRecyclerOptions.Builder<Message>()
.setQuery(query, Message.class)
.build();

LinearLayoutManager llm = new LinearLayoutManager(getContext());
llm.setStackFromEnd(true);
chatRv.setLayoutManager(llm);

adapter = new MessageAdapter(options, messageListener, auth.getCurrentUser().getUid(), getContext());
chatRv.setAdapter(adapter);
adapter.registerAdapterDataObserver(new ScrollToBottomObserver(chatRv, adapter, llm));

sendBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String content = msgInput.getText().toString().trim();
if (content.equals("")) return;

closeKeyboard();
DatabaseReference ref = database.getReference().child("chats").push();

String msgId = ref.getKey();
String senderId = auth.getCurrentUser().getUid();
String senderName = auth.getCurrentUser().getDisplayName();

if (senderName == null || senderName.trim().equals("")) {
senderName = "Unknown";
}

Message message = new Message(msgId, senderName, senderId, content, new Date().getTime());

ref.setValue(message);


msgInput.setText("");

}
});
msgInput.addTextChangedListener(new TextWatcher() {
boolean prevEmpty = true;

@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}

@Override
public void afterTextChanged(Editable s) {
final boolean isEmpty = s.toString().trim().equals("");
if (isEmpty == prevEmpty) return;
prevEmpty = isEmpty;

if (isEmpty) {
sendBtn.setVisibility(View.GONE);
} else {
sendBtn.setVisibility(View.VISIBLE);
}
}
});
}

@Override
public void onStart() {
super.onStart();
if (adapter != null) {
adapter.startListening();
}
}

@Override
public void onStop() {
super.onStop();
if (adapter != null) {
adapter.stopListening();
}
}

private void closeKeyboard() {
try {
View view = getActivity().getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
} catch(Exception ignored) {}
}
}
2 changes: 0 additions & 2 deletions app/src/main/java/com/cswala/cswala/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
Expand Down
Loading