Esempio n. 1
0
  @Override
  public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    ParseObject message = mMessages.get(position);
    String messageType = message.getString(ParseConstant.KEY_FILE_TYPE);
    ParseFile file = message.getParseFile(ParseConstant.KEY_FILE);
    Uri fileUri = Uri.parse(file.getUrl());

    if (messageType.equals(ParseConstant.TYPE_IMAGE)) {
      Intent intent = new Intent(getActivity(), ViewimageActivity.class);
      intent.setData(fileUri);
      startActivity(intent);
    } else {
      Intent intent = new Intent(Intent.ACTION_VIEW, fileUri);
      intent.setDataAndType(fileUri, "video/*");
      startActivity(intent);
    }

    // Delete it
    List<String> ids = message.getList(ParseConstant.KEY_RECIPIENT_IDS);
    if (ids.size() == 1) {
      // last recipients
      message.deleteInBackground();
    } else {
      ids.remove(ParseUser.getCurrentUser().getObjectId());
      ArrayList<String> idsToRemove = new ArrayList<String>();
      idsToRemove.add(ParseUser.getCurrentUser().getObjectId());

      message.removeAll(ParseConstant.KEY_RECIPIENT_IDS, idsToRemove);
      message.saveInBackground();
    }
  }
Esempio n. 2
0
  public void sendAlert(String stockSymbol, String targetPrice, String stockState) {
    Notification.Builder mBuilder =
        new Notification.Builder(this)
            .setSmallIcon(R.drawable.appicon)
            .setContentTitle("EZQuote - '" + stockSymbol + "'")
            .setContentText(stockState + " Target Price " + targetPrice + " reached. Hurry!");
    // Creates an explicit intent for an Activity in your app

    Intent resultIntent = new Intent(this, MarketSummaryActivity.class);

    // The stack builder object will contain an artificial back stack for
    // the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MarketSummaryActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(getRandomNumber(), mBuilder.build());

    // Delete the alarm after it goes off.
    for (ParseObject o : alertObjs) {
      if (stockSymbol.equalsIgnoreCase((o.getString("symbol")))
          && targetPrice.equals(o.getString("targetPrice"))
          && stockState.equals(o.getString("StockState"))) {

        o.deleteInBackground();
      }
    }
  }
Esempio n. 3
0
  @Override
  public void onClick(View v) {
    final ParseUser currentUser = ParseUser.getCurrentUser();

    switch (v.getId()) {
      case (R.id.reset_password_button):
        Utils.resetPassword(ProfileEditActivity.this, currentUser.getEmail());
        break;

      case (R.id.save_changes_button):

        // check that all the user availabilities are valid
        for (int i = 0; i < availabilityAdapter.getCount() - 1; i++) {
          if (!availabilityAdapter.getItem(i).isValid()) {
            Utils.showMessageBox(
                v.getContext(),
                "Invalid period",
                "At least one of the availability period are invalid");
            return;
          }
        }

        // handle name
        String name = nameEdit.getText().toString();
        if (!name.isEmpty()) {
          currentUser.put("name", name);
        }

        // handle address
        if (address != null) {
          currentUser.put("address", Utils.addressToJSONArray(address));
          currentUser.put(
              "addressLocation", new ParseGeoPoint(address.getLatitude(), address.getLongitude()));
        }

        // handle phone number
        String phone = phoneEdit.getText().toString();
        if (!phone.isEmpty()) {
          currentUser.put("phone", phone);
        }
        currentUser.put("sharePhone", phoneShareEdit.isChecked());

        final ProgressDialog pd =
            ProgressDialog.show(ProfileEditActivity.this, "", "Saving profile...", true, false);
        List<Task<Void>> tasks = new ArrayList<>();

        // handle profile picture (save before proceeding
        if (picByteArray != null) {
          Log.d("My Loggggg", "profile picture changed");
          final ParseFile photoFile =
              new ParseFile(currentUser.getUsername().toString() + "profile_pic.jpg", picByteArray);

          tasks.add(
              photoFile
                  .saveInBackground()
                  .onSuccess(
                      new Continuation<Void, Void>() {
                        @Override
                        public Void then(Task<Void> task) throws Exception {
                          currentUser.put("photo", photoFile);
                          return null;
                        }
                      }));
        }

        // save changes in user availability
        for (int i = 0; i < availabilityAdapter.getCount() - 1; i++) {
          Integer id = (Integer) availabilityAdapter.getItem(i).getTag();
          AvailabilityRecord record = availabilityAdapter.getItem(i);
          if (id != null) {
            // update if need old records
            ParseObject userAvailability = userAvailabilitiesList.get(id);
            userAvailabilitiesList.set(id, null);
            record.toParseObject(userAvailability);
            tasks.add(userAvailability.saveInBackground());
          } else {
            // else is a new record
            ParseObject newUserAvailability = record.toParseObject();
            newUserAvailability.put("user", currentUser);
            tasks.add(newUserAvailability.saveInBackground());
          }
        }
        // remove from parse all availabilities that user remove
        for (ParseObject availability : userAvailabilitiesList) {
          if (availability != null) {
            tasks.add(availability.deleteInBackground());
          }
        }

        Task.whenAll(tasks)
            .onSuccessTask(
                new Continuation<Void, Task<Void>>() {
                  @Override
                  public Task<Void> then(Task<Void> task) throws Exception {
                    return currentUser.saveInBackground();
                  }
                })
            .continueWith(
                new Continuation<Void, Void>() {
                  @Override
                  public Void then(Task<Void> task) throws Exception {
                    pd.dismiss();
                    if (!task.isFaulted()) {
                      Toast.makeText(
                              getApplicationContext(),
                              "Changes saved successfully",
                              Toast.LENGTH_LONG)
                          .show();
                      finish();
                    } else {
                      Log.e("ProfileEdit", "error saving changes: " + task.getError().getMessage());
                      Utils.showMessageBox(
                          ProfileEditActivity.this,
                          "Failed saving changes",
                          getString(R.string.unknown_error_occur));
                    }
                    return null;
                  }
                },
                Task.UI_THREAD_EXECUTOR);

        break;

      case (R.id.change_pic_button):
        // create Intent to take a picture and return control to the calling application
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(intent, CAMERA_REQUEST);

        break;

      case R.id.profile_address_change_edit:
        // move user to address selection activity
        Intent addressSelectionIntent =
            new Intent(ProfileEditActivity.this, AddressSelectionActivity.class);
        startActivityForResult(addressSelectionIntent, REQUEST_ADDRESS);

        break;
    }
  }