Skip to content

Commit

Permalink
🎨 The search page uses FlexboxLayoutManager and upgrades the minimum …
Browse files Browse the repository at this point in the history
…support API to 14
  • Loading branch information
Flyge committed Jan 13, 2018
1 parent 5b10ec4 commit fbd7746
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 81 deletions.
20 changes: 8 additions & 12 deletions README.md
Expand Up @@ -5,7 +5,7 @@
[![License][license_image]][license_link]
[![Logs][logs_image]][logs_link]
[![Sketch Version][sketch_version_image]][sketch_version_link]
[![API][api_10_image]][api_10_link]
[![API][min_api_image]][min_api_link]
![QQ Group][qq_group_image]

[English version of the README.md](README_EN.md)
Expand Down Expand Up @@ -54,13 +54,11 @@ Sketch 是 Android 上一款强大且全面的图片加载器,除了图片加

### 支持的图片类型

|Image Format|Supported Version|
|:---|:---|
|jpeg|[![api_10_image]][api_10_link]|
|png|[![api_10_image]][api_10_link]|
|gif|[![api_10_image]][api_10_link]|
|bmp|[![api_10_image]][api_10_link]|
|webp|[![api_14_image]][api_14_link]|
* jpeg
* png
* gif
* bmp
* webp

### 开始使用

Expand Down Expand Up @@ -204,10 +202,8 @@ sketchImageView.displayImage("http://t.cn/RShdS1f");
[sketch_version_link]: https://bintray.com/panpf/maven/sketch/_latestVersion#files
[sketch_gif_version_image]: https://img.shields.io/github/release/panpf/sketch.svg?label=JCenter&colorB=4AC41C
[sketch_gif_version_link]: https://bintray.com/panpf/maven/sketch-gif/_latestVersion#files
[api_10_image]: https://img.shields.io/badge/API-10%2B-orange.svg
[api_10_link]: https://android-arsenal.com/api?level=10
[api_14_image]: https://img.shields.io/badge/API-14%2B-blue.svg
[api_14_link]: https://android-arsenal.com/api?level=14
[min_api_image]: https://img.shields.io/badge/API-14%2B-orange.svg
[min_api_link]: https://android-arsenal.com/api?level=14
[email_image]: https://img.shields.io/badge/Email-sky@panpf.me-red.svg

[sample_app_download_qrcode]: docs/sketch-sample.png
Expand Down
20 changes: 8 additions & 12 deletions README_EN.md
Expand Up @@ -5,7 +5,7 @@
[![License][license_image]][license_link]
[![Logs][logs_image]][logs_link]
[![Version][sketch_version_image]][sketch_version_link]
[![API][api_10_image]][api_10_link]
[![API][min_api_image]][min_api_link]
![QQ Group][qq_group_image]

[中文版本 README.md](README.md)
Expand Down Expand Up @@ -54,13 +54,11 @@ Please refer to the details [URI type and usage guide][uri]

### Supported Image Format

|Image Format|Supported Version|
|:---|:---|
|jpeg|[![api_10_image]][api_10_link]|
|png|[![api_10_image]][api_10_link]|
|gif|[![api_10_image]][api_10_link]|
|bmp|[![api_10_image]][api_10_link]|
|webp|[![api_14_image]][api_14_link]|
* jpeg
* png
* gif
* bmp
* webp

### Getting Started

Expand Down Expand Up @@ -204,10 +202,8 @@ More:
[sketch_version_link]: https://bintray.com/panpf/maven/sketch/_latestVersion#files
[sketch_gif_version_image]: https://img.shields.io/github/release/panpf/sketch.svg?label=JCenter&colorB=4AC41C
[sketch_gif_version_link]: https://bintray.com/panpf/maven/sketch-gif/_latestVersion#files
[api_10_image]: https://img.shields.io/badge/API-10%2B-orange.svg
[api_10_link]: https://android-arsenal.com/api?level=10
[api_14_image]: https://img.shields.io/badge/API-14%2B-blue.svg
[api_14_link]: https://android-arsenal.com/api?level=14
[min_api_image]: https://img.shields.io/badge/API-14%2B-orange.svg
[min_api_link]: https://android-arsenal.com/api?level=14
[email_image]: https://img.shields.io/badge/Email-sky@panpf.me-red.svg

[sample_app_download_qrcode]: docs/sketch-sample.png
Expand Down
6 changes: 5 additions & 1 deletion docs/logs/log_2.6.1.md
@@ -1,2 +1,6 @@
bug:
* Fix StatFs Invalid path exception
* Fix StatFs Invalid path exception
* 修复当一个已经乘坐上了顺风车的请求取消后,依然还会运行的 bug


最低支持 API 升至 14
5 changes: 3 additions & 2 deletions gradle.properties
Expand Up @@ -18,7 +18,7 @@
# org.gradle.parallel=true

