コード例 #1
0
  public void onSubmitClick(View v) {
    // Validate and Save the resource
    mProgressBar.setVisibility(View.VISIBLE);
    String errorMessage = validateResource();

    if (!Strings.isNullOrEmpty(errorMessage)) {
      showError(errorMessage);
      mProgressBar.setVisibility(View.GONE);
      return;
    }

    mSubmitButton.setEnabled(false);
    switch (mResourceType) {
      case Constants.ANNOUNCEMENT_RESOURCE:
        mResourceObject =
            Strings.isNullOrEmpty(mResourceObjectId)
                ? new Announcement()
                : ParseObject.createWithoutData(Announcement.class, mResourceObjectId);
        ((Announcement) mResourceObject).setAnnouncementText(mDescriptionText.getText().toString());
        ((Announcement) mResourceObject).setIsActive(mActiveStatus.isChecked());
        Announcement.saveAnnouncement((Announcement) mResourceObject, onResourceSave());
        break;

      case Constants.CATEGORY_RESOURCE:
        mResourceObject =
            Strings.isNullOrEmpty(mResourceObjectId)
                ? new Category()
                : ParseObject.createWithoutData(Category.class, mResourceObjectId);
        ((Category) mResourceObject).setCategoryName(mTitleText.getText().toString());
        ((Category) mResourceObject).setDescription(mDescriptionText.getText().toString());
        ((Category) mResourceObject).setCategoryColor(mColorHexText.getText().toString());
        ((Category) mResourceObject).setIsActive(mActiveStatus.isChecked());

        try {
          Category.saveCategory((Category) mResourceObject, onResourceSave());
        } catch (ParseException ex) {

        }

        break;

      case Constants.RECOGNITION_RESOURCE:
        mResourceObject =
            Strings.isNullOrEmpty(mResourceObjectId)
                ? new Recognition()
                : ParseObject.createWithoutData(Recognition.class, mResourceObjectId);
        ((Recognition) mResourceObject).setTitle(mTitleText.getText().toString());
        ((Recognition) mResourceObject).setDescription(mDescriptionText.getText().toString());
        ((Recognition) mResourceObject)
            .setPointsRequired(Integer.parseInt(mRecogReqPtsText.getText().toString()));
        ((Recognition) mResourceObject)
            .setMaxUnits(Integer.parseInt(mRecogMaxUnitsText.getText().toString()));
        ((Recognition) mResourceObject).setIsHoursBased(mRecognitionUnit.isChecked());
        ((Recognition) mResourceObject)
            .setRecognitionType(String.valueOf(mRecognitionTypeSpinner.getSelectedItem()));
        // TODO: Set logo
        ////// ((Recognition)mResourceObject).getLogo();
        ((Recognition) mResourceObject).setIsActive(mActiveStatus.isChecked());

        Recognition.saveRecognition((Recognition) mResourceObject, onResourceSave());
        break;

      case Constants.INTEREST_RESOURCE:
        mResourceObject =
            Strings.isNullOrEmpty(mResourceObjectId)
                ? new Interest()
                : ParseObject.createWithoutData(Interest.class, mResourceObjectId);
        ((Interest) mResourceObject).setInterestTitle(mTitleText.getText().toString());
        ((Interest) mResourceObject).setDescription(mDescriptionText.getText().toString());
        // TODO: Set logo
        ////// ((Interest)mResourceObject).getLogo();
        ((Interest) mResourceObject).setIsActive(mActiveStatus.isChecked());

        Interest.saveInterest((Interest) mResourceObject, onResourceSave());
        break;

      case Constants.SKILL_RESOURCE:
        mResourceObject =
            Strings.isNullOrEmpty(mResourceObjectId)
                ? new Skill()
                : ParseObject.createWithoutData(Skill.class, mResourceObjectId);
        ((Skill) mResourceObject).setSkillTitle(mTitleText.getText().toString());
        ((Skill) mResourceObject).setDescription(mDescriptionText.getText().toString());
        // TODO: Set logo
        // ((Skill)mResourceObject).setLogo();
        ((Skill) mResourceObject).setIsActive(mActiveStatus.isChecked());

        Skill.saveSkill((Skill) mResourceObject, onResourceSave());
        break;

      case Constants.USER_RESOURCE:
        mResourceObject =
            Strings.isNullOrEmpty(mResourceObjectId)
                ? new SpecialUser()
                : ParseObject.createWithoutData(SpecialUser.class, mResourceObjectId);
        ((SpecialUser) mResourceObject).setEmailId(mTitleText.getText().toString());
        ((SpecialUser) mResourceObject).setRole(String.valueOf(mUserRoleSpinner.getSelectedItem()));
        ((SpecialUser) mResourceObject)
            .setOrganizationName(String.valueOf(mUserOrgSpinner.getSelectedItem()));
        ((SpecialUser) mResourceObject).setIsActive(mActiveStatus.isChecked());
        SpecialUser.saveSpecialUser((SpecialUser) mResourceObject, onResourceSave());
        break;

      case Constants.SCHOOL_RESOURCE:
        mResourceObject =
            Strings.isNullOrEmpty(mResourceObjectId)
                ? new School()
                : ParseObject.createWithoutData(School.class, mResourceObjectId);
        ((School) mResourceObject).setSchoolName(mTitleText.getText().toString());
        ((School) mResourceObject).setDescription(mDescriptionText.getText().toString());
        // TODO: Set logo
        // ((School)mResourceObject).setLogo();
        ((School) mResourceObject).setIsActive(mActiveStatus.isChecked());
        School.saveSchool((School) mResourceObject, onResourceSave());
        break;

      case Constants.GROUP_RESOURCE:
        mResourceObject =
            Strings.isNullOrEmpty(mResourceObjectId)
                ? new InterestGroup()
                : ParseObject.createWithoutData(InterestGroup.class, mResourceObjectId);
        ((InterestGroup) mResourceObject).setGroupName(mTitleText.getText().toString());
        ((InterestGroup) mResourceObject)
            .setGroupDescription(mDescriptionText.getText().toString());
        // TODO: Set logo
        // ((InterestGroup)mResourceObject).setLogo();
        ((InterestGroup) mResourceObject).setIsActive(mActiveStatus.isChecked());
        InterestGroup.saveGroup((InterestGroup) mResourceObject, onResourceSave());
        // TODO: Add members
        break;

      case Constants.ORGANIZATION_RESOURCE:
        mResourceObject =
            Strings.isNullOrEmpty(mResourceObjectId)
                ? new Organization()
                : ParseObject.createWithoutData(Organization.class, mResourceObjectId);
        ((Organization) mResourceObject).setOrganizationName(mTitleText.getText().toString());
        ((Organization) mResourceObject).setDescription(mDescriptionText.getText().toString());
        // TODO: Set logo
        // ((Organization)mResourceObject).setLogo();
        ((Organization) mResourceObject).setIsActive(mActiveStatus.isChecked());

        Organization.saveOrganization((Organization) mResourceObject, onResourceSave());
        break;

      default:
        mResourceObject.saveInBackground(
            new SaveCallback() {
              @Override
              public void done(ParseException e) {
                Snackbar snackbar =
                    Snackbar.make(
                        mSaveResourceForm, R.string.msg_data_success, Snackbar.LENGTH_LONG);
                snackbar.show();
              }
            });
    }
    mProgressBar.setVisibility(View.GONE);
  }
コード例 #2
0
  private void loadPageContent() {

    if (!CheckNetworkConnection.isInternetAvailable(this)) {
      showToastLong(R.string.internet_connection_unavailable);

      VolunteerUser userFromDataStore = VolunteerUser.getCurrentUserInformationFromLocalStore();
      if (userFromDataStore == null) {
        Intent errorIntent = new Intent(this, ErrorMessageActivity.class);
        errorIntent.putExtra(
            Constants.ERROR_ITEM_KEY,
            getResources().getString(R.string.internet_connection_unavailable));
        startActivity(errorIntent);
        return;
      }
      // User available from local datastore
      if (!userFromDataStore.isEmailVerified()) {
        displayError(userFromDataStore.getEmail());

        return;
      }

      if (!userFromDataStore.isProfileComplete()) {
        Intent errorIntent = new Intent(this, ErrorMessageActivity.class);
        String errorMessage = getResources().getString(R.string.incomplete_profile_no_internet);
        errorIntent.putExtra(Constants.ERROR_ITEM_KEY, errorMessage);
        startActivity(errorIntent);

        return;
      }

      // Start Main Activity
      Intent mainIntent = new Intent(this, MainActivity.class);
      mainIntent.putExtra(Constants.INTENT_SENDER, "intro");
      mainIntent.putExtra(Constants.INTERNET_AVAILABLE, false);
      startActivity(mainIntent);
    }

    // currentUser
    final ParseUser currentParseUser = ParseUser.getCurrentUser();
    if (currentParseUser == null) {
      startActivity(DispatchActivity.class);
      return;
    }

    final VolunteerUser currentUser = VolunteerUser.getCurrentUserInformation(currentParseUser);
    currentUser.pinInBackground();

    if (!currentUser.isEmailVerified()) {
      displayError(currentUser.getEmail());

      return;
    }

    if (!currentUser.isProfileComplete()) {
      showToastLong(R.string.help_us_know_you);
      startActivity(ProfileActivitySimple.class);
    } else {

      try {
        UserCategoryPoints.unpinAll(Constants.CURRENT_USER_POINTS);
        Category.unpinAll(Constants.CATEGORY_RESOURCE);
      } catch (ParseException e) {
        e.printStackTrace();
      }

      Category.pinAllInBackground(Constants.CATEGORY_RESOURCE, Category.getAllCategories(true));

      mUserPoints = 0;
      mUserHours = 0;
      mUserRank = 5;

      mCurrentAnnouncements = Joiner.on("|").join(Announcement.getAllAnnouncementText());
      mTotalUsers = VolunteerUser.getTotalUserCount();
      mTotalUserHours =
          DateUtils.minutesToHoursRepresentation(
              CommonUtils.sum(UserCategoryPoints.findMinutesForAllUsers(), 0));

      try {
        List<VolunteerUser> rankedUsers = VolunteerUser.findUsersRanked();
        mUserRank = rankedUsers.indexOf(currentUser);
      } catch (ParseException e) {
        e.printStackTrace();
      }
      UserCategoryPoints.findCurrentUserPointsInBackground(
          currentParseUser,
          0,
          new FindCallback<UserCategoryPoints>() {
            @Override
            public void done(List<UserCategoryPoints> list, ParseException e) {
              if (e == null) {
                UserCategoryPoints.pinAllInBackground(Constants.CURRENT_USER_POINTS, list);
                for (UserCategoryPoints item : list) {
                  mUserPoints += item.getCategoryPoints();
                  mUserHours += item.getCategoryMinutes();
                }
              } else {
                e.getMessage();
              }

              startMainActivity();
            }
          });
    }
  }