private void updateWifiSwitch(View layout) { final PrefManager wifiPrefManager = new PrefManager(getActivity().getBaseContext(), PrefManager.Pref.WIFI); Switch wifi_switch = (Switch) layout.findViewById(R.id.wifi_setting); wifi_switch.setOnCheckedChangeListener(null); wifi_switch.setChecked(wifiPrefManager.getBoolean(PrefManager.Key.DOWNLOAD_ONLY_ON_WIFI, true)); wifi_switch.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { wifiPrefManager.put(PrefManager.Key.DOWNLOAD_ONLY_ON_WIFI, true); } else { showWifiDialog(); } } }); }
@Override public void onResume() { super.onResume(); uiLifecycleHelper.onResume(); if (getView() != null) { TextView groups_tv = (TextView) getView().findViewById(R.id.drawer_option_my_groups); boolean allowSocialFeatures = socialPref.getBoolean(PrefManager.Key.ALLOW_SOCIAL_FEATURES, true); groups_tv.setVisibility(allowSocialFeatures ? View.VISIBLE : View.GONE); } }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); Context context = getActivity().getBaseContext(); socialPref = new PrefManager(context, PrefManager.Pref.FEATURES); pref = new PrefManager(context, PrefManager.Pref.LOGIN); View layout = inflater.inflate(R.layout.drawer_navigation, null); TextView name_tv = (TextView) layout.findViewById(R.id.name_tv); TextView email_tv = (TextView) layout.findViewById(R.id.email_tv); TextView tvMyCourses = (TextView) layout.findViewById(R.id.drawer_option_my_courses); tvMyCourses.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Activity act = getActivity(); ((BaseFragmentActivity) act).closeDrawer(); if (!(act instanceof MyCoursesListActivity)) { environment.getRouter().showMyCourses(act); act.finish(); } } }); TextView tvMyVideos = (TextView) layout.findViewById(R.id.drawer_option_my_videos); tvMyVideos.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Activity act = getActivity(); ((BaseFragmentActivity) act).closeDrawer(); if (!(act instanceof MyVideosTabActivity)) { environment.getRouter().showMyVideos(act); // Finish need not be called if the current activity is MyCourseListing // as on returning back from FindCourses, // the student should be returned to the MyCourses screen if (!(act instanceof MyCoursesListActivity)) { act.finish(); } } } }); TextView tvFindCourses = (TextView) layout.findViewById(R.id.drawer_option_find_courses); tvFindCourses.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { try { ISegment segIO = environment.getSegment(); segIO.trackUserFindsCourses(); } catch (Exception e) { logger.error(e); } Activity act = getActivity(); ((BaseFragmentActivity) act).closeDrawer(); if (environment.getConfig().getEnrollmentConfig().isEnabled()) { if (!(act instanceof FindCoursesActivity)) { environment.getRouter().showFindCourses(act); // Finish need not be called if the current activity is MyCourseListing // as on returning back from FindCourses, // the student should be returned to the MyCourses screen if (!(act instanceof MyCoursesListActivity)) { act.finish(); } } } else { // Show the dialog only if the activity is started. This is to avoid Illegal state // exceptions if the dialog fragment tries to show even if the application is not in // foreground if (isAdded() && isVisible()) { FindCoursesDialogFragment findCoursesFragment = new FindCoursesDialogFragment(); findCoursesFragment.setStyle( DialogFragment.STYLE_NORMAL, android.R.style.Theme_Black_NoTitleBar_Fullscreen); findCoursesFragment.setCancelable(false); findCoursesFragment.show(getFragmentManager(), "dialog-find-courses"); } } } }); TextView tvMyGroups = (TextView) layout.findViewById(R.id.drawer_option_my_groups); tvMyGroups.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Activity act = getActivity(); ((BaseFragmentActivity) act).closeDrawer(); if (!(act instanceof MyGroupsListActivity)) { environment.getRouter().showMyGroups(act); if (!(act instanceof MyCoursesListActivity)) { act.finish(); } } } }); TextView tvSettings = (TextView) layout.findViewById(R.id.drawer_option_my_settings); tvSettings.setOnClickListener( new OnClickListener() { @Override public void onClick(View view) { Activity act = getActivity(); ((BaseFragmentActivity) act).closeDrawer(); if (!(act instanceof SettingsActivity)) { environment.getRouter().showSettings(act); if (!(act instanceof MyCoursesListActivity)) { act.finish(); } } } }); TextView tvSubmitFeedback = (TextView) layout.findViewById(R.id.drawer_option_submit_feedback); tvSubmitFeedback.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { String to = environment.getConfig().getFeedbackEmailAddress(); String subject = getString(R.string.email_subject); String email = ""; EmailUtil.sendEmail(getActivity(), to, subject, email, environment.getConfig()); } }); ProfileModel profile = pref.getCurrentUserProfile(); if (profile != null) { if (profile.name != null) { name_tv.setText(profile.name); } if (profile.email != null) { email_tv.setText(profile.email); } } Button logout_btn = (Button) layout.findViewById(R.id.logout_button); logout_btn.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { environment .getRouter() .forceLogout( getActivity(), environment.getSegment(), environment.getNotificationDelegate()); } }); TextView version_tv = (TextView) layout.findViewById(R.id.tv_version_no); try { String versionName = PropertyUtil.getManifestVersionName(getActivity()); if (versionName != null) { String envDisplayName = environment.getConfig().getEnvironmentDisplayName(); String text = String.format( "%s %s %s", getString(R.string.label_version), versionName, envDisplayName); version_tv.setText(text); } } catch (Exception e) { logger.error(e); } return layout; }