/*
 * Copyright 2012 GitHub Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.github.mobile.ui.commit;

import static com.github.mobile.Intents.EXTRA_BASE;
import static com.github.mobile.Intents.EXTRA_HEAD;
import static com.github.mobile.Intents.EXTRA_REPOSITORY;
import android.content.Intent;
import android.os.Bundle;

import com.actionbarsherlock.app.ActionBar;
import com.github.mobile.Intents.Builder;
import com.github.mobile.ui.DialogFragmentActivity;
import com.github.mobile.util.AvatarLoader;
import com.google.inject.Inject;
import com.viewpagerindicator.R.layout;

import org.eclipse.egit.github.core.Repository;

/**
 * Activity to display a comparison between two commits
 */
public class CommitCompareViewActivity extends DialogFragmentActivity {

    /**
     * Create intent for this activity
     *
     * @param repository
     * @param base
     * @param head
     * @return intent
     */
    public static Intent createIntent(final Repository repository,
            final String base, final String head) {
        Builder builder = new Builder("commits.compare.VIEW");
        builder.add(EXTRA_BASE, base);
        builder.add(EXTRA_HEAD, head);
        builder.repo(repository);
        return builder.toIntent();
    }

    @Inject
    private AvatarLoader avatars;

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

        setContentView(layout.commit_compare);

        Intent intent = getIntent();
        Repository repository = (Repository) intent
                .getSerializableExtra(EXTRA_REPOSITORY);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setSubtitle(repository.generateId());
        avatars.bind(actionBar, repository.getOwner());
    }
}

@@ -619,24 +619,149 @@
 ui.commit;%0A%0A
+import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;%0Aimport static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;%0A
 import stati
@@ -800,16 +800,16 @@
 A_BASE;%0A
-
 import s
@@ -1012,16 +1012,60 @@
 ionBar;%0A
+import com.actionbarsherlock.view.MenuItem;%0A
 import c
@@ -1150,16 +1150,73 @@
 tivity;%0A
+import com.github.mobile.ui.repo.RepositoryViewActivity;%0A
 import c
@@ -1374,16 +1374,54 @@
 itory;%0A%0A
+import roboguice.inject.InjectExtra;%0A%0A
 /**%0A * A
@@ -2032,16 +2032,87 @@
 %0A    %7D%0A%0A
+    @InjectExtra(EXTRA_REPOSITORY)%0A    private Repository repository;%0A%0A
     @Inj
@@ -2318,154 +2318,8 @@
 );%0A%0A
-        Intent intent = getIntent();%0A        Repository repository = (Repository) intent%0A                .getSerializableExtra(EXTRA_REPOSITORY);%0A
     
@@ -2363,24 +2363,75 @@
 ctionBar();%0A
+        actionBar.setDisplayHomeAsUpEnabled(true);%0A
         acti
@@ -2470,24 +2470,24 @@
 erateId());%0A
-
         avat
@@ -2535,11 +2535,457 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public boolean onOptionsItemSelected(MenuItem item) %7B%0A        switch (item.getItemId()) %7B%0A        case android.R.id.home:%0A            Intent intent = RepositoryViewActivity.createIntent(repository);%0A            intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP %7C FLAG_ACTIVITY_SINGLE_TOP);%0A            startActivity(intent);%0A            return true;%0A        default:%0A            return super.onOptionsItemSelected(item);%0A        %7D%0A    %7D
 %0A%7D%0A

Return to repository view from CommitCompareViewActivity