package honkot.gscheduler;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;

import honkot.gscheduler.di.AppComponent;

public class BaseActivity extends AppCompatActivity {
    private AppComponent activityComponent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @NonNull
    public AppComponent getComponent() {
        if (activityComponent == null) {
            GlobalTimerApplication hackApplication = (GlobalTimerApplication) getApplication();
            activityComponent = hackApplication.getComponent();
        }
        return activityComponent;
    }

    public void updateActionBar(String title) {
//        int stringId = getApplicationInfo().labelRes;
//        String name = getString(stringId);
//        if (title != null) {
//            setTitle(title);
//        } else {
//            setTitle(name);
//        }
//
//        ActionBar actionBar = getSupportActionBar();
//        if (actionBar != null) {
//            if (this instanceof GoBackToHomeInterface) {
//                actionBar.setDisplayHomeAsUpEnabled(((GoBackToHomeInterface) this).shouldShowGoBackButton());
//                actionBar.setHomeAsUpIndicator(R.drawable.ic_home_white_24dp);
//            } else {
//                actionBar.setDisplayHomeAsUpEnabled(false);
//            }
//
//            Session session = SessionManager.getInstance().getSession();
//            if (session == null) {
//                actionBar.setSubtitle(null);
//                actionBar.setDisplayShowHomeEnabled(false);
//            } else {
//                String userAccount = session.getUserAccount();
//                Company company = sessionDao.findCompany(session);
//                String companyName = company == null ? "" : company.getName();
//                actionBar.setSubtitle(userAccount + " @ " + companyName);
//
//                actionBar.setDisplayShowHomeEnabled(true);
//            }
//        }
    }

    @Override
    public boolean onKeyDown (int keyCode, KeyEvent event) {
        event.startTracking();
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean onKeyUp (int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.isTracking()) {
            if (!onBackKey()) {
                return false;
            }
        }
        return super.onKeyUp(keyCode, event);
    }

    /**
     * バックしたくなければfalseを返すこと
     * @return
     */
    protected boolean onBackKey() {
        return true;
    }
}

@@ -90,16 +90,57 @@
 onNull;%0A
+import android.support.v7.app.ActionBar;%0A
 import a
@@ -180,16 +180,16 @@
 tivity;%0A
-
 import a
@@ -351,16 +351,67 @@
 mponent;
+%0A    private boolean calledUpdateActionBar = false;
 %0A%0A    @O
@@ -522,24 +522,192 @@
 te);%0A    %7D%0A%0A
+    @Override%0A    protected void onResume() %7B%0A        super.onResume();%0A        if (!calledUpdateActionBar) %7B%0A            updateActionBar(null, null);%0A        %7D%0A    %7D%0A%0A
     @NonNull
@@ -1044,22 +1044,76 @@
 ng title
-) %7B%0A//
+, String subTitle) %7B%0A        calledUpdateActionBar = true;%0A%0A
         
@@ -1158,18 +1158,16 @@
 belRes;%0A
-//
         
@@ -1201,18 +1201,16 @@
 ingId);%0A
-//
         
@@ -1222,34 +1222,32 @@
 itle != null) %7B%0A
-//
             setT
@@ -1255,26 +1255,24 @@
 tle(title);%0A
-//
         %7D el
@@ -1268,34 +1268,32 @@
        %7D else %7B%0A
-//
             setT
@@ -1300,26 +1300,24 @@
 itle(name);%0A
-//
         %7D%0A//
@@ -1306,37 +1306,33 @@
 ame);%0A        %7D%0A
-//%0A//
+%0A
         ActionBa
@@ -1364,26 +1364,24 @@
 ctionBar();%0A
-//
         if (
@@ -1393,34 +1393,32 @@
 nBar != null) %7B%0A
-//
             if (
@@ -1417,464 +1417,33 @@
     
-if (this instanceof GoBackToHomeInterface) %7B%0A//                actionBar.setDisplayHomeAsUpEnabled(((GoBackToHomeInterface) this).shouldShowGoBackButton());%0A//                actionBar.setHomeAsUpIndicator(R.drawable.ic_home_white_24dp);%0A//            %7D else %7B%0A//                actionBar.setDisplayHomeAsUpEnabled(false);%0A//            %7D%0A//%0A//            Session session = SessionManager.getInstance().getSession();%0A//            if (session == null) %7B%0A//
+// setSubtitle%E3%81%AFNull%E3%82%92%E8%A8%B1%E5%AE%B9%E3%81%99%E3%82%8B%0A
     
@@ -1442,36 +1442,32 @@
 %E5%AE%B9%E3%81%99%E3%82%8B%0A            
-    
 actionBar.setSub
@@ -1476,473 +1476,19 @@
 tle(
-null);%0A//                actionBar.setDisplayShowHomeEnabled(false);%0A//            %7D else %7B%0A//                String userAccount = session.getUserAccount();%0A//                Company company = sessionDao.findCompany(session);%0A//                String companyName = company == null ? %22%22 : company.getName();%0A//                actionBar.setSubtitle(userAccount + %22 @ %22 + companyName);%0A//%0A//                actionBar.setDisplayShowHomeEnabled(true);%0A//            %7D%0A//
+subTitle);%0A
     

Add updateActionBar