diff --git a/library/src/main/java/com/thefinestartist/finestwebview/FinestWebView.kt b/library/src/main/java/com/thefinestartist/finestwebview/FinestWebView.kt index 684432a..2f4d935 100644 --- a/library/src/main/java/com/thefinestartist/finestwebview/FinestWebView.kt +++ b/library/src/main/java/com/thefinestartist/finestwebview/FinestWebView.kt @@ -19,6 +19,7 @@ import com.thefinestartist.finestwebview.listeners.BroadCastManager import com.thefinestartist.finestwebview.listeners.WebViewListener import java.io.Serializable import java.util.* +import kotlin.collections.HashMap /** Created by Leonardo on 11/21/15. */ data class FinestWebView( @@ -154,6 +155,7 @@ data class FinestWebView( var encoding: String? = null, var data: String? = null, var url: String? = null, + var headers: HashMap? = null ) : Serializable { constructor(ctx: Context) : this(context = ctx) @@ -428,9 +430,12 @@ data class FinestWebView( load(context.getString(dataRes)) } - fun load(data: String?, mimeType: String? = "text/html", encoding: String? = "UTF-8") { + fun load(data: String?, mimeType: String? = "text/html", encoding: String? = "UTF-8", headers: HashMap? = null) { this.mimeType = mimeType this.encoding = encoding + headers?.let { + this.headers = headers + } show(null, data) } diff --git a/library/src/main/java/com/thefinestartist/finestwebview/FinestWebViewActivity.kt b/library/src/main/java/com/thefinestartist/finestwebview/FinestWebViewActivity.kt index 9b5ee98..86f12c5 100644 --- a/library/src/main/java/com/thefinestartist/finestwebview/FinestWebViewActivity.kt +++ b/library/src/main/java/com/thefinestartist/finestwebview/FinestWebViewActivity.kt @@ -187,6 +187,7 @@ class FinestWebViewActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedL protected var encoding: String? = null protected var data: String? = null protected var url: String? = null + protected var headers: HashMap? = null protected var coordinatorLayout: CoordinatorLayout? = null protected var appBar: AppBarLayout? = null protected var toolbar: Toolbar? = null @@ -352,6 +353,10 @@ class FinestWebViewActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedL encoding = finestWebView.encoding data = finestWebView.data url = finestWebView.url + finestWebView.headers?.let { headerMap -> + headers = headerMap + } + } protected fun bindViews() { @@ -645,7 +650,12 @@ class FinestWebViewActivity : AppCompatActivity(), AppBarLayout.OnOffsetChangedL if (data != null) { webView!!.loadData(data!!, mimeType, encoding) } else if (url != null) { - webView!!.loadUrl(url!!) + headers?.let { headers -> + webView!!.loadUrl(url!!,headers) + }?.run { + webView!!.loadUrl(url!!) + } + } } run { // SwipeRefreshLayout