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

Feat: Headers Added in FinestWebView #195

Open
wants to merge 1 commit into
base: master
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
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -154,6 +155,7 @@ data class FinestWebView(
var encoding: String? = null,
var data: String? = null,
var url: String? = null,
var headers: HashMap<String,String>? = null
) : Serializable {

constructor(ctx: Context) : this(context = ctx)
Expand Down Expand Up @@ -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<String, String>? = null) {
this.mimeType = mimeType
this.encoding = encoding
headers?.let {
this.headers = headers
}
show(null, data)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String,String>? = null
protected var coordinatorLayout: CoordinatorLayout? = null
protected var appBar: AppBarLayout? = null
protected var toolbar: Toolbar? = null
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down