From d880d580e852f66349c328d70351ea9604e852a9 Mon Sep 17 00:00:00 2001 From: akshaaatt Date: Fri, 28 May 2021 00:37:05 +0530 Subject: [PATCH] Added sample for handling the onClick trigger on selecting an image. --- app/build.gradle | 4 +++- app/src/main/AndroidManifest.xml | 1 + .../com/limerse/sliding/KotlinActivity.kt | 7 +++++-- .../java/com/limerse/sliding/SelectedImage.kt | 19 +++++++++++++++++++ .../res/layout/selected_image_activity.xml | 14 ++++++++++++++ build.gradle | 1 + 6 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/com/limerse/sliding/SelectedImage.kt create mode 100644 app/src/main/res/layout/selected_image_activity.xml diff --git a/app/build.gradle b/app/build.gradle index 1098c3c..483dcc6 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 @@ -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' } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3bd89f0..f7408b8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -18,6 +18,7 @@ + \ No newline at end of file diff --git a/app/src/main/java/com/limerse/sliding/KotlinActivity.kt b/app/src/main/java/com/limerse/sliding/KotlinActivity.kt index 70269ce..dbe65f8 100644 --- a/app/src/main/java/com/limerse/sliding/KotlinActivity.kt +++ b/app/src/main/java/com/limerse/sliding/KotlinActivity.kt @@ -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 @@ -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) { diff --git a/app/src/main/java/com/limerse/sliding/SelectedImage.kt b/app/src/main/java/com/limerse/sliding/SelectedImage.kt new file mode 100644 index 0000000..8a77834 --- /dev/null +++ b/app/src/main/java/com/limerse/sliding/SelectedImage.kt @@ -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) + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/selected_image_activity.xml b/app/src/main/res/layout/selected_image_activity.xml new file mode 100644 index 0000000..6ecf13c --- /dev/null +++ b/app/src/main/res/layout/selected_image_activity.xml @@ -0,0 +1,14 @@ + + + + + + diff --git a/build.gradle b/build.gradle index 1405fa6..2827379 100644 --- a/build.gradle +++ b/build.gradle @@ -19,6 +19,7 @@ allprojects { repositories { google() jcenter() + maven { url 'https://jitpack.io' } } }