X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fde%2Fdhbwloe%2Fcampusapp%2Ffragments%2FFirstRun.java;h=3e723802fa04501ddcc9c534a282e9f8758e9dbb;hb=17d3a2ce93fd3ba1ec692dea601f246ef8e068b2;hp=b84a9abb23c417e77f2548a30922a1c043d57b16;hpb=a0f644715b43af1e4acf2513b972c3f980efdaca;p=DHBWCampusApp.git diff --git a/app/src/main/java/de/dhbwloe/campusapp/fragments/FirstRun.java b/app/src/main/java/de/dhbwloe/campusapp/fragments/FirstRun.java index b84a9ab..3e72380 100644 --- a/app/src/main/java/de/dhbwloe/campusapp/fragments/FirstRun.java +++ b/app/src/main/java/de/dhbwloe/campusapp/fragments/FirstRun.java @@ -1,37 +1,94 @@ +/* FirstRun.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.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.inputmethod.InputMethodManager; +import android.widget.ArrayAdapter; +import android.widget.AutoCompleteTextView; import android.widget.Button; +import android.widget.EditText; import de.dhbwloe.campusapp.CampusAppFragment; import de.dhbwloe.campusapp.R; +import de.dhbwloe.campusapp.coursenames.CourseName; /** * A simple {@link Fragment} subclass. */ public class FirstRun extends CampusAppFragment { + private View view; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_first_run, container, false); + view = inflater.inflate(R.layout.fragment_first_run, container, false); AppContext.setTitle("Campus App"); + final FirstRun that = this; Button startAppBtn = (Button)view.findViewById(R.id.startAppBtn); startAppBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - AppContext.getDatabaseManager().setRuntimeCache("AppStartCounter", "1"); - AppContext.getNavigationManager().navigatePage("SplashScreen", null, false); + that.startApp(); + } + }); + + Button courseSendBtn = (Button)view.findViewById(R.id.courseSubmitBtn); + courseSendBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if(that.setCourse()) + that.startApp(); } }); + AutoCompleteTextView courseInput = (AutoCompleteTextView )view.findViewById(R.id.courseInput); + 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); + courseInput.setAdapter(adapter); + return view; } + private void startApp() { + AppContext.getDatabaseManager().setRuntimeCache("AppStartCounter", "1"); + AppContext.getNavigationManager().navigatePage("SplashScreen", null, false); + + InputMethodManager imm = (InputMethodManager)AppContext.getMainActivity().getSystemService(Context.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + + private boolean setCourse() { + AutoCompleteTextView courseInput = (AutoCompleteTextView )view.findViewById(R.id.courseInput); + String courseName = courseInput.getText().toString(); + if(courseName.length() <= 3) + return false; + + AppContext.getDatabaseManager().setRuntimeCache("CourseName", courseName); + return true; + } + }