3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 package de.dhbwloe.campusapp.fragments;
17 import android.os.Bundle;
18 import android.support.v4.app.Fragment;
19 import android.view.LayoutInflater;
20 import android.view.View;
21 import android.view.ViewGroup;
22 import android.widget.EditText;
23 import android.widget.Spinner;
25 import de.dhbwloe.campusapp.CampusAppFragment;
26 import de.dhbwloe.campusapp.R;
29 * A simple {@link Fragment} subclass.
31 public class Settings extends CampusAppFragment {
32 private EditText courseNameInput;
33 private Spinner mensaRoleInput;
36 // Required empty public constructor
41 public View onCreateView(LayoutInflater inflater, ViewGroup container,
42 Bundle savedInstanceState) {
43 oFragmentView = inflater.inflate(R.layout.fragment_settings, container, false);
45 courseNameInput = (EditText) oFragmentView.findViewById(R.id.courseNameInput);
46 mensaRoleInput = (Spinner) oFragmentView.findViewById(R.id.mensaRoleInput);
53 public void onStart() {
56 String courseName = AppContext.getDatabaseManager().getRuntimeCache("CourseName");
57 if(courseName == null || courseName.isEmpty())
59 courseNameInput.setText(courseName);
61 String mensaRoleName = AppContext.getDatabaseManager().getRuntimeCache("MensaRole");
62 if (mensaRoleName == null || mensaRoleName.isEmpty())
64 int mensaRole = Integer.parseInt(mensaRoleName);
65 mensaRoleInput.setSelection(mensaRole);
69 public void onStop() {
71 boolean overrideNavigation = false;
73 String courseName = AppContext.getDatabaseManager().getRuntimeCache("CourseName");
74 if (courseName == null || courseName.isEmpty())
77 String newCourseName = courseNameInput.getText().toString();
78 if(!courseName.equalsIgnoreCase(newCourseName)) {
79 AppContext.getDatabaseManager().setRuntimeCache("CourseName", newCourseName);
80 overrideNavigation = true;
83 String mensaRoleName = AppContext.getDatabaseManager().getRuntimeCache("MensaRole");
84 if (mensaRoleName == null || mensaRoleName.isEmpty())
86 String newMensaRoleName = Integer.toString(mensaRoleInput.getSelectedItemPosition());
87 if(!mensaRoleName.equalsIgnoreCase(newMensaRoleName)) {
88 AppContext.getDatabaseManager().setRuntimeCache("MensaRole", newMensaRoleName);
89 overrideNavigation = true;
92 if(overrideNavigation) {
93 AppContext.getNavigationManager().navigatePage("Splashscreen", null, false);