package com.iic.mokojin.activities;

import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import com.iic.mokojin.R;
import com.iic.mokojin.cloud.operations.GoodNightOperation;
import com.iic.mokojin.data.CurrentSessionStore;
import com.iic.mokojin.views.ProgressHudDialog;

import javax.inject.Inject;

import bolts.Continuation;
import bolts.Task;


public class MainActivity extends AbstractMokojinActivity {

    @Inject CurrentSessionStore mCurrentSessionStore;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_current_match, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_settings) {
            return true;
        } else if (id == R.id.action_goodnight){
            final ProgressHudDialog dialog = new ProgressHudDialog(this, getString(R.string.good_night_progress));
            dialog.show();
            GoodNightOperation goodNightOperation = new GoodNightOperation();
            goodNightOperation.run().continueWith(new Continuation<Void, Object>() {
                @Override
                public Object then(Task<Void> task) throws Exception {
                    dialog.dismiss();
                    mCurrentSessionStore.refreshData();
                    return null;
                }
            });
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

}

@@ -1127,24 +1127,183 @@
 night)%7B%0A    
+        performGoodNight();%0A            return true;%0A        %7D%0A%0A        return super.onOptionsItemSelected(item);%0A    %7D%0A%0A    private void performGoodNight() %7B%0A
         fina
@@ -1405,28 +1405,24 @@
 ));%0A        
-  
-  
 dialog.show(
@@ -1420,28 +1420,24 @@
 log.show();%0A
-    
         Good
@@ -1506,20 +1506,16 @@
         
-   
- 
 goodNigh
@@ -1591,20 +1591,16 @@
         
-    
 @Overrid
@@ -1601,20 +1601,16 @@
 verride%0A
-    
         
@@ -1680,28 +1680,24 @@
             
-    
 dialog.dismi
@@ -1698,28 +1698,24 @@
 .dismiss();%0A
-    
             
@@ -1766,28 +1766,24 @@
             
-    
 return null;
@@ -1799,113 +1799,19 @@
     
-    %7D%0A            %7D);%0A            return true;%0A        %7D%0A%0A        return super.onOptionsItemSelected(item
+%7D%0A        %7D
 );%0A 

extract good night op