package com.tuenti.tuentitv.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ProgressBar;
import butterknife.InjectView;
import com.tuenti.tuentitv.R;
import java.util.LinkedList;
import java.util.List;

/**
 * @author Pedro Vicente Gómez Sánchez.
 */
public class LoadingActivity extends BaseActivity {

  private static final long LOADING_TIME_IN_MILLIS = 3000;

  @InjectView(R.id.pb_loading) ProgressBar pb_loading;

  @Override protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.loading_activity);
    super.onCreate(savedInstanceState);
    pb_loading.getIndeterminateDrawable()
        .setColorFilter(0x32FFFFFF, android.graphics.PorterDuff.Mode.MULTIPLY);

    new Handler().postDelayed(new Runnable() {
      @Override public void run() {
        startMainActivity();
      }
    }, LOADING_TIME_IN_MILLIS);
  }

  private void startMainActivity() {
    Intent intent = new Intent(this, MainActivity.class);
    startActivity(intent);
    finish();
  }

  @Override protected List getModules() {
    return new LinkedList();
  }
}

@@ -485,16 +485,82 @@
 ading;%0A%0A
+  private Runnable startMainActivity;%0A  private Handler handler;%0A%0A
   @Overr
@@ -612,24 +612,24 @@
 nceState) %7B%0A
-
     setConte
@@ -825,20 +825,29 @@
 TIPLY);%0A
-%0A
+ 
    
+handler =
  new Han
@@ -856,21 +856,34 @@
 er()
-.postDelayed(
+;%0A    startMainActivity = 
 new 
@@ -977,32 +977,197 @@
    %7D
-, LOADING_TIME_IN_MILLIS
+;%0A    handler.postDelayed(startMainActivity, LOADING_TIME_IN_MILLIS);%0A  %7D%0A%0A  @Override public void onBackPressed() %7B%0A    super.onBackPressed();%0A    handler.removeCallbacks(startMainActivity
 );%0A 

Remove start main activity task from handler if back button is pressed during loading process.