+/* 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 <http://www.gnu.org/licenses/>.
+ */
package de.dhbwloe.campusapp.fragments;
-
-
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.EditText;
+import android.widget.Spinner;
import de.dhbwloe.campusapp.CampusAppFragment;
import de.dhbwloe.campusapp.R;
* A simple {@link Fragment} subclass.
*/
public class Settings extends CampusAppFragment {
-
+ private EditText courseNameInput;
+ private Spinner mensaRoleInput;
public Settings() {
// Required empty public constructor
@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 = (EditText) oFragmentView.findViewById(R.id.courseNameInput);
+ mensaRoleInput = (Spinner) oFragmentView.findViewById(R.id.mensaRoleInput);
+
+ 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 = "";
+ 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);
+
+ }
+ }
}