COMPILE_SDK_VERSION=25
MIN_SDK_VERSION=10
MIN_SDK_VERSION=14
TARGET_SDK_VERSION=22

VERSION_CODE=2610
Expand All @@ -31,4 +31,5 @@ PAGER_SLIDING_TAB_STRIP_VERSION=1.7.1
FFMPEG_MEDIA_METADATA_RETRIEVER_VERSION=1.0.14
EVENT_BUS_VERSION=3.0.0
RETROFIT_VERSION=2.3.0
LEAK_CANARY_ANDROID_VERSION=1.5
LEAK_CANARY_ANDROID_VERSION=1.5
FLEXBOX=0.3.2
2 changes: 2 additions & 0 deletions sample/build.gradle
Expand Up @@ -91,6 +91,8 @@ dependencies {

implementation "com.squareup.retrofit2:retrofit:${RETROFIT_VERSION}"
implementation "com.squareup.retrofit2:converter-gson:${RETROFIT_VERSION}"

implementation "com.google.android:flexbox:${FLEXBOX}"
}

repositories {
Expand Down
Expand Up @@ -24,6 +24,7 @@ import android.view.MotionEvent
import android.view.View
import me.panpf.sketch.sample.*
import me.panpf.sketch.sample.fragment.ImageDetailFragment
import me.panpf.sketch.sample.kotlinextends.isPortraitOrientation
import me.panpf.sketch.sample.util.DeviceUtils
import me.panpf.sketch.sample.widget.SampleImageView

Expand All @@ -45,7 +46,12 @@ class ImageDetailActivity : BaseActivity(), PageBackgApplyCallback {
// + DeviceUtils.getNavigationBarHeightByUiVisibility(this) 是为了兼容 MIX 2
backgroundImageView.layoutParams?.let {
it.width = resources.displayMetrics.widthPixels
it.height = resources.displayMetrics.heightPixels + DeviceUtils.getWindowHeightSupplement(this)
it.height = resources.displayMetrics.heightPixels
if (isPortraitOrientation()) {
it.height += DeviceUtils.getWindowHeightSupplement(this)
} else {
it.width += DeviceUtils.getWindowHeightSupplement(this)
}
backgroundImageView.layoutParams = it
}

Expand Down
Expand Up @@ -35,6 +35,8 @@ import android.util.TypedValue
import android.view.*
import android.widget.TextView
import android.widget.Toast
import me.panpf.sketch.SLog
import me.panpf.sketch.Sketch
import me.panpf.sketch.sample.*
import me.panpf.sketch.sample.adapter.itemfactory.CheckMenuItemFactory
import me.panpf.sketch.sample.adapter.itemfactory.InfoMenuItemFactory
Expand All @@ -44,16 +46,15 @@ import me.panpf.sketch.sample.bean.CheckMenu
import me.panpf.sketch.sample.bean.InfoMenu
import me.panpf.sketch.sample.event.CacheCleanEvent
import me.panpf.sketch.sample.fragment.*
import me.panpf.sketch.sample.kotlinextends.isPortraitOrientation
import me.panpf.sketch.sample.util.AnimationUtils
import me.panpf.sketch.sample.util.AppConfig
import me.panpf.sketch.sample.util.DeviceUtils
import me.panpf.sketch.sample.util.ImageOrientationCorrectTestFileGenerator
import me.panpf.sketch.sample.widget.SampleImageView
import me.panpf.sketch.util.SketchUtils
import me.xiaopan.assemblyadapter.AssemblyRecyclerAdapter
import me.xiaopan.psts.PagerSlidingTabStrip
import me.panpf.sketch.SLog
import me.panpf.sketch.Sketch
import me.panpf.sketch.util.SketchUtils
import org.greenrobot.eventbus.EventBus
import java.lang.ref.WeakReference
import java.util.*
Expand Down Expand Up @@ -91,7 +92,12 @@ class MainActivity : BaseActivity(), AppListFragment.GetAppListTagStripListener,
// + DeviceUtils.getNavigationBarHeightByUiVisibility(this) 是为了兼容 MIX 2
backgroundImageView.layoutParams?.let {
it.width = resources.displayMetrics.widthPixels
it.height = resources.displayMetrics.heightPixels + DeviceUtils.getWindowHeightSupplement(this)
it.height = resources.displayMetrics.heightPixels
if (isPortraitOrientation()) {
it.height += DeviceUtils.getWindowHeightSupplement(this)
} else {
it.width += DeviceUtils.getWindowHeightSupplement(this)
}
backgroundImageView.layoutParams = it
}

Expand All @@ -100,7 +106,12 @@ class MainActivity : BaseActivity(), AppListFragment.GetAppListTagStripListener,
// + DeviceUtils.getNavigationBarHeightByUiVisibility(this) 是为了兼容 MIX 2
menuBackgroundImageView.layoutParams?.let {
it.width = resources.displayMetrics.widthPixels
it.height = resources.displayMetrics.heightPixels + DeviceUtils.getWindowHeightSupplement(this)
it.height = resources.displayMetrics.heightPixels
if (isPortraitOrientation()) {
it.height += DeviceUtils.getWindowHeightSupplement(this)
} else {
it.width += DeviceUtils.getWindowHeightSupplement(this)
}
menuBackgroundImageView.layoutParams = it
}

Expand Down Expand Up @@ -153,7 +164,7 @@ class MainActivity : BaseActivity(), AppListFragment.GetAppListTagStripListener,
private fun initData() {
val adapter = AssemblyRecyclerAdapter(makeMenuList())
adapter.addItemFactory(MenuTitleItemFactory())
adapter.addItemFactory(PageMenuItemFactory(object : PageMenuItemFactory.OnClickItemListener{
adapter.addItemFactory(PageMenuItemFactory(object : PageMenuItemFactory.OnClickItemListener {
override fun onClickItem(page: Page) {
switchPage(page)
}
Expand Down
Expand Up @@ -3,17 +3,17 @@ package me.panpf.sketch.sample.adapter.itemfactory
import android.content.Context
import android.view.View
import android.view.ViewGroup
import me.xiaopan.assemblyadapter.AssemblyRecyclerItem
import me.xiaopan.assemblyadapter.AssemblyRecyclerItemFactory
import me.panpf.sketch.util.SketchUtils
import com.google.android.flexbox.FlexboxLayoutManager
import me.panpf.sketch.sample.ImageOptions
import me.panpf.sketch.sample.R
import me.panpf.sketch.sample.bean.BaiduImage
import me.panpf.sketch.sample.bindView
import me.panpf.sketch.sample.kotlinextends.isPortraitOrientation
import me.panpf.sketch.sample.widget.SampleImageView
import me.xiaopan.assemblyadapter.AssemblyRecyclerItem
import me.xiaopan.assemblyadapter.AssemblyRecyclerItemFactory

class StaggeredImageItemFactory(private val onItemClickListener: OnItemClickListener?) : AssemblyRecyclerItemFactory<StaggeredImageItemFactory.StaggeredImageItem>() {
private var itemWidth: Int = 0

override fun isTarget(o: Any): Boolean {
return o is BaiduImage
Expand All @@ -37,17 +37,18 @@ class StaggeredImageItemFactory(private val onItemClickListener: OnItemClickList
imageView.setOptions(ImageOptions.RECT)

imageView.page = SampleImageView.Page.SEARCH_LIST
}

override fun onSetData(i: Int, image: BaiduImage) {
if (itemWidth == 0) {
val screenWidth = imageView.context.resources.displayMetrics.widthPixels
itemWidth = (screenWidth - SketchUtils.dp2px(imageView.context, 4) * 3) / 2
imageView.layoutParams?.let {
if (it is FlexboxLayoutManager.LayoutParams) {
it.flexGrow = 1.0f
}
}
}

override fun onSetData(i: Int, image: BaiduImage) {
imageView.layoutParams?.let {
it.width = itemWidth
it.height = (itemWidth / (image.width / image.height.toFloat())).toInt()
it.height = imageView.context.resources.displayMetrics.heightPixels / (if (imageView.context.isPortraitOrientation()) 5 else 2)
it.width = (it.height / (image.height / image.width.toFloat())).toInt()
imageView.layoutParams = it
}

Expand Down
@@ -1,5 +1,6 @@
package me.panpf.sketch.sample.adapter.itemfactory

import android.app.Activity
import android.content.Context
import android.view.View
import android.view.ViewGroup
Expand All @@ -8,11 +9,15 @@ import me.panpf.sketch.sample.ImageOptions
import me.panpf.sketch.sample.R
import me.panpf.sketch.sample.bean.UnsplashImage
import me.panpf.sketch.sample.bindView
import me.panpf.sketch.sample.kotlinextends.isPortraitOrientation
import me.panpf.sketch.sample.util.DeviceUtils
import me.panpf.sketch.sample.widget.SampleImageView
import me.xiaopan.assemblyadapter.AssemblyRecyclerItem
import me.xiaopan.assemblyadapter.AssemblyRecyclerItemFactory

class UnsplashPhotosItemFactory(private val unsplashPhotosItemEventListener: UnsplashPhotosItemEventListener?) : AssemblyRecyclerItemFactory<UnsplashPhotosItemFactory.UnsplashPhotosItem>() {
class UnsplashPhotosItemFactory(private val activity: Activity,
private val unsplashPhotosItemEventListener: UnsplashPhotosItemEventListener?)
: AssemblyRecyclerItemFactory<UnsplashPhotosItemFactory.UnsplashPhotosItem>() {

override fun isTarget(o: Any): Boolean {
return o is UnsplashImage
Expand Down Expand Up @@ -57,13 +62,19 @@ class UnsplashPhotosItemFactory(private val unsplashPhotosItemEventListener: Uns

imageView.layoutParams?.let {
it.width = itemWidth
it.height = (itemWidth / (image.width / image.height.toFloat())).toInt()
if (!imageView.context.isPortraitOrientation()) {
it.width += DeviceUtils.getWindowHeightSupplement(activity)
}
it.height = (it.width / (image.width / image.height.toFloat())).toInt()
imageView.layoutParams = it
}

rootViewGroup.layoutParams?.let {
it.width = itemWidth
it.height = (itemWidth / (image.width / image.height.toFloat())).toInt()
if (!imageView.context.isPortraitOrientation()) {
it.width += DeviceUtils.getWindowHeightSupplement(activity)
}
it.height = (it.width / (image.width / image.height.toFloat())).toInt()
rootViewGroup.layoutParams = it
}

Expand Down
Expand Up @@ -15,32 +15,32 @@ import android.widget.ImageView
import android.widget.Toast
import me.panpf.sketch.Sketch
import me.panpf.sketch.datasource.DataSource
import me.panpf.sketch.display.FadeInImageDisplayer
import me.panpf.sketch.decode.ImageAttrs
import me.panpf.sketch.display.FadeInImageDisplayer
import me.panpf.sketch.drawable.SketchDrawable
import me.panpf.sketch.drawable.SketchGifDrawable
import me.panpf.sketch.drawable.SketchRefBitmap
import me.panpf.sketch.request.*
import me.panpf.sketch.state.MemoryCacheStateImage
import me.panpf.sketch.uri.FileUriModel
import me.panpf.sketch.uri.GetDataSourceException
import me.panpf.sketch.uri.UriModel
import me.panpf.sketch.util.SketchUtils
import me.panpf.sketch.zoom.ImageZoomer
import me.panpf.sketch.zoom.Size
import me.panpf.sketch.sample.BaseFragment
import me.panpf.sketch.sample.BindContentView
import me.panpf.sketch.sample.R
import me.panpf.sketch.sample.activity.PageBackgApplyCallback
import me.panpf.sketch.sample.bean.Image
import me.panpf.sketch.sample.bindView
import me.panpf.sketch.sample.event.AppConfigChangedEvent
import me.panpf.sketch.sample.util.AppConfig
import me.panpf.sketch.sample.util.ApplyWallpaperAsyncTask
import me.panpf.sketch.sample.util.SaveImageAsyncTask
import me.panpf.sketch.sample.widget.HintView
import me.panpf.sketch.sample.widget.MappingView
import me.panpf.sketch.sample.widget.SampleImageView
import me.panpf.sketch.sample.bindView
import me.panpf.sketch.state.MemoryCacheStateImage
import me.panpf.sketch.uri.FileUriModel
import me.panpf.sketch.uri.GetDataSourceException
import me.panpf.sketch.uri.UriModel
import me.panpf.sketch.util.SketchUtils
import me.panpf.sketch.zoom.ImageZoomer
import me.panpf.sketch.zoom.Size
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import java.io.File
Expand Down Expand Up @@ -154,21 +154,36 @@ class ImageFragment : BaseFragment() {

inner class ImageDisplayListener : DisplayListener {
override fun onStarted() {
if (view == null) {
return
}
hintView.loading(null)
}

override fun onCompleted(drawable: Drawable, imageFrom: ImageFrom, imageAttrs: ImageAttrs) {
if (view == null) {
return
}

hintView.hidden()

setWindowBackgroundHelper.onDisplayCompleted()
gifPlayFollowPageVisibleHelper.onDisplayCompleted()
}

override fun onError(cause: ErrorCause) {
if (view == null) {
return
}

hintView.hint(R.drawable.ic_error, "Image display failed", "Again", View.OnClickListener { imageView.displayImage(finalShowImageUrl) })
}

override fun onCanceled(cause: CancelCause) {
if (view == null) {
return
}

@Suppress("NON_EXHAUSTIVE_WHEN")
when (cause) {
CancelCause.PAUSE_DOWNLOAD -> hintView.hint(R.drawable.ic_error, "Pause to download new image for saving traffic", "I do not care", View.OnClickListener {
Expand All @@ -190,6 +205,10 @@ class ImageFragment : BaseFragment() {
inner class ImageDownloadProgressListener : DownloadProgressListener {

override fun onUpdateDownloadProgress(totalLength: Int, completedLength: Int) {
if (view == null) {
return
}

hintView.setProgress(totalLength, completedLength)
}
}
Expand Down

0 comments on commit fbd7746

Please sign in to comment.