-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
166 additions
and
11 deletions.
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
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
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
20 changes: 20 additions & 0 deletions
20
...orkshop_android_crm14/services/discussion/getDiscussionById/GetDiscussionByIdHandler.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,20 @@ | ||
package fr.gobelins.crm14.workshop_android_crm14.services.discussion.getDiscussionById; | ||
|
||
import com.firebase.client.DataSnapshot; | ||
import com.firebase.client.FirebaseError; | ||
import com.firebase.client.ValueEventListener; | ||
|
||
/** | ||
* Created by risq on 10/24/15. | ||
*/ | ||
public class GetDiscussionByIdHandler implements ValueEventListener { | ||
@Override | ||
public void onDataChange(DataSnapshot dataSnapshot) { | ||
|
||
} | ||
|
||
@Override | ||
public void onCancelled(FirebaseError firebaseError) { | ||
|
||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...d_crm14/services/discussion/getDiscussionIdByContact/GetDiscussionIdByContactHandler.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,68 @@ | ||
package fr.gobelins.crm14.workshop_android_crm14.services.discussion.getDiscussionIdByContact; | ||
|
||
import android.util.Log; | ||
|
||
import com.firebase.client.DataSnapshot; | ||
import com.firebase.client.FirebaseError; | ||
import com.firebase.client.ValueEventListener; | ||
|
||
import java.security.GeneralSecurityException; | ||
|
||
import fr.gobelins.crm14.workshop_android_crm14.discussion.Discussion; | ||
import fr.gobelins.crm14.workshop_android_crm14.services.BusProvider; | ||
import fr.gobelins.crm14.workshop_android_crm14.services.crypto.RSACryptoService; | ||
import fr.gobelins.crm14.workshop_android_crm14.services.discussion.DiscussionService; | ||
import fr.gobelins.crm14.workshop_android_crm14.services.user.findUserByUserName.FindUserByUsernameEvent; | ||
import fr.gobelins.crm14.workshop_android_crm14.user.User; | ||
|
||
/** | ||
* Created by risq on 10/24/15. | ||
*/ | ||
public class GetDiscussionIdByContactHandler implements ValueEventListener { | ||
private final User guest; | ||
private final User author; | ||
private int requestId; | ||
|
||
public GetDiscussionIdByContactHandler(User author, User guest) { | ||
this.author = author; | ||
this.guest = guest; | ||
} | ||
|
||
@Override | ||
public void onDataChange(DataSnapshot dataSnapshot) { | ||
if (dataSnapshot.getValue() != null) { | ||
String discussionId = dataSnapshot.getValue().toString(); | ||
DiscussionService.getInstance() | ||
.getDiscussionById(discussionId); | ||
} else { | ||
Log.d("discussionID", "null"); | ||
try { | ||
String uid = RSACryptoService.generateId(); | ||
Discussion discussion = new Discussion(uid); | ||
discussion.setAuthorUid(author.getUid()); | ||
discussion.setGuestUid(guest.getUid()); | ||
DiscussionService.getInstance() | ||
.saveDiscussion(discussion); | ||
|
||
DiscussionService.getInstance() | ||
.addDiscussionToUsers(discussion); | ||
} catch (GeneralSecurityException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
// if (dataSnapshot.getChildren().iterator().hasNext()) { | ||
// BusProvider.getInstance() | ||
// .post(new FindUserByUsernameEvent(dataSnapshot.getChildren().iterator().next().getKey(), requestId)); | ||
// } else { | ||
// BusProvider.getInstance() | ||
// .post(new FindUserByUsernameEvent(requestId)); | ||
// } | ||
// | ||
} | ||
|
||
@Override | ||
public void onCancelled(FirebaseError firebaseError) { | ||
Log.d("FindUserByUsername", "CANCELLED"); | ||
BusProvider.getInstance().post(new FindUserByUsernameEvent(firebaseError, requestId)); | ||
} | ||
} |