Search in sources :

Example 26 with FirebaseDatabase

use of com.google.firebase.database.FirebaseDatabase in project SpotiQ by ZinoKader.

the class AppModule method providePartiesRepository.

@Provides
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) Provides(dagger.Provides)

Example 27 with FirebaseDatabase

use of com.google.firebase.database.FirebaseDatabase in project FirebaseUI-Android by firebase.

the class FirebaseIndexArrayTest method setUp.

@Before
public void setUp() throws Exception {
    FirebaseDatabase databaseInstance = FirebaseDatabase.getInstance(getAppInstance(ApplicationProvider.getApplicationContext()));
    mRef = databaseInstance.getReference().child("firebasearray");
    mKeyRef = databaseInstance.getReference().child("firebaseindexarray");
    mArray = new FirebaseIndexArray<>(mKeyRef, mRef, new ClassSnapshotParser<>(Integer.class));
    mRef.removeValue();
    mKeyRef.removeValue();
    mListener = runAndWaitUntil(mArray, () -> {
        for (int i = 1; i <= INITIAL_SIZE; i++) {
            TestUtils.pushValue(mKeyRef, mRef, i, i);
        }
    }, () -> mArray.size() == INITIAL_SIZE);
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) Before(org.junit.Before)

Example 28 with FirebaseDatabase

use of com.google.firebase.database.FirebaseDatabase in project FirebaseUI-Android by firebase.

the class FirebaseIndexArrayOfObjectsTest method setUp.

@Before
public void setUp() throws Exception {
    FirebaseDatabase databaseInstance = FirebaseDatabase.getInstance(getAppInstance(ApplicationProvider.getApplicationContext()));
    mRef = databaseInstance.getReference().child("firebasearray").child("objects");
    mKeyRef = databaseInstance.getReference().child("firebaseindexarray").child("objects");
    mArray = new FirebaseIndexArray<>(mKeyRef, mRef, new ClassSnapshotParser<>(Bean.class));
    mRef.removeValue();
    mKeyRef.removeValue();
    mListener = runAndWaitUntil(mArray, () -> {
        for (int i = 1; i <= INITIAL_SIZE; i++) {
            TestUtils.pushValue(mKeyRef, mRef, new Bean(i, "Text " + i, i % 2 == 0), i);
        }
    }, () -> mArray.size() == INITIAL_SIZE);
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) Before(org.junit.Before)

Example 29 with FirebaseDatabase

use of com.google.firebase.database.FirebaseDatabase in project NPSmiles by bmcglynn1.

the class NewsFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View viewer = inflater.inflate(R.layout.activity_news_feed, container, false);
    View popupLayout = inflater.inflate(R.layout.popup_layout_logged_in, null);
    final ListView list = (ListView) viewer.findViewById(R.id.list);
    final ArrayList<NewsMessage> newsList = new ArrayList<>();
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference myRef = database.getReference("Reference");
    mAuth = FirebaseAuth.getInstance();
    if (mAuth.getCurrentUser() != null) {
        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                PopupMenu popup = new PopupMenu(parent.getContext(), view);
                popup.getMenuInflater().inflate(R.menu.popup_menu, popup.getMenu());
                final TextView title = (TextView) view.findViewById(R.id.title);
                final TextView message = (TextView) view.findViewById(R.id.information);
                if (mAuth.getCurrentUser() != null) {
                    popup.show();
                    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            switch(item.getItemId()) {
                                case R.id.EditMenu:
                                    // refresh view if needed
                                    break;
                                case R.id.DeleteMenu:
                                    // delete from firebase
                                    // refresh view
                                    FirebaseDatabase database = FirebaseDatabase.getInstance();
                                    DatabaseReference myRef = database.getReference("Reference");
                                    Query titleQuery = myRef.child(title.getText().toString());
                                    titleQuery.addListenerForSingleValueEvent(new ValueEventListener() {

                                        @Override
                                        public void onDataChange(DataSnapshot dataSnapshot) {
                                            for (DataSnapshot titleSnapshot : dataSnapshot.getChildren()) {
                                                dataSnapshot.getRef().removeValue();
                                            }
                                        }

                                        @Override
                                        public void onCancelled(DatabaseError databaseError) {
                                        }
                                    });
                                    break;
                            }
                            return true;
                        }
                    });
                }
            }
        });
    }
    myRef.addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            newsList.clear();
            for (DataSnapshot newsItem : dataSnapshot.getChildren()) {
                NewsMessage newsMessage = new NewsMessage();
                for (DataSnapshot item : newsItem.getChildren()) {
                    if (item.getKey().equals("title")) {
                        newsMessage.setTitle((String) item.getValue());
                    } else if (item.getKey().equals("message")) {
                        newsMessage.setMessage((String) item.getValue());
                    } else {
                        newsMessage.setDate((String) item.getValue());
                    }
                }
                newsList.add(newsMessage);
            }
            Collections.sort(newsList);
            CustomAdapter adapter = new CustomAdapter(context, newsList);
            list.setAdapter(adapter);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
    return viewer;
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) Query(com.google.firebase.database.Query) DatabaseReference(com.google.firebase.database.DatabaseReference) ArrayList(java.util.ArrayList) MenuItem(android.view.MenuItem) DataSnapshot(com.google.firebase.database.DataSnapshot) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) ListView(android.widget.ListView) DatabaseError(com.google.firebase.database.DatabaseError) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ValueEventListener(com.google.firebase.database.ValueEventListener) PopupMenu(android.widget.PopupMenu)

Example 30 with FirebaseDatabase

use of com.google.firebase.database.FirebaseDatabase in project NPSmiles by bmcglynn1.

the class CreatePost method addPost.

public void addPost() {
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference myRef = database.getReference("Reference");
    DatabaseReference childRef = myRef.child(newsMessage.getTitle());
    childRef.setValue(newsMessage);
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) DatabaseReference(com.google.firebase.database.DatabaseReference)

Aggregations

FirebaseDatabase (com.google.firebase.database.FirebaseDatabase)53 DatabaseReference (com.google.firebase.database.DatabaseReference)49 DatabaseError (com.google.firebase.database.DatabaseError)28 DataSnapshot (com.google.firebase.database.DataSnapshot)26 ValueEventListener (com.google.firebase.database.ValueEventListener)24 ArrayList (java.util.ArrayList)7 FirebaseUser (com.google.firebase.auth.FirebaseUser)6 ListView (android.widget.ListView)5 Test (org.junit.Test)5 TextView (android.widget.TextView)4 Intent (android.content.Intent)3 View (android.view.View)3 Query (com.google.firebase.database.Query)3 Provides (dagger.Provides)3 SharedPreferences (android.content.SharedPreferences)2 AdapterView (android.widget.AdapterView)2 Product (com.example.asus.onlinecanteen.model.Product)2 ChildEventListener (com.google.firebase.database.ChildEventListener)2 HashMap (java.util.HashMap)2 Before (org.junit.Before)2