Commits

Juha Kuitunen committed b771c12

Wiki links almost working. Sometimes getting HTTP 403 Forbidden

Comments (0)

Files changed (2)

 	var links = document.getElementsByTagName("a");
 	for (i=0; i<links.length; i++) {
 		if (links[i].href.substring(0,25) == "https://api.bitbucket.org") {
-			links[i].addEventListener('click', bitbeaker.openWikiLink(links[i].href), false);
-			links[i].href="";
+			links[i].addEventListener('click', function(url){ return function() { bitbeaker.openWikiLink(url); } }(links[i].href), false);
 		}
 	}
 </script>

src/com/saibotd/bitbeaker/WikiActivity.java

 import android.widget.TextView;
 
 public class WikiActivity extends MyActivity {
-    
+
 	private String slug;
 	private String owner;
 	private String data; 
-	
+	private WebView webView;
+
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.wiki);
         ((TextView) findViewById(R.id.header_title)).setText(slug + "/wiki");
         AsyncLoader asyncLoader = new AsyncLoader();
         asyncLoader.execute("https://api.bitbucket.org/1.0/repositories/"+ owner +"/"+ slug +"/wiki/");
-    }
+
+		webView = (WebView) findViewById(R.id.wiki_webview);
+		webView.getSettings().setBuiltInZoomControls(true);
+		webView.getSettings().setUseWideViewPort(true);
+		webView.getSettings().setJavaScriptEnabled(true);
+		webView.addJavascriptInterface(new JavaScriptInterface(), "bitbeaker");
+		webView.setWebChromeClient(new WebChromeClient());
+	}
 
 	public void AsyncLoaderDone(String result) {
 		super.AsyncLoaderDone(result);
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 		}
-		WebView webView = (WebView) findViewById(R.id.wiki_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/wiki.html");
-		
+
 		webView.setWebViewClient(new WebViewClient() {
 		    public boolean shouldOverrideUrlLoading(WebView view, String url){
 		        view.loadUrl(url);
 	         return data;
 	    }
 
+		@SuppressWarnings("unused")
 		public void openWikiLink(final String url) {
-			Log.d("wiki", "javascript callback from local link in wiki is working");
+			AsyncLoader asyncLoader = new AsyncLoader();
+			asyncLoader.execute(url);
 		}
 	}
 }