Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not merge - Example code for opening Viasat Browser in a CCT or in a new Intent #104

Open
wants to merge 4 commits into
base: veranda-develop
Choose a base branch
from
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
Empty file modified app/gradlew
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package chat.rocket.android.chatrooms.ui

import android.app.AlertDialog
import android.content.Intent
import android.content.SharedPreferences
import android.net.Uri
import android.os.Bundle
import android.os.Handler
import android.util.Log
Expand Down Expand Up @@ -391,7 +393,7 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView, WebLinksView {
val title = SharedPreferenceHelper.getString("web_search_title", "Internet Search")
val description = SharedPreferenceHelper.getString("web_search_desc", "Faster web with the Viasat Browser")
val imageUrl = SharedPreferenceHelper.getString("web_search_image", "")
val link = SharedPreferenceHelper.getString("web_search_link", "https://www.google.com")
val link = SharedPreferenceHelper.getString("web_search_link", "viasat-native://newtab")

updateUI(title, text_title,
description, text_description,
Expand All @@ -400,9 +402,17 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView, WebLinksView {


web_search.setOnClickListener {
// The following line creates CCT after clicking "Internet Search", which is not what we want
// CustomTab.openCustomTab(context!!, link, WebViewFallback(), true)
startActivity(this.activity?.webViewIntent(link, if (!title.isEmpty()) title else resources.getString(R.string.url_preview_title)))
// start Viasat Browser and have it open new tab page in a custom tab
CustomTab.openCustomTab(context!!, link, WebViewFallback(), true)

// alternative: start Viasat Browser as a new intent - causes Viasat Browser
// to be the foreground app open to new tab page

//val intent = Intent(Intent.ACTION_VIEW,
//Uri.parse("viasat-native://newtab"))
//intent.setPackage("com.viasat.browser")

//startActivity(intent)
}

val linkPreviewCallback = object : LinkPreviewCallback {
Expand Down Expand Up @@ -476,4 +486,4 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView, WebLinksView {
//presenter.chatRoomsByName(name ?: "")
return true
}
}
}
6 changes: 3 additions & 3 deletions app/src/main/java/chat/rocket/android/customtab/CustomTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import chat.rocket.android.R

object CustomTab {
fun openCustomTab(context: Context, url: String, fallback: CustomTabFallback?, setBackButton: Boolean = false) {
val uri = Uri.parse(CustomTabsHelper.convertSchemeToLower(url))

val uri = Uri.parse(url)
val customTabIntentBuilder = CustomTabsIntent.Builder()
customTabIntentBuilder.setToolbarColor(ResourcesCompat.getColor(context.resources, R.color.colorPrimary, context.theme))

Expand Down Expand Up @@ -55,4 +55,4 @@ object CustomTab {
interface CustomTabFallback {
fun openUri(context: Context, uri: Uri)
}
}
}