package edu.rpi.cs.yacs.slides;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.afollestad.materialdialogs.MaterialDialog;
import com.github.paolorotolo.appintro.ISlidePolicy;

import edu.rpi.cs.yacs.R;

/**
 * Created by Mark Robinson on 9/26/16.
 */

public final class SelectHomeSlide extends Fragment implements ISlidePolicy {

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.select_home_slide, container, false);

        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
        String houseOfYACS = preferences.getString(getString(R.string.houseOfYACS), "unkown");

        if (houseOfYACS.equals("unkown")) {
            makeYACSHomeDialog();
        }

        return view;
    }

        @Override
    public boolean isPolicyRespected() {
            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
            String houseOfYACS = preferences.getString(getString(R.string.houseOfYACS), "unkown");

            return !(houseOfYACS.equals("unkown")); // If user should be allowed to leave this slide
    }

    @Override
    public void onUserIllegallyRequestedNextPage() {
        makeYACSHomeDialog();
    }

    public void makeYACSHomeDialog() {
        new MaterialDialog.Builder(getActivity())
                .title(R.string.houseOfYACS)
                .items(R.array.home_YACS_values)
                .itemsCallbackSingleChoice(0, new MaterialDialog.ListCallbackSingleChoice() {
                    @Override
                    public boolean onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
                        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
                        preferences.edit().putString(getString(R.string.houseOfYACS), String.valueOf(text)).apply();

                        return true;
                    }
                })
                .positiveText(R.string.Select)
                .show();
    }
}
@@ -732,17 +732,16 @@
 tate) %7B%0A
-%0A
         
@@ -816,17 +816,207 @@
 false);%0A
-%0A
+        return view;%0A    %7D%0A%0A    @Override%0A    public void setUserVisibleHint(boolean isVisibleToUser) %7B%0A        super.setUserVisibleHint(isVisibleToUser);%0A%0A        if (isVisibleToUser) %7B%0A    
         
@@ -1092,32 +1092,31 @@
 ferences(get
-Activity
+Context
 ());%0A       
@@ -1108,32 +1108,36 @@
 ext());%0A        
+    
 String houseOfYA
@@ -1212,24 +1212,28 @@
 );%0A%0A        
+    
 if (houseOfY
@@ -1260,32 +1260,36 @@
 ) %7B%0A            
+    
 makeYACSHomeDial
@@ -1298,26 +1298,29 @@
 ();%0A        
+   
+ 
 %7D
-%0A
 %0A        ret
@@ -1316,36 +1316,25 @@
         
-return view;
+%7D
 %0A    %7D%0A%0A
         
@@ -1325,20 +1325,16 @@
 %0A    %7D%0A%0A
-    
     @Ove
@@ -1469,32 +1469,31 @@
 ferences(get
-Activity
+Context
 ());%0A       
@@ -1874,24 +1874,23 @@
 lder(get
-Activity
+Context
 ())%0A    
@@ -2329,16 +2329,15 @@
 (get
-Activity
+Context
 ());

Modify SelectHomeSlide