Search in sources :

Example 1 with IterApi

use of app.abhijit.iter.data.IterApi 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)

Aggregations

View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ArrayAdapter (android.widget.ArrayAdapter)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 Cache (app.abhijit.iter.data.Cache)1 IterApi (app.abhijit.iter.data.IterApi)1 Student (app.abhijit.iter.models.Student)1 ArrayList (java.util.ArrayList)1