Skip to content

Commit

Permalink
Merge pull request #2 from Fuadafdhal/development
Browse files Browse the repository at this point in the history
update library
  • Loading branch information
Fuadafdhal authored Jun 30, 2021
2 parents 527d541 + 2c10b9c commit ee4bcfd
Show file tree
Hide file tree
Showing 32 changed files with 72 additions and 24 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation project(path: ':ImageSlider')
implementation project(path: ':imageslider')
implementation("io.coil-kt:coil:1.2.2")


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.afdhal_fa.imagesliderlibarary

/**
* Created by Muh Fuad Afdhal on 30/06/2021
* Email: [email protected]
*/

data class BannerUIModel(
var imageUrl: String,
var title: String
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.afdhal_fa.imagesliderlibarary

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
Expand Down Expand Up @@ -28,6 +29,8 @@ class MainActivity : AppCompatActivity() {
}
})


binding.buttonWithCustomAdapter.setOnClickListener {
startActivity(Intent(this, WithCustomAdapterActivity::class.java))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import com.afdhal_fa.imagesliderlibarary.databinding.ItemSampleImageSliderBindin
*/

class SampleAdapter : RecyclerView.Adapter<SampleAdapter.VHolder>() {
private var items: MutableList<String> = mutableListOf()
private var items: MutableList<BannerUIModel> = mutableListOf()

var onItemClick: ((String) -> Unit)? = null
var onItemClick: ((BannerUIModel) -> Unit)? = null

fun setItem(items: List<String>) {
fun setItem(items: List<BannerUIModel>) {
this.items.clear()
this.items.addAll(items)
notifyDataSetChanged()
Expand All @@ -27,11 +27,12 @@ class SampleAdapter : RecyclerView.Adapter<SampleAdapter.VHolder>() {
inner class VHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val binding = ItemSampleImageSliderBinding.bind(itemView)

fun onBind(image: String) {
binding.imageSlide.load(image)
fun onBind(model: BannerUIModel) {
binding.imageSlide.load(model.imageUrl)
binding.textTitle.text = model.title

binding.root.setOnClickListener {
onItemClick?.invoke(image)
onItemClick?.invoke(model)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.afdhal_fa.imagesliderlibarary
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import com.afdhal_fa.imageslider.model.SlideUIModel
import com.afdhal_fa.imagesliderlibarary.databinding.ActivityWithCustomAdapterBinding

class WithCustomAdapterActivity : AppCompatActivity() {
Expand All @@ -14,15 +15,14 @@ class WithCustomAdapterActivity : AppCompatActivity() {
binding = ActivityWithCustomAdapterBinding.inflate(layoutInflater)
setContentView(binding.root)


val imageList = ArrayList<String>() // Create image list
imageList.add("https://bit.ly/37Rn50u")
imageList.add("https://bit.ly/2BteuF2")
imageList.add("https://bit.ly/3fLJf72")
val imageList = ArrayList<BannerUIModel>() // Create image list
imageList.add(BannerUIModel("https://bit.ly/37Rn50u", "Baby Owl"))
imageList.add(BannerUIModel("https://bit.ly/2BteuF2", "Elephants and tigers may become extinct."))
imageList.add(BannerUIModel("https://bit.ly/3fLJf72", "The population of elephants is decreasing in the world."))
mAdapter.setItem(imageList)
binding.imageSlide.setImageListWithAdapter(mAdapter, imageList.size)
mAdapter.onItemClick = {
Toast.makeText(this, it, Toast.LENGTH_SHORT).show()
Toast.makeText(this, it.title, Toast.LENGTH_SHORT).show()
}
}
}
20 changes: 16 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,28 @@
<com.afdhal_fa.imageslider.ImageSlider
android:id="@+id/imageSlide"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="200dp"
app:iss_auto_cycle="true"
app:iss_image_scaleType="centerCrop"
app:iss_delay="0"
app:iss_with_title="false"
app:iss_period="5000"
app:iss_period="1000"
app:iss_title_color="@color/purple_500"
app:layout_constraintBottom_toBottomOf="parent"
app:iss_with_title="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.button.MaterialButton
android:id="@+id/buttonWithCustomAdapter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_marginBottom="32dp"
android:text="@string/with_custom_adapter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>
5 changes: 2 additions & 3 deletions app/src/main/res/layout/activity_with_custom_adapter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
<com.afdhal_fa.imageslider.ImageSlider
android:id="@+id/imageSlide"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="200dp"
app:iss_auto_cycle="true"
app:iss_delay="0"
app:iss_period="5000"
app:iss_period="1000"
app:iss_title_color="@color/purple_500"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/res/layout/item_sample_image_slider.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
android:layout_height="0dp"
android:adjustViewBounds="true"
android:contentDescription="@string/image"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
Expand All @@ -19,4 +20,24 @@
app:layout_constraintVertical_chainStyle="packed"
tools:srcCompat="@drawable/ic_image_placeholder" />

<LinearLayout
android:layout_width="80dp"
android:layout_height="match_parent"
android:background="@drawable/gradient"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/textTitle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center"
android:textColor="@color/white"
tools:text="Lorem Ipsum Dolor" />
</LinearLayout>


</androidx.constraintlayout.widget.ConstraintLayout>
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">Image Slider Libarary</string>
<string name="app_name">Image Slider</string>
<string name="with_custom_adapter">With Custom Adapter</string>
</resources>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
rootProject.name = "Image Slider Libarary"
include ':app'
include ':ImageSlider'
include ':imageslider'

0 comments on commit ee4bcfd

Please sign in to comment.