Added README.txt and GPL Header to Source Files
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / fragments / FirstRun.java
1 /* FirstRun.java
2  *
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.
7  *
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.
12  *
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/>.
15  */
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.Button;
23 import android.widget.EditText;
24
25 import de.dhbwloe.campusapp.CampusAppFragment;
26 import de.dhbwloe.campusapp.R;
27
28 /**
29  * A simple {@link Fragment} subclass.
30  */
31 public class FirstRun extends CampusAppFragment {
32     private View view;
33
34     @Override
35     public View onCreateView(LayoutInflater inflater, ViewGroup container,
36                              Bundle savedInstanceState) {
37         view = inflater.inflate(R.layout.fragment_first_run, container, false);
38         AppContext.setTitle("Campus App");
39         final FirstRun that = this;
40
41         Button startAppBtn = (Button)view.findViewById(R.id.startAppBtn);
42         startAppBtn.setOnClickListener(new View.OnClickListener() {
43             @Override
44             public void onClick(View v) {
45                 that.startApp();
46             }
47         });
48
49         Button courseSendBtn = (Button)view.findViewById(R.id.courseSubmitBtn);
50         courseSendBtn.setOnClickListener(new View.OnClickListener() {
51             @Override
52             public void onClick(View v) {
53                 if(that.setCourse())
54                     that.startApp();
55             }
56         });
57
58         return view;
59     }
60
61     private void startApp() {
62         AppContext.getDatabaseManager().setRuntimeCache("AppStartCounter", "1");
63         AppContext.getNavigationManager().navigatePage("SplashScreen", null, false);
64     }
65
66     private boolean setCourse() {
67         EditText courseInput = (EditText)view.findViewById(R.id.courseInput);
68         String courseName = courseInput.getText().toString();
69         if(courseName.length() <= 3)
70             return false;
71
72         AppContext.getDatabaseManager().setRuntimeCache("CourseName", courseName);
73         return true;
74     }
75
76 }