Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Room Park Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vladislav Bogdashkin
Room Park Android
Commits
6dbbbb66
Commit
6dbbbb66
authored
Dec 02, 2019
by
Vladislav Bogdashkin
🎣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PicassoImageGetter
parent
9c0ec0ce
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
171 additions
and
54 deletions
+171
-54
Project.xml
.idea/codeStyles/Project.xml
+0
-3
AppComponent.kt
...ava/com/biganto/visual/roompark/di/dagger/AppComponent.kt
+3
-0
ScreenController.kt
.../roompark/presentation/screen/article/ScreenController.kt
+37
-46
ScreenDI.kt
...o/visual/roompark/presentation/screen/article/ScreenDI.kt
+3
-5
PicassoImageGetter.kt
...isual/roompark/util/view_utils/html/PicassoImageGetter.kt
+67
-0
TagHandler.kt
...iganto/visual/roompark/util/view_utils/html/TagHandler.kt
+61
-0
No files found.
.idea/codeStyles/Project.xml
View file @
6dbbbb66
<component
name=
"ProjectCodeStyleConfiguration"
>
<code_scheme
name=
"Project"
version=
"173"
>
<AndroidXmlCodeStyleSettings>
<option
name=
"ARRANGEMENT_SETTINGS_MIGRATED_TO_191"
value=
"true"
/>
</AndroidXmlCodeStyleSettings>
<JetCodeStyleSettings>
<option
name=
"CODE_STYLE_DEFAULTS"
value=
"KOTLIN_OFFICIAL"
/>
</JetCodeStyleSettings>
...
...
app/src/main/java/com/biganto/visual/roompark/di/dagger/AppComponent.kt
View file @
6dbbbb66
package
com.biganto.visual.roompark.di.dagger
import
android.app.Application
import
com.biganto.visual.androidplayer.data.repository.local.ILocalStore
import
com.biganto.visual.roompark.base.RoomParkApplication
import
com.biganto.visual.roompark.data.local.LocalStorage
...
...
@@ -57,6 +58,8 @@ interface AppComponent : AndroidInjector<RoomParkApplication>{
fun
providedb
():
IDb
fun
provideAppContext
():
Application
@Component
.
Factory
interface
Factory
{
...
...
app/src/main/java/com/biganto/visual/roompark/presentation/screen/article/ScreenController.kt
View file @
6dbbbb66
package
com.biganto.visual.roompark.presentation.screen.article
import
PicassoImageGetter
import
android.os.Build
import
android.text.Html
import
android.view.View
import
android.view.ViewGroup
import
android.widget.ImageView
import
androidx.core.graphics.drawable.toDrawable
import
androidx.core.os.bundleOf
import
androidx.core.text.HtmlCompat
import
butterknife.BindView
...
...
@@ -13,6 +14,7 @@ import com.biganto.visual.roompark.R
import
com.biganto.visual.roompark.base.RoomParkApplication
import
com.biganto.visual.roompark.base.RoomParkMainActivity
import
com.biganto.visual.roompark.conductor.BigantoBaseController
import
com.biganto.visual.roompark.util.view_utils.html.HtmlTagHandler
import
com.google.android.material.floatingactionbutton.FloatingActionButton
import
com.google.android.material.textview.MaterialTextView
import
com.squareup.picasso.Picasso
...
...
@@ -20,6 +22,7 @@ import jp.wasabeef.picasso.transformations.BlurTransformation
import
timber.log.Timber
import
javax.inject.Inject
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
*/
...
...
@@ -116,13 +119,39 @@ class ArticleScreenController :
private
fun
render
(
viewState
:
ArticleScreenViewState
.
ArticleLoaded
)
{
title
.
text
=
viewState
.
item
.
title
contentView
.
text
=
Html
.
fromHtml
(
viewState
.
item
.
htmlBody
,
HtmlCompat
.
FROM_HTML_MODE_LEGACY
,
Html
.
ImageGetter
{
url
->
Picasso
.
get
()
.
load
(
url
)
.
get
()
.
toDrawable
(
resources
!!
)
},
HtmlTa
)
val
imageGetter
=
PicassoImageGetter
(
contentView
)
val
parsedHtml
=
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
N
)
Html
.
fromHtml
(
viewState
.
item
.
htmlBody
,
HtmlCompat
.
FROM_HTML_MODE_LEGACY
,
imageGetter
// Html.ImageGetter { url ->
// val rUrl = "room-park.ru$url"
// Timber.d("trying to get image: $rUrl")
// Picasso.get()
// .load(rUrl)
// .get()
// .toDrawable(resources!!)
//// .current
// }
,
HtmlTagHandler
())
else
Html
.
fromHtml
(
viewState
.
item
.
htmlBody
,
imageGetter
// Html.ImageGetter { url ->
// val rUrl = "room-park.ru$url"
// Timber.d("trying to get image: $rUrl")
// Picasso.get()
// .load(rUrl)
// .get()
// .toDrawable(resources!!)
//// .current
// }
,
HtmlTagHandler
())
contentView
.
text
=
parsedHtml
articleDate
.
text
=
viewState
.
item
.
published
.
toString
()
Picasso
.
get
()
...
...
@@ -146,41 +175,3 @@ class ArticleScreenController :
}
public
class
HtmlTagHandler
implements
Html
.
TagHandler
{
@Override
public
void
handleTag
(
boolean
opening
,
String
tag
,
Editable
output
,
XMLReader
xmlReader
)
{
Log
.
e
(
"Tag"
,
tag
);
if
(
tag
.
startsWith
(
"b"
)
)
{
Log
.
e
(
"Tage"
,
"Code tag encountered1"
);
if
(
opening
)
{
Log
.
e
(
"Tage"
,
"Code tag encountered1"
);
output
.
setSpan
(
new
TypefaceSpan
(
"monospace"
),
output
.
length
(),
output
.
length
(),
Spannable
.
SPAN_MARK_MARK
);
}
else
{
Log
.
e
(
"Tage"
,
"Code tag encountered2"
);
Object
obj
=
getLast
(
output
,
TypefaceSpan
.
class
);
int
where
=
output
.
getSpanStart
(
obj
);
output
.
removeSpan
(
obj
);
output
.
setSpan
(
new
TypefaceSpan
(
"monospace"
),
where
,
output
.
length
(),
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
);
}
}
else
{
Log
.
e
(
"Tage"
,
"Code Exited"
);
}
}
private
Object
getLast
(
Editable
text
,
Class
kind
)
{
Object
[]
objs
=
text
.
getSpans
(
0
,
text
.
length
(),
kind
);
if
(
objs
.
length
==
0
)
{
return
null
;
}
else
{
for
(
int
i
=
objs
.
length
;
i
>
0
;
i
--)
{
if
(
text
.
getSpanFlags
(
objs
[
i
-
1
])
==
Spannable
.
SPAN_MARK_MARK
)
{
return
objs
[
i
-
1
];
}
}
return
null
;
}
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/presentation/screen/article/ScreenDI.kt
View file @
6dbbbb66
...
...
@@ -2,10 +2,8 @@ package com.biganto.visual.roompark.presentation.screen.article
import
android.content.Context
import
com.biganto.visual.roompark.base.RoomParkMainActivity
import
com.biganto.visual.roompark.data.data_provider.FeedsContractModule
import
com.biganto.visual.roompark.di.dagger.AppComponent
import
com.biganto.visual.roompark.di.dagger.PerScreen
import
com.biganto.visual.roompark.domain.contract.FeedsContract
import
dagger.Binds
import
dagger.BindsInstance
import
dagger.Component
...
...
@@ -41,7 +39,7 @@ abstract class ArticleScreenModule{
@Binds
abstract
fun
provideContext
(
activity
:
RoomParkMainActivity
):
Context
@PerScreen
@Binds
abstract
fun
provideContract
(
impl
:
FeedsContractModule
):
FeedsContract
//
@PerScreen
//
@Binds
//
abstract fun provideContract(impl: FeedsContractModule): FeedsContract
}
app/src/main/java/com/biganto/visual/roompark/util/view_utils/html/PicassoImageGetter.kt
0 → 100644
View file @
6dbbbb66
import
android.content.res.Resources
import
android.graphics.Bitmap
import
android.graphics.Canvas
import
android.graphics.drawable.BitmapDrawable
import
android.graphics.drawable.Drawable
import
android.text.Html
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
com.squareup.picasso.Target
import
kotlin.math.min
class
PicassoImageGetter
(
private
val
target
:
MaterialTextView
)
:
Html
.
ImageGetter
{
override
fun
getDrawable
(
source
:
String
):
Drawable
{
val
drawable
=
BitmapDrawablePlaceHolder
()
Picasso
.
get
()
.
load
(
"https://room-park.ru$source"
)
.
placeholder
(
R
.
drawable
.
ic_deals
)
.
into
(
drawable
)
return
drawable
}
private
inner
class
BitmapDrawablePlaceHolder
:
BitmapDrawable
(),
Target
{
protected
var
_drawable
:
Drawable
?
=
null
private
val
resources
:
Resources
=
RoomParkApplication
.
component
.
provideAppContext
().
resources
override
fun
draw
(
canvas
:
Canvas
)
{
if
(
_drawable
!=
null
)
{
_drawable
!!
.
draw
(
canvas
)
}
}
fun
setDrawable
(
drawable
:
Drawable
)
{
this
.
_drawable
=
drawable
var
width
=
drawable
.
intrinsicWidth
var
height
=
drawable
.
intrinsicHeight
target
.
let
{
val
aspect
=
it
.
measuredWidthAndState
.
toFloat
()/
width
.
toFloat
()
height
=
(
height
*
min
(
aspect
,
1.0f
)).
toInt
()
width
=
min
(
width
,
it
.
measuredWidthAndState
)
drawable
.
setBounds
(
0
,
0
,
width
,
height
)
setBounds
(
0
,
0
,
width
,
height
)
it
.
text
=
it
.
text
}
}
override
fun
onBitmapLoaded
(
bitmap
:
Bitmap
,
from
:
Picasso
.
LoadedFrom
)
{
setDrawable
(
BitmapDrawable
(
resources
,
bitmap
))
}
override
fun
onBitmapFailed
(
e
:
Exception
?,
errorDrawable
:
Drawable
?)
{}
override
fun
onPrepareLoad
(
placeHolderDrawable
:
Drawable
)
{
}
}
}
\ No newline at end of file
app/src/main/java/com/biganto/visual/roompark/util/view_utils/html/TagHandler.kt
0 → 100644
View file @
6dbbbb66
package
com.biganto.visual.roompark.util.view_utils.html
import
android.text.Editable
import
android.text.Html
import
android.text.Spannable
import
android.text.Spanned
import
android.text.style.TypefaceSpan
import
org.xml.sax.XMLReader
import
timber.log.Timber
/**
* Created by Vladislav Bogdashkin on 02.12.2019.
*/
class
HtmlTagHandler
:
Html
.
TagHandler
{
override
fun
handleTag
(
opening
:
Boolean
,
tag
:
String
,
output
:
Editable
,
xmlReader
:
XMLReader
)
{
Timber
.
e
(
tag
,
"Tag"
)
if
(
tag
.
startsWith
(
"b"
))
{
Timber
.
d
(
"Code tag encountered1"
)
if
(
opening
)
{
Timber
.
d
(
"Code tag encountered1"
)
output
.
setSpan
(
TypefaceSpan
(
"monospace"
),
output
.
length
,
output
.
length
,
Spannable
.
SPAN_MARK_MARK
)
}
else
{
Timber
.
d
(
"Code tag encountered2"
)
val
obj
=
getLast
(
output
,
TypefaceSpan
::
class
.
java
)
val
where
=
output
.
getSpanStart
(
obj
)
output
.
removeSpan
(
obj
)
output
.
setSpan
(
TypefaceSpan
(
"monospace"
),
where
,
output
.
length
,
Spanned
.
SPAN_EXCLUSIVE_EXCLUSIVE
)
}
}
else
{
Timber
.
d
(
"Code Exited"
)
}
}
private
fun
getLast
(
text
:
Editable
,
kind
:
Class
<
*
>):
Any
?
{
val
objs
=
text
.
getSpans
(
0
,
text
.
length
,
kind
)
if
(
objs
.
isEmpty
())
{
return
null
}
else
{
for
(
i
in
objs
.
size
downTo
1
)
{
if
(
text
.
getSpanFlags
(
objs
[
i
-
1
])
==
Spannable
.
SPAN_MARK_MARK
)
{
return
objs
[
i
-
1
]
}
}
return
null
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment