コード例 #1
0
  public void isUserCheckedIn() {
    Log.d(TAG, "isUserCheckedIn()");
    Query query = confRef.child("users").child(firebase.getAuth().getUid());
    query.addListenerForSingleValueEvent(
        new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
            String uid = dataSnapshot.getValue(String.class);
            Log.d(TAG, "UserID: " + uid);
            if (uid != null) {
              if (uid.equals(firebase.getAuth().getUid())) {
                Log.d(TAG, "User checked in.");
                giveFeedback();
                deactivateButton();
              } else {
                Log.d(TAG, "User not checked in.");
              }
            }
          }

          @Override
          public void onCancelled(FirebaseError firebaseError) {
            Log.d(
                TAG,
                "Firebase Error: " + firebaseError.getCode() + "\n" + firebaseError.getMessage());
          }
        });
  }
コード例 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    SystemClock.sleep(2000);

    // Check network connection
    if (!Commons.isNetworkAvailable(getApplicationContext())) {
      SystemClock.sleep(1500);
      Commons.showToastMessage("No internet connection", getApplicationContext());
      nextActivityAfterLogin(MainActivity.class);
      return;
    }

    // Check if there is already an authorisation for firebase which the user application have
    // logged in previously
    Firebase fbRef = new Firebase(Constants.FIREBASE_MAIN);
    SharedPreferences prefs;
    // if there is valid authorisation, redirect to next activity
    if (fbRef.getAuth() != null) {
      prefs = getSharedPreferences(Constants.SHARE_PREF_LINK, MODE_PRIVATE);
      String role = prefs.getString(Constants.SHAREPREF_ROLE, null);
      String phoneNo = prefs.getString(Constants.SHAREPREF_PHONE_NO, null);
      if (phoneNo == null || role == null) {
        fbRef.unauth();
        nextActivityAfterLogin(MainActivity.class);
      } else retrieveAccountInfo(phoneNo, role);
    } else {
      nextActivityAfterLogin(MainActivity.class);
    }
  }
コード例 #3
0
  private void addContact(String contact) {
    userAddContact = firebase.getAuth().getUid();
    contactAddContact = contact;
    userContacts = new ArrayList<>();

    firebase
        .child("users")
        .child(userAddContact)
        .addListenerForSingleValueEvent(
            new ValueEventListener() {
              @Override
              public void onDataChange(DataSnapshot dataSnapshot) {
                User user = dataSnapshot.getValue(User.class);
                if (user.getContacts() != null) userContacts = user.getContacts();
                if (!userContacts.contains(contactAddContact)) userContacts.add(contactAddContact);
                firebase
                    .child("users")
                    .child(userAddContact)
                    .child("contacts")
                    .setValue(userContacts);
              }

              @Override
              public void onCancelled(FirebaseError firebaseError) {}
            });

    Log.d(TAG, "Adding contact to user");

    contactContacts = new ArrayList<>();

    firebase
        .child("users")
        .child(contactAddContact)
        .addListenerForSingleValueEvent(
            new ValueEventListener() {
              @Override
              public void onDataChange(DataSnapshot dataSnapshot) {
                User contact = dataSnapshot.getValue(User.class);
                if (contact.getContacts() != null) contactContacts = contact.getContacts();
                if (!contactContacts.contains(userAddContact)) contactContacts.add(userAddContact);
                firebase
                    .child("users")
                    .child(contactAddContact)
                    .child("contacts")
                    .setValue(contactContacts);
              }

              @Override
              public void onCancelled(FirebaseError firebaseError) {}
            });
    Log.d(TAG, "Adding user to contact");
  }
