Search in sources :

Example 1 with Student

use of app.abhijit.iter.models.Student in project bunk by abhijitparida.

the class ResponseParserTest method parse_EmptyAttendanceJson_ReturnsStudentWithEmptySubjectList.

@Test
public void parse_EmptyAttendanceJson_ReturnsStudentWithEmptySubjectList() {
    ResponseParser responseParser = new ResponseParser();
    Student student = responseParser.parse("{\"name\":\"name\",\"status\":\"success\"}", "");
    assertEquals(0, student.subjects.size());
}
Also used : Student(app.abhijit.iter.models.Student) Test(org.junit.Test)

Example 2 with Student

use of app.abhijit.iter.models.Student in project bunk by abhijitparida.

the class ResponseParserTest method parse_InvalidAttendanceJson_ReturnsStudentWithEmptySubjectList.

@Test
public void parse_InvalidAttendanceJson_ReturnsStudentWithEmptySubjectList() {
    ResponseParser responseParser = new ResponseParser();
    Student student = responseParser.parse("{\"name\":\"name\",\"status\":\"success\"}", "bad json");
    assertEquals(0, student.subjects.size());
}
Also used : Student(app.abhijit.iter.models.Student) Test(org.junit.Test)

Example 3 with Student

use of app.abhijit.iter.models.Student in project bunk by abhijitparida.

the class ResponseParserTest method parse_ValidAttendanceJson_ParsesCorrectly.

@Test
public void parse_ValidAttendanceJson_ParsesCorrectly() {
    ResponseParser responseParser = new ResponseParser();
    Student student = responseParser.parse("{\"name\":\"name\",\"status\":\"success\"}", "{\"griddata\":[{\"Latt\":\"10 / 10\",\"Patt\":\"Not Applicable\",\"subject\":\"Subject I\",\"subjectcode\":\"SUB001\"},{\"Latt\":\"Not Applicable\",\"Patt\":\"20 / 20\",\"subject\":\"Subject II\",\"subjectcode\":\"SUB002\"}]}");
    HashMap<String, Subject> subjects = student.subjects;
    assertEquals(2, subjects.size());
    assertEquals("Subject I", subjects.get("SUB001").name);
    assertEquals("SUB001", subjects.get("SUB001").code);
    assertEquals(10, subjects.get("SUB001").theoryPresent);
    assertEquals(10, subjects.get("SUB001").theoryTotal);
    assertEquals(0, subjects.get("SUB001").labPresent);
    assertEquals(0, subjects.get("SUB001").labTotal);
    assertEquals("Subject II", subjects.get("SUB002").name);
    assertEquals("SUB002", subjects.get("SUB002").code);
    assertEquals(0, subjects.get("SUB002").theoryPresent);
    assertEquals(0, subjects.get("SUB002").theoryTotal);
    assertEquals(20, subjects.get("SUB002").labPresent);
    assertEquals(20, subjects.get("SUB002").labTotal);
}
Also used : Student(app.abhijit.iter.models.Student) Subject(app.abhijit.iter.models.Subject) Test(org.junit.Test)

Example 4 with Student

use of app.abhijit.iter.models.Student in project bunk by abhijitparida.

the class LoginActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    mContext = this;
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
    mCache = new Cache(mContext);
    mIterApi = new IterApi(mContext);
    mUsernameInput = findViewById(R.id.username);
    mPasswordInput = findViewById(R.id.password);
    mPasswordVisilibity = findViewById(R.id.password_visibility);
    mLoginButton = findViewById(R.id.login);
    setupToolbar();
    setupLoginButton();
    final ArrayList<Student> students = mCache.getStudents();
    final ArrayList<String> usernames = new ArrayList<>();
    for (Student student : students) {
        usernames.add(student.username);
    }
    ArrayAdapter<String> adapter = new ArrayAdapter<>(mContext, android.R.layout.simple_dropdown_item_1line, usernames);
    mUsernameInput.setAdapter(adapter);
    mUsernameInput.setThreshold(1);
    mUsernameInput.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            int index = usernames.indexOf(mUsernameInput.getText().toString());
            mPasswordInput.setText(students.get(index).password);
        }
    });
    Student selectedStudent = mCache.getStudent(mSharedPreferences.getString("pref_student", null));
    if (selectedStudent != null) {
        mUsernameInput.setText(selectedStudent.username);
        mPasswordInput.setText(selectedStudent.password);
        mLoginButton.performClick();
    }
}
Also used : ArrayList(java.util.ArrayList) Student(app.abhijit.iter.models.Student) View(android.view.View) AdapterView(android.widget.AdapterView) AutoCompleteTextView(android.widget.AutoCompleteTextView) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter) Cache(app.abhijit.iter.data.Cache) IterApi(app.abhijit.iter.data.IterApi)

Example 5 with Student

use of app.abhijit.iter.models.Student in project bunk by abhijitparida.

the class ResponseParser method processLogin.

private Student processLogin(String loginJson) {
    JsonObject login;
    try {
        login = this.jsonParser.parse(loginJson).getAsJsonObject();
    } catch (Exception e) {
        throw new InvalidResponseException();
    }
    if (!login.has("status") || !login.has("name")) {
        throw new InvalidResponseException();
    }
    if (!login.get("status").getAsString().equals("success")) {
        throw new InvalidCredentialsException();
    }
    Student student = new Student();
    student.name = WordUtils.capitalizeFully(login.get("name").getAsString());
    return student;
}
Also used : InvalidCredentialsException(app.abhijit.iter.exceptions.InvalidCredentialsException) JsonObject(com.google.gson.JsonObject) Student(app.abhijit.iter.models.Student) InvalidResponseException(app.abhijit.iter.exceptions.InvalidResponseException) InvalidResponseException(app.abhijit.iter.exceptions.InvalidResponseException) InvalidCredentialsException(app.abhijit.iter.exceptions.InvalidCredentialsException)

Aggregations

Student (app.abhijit.iter.models.Student)8 Test (org.junit.Test)4 Intent (android.content.Intent)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 AutoCompleteTextView (android.widget.AutoCompleteTextView)2 Cache (app.abhijit.iter.data.Cache)2 InvalidCredentialsException (app.abhijit.iter.exceptions.InvalidCredentialsException)2 InvalidResponseException (app.abhijit.iter.exceptions.InvalidResponseException)2 Gson (com.google.gson.Gson)2 AnimationDrawable (android.graphics.drawable.AnimationDrawable)1 Handler (android.os.Handler)1 NonNull (android.support.annotation.NonNull)1 ArrayAdapter (android.widget.ArrayAdapter)1 Button (android.widget.Button)1 CompoundButton (android.widget.CompoundButton)1 IterApi (app.abhijit.iter.data.IterApi)1 ConnectionFailedException (app.abhijit.iter.exceptions.ConnectionFailedException)1 Subject (app.abhijit.iter.models.Subject)1 JsonObject (com.google.gson.JsonObject)1