Skip to content

feat: Implement group notification #163

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

Merged
merged 1 commit into from
Jun 10, 2019
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
Binary file added .DS_Store
Binary file not shown.
Binary file added app/.DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions app/src/main/java/com/example/saar/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ public class Constant {
public static final String ACHIEVEMENTS = "achievements";
public static final String IMG_URL = "img_url";

//Notification service
public static final String SUBSCRIBE_NOTIFICATION="subscribe_notification";

}
67 changes: 54 additions & 13 deletions app/src/main/java/com/example/saar/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@
import com.google.firebase.messaging.FirebaseMessaging;

import de.hdodenhof.circleimageview.CircleImageView;
import timber.log.Timber;

public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {

//creating fragment object
Fragment fragment = null;
SharedPreferences preferences;
SharedPreferences.Editor editor;
SharedPreferences.Editor editor, notifications;
TextView name, email;
CircleImageView circleImageView;

Expand Down Expand Up @@ -105,17 +106,57 @@ public void onClick(View v) {
}

private void subscribeForNotification() {
FirebaseMessaging.getInstance().subscribeToTopic("alumnus")
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
String msg = getString(R.string.msg_subscribed);
if (!task.isSuccessful()) {
msg = getString(R.string.msg_subscribe_failed);
notifications= PreferenceManager.getDefaultSharedPreferences(this).edit();
if (!preferences.getBoolean(Constant.SUBSCRIBE_NOTIFICATION, false)) {
FirebaseMessaging.getInstance().subscribeToTopic("alumnus")
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
String msg = getString(R.string.msg_subscribed);
if (!task.isSuccessful()) {
msg = getString(R.string.msg_subscribe_failed);
}
Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
}
Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
}
});
});
if (preferences.getBoolean(Constant.LOGIN_STATUS, false)) {
String rollno = preferences.getString(Constant.ROLLNO, "");

String batch = getBatch(rollno);
String department = getDepartment(rollno);
FirebaseMessaging.getInstance().subscribeToTopic(batch);
FirebaseMessaging.getInstance().subscribeToTopic(department);
}
}
notifications.putBoolean(Constant.SUBSCRIBE_NOTIFICATION,true);
notifications.apply();
Toast.makeText(MainActivity.this, getString(R.string.msg_subscribed), Toast.LENGTH_SHORT).show();
Timber.d("Subscribed to notification.");
}

private String getDepartment(String rollno) {
String year = rollno.substring(0, 2);
String dept = rollno.substring(4, 6);
return dept + year;
}

private String getBatch(String rollno) {
String year = rollno.substring(0, 2);
String category = rollno.substring(2, 4);
String value= null;

if (category.equals("01")) {
value= "btech" + year;
} else if (category.equals("21")) {
value= "phd" + year;
} else if (category.equals("11")) {
value= "mtech" + year;
} else if (category.equals("12")) {
value= "msc" + year;
}else {
value="unknown";
}
return value;
}

private void showHomeFragment() {
Expand Down Expand Up @@ -143,7 +184,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
MenuItem login = menu.findItem(R.id.action_login_signup);
MenuItem logout = menu.findItem(R.id.action_logout);
MenuItem change_email=menu.findItem(R.id.action_change_email);
MenuItem change_email = menu.findItem(R.id.action_change_email);
if (preferences.getBoolean(Constant.LOGIN_STATUS, false)) {
//user is logged in
login.setVisible(false);
Expand Down Expand Up @@ -177,7 +218,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
public void onClick(DialogInterface dialog, int which) {
clearData();
finish();
startActivity(new Intent(MainActivity.this,LoginSignupActivity.class));
startActivity(new Intent(MainActivity.this, LoginSignupActivity.class));
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
Expand Down