-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from jogrimst/master
#31 Create StudentUpdateReceiver
- Loading branch information
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
app/src/main/java/org/literacyapp/chat/receiver/StudentUpdateReceiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.literacyapp.chat.receiver; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
import android.preference.PreferenceManager; | ||
import android.text.TextUtils; | ||
import android.util.Log; | ||
|
||
public class StudentUpdateReceiver extends BroadcastReceiver { | ||
|
||
public static final String PREF_STUDENT_ID = "pref_student_id"; | ||
public static final String PREF_STUDENT_AVATAR = "pref_student_avatar"; | ||
|
||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
Log.i(getClass().getName(), "onReceive"); | ||
|
||
String studentId = intent.getStringExtra("studentId"); | ||
Log.i(getClass().getName(), "studentId: " + studentId); | ||
|
||
String studentAvatar = intent.getStringExtra("studentAvatar"); | ||
Log.i(getClass().getName(), "studentAvatar: " + studentAvatar); | ||
|
||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); | ||
|
||
if (!TextUtils.isEmpty(studentId)) { | ||
sharedPreferences.edit().putString(PREF_STUDENT_ID, studentId).commit(); | ||
} | ||
|
||
if (!TextUtils.isEmpty(studentAvatar)) { | ||
sharedPreferences.edit().putString(PREF_STUDENT_AVATAR, studentAvatar).commit(); | ||
} | ||
} | ||
} |