コード例 #4
0
  /**
   * searches for recommended movies based on movie and rating
   *
   * @param searchMajorP major to search for
   * @param searchRatingP rating to search for
   */
  public void getRecommendations(String searchMajorP, int searchRatingP) {
    final String searchMajor = searchMajorP;
    final int searchRating = searchRatingP;
    mArrayAdapter.clear();
    AuthData authData = fb.getAuth();
    if (authData != null) {
      fb.addListenerForSingleValueEvent(
          new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
              for (DataSnapshot movies : snapshot.child("movies").getChildren()) {
                // private String movieID;
                movieAdded = false;
                movieName = movies.child("name").getValue().toString();
                // movieID = movies.getValue().toString();
                // Log.d("TAG",movieName);
                for (DataSnapshot ratings : movies.child("ratings").getChildren()) {
                  userID = ratings.getKey();
                  // Log.d("TAG",userID);
                  String s = ratings.child("rating").getValue().toString();
                  rating = Integer.parseInt(s);
                  Object m = snapshot.child("users").child(userID).child("Major").getValue();
                  if (m != null) {
                    major = m.toString();
                    if (rating >= searchRating
                        && major.equalsIgnoreCase(searchMajor)
                        && !movieAdded) {
                      // Log.d("TAG",movieName);
                      movieAdded = true;
                      mArrayAdapter.add(movieName);
                    }
                  }
                }
              }
            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {
              Log.d("TAG", firebaseError.getMessage());
            }
          });
    }
  }
コード例 #5
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int density = metrics.densityDpi;
    //		Log.i("flag", ((Integer) density).toString());
    DENSITY = density;
    mGlobalVariables = ((GlobalVariables) getApplicationContext());

    ActionBar actionBar = getActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(0x268bd2));

    Firebase ref = new Firebase(mGlobalVariables.getFirebaseUrl());

    AuthData authData = ref.getAuth();
    if (mGlobalVariables.getUser() != null) {
      // I've been rotated!!!!!
      resumeOnRotate();
    } else if (authData != null) {
      mGlobalVariables.setUser(
          new User(mGlobalVariables.getFirebaseUrl() + "users/" + authData.getUid()));
      createProjectList();
    } else if (this.getIntent().getStringExtra("user") != null) {
      // If logged in get the user's project list
      this.fragmentStack = new Stack<Fragment>();
      mGlobalVariables.setUser(new User(this.getIntent().getStringExtra("user")));
      createProjectList();
    } else {
      // Starts the LoginActivity if the user has not been logged in just
      // yet
      Intent intent = new Intent(this, LoginActivity.class);
      this.startActivity(intent);
      this.finish();
    }
    String s = mGlobalVariables.getFirebaseUrl() + "users/" + authData.getUid();
    Log.i("User Info", s);
  }
コード例 #6
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_conference_view);

    Intent intent = getIntent();
    firebase = new Firebase(FIREBASE_URL);
    userRef = new Firebase(FIREBASE_URL).child("users").child(firebase.getAuth().getUid());
    confRef = firebase.child("conferences").child(intent.getStringExtra("cid"));

    name = (TextView) findViewById(R.id.view_conference_name);
    description = (TextView) findViewById(R.id.view_conference_description);
    date = (TextView) findViewById(R.id.view_conference_date);
    time = (TextView) findViewById(R.id.view_conference_time);
    feedback = (TextView) findViewById(R.id.view_conference_feedback);
    checkInButton = (Button) findViewById(R.id.view_conference_button);

    currentapiVersion = android.os.Build.VERSION.SDK_INT;
    context = getBaseContext();
    requestingLocationUpdates = false;

    updateValuesFromBundle(savedInstanceState);
  }
コード例 #7
0
 private String getLoggedInUserId() {
   return commentsFirebaseRef.getAuth().getUid();
 }
コード例 #8
0
 private void checkAuthentication() {
   if (commentsFirebaseRef.getAuth() == null) {
     throw new FirebaseNotAuthenticatedException("Must be " + "authenticated with firebase");
   }
 }
