Search in sources :

Example 1 with DatabaseReference

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;
}
Also used : DatabaseReference(com.google.firebase.database.DatabaseReference) Metric(com.supercilex.robotscouter.data.model.Metric)

Example 2 with DatabaseReference

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());
}
Also used : Action(com.google.firebase.appindexing.Action) DatabaseReference(com.google.firebase.database.DatabaseReference)

Example 3 with DatabaseReference

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);
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) DatabaseReference(com.google.firebase.database.DatabaseReference) PartiesRepository(se.zinokader.spotiq.repository.PartiesRepository) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 4 with 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);
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) DatabaseReference(com.google.firebase.database.DatabaseReference) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Example 5 with DatabaseReference

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) {
        }
    });
}
Also used : DatabaseReference(com.google.firebase.database.DatabaseReference) DataSnapshot(com.google.firebase.database.DataSnapshot) DatabaseError(com.google.firebase.database.DatabaseError) Transaction(com.google.firebase.database.Transaction) MutableData(com.google.firebase.database.MutableData) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

DatabaseReference (com.google.firebase.database.DatabaseReference)157 DatabaseError (com.google.firebase.database.DatabaseError)95 DataSnapshot (com.google.firebase.database.DataSnapshot)87 ValueEventListener (com.google.firebase.database.ValueEventListener)61 FirebaseDatabase (com.google.firebase.database.FirebaseDatabase)50 HashMap (java.util.HashMap)24 View (android.view.View)18 MutableData (com.google.firebase.database.MutableData)17 Transaction (com.google.firebase.database.Transaction)17 Intent (android.content.Intent)16 FirebaseUser (com.google.firebase.auth.FirebaseUser)13 ArrayList (java.util.ArrayList)12 TextView (android.widget.TextView)11 Query (com.google.firebase.database.Query)11 Map (java.util.Map)11 ProgressDialog (android.app.ProgressDialog)10 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)10 ChildEventListener (com.google.firebase.database.ChildEventListener)9 SharedPreferences (android.content.SharedPreferences)8 ChatMessageHelper (ingage.ingage20.helpers.ChatMessageHelper)8