Search in sources :

Example 16 with FirebaseDatabase

use of com.google.firebase.database.FirebaseDatabase in project SEProject by NicholasBarreyre.

the class UserInformationEditActivity method updateDatabase.

/**
 * This method updates the UserInformation object in Firebase associated
 * with the user currently logged in.
 */
private void updateDatabase() {
    FirebaseDatabase db = FirebaseDatabase.getInstance();
    DatabaseReference myRef = db.getReference(getString(R.string.activity_user_information_firebase, user.getUsername()));
    myRef.setValue(info);
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) DatabaseReference(com.google.firebase.database.DatabaseReference)

Example 17 with FirebaseDatabase

use of com.google.firebase.database.FirebaseDatabase in project SocialRec by Jkuras.

the class QR_Scan method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
    if (requestCode == BARCODE_READER_REQUEST_CODE) {
        if (resultCode == CommonStatusCodes.SUCCESS) {
            if (data != null) {
                final Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject);
                final FirebaseDatabase database = FirebaseDatabase.getInstance();
                // make sure the substring w/the id code does not contain . # $ [ or ]
                if (!authenticateBarcode(barcode.displayValue)) {
                    mResultTextView.setText("Invalid QR code scanned");
                } else {
                    // parse barcode, remove "uid: " from barcode value
                    final String string = barcode.displayValue.substring(5);
                    // set ref to store/:barcodevalue
                    DatabaseReference aref = database.getReference("stores/" + string);
                    final ValueEventListener postListener = new ValueEventListener() {

                        @Override
                        public void onDataChange(DataSnapshot dataSnapshot) {
                            // if the result is not null, it IS a registered store
                            if (dataSnapshot.getValue() != null) {
                                Store store = dataSnapshot.getValue(Store.class);
                                mResultTextView.setText("Welcome to " + store.getName() + "!");
                                FirebaseDatabase database = FirebaseDatabase.getInstance();
                                // TODO: PART OF CLEANUP
                                // set ref to the reward corresponding to the store
                                DatabaseReference ref = database.getReference("users/" + MainActivity.mAuth.getCurrentUser().getUid() + "/storeRewards/" + string);
                                // get the correct reward
                                StoreReward reward = MainActivity.mUser.getStoreRewards().get(string);
                                // if they have current rewards
                                if (reward != null) {
                                    // increment visit
                                    reward.incrementVisit();
                                    // WIN CONDITION
                                    if (reward.getVisits() % reward.getReward() == 0 & reward.getVisits() != 0) {
                                        LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
                                        View rewardView = inflater.inflate(R.layout.popup_get_reward, null);
                                        final PopupWindow rewardPopup = new PopupWindow(rewardView, 1200, 800);
                                        mRewardTextView.setText("Reward Time!");
                                        rewardPopup.setOutsideTouchable(false);
                                        rewardPopup.showAtLocation(findViewById(R.id.result_textview), Gravity.CENTER, 0, 0);
                                        Button confirmRewardButton = (Button) rewardView.findViewById(R.id.reward_confirm_button);
                                        confirmRewardButton.setOnClickListener(new View.OnClickListener() {

                                            @Override
                                            public void onClick(View view) {
                                                rewardPopup.dismiss();
                                            }
                                        });
                                    } else // NO REWARD CONDITION
                                    {
                                        // tell how many more you need for your next reward
                                        mRewardTextView.setText(reward.getVisits() % reward.getReward() + " out of " + reward.getReward() + " visits");
                                    }
                                    // add the user to the stores customers section
                                    DatabaseReference bref = database.getReference("stores/" + dataSnapshot.getKey() + "/customers/" + MainActivity.mAuth.getCurrentUser().getUid() + "/visits");
                                    bref.setValue(reward.getVisits());
                                    // save storerewards back to the db
                                    ref.setValue(reward);
                                    // increment users total visit counter, and save it to db
                                    MainActivity.mUser.incrementtotalVisits();
                                    database.getReference("users/" + MainActivity.mAuth.getCurrentUser().getUid() + "/totalVisits").setValue(MainActivity.mUser.getTotalVisits());
                                    return;
                                // IF THIS if TRIGGERS NONE OF THE FOLLOWING 20ish LINES WILL HAPPEN
                                }
                                // if they have never visited that store, add a new storeReward
                                mRewardTextView.setText("first visit");
                                reward = (new StoreReward(store.getName(), 1, store.getReward().getReward()));
                                // add the user to the stores customers section
                                DatabaseReference bref = database.getReference("stores/" + dataSnapshot.getKey() + "/customers/" + MainActivity.mAuth.getCurrentUser().getUid());
                                bref.setValue(new StoreReward(MainActivity.mUser.getMyName(), 1, store.getReward().getReward()));
                                // save to db
                                ref.setValue(reward);
                                // increment total visits
                                MainActivity.mUser.incrementtotalVisits();
                                database.getReference("users/" + MainActivity.mAuth.getCurrentUser().getUid() + "/totalVisits").setValue(MainActivity.mUser.getTotalVisits());
                            } else {
                                mResultTextView.setText("Not a Store");
                                mRewardTextView.setText("n/a");
                            }
                        }

                        @Override
                        public void onCancelled(DatabaseError databaseError) {
                            // Getting Post failed, log a message
                            Log.w("", "loadPost:onCancelled", databaseError.toException());
                        // ...
                        }
                    };
                    aref.addListenerForSingleValueEvent(postListener);
                }
            } else
                mResultTextView.setText("No barcode captured");
        } else
            Log.e(LOG_TAG, String.format("Barcode format error", CommonStatusCodes.getStatusCodeString(resultCode)));
    } else
        super.onActivityResult(requestCode, resultCode, data);
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) DatabaseReference(com.google.firebase.database.DatabaseReference) PopupWindow(android.widget.PopupWindow) DataSnapshot(com.google.firebase.database.DataSnapshot) TextView(android.widget.TextView) View(android.view.View) DatabaseError(com.google.firebase.database.DatabaseError) Button(android.widget.Button) Barcode(com.google.android.gms.vision.barcode.Barcode) LayoutInflater(android.view.LayoutInflater) ValueEventListener(com.google.firebase.database.ValueEventListener)