コード例 #9
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_compose);
    this.setTitle("New Conversation");
    Firebase.setAndroidContext(this.getApplicationContext());
    final Firebase sFireRef = new Firebase("https://mi491app.firebaseio.com");
    final MultiAutoCompleteTextView contacts =
        (MultiAutoCompleteTextView) findViewById(R.id.compose_mactv);
    contacts.setAdapter(
        new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1));
    final HashMap<String, String> users = new HashMap<String, String>();

    sFireRef
        .child("users")
        .child(sFireRef.getAuth().getUid())
        .child("contacts")
        .addListenerForSingleValueEvent(
            new ValueEventListener() {
              @Override
              public void onDataChange(DataSnapshot dataSnapshot) {
                System.out.println(dataSnapshot.hasChildren());
                if (!dataSnapshot.hasChildren()) {
                  AlertDialog.Builder warning = new AlertDialog.Builder(ComposeActivity.this);
                  warning.setMessage("You have no contacts to message!").setTitle("Awww....");
                  warning.setPositiveButton(
                      "Sigh.",
                      new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                          finish();
                        }
                      });
                  warning.create();
                  warning.show();
                }

                final ArrayList<String> user_names = new ArrayList<String>();
                for (DataSnapshot contact : dataSnapshot.getChildren()) {

                  sFireRef
                      .child("users")
                      .child(contact.getKey())
                      .addListenerForSingleValueEvent(
                          new ValueEventListener() {
                            @Override
                            public void onDataChange(DataSnapshot dataSnapshot) {
                              User user = new User();
                              System.out.println(
                                  dataSnapshot.child("displayName").getValue().toString());

                              user.setDisplayName(
                                  dataSnapshot.child("displayName").getValue().toString());
                              user.setUsername(
                                  dataSnapshot.child("username").getValue().toString());
                              user.setPhoneNumber(
                                  dataSnapshot.child("phoneNumber").getValue().toString());
                              users.put(
                                  dataSnapshot.child("displayName").getValue().toString(),
                                  dataSnapshot.getKey());
                              user_names.add(
                                  dataSnapshot.child("displayName").getValue().toString());
                              ArrayAdapter AutoCompleteAdapter =
                                  new ArrayAdapter(
                                      getApplicationContext(),
                                      R.layout.content_add_friend,
                                      user_names.toArray());
                              System.out.println(user_names.toString());
                              contacts.setAdapter(AutoCompleteAdapter);
                              contacts.setThreshold(1);
                              contacts.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
                            }

                            @Override
                            public void onCancelled(FirebaseError firebaseError) {}
                          });
                }
              }

              @Override
              public void onCancelled(FirebaseError firebaseError) {
                AlertDialog.Builder warning = new AlertDialog.Builder(ComposeActivity.this);
                warning
                    .setMessage("We're having problems contacting the server")
                    .setTitle("Awww....");
                warning.setPositiveButton(
                    "Sigh.",
                    new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                        finish();
                      }
                    });
                warning.create();
                warning.show();
              }
            });

    final FloatingActionButton sendButton =
        (FloatingActionButton) findViewById(R.id.compose_send_btn);

    sendButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            String[] recipients = contacts.getText().toString().split(",");
            Map<String, Object> conversation = new HashMap<String, Object>();
            ArrayList<String> validated_recipients = new ArrayList<String>();
            for (int i = 0; i < recipients.length; i++) {
              if (users.containsKey(recipients[i].trim())) {
                validated_recipients.add(users.get(recipients[i]));
                System.out.println("validated: " + recipients[i]);
                conversation.put(users.get(recipients[i].trim()), true);
              }
            }
            conversation.put(sFireRef.getAuth().getUid(), true);
            conversation.put("cSummary", "Example");
            conversation.put("cTitle", contacts.getText().toString());
            System.out.println(conversation);

            Firebase cFireRef = sFireRef.child("conversations").push();
            cFireRef.updateChildren(conversation);
            finish();
          }
        });
  }
コード例 #10
0
 private void registerUserToConference() {
   HashMap<String, Object> attendingUser = new HashMap<>();
   attendingUser.put(firebase.getAuth().getUid(), firebase.getAuth().getUid());
   confRef.child("users").updateChildren(attendingUser);
 }
コード例 #11
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mes_trajets);

    Intent intent = getIntent();
    final String typeDem = intent.getStringExtra("type");

    final ListView listView = (ListView) findViewById(R.id.listView);
    final ArrayList<HashMap<String, String>> listTrajet = new ArrayList<>();

    final Firebase myFireBase = new Firebase("https://bettercallsam.firebaseio.com/");

    final AuthData authData = myFireBase.getAuth();
    if (authData != null) {
      final String idUtilisateur = authData.getUid();
      myFireBase.addValueEventListener(
          new ValueEventListener() {
            // S'il est connecté, on récupère ses informations
            @Override
            public void onDataChange(DataSnapshot snapshot) {

              HashMap<String, String> map;

              if (typeDem.equals("passager")) {
                List<String> listReservIdTrajet = new ArrayList<String>();
                for (DataSnapshot postSnapshot : snapshot.child("reservations").getChildren()) {
                  Reservation reserv = postSnapshot.getValue(Reservation.class);
                  if (idUtilisateur.equals(reserv.getPassager())) {
                    listReservIdTrajet.add(reserv.getTrajet());
                  }
                }

                for (DataSnapshot postSnapshot : snapshot.child("trips").getChildren()) {
                  Trajet trajet = postSnapshot.getValue(Trajet.class);

                  if (listReservIdTrajet.contains(postSnapshot.getKey())) {
                    compt++;
                    String villeArrivee = trajet.getVilleArrivee().toString();
                    String adDep = trajet.getAdresseDepart().toString();
                    String adArr = trajet.getAdresseArrivee().toString();
                    String villeDepart = trajet.getVilleDepart().toString();
                    String dateDep = trajet.getDateDepart().toString();
                    String heureDep = trajet.getHeureDepart().toString();
                    String placeDispo = Integer.toString(trajet.getNombrePlaceDisponibles());

                    map = new HashMap<String, String>();

                    map.put("departVille", "Ville de depart  : " + villeDepart);
                    map.put("departAdresse", "Adresse de départ : " + adDep);
                    map.put("arriveeVille", "Ville d'arrivée : " + villeArrivee);
                    map.put("arriveeAdresse", "Adresse d'arrivée : " + adArr);
                    map.put("date", "Départ le " + dateDep + " à " + heureDep);
                    map.put("nbPlaces", "Nombre de places disponibles : " + placeDispo);
                    map.put("idTrajet", postSnapshot.getKey());

                    listTrajet.add(map);
                  }
                }
              } else {
                for (DataSnapshot postSnapshot : snapshot.child("trips").getChildren()) {
                  Trajet trajet = postSnapshot.getValue(Trajet.class);

                  if (idUtilisateur.equals(trajet.getConducteur())) {
                    compt++;
                    String villeArrivee = trajet.getVilleArrivee().toString();
                    String adDep = trajet.getAdresseDepart().toString();
                    String adArr = trajet.getAdresseArrivee().toString();
                    String villeDepart = trajet.getVilleDepart().toString();
                    String dateDep = trajet.getDateDepart().toString();
                    String heureDep = trajet.getHeureDepart().toString();
                    String placeDispo = Integer.toString(trajet.getNombrePlaceDisponibles());

                    map = new HashMap<String, String>();

                    map.put("departVille", "Ville de depart  : " + villeDepart);
                    map.put("departAdresse", "Adresse de départ : " + adDep);
                    map.put("arriveeVille", "Ville d'arrivée : " + villeArrivee);
                    map.put("arriveeAdresse", "Adresse d'arrivée : " + adArr);
                    map.put("date", "Départ le " + dateDep + " à " + heureDep);
                    map.put("nbPlaces", "Nombre de places disponibles : " + placeDispo);
                    map.put("idTrajet", postSnapshot.getKey());

                    listTrajet.add(map);
                  }
                }
              }

              /* if (compt == 0) {
                  final String erreur = "Il n'y a pas de trajet";
                  listTrajet.add(erreur);

              }*/

              final SimpleAdapter mSchedule =
                  new SimpleAdapter(
                      getApplicationContext(),
                      listTrajet,
                      R.layout.activity_affichage_item,
                      new String[] {
                        "departVille",
                        "departAdresse",
                        "arriveeVille",
                        "arriveeAdresse",
                        "date",
                        "nbPlaces",
                        "idTrajet"
                      },
                      new int[] {
                        R.id.departVille,
                        R.id.departAdresse,
                        R.id.arriveeVille,
                        R.id.arriveeAdresse,
                        R.id.date,
                        R.id.nbPlaces,
                        R.id.idTrajet
                      });

              listView.setAdapter(mSchedule);

              listView.setOnItemClickListener(
                  new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(
                        AdapterView<?> parent, View view, int position, long id) {
                      HashMap<String, String> map =
                          (HashMap<String, String>) listView.getItemAtPosition(position);
                      final Intent intent =
                          new Intent(MesTrajets.this, AffichageDetailsTrajet.class);
                      intent.putExtra("trajet", map.get("idTrajet"));
                      intent.putExtra("nbPlacesReservees", 3);
                      startActivity(intent);
                    }
                  });
            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {}
          });
    } else

      // S'il n'est pas connecté, on le redirige sur l'activité principale
      startActivity(new Intent(this, MainActivity.class));
  }