Esempio n. 1
0
  @SuppressWarnings("StatementWithEmptyBody")
  @Override
  public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    Intent intent = new Intent();
    int id = item.getItemId();

    if (id == R.id.nav_activation) {
      intent = new Intent(ContactsActivity.this, ActivationActivity.class);
    } else if (id == R.id.nav_profile) {
      intent = new Intent(ContactsActivity.this, ProfileActivity.class);
      intent.putExtra(
          "username",
          SharedPreferencesHelper.getStringProperty(getApplicationContext(), "username"));
    } else if (id == R.id.nav_contacts) {
      intent = new Intent(ContactsActivity.this, ContactsActivity.class);
    } else if (id == R.id.nav_settings) {
      intent = new Intent(ContactsActivity.this, SettingsActivity.class);
    } else if (id == R.id.nav_logout) {
      SharedPreferencesHelper.removeKey(getApplicationContext(), "username");
      SharedPreferencesHelper.removeKey(getApplicationContext(), "loggedIn");
      intent = new Intent(ContactsActivity.this, LoginActivity.class);
      TaskStackBuilder.create(getApplicationContext())
          .addNextIntentWithParentStack(intent)
          .startActivities();
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    startActivity(intent);
    return true;
  }
Esempio n. 2
0
    protected Integer doInBackground(Integer... params) {

      Integer responseCode = 0;
      try {
        MultivaluedMap map = new MultivaluedMapImpl();
        map.add(
            "username",
            SharedPreferencesHelper.getStringProperty(getApplicationContext(), "username"));
        map.add("contactId", params[0].toString());

        RestClient tc = new RestClient(map);
        responseCode = tc.postForResponseCode("user/delete/contact");
      } catch (Exception e) {
        e.printStackTrace();
      }
      return responseCode;
    }
Esempio n. 3
0
  private void load() {
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    View headerLayout = navigationView.getHeaderView(0);
    TextView tv = (TextView) headerLayout.findViewById(R.id.nav_header_username);
    tv.setText(SharedPreferencesHelper.getStringProperty(getApplicationContext(), "username"));

    if (!BaseHelper.isServiceRunning(RetreiveNotificationsService.class, this)) {
      Intent myIntent = new Intent(this, RetreiveNotificationsService.class);
      this.startService(myIntent);
    }

    if (ValidationHelper.isInternetConnected(getApplicationContext())) {
      LinearLayout l = (LinearLayout) findViewById(R.id.contacts_container);
      if (retryButton != null) {
        l.removeView(findViewById(R.id.contactRetry));
      }
      progress = ProgressDialog.show(ContactsActivity.this, "", "Retrieving contacts...", true);
      progress.show();

      PendingRequestsTask pendingRequestsTask = new PendingRequestsTask();
      pendingRequestsTask.execute(
          SharedPreferencesHelper.getStringProperty(getApplicationContext(), "username"));

      ContactsTask contactsTask = new ContactsTask();
      contactsTask.execute(
          SharedPreferencesHelper.getStringProperty(getApplicationContext(), "username"));
    } else {
      LinearLayout l = (LinearLayout) findViewById(R.id.contacts_container);
      if (retryButton != null) {
        l.addView(retryButton);
      } else {
        toast = Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT);
        toast.setText("Could not retrieve contacts. No internet connection.");
        toast.show();

        retryButton = new Button(getApplicationContext());
        int size =
            (int)
                TypedValue.applyDimension(
                    TypedValue.COMPLEX_UNIT_DIP, 30, getResources().getDisplayMetrics());
        LinearLayout.LayoutParams params =
            new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        params.gravity = Gravity.CENTER_HORIZONTAL;
        retryButton.setLayoutParams(params);
        retryButton.setId(R.id.contactRetry);
        retryButton.setText("Retry");
        retryButton.setBackgroundColor(Color.RED);
        retryButton.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                if (ValidationHelper.isInternetConnected(getApplicationContext())) {
                  LinearLayout l = (LinearLayout) findViewById(R.id.contacts_container);
                  l.removeView(findViewById(R.id.contactRetry));
                  progress =
                      ProgressDialog.show(
                          ContactsActivity.this, "", "Retrieving contacts...", true);
                  progress.show();
                  ContactsTask contactsTask = new ContactsTask();
                  contactsTask.execute(
                      SharedPreferencesHelper.getStringProperty(
                          getApplicationContext(), "username"));
                } else {
                  toast = Toast.makeText(getApplicationContext(), "", Toast.LENGTH_SHORT);
                  toast.setText("Could not retrieve contacts. No internet connection.");
                  toast.show();
                }
              }
            });
        l.addView(retryButton);
      }
    }
    LocationUpdateReceiver.SetAlarm(getApplicationContext(), BaseHelper.INTERVAL_ONE_HOUR);
  }