Android Open Source - GroupSmart-Android Group Info






From Project

Back to project page GroupSmart-Android.

License

The source code is released under:

Copyright (C) <2014> <Derek Argueta - Hunter Kehoe> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), ...

If you think the Android project GroupSmart-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.dargueta.groupsmart;
/* www. j a  v a  2  s . c  o m*/
import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.google.analytics.tracking.android.EasyTracker;

/**
 * 
 * @author Hunter Kehoe
 * 
 * Provides the Activity for the user to view information about a specific group.
 *
 */
public class GroupInfo extends Activity{
  
  TextView tvGroupName, tvClassName, tvClassNameLong, tvTeacherName, tvGroupDescription, tvLeaders, tvMeetingDay, tvMeetingTime, tvMeetingPlace, tvGroupNotes;
  Button btnJoinGroup;
  
  String getGroupInfoURL = "";
  String getLeaderNamesURL = "";
  String checkAlreadyMemberURL = "";
  String joinGroupURL = "";
  String unjoinGroupURL = "";
  String groupName, teacherName, className, classNameLong, groupDescription, daysLong, timesLong, placesLong, groupNotes, leadersLong, whiteList, memberList;
  int id, sameLocation, open, school, oneTime;
  
  Button btnHome, btnProfile, btnNewGroups, btnSettings;
  
  String leaders;
  int leaderNum, leaderCount;
  JSONArray groups = null;
  
  public void onCreate(Bundle savedInstanceState) {
    
    super.onCreate(savedInstanceState);
    setContentView(R.layout.group_info);
    
    btnProfile = (Button) findViewById(R.id.btnProfile);
    btnSettings = (Button) findViewById(R.id.btnSettings);
    btnHome = (Button) findViewById(R.id.btnHome);
    
    btnProfile.setOnClickListener(new OnClickListener() {
      
      public void onClick(View v) {
        
        Intent i = new Intent(getApplicationContext(), Profile.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        startActivity(i);
        finish();
        overridePendingTransition(0, 0);
      }
    });
    
    btnSettings.setOnClickListener(new OnClickListener() {
      
      public void onClick(View v) {
        
        Intent i = new Intent(getApplicationContext(), Settings.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        startActivity(i);
        finish();
        overridePendingTransition(0, 0);
      }
    });
    
    btnHome.setOnClickListener(new OnClickListener() {
      
      public void onClick(View v) {
        
        Intent i = new Intent(getApplicationContext(), Main.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        startActivity(i);
        finish();
        overridePendingTransition(0, 0);
      }
    });
    
    tvGroupName = (TextView) findViewById(R.id.tvGroupName);
    tvClassName = (TextView) findViewById(R.id.tvClassName);
    tvClassNameLong = (TextView) findViewById(R.id.tvClassNameLong);
    tvTeacherName = (TextView) findViewById(R.id.tvTeacherName);
    tvGroupDescription = (TextView) findViewById(R.id.tvGroupDescription);
    tvMeetingDay = (TextView) findViewById(R.id.tvMeetingDay);
    tvMeetingTime = (TextView) findViewById(R.id.tvMeetingTime);
    tvMeetingPlace = (TextView) findViewById(R.id.tvMeetingPlace);
    tvGroupNotes = (TextView) findViewById(R.id.tvGroupNotes);
    tvLeaders = (TextView) findViewById(R.id.tvGroupLeader);
    
    btnJoinGroup = (Button) findViewById(R.id.btnJoinGroup);
    
    btnJoinGroup.setOnClickListener(new OnClickListener() {
      
      public void onClick(View v) {
        
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        String userId = String.valueOf(prefs.getInt(Constants.ID_KEY, -1));
        joinGroupURL = Constants.BASE_URL + "mode=ujg&id=" + userId + "&gid=" + id;
        new JoinGroup().execute();
      }
    });
    
    String id = getIntent().getStringExtra("id");
    
    getGroupInfoURL = Constants.BASE_URL + "mode=ggifi&id=" + id;
    leaders = "";
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    String userId = String.valueOf(prefs.getInt(Constants.ID_KEY, -1));
    checkAlreadyMemberURL = Constants.BASE_URL + "mode=gugla&id=" + userId;
    
    new GetGroupInfo().execute();
    new CheckAlreadyMember().execute();
  }
  
  /**
   * 
   * @author Hunter Kehoe
   * 
   * Asynchronously get the information for the current group from the remote database.
   *
   */
  private class GetGroupInfo extends AsyncTask<Void, Void, Void> {  
    
    boolean successful = false;
    ProgressDialog pDialog;
    
    protected void onPreExecute() {
      
      super.onPreExecute();
      pDialog = new ProgressDialog(GroupInfo.this);
      pDialog.setMessage(getString(R.string.pleaseWait));
      pDialog.setCancelable(false);
      pDialog.show();
    }
    
    protected Void doInBackground(Void... arg0) {
      
      ServiceHandler sh = new ServiceHandler();
      String jsonStr = sh.makeServiceCall(getGroupInfoURL, ServiceHandler.GET);
      
      if (!jsonStr.equals("Failed Execution")) {
        
        successful = true;
        
        try {
          
          JSONObject jsonObj = new JSONObject(jsonStr);
          groups = jsonObj.getJSONArray(Constants.GROUPS_KEY);
          
          for(int i = 0; i < groups.length(); i++) {
            
            JSONObject u = groups.getJSONObject(i);
            id = u.getInt(Constants.ID_KEY);
            groupName = u.getString(Constants.NAME_KEY);
            className = u.getString(Constants.CLASS_KEY);
            teacherName = u.getString(Constants.TEACHER_KEY);
            daysLong = u.getString(Constants.DAY_KEY);
            timesLong = u.getString(Constants.TIME_KEY);
            placesLong = u.getString(Constants.LOCATION_KEY);
            sameLocation = u.getInt(Constants.SAME_LOCATION_KEY);
            leadersLong = u.getString(Constants.LEADER_KEY);
            open = u.getInt(Constants.OPEN_KEY);
            whiteList = u.getString(Constants.WHITE_LIST_KEY);
            groupNotes = u.getString(Constants.NOTES_KEY);
            groupDescription = u.getString(Constants.DESCRIPTION_KEY);
            school = u.getInt(Constants.SCHOOL_KEY);
            memberList = u.getString(Constants.MEMBER_LIST_KEY);
            oneTime = u.getInt(Constants.ONE_TIME_KEY);
          }
          
        } catch (JSONException e) {
          
          e.printStackTrace();
        }
        
      }
          
      return null;
    }
    
    protected void onPostExecute(Void result) {
      
      super.onPostExecute(result);
      
      if(pDialog.isShowing()) {
        
        pDialog.dismiss();
      }
      
      if (successful) {
        
        groupName = groupName.replaceAll("\\\\", "");
        className = className.replaceAll("\\\\", "");
        teacherName = teacherName.replaceAll("\\\\", "");
        groupDescription = groupDescription.replaceAll("\\\\", "");
        groupNotes = groupNotes.replaceAll("\\\\", "");
        
        if (className.contains(":")) {
          
          classNameLong = className.substring(className.indexOf(":") + 1).trim();
          className = className.substring(0, className.indexOf(":") - 1);
          
        } else {
          
          classNameLong = "";
        }
        
        tvGroupName.setText(groupName);
        tvClassName.setText(className);
        tvClassNameLong.setText(classNameLong);
        tvTeacherName.setText(teacherName);
        tvGroupDescription.setText(groupDescription);
        tvGroupNotes.setText(groupNotes);
        
        String[] days = daysLong.split("\\|");
        String[] times = timesLong.split(";");
        String[] places = placesLong.split(";");
        
        String tvDay = "";
        String tvTime = "";
        String tvPlace = "";
        
        for (int i = 0; i < days.length; i++) {
          
          tvDay += days[i].replaceAll(";", " ") + '\n';
          tvTime += times[i] + '\n';
          tvPlace += places[i] + '\n';
        }
        
        tvMeetingDay.setText(tvDay);
        tvMeetingTime.setText(tvTime);
        tvMeetingPlace.setText(tvPlace);
        
        String[] temp = leadersLong.split(";");
        ArrayList<String> leaderArray = new ArrayList<String>();
        
        for(int i = 0; i < temp.length; i++) {
          
          if (temp[i].length() > 0) {
            leaderArray.add(temp[i]);
          }
        }
        
        leaderNum = leaderArray.size();
        
        for(int i = 0; i < leaderNum; i++) {
          
          getLeaderNamesURL = Constants.BASE_URL + "mode=gufi&id=" + leaderArray.get(i);
          leaderCount++;
          new GetLeaderNames().execute();
        }
        
      } else {
        
        Toast.makeText(getApplicationContext(),
                 R.string.somethingWrong,
                 Toast.LENGTH_SHORT).show();
        finish();
      }
    }
  }

  /**
   * 
   * @author Hunter Kehoe
   * 
   * Asynchronously get the names of the group leaders from the remote database.
   *
   */
  private class GetLeaderNames extends AsyncTask<Void, Void, Void> {  
    
    boolean successful = false;
    String leaderName = "";
    
    ProgressDialog pDialog;
    
    protected void onPreExecute() {
      
      super.onPreExecute();
      pDialog = new ProgressDialog(GroupInfo.this);
      pDialog.setMessage(getString(R.string.pleaseWait));
      pDialog.setCancelable(false);
      pDialog.show();
    }
    
    protected Void doInBackground(Void... arg0) {
      
      ServiceHandler sh = new ServiceHandler();
      String jsonStr = sh.makeServiceCall(getLeaderNamesURL, ServiceHandler.GET);
      
      if (jsonStr.indexOf("failed: ") == -1) {
        
        successful = true;
        leaderName = jsonStr;
      }
          
      return null;
    }
    
    protected void onPostExecute(Void result) {
      
      super.onPostExecute(result);
      
      if(pDialog.isShowing()) {
        pDialog.dismiss();
      }
      
      if (successful) {
        
        if (leaderCount == leaderNum) {
          
          leaders += leaderName;
          tvLeaders.setText(leaders);
          
        } else {
          
          leaders += leaderName + ", ";
        }
        
      } else {
        
        Toast.makeText(getApplicationContext(),
                 "Missing Leader names",
                 Toast.LENGTH_SHORT).show();
      }
    }
  }
  
  /**
   * 
   * @author Hunter Kehoe
   * 
   * Asynchronously update the group on the remote server to include this user.
   *
   */
  private class JoinGroup extends AsyncTask<Void, Void, Void> {
    
    boolean success = false;
    
    ProgressDialog pDialog;
    
    protected void onPreExecute() {
      
      super.onPreExecute();
      pDialog = new ProgressDialog(GroupInfo.this);
      pDialog.setMessage(getString(R.string.pleaseWait));
      pDialog.setCancelable(false);
      pDialog.show();
    }
    
    protected Void doInBackground(Void... arg0) {
      
      ServiceHandler sh = new ServiceHandler();
      String jsonStr = sh.makeServiceCall(joinGroupURL, ServiceHandler.GET);
      
      if (jsonStr.contains("Successfully")) {
        
        success = true;
      }
          
      return null;
    }
    
    protected void onPostExecute(Void result) {
      
      super.onPostExecute(result);
      
      if(pDialog.isShowing()) {
        
        pDialog.dismiss();
      }
      
      if (success) {
        
        Toast.makeText(getApplicationContext(),
                 R.string.joinedGroup,
                 Toast.LENGTH_SHORT).show();
        Intent i = new Intent(getApplicationContext(), Profile.class);
        startActivity(i);
        finish();
        
      } else {
        
        Toast.makeText(getApplicationContext(),
                 R.string.notJoinGroup,
                 Toast.LENGTH_SHORT).show();
      }
    }
  }

  public void onBackPressed() {
    
    super.onBackPressed();
    this.overridePendingTransition(0, 0);
  }
  
  /**
   * 
   * @author Hunter Kehoe
   * 
   * Makes an asynchronous call to the server to check if this user is already a member of the 
   * group.
   *
   */
  private class CheckAlreadyMember extends AsyncTask<Void, Void, Void> {  
    
    boolean successful = false;
    String ids = "";
    
    ProgressDialog pDialog;
    
    protected void onPreExecute() {
      
      super.onPreExecute();
      pDialog = new ProgressDialog(GroupInfo.this);
      pDialog.setMessage(getString(R.string.pleaseWait));
      pDialog.setCancelable(false);
      pDialog.show();
    }
    
    protected Void doInBackground(Void... arg0) {
      
      ServiceHandler sh = new ServiceHandler();
      String jsonStr = sh.makeServiceCall(checkAlreadyMemberURL, ServiceHandler.GET);
      
      if (jsonStr.contains("no groups")) {
        
        return null;
        
      } else if (jsonStr.indexOf("failed: ") == -1 && !jsonStr.contains("something strange")) {  
        
        successful = true;
        
        try {
          
          JSONObject jsonObj = new JSONObject(jsonStr);
          groups = jsonObj.getJSONArray("groups");
          
          for(int i = 0; i < groups.length(); i++) {
            
            JSONObject u = groups.getJSONObject(i);
            ids += ";" + String.valueOf(u.getInt(Constants.ID_KEY)) + ";";
          }
          
        } catch (JSONException e) {
          
          e.printStackTrace();
        }
      }
          
      return null;
    }
    
    protected void onPostExecute(Void result) {
      
      super.onPostExecute(result);
      
      if(pDialog.isShowing()) {
        
        pDialog.dismiss();
      }
      
      if (successful) {
        
        if (ids.indexOf(";"+id+";") != -1) {
          
          btnJoinGroup.setText("UNJOIN GROUP");
          
          btnJoinGroup.setOnClickListener(new OnClickListener() {
            
            public void onClick(View v) {
              
              SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
              String userId = String.valueOf(prefs.getInt("id", -1));
              unjoinGroupURL = Constants.BASE_URL + "mode=uujg&id=" + userId + "&gid="+id;
              new UnjoinGroup().execute();
            }
          });
        }
      }
    }
  }

  /**
   * 
   * @author Hunter Kehoe
   * 
   * Makes an asynchronous call to the server to update the group to uninclude this user.
   *
   */
  private class UnjoinGroup extends AsyncTask<Void, Void, Void> {  
    
    boolean successful = false;
    
    ProgressDialog pDialog;
    
    protected void onPreExecute() {
      
      super.onPreExecute();
      pDialog = new ProgressDialog(GroupInfo.this);
      pDialog.setMessage(getString(R.string.pleaseWait));
      pDialog.setCancelable(false);
      pDialog.show();
    }
    
    protected Void doInBackground(Void... arg0) {
      
      ServiceHandler sh = new ServiceHandler();
      String jsonStr = sh.makeServiceCall(unjoinGroupURL, ServiceHandler.GET);
      
      if (jsonStr.contains("Successfully")) {
        
        successful = true;
      }
          
      return null;
    }
    
    protected void onPostExecute(Void result) {
      
      super.onPostExecute(result);
      
      if(pDialog.isShowing()) {
        
        pDialog.dismiss();
      }
      
      if (successful) {
        
        Toast.makeText(getApplicationContext(),
                 R.string.unjoinedGroup,
                 Toast.LENGTH_SHORT).show();
        finish();
        
      } else {
        
        Toast.makeText(getApplicationContext(),
                 R.string.somethingWrong,
                 Toast.LENGTH_SHORT).show();
      }
    }
  }
  
  // Google Analytics
  public void onStart() {
    
    super.onStart();
    EasyTracker.getInstance(this).activityStart(this);
  }
  
  public void onStop() {
    
    super.onStop();
    EasyTracker.getInstance(this).activityStop(this);
  }
}




Java Source Code List

com.dargueta.groupsmart.ChangePassword.java
com.dargueta.groupsmart.Constants.java
com.dargueta.groupsmart.CourseSelect.java
com.dargueta.groupsmart.CreateGroup.java
com.dargueta.groupsmart.Feedback.java
com.dargueta.groupsmart.FindGroup.java
com.dargueta.groupsmart.GroupInfo.java
com.dargueta.groupsmart.Login.java
com.dargueta.groupsmart.Main.java
com.dargueta.groupsmart.MajorSelect.java
com.dargueta.groupsmart.Profile.java
com.dargueta.groupsmart.Register.java
com.dargueta.groupsmart.ServiceHandler.java
com.dargueta.groupsmart.Settings.java
com.dargueta.groupsmart.UpdateGroup.java
com.dargueta.groupsmart.UpdateProfile.java