use of garbagecollectors.com.unipool.Message in project UniPool by divya21raj.
the class BaseActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
setContentView(getContentViewId());
mAuth = FirebaseAuth.getInstance();
currentUser = mAuth.getCurrentUser();
userDatabaseReference = FirebaseDatabase.getInstance().getReference("users/" + finalCurrentUser.getUserId());
userMessageDatabaseReference = FirebaseDatabase.getInstance().getReference("messages/" + finalCurrentUser.getUserId());
MessageDBTask.addOnCompleteListener(task -> {
DataSnapshot messageData = (DataSnapshot) MessageDBTask.getResult();
for (DataSnapshot dataSnapshot : messageData.getChildren()) {
Message message = dataSnapshot.getValue(Message.class);
assert message != null;
if (!(message.getMessageId().equals("def@ult")))
UtilityMethods.putMessageInMap(messages, message);
}
});
entryDatabaseReference.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
TripEntry tripEntry = dataSnapshot.getValue(TripEntry.class);
UtilityMethods.updateTripList(tripEntryList, tripEntry);
HomeActivity.updateRecycleAdapter();
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
TripEntry tripEntry = dataSnapshot.getValue(TripEntry.class);
UtilityMethods.updateTripList(tripEntryList, tripEntry);
HomeActivity.updateRecycleAdapter();
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
TripEntry tripEntry = dataSnapshot.getValue(TripEntry.class);
if (tripEntry != null) {
UtilityMethods.removeFromList(tripEntryList, tripEntry.getEntry_id());
HomeActivity.updateRecycleAdapter();
}
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
// IDK
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Failed to read value
Log.w("Hello", "Failed to read value.", databaseError.toException());
Toast.makeText(getApplicationContext(), "Network Issues!", Toast.LENGTH_SHORT).show();
}
});
userDatabaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// whenever data at this location is updated.
try {
finalCurrentUser = dataSnapshot.getValue(User.class);
UtilityMethods.populateChatMap(dataSnapshot);
ReceivedRequestsFragment.refreshRecycler();
SentRequestsFragment.refreshRecycler();
ChatFragment.refreshRecycler();
} catch (DatabaseException dbe) {
Toast.makeText(getApplicationContext(), "Some problems, mind restarting the app?", Toast.LENGTH_LONG).show();
}
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w("UserDB", "Failed to read userDB value.", error.toException());
Toast.makeText(getApplicationContext(), "Network Issues!", Toast.LENGTH_SHORT).show();
}
});
bottomNavigationView = findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnNavigationItemSelectedListener(this);
} catch (NullPointerException nlp) {
finish();
startActivity(new Intent(getApplicationContext(), LoginActivity.class));
}
}
use of garbagecollectors.com.unipool.Message in project UniPool by divya21raj.
the class MessageListActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_message_list);
messagesLayout = findViewById(R.id.layout1);
sendButton = findViewById(R.id.sendButton);
messageArea = findViewById(R.id.message_edit_text);
scrollView = findViewById(R.id.scrollView);
personalMessageMap = new TreeMap<>();
messagesOnScreen = new ArrayList<>();
messageProgressDialog = new ProgressDialog(this);
messageProgressDialog.setMessage("Fetching your messages...");
messageProgressDialog.show();
setScrollViewToBottom();
DatabaseReference userMessageDatabaseReference = FirebaseDatabase.getInstance().getReference("messages/" + BaseActivity.getFinalCurrentUser().getUserId());
// load from local
userMessageDatabaseReference.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Message message = dataSnapshot.getValue(Message.class);
if (message != null) {
UtilityMethods.putMessageInMap(BaseActivity.getMessages(), message);
if (!message.getMessageId().equals("def@ult") && (message.getSenderId().equals(chatUser.getUserId()) || message.getReceiverId().equals(chatUser.getUserId()))) {
personalMessageMap.containsKey(message.getCreatedAtTime());
if (!messagesOnScreen.contains(message.getMessageId())) {
showMessage(message);
}
} else if (message.getMessageId().equals("def@ult"))
messageProgressDialog.dismiss();
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Failed to read value
Log.w("Hello", "Failed to read value.", databaseError.toException());
Toast.makeText(getApplicationContext(), "Problems! Couldn't fetch messages...", Toast.LENGTH_LONG).show();
}
});
sendButton.setOnClickListener(view -> {
String typedMessage = messageArea.getText().toString();
if (!typedMessage.isEmpty()) {
Message message = new Message("", pairUp.getPairUpId(), typedMessage, BaseActivity.getFinalCurrentUser().getUserId(), chatUser.getUserId(), UtilityMethods.getCurrentTime());
// online update
UtilityMethods.putMessageOnDB(message, chatUser, BaseActivity.getFinalCurrentUser());
// local update
UtilityMethods.putMessageInMap(BaseActivity.getMessages(), message);
HashMap<String, String> notificationObject = new HashMap<>();
notificationObject.put("from", BaseActivity.getFinalCurrentUser().getUserId());
notificationObject.put("type", "chat");
notificationDatabaseReference.child(chatUser.getUserId()).push().setValue(notificationObject);
messageArea.setText("");
personalMessageMap.put(message.getCreatedAtTime(), message);
showMessage(message);
}
});
// detecting if keyboard on-screen
final View activityRootView = findViewById(R.id.activity_message_list);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
int heightDiff = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
if (heightDiff > UtilityMethods.dpToPx(MessageListActivity.this, 200))
setScrollViewToBottom();
});
}
use of garbagecollectors.com.unipool.Message in project UniPool by divya21raj.
the class LoginActivity method dummyInitFinalCurrentUser.
private void dummyInitFinalCurrentUser(FirebaseUser user) throws ParseException {
HashMap<String, Float> dummyLambdaMap = new HashMap<>();
dummyLambdaMap.put("123", 0f);
GenLocation dummyGenLocation = new GenLocation("dummy", "dummy", 0d, 0d);
TripEntry dummyTripEntry = new TripEntry("dummy", "dummyId", "DummyUser", "12:00", "1/11/12", dummyGenLocation, dummyGenLocation, dummyLambdaMap);
HashMap<String, TripEntry> dummyUserEntries = new HashMap<>();
dummyUserEntries.put("dummy", dummyTripEntry);
HashMap<String, TripEntry> dummyRequestSent = new HashMap<>();
dummyRequestSent.put(dummyTripEntry.getEntry_id(), dummyTripEntry);
ArrayList<String> dummyUserIdList = new ArrayList<>();
dummyUserIdList.add("dummy");
HashMap<String, ArrayList<String>> dummyRequestReceived = new HashMap<>();
dummyRequestReceived.put("dummy", dummyUserIdList);
Message dummyMessage = new Message("dummy", "", "", "dummy", "dummy", 1L);
ArrayList<Message> dummyMessages = new ArrayList<>();
dummyMessages.add(dummyMessage);
PairUp dummyPairUp = new PairUp("dummydummy", "dummy", "dummy", "dummy", dummyUserIdList);
HashMap<String, PairUp> dummyPairUps = new HashMap<>();
dummyPairUps.put("dummy", dummyPairUp);
String deviceToken = FirebaseInstanceId.getInstance().getToken();
String url = "";
Uri photoUrl = user.getPhotoUrl();
if (photoUrl != null)
url = photoUrl.toString();
finalCurrentUser = new User(user.getUid(), user.getDisplayName(), url, dummyUserEntries, dummyRequestSent, dummyRequestReceived, deviceToken, true, dummyPairUps);
}
Aggregations