Skip to content

Commit

Permalink
added Calendar to Home #18
Browse files Browse the repository at this point in the history
added some Strings #22
set HomeFragment as pre-selected on app start
  • Loading branch information
Schmitt-Florian committed Apr 30, 2017
1 parent b6a6788 commit 9a6ce56
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 87 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package schmitt_florian.schoolplanner.activities;



import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.TextView;



/**
* A basic auxiliary class containing simple methods for GUI interaction
*/
class GuiHelper {

/**
* method to set the Text of a TextView
* @param view the view the TextView is in
* @param id Resource ID of the TextView
* @param text The text to set to the TextView
*/
void setTextToTextView(View view, int id, String text) {
TextView textView = (TextView) view.findViewById(id);
textView.setText(text);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,71 +8,34 @@
import android.view.View;
import android.view.ViewGroup;

import java.util.Calendar;

import schmitt_florian.schoolplanner.R;

/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* {@link HomeFragment.OnFragmentInteractionListener} interface
* to handle interaction events.
* Use the {@link HomeFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class HomeFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;

private OnFragmentInteractionListener mListener;

public HomeFragment() {
// Required empty public constructor
}

/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment HomeFragment.
*/
// TODO: Rename and change types and number of parameters
public static HomeFragment newInstance(String param1, String param2) {
HomeFragment fragment = new HomeFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
private GuiHelper guiHelper;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
guiHelper = new GuiHelper();

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_home, container, false);
}
View view = inflater.inflate(R.layout.fragment_home, container, false);
setDateToLabels(view);

// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
return view;
}

@Override
Expand Down Expand Up @@ -102,8 +65,49 @@ public void onDetach() {
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}

//region private methods

/**
* method to initialise the Labels, which show the the Date at the home screen
*
* @param view the view of the fragment
*/
private void setDateToLabels(View view) {
Calendar calendar = Calendar.getInstance();
switch (calendar.get(Calendar.DAY_OF_WEEK)) {
case Calendar.MONDAY:
guiHelper.setTextToTextView(view, R.id.home_labelWeekday, getString(R.string.string_day_monday));
break;
case Calendar.TUESDAY:
guiHelper.setTextToTextView(view, R.id.home_labelWeekday, getString(R.string.string_day_tuesday));
break;
case Calendar.WEDNESDAY:
guiHelper.setTextToTextView(view, R.id.home_labelWeekday, getString(R.string.string_day_wednesday));
break;
case Calendar.THURSDAY:
guiHelper.setTextToTextView(view, R.id.home_labelWeekday, getString(R.string.string_day_thursday));
break;
case Calendar.FRIDAY:
guiHelper.setTextToTextView(view, R.id.home_labelWeekday, getString(R.string.string_day_friday));
break;
case Calendar.SATURDAY:
guiHelper.setTextToTextView(view, R.id.home_labelWeekday, getString(R.string.string_day_saturday));
break;
case Calendar.SUNDAY:
guiHelper.setTextToTextView(view, R.id.home_labelWeekday, getString(R.string.string_day_sunday));
break;
default:
guiHelper.setTextToTextView(view, R.id.home_labelWeekday, "Error");
break;
}
//Todo support different date formats
guiHelper.setTextToTextView(view, R.id.home_lableDate, calendar.get(Calendar.DAY_OF_MONTH) + "." + calendar.get(Calendar.MONTH) + "." + calendar.get(Calendar.YEAR));
}
//endregion

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On

private static final String TAG = "MainActivity";
FragmentManager fragmentManager;
Fragment f;
boolean a = true;


@Override
Expand All @@ -40,7 +38,6 @@ protected void onCreate(Bundle savedInstanceState) {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);


DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
Expand All @@ -50,10 +47,11 @@ protected void onCreate(Bundle savedInstanceState) {
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);



fragmentManager = this.getSupportFragmentManager();

navigationView.getMenu().getItem(0).setChecked(true);
onNavigationItemSelected(navigationView.getMenu().getItem(0));

}

@Override
Expand All @@ -66,60 +64,45 @@ public void onBackPressed() {
}
}


@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();

if (id == R.id.nav_main) {
// Goto Home
HomeFragment homeFragment = new HomeFragment();
FragmentTransaction ft = fragmentManager.beginTransaction();
ft.replace(R.id.containerMain, homeFragment);
ft.replace(R.id.containerMain, new HomeFragment());
ft.commit();

} else if (id == R.id.nav_schedule) {
// Goto Schedule
ScheduleFragment scheduleFragment = new ScheduleFragment();
FragmentTransaction ft = fragmentManager.beginTransaction();
ft.replace(R.id.containerMain, scheduleFragment);
ft.replace(R.id.containerMain, new ScheduleFragment());
ft.commit();

} else if (id == R.id.nav_subjects) {
// Goto Subjects
SubjectsFragment subjectsFragment = new SubjectsFragment();
FragmentTransaction ft = fragmentManager.beginTransaction();
ft.replace(R.id.containerMain, subjectsFragment);
ft.replace(R.id.containerMain, new SubjectsFragment());
ft.commit();

} else if (id == R.id.nav_homework) {
//Goto Homework
HomeworkFragment homeworkFragment = new HomeworkFragment();
FragmentTransaction ft = fragmentManager.beginTransaction();
ft.replace(R.id.containerMain, homeworkFragment);
ft.replace(R.id.containerMain, new HomeworkFragment());
ft.commit();

} else if (id == R.id.nav_exams) {
// Goto Exams
ExamsFragment examsFragment = new ExamsFragment();
FragmentTransaction ft = fragmentManager.beginTransaction();
ft.replace(R.id.containerMain, examsFragment);
ft.replace(R.id.containerMain, new ExamsFragment());
ft.commit();

} else if (id == R.id.nav_credits) {
//Goto Credits
CreditsFragment creditsFragment = new CreditsFragment();
FragmentTransaction ft = fragmentManager.beginTransaction();
ft.replace(R.id.containerMain, creditsFragment);
ft.replace(R.id.containerMain, new CreditsFragment());
ft.commit();

} else if (id == R.id.nav_settings) {
// Goto Settings
SettingsFragment settingsFragment = new SettingsFragment();
FragmentTransaction ft = fragmentManager.beginTransaction();
ft.replace(R.id.containerMain, settingsFragment);
ft.replace(R.id.containerMain, new SettingsFragment());
ft.commit();

}
Expand Down
Loading

0 comments on commit 9a6ce56

Please sign in to comment.