Example 18 with FirebaseDatabase

use of com.google.firebase.database.FirebaseDatabase in project priend by TakoJ.

the class ProfileActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);
    firebaseAuth = FirebaseAuth.getInstance();
    FirebaseUser user = firebaseAuth.getCurrentUser();
    mStorageRef = FirebaseStorage.getInstance().getReference();
    SharedPreferences sharedPreferences = getSharedPreferences("email", Context.MODE_PRIVATE);
    // 유저 uid받기
    userUid = sharedPreferences.getString("uid", user.getUid());
    // 유저 email(아이디)받기
    userEmail = sharedPreferences.getString("email", user.getEmail());
    username = usernameFromEmail(user.getEmail());
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference myRef = database.getReference();
    if (firebaseAuth.getCurrentUser() == null) {
        finish();
        startActivity(new Intent(this, LoginActivity.class));
    }
    // 이 activity가 켜졌을 때 권한설정 물어보기
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, android.Manifest.permission.READ_EXTERNAL_STORAGE)) {
        // Show an expanation to the user *asynchronously* -- don't block
        // this thread waiting for the user's response! After the user
        // sees the explanation, try again to request the permission.
        } else {
            // No explanation needed, we can request the permission.
            ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.READ_EXTERNAL_STORAGE }, 1);
        // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
        // app-defined int constant. The callback method gets the
        // result of the request.
        }
    }
    // butterknife: view binder , list adapter 할때도 간편한 코드 구현가능
    petImage = (ImageView) findViewById(R.id.petImage);
    btn_UploadPicture = (Button) findViewById(R.id.btn_UploadPicture);
    textViewUserEmail = (TextView) findViewById(R.id.textViewUserEmail);
    textViewUserEmail.setText(user.getEmail() + "님의 반려동물");
    buttonLogout = (Button) findViewById(R.id.buttonLogout);
    buttonLogout.setOnClickListener(this);
    petImage = (ImageView) findViewById(R.id.petImage);
    btn_UploadPicture = (Button) findViewById(R.id.btn_UploadPicture);
    petName = (EditText) findViewById(R.id.petName);
    petAge = (EditText) findViewById(R.id.petAge);
    radiogroup_gender = (RadioGroup) findViewById(R.id.radiogroup_gender);
    radioGender_male = (RadioButton) findViewById(R.id.radioGender_male);
    radioGender_female = (RadioButton) findViewById(R.id.radioGender_female);
    radiogroup_type = (RadioGroup) findViewById(R.id.radiogroup_type);
    radio_dog = (RadioButton) findViewById(R.id.radio_dog);
    radio_cat = (RadioButton) findViewById(R.id.radio_cat);
    radiogroup_size = (RadioGroup) findViewById(R.id.radiogroup_size);
    radioSize_small = (RadioButton) findViewById(R.id.radioSize_small);
    radioSize_middle = (RadioButton) findViewById(R.id.radioSize_middle);
    radioSize_large = (RadioButton) findViewById(R.id.radioSize_large);
    btn_profilefinish = (Button) findViewById(R.id.btn_profilefinish);
    btn_UploadPicture.setOnClickListener(this);
    btn_profilefinish.setOnClickListener(this);
    loadSavedPreferences();
    // 원래 사진받아오는 자리
    new DownloadImage().execute();
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) SharedPreferences(android.content.SharedPreferences) DatabaseReference(com.google.firebase.database.DatabaseReference) Intent(android.content.Intent) FirebaseUser(com.google.firebase.auth.FirebaseUser)

