diff --git a/app/res/menu/file_view.xml b/app/res/menu/file_view.xml index 2c7183d7d..77a347562 100644 --- a/app/res/menu/file_view.xml +++ b/app/res/menu/file_view.xml @@ -1,5 +1,4 @@ - - + xmlns:app="http://schemas.android.com/apk/res-auto"> - - - + + + + \ No newline at end of file diff --git a/app/res/values/strings.xml b/app/res/values/strings.xml index afb0b9dbf..53d88a78e 100644 --- a/app/res/values/strings.xml +++ b/app/res/values/strings.xml @@ -288,6 +288,7 @@ Render markdown Copy hash Copied to clipboard + Open in Browser Open navigation drawer diff --git a/app/src/main/java/com/github/mobile/ui/ref/BranchFileViewActivity.java b/app/src/main/java/com/github/mobile/ui/ref/BranchFileViewActivity.java index b442a509e..2de1c36b9 100644 --- a/app/src/main/java/com/github/mobile/ui/ref/BranchFileViewActivity.java +++ b/app/src/main/java/com/github/mobile/ui/ref/BranchFileViewActivity.java @@ -37,6 +37,7 @@ import com.github.mobile.util.AvatarLoader; import com.github.mobile.util.HttpImageGetter; import com.github.mobile.util.MarkdownUtils; +import com.github.mobile.util.OpenBrowserUtils; import com.github.mobile.util.PreferenceUtils; import com.github.mobile.util.ShareUtils; import com.github.mobile.util.SourceEditor; @@ -190,6 +191,10 @@ public boolean onOptionsItemSelected(MenuItem item) { shareFile(); return true; + case R.id.m_open_in_browser: + openBrowser(); + return true; + case R.id.m_render_markdown: if (editor.isMarkdown()) { item.setTitle(R.string.render_markdown); @@ -247,6 +252,11 @@ private void shareFile() { "https://github.com/" + id + "/blob/" + branch + '/' + path)); } + private void openBrowser() { + String id = repo.generateId(); + startActivity(OpenBrowserUtils.create("https://github.com/" + id + "/blob/" + branch + '/' + path)); + } + private void loadMarkdown() { ViewUtils.setGone(loadingBar, false); ViewUtils.setGone(codeView, true); diff --git a/app/src/main/java/com/github/mobile/util/OpenBrowserUtils.java b/app/src/main/java/com/github/mobile/util/OpenBrowserUtils.java new file mode 100644 index 000000000..f6a2ec085 --- /dev/null +++ b/app/src/main/java/com/github/mobile/util/OpenBrowserUtils.java @@ -0,0 +1,34 @@ +package com.github.mobile.util; + +import android.content.Intent; +import android.net.Uri; + +/** + * Created by jaellysbales on 6/19/15. + * Utilities for opening file in browser. + */ +public class OpenBrowserUtils { + + /** + * Create intent with file URL + * + * @param url + * @return intent + */ + public static Intent create(final String url) { + String fileUrl = url; + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse(url)); + return intent; + } + + /** + * Get URL from intent + * + * @param intent + * @return url + */ + public static String getBody(final Intent intent) { + return intent != null ? intent.getStringExtra(Intent.ACTION_VIEW) : null; + } +}