Skip to content

Commit

Permalink
trying to get shit working
Browse files Browse the repository at this point in the history
  • Loading branch information
iwasunowimme committed Oct 22, 2017
1 parent 9d6714a commit 565518e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
13 changes: 10 additions & 3 deletions ReminderApp/app/src/main/AndroidManifest.xml
Expand Up @@ -13,12 +13,19 @@
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Register" >
<intent-filter>
<action android:name="Register" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".Register" />
<activity android:name=".Users" />
<activity android:name=".Chat" />
<activity android:name=".Chat"
android:configChanges="keyboardHidden"
/>

<service android:name=".MyFirebaseInstanceIDService">
<intent-filter>
Expand Down
Expand Up @@ -90,7 +90,8 @@ public void run() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
value = (String) dataSnapshot.child("users").child(UserDetails.chatWith).child("token").getValue();
sendFCMNotification(value, messageText);
String nickname = (String) dataSnapshot.child("users").child(UserDetails.username).child("nickname").getValue();
sendFCMNotification(value, messageText, nickname);
}

@Override
Expand Down Expand Up @@ -149,7 +150,7 @@ public void onCancelled(DatabaseError firebaseError) {
//AAAAJ6Ftp0Q:APA91bE_zC-a3x7_SobgoxfLeptgBUu5EUw4bCCxYW2SoKVr90cS6rvfSz7UhvmPjRAlXtgElKLXekTFYO9TVJSQLQPBXqHFEZgKsSSNs4yMqiK2ReIMcuzXTgwkp0ZoeZxP5xQF5HKb
//dtEW9bbkOf8:APA91bGN_oHvsik8x-mmhJOXqrc2k7G9m270j1Db5rqvKHWSzEzNScv5SveyERDiQ57wMnJtjCztTvqZ51VIUTkPjy90524KDDqwT3d-y2HbgtLPdFSu5j4_ydWBrTwi_4d6w_asTfXJ

private void sendFCMNotification(String token, String reminderMessage) {
private void sendFCMNotification(String token, String reminderMessage, String nickname) {

try {
//TODO this FCM post request not working
Expand All @@ -169,12 +170,15 @@ private void sendFCMNotification(String token, String reminderMessage) {
JSONObject root = new JSONObject();
JSONObject data = new JSONObject();
data.put("body", reminderMessage);
data.put("title", "Message from " + UserDetails.chatWith);
data.put("title", "Message from " + nickname);
data.put("sound", "Default");
data.put("click_action", "Register");
root.put("notification", data);
root.put("to",token);




byte[] outputBytes = root.toString().getBytes("UTF-8");
OutputStream os = connection.getOutputStream();
os.write(outputBytes);
Expand Down
Expand Up @@ -17,9 +17,6 @@ protected void onCreate(Bundle savedInstanceState) {

/*TODO LIST
1: Comments everything
2:FCM token
3: duplicate user
4: duplicate email
5: chat scroll and a lot more, no auto scroll
5: chat scroll and a lot more, no auto scroll
5: chat scroll and a lot more, no auto scroll
Expand Down
Expand Up @@ -21,9 +21,14 @@ public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);

Log.d("Msg", "Message received ["+remoteMessage+"]");

Intent intent;
// Create Notification
Intent intent = new Intent(this, MainActivity.class);
String click_action = remoteMessage.getNotification().getClickAction();
if(click_action=="") {
intent = new Intent(this, MainActivity.class);
}else{
intent = new Intent(click_action);
}
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 1410,
intent, PendingIntent.FLAG_ONE_SHOT);
Expand Down
Expand Up @@ -28,6 +28,7 @@ public class Users extends AppCompatActivity {
ListView usersList;
TextView noUsersText;
ArrayList<String> al = new ArrayList<>();
ArrayList<String> a2 = new ArrayList<>();
int totalUsers = 0;
ProgressDialog pd;

Expand All @@ -43,6 +44,7 @@ protected void onCreate(Bundle savedInstanceState) {
pd.setMessage("Loading...");
pd.show();

//generates a json string to get all users and their nicknames
String url = "https://reminderapp-bf7f0.firebaseio.com/users.json";

StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener<String>(){
Expand All @@ -63,12 +65,13 @@ public void onErrorResponse(VolleyError volleyError) {
usersList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
UserDetails.chatWith = al.get(position);
UserDetails.chatWith = a2.get(position);
startActivity(new Intent(Users.this, Chat.class));
}
});
}

//itterates through a json string to populate usernames
public void doOnSuccess(String s){
try {
JSONObject obj = new JSONObject(s);
Expand All @@ -80,7 +83,8 @@ public void doOnSuccess(String s){
key = i.next().toString();

if(!key.equals(UserDetails.username)) {
al.add(key);
a2.add(key);
al.add(obj.optJSONObject(key).optString("nickname"));
}

totalUsers++;
Expand All @@ -90,6 +94,7 @@ public void doOnSuccess(String s){
e.printStackTrace();
}

//if users exist display list otherwise display no users text
if(totalUsers <=1){
noUsersText.setVisibility(View.VISIBLE);
usersList.setVisibility(View.GONE);
Expand Down

0 comments on commit 565518e

Please sign in to comment.