package io.github.droidkaigi.confsched2017.view.activity;

import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.MenuItem;

import io.github.droidkaigi.confsched2017.R;
import io.github.droidkaigi.confsched2017.view.fragment.SessionDetailFragmentCreator;

public class SessionDetailActivity extends BaseActivity {

    private static final String EXTRA_SESSION_ID = "session_id";

    public static Intent createIntent(@NonNull Context context, int sessionId) {
        Intent intent = new Intent(context, SessionDetailActivity.class);
        intent.putExtra(EXTRA_SESSION_ID, sessionId);
        return intent;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        DataBindingUtil.setContentView(this, R.layout.activity_session_detail);
        getComponent().inject(this);

        final int sessionId = getIntent().getIntExtra(EXTRA_SESSION_ID, 0);
        replaceFragment(SessionDetailFragmentCreator.newBuilder(sessionId).build(), R.id.content_view);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                upToMainActivity();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    private void upToMainActivity() {
        Intent upIntent = new Intent(getApplicationContext(), MainActivity.class);
        upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivity(upIntent);
        finish();
    }

}

@@ -228,16 +228,47 @@
 onNull;%0A
+import android.text.TextUtils;%0A
 import a
@@ -289,16 +289,16 @@
 nuItem;%0A
-
 %0Aimport 
@@ -545,16 +545,115 @@
 ion_id%22;
+%0A    private static final String EXTRA_PARENT_NAME = %22parent_name%22;%0A%0A    private String parentName;
 %0A%0A    pu
@@ -855,16 +855,99 @@
 ionId);%0A
+        intent.putExtra(EXTRA_PARENT_NAME, context.getClass().getCanonicalName());%0A
         
@@ -1277,16 +1277,84 @@
 ID, 0);%0A
+        parentName = getIntent().getStringExtra(EXTRA_PARENT_NAME);%0A
         
@@ -1616,28 +1616,30 @@
         upTo
-Main
+Parent
 Activity();%0A
@@ -1759,33 +1759,341 @@
 upTo
-MainActivity() %7B%0A
+ParentActivity() %7B%0A        Intent upIntent;%0A        if (TextUtils.equals(this.parentName, MySessionsActivity.class.getCanonicalName())) %7B%0A            upIntent = new Intent(getApplicationContext(), MySessionsActivity.class);%0A        %7D else if (TextUtils.equals(this.parentName, SearchActivity.class.getCanonicalName())) %7B%0A    
         
 Inte
@@ -2080,39 +2080,131 @@
 ) %7B%0A            
+up
 Intent 
+= new Intent(getApplicationContext(), SearchActivity.class);%0A        %7D else %7B%0A            
 upIntent = new I
@@ -2247,32 +2247,42 @@
 ctivity.class);%0A
+        %7D%0A
         upIntent

Fix session detail UP button