SlideShare a Scribd company logo
Glide usage tips
2018/12/10 LINE Developer Meetup #47 in Fukuoka
LINE Fukuoka
Kelvin Ko
About me
• Kelvin Ko (from Hong Kong)
• Software Engineer @ LINE Fukuoka
• Project: LINE Client (Android)
Outline
• Passing correct context
• Preload image in recycler view
• How to use custom model
• How to do overlay image
Tips 1: Passing context
What is
• Glide is a image loading library for Android.
• Basic usage:
Passing correct scope of context
is important!
Glide will clear automatically base on
lifecycle of given context
So, don’t just pass ApplicationContext
Try to pass closer context
Tips 2: Pre-load in recycler view
Using RecyclerViewPreloader
• RecyclerViewPreloader
• can automatically load images just ahead of where a
user is scrolling in a RecyclerView.
• Available in “recycler-integration” library
Setup RecyclerViewPreloader
1. Create PreloadSizeProvider
2. Create PreloadModelProvider
3. Create RecyclerViewPreloader with
PreloadSizeProvider and PreloadModelProvider
4. Add RecyclerViewPreloader to RecyclerView as
scroll listener
1. Size Provider
• PreloadSizeProvider provide size of the image Glide
should load.
• If all target image view in recycler view is same size, can
use FixedPreloadSizeProvider
2. Model Provider
• PreloadModelProvider provide list of models for glide to
preload (Like in adapter provide data for recycler view to
display on bind view)
If current adapter like this:
3. Add onScrollListener
• Create preloader with previous components
• Attach preloader on scroll listener
• Now, it will preload image base on scroll direction
Tips 3: You can you use your
own model
Using custom model
Beside URL, Uri, File Path
You can create custom model to support
more model
We use custom model to display sticker
For example, a sticker data model contain sticker related information
We can display sticker with this code:
*Actual sticker display logic is more complex, this is a simplified example
Custom model
• Why use custom model?
• Custom data fetching flow
• Readability, look strict forward, right?
• How to do that?
1. Model Loader
• handles()
• Checking whether this loader can handle the input model
• buildLoadData()
• Return a Data Loader which can fetch data when cache not hit
2. Data Fetcher
• loadData()
• Implement actual data fetching logic. For example, load image from network
• getDataSource()
• Return the nature of data source, which will affect Cache strategy.
• E.g LOCAL: cache the transformed image, REMOTE: cache the original image.
3. Register Model Loader in Glide
• Implement ModelLoaderFactory
• Register the model loader in Glide
• Now, we can use our custom model in Glide!~
Tips 4: How to overlay image?
Overlay image
• Use Glide to download image as Drawable
• Supply Drawable(s) to LayerDrawable
Base Overlay
Conclusion
• Passing minimum scope of context for better memory
usage
• Use Pre-Loader in Recycler view for better UX
• Register your own model in AppGlideModule
• Can consider using LayerDrawable if you want to form an
image by multiple drawable
Thank you~!

More Related Content

PDF
The benefit of custom elements: a real use case
PDF
KAPT Annotation processing & Code generation
PDF
Website → App
PDF
Financial Project with Spring WebFlux
PDF
Browser and Cloud - The Future of IDEs?
PPTX
Entity Framework Core 1.0
PDF
Tutorial introduction to OSGi
PPT
OSGi and JavaScript - Simon Kaegi
The benefit of custom elements: a real use case
KAPT Annotation processing & Code generation
Website → App
Financial Project with Spring WebFlux
Browser and Cloud - The Future of IDEs?
Entity Framework Core 1.0
Tutorial introduction to OSGi
OSGi and JavaScript - Simon Kaegi

What's hot (20)

KEY
Portal - Lego set for app development
PPTX
Microservices: A developer's approach
PPTX
Entity Framework 7: What's New?
PPTX
Software architecture : From project management to deployment
PDF
Transforming Front-End Disaster Code™ Into A Maintainable Masterpiece
PPTX
Web Components
PDF
Pundit at 3rd DBpedia Community Meeting 2015
PPTX
SDLC, Agile methodologies and Career in Product management
PPTX
Polymer and web component
PPTX
Angular Introduction (RS)
PPTX
A practical approach on - How to design offline-online synchronization system
PPTX
iOS RESTful Library for Drupal 8
PPTX
Backbonemeetup
PPTX
Kickstart android development with xamarin
PDF
Modern web technologies
PPTX
Interface builder: Friend or foe
PPT
PDF
The shift to the edge
PDF
PolymerJS 開發實戰
PPTX
Intro to modern web technology
Portal - Lego set for app development
Microservices: A developer's approach
Entity Framework 7: What's New?
Software architecture : From project management to deployment
Transforming Front-End Disaster Code™ Into A Maintainable Masterpiece
Web Components
Pundit at 3rd DBpedia Community Meeting 2015
SDLC, Agile methodologies and Career in Product management
Polymer and web component
Angular Introduction (RS)
A practical approach on - How to design offline-online synchronization system
iOS RESTful Library for Drupal 8
Backbonemeetup
Kickstart android development with xamarin
Modern web technologies
Interface builder: Friend or foe
The shift to the edge
PolymerJS 開發實戰
Intro to modern web technology
Ad

More from LINE Corporation (20)

PDF
JJUG CCC 2018 Fall 懇親会LT
PDF
Reduce dependency on Rx with Kotlin Coroutines
PDF
Kotlin/NativeでAndroidのNativeメソッドを実装してみた
PDF
Use Kotlin scripts and Clova SDK to build your Clova extension
PDF
The Magic of LINE 購物 Testing
PPTX
GA Test Automation
PDF
UI Automation Test with JUnit5
PDF
Feature Detection for UI Testing
PDF
LINE 新星計劃介紹與新創團隊分享
PDF
​LINE 技術合作夥伴與應用分享
PDF
LINE 開發者社群經營與技術推廣
PDF
日本開發者大會短講分享
PDF
LINE Chatbot - 活動報名報到設計分享
PDF
在 LINE 私有雲中使用 Managed Kubernetes
PDF
LINE TODAY高效率的敏捷測試開發技巧
PDF
LINE 區塊鏈平台及代幣經濟 - LINK Chain及LINK介紹
PDF
LINE Things - LINE IoT平台新技術分享
PDF
LINE Pay - 一卡通支付新體驗
PDF
LINE Platform API Update - 打造一個更好的Chatbot服務
PDF
Keynote - ​LINE 的技術策略佈局與跨國產品開發
JJUG CCC 2018 Fall 懇親会LT
Reduce dependency on Rx with Kotlin Coroutines
Kotlin/NativeでAndroidのNativeメソッドを実装してみた
Use Kotlin scripts and Clova SDK to build your Clova extension
The Magic of LINE 購物 Testing
GA Test Automation
UI Automation Test with JUnit5
Feature Detection for UI Testing
LINE 新星計劃介紹與新創團隊分享
​LINE 技術合作夥伴與應用分享
LINE 開發者社群經營與技術推廣
日本開發者大會短講分享
LINE Chatbot - 活動報名報到設計分享
在 LINE 私有雲中使用 Managed Kubernetes
LINE TODAY高效率的敏捷測試開發技巧
LINE 區塊鏈平台及代幣經濟 - LINK Chain及LINK介紹
LINE Things - LINE IoT平台新技術分享
LINE Pay - 一卡通支付新體驗
LINE Platform API Update - 打造一個更好的Chatbot服務
Keynote - ​LINE 的技術策略佈局與跨國產品開發
Ad

Recently uploaded (20)

PDF
KodekX | Application Modernization Development
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Empathic Computing: Creating Shared Understanding
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Approach and Philosophy of On baking technology
PDF
cuic standard and advanced reporting.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Machine learning based COVID-19 study performance prediction
KodekX | Application Modernization Development
Unlocking AI with Model Context Protocol (MCP)
Encapsulation_ Review paper, used for researhc scholars
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Advanced methodologies resolving dimensionality complications for autism neur...
Diabetes mellitus diagnosis method based random forest with bat algorithm
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Encapsulation theory and applications.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Empathic Computing: Creating Shared Understanding
Network Security Unit 5.pdf for BCA BBA.
Building Integrated photovoltaic BIPV_UPV.pdf
Understanding_Digital_Forensics_Presentation.pptx
Approach and Philosophy of On baking technology
cuic standard and advanced reporting.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Machine learning based COVID-19 study performance prediction

Glide usage tips

  • 1. Glide usage tips 2018/12/10 LINE Developer Meetup #47 in Fukuoka LINE Fukuoka Kelvin Ko
  • 2. About me • Kelvin Ko (from Hong Kong) • Software Engineer @ LINE Fukuoka • Project: LINE Client (Android)
  • 3. Outline • Passing correct context • Preload image in recycler view • How to use custom model • How to do overlay image
  • 4. Tips 1: Passing context
  • 5. What is • Glide is a image loading library for Android. • Basic usage: Passing correct scope of context is important! Glide will clear automatically base on lifecycle of given context So, don’t just pass ApplicationContext Try to pass closer context
  • 6. Tips 2: Pre-load in recycler view
  • 7. Using RecyclerViewPreloader • RecyclerViewPreloader • can automatically load images just ahead of where a user is scrolling in a RecyclerView. • Available in “recycler-integration” library
  • 8. Setup RecyclerViewPreloader 1. Create PreloadSizeProvider 2. Create PreloadModelProvider 3. Create RecyclerViewPreloader with PreloadSizeProvider and PreloadModelProvider 4. Add RecyclerViewPreloader to RecyclerView as scroll listener
  • 9. 1. Size Provider • PreloadSizeProvider provide size of the image Glide should load. • If all target image view in recycler view is same size, can use FixedPreloadSizeProvider
  • 10. 2. Model Provider • PreloadModelProvider provide list of models for glide to preload (Like in adapter provide data for recycler view to display on bind view) If current adapter like this:
  • 11. 3. Add onScrollListener • Create preloader with previous components • Attach preloader on scroll listener • Now, it will preload image base on scroll direction
  • 12. Tips 3: You can you use your own model
  • 13. Using custom model Beside URL, Uri, File Path You can create custom model to support more model We use custom model to display sticker For example, a sticker data model contain sticker related information We can display sticker with this code: *Actual sticker display logic is more complex, this is a simplified example
  • 14. Custom model • Why use custom model? • Custom data fetching flow • Readability, look strict forward, right? • How to do that?
  • 15. 1. Model Loader • handles() • Checking whether this loader can handle the input model • buildLoadData() • Return a Data Loader which can fetch data when cache not hit
  • 16. 2. Data Fetcher • loadData() • Implement actual data fetching logic. For example, load image from network • getDataSource() • Return the nature of data source, which will affect Cache strategy. • E.g LOCAL: cache the transformed image, REMOTE: cache the original image.
  • 17. 3. Register Model Loader in Glide • Implement ModelLoaderFactory • Register the model loader in Glide • Now, we can use our custom model in Glide!~
  • 18. Tips 4: How to overlay image?
  • 19. Overlay image • Use Glide to download image as Drawable • Supply Drawable(s) to LayerDrawable Base Overlay
  • 20. Conclusion • Passing minimum scope of context for better memory usage • Use Pre-Loader in Recycler view for better UX • Register your own model in AppGlideModule • Can consider using LayerDrawable if you want to form an image by multiple drawable