コード例 #1
0
  private boolean saveUrl() {
    if (UserHelper.userStillLoggedIn(userCreds.getExpireDate())) {
      try {
        Firebase ref =
            new Firebase(
                "https://yeah-url-extension.firebaseio.com/"
                    + userCreds.getUserId()
                    + "/urlcollector");
        Firebase urlRef = ref.push();

        List<UrlItem> urlItemList = new ArrayList<>(1);
        UrlItem urlItem = new UrlItem();
        urlItem.setId(1);
        urlItem.setTimestamp(String.valueOf(Math.round(new Date().getTime() / 1000.0)));
        urlItem.setTime(
            new SimpleDateFormat("HH:mm:ss", Locale.GERMANY).format(System.currentTimeMillis()));
        urlItem.setDate(
            new SimpleDateFormat("dd.MM.yyyy", Locale.GERMANY).format(System.currentTimeMillis()));
        urlItem.setKeywords(etKeywordsUrl.getText().toString());
        urlItem.setValue(tvUrl.getText().toString());
        urlItem.setObjId(urlRef.getKey());
        urlItemList.add(urlItem);

        urlRef.setValue(
            urlItemList,
            new Firebase.CompletionListener() {
              @Override
              public void onComplete(FirebaseError firebaseError, Firebase firebase) {
                if (firebaseError != null) {
                  Utilities.buildToast(
                      AddUrlActivity.this,
                      "Url saving failed: " + firebaseError.getMessage(),
                      Toast.LENGTH_LONG);
                } else {
                  Utilities.buildToast(
                      AddUrlActivity.this, "Url saved successfully!", Toast.LENGTH_LONG);
                }
              }
            });
      } catch (Exception e) {
        Utilities.buildToast(this, "Add Url failed! Error: " + e.getMessage(), Toast.LENGTH_LONG);
        return false;
      }
    } else {
      Utilities.buildToast(this, "User is not logged in!", Toast.LENGTH_LONG);
      startActivity(new Intent(AddUrlActivity.this, MainActivity.class));
    }
    return true;
  }
コード例 #2
0
  private boolean updateUrl() {
    if (UserHelper.userStillLoggedIn(userCreds.getExpireDate())) {
      try {
        Firebase ref =
            new Firebase(
                "https://yeah-url-extension.firebaseio.com/"
                    + userCreds.getUserId()
                    + "/urlcollector/"
                    + objId
                    + "/"
                    + id);

        Map<String, Object> updateNote = new HashMap<>(2);
        updateNote.put("keywords", etKeywordsUrl.getText().toString());
        updateNote.put("value", tvUrl.getText().toString());

        ref.updateChildren(
            updateNote,
            new Firebase.CompletionListener() {
              @Override
              public void onComplete(FirebaseError firebaseError, Firebase firebase) {
                if (firebaseError != null) {
                  Utilities.buildToast(
                      AddUrlActivity.this,
                      "Url updating failed: " + firebaseError.getMessage(),
                      Toast.LENGTH_LONG);
                } else {
                  Utilities.buildToast(
                      AddUrlActivity.this, "Url updated successfully!", Toast.LENGTH_LONG);
                }
              }
            });
      } catch (Exception e) {
        Utilities.buildToast(
            this, "Update Url failed! Error: " + e.getMessage(), Toast.LENGTH_LONG);
        return false;
      }

    } else {
      Utilities.buildToast(this, "User is not logged in!", Toast.LENGTH_LONG);
      startActivity(new Intent(AddUrlActivity.this, MainActivity.class));
    }
    return true;
  }
コード例 #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_url);

    this.setFinishOnTouchOutside(false);

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    userCreds = SharedPreferencesHelper.getUserCredsFromPreferences(preferences);
    intent = getIntent();

    if (UserHelper.userStillLoggedIn(userCreds.getExpireDate())) {
      initComponents();
      initButtonListener();
      getSharingData();
    } else {
      Utilities.buildToast(this, "User is not logged in!", Toast.LENGTH_LONG);
      startActivity(new Intent(AddUrlActivity.this, MainActivity.class));
      finish();
    }
  }