package org.commcare.android.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.widget.TextView;

import org.commcare.android.view.SquareButtonWithText;
import org.commcare.dalvik.R;
import org.javarosa.core.services.locale.Localization;

/**
 * Fragment to start, update or cancel an app installation.
 *
 * @author Daniel Luna (dcluna@dimagi.com)
 */
public class SetupKeepInstallFragment extends Fragment {
    private StartStopInstallCommands buttonCommands;

    public interface StartStopInstallCommands {
        void onStartInstallClicked();

        void onStopInstallClicked();
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (!(context instanceof StartStopInstallCommands)) {
            throw new ClassCastException(context + " must implemement " + StartStopInstallCommands.class.getName());
        }

        this.buttonCommands = (StartStopInstallCommands)context;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_setup_keepinstall, container, false);

        SquareButtonWithText btnStartInstall = (SquareButtonWithText)view.findViewById(R.id.btn_start_install);
        btnStartInstall.setText(Localization.get("install.button.start"));
        btnStartInstall.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (buttonCommands != null) buttonCommands.onStartInstallClicked();
            }
        });

        SquareButtonWithText btnStopInstall = (SquareButtonWithText)view.findViewById(R.id.btn_stop_install);
        btnStopInstall.setText(Localization.get("install.button.startover"));
        btnStopInstall.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (buttonCommands != null) buttonCommands.onStopInstallClicked();
            }
        });

        TextView setupMsg = (TextView)view.findViewById(R.id.str_setup_message);
        setupMsg.setText(Localization.get("install.ready.top"));

        TextView setupMsg2 = (TextView)view.findViewById(R.id.str_setup_message_2);
        setupMsg2.setText(Localization.get("install.ready.bottom"));

        TextView netWarn = (TextView)view.findViewById(R.id.net_warn);
        netWarn.setText(Localization.get("install.netwarn"));

        return view;
    }
}

@@ -1503,24 +1503,66 @@
 n.start%22));%0A
+        btnStartInstall.setEnabled(true);%0A
         btnS
@@ -1980,24 +1980,65 @@
 artover%22));%0A
+        btnStopInstall.setEnabled(true);%0A
         btnS

set install buttons as enabled so they show correctly