Created
July 28, 2016 00:25
-
-
Save SahajRana/fe4c5247019891c9f690b320a8f3bb3e to your computer and use it in GitHub Desktop.
Realm update Problem
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
private void addOnFirebase(){ | |
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); | |
EmailPref = prefs.getString("EmailPref", EmailPref); | |
DatabaseReference mFirebaseRef = FirebaseDatabase.getInstance().getReferenceFromUrl(constants.FIREBASE_URL + "rootssahaj/authGplus/users/students/" + EmailPref + "/profile"); | |
DatabaseReference mFirebaseRefHashnamePool = FirebaseDatabase.getInstance().getReferenceFromUrl(constants.FIREBASE_URL + "rootssahaj/authGplus/hashnamePool"); | |
String month=monthSelected; | |
month=month.substring(0,3); | |
Map<String, Object> statusChange = new HashMap<String, Object>(); | |
statusChange.put("userNAME",usernameString); | |
statusChange.put("hashname", hashnameString); | |
if (datePosition!=0) | |
statusChange.put("birthday",dateSelected+" "+month); | |
Realm realm2 = Realm.getInstance(realmConfig); | |
final RealmResults<ToTal_ProfileModelRealmClass> result2 = realm2.where(ToTal_ProfileModelRealmClass.class) | |
.equalTo("userEmailKey", EmailPref) | |
.findAll(); | |
//ToTal_ProfileModelRealmClass toTal_profileModelRealmClass = result.get(0); | |
ToTal_ProfileModelRealmClass toTal_profileModelRealmClass= new ToTal_ProfileModelRealmClass(); | |
toTal_profileModelRealmClass.setUserEmailKey(EmailPref); | |
if (mTextViewQuote.getText().toString().length()!=0) { | |
statusChange.put("quote", mTextViewQuote.getText().toString()); | |
toTal_profileModelRealmClass.setQuote(mTextViewQuote.getText().toString()); | |
}else | |
toTal_profileModelRealmClass.setQuote(null); | |
Log.e("SahajLOG18", "hashaname String "+hashnameString); | |
if (datePosition!=0){ | |
toTal_profileModelRealmClass.setBirthday("Wish me on " + dateSelected + " " + month); | |
}else | |
toTal_profileModelRealmClass.setBirthday(null); | |
if (yearPosition!=0) { | |
toTal_profileModelRealmClass.setYear(yearSelected); | |
}else | |
toTal_profileModelRealmClass.setYear(result2.get(0).getYear()); | |
toTal_profileModelRealmClass.setHashname(hashnameString); | |
toTal_profileModelRealmClass.setUserNAME(usernameString); | |
toTal_profileModelRealmClass.setBranch(result2.get(0).getBranch()); | |
toTal_profileModelRealmClass.setCampus(result2.get(0).getCampus()); | |
toTal_profileModelRealmClass.setCourse(result2.get(0).getCourse()); | |
toTal_profileModelRealmClass.setGplusURL(result2.get(0).getGplusURL()); | |
toTal_profileModelRealmClass.setPicurl(result2.get(0).getPicurl()); | |
toTal_profileModelRealmClass.setPicOfflineName(result2.get(0).getPicOfflineName()); | |
toTal_profileModelRealmClass.setPicurl50DP(result2.get(0).getPicurl50DP()); | |
toTal_profileModelRealmClass.setUserEmail(result2.get(0).getUserEmail()); | |
realm2.beginTransaction(); | |
realm2.copyToRealmOrUpdate(toTal_profileModelRealmClass); | |
realm2.commitTransaction(); | |
Realm realm = Realm.getInstance(realmConfig); | |
final RealmResults<ToTal_ProfileModelRealmClass> result = realm.where(ToTal_ProfileModelRealmClass.class) | |
.equalTo("userEmailKey", EmailPref) | |
.findAll(); | |
// realm.beginTransaction(); | |
// ToTal_ProfileModelRealmClass totalPro= realm.createObject(ToTal_ProfileModelRealmClass.class); | |
// totalPro=result.get(0); | |
// realm.copyToRealmOrUpdate(totalPro); | |
// realm.commitTransaction(); | |
Log.e("SahajLOG18", "resultChecking "+result); | |
if (yearPosition!=0) | |
statusChange.put("year",yearSelected); | |
Map<String, Object> HashnameAdd = new HashMap<String, Object>(); | |
HashnameAdd.put(hashnameString, EmailPref); | |
mFirebaseRefHashnamePool.updateChildren(HashnameAdd); | |
mFirebaseRef.updateChildren(statusChange); | |
if (!PreviousHashname.equals(mTextViewHashName.getText().toString())) | |
mFirebaseRefHashnamePool.child(PreviousHashname).removeValue(); | |
//finish(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment