Example #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_teacher_classes);

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle("Attendance");
    noti_bar = (Notification_bar) getSupportFragmentManager().findFragmentById(R.id.noti);
    noti_bar.setTexts(ParseUser.getCurrentUser().getUsername(), "Teacher");
    dbHandler = new MyDBHandler(getApplicationContext(), null, null, 1);
    classList = (ListView) findViewById(R.id.classesList);
    drawerFragment =
        (FragmentDrawer)
            getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
    drawerFragment.setUp(
        R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
    drawerFragment.setDrawerListener(this);

    //  myList = dbHandler.getAllTasks();

    // Log.i("Anmol", "(Inside MainActivity) dbHandler.getAllTasks().toString() gives " +
    // dbHandler.getAllTasks().toString());
    // ListAdapter adapter = new CustomListAdapter(getApplicationContext(),
    // dbHandler.getAllTasks());
    // taskList.setAdapter(adapter);
    ParseQuery<ParseObject> classQuery = ParseQuery.getQuery("Class");
    classQuery.whereEqualTo("teacher", ParseUser.getCurrentUser());
    classQuery.findInBackground(
        new FindCallback<ParseObject>() {
          public void done(List<ParseObject> classListRet, ParseException e) {
            if (e == null) {
              ArrayList<String> classLt = new ArrayList<String>();
              ArrayAdapter adapter =
                  new ArrayAdapter(
                      AddAttendance.this, android.R.layout.simple_list_item_1, classLt);

              Log.d("classes", "Retrieved " + classListRet.size() + " users");
              // Toast.makeText(getApplicationContext(), studentListRet.toString(),
              // Toast.LENGTH_LONG).show();
              for (int i = 0; i < classListRet.size(); i++) {
                ParseObject u = (ParseObject) classListRet.get(i);
                String name = u.getString("class").toString();
                // name += "\n";
                // name += u.getInt("age");

                adapter.add(name);
              }

              classList.setAdapter(adapter);
            } else {
              Log.d("user", "Error: " + e.getMessage());
            }
          }
        });

    /*ParseQuery<ParseObject> studentQuery = ParseQuery.getQuery("Student");
            studentQuery.whereEqualTo("addedBy", ParseUser.getCurrentUser());
            studentQuery.findInBackground(new FindCallback<ParseObject>() {
                public void done(List<ParseObject> studentListRet, ParseException e) {
                    if (e == null) {

                        ArrayList<String> studentLt = new ArrayList<String>();
                        ArrayAdapter adapter = new ArrayAdapter(Students.this, android.R.layout.simple_list_item_1, studentLt);


                        Log.d("user", "Retrieved " + studentListRet.size() + " users");
                        //Toast.makeText(getApplicationContext(), studentListRet.toString(), Toast.LENGTH_LONG).show();
                        for (int i = 0; i < studentListRet.size(); i++) {
                            ParseObject u = (ParseObject) studentListRet.get(i);
                            String name = u.getString("name").toString();
                            //name += "\n";
                            // name += u.getInt("age");

                            adapter.add(name);

                        }


                        studentList.setAdapter(adapter);

                    } else {
                        Log.d("user", "Error: " + e.getMessage());
                    }
                }
            });
    */

    classList.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            final String item = ((TextView) view).getText().toString();

            ParseQuery<ParseObject> studentQuery = ParseQuery.getQuery("Class");
            studentQuery.whereEqualTo("class", item);
            studentQuery.whereEqualTo("teacher", ParseUser.getCurrentUser());
            studentQuery.findInBackground(
                new FindCallback<ParseObject>() {
                  public void done(List<ParseObject> classObjRet, ParseException e) {
                    if (e == null) {
                      ParseObject u = (ParseObject) classObjRet.get(0);
                      String id = u.getObjectId();
                      Toast.makeText(
                              AddAttendance.this,
                              "id of class selected is = " + id,
                              Toast.LENGTH_LONG)
                          .show();
                      Intent to_student =
                          new Intent(AddAttendance.this, AddAttendance_Students.class);
                      to_student.putExtra("id", id);
                      startActivity(to_student);
                    } else {
                      Log.d("user", "Error: " + e.getMessage());
                    }
                  }
                });
          }
        });
  }
Example #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_new_task);

    /* mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setTitle("New Task");*/

    taskTitle = (EditText) findViewById(R.id.taskTitle);
    taskDescription = (EditText) findViewById(R.id.taskDescription);
    addTaskButton = (Button) findViewById(R.id.addTaskButton);

    DATE = (TextView) findViewById(R.id.dateText);
    test = (ImageButton) findViewById(R.id.test);

    Log.i("abcd", "tasktitle is......" + taskTitle);
    Bundle fromrole = getIntent().getExtras();
    role = fromrole.getString("role");
    noti_bar = (Notification_bar) getSupportFragmentManager().findFragmentById(R.id.noti);
    noti_bar.setTexts(ParseUser.getCurrentUser().getUsername(), role);
    final Date date2 = new Date(Year - 1900, Month, Day + 1);

    addTaskButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            myTitle = taskTitle.getText().toString().trim();
            myDesc = taskDescription.getText().toString();

            if (myTitle.equals("")
                || myDesc.equals("")
                || ((DATE.getText().equals("Select Due Date")))) {
              Toast.makeText(
                      getApplicationContext(), "Event details cannot be empty!", Toast.LENGTH_LONG)
                  .show();
            } else {
              ParseObject task = new ParseObject("Task");
              task.put("createdBy", ParseUser.getCurrentUser());
              task.put("addedByRole", role);
              task.put("TaskName", myTitle);
              task.put("TaskDescription", myDesc);
              // String id = task.getObjectId();
              String string_date =
                  String.valueOf(Day)
                      + "-"
                      + String.valueOf(Month + 1)
                      + "-"
                      + String.valueOf(Year);

              SimpleDateFormat f = new SimpleDateFormat("dd-MM-yyyy");
              Date d = null;
              try {
                d = f.parse(string_date);
              } catch (ParseException e) {
                e.printStackTrace();
              }
              long milliseconds = d.getTime();
              task.put("dueDate", milliseconds);
              task.saveInBackground();
              Toast.makeText(
                      getApplicationContext(),
                      "Event details successfully stored",
                      Toast.LENGTH_LONG)
                  .show();

              Intent to_tasks = new Intent(NewTask.this, Tasks.class);
              to_tasks.putExtra("role", role);
              startActivity(to_tasks);
              finish();

              /* ParseQuery<ParseObject> taskQuery = ParseQuery.getQuery("Task");
              taskQuery.whereEqualTo("TaskName", myTitle);
              taskQuery.whereEqualTo("createdBy", ParseUser.getCurrentUser());
              taskQuery.whereEqualTo("addedByRole", role);
              taskQuery.whereEqualTo("dueDate", milliseconds);
              taskQuery.findInBackground(new FindCallback<ParseObject>() {
                  public void done(List<ParseObject> taskListRet, com.parse.ParseException e) {
                      if (e == null) {
                          ParseObject u = (ParseObject) taskListRet.get(0);
                          String id = u.getObjectId();
                          Toast.makeText(NewTask.this, "id of task selected is = " + id, Toast.LENGTH_LONG).show();
                          Intent to_tasks = new Intent(NewTask.this, Tasks.class);
                          to_tasks.putExtra("id", id);
                          startActivity(to_tasks);
                          finish();
                      } else {
                          Log.d("user", "Error: " + e.getMessage());
                      }
                  }
              }); */

            }
          }
        });
  }