Skip to content

Commit

Permalink
- Zoom feature added
Browse files Browse the repository at this point in the history
- Kotlin version updated
  • Loading branch information
smhdk committed Nov 27, 2018
1 parent 92a418c commit b8599b7
Show file tree
Hide file tree
Showing 23 changed files with 1,391 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class MainActivity : AppCompatActivity() {
.setLoadingView(R.layout.loading_view)
.setDialogStyle(R.style.DialogStyle)
.showThumbSlider(false)
.setIsZoomable(true)
.setSliderImageScaleType(ScaleType.FIT_XY)
.setSelectorIndicator(R.drawable.sample_indicator_selector)
.build()
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.2.60'
ext.kotlin_version = '1.2.71'
repositories {
google()
jcenter()
Expand Down
19 changes: 12 additions & 7 deletions library/src/main/java/com/kodmap/app/library/PopopDialogBuilder.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.kodmap.app.library

import android.annotation.SuppressLint
import android.app.Activity
import android.app.Dialog
import android.content.Context
Expand Down Expand Up @@ -39,6 +38,7 @@ class PopopDialogBuilder(private val mContext: Context) {
private var mLoadingView: View? = null
private var mDialogStyle: Int = R.style.KmPopupDialog
private var mSelectorIndicator: Int = R.drawable.indicator_selector
private var mIsZoomable: Boolean = false

private lateinit var mAdapterClickListener: AdapterClickListener
private lateinit var mDialog: Dialog
Expand All @@ -48,6 +48,11 @@ class PopopDialogBuilder(private val mContext: Context) {
private lateinit var mImagePager: KmViewPager
private lateinit var mThumbAdapter: PopupThumbAdapter

fun setIsZoomable(bool: Boolean): PopopDialogBuilder {
mIsZoomable = bool
return this
}

fun setSelectorIndicator(draw: Int): PopopDialogBuilder {
mSelectorIndicator = draw
return this
Expand Down Expand Up @@ -127,7 +132,7 @@ class PopopDialogBuilder(private val mContext: Context) {
}

private fun initTabLayout() {
val tabLayout = mDialogView.findViewById<TabLayout>(R.id.tabLayout)
val tabLayout = mDialogView.findViewById<TabLayout>(R.id.km_tab_layout)
tabLayout.visibility = View.VISIBLE
tabLayout.setupWithViewPager(mImagePager)

Expand All @@ -141,21 +146,22 @@ class PopopDialogBuilder(private val mContext: Context) {
}

private fun initHeader() {
val headerLayout = mDialogView.findViewById<RelativeLayout>(R.id.headerLayout)
val headerLayout = mDialogView.findViewById<RelativeLayout>(R.id.km_header_layout)
headerLayout.setBackgroundColor(ContextCompat.getColor(mContext, mHeaderBgColor))

val btn_close = mDialogView.findViewById<ImageView>(R.id.iv_close)
val btn_close = mDialogView.findViewById<ImageView>(R.id.km_iv_close)
btn_close.setImageDrawable(ContextCompat.getDrawable(mContext, mCloseDrawable))
btn_close.setOnClickListener {
mDialog.dismiss()
}
}

private fun initImageViewPager() {
mImagePager = mDialogView.findViewById(R.id.viewPager)
mImagePager = mDialogView.findViewById(R.id.km_view_pager)
mSliderAdapter = PopupSliderAdapter()
mSliderAdapter.setLoadingView(mLoadingView)
mSliderAdapter.setScaleType(mSliderImageScaleType)
mSliderAdapter.setIsZoomable(mIsZoomable)
mImagePager.adapter = mSliderAdapter
(mImagePager.adapter as PopupSliderAdapter).setItemList(mImageList)
mImagePager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
Expand All @@ -173,7 +179,7 @@ class PopopDialogBuilder(private val mContext: Context) {

private fun initThumbReclerView() {
mThumbAdapter = PopupThumbAdapter(mAdapterClickListener)
mRvThumb = mDialogView.findViewById(R.id.rv_thumb)
mRvThumb = mDialogView.findViewById(R.id.km_rv_thumb)
mRvThumb.visibility = View.VISIBLE
mImageList[0].isSelected = true
mThumbAdapter.setList(mImageList)
Expand Down Expand Up @@ -216,7 +222,6 @@ class PopopDialogBuilder(private val mContext: Context) {
}
}

@SuppressLint("ResourceType")
private fun createDialog() {
mDialog = Dialog(mContext, mDialogStyle)
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.kodmap.app.library.R
import com.kodmap.app.library.constant.ScaleType
import com.kodmap.app.library.model.BaseItem
import com.kodmap.app.library.ui.KmRelativeLayout
import com.kodmap.app.library.ui.KmImageView
import com.kodmap.app.library.ui.zoomableImaveView.KmZoomableImageView
import com.squareup.picasso.Callback
import com.squareup.picasso.Picasso
import java.util.*
Expand All @@ -17,6 +17,7 @@ import java.util.*
class PopupSliderAdapter : PagerAdapter() {

private var mImageScaleType: ImageView.ScaleType = ScaleType.FIT_CENTER
private var mIsZoomable: Boolean = false
lateinit var mLoadingView: View
private val itemList = ArrayList<BaseItem>()

Expand All @@ -36,7 +37,7 @@ class PopupSliderAdapter : PagerAdapter() {

override fun instantiateItem(container: ViewGroup, position: Int): Any {
val itemView = View.inflate(container.context, R.layout.item_slider, null) as KmRelativeLayout
val imageView = itemView.findViewById<KmImageView>(R.id.iv_item)
val imageView = itemView.findViewById<KmZoomableImageView>(R.id.km_iv_item_slider)

if (::mLoadingView.isInitialized) {
itemView.addLoadingLayout(mLoadingView)
Expand All @@ -45,8 +46,8 @@ class PopupSliderAdapter : PagerAdapter() {
}

imageView.scaleType = mImageScaleType
imageView.isZoomable = mIsZoomable

Picasso.get().cancelRequest(imageView)
if (itemList[position].imageUrl == null) {
Picasso.get()
.load(itemList[position].drawableId!!)
Expand Down Expand Up @@ -90,5 +91,9 @@ class PopupSliderAdapter : PagerAdapter() {
}
}

fun setIsZoomable(bool: Boolean) {
mIsZoomable = bool
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class PopupThumbAdapter(private val listener: AdapterClickListener) : ListAdapte
var target: Target

init {
iv_thumb = itemView.findViewById(R.id.iv_thumb)
gradient_view = itemView.findViewById(R.id.gradient_view)
iv_thumb = itemView.findViewById(R.id.km_iv_thumb)
gradient_view = itemView.findViewById(R.id.km_gradient_view)

target = object : Target {
override fun onPrepareLoad(placeHolderDrawable: Drawable?) {
Expand Down
14 changes: 14 additions & 0 deletions library/src/main/java/com/kodmap/app/library/constant/ZoomType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.kodmap.app.library.constant

object ZoomType {
const val DEFAULT_MAX_SCALE = 3.0f
const val DEFAULT_MID_SCALE = 1.75f
const val DEFAULT_MIN_SCALE = 1.0f
const val DEFAULT_ZOOM_DURATION = 200

const val EDGE_NONE = -1
const val EDGE_LEFT = 0
const val EDGE_RIGHT = 1
const val EDGE_BOTH = 2
const val SINGLE_TOUCH = 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ class KmImageView : ImageView {
private var isLoadingFinished = false

constructor(context: Context) : super(context) {
init(context, null)
init(null)
}

constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
init(context, attrs)
init(attrs)
}

constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) {
init(context, attrs)
init(attrs)
}

private fun init(context: Context, attrs: AttributeSet?) {
private fun init(attrs: AttributeSet?) {
val ta: TypedArray = context.obtainStyledAttributes(attrs, R.styleable.KmImageView, 0, 0)

val loadingViewResourceId = ta.getResourceId(R.styleable.KmImageView_setLoadingView, -1)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.kodmap.app.library.ui.zoomableImaveView

import android.annotation.TargetApi
import android.os.Build.VERSION
import android.os.Build.VERSION_CODES
import android.view.View

internal object Compat {

private val SIXTY_FPS_INTERVAL = 1000 / 60

fun postOnAnimation(view: View, runnable: Runnable) {
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
postOnAnimationJellyBean(view, runnable)
} else {
view.postDelayed(runnable, SIXTY_FPS_INTERVAL.toLong())
}
}

@TargetApi(16)
private fun postOnAnimationJellyBean(view: View, runnable: Runnable) {
view.postOnAnimation(runnable)
}
}
Loading

0 comments on commit b8599b7

Please sign in to comment.