Search in sources :

Example 1 with Cache

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();
    }
}
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 2 with Cache

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();
    }
}
Also used : Gson(com.google.gson.Gson) Intent(android.content.Intent) Student(app.abhijit.iter.models.Student) Cache(app.abhijit.iter.data.Cache)

Aggregations

Cache (app.abhijit.iter.data.Cache)2 Student (app.abhijit.iter.models.Student)2 Intent (android.content.Intent)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ArrayAdapter (android.widget.ArrayAdapter)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 IterApi (app.abhijit.iter.data.IterApi)1 Gson (com.google.gson.Gson)1 ArrayList (java.util.ArrayList)1