use of app.abhijit.iter.models.Student in project bunk by abhijitparida.
the class AttendanceActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_attendance);
mContext = this;
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
mCache = new Cache(mContext);
try {
mNewStudent = new Gson().fromJson(getIntent().getStringExtra("student"), Student.class);
} catch (Exception ignored) {
}
mOldStudent = mCache.getStudent(mSharedPreferences.getString("pref_student", null));
if (mNewStudent == null && mOldStudent == null) {
startActivity(new Intent(AttendanceActivity.this, LoginActivity.class));
finish();
}
if (mNewStudent == null)
mNewStudent = mOldStudent;
if (mOldStudent == null)
mOldStudent = mNewStudent;
mPrefExtendedStats = mSharedPreferences.getBoolean("pref_extended_stats", true);
mPrefMinimumAttendance = Integer.parseInt(mSharedPreferences.getString("pref_minimum_attendance", "75"));
setupToolbar();
setupDrawer();
setupFab();
setupListView();
processAndDisplayAttendance();
if (!BuildConfig.DEBUG) {
displayBannerAd();
}
}
use of app.abhijit.iter.models.Student in project bunk by abhijitparida.
the class LoginActivity method setupLoginButton.
private void setupLoginButton() {
Button loginButton = findViewById(R.id.login);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = mUsernameInput.getText().toString();
String password = mPasswordInput.getText().toString();
mSharedPreferences.edit().putString("pref_student", username).apply();
mUsernameInput.setEnabled(false);
mPasswordInput.setEnabled(false);
mPasswordVisilibity.setEnabled(false);
mLoginButton.setEnabled(false);
mLoginButton.setText("LOADING...");
mLoginButton.setBackgroundResource(R.drawable.bg_login_button_loading);
((AnimationDrawable) mLoginButton.getBackground()).start();
mIterApi.getStudent(username, password, new IterApi.Callback() {
@Override
public void onData(@NonNull final Student student) {
if (mCache.getStudent(student.username) == null) {
Toast.makeText(mContext, "Credentials will be stored on your device until you Logout", Toast.LENGTH_SHORT).show();
}
mLoginButton.setText(emoji(0x1F60F) + emoji(0x1F60F) + emoji(0x1F60F));
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(LoginActivity.this, AttendanceActivity.class);
intent.putExtra("student", new Gson().toJson(student));
startActivity(intent);
finish();
}
}, 750);
}
@Override
public void onError(@NonNull RuntimeException error) {
if (error instanceof ConnectionFailedException) {
Toast.makeText(mContext, "ITER servers are currently down", Toast.LENGTH_LONG).show();
} else if (error instanceof InvalidCredentialsException) {
Toast.makeText(mContext, "Invalid credentials", Toast.LENGTH_LONG).show();
} else if (error instanceof InvalidResponseException) {
Toast.makeText(mContext, "Invalid API response", Toast.LENGTH_LONG).show();
}
if ((error instanceof InvalidResponseException || error instanceof ConnectionFailedException) && mCache.getStudent(mSharedPreferences.getString("pref_student", null)) != null) {
mLoginButton.setText("¯\\_(ツ)_/¯");
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(LoginActivity.this, AttendanceActivity.class);
startActivity(intent);
finish();
}
}, 750);
} else {
mSharedPreferences.edit().putString("pref_student", null).apply();
((AnimationDrawable) mLoginButton.getBackground()).stop();
mUsernameInput.setEnabled(true);
mPasswordInput.setEnabled(true);
mPasswordVisilibity.setEnabled(true);
mLoginButton.setBackgroundResource(R.drawable.bg_login_button_error);
mLoginButton.setText("ERROR");
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mLoginButton.setEnabled(true);
mLoginButton.setText("BUNK!");
mLoginButton.setBackgroundResource(R.drawable.bg_login_button);
}
}, 2000);
}
}
});
}
});
}
use of app.abhijit.iter.models.Student in project bunk by abhijitparida.
the class ResponseParserTest method parse_StatusSuccess_ProperlyCapitalizesStudentName.
@Test
public void parse_StatusSuccess_ProperlyCapitalizesStudentName() {
ResponseParser responseParser = new ResponseParser();
Student student = responseParser.parse("{\"name\":\"fIrStNaMe LASTNAME\",\"status\":\"success\"}", "");
assertEquals("Firstname Lastname", student.name);
}
Aggregations