Example 19 with FirebaseDatabase

use of com.google.firebase.database.FirebaseDatabase in project priend by TakoJ.

the class disease_searchActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_disease_search);
    search = (EditText) findViewById(R.id.search);
    final ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1);
    listview = (ListView) findViewById(R.id.listview1);
    listview.setAdapter(adapter);
    for (int i = 1; i < 40; i++) {
        // 일단 질병 40개만 받음.
        final String num = Integer.toString(i);
        FirebaseDatabase database = FirebaseDatabase.getInstance();
        final DatabaseReference myRef = database.getReference().child("diseases").child(num);
        myRef.child("diease_name").addListenerForSingleValueEvent(new ValueEventListener() {

            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                if (dataSnapshot.exists()) {
                    String name = dataSnapshot.getValue().toString();
                    adapter.add(name);
                } else {
                    System.out.println("없음");
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
            }
        });
    }
    search.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            // text가 바뀔때 수행되는 함수
            String filterText = s.toString();
            if (filterText.length() > 0) {
                // 글자 입력시
                listview.setFilterText(filterText);
            } else {
                listview.clearTextFilter();
            }
        }
    });
    listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // listview의 item클릭시 detail로 넘어가기
            Intent intent = new Intent(getApplicationContext(), disease_detail.class);
            // intent객체에 데이터를 실어서 보내기
            String disease_name = ((TextView) view).getText().toString();
            intent.putExtra("name", disease_name);
            startActivity(intent);
        }
    });
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) DatabaseReference(com.google.firebase.database.DatabaseReference) Intent(android.content.Intent) DataSnapshot(com.google.firebase.database.DataSnapshot) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) DatabaseError(com.google.firebase.database.DatabaseError) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ValueEventListener(com.google.firebase.database.ValueEventListener) ArrayAdapter(android.widget.ArrayAdapter)

Example 20 with FirebaseDatabase

use of com.google.firebase.database.FirebaseDatabase in project OnlineCanteen by josephgunawan97.

the class AccountUtil method updateStoreInformationOnDatabase.

private static Task<Void> updateStoreInformationOnDatabase(Store store) {
    FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
    FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
    DatabaseReference reference = firebaseDatabase.getReference("store");
    return reference.child(firebaseUser.getUid()).setValue(store);
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) DatabaseReference(com.google.firebase.database.DatabaseReference) FirebaseUser(com.google.firebase.auth.FirebaseUser)

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