Skip to content

Commit

Permalink
v1.5.6
Browse files Browse the repository at this point in the history
amazon flavour;
hide voice search button on amazon build;
handle blocked apk downloads on amazon build;
downloads content disposition headers handling;
fixed aliexpress link in predefined shortcuts :)
  • Loading branch information
truefedex committed Aug 20, 2020
1 parent 8e7cc83 commit f8e19f0
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 133 deletions.
1 change: 1 addition & 0 deletions .idea/codeStyles/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

116 changes: 0 additions & 116 deletions .idea/codeStyles/Project.xml

This file was deleted.

1 change: 1 addition & 0 deletions .idea/modules/app/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ android {
applicationId "com.phlox.tvwebbrowser"
minSdkVersion 21
targetSdkVersion 29
versionCode 38
versionName "1.5.5"
versionCode 39
versionName "1.5.6"

javaCompileOptions {
annotationProcessorOptions {
Expand All @@ -42,7 +42,7 @@ android {
}
}

flavorDimensions "crashlytics"
flavorDimensions "crashlytics", "appstore"
productFlavors {
crashlyticsfree {
dimension "crashlytics"
Expand All @@ -51,6 +51,13 @@ android {
dimension "crashlytics"
//versionNameSuffix "-crashlytics"
}

google {
dimension "appstore"
}
amazon {
dimension "appstore"
}
}

lintOptions {
Expand Down Expand Up @@ -80,6 +87,6 @@ dependencies {
implementation 'com.github.truefedex:segmented-button:v1.0.0'
implementation 'de.halfbit:pinned-section-listview:1.0.0'

crashlyticsImplementation 'com.google.firebase:firebase-core:17.4.4'
crashlyticsImplementation 'com.google.firebase:firebase-core:17.5.0'
crashlyticsImplementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
}
1 change: 1 addition & 0 deletions app/crashlyticsAmazon/release/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/output-metadata.json
25 changes: 25 additions & 0 deletions app/src/amazon/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.phlox.tvwebbrowser">

<application
android:name=".TVBro"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/fireos_launcher_icon"
tools:replace="android:icon"
android:label="@string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:screenOrientation="sensor"
android:theme="@style/AppTheme"
tools:targetApi="m" >


<activity
android:name=".activity.main.MainActivity" />
</application>

</manifest>
Binary file added app/src/amazon/res/drawable/fireos_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/src/amazon/res/values/custom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<drawable name="splash_logo">@drawable/fireos_logo</drawable>
<drawable name="app_logo">@mipmap/fireos_launcher_icon</drawable>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/assets/pages/new-tab.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
{"title": "Amazon", "url":"https://www.amazon.com/video"},
{"title": "Deezer", "url":"https://www.deezer.com"},
{"title": "BBC", "url":"https://www.bbc.com"},
{"title": "AliExpress", "url":"https://aliexpress.comi"}];
{"title": "AliExpress", "url":"https://aliexpress.com"}];
var suggsStr = TVBro.suggestions();
suggs = JSON.parse(suggsStr);
//suggs = [{"title": "test", "url":"http://google.com"}, {"title": "test", "url":"http://googlewerqwerqwerwqerqwerdfasdfaserfwsderfwerqwerqwerwqdfasdfawsefWEFefWEFwaefAWSF.com"}, {"title": "test", "url":"http://google.com"}, {"title": "test", "url":"http://google.com"}, {"title": "test", "url":"http://google.com"}, {"title": "test", "url":"http://google.com"}, {"title": "test", "url":"http://google.com"}];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package com.phlox.tvwebbrowser.activity.downloads

import android.content.Context
import android.graphics.Color
import android.text.format.Formatter
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import android.widget.ProgressBar
import android.widget.TextView

import com.phlox.tvwebbrowser.R
import com.phlox.tvwebbrowser.model.Download
import com.phlox.tvwebbrowser.service.downloads.DownloadService

import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.Date
import java.util.*

/**
* Created by PDT on 24.01.2017.
Expand Down Expand Up @@ -70,6 +66,9 @@ class DownloadListItemView(private val downloadsActivity: DownloadsActivity, pri
}

private fun updateUI(download: Download) {
if (tvTitle?.text != download.filename) {
tvTitle?.text = download.filename
}
this.download?.size = download.size
this.download?.bytesReceived = download.bytesReceived
progressBar!!.visibility = View.INVISIBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import androidx.core.content.ContextCompat
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import com.phlox.tvwebbrowser.BuildConfig
import com.phlox.tvwebbrowser.R
import com.phlox.tvwebbrowser.TVBro
import com.phlox.tvwebbrowser.activity.downloads.DownloadsActivity
Expand Down Expand Up @@ -117,7 +118,12 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
}
})

ibVoiceSearch.setOnClickListener { initiateVoiceSearch() }
if (BuildConfig.FLAVOR_appstore == "amazon") {
ibVoiceSearch.visibility = View.GONE
ibMenu.nextFocusRightId = R.id.ibHistory
} else {
ibVoiceSearch.setOnClickListener { initiateVoiceSearch() }
}

ibHome.setOnClickListener {navigate(HOME_URL) }
ibBack.setOnClickListener { navigateBack() }
Expand Down Expand Up @@ -281,8 +287,8 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
}

override fun onAllDownloadsComplete() {
if (downloadAnimation != null) {
downloadAnimation!!.reset()
downloadAnimation?.apply {
this.reset()
ibDownloads.clearAnimation()
downloadAnimation = null
}
Expand Down Expand Up @@ -467,6 +473,18 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
}
}
}

if (BuildConfig.FLAVOR_appstore == "amazon") {
//amazon blocks some downloads, this is workaround
viewModel.logCatOutput().observe(this@MainActivity, Observer{ logMessage ->
if (logMessage.endsWith("AwContentsClientBridge: Dropping new download request.")) {
viewModel.currentTab.value?.apply {
val url = this.lastLoadingUrl ?: return@apply
onDownloadRequested(url, this)
}
}
})
}
}

private fun openInNewTab(url: String?, index: Int = 0) {
Expand Down Expand Up @@ -579,10 +597,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
}

override fun onDownloadRequested(url: String) {
val fileName = Uri.parse(url).lastPathSegment
val mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(url))
onDownloadRequested(url, tab.currentOriginalUrl ?: "", fileName
?: "url.html", tab.webView?.settings?.userAgentString ?: getString(R.string.app_name), mimeType)
onDownloadRequested(url, tab)
}

override fun onLongTap() {
Expand Down Expand Up @@ -793,6 +808,8 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
Log.d(TAG, "shouldOverrideUrlLoading url: ${request?.url}")
val url: String = request?.url.toString()

tab.lastLoadingUrl = url

if (URLUtil.isNetworkUrl(url)) {
tab.currentOriginalUrl = url
if (tabByTitleIndex(vTitles.current) == tab) {
Expand Down Expand Up @@ -888,6 +905,7 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
}

webView.setDownloadListener { url, userAgent, contentDisposition, mimetype, contentLength ->
Log.i(TAG, "DownloadListener.onDownloadStart url: $url")
onDownloadRequested(url, tab.currentOriginalUrl ?: "", DownloadUtils.guessFileName(url, contentDisposition, mimetype), userAgent
?: tab.webView?.settings?.userAgentString ?: getString(R.string.app_name), mimetype)
}
Expand All @@ -901,6 +919,15 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
return webView
}

private fun onDownloadRequested(url: String, tab: WebTabState) {
Log.i(TAG, "onDownloadRequested url: $url")
val fileName = Uri.parse(url).lastPathSegment
val mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(url))
onDownloadRequested(url, tab.currentOriginalUrl ?: "", fileName
?: "url.html", tab.webView?.settings?.userAgentString
?: getString(R.string.app_name), mimeType)
}

private fun onWebViewUpdated(tab: WebTabState) {
ibBack.isEnabled = tab.webView?.canGoBack() == true
ibForward.isEnabled = tab.webView?.canGoForward() == true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.os.Environment
import android.widget.Toast
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.liveData
import androidx.lifecycle.viewModelScope
import com.phlox.tvwebbrowser.R
import com.phlox.tvwebbrowser.TVBro
Expand Down Expand Up @@ -193,4 +194,13 @@ class MainActivityViewModel: ViewModel() {

activity.onDownloadStarted(fileName)
}

fun logCatOutput() = liveData(viewModelScope.coroutineContext + Dispatchers.IO) {
Runtime.getRuntime().exec("logcat -c")
Runtime.getRuntime().exec("logcat")
.inputStream
.bufferedReader()
.useLines { lines -> lines.forEach { line -> emit(line) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ data class WebTabState(var currentOriginalUrl: String? = null, var currentTitle:
var webChromeClient: WebChromeClient? = null
var lastSSLError: SslError? = null
var trustSsl: Boolean = false
var lastLoadingUrl: String? = null //this is last url appeared in WebViewClient.shouldOverrideUrlLoading callback

constructor(context: Context, json: JSONObject) : this() {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.phlox.tvwebbrowser.service.downloads

import android.webkit.CookieManager
import android.webkit.URLUtil

import com.phlox.tvwebbrowser.model.Download
import com.phlox.tvwebbrowser.singleton.AppDatabase
Expand Down Expand Up @@ -59,6 +60,11 @@ class DownloadTask(var downloadInfo: Download, private val userAgent: String, va
downloadInfo.size = fileLength.toLong()

input = connection.inputStream
if (connection.headerFields.containsKey("Content-Disposition")) {
val mime = connection.getHeaderField("Content-Type")
downloadInfo.filename = URLUtil.guessFileName(downloadInfo.url, connection.getHeaderField("Content-Disposition"), mime)
downloadInfo.filepath = File(File(downloadInfo.filepath).parentFile, downloadInfo.filename).absolutePath
}
output = FileOutputStream(downloadInfo.filepath)

val data = ByteArray(4096)
Expand Down

0 comments on commit f8e19f0

Please sign in to comment.