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();
}
}
Aggregations