use of com.google.firebase.database.DatabaseReference in project Robot-Scouter by SUPERCILEX.
the class ScoutTemplateSheet method onClick.
@Override
public void onClick(View v) {
int id = v.getId();
DatabaseReference templateRef = FIREBASE_SCOUT_TEMPLATES.child(mTemplateKey);
if (id == R.id.reset_template_all || id == R.id.reset_template_team) {
mRecyclerView.clearFocus();
ResetTemplateDialog.Companion.show(getChildFragmentManager(), TeamHelper.parse(getArguments()), id == R.id.reset_template_all);
return;
} else if (id == R.id.remove_metrics) {
RemoveAllMetricsDialog.Companion.show(getFragmentManager(), templateRef);
return;
}
int priority = getHighestIntPriority(mAdapter.getSnapshots()) + 1;
DatabaseReference metricRef = templateRef.push();
switch(id) {
case R.id.add_checkbox:
metricRef.setValue(new Metric.Boolean("", false), priority);
break;
case R.id.add_counter:
metricRef.setValue(new Metric.Number("", 0, null), priority);
break;
case R.id.add_spinner:
metricRef.setValue(new Metric.List("", Collections.singletonMap("a", "Item 1"), "a"), priority);
metricRef.child(FIREBASE_VALUE).child("a").setPriority(0);
break;
case R.id.add_note:
metricRef.setValue(new Metric.Text("", ""), priority);
break;
case R.id.add_stopwatch:
metricRef.setValue(new Metric.Stopwatch("", Collections.emptyList()), priority);
break;
case R.id.add_header:
metricRef.setValue(new Metric.Header("", null), priority);
break;
default:
throw new IllegalStateException("Unknown id: " + id);
}
mItemTouchCallback.addItemToScrollQueue(mAdapter.getItemCount());
mFam.close(true);
mHasAddedItem = true;
}
use of com.google.firebase.database.DatabaseReference in project Robot-Scouter by SUPERCILEX.
the class TeamHelper method addTeam.
public void addTeam() {
DatabaseReference index = getIndicesRef().push();
mTeam.setKey(index.getKey());
Long number = mTeam.getNumberAsLong();
index.setValue(number, number);
if (!Constants.sFirebaseScoutTemplates.isEmpty()) {
mTeam.setTemplateKey(Constants.sFirebaseScoutTemplates.get(0).getKey());
}
forceUpdateTeam();
forceRefresh();
FirebaseUserActions.getInstance().end(new Action.Builder(Action.Builder.ADD_ACTION).setObject(toString(), getDeepLink()).build());
}
use of com.google.firebase.database.DatabaseReference in project SpotiQ by ZinoKader.
the class AppModule method providePartiesRepository.
@Provides
@Singleton
PartiesRepository providePartiesRepository() {
FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
DatabaseReference databaseReference = firebaseDatabase.getReference().child(FirebaseConstants.CHILD_PARTYLIST);
return new PartiesRepository(databaseReference);
}
use of com.google.firebase.database.DatabaseReference in project FirebaseUI-Android by firebase.
the class ChatActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chat);
mAuth = FirebaseAuth.getInstance();
mAuth.addAuthStateListener(this);
mSendButton = (Button) findViewById(R.id.sendButton);
mMessageEdit = (EditText) findViewById(R.id.messageEdit);
mEmptyListMessage = (TextView) findViewById(R.id.emptyTextView);
mRef = FirebaseDatabase.getInstance().getReference();
mChatRef = mRef.child("chats");
mSendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String uid = mAuth.getCurrentUser().getUid();
String name = "User " + uid.substring(0, 6);
Chat chat = new Chat(name, mMessageEdit.getText().toString(), uid);
mChatRef.push().setValue(chat, new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError error, DatabaseReference reference) {
if (error != null) {
Log.e(TAG, "Failed to write message", error.toException());
}
}
});
mMessageEdit.setText("");
}
});
mManager = new LinearLayoutManager(this);
mManager.setReverseLayout(false);
mMessages = (RecyclerView) findViewById(R.id.messagesList);
mMessages.setHasFixedSize(false);
mMessages.setLayoutManager(mManager);
}
use of com.google.firebase.database.DatabaseReference in project iNGAGE by davis123123.
the class PostThreadActivity method checkPageExist.
public void checkPageExist(String threadTitle) {
Log.d("CHECKPAGE", "yes3");
final DatabaseReference post_root = FirebaseDatabase.getInstance().getReference().child(threadTitle);
post_root.runTransaction(new Transaction.Handler() {
@Override
public Transaction.Result doTransaction(MutableData mutableData) {
Log.d("ROOT", String.valueOf(mutableData));
if (mutableData.hasChildren()) {
Log.d("ROOTCHILDREN", "yes");
} else {
Log.d("ROOTCHILDREN", "no");
Map<String, Object> map_page = new HashMap<String, Object>();
map_page.put("1", "");
String fPage = "1";
post_root.updateChildren(map_page);
}
return Transaction.success(mutableData);
}
@Override
public void onComplete(DatabaseError databaseError, boolean b, DataSnapshot dataSnapshot) {
}
});
}
Aggregations