package org.stepic.droid.ui.activities;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;

import org.stepic.droid.R;
import org.stepic.droid.analytic.Analytic;
import org.stepic.droid.util.AppConstants;

import butterknife.BindView;
import butterknife.ButterKnife;


public class LaunchActivity extends BackToExitActivityBase {

    public static final String OVERRIDE_ANIMATION_FLAG = "override_animation_flag";

    @BindView(R.id.sign_up_btn_activity_launch)
    View mSignUpButton;

    @BindView(R.id.sign_in_tv)
    View mSignInTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_launch);
        unbinder = ButterKnife.bind(this);

        enableLoginCallback();

        //Activity override animation has to be handled if the Launch Activity
        //is called after user logs out and closes the Sign-in screen.
        if (getIntent().getBooleanExtra(OVERRIDE_ANIMATION_FLAG, false)) {
            overridePendingTransition(R.anim.no_transition, R.anim.slide_out_to_bottom);
        }

        mSignUpButton.setOnClickListener((new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                analytic.reportEvent(Analytic.Interaction.CLICK_SIGN_UP);
                shell.getScreenProvider().showRegistration(LaunchActivity.this);
            }
        }));

        mSignInTextView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                analytic.reportEvent(Analytic.Interaction.CLICK_SIGN_IN);
                shell.getScreenProvider().showLogin(LaunchActivity.this);
            }
        });
    }

    @Override
    protected void onStart() {
        super.onStart();
        bus.register(this);
    }

    @Override
    protected void onStop() {
        super.onStop();
        bus.unregister(this);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        disableLoginCallback();
    }

    //Broadcast Receiver to notify all activities to onFinish if user logs out
    private BroadcastReceiver loginReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            finish();
        }
    };

    protected void enableLoginCallback() {
        // register for login listener
        IntentFilter filter = new IntentFilter();
        filter.addAction(AppConstants.USER_LOG_IN);
        registerReceiver(loginReceiver, filter);
    }

    protected void disableLoginCallback() {
        // un-register loginReceiver
        unregisterReceiver(loginReceiver);
    }
}

@@ -38,150 +38,8 @@
 s;%0A%0A
-import android.content.BroadcastReceiver;%0Aimport android.content.Context;%0Aimport android.content.Intent;%0Aimport android.content.IntentFilter;%0A
 impo
@@ -60,16 +60,16 @@
 Bundle;%0A
+
 import a
@@ -160,51 +160,8 @@
 tic;
-%0Aimport org.stepic.droid.util.AppConstants;
 %0A%0Aim
@@ -425,18 +425,17 @@
    View 
-mS
+s
 ignUpBut
@@ -480,18 +480,17 @@
    View 
-mS
+s
 ignInTex
@@ -710,40 +710,8 @@
 );%0A%0A
-        enableLoginCallback();%0A%0A
     
@@ -1039,18 +1039,17 @@
         
-mS
+s
 ignUpBut
@@ -1360,10 +1360,9 @@
     
-mS
+s
 ignI
@@ -1638,32 +1638,32 @@
 ;%0A            %7D%0A
+
         %7D);%0A    
@@ -1667,975 +1667,7 @@
    %7D
-%0A%0A    @Override%0A    protected void onStart() %7B%0A        super.onStart();%0A        bus.register(this);%0A    %7D%0A%0A    @Override%0A    protected void onStop() %7B%0A        super.onStop();%0A        bus.unregister(this);%0A    %7D%0A%0A%0A    @Override%0A    protected void onDestroy() %7B%0A        super.onDestroy();%0A        disableLoginCallback();%0A    %7D%0A%0A    //Broadcast Receiver to notify all activities to onFinish if user logs out%0A    private BroadcastReceiver loginReceiver = new BroadcastReceiver() %7B%0A        @Override%0A        public void onReceive(Context context, Intent intent) %7B%0A            finish();%0A        %7D%0A    %7D;%0A%0A    protected void enableLoginCallback() %7B%0A        // register for login listener%0A        IntentFilter filter = new IntentFilter();%0A        filter.addAction(AppConstants.USER_LOG_IN);%0A        registerReceiver(loginReceiver, filter);%0A    %7D%0A%0A    protected void disableLoginCallback() %7B%0A        // un-register loginReceiver%0A        unregisterReceiver(loginReceiver);%0A    %7D
 %0A%7D%0A

remove obsolete code from launch activity