package com.github.mobile.android.gist;

import static com.github.mobile.android.util.GitHubIntents.EXTRA_GIST;
import static com.github.mobile.android.util.GitHubIntents.EXTRA_GIST_FILE;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.TextView;

import com.github.mobile.android.R.id;
import com.github.mobile.android.R.layout;
import com.github.mobile.android.R.string;
import com.github.mobile.android.util.GitHubIntents.Builder;
import com.github.mobile.android.util.SourceEditor;

import org.eclipse.egit.github.core.Gist;
import org.eclipse.egit.github.core.GistFile;

import roboguice.activity.RoboActivity;
import roboguice.inject.InjectView;

/**
 * Activity to view a file in a Gist
 */
public class ViewGistFileActivity extends RoboActivity {

    /**
     * Create intent to show file
     *
     * @param gist
     * @param file
     * @return intent
     */
    public static Intent createIntent(Gist gist, GistFile file) {
        return new Builder("gist.file.VIEW").add(EXTRA_GIST, gist).add(EXTRA_GIST_FILE, file).toIntent();
    }

    @InjectView(id.tv_gist_id)
    private TextView gistId;

    @InjectView(id.wv_gist_content)
    private WebView webView;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(layout.gist_view_content_item);

        final Gist gist = (Gist) getIntent().getSerializableExtra(EXTRA_GIST);
        final GistFile file = (GistFile) getIntent().getSerializableExtra(EXTRA_GIST_FILE);

        setTitle(file.getFilename());
        gistId.setText(getString(string.gist) + " " + gist.getId());

        SourceEditor.showSource(webView, file.getFilename(), new Object() {
            public String toString() {
                return file.getContent();
            }
        });
    }
}

@@ -34,16 +34,141 @@
 .gist;%0A%0A
+import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;%0Aimport static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;%0A
 import s
@@ -427,16 +427,60 @@
 tView;%0A%0A
+import com.actionbarsherlock.view.MenuItem;%0A
 import c
@@ -708,16 +708,107 @@
 eEditor;
+%0Aimport com.github.rtyley.android.sherlock.roboguice.activity.RoboSherlockFragmentActivity;
 %0A%0Aimport
@@ -911,29 +911,26 @@
 ice.
-activity.RoboActivity
+inject.InjectExtra
 ;%0Aim
@@ -1055,16 +1055,32 @@
 nds Robo
+SherlockFragment
 Activity
@@ -1506,16 +1506,131 @@
 bView;%0A%0A
+    @InjectExtra(EXTRA_GIST)%0A    private Gist gist;%0A%0A    @InjectExtra(EXTRA_GIST_FILE)%0A    private GistFile file;%0A%0A
     prot
@@ -1777,25 +1777,24 @@
 _item);%0A
-%0A
         
 final Gi
@@ -1789,210 +1789,102 @@
     
-final Gist gist = (Gist) getIntent().getSerializableExtra(EXTRA_GIST);%0A        final GistFile file = (GistFile) getIntent().getSerializableExtra(EXTRA_GIST_FILE);%0A%0A        setTitle(file.getFilename()
+setTitle(file.getFilename());%0A        getSupportActionBar().setDisplayHomeAsUpEnabled(true
 );%0A
+%0A
     
@@ -2137,11 +2137,497 @@
 );%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 = new Intent(this, ViewGistActivity.class);%0A            intent.putExtra(EXTRA_GIST, gist);%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

Add home link to ViewGistFileActivity