Commits

Juha Kuitunen  committed cc65079

limited support for viewing changeset diff

  • Participants
  • Parent commits aa1d9c4

Comments (0)

Files changed (6)

File AndroidManifest.xml

 		<activity android:name="SourceBrowserActivity"></activity>
 		<activity android:name="WikiActivity"></activity>
 		<activity android:name="SourceActivity"></activity>
+		<activity android:name="DiffActivity"></activity>
 		<activity android:name="IssuesActivity"></activity>
 		<activity android:name=".SearchableActivity">
 	        <intent-filter>

File assets/diff.html

+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>Diff</title>
+<link href="file:///android_asset/prettify.css" type="text/css" rel="stylesheet" />
+<script type="text/javascript" src="file:///android_asset/prettify.js"></script>
+</head>
+<body>
+<pre><code id="code" class="prettyprint"></code></pre>
+<script language="javascript">
+	document.getElementById("code").innerHTML = bitbeaker.getCode();
+	prettyPrint();
+</script>
+</body>
+</html>

File res/layout/diff.xml

+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+  xmlns:android="http://schemas.android.com/apk/res/android"
+  android:layout_width="match_parent"
+  android:layout_height="match_parent" android:orientation="vertical">
+    <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content">
+        <include layout="@layout/header" android:layout_height="wrap_content" android:layout_width="match_parent"></include>
+    </LinearLayout>
+    <WebView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/diff_webview"></WebView>
+</LinearLayout>

File src/com/saibotd/bitbeaker/ChangesetActivity.java

 
 import android.app.Activity;
 import android.content.Context;
+import android.content.Intent;
 import android.os.Bundle;
 import android.util.Log;
 import android.view.View;
+import android.view.View.OnClickListener;
 import android.view.ViewGroup;
 import android.widget.ImageView;
 import android.widget.ListView;
 import android.widget.TextView;
 
 public class ChangesetActivity extends Activity {
-    
+
 	private JSONObject mData;
-	
+	private String changeset_id;
+	private String slug;
+	private String owner;
+
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.changeset);
         ((TextView) findViewById(R.id.header_title)).setText("Changeset");
         
         Bundle b = getIntent().getExtras();
+        owner = b.getString("owner");
+        slug = b.getString("slug");
         try {
 			mData = new JSONObject(b.getString("data"));
 		} catch (JSONException e) {
 		ChangesetAdapter adapter;
 		try {
 			Log.d("XXX", mData.getJSONArray("files").toString());
+			changeset_id = mData.getString("node");
 			adapter = new ChangesetAdapter(this, mData.getJSONArray("files"));
 			listView.setAdapter(adapter);
 		} catch (JSONException e1) {
     }
     
     protected class ChangesetAdapter extends MyAdapter {
-    	
+
     	public ChangesetAdapter(Context context, JSONArray jsonArray) {
     		super(context, jsonArray);
     	}
-    	
+
     	public View getView(int position, View convertView, ViewGroup parent) {
     		View view;
     		if (convertView == null) {
     			// TODO Auto-generated catch block
     			e.printStackTrace();
     		}
+    		view.setOnClickListener(showDiffClickListener);
     		return view;
     	}
 
-    }
+		private OnClickListener showDiffClickListener = new OnClickListener() {
+			public void onClick(View v) {
+				Intent intent = new Intent(v.getContext(), DiffActivity.class);
+				Bundle b = new Bundle();
+				b.putString("owner", owner);
+				b.putString("slug", slug);
+				b.putString("changeset", changeset_id);
+				b.putString("file", ((TextView) v.findViewById(R.id.subtitle)).getText().toString());
+				intent.putExtras(b);
+				v.getContext().startActivity(intent);
+			}
+		};
+
+	}
 }

File src/com/saibotd/bitbeaker/DiffActivity.java

+package com.saibotd.bitbeaker;
+
+import android.app.ProgressDialog;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.Log;
+import android.webkit.JsResult;
+import android.webkit.WebChromeClient;
+import android.webkit.WebView;
+import android.widget.TextView;
+
+public class DiffActivity extends MyActivity {
+
+	private String slug;
+	private String owner;
+	private String file;
+	private String code;
+	private String changeset_id;
+	
+	public void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.diff);
+		Bundle b = getIntent().getExtras();
+		owner = b.getString("owner");
+		slug = b.getString("slug");
+		changeset_id = b.getString("changeset");
+		file = b.getString("file");
+
+		progressDialog = ProgressDialog.show(this, "", "Loading ...", true);
+		AsyncLoader asyncLoader = new AsyncLoader();
+		asyncLoader.execute("https://bitbucket.org/"+ owner +"/"+slug+"/changeset/"+changeset_id+"/raw/");
+		((TextView) findViewById(R.id.header_title)).setText("Diff: "+changeset_id);
+	}
+
+	public void AsyncLoaderDone(String result) {
+		super.AsyncLoaderDone(result);
+		code = TextUtils.htmlEncode(result);
+		WebView webView = (WebView) findViewById(R.id.diff_webview);
+		webView.getSettings().setBuiltInZoomControls(true);
+		webView.getSettings().setUseWideViewPort(true);
+		webView.getSettings().setJavaScriptEnabled(true);
+		webView.addJavascriptInterface(new JavaScriptInterface(), "bitbeaker");
+		webView.setWebChromeClient(new WebChromeClient());
+		webView.loadUrl("file:///android_asset/diff.html");
+	}
+
+	private class JavaScriptInterface{
+		@SuppressWarnings("unused")
+		public String getCode() {
+			return code;
+		}
+	}
+
+}

File src/com/saibotd/bitbeaker/RepositoryActivity.java

 	}
 	
 	protected class ChangesetsAdapter extends MyAdapter {
-		
 
 		public ChangesetsAdapter(RepositoryActivity context, JSONArray jsonArray) {
 			super(context, jsonArray);
 		}
-		
+
 		private OnClickListener clickListener = new OnClickListener() {
 			public void onClick(View v) {
 				try {
 					JSONObject rec = (JSONObject) mData.get(v.getId());
 					//((RepositoriesActivity) mContext).launchActivity(rec.getString("name"));
-			    	Intent intent = new Intent(v.getContext(), ChangesetActivity.class);
+					Intent intent = new Intent(v.getContext(), ChangesetActivity.class);
 					Bundle b = new Bundle();
 					b.putString("data", rec.toString());
+					b.putString("slug", slug);
+					b.putString("owner", owner);
 					intent.putExtras(b);
 					v.getContext().startActivity(intent);
 				} catch (JSONException e) {
 			TextView subtitle = (TextView) view.findViewById(R.id.subtitle);
 			try {
 				title.setText(this.getItem(position).getString("node"));
-				subtitle.setText(this.getItem(position).getString("timestamp") + " - " + this.getItem(position).getString("author") + ": \"" + this.getItem(position).getString("message") + "\"");
+				subtitle.setText(this.getItem(position).getString("timestamp") + " - " + this.getItem(position).getString("author") + ": \"" + this.getItem(position).getString("message").trim() + "\"");
 			} catch (JSONException e) {
 				// TODO Auto-generated catch block
 				e.printStackTrace();