use of app.abhijit.iter.data.Cache 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();
}
}
use of app.abhijit.iter.data.Cache 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();
}
}
Aggregations