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

Added login as admin functionality #2

Open
wants to merge 1 commit into
base: develop
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
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
viewBinding {
enabled = true

}

defaultConfig {
applicationId "com.acm.omnia"
Expand Down Expand Up @@ -55,5 +59,6 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.android.volley:volley:1.1.1'

}
13 changes: 13 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

<application
Expand Down Expand Up @@ -32,6 +33,18 @@
<activity
android:name=".activity.MainActivity"
android:screenOrientation="portrait" />

<activity android:name=".Notifications.NotificationsActivity"></activity>
<activity android:name=".activity.DeleteEventActivity" />
<activity android:name=".activity.AdminActivity">


</activity>
<activity android:name=".activity.AddBlogsActivity" />
<activity android:name=".activity.AddProjectsActivity" />
<activity android:name=".activity.AddEventsActivity" />
<activity android:name=".activity.AdminMainActivity"/>

<service
android:name="com.google.firebase.messaging.FirebaseMessagingService"
android:exported="false">
Expand Down
41 changes: 41 additions & 0 deletions app/src/main/java/com/acm/omnia/Model/BlogsData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.acm.omnia.Model;

public class BlogsData {
String title;
String imgUrl;
String blogLink;

public BlogsData() {
}


public BlogsData(String title, String imgUrl, String blogLink) {
this.title = title;
this.imgUrl = imgUrl;
this.blogLink = blogLink;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getImgUrl() {
return imgUrl;
}

public void setImgUrl(String imgUrl) {
this.imgUrl = imgUrl;
}

public String getBlogLink() {
return blogLink;
}

public void setBlogLink(String blogLink) {
this.blogLink = blogLink;
}
}
51 changes: 51 additions & 0 deletions app/src/main/java/com/acm/omnia/Model/EventsData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.acm.omnia.Model;

public class EventsData {
String title;
String date;
String time;
String month;


public EventsData() {
}

public EventsData(String title, String date, String time, String month) {
this.title = title;
this.date = date;
this.time = time;
this.month = month;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getDate() {
return date;
}

public void setDate(String date) {
this.date = date;
}

public String getTime() {
return time;
}

public void setTime(String time) {
this.time = time;
}

public String getMonth() {
return month;
}

public void setMonth(String month) {
this.month = month;
}
}
31 changes: 31 additions & 0 deletions app/src/main/java/com/acm/omnia/Model/ProjectsData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.acm.omnia.Model;

public class ProjectsData {

String title;
String imgUrl;

public ProjectsData() {
}

public ProjectsData(String title, String imgUrl) {
this.title = title;
this.imgUrl = imgUrl;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getImgUrl() {
return imgUrl;
}

public void setImgUrl(String imgUrl) {
this.imgUrl = imgUrl;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.acm.omnia.Notifications;

import android.app.Activity;
import android.content.Context;

import com.acm.omnia.R;
import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;


import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class FcmNotificationsSender {


private final String Url = "https://fcm.googleapis.com/fcm/send";
private final String ServerKey = "AAAA6pN8hLU:APA91bHo83DOiE_g8SdckfL1c36s8qsD-OBS89Ue9PD1l6Zhfvtb47p73ZL9vlXBdYJNzI2QI_3LuLJKvbSaBSJx1_zG2XmyGEA9REsgmFyrICSxiBG482vgFhqk0wG96Cm1amHM6nx5";
String userFcmToken;
String title;
String body;
Context context;
Activity activity;
private RequestQueue requestQueue;


public FcmNotificationsSender(String userFcmToken, String title, String body, Context context, Activity activity) {
this.userFcmToken = userFcmToken;
this.title = title;
this.body = body;
this.context = context;
this.activity = activity;
}

public void SendNotifications() {
requestQueue = Volley.newRequestQueue(activity);
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("to", userFcmToken);
JSONObject notiObject = new JSONObject();
notiObject.put("title", title);
notiObject.put("body", body);
notiObject.put("icon", R.drawable.acm_logo_white); // enter icon that exists in drawable only


jsonObject.put("notification", notiObject);


JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, Url, jsonObject, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {

// code run is got response

}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// code run is got error

}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {


Map<String, String> header = new HashMap<>();
header.put("content-type", "application/json");
header.put("authorization", "key=" + ServerKey);
return header;


}
};
requestQueue.add(request);


} catch (JSONException e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.acm.omnia.Notifications;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Build;
import android.os.Vibrator;

import androidx.core.app.NotificationCompat;


import com.acm.omnia.activity.AdminMainActivity;
import com.google.firebase.messaging.RemoteMessage;

public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {

NotificationManager mNotificationManager;


@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);


// playing audio and vibration when user se request
Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
r.setLooping(false);
}

// vibration
Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
long[] pattern = {100, 300, 300, 300};
v.vibrate(pattern, -1);


int resourceImage = getResources().getIdentifier(remoteMessage.getNotification().getIcon(), "drawable", getPackageName());


NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "CHANNEL_ID");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

builder.setSmallIcon(resourceImage);
} else {

builder.setSmallIcon(resourceImage);
}


Intent resultIntent = new Intent(this, AdminMainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);


builder.setContentTitle(remoteMessage.getNotification().getTitle());
builder.setContentText(remoteMessage.getNotification().getBody());
builder.setContentIntent(pendingIntent);
builder.setStyle(new NotificationCompat.BigTextStyle().bigText(remoteMessage.getNotification().getBody()));
builder.setAutoCancel(true);
builder.setPriority(Notification.PRIORITY_MAX);

mNotificationManager =
(NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);


if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String channelId = "Your_channel_id";
NotificationChannel channel = new NotificationChannel(
channelId,
"Channel human readable title",
NotificationManager.IMPORTANCE_HIGH);
mNotificationManager.createNotificationChannel(channel);
builder.setChannelId(channelId);
}


// notificationId is a unique int for each notification that you must define
mNotificationManager.notify(100, builder.build());


}

}
Loading