Commits

Juha Kuitunen committed 1d50f3a

show diff only for requested file

  • Participants
  • Parent commits c3fad89

Comments (0)

Files changed (2)

File res/layout/diff.xml

   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>
+    <include layout="@layout/header" android:layout_height="wrap_content" android:layout_width="match_parent"></include>
     <WebView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/diff_webview"></WebView>
 </LinearLayout>

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

 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;
 	private String file;
 	private String code;
 	private String changeset_id;
-	
+
 	public void onCreate(Bundle savedInstanceState) {
 		super.onCreate(savedInstanceState);
 		setContentView(R.layout.diff);
 		changeset_id = b.getString("changeset");
 		file = b.getString("file");
 
-		progressDialog = ProgressDialog.show(this, "", "Loading ...", true);
+		progressDialog = ProgressDialog.show(this, "", "Loading diff...", 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);
+		result = splitDiff(result);
+		code = TextUtils.htmlEncode(result.replace("\t", "  "));
 		WebView webView = (WebView) findViewById(R.id.diff_webview);
 		webView.getSettings().setBuiltInZoomControls(true);
 		webView.getSettings().setUseWideViewPort(true);
 		}
 	}
 
+	private String splitDiff(String input) {
+		// search only requested file's diff and display it
+		String lines[] = input.split("\n");
+		String contents = "";
+		String filename = "";
+		boolean right_file = false;
+		for (int i=0; i<lines.length; i++) {
+			if ( lines[i].matches("^diff -r .*") || lines[i].matches("^diff --git .*") ) {
+				String[] tmp = lines[i].split(" ");
+				filename = tmp[tmp.length-1];
+				if (lines[i].matches("^diff --git .*"))
+					filename = filename.substring(2);
+				if (filename.equals(file)) {
+					right_file = true;
+					contents = contents + lines[i] + "\n";
+				} else right_file = false;
+			}
+			else {
+				if (right_file) contents = contents + lines[i] + "\n";
+			}
+		}
+		return contents;
+	}
+
 }