Skip to content

Commit

Permalink
Merge pull request #7 from AlfredoHdez1709/develop
Browse files Browse the repository at this point in the history
update app
  • Loading branch information
AlfredoHdez1709 authored Aug 22, 2024
2 parents ece18f1 + 44ad1e5 commit a54d7a6
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 47 deletions.
18 changes: 9 additions & 9 deletions EasyCameraAndGallery/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ plugins {
}

android {
compileSdk 32
compileSdk 34

defaultConfig {
minSdk 21
targetSdk 32
targetSdk 34

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand All @@ -31,26 +31,26 @@ android {
buildFeatures {
viewBinding true
}
namespace 'dev.ahrsoft.easycameraandgallery'
}

dependencies {

implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.core:core-ktx:1.13.1'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

def camerax_version = "1.1.0"
def camerax_version = "1.3.4"
implementation "androidx.camera:camera-core:${camerax_version}"
implementation "androidx.camera:camera-camera2:${camerax_version}"
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
// implementation "androidx.camera:camera-video:${camerax_version}" new version

implementation "androidx.camera:camera-view:${camerax_version}"
implementation "androidx.camera:camera-extensions:${camerax_version}"

implementation 'com.github.bumptech.glide:glide:4.13.2'
implementation 'com.github.bumptech.glide:glide:4.16.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.13.2'

implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.4")
}
12 changes: 8 additions & 4 deletions EasyCameraAndGallery/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="dev.ahrsoft.easycameraandgallery">
xmlns:tools="http://schemas.android.com/tools">


<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"
android:required="false"/>

<uses-permission android:name="android.permission.CAMERA" />

<uses-feature android:name="android.hardware.camera.any" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dev.ahrsoft.easycameraandgallery

import android.Manifest
import android.os.Build
import androidx.annotation.RequiresApi

object Constant {
const val TAG = "CameraAndGallery"
Expand All @@ -13,5 +15,12 @@ object Constant {
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE
)

@RequiresApi(Build.VERSION_CODES.TIRAMISU)
val REQUIRED_PERMISSIONS_TIRAMISU = arrayOf(
Manifest.permission.CAMERA,
Manifest.permission.READ_MEDIA_IMAGES
)

const val REQUEST_CODE_PERMISSIONS = 10
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,37 @@ import android.annotation.SuppressLint
import android.app.Activity
import android.app.AlertDialog
import android.content.ContentValues
import android.content.DialogInterface
import android.content.Intent
import android.content.pm.PackageManager
import android.media.MediaScannerConnection
import android.net.Uri
import android.os.Build
import android.os.Build.VERSION
import android.os.Bundle
import android.os.Environment
import android.provider.MediaStore
import android.provider.Settings
import android.util.Log
import android.view.Surface.ROTATION_0
import android.view.View
import android.webkit.MimeTypeMap
import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.camera.core.*
import androidx.camera.core.CameraSelector
import androidx.camera.core.ImageCapture
import androidx.camera.core.ImageCaptureException
import androidx.camera.core.Preview
import androidx.camera.lifecycle.ProcessCameraProvider
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.core.net.toFile
import androidx.core.view.isVisible
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.bumptech.glide.util.Util
import dev.ahrsoft.easycameraandgallery.Constant.FILENAME
import dev.ahrsoft.easycameraandgallery.Constant.PHOTO_EXTENSION
import dev.ahrsoft.easycameraandgallery.Constant.REQUEST_CODE_PERMISSIONS
import dev.ahrsoft.easycameraandgallery.Constant.REQUIRED_PERMISSIONS
import dev.ahrsoft.easycameraandgallery.Constant.TAG
import dev.ahrsoft.easycameraandgallery.Constant.REQUIRED_PERMISSIONS_TIRAMISU
import dev.ahrsoft.easycameraandgallery.EasyCamera.IMAGE_RESULTS
import dev.ahrsoft.easycameraandgallery.Flash
import dev.ahrsoft.easycameraandgallery.OptionsCamera
Expand All @@ -47,7 +46,7 @@ import dev.ahrsoft.easycameraandgallery.gallery.GalleryAdapter
import dev.ahrsoft.easycameraandgallery.gallery.ImageModel
import java.io.File
import java.text.SimpleDateFormat
import java.util.*
import java.util.Locale


class CameraActivity : AppCompatActivity(), GalleryAdapter.OnItemClickListener {
Expand All @@ -74,26 +73,25 @@ class CameraActivity : AppCompatActivity(), GalleryAdapter.OnItemClickListener {
binding = ActivityCameraBinding.inflate(layoutInflater)
setContentView(binding.root)
supportActionBar?.hide()
optionsCamera = (intent.getSerializableExtra("options") as? OptionsCamera)!!
optionsCamera = if (VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
intent.getSerializableExtra("options", OptionsCamera::class.java) as OptionsCamera
}else{
intent.getSerializableExtra("options") as OptionsCamera
}
viewModel = ViewModelProvider(this)[CameraViewModel::class.java]
initCameraUI()
initObserver()
openCallback()
}

override fun onRestart() {
super.onRestart()
initCameraUI()
}

private fun initCameraUI() {
if (allPermissionsGranted()){
binding.cameraVfState.displayedChild = CameraFlipperState.SHOW_CAMERA.state
initialSettingsCamera()
startCamera()
viewModel.getAllPhoto(this)
}else{
ActivityCompat.requestPermissions(this, REQUIRED_PERMISSIONS, REQUEST_CODE_PERMISSIONS)
ActivityCompat.requestPermissions(this, if (VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) REQUIRED_PERMISSIONS_TIRAMISU else REQUIRED_PERMISSIONS, REQUEST_CODE_PERMISSIONS)
}
}

Expand Down Expand Up @@ -244,7 +242,7 @@ class CameraActivity : AppCompatActivity(), GalleryAdapter.OnItemClickListener {
outputDirectory = getOutputDirectory()
var photoFile: File? = null
val outputOptions: ImageCapture.OutputFileOptions =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val contentValues = ContentValues().apply {
put(
MediaStore.MediaColumns.DISPLAY_NAME, SimpleDateFormat(
Expand Down Expand Up @@ -276,7 +274,7 @@ class CameraActivity : AppCompatActivity(), GalleryAdapter.OnItemClickListener {
ContextCompat.getMainExecutor(this),
object : ImageCapture.OnImageSavedCallback {
override fun onImageSaved(outputFileResults: ImageCapture.OutputFileResults) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q){
if (VERSION.SDK_INT < Build.VERSION_CODES.Q){
outputFileResults.savedUri?.let { mediaScanner(it) }
viewModel.addImage(outputFileResults.savedUri, photoFile)
}else{
Expand All @@ -298,8 +296,16 @@ class CameraActivity : AppCompatActivity(), GalleryAdapter.OnItemClickListener {
) { _, _ -> }
}

private fun allPermissionsGranted() = REQUIRED_PERMISSIONS.all {
ContextCompat.checkSelfPermission(baseContext, it) == PackageManager.PERMISSION_GRANTED
private fun allPermissionsGranted() : Boolean {
return if (VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
REQUIRED_PERMISSIONS_TIRAMISU.all {
ContextCompat.checkSelfPermission(baseContext, it) == PackageManager.PERMISSION_GRANTED
}
}else {
REQUIRED_PERMISSIONS.all {
ContextCompat.checkSelfPermission(baseContext, it) == PackageManager.PERMISSION_GRANTED
}
}
}

override fun onRequestPermissionsResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class GalleryAdapter(private val context : Context) : RecyclerView.Adapter<Galle
private var imageList: List<ImageModel>? = null
fun getGallery(imageList: List<ImageModel>){
this.imageList = imageList
notifyDataSetChanged()
}

class GalleryHolder(private val binding: ImagePickerListCameraBinding) : RecyclerView.ViewHolder(binding.root){
Expand Down
17 changes: 9 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ plugins {
}

android {
compileSdk 32
compileSdk 34

defaultConfig {
applicationId "dev.ahrsoft.cameralibrary"
minSdk 21
targetSdk 32
targetSdk 34
versionCode 1
versionName "0.5"

Expand All @@ -32,17 +32,18 @@ android {
buildFeatures {
viewBinding true
}
namespace 'dev.ahrsoft.cameralibrary'
}

dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.core:core-ktx:1.13.1'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation project(path: ':EasyCameraAndGallery')

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
}
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="dev.ahrsoft.cameralibrary">
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'com.android.application' version '8.5.2' apply false
id 'com.android.library' version '8.5.2' apply false
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
}

task clean(type: Delete) {
tasks.register('clean', Delete) {
delete rootProject.buildDir
}
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true
android.defaults.buildfeatures.buildconfig=true
android.nonFinalResIds=false
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Jul 23 20:21:01 CDT 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

0 comments on commit a54d7a6

Please sign in to comment.