├── .github
└── workflows
│ └── android.yml
├── .gitignore
├── .travis.yml
├── LICENSE.md
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── cooltechworks
│ │ └── sample
│ │ ├── DemoActivity.kt
│ │ ├── MainActivity.kt
│ │ ├── adapters
│ │ └── CardAdapter.kt
│ │ ├── models
│ │ └── ItemCard.kt
│ │ ├── utils
│ │ ├── BaseUtils.kt
│ │ ├── DemoConfiguration.kt
│ │ └── view
│ │ │ └── CardPaddingItemDecoration.kt
│ │ └── viewholders
│ │ └── ItemHolder.kt
│ └── res
│ ├── drawable
│ ├── bg_card.xml
│ ├── bg_sharp_card.xml
│ └── gradient_background.xml
│ ├── layout
│ ├── activity_grid.xml
│ ├── activity_list.xml
│ ├── activity_main.xml
│ ├── activity_second_grid.xml
│ ├── activity_second_list.xml
│ ├── layout_demo.xml
│ ├── layout_demo_grid.xml
│ ├── layout_ecom_item.xml
│ ├── layout_news_card.xml
│ ├── layout_second_demo.xml
│ ├── layout_second_demo_grid.xml
│ └── layout_second_news_card.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── screenshots
├── grid_demo.gif
├── list_demo.gif
├── second_grid_demo.gif
└── second_list_demo.gif
├── settings.gradle
└── shimmer
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
└── main
├── AndroidManifest.xml
├── java
└── com
│ └── cooltechworks
│ └── views
│ └── shimmer
│ ├── ShimmerAdapter.kt
│ ├── ShimmerRecyclerView.kt
│ └── ShimmerViewHolder.kt
└── res
├── layout
├── layout_sample_view.xml
└── viewholder_shimmer.xml
└── values
├── attrs.xml
└── colors.xml
/.github/workflows/android.yml:
--------------------------------------------------------------------------------
1 | name: Android CI
2 |
3 | on:
4 | push:
5 | branches: [ master ]
6 | pull_request:
7 | branches: [ master ]
8 |
9 | jobs:
10 | build:
11 |
12 | runs-on: ubuntu-latest
13 |
14 | steps:
15 | - uses: actions/checkout@v2
16 | - name: set up JDK 1.8
17 | uses: actions/setup-java@v1
18 | with:
19 | java-version: 1.8
20 | - name: Build with Gradle
21 | run: ./gradlew build
22 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | .idea
4 | /local.properties
5 | /.idea/workspace.xml
6 | /.idea/libraries
7 | .DS_Store
8 | /build
9 | /captures
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 |
3 | sudo: false
4 |
5 | android:
6 | components:
7 | # Note that the tools section appears twice on purpose as it’s required to get the newest Android SDK tools.
8 | - tools
9 | - platform-tools
10 | - tools
11 | - build-tools-27.0.3
12 | - android-27
13 | - extra-android-m2repository
14 |
15 | before_install:
16 | - yes | sdkmanager "platforms;android-27" # https://github.com/travis-ci/travis-ci/issues/8651
17 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Copyright 2017 Harish Sridharan
2 |
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://android-arsenal.com/details/1/5058)
2 | [](https://travis-ci.org/sharish/ShimmerRecyclerView)
3 |
4 | # ShimmerRecyclerView
5 |
6 |
7 | Intro
8 | ------
9 |
10 | A custom recycler view with shimmer views to indicate that views are loading. The recycler view has a built-in adapter to control the shimmer appearance and provide two methods -
11 |
12 | * showShimmerAdapter() - set up a demo adapter a predefined number of child demo views.
13 | * hideShimmerAdapter() - restores your adapter to show the actual child elements.
14 |
15 |
16 | Demo Screen
17 | ------
18 |
19 | There are two kinds of shimmer animation which you can see here:
20 |
21 | 1. This type of shimmer effect uses the whole ViewHolder item to animate on.
22 |
23 | | List Demo | Grid Demo |
24 | | ---------------------------- | ----------------------------- |
25 | |
|
|
26 |
27 | 2. Here the shimmer effect only applied on for those views which background color is nontransparent.
28 |
29 | | List Demo | Grid Demo |
30 | | ---------------------------- | ----------------------------- |
31 | |
|
|
32 |
33 |
34 | ### Shimmer effect types
35 |
36 | 1. As you can see the first demo examples show that the whole ViewHolder item is animated. To achieve the desired effect, the children of the ShimmerLayout should have a nontransparent background.
37 | 2. You can achieve the second kind of shimmer effect by adding only one ViewGroup child to the ShimmerLayout with a transparent background. This ViewGroup will have the other views with nontransparent backgrounds on which the effect will be seen.
38 |
39 | You may wonder how can you add background to the root view of the ViewHolder, if you do not have direct access to the ShimmerLayout and the only child has a nontransparent background. The solution for this is to use the `shimmer_demo_view_holder_item_background` attribute.
40 |
41 | ### Attributes and Methods
42 |
43 | Following are the attributes and methods to initialise the demo views.
44 |
45 | | XML Attributes | Java Methods | Explanation |
46 | | ------------- | ------------ | ----------- |
47 | |```app:shimmer_demo_child_count``` | ```setDemoChildCount(int)``` | Integer value that sets the number of demo views should be present in shimmer adapter. |
48 | |```app:shimmer_demo_layout``` | ```setDemoLayoutReference(int)``` | Layout reference to your demo view. Define your my_demo_view.xml and refer the layout reference here. |
49 | |```app:shimmer_demo_layout_manager_type``` | ```setDemoLayoutManager(LayoutManagerType)``` | Layout manager of demo view. Can be one among linear_vertical or linear_horizontal or grid. |
50 | |```app:shimmer_demo_shimmer_color``` | ``` - ``` | Color reference or value. It can be used to change the color of the shimmer line. |
51 | |```app:shimmer_demo_angle``` | ``` - ``` | Integer value between 0 and 30 which can modify the angle of the shimmer line. The default value is zero. |
52 | |```app:shimmer_demo_mask_width``` | ``` setDemoShimmerMaskWidth(float) ``` | Float value between 0 and 1 which can modify the width of the shimmer line. The default value is 0.5. |
53 | |```app:shimmer_demo_view_holder_item_background``` | ``` - ``` | Color or an xml drawable for the ViewHolder background if you want to achieve the second type of shimmer effect. |
54 | |```app:shimmer_demo_reverse_animation``` | ``` - ``` | Defines whether the animation should be reversed. If it is true, then the animation starts from the right side of the View. Default value is false. |
55 |
56 |
57 |
58 | Usage
59 | --------
60 |
61 | Define your xml as:
62 |
63 | ```xml
64 |
75 |
76 | ```
77 | where ```@layout/layout_demo_grid``` refers to your sample layout that should be shown during loading spinner. Now on your activity onCreate, initialize the shimmer as below:
78 |
79 | ```java
80 | ShimmerRecyclerView shimmerRecycler = (ShimmerRecyclerView) findViewById(R.id.shimmer_recycler_view);
81 | shimmerRecycler.showShimmerAdapter();
82 | ```
83 |
84 | Adding to your project
85 | ------------------------
86 |
87 | - Add the following configuration in your build.gradle file.
88 |
89 | ```gradle
90 | repositories {
91 | jcenter()
92 | maven { url "https://jitpack.io" }
93 | }
94 |
95 | dependencies {
96 | implementation 'com.github.sharish:ShimmerRecyclerView:v1.3'
97 | }
98 | ```
99 |
100 | Developed By
101 | ------------
102 |
103 | * Harish Sridharan -
104 |
105 |
106 | Used libraries
107 | ----------------
108 |
109 | * ShimmerLayout: the library which achieves the shimmer effect in a memory efficient way.
110 |
111 | License
112 | --------
113 | The repo is released under following licenses
114 |
115 | Apache License for ShimmerRecycler
116 | Apache License for ShimmerLayout
117 |
118 |
119 |
120 |
121 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android-extensions'
3 | apply plugin: 'kotlin-android'
4 |
5 | android {
6 | compileSdkVersion 27
7 | buildToolsVersion "27.0.3"
8 | defaultConfig {
9 | applicationId "com.cooltechworks.sample"
10 | minSdkVersion 14
11 | targetSdkVersion 27
12 | versionCode 2
13 | versionName "1.3"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | implementation 'com.android.support:appcompat-v7:27.1.1'
25 | implementation 'com.android.support:recyclerview-v7:27.1.1'
26 | implementation 'com.github.bumptech.glide:glide:4.5.0'
27 | implementation project(':shimmer')
28 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
29 | }
30 | repositories {
31 | mavenCentral()
32 | }
33 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/sharish/SDK_HOME/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
21 |
22 |
23 |
24 |
25 |
29 |
30 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cooltechworks/sample/DemoActivity.kt:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017 Harish Sridharan
3 | *
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package com.cooltechworks.sample
21 |
22 | import android.os.Bundle
23 | import android.support.v7.app.AppCompatActivity
24 | import android.support.v7.widget.RecyclerView
25 | import com.cooltechworks.sample.adapters.CardAdapter
26 | import com.cooltechworks.sample.utils.BaseUtils
27 | import kotlinx.android.synthetic.main.activity_grid.*
28 |
29 |
30 | class DemoActivity : AppCompatActivity() {
31 |
32 | private lateinit var mAdapter: CardAdapter
33 |
34 | private val type: Int
35 | get() = intent.getIntExtra(EXTRA_TYPE, BaseUtils.TYPE_LIST)
36 |
37 | override fun onCreate(savedInstanceState: Bundle?) {
38 | super.onCreate(savedInstanceState)
39 |
40 | val type = type
41 |
42 | val layoutManager: RecyclerView.LayoutManager
43 |
44 | val demoConfiguration = BaseUtils.getDemoConfiguration(type, this)
45 | setTheme(demoConfiguration!!.styleResource)
46 | setContentView(demoConfiguration.layoutResource)
47 | layoutManager = demoConfiguration.layoutManager!!
48 | setTitle(demoConfiguration.titleResource)
49 |
50 | if (demoConfiguration.itemDecoration != null) {
51 | shimmer_recycler_view.addItemDecoration(demoConfiguration.itemDecoration)
52 | }
53 |
54 | mAdapter = CardAdapter()
55 | mAdapter.setType(type)
56 |
57 | shimmer_recycler_view.layoutManager = layoutManager
58 | shimmer_recycler_view.adapter = mAdapter
59 | shimmer_recycler_view.showShimmerAdapter()
60 |
61 | shimmer_recycler_view.postDelayed({ loadCards() }, 3000)
62 | }
63 |
64 | private fun loadCards() {
65 | val type = type
66 |
67 | mAdapter.setCards(BaseUtils.getCards(resources, type))
68 | shimmer_recycler_view.hideShimmerAdapter()
69 | }
70 |
71 | companion object {
72 | const val EXTRA_TYPE = "type"
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cooltechworks/sample/MainActivity.kt:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017 Harish Sridharan
3 | *
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package com.cooltechworks.sample
21 |
22 | import android.content.Intent
23 | import android.os.Bundle
24 | import android.support.v7.app.AppCompatActivity
25 | import android.widget.Button
26 | import com.cooltechworks.sample.utils.BaseUtils
27 | import kotlinx.android.synthetic.main.activity_main.*
28 |
29 | class MainActivity : AppCompatActivity() {
30 |
31 | override fun onCreate(savedInstanceState: Bundle?) {
32 | super.onCreate(savedInstanceState)
33 | setContentView(R.layout.activity_main)
34 |
35 | createClickListener(list_demo_button, BaseUtils.TYPE_LIST)
36 | createClickListener(grid_demo_button, BaseUtils.TYPE_GRID)
37 | createClickListener(list_second_demo_button, BaseUtils.TYPE_SECOND_LIST)
38 | createClickListener(grid_second_demo_button, BaseUtils.TYPE_SECOND_GRID)
39 | }
40 |
41 | private fun createClickListener(button: Button, demoType: Int) {
42 | button.setOnClickListener { startDemo(demoType) }
43 | }
44 |
45 | private fun startDemo(demoType: Int) {
46 | val intent = Intent(this, DemoActivity::class.java)
47 | intent.putExtra(DemoActivity.EXTRA_TYPE, demoType)
48 | startActivity(intent)
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cooltechworks/sample/adapters/CardAdapter.kt:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017 Harish Sridharan
3 | *
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | package com.cooltechworks.sample.adapters
20 |
21 | import android.support.v7.widget.RecyclerView
22 | import android.view.ViewGroup
23 | import com.cooltechworks.sample.models.ItemCard
24 | import com.cooltechworks.sample.utils.BaseUtils
25 | import com.cooltechworks.sample.viewholders.ItemHolder
26 | import java.util.*
27 |
28 | class CardAdapter : RecyclerView.Adapter() {
29 |
30 | private var mCards: List = ArrayList()
31 | private var mType = BaseUtils.TYPE_LIST
32 |
33 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
34 | return ItemHolder.newInstance(parent, mType)
35 | }
36 |
37 | override fun onBindViewHolder(holder: ItemHolder, position: Int) {
38 | holder.bind(mCards[position])
39 | }
40 |
41 | override fun getItemCount() = mCards.size
42 |
43 |
44 | fun setCards(cards: List?) {
45 | if (cards == null) {
46 | return
47 | }
48 |
49 | mCards = cards
50 | }
51 |
52 | fun setType(type: Int) {
53 | this.mType = type
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cooltechworks/sample/models/ItemCard.kt:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017 Harish Sridharan
3 | *
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | package com.cooltechworks.sample.models
20 |
21 | class ItemCard {
22 |
23 | var title: String? = null
24 | var description: String? = null
25 | var thumbnailUrl: String? = null
26 | var summaryText: String? = null
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cooltechworks/sample/utils/BaseUtils.kt:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017 Harish Sridharan
3 | *
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | package com.cooltechworks.sample.utils
20 |
21 | import android.content.Context
22 | import android.content.res.Resources
23 | import android.support.annotation.StringRes
24 | import android.support.v7.widget.GridLayoutManager
25 | import android.support.v7.widget.LinearLayoutManager
26 |
27 | import com.cooltechworks.sample.R
28 | import com.cooltechworks.sample.models.ItemCard
29 | import com.cooltechworks.sample.utils.view.CardPaddingItemDecoration
30 |
31 | import java.util.Arrays
32 |
33 | object BaseUtils {
34 |
35 | const val TYPE_LIST = 0
36 | const val TYPE_GRID = 1
37 | const val TYPE_SECOND_LIST = 2
38 | const val TYPE_SECOND_GRID = 3
39 |
40 | private fun getListCards(resources: Resources): List {
41 | val ndtvCard = createItemCard(resources, R.string.ndtv_titletext, R.string.ndtv_image_url,
42 | R.string.ndtv_subtext, R.string.ndtv_summarytext)
43 |
44 | val opCard = createItemCard(resources, R.string.op_titletext, R.string.op_image_url,
45 | R.string.op_subtext, R.string.op_summarytext)
46 |
47 | val gotCard = createItemCard(resources, R.string.got_titletext, R.string.got_image_url,
48 | R.string.got_subtext, R.string.got_summarytext)
49 |
50 | val jetCard = createItemCard(resources, R.string.jet_titletext, R.string.jet_image_url,
51 | R.string.jet_subtext, R.string.jet_summarytext)
52 |
53 | return Arrays.asList(ndtvCard, opCard, gotCard, jetCard)
54 | }
55 |
56 | private fun getGridCards(resources: Resources): List {
57 | val on7 = createItemCard(resources, R.string.on7_titletext, R.string.on7_image_url,
58 | R.string.on7_subtext, R.string.on7_summarytext)
59 |
60 | val note5 = createItemCard(resources, R.string.note5_titletext, R.string.note5_image_url,
61 | R.string.note5_subtext, R.string.note5_summarytext)
62 |
63 | val pixel = createItemCard(resources, R.string.pix_titletext, R.string.pix_image_url,
64 | R.string.pix_subtext, R.string.pix_summarytext)
65 |
66 | val iphone6 = createItemCard(resources, R.string.i6_titletext, R.string.i6_image_url,
67 | R.string.i6_subtext, R.string.i6_summarytext)
68 |
69 | val moto = createItemCard(resources, R.string.moto_titletext, R.string.moto_image_url,
70 | R.string.moto_subtext, R.string.moto_summarytext)
71 |
72 | val s7 = createItemCard(resources, R.string.s7_titletext, R.string.s7_image_url,
73 | R.string.s7_subtext, R.string.s7_summarytext)
74 |
75 | return Arrays.asList(on7, note5, pixel, iphone6, s7, moto)
76 | }
77 |
78 | fun getCards(resources: Resources, type: Int): List? {
79 | val itemCards: List?
80 |
81 | when (type) {
82 | TYPE_LIST, TYPE_SECOND_LIST -> itemCards = getListCards(resources)
83 | TYPE_GRID, TYPE_SECOND_GRID -> itemCards = getGridCards(resources)
84 | else -> itemCards = null
85 | }
86 |
87 | return itemCards
88 | }
89 |
90 | fun getDemoConfiguration(configurationType: Int, context: Context): DemoConfiguration? {
91 | val demoConfiguration: DemoConfiguration?
92 |
93 | when (configurationType) {
94 | TYPE_LIST -> {
95 | demoConfiguration = DemoConfiguration()
96 | demoConfiguration.styleResource = R.style.AppTheme
97 | demoConfiguration.layoutResource = R.layout.activity_list
98 | demoConfiguration.layoutManager = LinearLayoutManager(context)
99 | demoConfiguration.titleResource = R.string.ab_list_title
100 | }
101 | TYPE_GRID -> {
102 | demoConfiguration = DemoConfiguration()
103 | demoConfiguration.styleResource = R.style.AppThemeGrid
104 | demoConfiguration.layoutResource = R.layout.activity_grid
105 | demoConfiguration.layoutManager = GridLayoutManager(context, 2)
106 | demoConfiguration.titleResource = R.string.ab_grid_title
107 | }
108 | TYPE_SECOND_LIST -> {
109 | demoConfiguration = DemoConfiguration()
110 | demoConfiguration.styleResource = R.style.AppTheme
111 | demoConfiguration.layoutResource = R.layout.activity_second_list
112 | demoConfiguration.layoutManager = LinearLayoutManager(context)
113 | demoConfiguration.titleResource = R.string.ab_list_title
114 | demoConfiguration.itemDecoration = CardPaddingItemDecoration(context)
115 | }
116 | TYPE_SECOND_GRID -> {
117 | demoConfiguration = DemoConfiguration()
118 | demoConfiguration.styleResource = R.style.AppThemeGrid
119 | demoConfiguration.layoutResource = R.layout.activity_second_grid
120 | demoConfiguration.layoutManager = GridLayoutManager(context, 2)
121 | demoConfiguration.titleResource = R.string.ab_grid_title
122 | }
123 | else -> demoConfiguration = null
124 | }
125 |
126 | return demoConfiguration
127 | }
128 |
129 | private fun createItemCard(resources: Resources, @StringRes title: Int, @StringRes imageUrl: Int,
130 | @StringRes description: Int, @StringRes summary: Int): ItemCard {
131 | val itemCard = ItemCard()
132 |
133 | itemCard.title = resources.getString(title)
134 | itemCard.thumbnailUrl = resources.getString(imageUrl)
135 | itemCard.description = resources.getString(description)
136 | itemCard.summaryText = resources.getString(summary)
137 |
138 | return itemCard
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cooltechworks/sample/utils/DemoConfiguration.kt:
--------------------------------------------------------------------------------
1 | package com.cooltechworks.sample.utils
2 |
3 |
4 | import android.support.annotation.LayoutRes
5 | import android.support.annotation.StringRes
6 | import android.support.annotation.StyleRes
7 | import android.support.v7.widget.RecyclerView
8 |
9 | class DemoConfiguration {
10 | @StyleRes
11 | var styleResource: Int = 0
12 |
13 | @LayoutRes
14 | var layoutResource: Int = 0
15 |
16 | @StringRes
17 | var titleResource: Int = 0
18 |
19 | var layoutManager: RecyclerView.LayoutManager? = null
20 |
21 | var itemDecoration: RecyclerView.ItemDecoration? = null
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cooltechworks/sample/utils/view/CardPaddingItemDecoration.kt:
--------------------------------------------------------------------------------
1 | package com.cooltechworks.sample.utils.view
2 |
3 |
4 | import android.content.Context
5 | import android.graphics.Rect
6 | import android.support.v7.widget.RecyclerView
7 | import android.util.TypedValue
8 | import android.view.View
9 |
10 | class CardPaddingItemDecoration(context: Context) : RecyclerView.ItemDecoration() {
11 |
12 | private val paddingBetweenItems = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8f, context.resources.displayMetrics).toInt()
13 |
14 | override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State?) {
15 | outRect.set(0, 0, 0, paddingBetweenItems)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/cooltechworks/sample/viewholders/ItemHolder.kt:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017 Harish Sridharan
3 | *
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 | package com.cooltechworks.sample.viewholders
20 |
21 | import android.support.v7.widget.RecyclerView
22 | import android.view.LayoutInflater
23 | import android.view.View
24 | import android.view.ViewGroup
25 | import android.widget.ImageView
26 | import android.widget.TextView
27 |
28 | import com.bumptech.glide.Glide
29 | import com.cooltechworks.sample.R
30 | import com.cooltechworks.sample.models.ItemCard
31 |
32 | import com.cooltechworks.sample.utils.BaseUtils.TYPE_GRID
33 | import com.cooltechworks.sample.utils.BaseUtils.TYPE_LIST
34 | import com.cooltechworks.sample.utils.BaseUtils.TYPE_SECOND_GRID
35 | import com.cooltechworks.sample.utils.BaseUtils.TYPE_SECOND_LIST
36 |
37 | class ItemHolder private constructor(itemView: View) : RecyclerView.ViewHolder(itemView) {
38 |
39 | private val mTitleView: TextView = itemView.findViewById(R.id.card_title)
40 | private val mDescView: TextView = itemView.findViewById(R.id.card_subtitle)
41 | private val mThumbnailView: ImageView = itemView.findViewById(R.id.card_image)
42 | private val mSummaryView: TextView = itemView.findViewById(R.id.card_summary)
43 |
44 | fun bind(card: ItemCard) {
45 | mTitleView.text = card.title
46 | mDescView.text = card.description
47 | mSummaryView.text = card.summaryText
48 |
49 | Glide.with(itemView.context).load(card.thumbnailUrl).into(mThumbnailView)
50 | }
51 |
52 | companion object {
53 |
54 | fun newInstance(container: ViewGroup, type: Int): ItemHolder {
55 | val root = LayoutInflater.from(container.context).inflate(getLayoutResourceId(type),
56 | container, false)
57 |
58 | return ItemHolder(root)
59 | }
60 |
61 | private fun getLayoutResourceId(type: Int): Int {
62 | return when (type) {
63 | TYPE_LIST -> R.layout.layout_news_card
64 | TYPE_SECOND_LIST -> R.layout.layout_second_news_card
65 | TYPE_GRID, TYPE_SECOND_GRID -> R.layout.layout_ecom_item
66 | else -> 0
67 | }
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_card.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_sharp_card.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/gradient_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 |
22 |
23 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_grid.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 |
27 |
28 |
32 |
33 |
40 |
41 |
48 |
49 |
57 |
58 |
65 |
66 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_second_grid.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_second_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 |
29 |
30 |
38 |
39 |
45 |
46 |
52 |
53 |
60 |
61 |
68 |
69 |
76 |
77 |
84 |
85 |
92 |
93 |
99 |
100 |
101 |
102 |
110 |
111 |
112 |
113 |
120 |
121 |
128 |
129 |
136 |
137 |
144 |
145 |
146 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_demo_grid.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 |
26 |
27 |
33 |
34 |
41 |
42 |
50 |
51 |
59 |
60 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_ecom_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 |
26 |
27 |
33 |
34 |
46 |
47 |
59 |
60 |
73 |
74 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_news_card.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
31 |
32 |
36 |
37 |
42 |
43 |
53 |
54 |
65 |
66 |
67 |
68 |
74 |
75 |
76 |
77 |
88 |
89 |
90 |
91 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_second_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
21 |
22 |
28 |
29 |
36 |
37 |
44 |
45 |
52 |
53 |
60 |
61 |
68 |
69 |
75 |
76 |
77 |
78 |
85 |
86 |
87 |
88 |
95 |
96 |
103 |
104 |
111 |
112 |
119 |
120 |
121 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_second_demo_grid.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
21 |
22 |
30 |
31 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_second_news_card.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
21 |
22 |
32 |
33 |
44 |
45 |
46 |
52 |
53 |
54 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sharish/ShimmerRecyclerView/24cf1a07538bd55fa51a16c101d8bc568dd46850/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sharish/ShimmerRecyclerView/24cf1a07538bd55fa51a16c101d8bc568dd46850/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sharish/ShimmerRecyclerView/24cf1a07538bd55fa51a16c101d8bc568dd46850/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sharish/ShimmerRecyclerView/24cf1a07538bd55fa51a16c101d8bc568dd46850/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sharish/ShimmerRecyclerView/24cf1a07538bd55fa51a16c101d8bc568dd46850/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #455a64
4 | #374850
5 | #FF4081
6 |
7 | #2874f0
8 | #2368d7
9 | #388e3c
10 |
11 | #717171
12 | @color/colorAccentGrid
13 | #737373
14 |
15 | #212121
16 | #8b8b8b
17 |
18 | #24000000
19 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 | ShimmingRecyclerView
20 |
21 | List Demo
22 | Grid Demo
23 | Second List Demo
24 | Second Grid Demo
25 |
26 | Stories to read
27 | Offers Zone
28 |
29 | Who Will Ride The Third Dragon In \'Game Of Thrones\' Season 7?
30 | http://cdn.idigitaltimes.com/sites/idigitaltimes.com/files/styles/image_embed/public/2016/04/29/game-thrones-daenerys-dragon-drogon.jpg
31 | Game of Thrones season 7 will kick off a new age of Game of Thrones, with the show becoming a true epic fantasy for the first time. Don’t worry, it will remain a high political drama too, but the war between ice and fire isn’t far off now, and Daenerys Targaryen seems destined to lead the fight
32 | You\'ve shown interest in Game of Thrones series
33 |
34 | Agni 5, India\'s Longest Range Nuclear Capable Missile, Successfully Test Fired: 10 Points
35 | Agni-5, India\'s longest range nuclear capable missile, was successfully test fired from the Kalam Island off Odisha coast today by the Defence Research and Development Organisation or DRDO. The intercontinental surface-to-surface ballistic missile, the latest in India\'s \"Agni\" family of medium to intercontinental range missiles, with new technology for navigation and guidance, gives India the strategic depth it needs to contain its enemies, say scientists. Ready to be deployed, the Agni-5 will soon join India\'s military arsenal
36 | http://i.ndtvimg.com/i/2016-12/agni-5_650x400_71482721510.jpg
37 | You\'ve shown interest in Nuclear Capable Missles
38 |
39 | OnePlus releases leather case for OnePlus 3 and 3T
40 | OnePlus has released a leather case for the OnePlus 3/3T. Even though there are several cases for the OnePlus 3/3T, this one will offer a premium look for the smartphone. It has textured calfskin leather blend along with a classic matte finish making it easy to clean and also offers a comfortable grip.
41 | http://images.fonearena.com/blog/wp-content/uploads/2016/12/OnePlus-3-and-3T-leather-case-1.jpg
42 | You\'ve shown interest in One Plus
43 |
44 | Jet Airways Extends Sale, Offers Tickets Starting Rs. 990
45 | Jet Airways has extended its promotional scheme offering fares starting as low as Rs. 990 on select domestic flights under economy class travel. Under Jet Airways\' \"Best Fares Forever\" offer, tickets must be purchased till December 27, 2016, for travel on or after January 4, 2017. \"Tickets must be purchased a minimum of 15 days prior departure,\" the airline said on its website, adding that limited seats are available under the offer on a first come, first serve basis.
46 | http://i.ndtvimg.com/i/2016-11/jet-airways_650x400_51480009251.jpg
47 | You\'ve shown interest in Jet Airways
48 |
49 | Lenovo Vibe K5 Note
50 | https://rukminim1.flixcart.com/image/832/832/mobile/g/4/7/lenovo-k5-note-pa330010in-original-imaekyazjhfqveze.jpeg
51 | Exchange Offer
52 | From ₹11,999
53 |
54 | Samsung On7
55 | https://rukminim1.flixcart.com/image/832/832/mobile/c/n/y/samsung-galaxy-on7-sm-g600f-original-imaecqkgfgtmaw2y.jpeg
56 | ₹1,200 Off
57 | Now ₹8990
58 |
59 | Google Pixel | XL
60 | https://rukminim1.flixcart.com/image/832/832/mobile/6/g/7/google-pixel-m4-original-imaemzzdh3azqsqb.jpeg
61 | Exchange Offer
62 | From ₹57,000
63 |
64 | Apple iPhone6
65 | https://rukminim1.flixcart.com/image/832/832/mobile/f/2/j/apple-iphone-6-original-imaeymdqs5gm5xkz.jpeg
66 | ₹3,000 Off
67 | Now ₹33990
68 |
69 | Samsung Galaxy S7
70 | https://rukminim1.flixcart.com/image/832/832/mobile/7/n/x/samsung-galaxy-s7-na-original-imaegmjszvhghyzc.jpeg
71 | Just ₹43,000
72 | 4 GB RAM, 32 GB ROM
73 |
74 | Moto Turbo
75 | https://rukminim1.flixcart.com/image/832/832/mobile/c/v/x/motorola-moto-turbo-xt1225-original-imae5fyxgh7qy6ag.jpeg
76 | Exchange Offer
77 | Now ₹31990
78 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
17 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.3.31'
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.4'
11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sharish/ShimmerRecyclerView/24cf1a07538bd55fa51a16c101d8bc568dd46850/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Aug 13 15:09:32 AST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/screenshots/grid_demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sharish/ShimmerRecyclerView/24cf1a07538bd55fa51a16c101d8bc568dd46850/screenshots/grid_demo.gif
--------------------------------------------------------------------------------
/screenshots/list_demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sharish/ShimmerRecyclerView/24cf1a07538bd55fa51a16c101d8bc568dd46850/screenshots/list_demo.gif
--------------------------------------------------------------------------------
/screenshots/second_grid_demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sharish/ShimmerRecyclerView/24cf1a07538bd55fa51a16c101d8bc568dd46850/screenshots/second_grid_demo.gif
--------------------------------------------------------------------------------
/screenshots/second_list_demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sharish/ShimmerRecyclerView/24cf1a07538bd55fa51a16c101d8bc568dd46850/screenshots/second_list_demo.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':shimmer'
2 |
--------------------------------------------------------------------------------
/shimmer/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/shimmer/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android-extensions'
3 | apply plugin: 'kotlin-android'
4 |
5 | android {
6 | compileSdkVersion 27
7 | buildToolsVersion "27.0.3"
8 |
9 | defaultConfig {
10 | minSdkVersion 14
11 | targetSdkVersion 27
12 | versionCode 2
13 | versionName "1.3"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | implementation 'com.android.support:recyclerview-v7:27.1.1'
26 | implementation 'io.supercharge:shimmerlayout:2.1.0'
27 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
28 | }
29 | repositories {
30 | mavenCentral()
31 | }
32 |
--------------------------------------------------------------------------------
/shimmer/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/sharish/SDK_HOME/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/shimmer/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 |
--------------------------------------------------------------------------------
/shimmer/src/main/java/com/cooltechworks/views/shimmer/ShimmerAdapter.kt:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Copyright 2017 Harish Sridharan
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cooltechworks.views.shimmer
19 |
20 | import android.graphics.drawable.Drawable
21 | import android.support.v7.widget.RecyclerView
22 | import android.view.LayoutInflater
23 | import android.view.ViewGroup
24 |
25 | class ShimmerAdapter : RecyclerView.Adapter() {
26 |
27 | private var mItemCount: Int = 0
28 | private var mLayoutReference: Int = 0
29 | private var mShimmerAngle: Int = 0
30 | private var mShimmerColor: Int = 0
31 | private var mShimmerDuration: Int = 0
32 | private var mShimmerMaskWidth: Float = 0.toFloat()
33 | private var isAnimationReversed: Boolean = false
34 | private var mShimmerItemBackground: Drawable? = null
35 |
36 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ShimmerViewHolder {
37 | val inflater = LayoutInflater.from(parent.context)
38 |
39 | val shimmerViewHolder = ShimmerViewHolder(inflater, parent, mLayoutReference)
40 | shimmerViewHolder.setShimmerColor(mShimmerColor)
41 | shimmerViewHolder.setShimmerAngle(mShimmerAngle)
42 | shimmerViewHolder.setShimmerMaskWidth(mShimmerMaskWidth)
43 | shimmerViewHolder.setShimmerViewHolderBackground(mShimmerItemBackground)
44 | shimmerViewHolder.setShimmerAnimationDuration(mShimmerDuration)
45 | shimmerViewHolder.setAnimationReversed(isAnimationReversed)
46 |
47 | return shimmerViewHolder
48 | }
49 |
50 | override fun onBindViewHolder(holder: ShimmerViewHolder, position: Int) {
51 | holder.bind()
52 | }
53 |
54 | override fun getItemCount() = mItemCount
55 |
56 |
57 | fun setMinItemCount(itemCount: Int) {
58 | mItemCount = itemCount
59 | }
60 |
61 | fun setShimmerAngle(shimmerAngle: Int) {
62 | this.mShimmerAngle = shimmerAngle
63 | }
64 |
65 | fun setShimmerColor(shimmerColor: Int) {
66 | this.mShimmerColor = shimmerColor
67 | }
68 |
69 | fun setShimmerMaskWidth(maskWidth: Float) {
70 | this.mShimmerMaskWidth = maskWidth
71 | }
72 |
73 | fun setShimmerItemBackground(shimmerItemBackground: Drawable) {
74 | this.mShimmerItemBackground = shimmerItemBackground
75 | }
76 |
77 | fun setShimmerDuration(mShimmerDuration: Int) {
78 | this.mShimmerDuration = mShimmerDuration
79 | }
80 |
81 | fun setLayoutReference(layoutReference: Int) {
82 | this.mLayoutReference = layoutReference
83 | }
84 |
85 | fun setAnimationReversed(animationReversed: Boolean) {
86 | this.isAnimationReversed = animationReversed
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/shimmer/src/main/java/com/cooltechworks/views/shimmer/ShimmerRecyclerView.kt:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2017 Harish Sridharan
3 | *
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | *
13 | * Unless required by applicable law or agreed to in writing, software
14 | * distributed under the License is distributed on an "AS IS" BASIS,
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 | * See the License for the specific language governing permissions and
17 | * limitations under the License.
18 | */
19 |
20 | package com.cooltechworks.views.shimmer
21 |
22 | import android.content.Context
23 | import android.graphics.drawable.Drawable
24 | import android.os.Build
25 | import android.support.v7.widget.GridLayoutManager
26 | import android.support.v7.widget.LinearLayoutManager
27 | import android.support.v7.widget.RecyclerView
28 | import android.util.AttributeSet
29 |
30 | class ShimmerRecyclerView : RecyclerView {
31 |
32 | /**
33 | * Retrieves the actual adapter that contains the data set or null if no adapter is set.
34 | *
35 | * @return The actual adapter
36 | */
37 | var actualAdapter: RecyclerView.Adapter<*>? = null
38 | private set
39 | private var mShimmerAdapter: ShimmerAdapter? = null
40 |
41 | private var mShimmerLayoutManager: RecyclerView.LayoutManager? = null
42 | private var mActualLayoutManager: RecyclerView.LayoutManager? = null
43 | private var mLayoutMangerType: LayoutMangerType? = null
44 |
45 | private var mCanScroll: Boolean = false
46 | var layoutReference: Int = 0
47 | private set
48 | private var mGridCount: Int = 0
49 |
50 | @Suppress("unused")
51 | val shimmerAdapter: RecyclerView.Adapter<*>?
52 | get() = mShimmerAdapter
53 |
54 | enum class LayoutMangerType {
55 | LINEAR_VERTICAL, LINEAR_HORIZONTAL, GRID
56 | }
57 |
58 | constructor(context: Context) : super(context) {
59 | init(context, null)
60 | }
61 |
62 | constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
63 | init(context, attrs)
64 | }
65 |
66 | constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle) {
67 | init(context, attrs)
68 | }
69 |
70 | private fun init(context: Context, attrs: AttributeSet?) {
71 | mShimmerAdapter = ShimmerAdapter()
72 | val a = context.obtainStyledAttributes(attrs, R.styleable.ShimmerRecyclerView, 0, 0)
73 |
74 | val mShimmerAngle: Int
75 | val mShimmerColor: Int
76 | val mShimmerDuration: Int
77 | val mShimmerMaskWidth: Float
78 | val isAnimationReversed: Boolean
79 | val mShimmerItemBackground: Drawable?
80 |
81 | try {
82 | setDemoLayoutReference(a.getResourceId(R.styleable.ShimmerRecyclerView_shimmer_demo_layout, R.layout.layout_sample_view))
83 | setDemoChildCount(a.getInteger(R.styleable.ShimmerRecyclerView_shimmer_demo_child_count, 10))
84 | setGridChildCount(a.getInteger(R.styleable.ShimmerRecyclerView_shimmer_demo_grid_child_count, 2))
85 |
86 | val value = a.getInteger(R.styleable.ShimmerRecyclerView_shimmer_demo_layout_manager_type, 0)
87 | when (value) {
88 | 0 -> setDemoLayoutManager(LayoutMangerType.LINEAR_VERTICAL)
89 | 1 -> setDemoLayoutManager(LayoutMangerType.LINEAR_HORIZONTAL)
90 | 2 -> setDemoLayoutManager(LayoutMangerType.GRID)
91 | else -> throw IllegalArgumentException("This value for layout manager is not valid!")
92 | }
93 |
94 | mShimmerAngle = a.getInteger(R.styleable.ShimmerRecyclerView_shimmer_demo_angle, 0)
95 | mShimmerColor = a.getColor(R.styleable.ShimmerRecyclerView_shimmer_demo_shimmer_color, getColor(R.color.default_shimmer_color))
96 | mShimmerItemBackground = a.getDrawable(R.styleable.ShimmerRecyclerView_shimmer_demo_view_holder_item_background)
97 | mShimmerDuration = a.getInteger(R.styleable.ShimmerRecyclerView_shimmer_demo_duration, 1500)
98 | mShimmerMaskWidth = a.getFloat(R.styleable.ShimmerRecyclerView_shimmer_demo_mask_width, 0.5f)
99 | isAnimationReversed = a.getBoolean(R.styleable.ShimmerRecyclerView_shimmer_demo_reverse_animation, false)
100 | } finally {
101 | a.recycle()
102 | }
103 |
104 | mShimmerAdapter!!.setShimmerAngle(mShimmerAngle)
105 | mShimmerAdapter!!.setShimmerColor(mShimmerColor)
106 | mShimmerAdapter!!.setShimmerMaskWidth(mShimmerMaskWidth)
107 | if (mShimmerItemBackground != null)
108 | mShimmerAdapter!!.setShimmerItemBackground(mShimmerItemBackground)
109 | mShimmerAdapter!!.setShimmerDuration(mShimmerDuration)
110 | mShimmerAdapter!!.setAnimationReversed(isAnimationReversed)
111 |
112 | showShimmerAdapter()
113 | }
114 |
115 | /**
116 | * Specifies the number of child should exist in any row of the grid layout.
117 | *
118 | * @param count - count specifying the number of child.
119 | */
120 | fun setGridChildCount(count: Int) {
121 | mGridCount = count
122 | }
123 |
124 | /**
125 | * Sets the layout manager for the shimmer adapter.
126 | *
127 | * @param type layout manager reference
128 | */
129 | fun setDemoLayoutManager(type: LayoutMangerType) {
130 | mLayoutMangerType = type
131 | }
132 |
133 | /**
134 | * Sets the number of demo views should be shown in the shimmer adapter.
135 | *
136 | * @param count - number of demo views should be shown.
137 | */
138 | fun setDemoChildCount(count: Int) {
139 | mShimmerAdapter!!.setMinItemCount(count)
140 | }
141 |
142 | /**
143 | * Specifies the animation duration of shimmer layout.
144 | *
145 | * @param duration - count specifying the duration of shimmer in millisecond.
146 | */
147 | fun setDemoShimmerDuration(duration: Int) {
148 | mShimmerAdapter!!.setShimmerDuration(duration)
149 | }
150 |
151 | /**
152 | * Specifies the the width of the shimmer line.
153 | *
154 | * @param maskWidth - float specifying the width of shimmer line. The value should be from 0 to less or equal to 1.
155 | * The default value is 0.5.
156 | */
157 | fun setDemoShimmerMaskWidth(maskWidth: Float) {
158 | mShimmerAdapter!!.setShimmerMaskWidth(maskWidth)
159 | }
160 |
161 | /**
162 | * Sets the shimmer adapter and shows the loading screen.
163 | */
164 | fun showShimmerAdapter() {
165 | mCanScroll = false
166 |
167 | if (mShimmerLayoutManager == null) {
168 | initShimmerManager()
169 | }
170 |
171 | layoutManager = mShimmerLayoutManager
172 | adapter = mShimmerAdapter
173 | }
174 |
175 | /**
176 | * Hides the shimmer adapter
177 | */
178 | fun hideShimmerAdapter() {
179 | mCanScroll = true
180 | layoutManager = mActualLayoutManager
181 | adapter = actualAdapter
182 | }
183 |
184 | override fun setLayoutManager(manager: RecyclerView.LayoutManager?) {
185 | if (manager == null) {
186 | mActualLayoutManager = null
187 | } else if (manager !== mShimmerLayoutManager) {
188 | mActualLayoutManager = manager
189 | }
190 |
191 | super.setLayoutManager(manager)
192 | }
193 |
194 | override fun setAdapter(adapter: RecyclerView.Adapter<*>?) {
195 | if (adapter == null) {
196 | actualAdapter = null
197 | } else if (adapter !== mShimmerAdapter) {
198 | actualAdapter = adapter
199 | }
200 |
201 | super.setAdapter(adapter)
202 | }
203 |
204 | /**
205 | * Sets the demo layout reference
206 | *
207 | * @param mLayoutReference layout resource id of the layout which should be shown as demo.
208 | */
209 | fun setDemoLayoutReference(mLayoutReference: Int) {
210 | this.layoutReference = mLayoutReference
211 | mShimmerAdapter!!.setLayoutReference(layoutReference)
212 | }
213 |
214 | private fun initShimmerManager() {
215 | when (mLayoutMangerType) {
216 | ShimmerRecyclerView.LayoutMangerType.LINEAR_VERTICAL -> mShimmerLayoutManager = object : LinearLayoutManager(context) {
217 | override fun canScrollVertically(): Boolean {
218 | return mCanScroll
219 | }
220 | }
221 | ShimmerRecyclerView.LayoutMangerType.LINEAR_HORIZONTAL -> mShimmerLayoutManager = object : LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) {
222 | override fun canScrollHorizontally(): Boolean {
223 | return mCanScroll
224 | }
225 | }
226 | ShimmerRecyclerView.LayoutMangerType.GRID -> mShimmerLayoutManager = object : GridLayoutManager(context, mGridCount) {
227 | override fun canScrollVertically(): Boolean {
228 | return mCanScroll
229 | }
230 | }
231 | }
232 | }
233 |
234 | private fun getColor(id: Int) =
235 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
236 | context.getColor(id)
237 | } else {
238 | resources.getColor(id)
239 | }
240 |
241 | }
242 |
--------------------------------------------------------------------------------
/shimmer/src/main/java/com/cooltechworks/views/shimmer/ShimmerViewHolder.kt:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Copyright 2017 Harish Sridharan
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.cooltechworks.views.shimmer
19 |
20 | import android.graphics.drawable.Drawable
21 | import android.os.Build
22 | import android.support.v7.widget.RecyclerView
23 | import android.view.LayoutInflater
24 | import android.view.ViewGroup
25 |
26 | import io.supercharge.shimmerlayout.ShimmerLayout
27 |
28 | class ShimmerViewHolder(inflater: LayoutInflater, parent: ViewGroup, innerViewResId: Int) : RecyclerView.ViewHolder(inflater.inflate(R.layout.viewholder_shimmer, parent, false)) {
29 |
30 | private val mShimmerLayout: ShimmerLayout = itemView as ShimmerLayout
31 |
32 | init {
33 | inflater.inflate(innerViewResId, mShimmerLayout, true)
34 | }
35 |
36 | fun setShimmerAngle(angle: Int) {
37 | mShimmerLayout.setShimmerAngle(angle)
38 | }
39 |
40 | fun setShimmerColor(color: Int) {
41 | mShimmerLayout.setShimmerColor(color)
42 | }
43 |
44 | fun setShimmerMaskWidth(maskWidth: Float) {
45 | mShimmerLayout.setMaskWidth(maskWidth)
46 | }
47 |
48 | fun setShimmerViewHolderBackground(viewHolderBackground: Drawable?) {
49 | if (viewHolderBackground != null) {
50 | setBackground(viewHolderBackground)
51 | }
52 | }
53 |
54 | fun setShimmerAnimationDuration(duration: Int) {
55 | mShimmerLayout.setShimmerAnimationDuration(duration)
56 | }
57 |
58 | fun setAnimationReversed(animationReversed: Boolean) {
59 | mShimmerLayout.setAnimationReversed(animationReversed)
60 | }
61 |
62 | fun bind() {
63 | mShimmerLayout.startShimmerAnimation()
64 | }
65 |
66 | private fun setBackground(background: Drawable) {
67 | if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
68 | mShimmerLayout.background = background
69 | } else {
70 | mShimmerLayout.setBackgroundDrawable(background)
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/shimmer/src/main/res/layout/layout_sample_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
28 |
29 |
39 |
40 |
49 |
50 |
55 |
56 |
61 |
62 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/shimmer/src/main/res/layout/viewholder_shimmer.xml:
--------------------------------------------------------------------------------
1 |
18 |
--------------------------------------------------------------------------------
/shimmer/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/shimmer/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #16000000
4 | #e3e1e3
5 |
--------------------------------------------------------------------------------