package com.peterjosling.scroball.ui;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.Settings;

import com.peterjosling.scroball.ListenerService;
import com.peterjosling.scroball.R;
import com.peterjosling.scroball.ScroballApplication;

public class SplashScreen extends Activity {

  private AlertDialog alertDialog;
  private ScroballApplication application;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash_screen);
    PreferenceManager.setDefaultValues(this, R.xml.pref_notification, false);
    PreferenceManager.setDefaultValues(this, R.xml.pref_players, false);
    application = (ScroballApplication) getApplication();
    enableNotificationAccess();
  }

  @Override
  protected void onResume() {
    super.onResume();
    enableNotificationAccess();
  }

  private void enableNotificationAccess() {
    if (alertDialog != null) {
      alertDialog.dismiss();
    }

    if (!ListenerService.isNotificationAccessEnabled(this)) {
      alertDialog = new AlertDialog.Builder(this)
          .setTitle(R.string.splash_notification_access)
          .setMessage(R.string.splash_notification_access_text)
          .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
              String action;
              if (Build.VERSION.SDK_INT >= 22) {
                action = Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS;
              } else {
                action = "android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS";
              }
              startActivity(new Intent(action));
            }
          })
          .show();

      return;
    }

    if (application.getLastfmClient().isAuthenticated()) {
      Intent intent = new Intent(this, MainActivity.class);
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      startActivity(intent);
      finish();
    } else {
      Intent intent = new Intent(this, LoginActivity.class);
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
      startActivity(intent);
      finish();
    }
  }
}

@@ -97,48 +97,8 @@
 og;%0A
-import android.content.DialogInterface;%0A
 impo
@@ -1426,118 +1426,9 @@
 ok, 
-new DialogInterface.OnClickListener() %7B%0A            @Override%0A            public void onClick(DialogInterface 
+(
 dial
@@ -1445,13 +1445,12 @@
 e, i
-nt i)
+) -%3E
  %7B%0A 
@@ -1460,18 +1460,16 @@
         
- 
- 
 String a
@@ -1475,18 +1475,16 @@
 action;%0A
-  
         
@@ -1518,26 +1518,24 @@
 NT %3E= 22) %7B%0A
-  
             
@@ -1605,18 +1605,16 @@
         
-  
 %7D else %7B
@@ -1610,26 +1610,24 @@
    %7D else %7B%0A
-  
             
@@ -1699,38 +1699,34 @@
 S%22;%0A            
-  %7D%0A  
+%7D%0A
             star
@@ -1756,30 +1756,16 @@
 tion));%0A
-            %7D%0A
         

Migrate OnClickListener to lambda