Commit 0aca8f0a authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

floating close button least

parent 198311a2
package com.biganto.visual.roompark.presentation.screen.article
import android.os.Bundle
import android.text.Html
import android.view.View
import android.view.ViewGroup
import android.webkit.WebView
import android.widget.ImageView
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.LinearLayoutManager
......@@ -111,34 +111,21 @@ class ArticleScreenController :
}
private fun render(viewState: ArticleScreenViewState.ArticleLoaded) {
title.text = viewState.item.title
// val imageGetter = PicassoImageGetter()
val _escaped = Html.escapeHtml(viewState.item.htmlBody)
val charset = Charsets.UTF_8
val reg = "<img\\b(?=\\s)(?=(?:[^>=]|='[^']*'|=\"[^\"]*\"|=[^'\"][^\\s>]*)*?\\ssrc=['\"]([^\"]*)['\"]?)(?:[^>=]|='[^']*'|=\"[^\"]*\"|=[^'\"\\s]*)*\"\\s?\\/?>"
.toRegex()
val _esc =_escaped.toByteArray(charset).contentToString()
val z = viewState.item.htmlBody.replace("<\\br>","\n")
val z = viewState.item.htmlBody
.replace("<\\br>","\n")
.replace("<br>","\n")
.replace("</br>","\n").toString()
Timber.d(" escaped lines: ${z}")
val tags = z.lines().map{
val r = reg.matchEntire(it)?.groupValues?.last()
Timber.d("matched: $r")
val result = if (r == null) HtmlTag.Text(it)
else HtmlTag.ImageSource(r)
Timber.d(" result: ${result}")
result
.replace("</br>","\n")
.replace("<p>","")
.replace("</p>","")
val tags = z.lines().map {
if (it.startsWith("<img"))
HtmlTag.ImageSource(it.substringAfter("src=\"").substringBefore("\""))
else HtmlTag.Text(it)
}.toList()
(articleRecyclerView.adapter as HtmlPageAdapter).setItems(tags)
......
......@@ -7,9 +7,8 @@ import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import butterknife.ButterKnife
import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.RoomParkApplication
import com.google.android.material.textview.MaterialTextView
import com.squareup.picasso.Picasso
import timber.log.Timber
/**
* Created by Vladislav Bogdashkin on 29.01.2020.
......@@ -22,11 +21,8 @@ sealed class HtmlTag {
class ImageSource(val src:String):HtmlTag()
}
class HtmlPageAdapter : RecyclerView.Adapter<HtmlTagViewHolder<HtmlTag>>() {
private val list = mutableListOf<HtmlTag>()
override fun getItemViewType(position: Int): Int {
......@@ -37,7 +33,7 @@ class HtmlPageAdapter : RecyclerView.Adapter<HtmlTagViewHolder<HtmlTag>>() {
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HtmlTagViewHolder<HtmlTag> {
val ret = when (HtmlViewType.fromInt(viewType)) {
return when (HtmlViewType.fromInt(viewType)) {
HtmlViewType.TEXT ->
HtmlTextViewHolder(
LayoutInflater.from(parent.context)
......@@ -49,15 +45,9 @@ class HtmlPageAdapter : RecyclerView.Adapter<HtmlTagViewHolder<HtmlTag>>() {
.inflate(R.layout.htlm_image_viewholder, parent, false)
) as HtmlTagViewHolder<HtmlTag>
}
return ret
}
override fun onBindViewHolder(holder: HtmlTagViewHolder<HtmlTag>, position: Int) {
Timber.d(list[position].toString())
Timber.d(" holder: ${holder::class} - list: ${list[position]::class}")
Timber.d("position - $position")
holder.bindModel(list[position])
}
......@@ -81,7 +71,6 @@ abstract class HtmlTagViewHolder<M:HtmlTag>(itemView: View) : RecyclerView.ViewH
onViewBound(model)
}
protected lateinit var bindedModel: M
}
......@@ -95,14 +84,19 @@ class HtmlTextViewHolder(itemView: View) : HtmlTagViewHolder<HtmlTag.Text>(itemV
class HtmlImageViewHolder(itemView: View) :HtmlTagViewHolder<HtmlTag.ImageSource>(itemView) {
private val picassoAsync by lazy {
return@lazy RoomParkApplication.component.providePicassoAsync()
}
override fun onViewBound(model: HtmlTag.ImageSource) {
Picasso.get().load(
"https://room-park.ru${model.src}"
)
val url = "https://room-park.ru${model.src}"
picassoAsync
.load(url)
.into(itemView as ImageView)
}
}
private enum class HtmlViewType(val viewType:Int){
TEXT(0),
......
......@@ -18,8 +18,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/feed_title_info_text_view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_favorites" />
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
......
......@@ -13,12 +13,10 @@
android:layout_height="60dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="@color/colorAccentSecondary"
app:image_corner_radius="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_favorites" />
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
......
......@@ -14,12 +14,10 @@
android:layout_height="60dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="@color/colorAccentSecondary"
app:image_corner_radius="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_favorites" />
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
......
<?xml version="1.0" encoding="utf-8"?>
<com.biganto.visual.roompark.util.view_utils.image_view.RoundedImageView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:adjustViewBounds="true"
android:scaleType="fitStart"
app:image_corner_radius="4dp" />
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.textview.MaterialTextView
xmlns:android="http://schemas.android.com/apk/res/android"
<com.google.android.material.textview.MaterialTextView xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/Default_HtmlView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Default_TextView.Header_Text"
android:minHeight="16dp"
/>
\ No newline at end of file
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:minHeight="16dp" />
\ No newline at end of file
......@@ -287,8 +287,13 @@
<item name="android:textColor">@color/colorAccent</item>
</style>
<style name="Default_HtmlView" parent="Base.Widget.AppCompat.TextView.AcromRegularTextView">
<item name="android:textSize">@dimen/accent_header</item>
</style>
<style name="Default_TextView" parent="Base.Widget.AppCompat.TextView.AcromMediumTextView">
<item name="android:textSize">@dimen/accent_header</item>
<item name="android:textColor">@color/colorHeaderText</item>
</style>
<style name="Default_TextView.Accent_Text">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment