X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fde%2Fdhbwloe%2Fcampusapp%2Ffragments%2FSettings.java;h=e34eb72cf9203fdda130a42fe21c0656e169077d;hb=17d3a2ce93fd3ba1ec692dea601f246ef8e068b2;hp=85a444235abc457b58fcc58f2b708c7ddb836e94;hpb=cea4ee15ef92f521ae962404bd1b3c25042219fa;p=DHBWCampusApp.git diff --git a/app/src/main/java/de/dhbwloe/campusapp/fragments/Settings.java b/app/src/main/java/de/dhbwloe/campusapp/fragments/Settings.java index 85a4442..e34eb72 100644 --- a/app/src/main/java/de/dhbwloe/campusapp/fragments/Settings.java +++ b/app/src/main/java/de/dhbwloe/campusapp/fragments/Settings.java @@ -1,20 +1,44 @@ +/* Settings.java + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package de.dhbwloe.campusapp.fragments; - - +import android.content.Context; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodManager; +import android.widget.ArrayAdapter; +import android.widget.AutoCompleteTextView; +import android.widget.EditText; +import android.widget.Spinner; +import android.widget.TextView; import de.dhbwloe.campusapp.CampusAppFragment; import de.dhbwloe.campusapp.R; +import de.dhbwloe.campusapp.coursenames.CourseName; /** * A simple {@link Fragment} subclass. */ public class Settings extends CampusAppFragment { - + private AutoCompleteTextView courseNameInput; + private Spinner mensaRoleInput; public Settings() { // Required empty public constructor @@ -24,8 +48,84 @@ public class Settings extends CampusAppFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_settings, container, false); + oFragmentView = inflater.inflate(R.layout.fragment_settings, container, false); + + courseNameInput = (AutoCompleteTextView) oFragmentView.findViewById(R.id.courseNameInput); + mensaRoleInput = (Spinner) oFragmentView.findViewById(R.id.mensaRoleInput); + + courseNameInput.setImeOptions(EditorInfo.IME_ACTION_DONE); + courseNameInput.setOnEditorActionListener( + new EditText.OnEditorActionListener() { + @Override + public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { + if (actionId == EditorInfo.IME_ACTION_SEARCH || + actionId == EditorInfo.IME_ACTION_DONE || + event.getAction() == KeyEvent.ACTION_DOWN && + event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { + + InputMethodManager imm = (InputMethodManager)AppContext.getMainActivity().getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(v.getWindowToken(), 0); + return true; + } + return false; + } + }); + + CourseName names[] = AppContext.getDatabaseManager().getCourseNames(); + String courseNames[] = new String[names.length]; + for(int i = 0; i < names.length; i++) { + courseNames[i] = names[i].getName(); + } + + ArrayAdapter adapter = new ArrayAdapter(AppContext.getMainActivity(), android.R.layout.simple_list_item_1, courseNames); + courseNameInput.setAdapter(adapter); + + return oFragmentView; + } + + + @Override + public void onStart() { + super.onStart(); + + String courseName = AppContext.getDatabaseManager().getRuntimeCache("CourseName"); + if(courseName == null || courseName.isEmpty()) + courseName = ""; + courseNameInput.setText(courseName); + + String mensaRoleName = AppContext.getDatabaseManager().getRuntimeCache("MensaRole"); + if (mensaRoleName == null || mensaRoleName.isEmpty()) + mensaRoleName = "0"; + int mensaRole = Integer.parseInt(mensaRoleName); + mensaRoleInput.setSelection(mensaRole); } + @Override + public void onStop() { + super.onStop(); + boolean overrideNavigation = false; + + String courseName = AppContext.getDatabaseManager().getRuntimeCache("CourseName"); + if (courseName == null || courseName.isEmpty()) + courseName = ""; + + String newCourseName = courseNameInput.getText().toString(); + if(!courseName.equalsIgnoreCase(newCourseName)) { + AppContext.getDatabaseManager().setRuntimeCache("CourseName", newCourseName); + overrideNavigation = true; + } + + String mensaRoleName = AppContext.getDatabaseManager().getRuntimeCache("MensaRole"); + if (mensaRoleName == null || mensaRoleName.isEmpty()) + mensaRoleName = "0"; + String newMensaRoleName = Integer.toString(mensaRoleInput.getSelectedItemPosition()); + if(!mensaRoleName.equalsIgnoreCase(newMensaRoleName)) { + AppContext.getDatabaseManager().setRuntimeCache("MensaRole", newMensaRoleName); + overrideNavigation = true; + } + + if(overrideNavigation) { + AppContext.getNavigationManager().navigatePage("Splashscreen", null, false); + } + } }