Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
remove startActivityForResult on FeedbackActivity for camera and gall…
Browse files Browse the repository at this point in the history
…ery (#1523)

* remove startActivityForResult on FeedbackActivity for camera and gallery

* Update app/src/main/java/de/tum/in/tumcampusapp/component/tumui/feedback/FeedbackActivity.kt

Co-authored-by: Frank Elsinga <[email protected]>

* Update app/src/main/java/de/tum/in/tumcampusapp/component/tumui/feedback/FeedbackActivity.kt

Co-authored-by: Frank Elsinga <[email protected]>

* Update app/src/main/java/de/tum/in/tumcampusapp/component/tumui/feedback/FeedbackActivity.kt

Co-authored-by: Frank Elsinga <[email protected]>

Co-authored-by: Frank Elsinga <[email protected]>
Co-authored-by: Kordian Bruck <[email protected]>
  • Loading branch information
3 people authored Nov 14, 2022
1 parent 60eda86 commit 0b3b68b
Showing 1 changed file with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.tum.`in`.tumcampusapp.component.tumui.feedback

import android.annotation.SuppressLint
import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Intent
import android.content.pm.PackageManager.PERMISSION_GRANTED
import android.location.Location
Expand All @@ -13,9 +13,9 @@ import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.Toast
import android.widget.Toast.LENGTH_SHORT
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AlertDialog
import de.tum.`in`.tumcampusapp.utils.ThemedAlertDialogBuilder
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager.HORIZONTAL
Expand All @@ -28,10 +28,9 @@ import de.tum.`in`.tumcampusapp.component.other.generic.activity.BaseActivity
import de.tum.`in`.tumcampusapp.component.tumui.feedback.FeedbackPresenter.Companion.PERMISSION_CAMERA
import de.tum.`in`.tumcampusapp.component.tumui.feedback.FeedbackPresenter.Companion.PERMISSION_FILES
import de.tum.`in`.tumcampusapp.component.tumui.feedback.FeedbackPresenter.Companion.PERMISSION_LOCATION
import de.tum.`in`.tumcampusapp.component.tumui.feedback.FeedbackPresenter.Companion.REQUEST_GALLERY
import de.tum.`in`.tumcampusapp.component.tumui.feedback.FeedbackPresenter.Companion.REQUEST_TAKE_PHOTO
import de.tum.`in`.tumcampusapp.databinding.ActivityFeedbackBinding
import de.tum.`in`.tumcampusapp.utils.Const
import de.tum.`in`.tumcampusapp.utils.ThemedAlertDialogBuilder
import de.tum.`in`.tumcampusapp.utils.Utils
import io.reactivex.Observable
import java.io.File
Expand All @@ -47,6 +46,15 @@ class FeedbackActivity : BaseActivity(R.layout.activity_feedback), FeedbackContr

private lateinit var binding: ActivityFeedbackBinding

private val cameraLauncher = registerForActivityResult(StartActivityForResult()) {
presenter.onNewImageTaken()
}

private val galleryLauncher = registerForActivityResult(StartActivityForResult()) { result ->
val filePath = result.data?.data
presenter.onNewImageSelected(filePath)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand Down Expand Up @@ -134,11 +142,19 @@ class FeedbackActivity : BaseActivity(R.layout.activity_feedback), FeedbackContr
}

override fun openCamera(intent: Intent) {
startActivityForResult(intent, REQUEST_TAKE_PHOTO)
try {
cameraLauncher.launch(intent)
} catch (e: ActivityNotFoundException) {
Toast.makeText(this, R.string.error_unknown, LENGTH_SHORT).show()
}
}

override fun openGallery(intent: Intent) {
startActivityForResult(intent, REQUEST_GALLERY)
try {
galleryLauncher.launch(intent)
} catch (e: ActivityNotFoundException) {
Toast.makeText(this, R.string.error_unknown, LENGTH_SHORT).show()
}
}

@RequiresApi(api = Build.VERSION_CODES.M)
Expand Down Expand Up @@ -223,22 +239,6 @@ class FeedbackActivity : BaseActivity(R.layout.activity_feedback), FeedbackContr
.show()
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)

if (resultCode != Activity.RESULT_OK) {
return
}

when (requestCode) {
REQUEST_TAKE_PHOTO -> presenter.onNewImageTaken()
REQUEST_GALLERY -> {
val filePath = data?.data
presenter.onNewImageSelected(filePath)
}
}
}

override fun onImageAdded(path: String) {
thumbnailsAdapter.addImage(path)
}
Expand Down

0 comments on commit 0b3b68b

Please sign in to comment.