Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.jakewharton.sdksearch.ui

import android.content.Context
import android.support.customtabs.CustomTabsIntent
import com.jakewharton.sdksearch.R

internal class CustomTabsHelper {
companion object {
fun intent(context: Context): CustomTabsIntent = builder(context).build()
fun builder(context: Context): CustomTabsIntent.Builder = CustomTabsIntent.Builder()
.setToolbarColor(context.getColor(R.color.green))
.addDefaultShareMenuItem()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,20 @@ internal class OpenDocumentationItemHandler(
override fun invoke(item: Item) {
val uri = baseUrl.resolve(item.link).toUri()
val sourceUri = androidReference.sourceUrl(item.packageName, item.className)?.toUri()
CustomTabsIntent.Builder()
.setToolbarColor(context.getColor(R.color.green))
.addDefaultShareMenuItem()
.apply {
if (sourceUri != null) {
val sourceIntent = Intent(Intent.ACTION_VIEW, sourceUri)
val pendingIntent = PendingIntent.getActivity(context, 123, sourceIntent, 0)
setActionButton(
BitmapFactory.decodeResource(context.resources, R.drawable.ic_code_black_24dp),
context.getString(R.string.view_class_source, item.className),
pendingIntent,
true)
CustomTabsHelper.builder(context).apply {
if (sourceUri != null) {
val sourceIntent = CustomTabsHelper.intent(context).intent.apply {
data = sourceUri
}
val pendingIntent = PendingIntent.getActivity(context, 123, sourceIntent, 0)
setActionButton(
BitmapFactory.decodeResource(context.resources, R.drawable.ic_code_black_24dp),
context.getString(R.string.view_class_source, item.className),
pendingIntent,
true)
}
.build()
.launchUrl(context, uri)
}
.build()
.launchUrl(context, uri)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.jakewharton.sdksearch.ui

import android.content.Context
import android.support.customtabs.CustomTabsIntent
import android.widget.Toast
import com.jakewharton.sdksearch.R
import com.jakewharton.sdksearch.store.Item
Expand All @@ -15,11 +14,7 @@ internal class OpenSourceItemHandler(
override fun invoke(item: Item) {
val url = androidReference.sourceUrl(item.packageName, item.className)
if (url != null) {
CustomTabsIntent.Builder()
.setToolbarColor(context.getColor(R.color.green))
.addDefaultShareMenuItem()
.build()
.launchUrl(context, url.toUri())
CustomTabsHelper.intent(context).launchUrl(context, url.toUri())
} else {
Toast.makeText(context, R.string.unknown_source, Toast.LENGTH_SHORT).show()
}
Expand Down