Skip to content

Commit

Permalink
Kotlinize the ShimmerLibrary
Browse files Browse the repository at this point in the history
  • Loading branch information
Younes-Charfaoui committed May 9, 2019
1 parent 87c3706 commit 9b4ad6c
Show file tree
Hide file tree
Showing 9 changed files with 416 additions and 430 deletions.
6 changes: 6 additions & 0 deletions app/build.gradle
@@ -1,4 +1,6 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 27
Expand All @@ -23,4 +25,8 @@ dependencies {
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.github.bumptech.glide:glide:4.5.0'
implementation project(':shimmer')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
repositories {
mavenCentral()
}
2 changes: 2 additions & 0 deletions build.gradle
@@ -1,12 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.31'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
6 changes: 6 additions & 0 deletions shimmer/build.gradle
@@ -1,4 +1,6 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 27
Expand All @@ -22,4 +24,8 @@ android {
dependencies {
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'io.supercharge:shimmerlayout:2.1.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
repositories {
mavenCentral()
}

This file was deleted.

@@ -0,0 +1,88 @@
/**
*
* Copyright 2017 Harish Sridharan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.cooltechworks.views.shimmer

import android.graphics.drawable.Drawable
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.ViewGroup

class ShimmerAdapter : RecyclerView.Adapter<ShimmerViewHolder>() {

private var mItemCount: Int = 0
private var mLayoutReference: Int = 0
private var mShimmerAngle: Int = 0
private var mShimmerColor: Int = 0
private var mShimmerDuration: Int = 0
private var mShimmerMaskWidth: Float = 0.toFloat()
private var isAnimationReversed: Boolean = false
private var mShimmerItemBackground: Drawable? = null

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ShimmerViewHolder {
val inflater = LayoutInflater.from(parent.context)

val shimmerViewHolder = ShimmerViewHolder(inflater, parent, mLayoutReference)
shimmerViewHolder.setShimmerColor(mShimmerColor)
shimmerViewHolder.setShimmerAngle(mShimmerAngle)
shimmerViewHolder.setShimmerMaskWidth(mShimmerMaskWidth)
shimmerViewHolder.setShimmerViewHolderBackground(mShimmerItemBackground)
shimmerViewHolder.setShimmerAnimationDuration(mShimmerDuration)
shimmerViewHolder.setAnimationReversed(isAnimationReversed)

return shimmerViewHolder
}

override fun onBindViewHolder(holder: ShimmerViewHolder, position: Int) {
holder.bind()
}

override fun getItemCount() = mItemCount


fun setMinItemCount(itemCount: Int) {
mItemCount = itemCount
}

fun setShimmerAngle(shimmerAngle: Int) {
this.mShimmerAngle = shimmerAngle
}

fun setShimmerColor(shimmerColor: Int) {
this.mShimmerColor = shimmerColor
}

fun setShimmerMaskWidth(maskWidth: Float) {
this.mShimmerMaskWidth = maskWidth
}

fun setShimmerItemBackground(shimmerItemBackground: Drawable) {
this.mShimmerItemBackground = shimmerItemBackground
}

fun setShimmerDuration(mShimmerDuration: Int) {
this.mShimmerDuration = mShimmerDuration
}

fun setLayoutReference(layoutReference: Int) {
this.mLayoutReference = layoutReference
}

fun setAnimationReversed(animationReversed: Boolean) {
this.isAnimationReversed = animationReversed
}
}

0 comments on commit 9b4ad6c

Please sign in to comment.