Skip to content

Commit

Permalink
Added sample for handling the onClick trigger on selecting an image.
Browse files Browse the repository at this point in the history
  • Loading branch information
akshaaatt committed May 27, 2021
1 parent 24cc487 commit d880d58
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 3 deletions.
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'kotlin-android'
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.smarteist.imageslider"
applicationId "com.limerse.sliding"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
Expand Down Expand Up @@ -45,4 +45,6 @@ dependencies {
// Glide
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'

implementation 'com.github.chrisbanes:PhotoView:2.3.0'
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".SelectedImage"/>
</application>

</manifest>
7 changes: 5 additions & 2 deletions app/src/main/java/com/limerse/sliding/KotlinActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.limerse.sliding

import android.app.ActivityOptions
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
Expand Down Expand Up @@ -95,8 +97,9 @@ class KotlinActivity : AppCompatActivity() {

carouselListener = object : CarouselListener {
override fun onClick(position: Int, carouselItem: CarouselItem) {
Toast.makeText(this@KotlinActivity, "You clicked it.", Toast.LENGTH_SHORT)
.show()
val intent = Intent(this@KotlinActivity, SelectedImage::class.java)
intent.putExtra("file",carouselItem.imageUrl ?: carouselItem.imageDrawable )
startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this@KotlinActivity).toBundle())
}

override fun onLongClick(position: Int, carouselItem: CarouselItem) {
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/com/limerse/sliding/SelectedImage.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.limerse.sliding

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.bumptech.glide.Glide
import com.limerse.sliding.databinding.SelectedImageActivityBinding

class SelectedImage : AppCompatActivity() {
private lateinit var binding: SelectedImageActivityBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = SelectedImageActivityBinding.inflate(layoutInflater)
setContentView(binding.root)

Glide.with(this).load(intent.extras!!.get("file"))
.into(binding.imagePreview)
}
}
14 changes: 14 additions & 0 deletions app/src/main/res/layout/selected_image_activity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/preview_activity_container"
android:background="@color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/image_preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter" />

</RelativeLayout>
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}

Expand Down

0 comments on commit d880d58

Please sign in to comment.