Skip to content

Commit

Permalink
[Toolbar] 🔧 No more auto-collapsed
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercandj committed Sep 12, 2018
1 parent 313b945 commit 5ed37f4
Show file tree
Hide file tree
Showing 26 changed files with 329 additions and 343 deletions.
4 changes: 2 additions & 2 deletions app/src/main/assets/dark-theme-google.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ a, .w, a.feGi6e {
}

.card:not(:empty), .mnr-c:not(:empty) {
background-color: #333333 !important;
background-color: #222222 !important;
}
.jTw2d {
background-color: #333333 !important;
background-color: #222222 !important;
}


This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.mercandalli.android.browser.ad_blocker

import android.content.Context
import android.os.AsyncTask
import android.text.TextUtils
import android.util.Log
import android.webkit.WebResourceResponse

import java.io.BufferedReader
import java.io.ByteArrayInputStream
import java.io.IOException
import java.io.InputStream
import java.io.InputStreamReader
import java.net.MalformedURLException
import java.util.HashSet

import androidx.annotation.WorkerThread

/**
* https://github.com/AmniX/AdBlockedWebView-Android
*/
object AdBlocker {

private const val AD_HOSTS_FILE = "hosts.txt"
private val AD_HOSTS = HashSet<String>()

fun init(context: Context) {
object : AsyncTask<Void, Void, Void>() {
override fun doInBackground(vararg params: Void): Void? {
try {
loadFromAssets(context)
} catch (e: IOException) {
// noop
}

return null
}
}.execute()
}

@WorkerThread
private fun loadFromAssets(context: Context) {
val stream = context.assets.open(AD_HOSTS_FILE)

val inputStreamReader = InputStreamReader(stream)
val readLines = inputStreamReader.readLines()
AD_HOSTS.addAll(readLines)
}

fun isAd(url: String): Boolean {
return try {
isAdHost(UrlUtils.getHost(url))
} catch (e: MalformedURLException) {
Log.d("AmniX", e.toString())
false
}
}

fun createEmptyResource() = WebResourceResponse(
"text/plain",
"utf-8",
ByteArrayInputStream("".toByteArray())
)

private fun isAdHost(host: String): Boolean {
if (TextUtils.isEmpty(host)) {
return false
}
val index = host.indexOf(".")
val adHost = isAdHost(host.substring(index + 1))
return index >= 0 && (AD_HOSTS.contains(host) || index + 1 < host.length && adHost)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.mercandalli.android.browser.ad_blocker

import java.net.MalformedURLException
import java.net.URL

internal object UrlUtils {

@Throws(MalformedURLException::class)
fun getHost(url: String): String {
return URL(url).host
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ import com.mercandalli.android.browser.ad_blocker.AdBlocker
import com.mercandalli.android.browser.main.MainApplication
import com.mercandalli.android.libs.monetization.MonetizationGraph


class BrowserView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : NestedScrollWebView(context, attrs, defStyleAttr),
BrowserContract.Screen {
) : WebView(context, attrs, defStyleAttr) {

private val darkThemeEncoded by lazy {
val inputStream = context.assets.open("dark-theme-google.css")
Expand Down

This file was deleted.

Loading

0 comments on commit 5ed37f4

Please sign in to comment.