Skip to content

Commit

Permalink
Notification Added
Browse files Browse the repository at this point in the history
  • Loading branch information
mukul2428 committed Aug 20, 2020
1 parent ad696a4 commit 103d22c
Show file tree
Hide file tree
Showing 22 changed files with 813 additions and 92 deletions.
16 changes: 11 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,21 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.firebase:firebase-auth:19.3.1'
implementation 'com.google.firebase:firebase-database:19.3.0'
implementation 'com.google.firebase:firebase-auth:19.3.2'
implementation 'com.google.firebase:firebase-database:19.3.1'
implementation 'com.google.firebase:firebase-storage:19.1.1'
implementation 'com.firebaseui:firebase-ui-database:6.2.1'
implementation 'com.firebaseui:firebase-ui-storage:6.2.1'
implementation 'com.google.firebase:firebase-dynamic-links:19.1.0'
implementation 'com.google.firebase:firebase-messaging:20.2.0'

implementation 'com.google.firebase:firebase-messaging:20.2.4'
implementation 'com.squareup.retrofit2:retrofit:2.6.2'
implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
implementation 'com.google.firebase:firebase-analytics:17.5.0'

implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.+'
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
Expand All @@ -46,8 +51,9 @@ dependencies {
implementation 'com.squareup.okhttp3:okhttp:4.7.2'
implementation 'gun0912.ted:tedpermission:2.2.2'
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.google.android.material:material:1.2.0'
implementation 'id.zelory:compressor:3.0.0'
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
apply plugin: 'com.google.gms.google-services'
20 changes: 19 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:testOnly="false">

<provider
android:authorities="${applicationId}.provider"
Expand Down Expand Up @@ -68,6 +69,23 @@
<activity
android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
android:theme="@style/Base.Theme.AppCompat" />

<service android:name=".Notifications.MyFirebaseIdService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_SERVICE"/>
</intent-filter>
</service>

<service android:name=".Notifications.FirebaseMessaging"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>

</application>

</manifest>
241 changes: 220 additions & 21 deletions app/src/main/java/com/techexpert/indianvaarta/ChatActivity.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.techexpert.indianvaarta;
package com.techexpert.indianvaarta.Fragments;

import android.content.Intent;
import android.os.Bundle;
Expand All @@ -20,9 +20,15 @@
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.iid.FirebaseInstanceId;
import com.squareup.picasso.Callback;
import com.squareup.picasso.NetworkPolicy;
import com.squareup.picasso.Picasso;
import com.techexpert.indianvaarta.ChatActivity;
import com.techexpert.indianvaarta.LoginActivity;
import com.techexpert.indianvaarta.Notifications.Token;
import com.techexpert.indianvaarta.R;
import com.techexpert.indianvaarta.contacts;

import de.hdodenhof.circleimageview.CircleImageView;

Expand Down Expand Up @@ -63,23 +69,30 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
}
else
{
Intent loginIntent=new Intent(getContext(),LoginActivity.class);
Intent loginIntent=new Intent(getContext(), LoginActivity.class);
loginIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(loginIntent);
}



UsersRef = FirebaseDatabase.getInstance().getReference().child("Users");
ChatsRef = FirebaseDatabase.getInstance().getReference()
.child("Contacts").child(currentUserID);

chatList = private_chats_view.findViewById(R.id.chats_list);
chatList.setLayoutManager(new LinearLayoutManager(getContext()));

// updateToken(FirebaseInstanceId.getInstance().getToken());

return private_chats_view;
}

// private void updateToken(String token)
// {
// DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Tokens");
// Token token1 = new Token(token);
// reference.child(FirebaseAuth.getInstance().getCurrentUser().getUid()).setValue(token1);
// }

@Override
public void onStart()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.techexpert.indianvaarta;
package com.techexpert.indianvaarta.Fragments;

import android.os.Bundle;
import android.view.LayoutInflater;
Expand All @@ -21,6 +21,8 @@
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.squareup.picasso.Picasso;
import com.techexpert.indianvaarta.R;
import com.techexpert.indianvaarta.contacts;

import de.hdodenhof.circleimageview.CircleImageView;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.techexpert.indianvaarta;
package com.techexpert.indianvaarta.Fragments;

import android.os.Bundle;

Expand All @@ -8,6 +8,8 @@
import android.view.View;
import android.view.ViewGroup;

import com.techexpert.indianvaarta.R;


/**
* A simple {@link Fragment} subclass.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class IndianVaarta extends Application
public void onCreate() {
super.onCreate();


FirebaseDatabase.getInstance().setPersistenceEnabled(true);

Picasso.Builder builder = new Picasso.Builder(this);
Expand All @@ -22,10 +21,5 @@ public void onCreate() {
built.setIndicatorsEnabled(true);
built.setLoggingEnabled(true);
Picasso.setSingletonInstance(built);



}


}
45 changes: 41 additions & 4 deletions app/src/main/java/com/techexpert/indianvaarta/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import android.Manifest;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

Expand All @@ -29,11 +28,16 @@
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.iid.FirebaseInstanceId;
import com.gun0912.tedpermission.PermissionListener;
import com.gun0912.tedpermission.TedPermission;
import com.squareup.picasso.Callback;
import com.squareup.picasso.NetworkPolicy;
import com.squareup.picasso.Picasso;
import com.techexpert.indianvaarta.Fragments.ChatFragment;
import com.techexpert.indianvaarta.Fragments.ContactFragment;
import com.techexpert.indianvaarta.Fragments.GroupFragment;
import com.techexpert.indianvaarta.Notifications.Token;

import java.text.SimpleDateFormat;
import java.util.Calendar;
Expand Down Expand Up @@ -171,6 +175,23 @@ public boolean onNavigationItemSelected(@NonNull MenuItem menuItem)

});

updateToken(FirebaseInstanceId.getInstance().getToken());

}

private void updateToken(String token)
{
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Tokens");
Token token1 = new Token(token);

mAuth = FirebaseAuth.getInstance();

if(mAuth.getCurrentUser()!=null)
{
currentUser = mAuth.getCurrentUser();
currentUserID = mAuth.getCurrentUser().getUid();
}
reference.child(currentUserID).setValue(token1);
}


Expand Down Expand Up @@ -402,6 +423,8 @@ public void onCancelled(@NonNull DatabaseError databaseError) {

static void UpdateUserStatus(String state)
{

FirebaseAuth mAuth = FirebaseAuth.getInstance();
String saveCurrentTime, saveCurrentDate;

Calendar calendar = Calendar.getInstance();
Expand All @@ -419,9 +442,9 @@ static void UpdateUserStatus(String state)

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();

if(FirebaseAuth.getInstance().getCurrentUser()!=null)
if(mAuth.getCurrentUser()!=null)
{
String currentUserID = FirebaseAuth.getInstance().getCurrentUser().getUid();
String currentUserID = mAuth.getCurrentUser().getUid();
rootRef.child("Users").child(currentUserID).child("userState")
.updateChildren(OnlineStateMap);
}
Expand Down Expand Up @@ -490,4 +513,18 @@ public void onPermissionDenied(List<String> deniedPermissions) {
.setPermissions(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE)
.check();
}

private void SharedPreferences()
{
FirebaseAuth mAuth = FirebaseAuth.getInstance();
if(mAuth.getCurrentUser()!=null)
{
String currentUserID = mAuth.getCurrentUser().getUid();
SharedPreferences sp = getSharedPreferences("SP_USER", MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString("Current_USERID",currentUserID);
editor.apply();
}
}

}
Loading

0 comments on commit 103d22c

Please sign in to comment.