Skip to content

Commit

Permalink
Firebase Received messages
Browse files Browse the repository at this point in the history
#6
- RxJava and Retrofit2 for sending absence's messages
- new topics by login, approveIco for approving absences and
mytopicUserid for sending approvement to user
- subscribe topics by login
- name of user in settings
  • Loading branch information
eurosecom committed Feb 27, 2017
1 parent 362001d commit fc88968
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.messaging.*;

public class EmailPasswordActivity extends BaseActivity implements
View.OnClickListener {
Expand All @@ -60,7 +61,7 @@ public class EmailPasswordActivity extends BaseActivity implements
private FirebaseAuth.AuthStateListener mAuthListener;
// [END declare_auth_listener]

String usertype="0", userico="0";
String usertype="0", userico="0", myuserid="", username="";

@Override
public void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -201,19 +202,30 @@ private void onAuthSuccess(FirebaseUser user) {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// Get user information
User user = dataSnapshot.getValue(User.class);
usertype = user.getUstype();
userico = user.getUsico();
User userx = dataSnapshot.getValue(User.class);
usertype = userx.getUstype();
userico = userx.getUsico();
myuserid = user.getUid();
Log.d("usertype", usertype);
username = userx.getUsname();

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
SharedPreferences.Editor editor = prefs.edit();

editor.putString("ustype", usertype).apply();
editor.putString("usico", userico).apply();
editor.putString("usname", username).apply();

editor.commit();

String approvetopic = "approve" + userico;
String mytopic = "mytopic" + myuserid;

com.google.firebase.messaging.FirebaseMessaging.getInstance().subscribeToTopic(mytopic);
if( usertype.equals("99")) {
com.google.firebase.messaging.FirebaseMessaging.getInstance().subscribeToTopic(approvetopic);
}

}

@Override
Expand Down
26 changes: 23 additions & 3 deletions app/src/main/java/com/eusecom/attendance/NewAbsenceActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.eusecom.attendance.models.User;
import com.eusecom.attendance.models.Post;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
Expand Down Expand Up @@ -391,9 +392,17 @@ private void writeAbsence(String usico, String usid, String ume, String dmxa, St
mDatabase.updateChildren(childUpdates);


String Notititle = dmxa + "" + dmna;
String Notibody = "I woud like to get " + dmxa + " " + dmna;
String approvetopic = "/topics/news";
String Notititle = SettingsActivity.getUsname(NewAbsenceActivity.this) + " " + dmxa + " " + dmna;
long timestampod = Long.parseLong(daod) * 1000L;
String datefroms = getDate(timestampod );
long timestampdo = Long.parseLong(dado) * 1000L;
String datetos = getDate(timestampdo );

String Notibody = getString(R.string.idliketoget) + " " + dmxa + " " + dmna + " "
+ getString(R.string.from) + " " + datefroms + " " + getString(R.string.to) + " " + datetos
+ " " + hodxb + " " + getString(R.string.hodiny);

String approvetopic = "/topics/approve" + SettingsActivity.getUsIco(NewAbsenceActivity.this);
//FirebaseMessaging firebasemessaging = new FirebaseMessaging("/topics/news", Notititle, Notibody);
FirebaseRxSendMessaging firebasemessaging = new FirebaseRxSendMessaging(approvetopic, Notititle, Notibody);
subscription = firebasemessaging.SendNotification();
Expand Down Expand Up @@ -478,6 +487,17 @@ public void onNext(Message message) {

}//end of FirebaseRxSendMessaging

private String getDate(long timeStamp){

try{
DateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
Date netDate = (new Date(timeStamp));
return sdf.format(netDate);
}
catch(Exception ex){
return "xx";
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class SettingsActivity extends android.preference.PreferenceActivity {
public static final String USER_TYPE = "ustype";
public static final String USER_ICO = "usico";
public static final String USER_ATW = "usatw";
public static final String USNAME = "usname";


@Override
Expand Down Expand Up @@ -55,6 +56,9 @@ public static String getUsIco(Context ctx){
public static String getUsAtw(Context ctx){
return PreferenceManager.getDefaultSharedPreferences(ctx).getString(USER_ATW,"0");
}


public static String getUsname(Context ctx){
return PreferenceManager.getDefaultSharedPreferences(ctx).getString(USNAME,"0");
}

}
6 changes: 6 additions & 0 deletions app/src/main/java/com/eusecom/attendance/models/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public String getUstype() {

}

public String getUsname() {

return this.username;

}

public String getUsico() {

return this.usico;
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@
<string name="usico_summary">ID of Company where user work.</string>
<string name="usatw_title">User at work.</string>
<string name="usatw_summary">1-user at work, 0-user leav work.</string>
<string name="usname_title">Name of user.</string>
<string name="usname_summary">Name of logged user.</string>

<!-- Nav Drawer -->
<string name="slider">Slider</string>
Expand Down Expand Up @@ -195,6 +197,8 @@

<string name="abssave">Absence saved.</string>
<string name="mesapprovesent">Absence sent to approve.</string>
<string name="idliketoget">I am asking a</string>



</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
android:summary="@string/fir_summary"
android:title="@string/fir_title" />

<EditTextPreference
android:key="usname"
android:enabled="true"
android:summary="@string/usname_summary"
android:title="@string/usname_title" />

<EditTextPreference
android:key="ustype"
android:enabled="true"
Expand Down

0 comments on commit fc88968

Please sign in to comment.