Skip to content

Commit

Permalink
solve bug 0000025
Browse files Browse the repository at this point in the history
  • Loading branch information
domjos1994 committed Aug 21, 2018
1 parent a9f3686 commit 97e1e5c
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import de.domjos.schooltools.R;
Expand All @@ -54,8 +55,8 @@
public class TimeTableSubjectActivity extends AppCompatActivity {
private BottomNavigationView navigation;
private ListView lvSubjects;
private EditText txtSubjectTitle, txtSubjectHoursInWeek, txtSubjectDescription;
private AutoCompleteTextView txtSubjectAlias;
private EditText txtSubjectHoursInWeek, txtSubjectDescription;
private AutoCompleteTextView txtSubjectTitle, txtSubjectAlias;
private TextView lblSelectedColor;
private Spinner spSubjectTeachers;
private CheckBox chkSubjectMainSubject;
Expand Down Expand Up @@ -116,7 +117,26 @@ public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
@Override
public void afterTextChanged(Editable editable) {
if(MainActivity.globals.getUserSettings().isAutomaticallySubjects()) {
setDefaultSubjects(editable);
setDefaultSubjectByAlias(editable);
}
}
});

this.txtSubjectTitle.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override
public void afterTextChanged(Editable editable) {
if(MainActivity.globals.getUserSettings().isAutomaticallySubjects()) {
setDefaultSubjectByTitle(editable);
}
}
});
Expand Down Expand Up @@ -229,9 +249,10 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
// init controls
this.lvSubjects = this.findViewById(R.id.lvSubjects);
this.txtSubjectTitle = this.findViewById(R.id.txtSubjectTitle);
this.txtSubjectTitle.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, this.fillTitleAutoCompleteFields()));
this.txtSubjectAlias = this.findViewById(R.id.txtSubjectAlias);
List<String> aliases = Arrays.asList("M", "Mus", "D", "Eng", "NWA", "NWT", "Bio", "Ch", "Ph", "Geo", "Gk", "Rel", "Mus", "Edv", "Itg", "Inf", "Sp", "Spa", "lat");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, aliases);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, aliases);
this.txtSubjectAlias.setAdapter(adapter);


Expand Down Expand Up @@ -300,7 +321,54 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

private void setDefaultSubjects(Editable editable) {
private List<String> fillTitleAutoCompleteFields() {
List<String> list = new LinkedList<>();
list.add(this.getString(R.string.timetable_subject_d_name));
list.add(this.getString(R.string.timetable_subject_eng_name));
list.add(this.getString(R.string.timetable_subject_m_name));
list.add(this.getString(R.string.timetable_subject_nwa_name));
list.add(this.getString(R.string.timetable_subject_nwt_name));
list.add(this.getString(R.string.timetable_subject_bio_name));
list.add(this.getString(R.string.timetable_subject_ch_name));
list.add(this.getString(R.string.timetable_subject_geo_name));
list.add(this.getString(R.string.timetable_subject_gk_name));
list.add(this.getString(R.string.timetable_subject_ph_name));
list.add(this.getString(R.string.timetable_subject_rel_name));
list.add(this.getString(R.string.timetable_subject_sp_name));
list.add(this.getString(R.string.timetable_subject_mus_name));
list.add(this.getString(R.string.timetable_subject_itg_name));
list.add(this.getString(R.string.timetable_subject_spa_name));
list.add(this.getString(R.string.timetable_subject_lat_name));
return list;
}

private void setDefaultSubjectByTitle(Editable editable) {
String title = editable.toString();
this.fillDefaultSubject(title, R.string.timetable_subject_d_name, R.string.timetable_subject_d_color, true);
this.fillDefaultSubject(title, R.string.timetable_subject_eng_name, R.string.timetable_subject_eng_color, true);
this.fillDefaultSubject(title, R.string.timetable_subject_m_name, R.string.timetable_subject_m_color, true);
this.fillDefaultSubject(title, R.string.timetable_subject_nwa_name, R.string.timetable_subject_nwa_color, true);
this.fillDefaultSubject(title, R.string.timetable_subject_nwt_name, R.string.timetable_subject_nwt_color, true);
this.fillDefaultSubject(title, R.string.timetable_subject_bio_name, R.string.timetable_subject_bio_color, false);
this.fillDefaultSubject(title, R.string.timetable_subject_ch_name, R.string.timetable_subject_ch_color, false);
this.fillDefaultSubject(title, R.string.timetable_subject_geo_name, R.string.timetable_subject_geo_color, false);
this.fillDefaultSubject(title, R.string.timetable_subject_gk_name, R.string.timetable_subject_gk_color, false);
this.fillDefaultSubject(title, R.string.timetable_subject_ph_name, R.string.timetable_subject_ph_color, false);
this.fillDefaultSubject(title, R.string.timetable_subject_rel_name, R.string.timetable_subject_rel_color, false);
this.fillDefaultSubject(title, R.string.timetable_subject_sp_name, R.string.timetable_subject_sp_color, false);
this.fillDefaultSubject(title, R.string.timetable_subject_mus_name, R.string.timetable_subject_mus_color, false);
this.fillDefaultSubject(title, R.string.timetable_subject_itg_name, R.string.timetable_subject_itg_color, false);
this.fillDefaultSubject(title, R.string.timetable_subject_spa_name, R.string.timetable_subject_spa_color, true);
this.fillDefaultSubject(title, R.string.timetable_subject_lat_name, R.string.timetable_subject_lat_color, true);
}

private void fillDefaultSubject(String title, int name, int color, boolean main) {
if(title.equals(this.getString(name))) {
this.setDefaultValues(color, main);
}
}

private void setDefaultSubjectByAlias(Editable editable) {
String alias = editable.toString().toLowerCase();
switch (alias) {
case "d":
Expand Down Expand Up @@ -371,6 +439,19 @@ private void setDefaultValues(int name, int color_name, boolean main) {
lblSelectedColor.setText(this.getString(color_name));
}

@SuppressWarnings("deprecation")
private void setDefaultValues(int color_name, boolean main) {
chkSubjectMainSubject.setChecked(main);
if(main) {
txtSubjectHoursInWeek.setText(String.valueOf(4));
} else {
txtSubjectHoursInWeek.setText(String.valueOf(2));
}
int color = colorAdapter.getSelectedColor(this.getString(color_name));
lblSelectedColor.setBackgroundColor(this.getResources().getColor(color));
lblSelectedColor.setText(this.getString(color_name));
}

private void initValidation() {
this.validator = new Validator(getApplicationContext());
this.validator.addLengthValidator(txtSubjectTitle, 1, 500);
Expand Down
2 changes: 1 addition & 1 deletion src/main/res/layout/timetable_subject_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="text"/>
<EditText
<AutoCompleteTextView
android:id="@+id/txtSubjectTitle"
android:hint="@string/sys_title"
android:layout_weight="12"
Expand Down

0 comments on commit 97e1e5c

Please sign in to comment.