Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ewhang5 committed Jul 8, 2024
2 parents 2522a59 + 4dbefd5 commit d922fc7
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 81 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 21
targetSdkVersion 34
versionCode 1655
versionName "0.16.55"
versionCode 1657
versionName "0.16.57"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ abstract class BaseRecyclerFragment<LI> : BaseRecyclerParentFragment<Any?>(), On
"submission" -> (v as TextView).setText(R.string.no_submissions)
"teams" -> (v as TextView).setText(R.string.no_teams)
"chatHistory" -> (v as TextView).setText(R.string.no_chats)
"feedback" -> (v as TextView).setText(R.string.no_feedback)
else -> (v as TextView).setText(R.string.no_data_available_please_check_and_try_again)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.ole.planet.myplanet.model.RealmSubmission
import org.ole.planet.myplanet.model.RealmUserModel
import org.ole.planet.myplanet.service.UserProfileDbHandler
import org.ole.planet.myplanet.ui.exam.TakeExamFragment
import org.ole.planet.myplanet.utilities.CameraUtils.CapturePhoto
import org.ole.planet.myplanet.utilities.CameraUtils.capturePhoto
import org.ole.planet.myplanet.utilities.CameraUtils.ImageCaptureCallback
import org.ole.planet.myplanet.utilities.Constants
import org.ole.planet.myplanet.utilities.Constants.showBetaFeature
Expand Down Expand Up @@ -164,7 +164,7 @@ class CourseStepFragment : BaseContainerFragment(), ImageCaptureCallback {
takeExam.arguments = b
homeItemClickListener?.openCallFragment(takeExam)
context?.let { it1 ->
CapturePhoto(it1, object : ImageCaptureCallback {
capturePhoto(it1, object : ImageCaptureCallback {
override fun onImageCapture(fileUri: String?) {
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.ole.planet.myplanet.model.RealmExamQuestion
import org.ole.planet.myplanet.model.RealmSubmission
import org.ole.planet.myplanet.model.RealmSubmission.Companion.createSubmission
import org.ole.planet.myplanet.service.UserProfileDbHandler
import org.ole.planet.myplanet.utilities.CameraUtils.CapturePhoto
import org.ole.planet.myplanet.utilities.CameraUtils.capturePhoto
import org.ole.planet.myplanet.utilities.CameraUtils.ImageCaptureCallback
import org.ole.planet.myplanet.utilities.JsonParserUtils.getStringAsJsonArray
import org.ole.planet.myplanet.utilities.JsonUtils.getString
Expand Down Expand Up @@ -210,7 +210,7 @@ class TakeExamFragment : BaseExamFragment(), View.OnClickListener, CompoundButto
try {
if (isCertified && !isMySurvey) {
context?.let { it1 ->
CapturePhoto(it1, object : ImageCaptureCallback {
capturePhoto(it1, object : ImageCaptureCallback {
override fun onImageCapture(fileUri: String?) {
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.ole.planet.myplanet.model.RealmFeedback
import org.ole.planet.myplanet.model.RealmUserModel
import org.ole.planet.myplanet.service.UserProfileDbHandler
import org.ole.planet.myplanet.ui.feedback.FeedbackFragment.OnFeedbackSubmittedListener
import org.ole.planet.myplanet.base.BaseRecyclerFragment.Companion.showNoData

class FeedbackListFragment : Fragment(), OnFeedbackSubmittedListener {
private lateinit var fragmentFeedbackListBinding: FragmentFeedbackListBinding
Expand All @@ -25,6 +26,7 @@ class FeedbackListFragment : Fragment(), OnFeedbackSubmittedListener {
fragmentFeedbackListBinding = FragmentFeedbackListBinding.inflate(inflater, container, false)
mRealm = DatabaseService(requireActivity()).realmInstance
userModel = UserProfileDbHandler(requireContext()).userModel

fragmentFeedbackListBinding.fab.setOnClickListener {
val feedbackFragment = FeedbackFragment()
feedbackFragment.setOnFeedbackSubmittedListener(this)
Expand All @@ -33,15 +35,13 @@ class FeedbackListFragment : Fragment(), OnFeedbackSubmittedListener {
}
}

mRealm.executeTransactionAsync(
Realm.Transaction { },
Realm.Transaction.OnSuccess {
feedbackList = mRealm.where(RealmFeedback::class.java)
.equalTo("owner", userModel?.name).findAllAsync()
feedbackList?.addChangeListener { results ->
updatedFeedbackList(results)
}
})
feedbackList = mRealm.where(RealmFeedback::class.java)
.equalTo("owner", userModel?.name).findAllAsync()

feedbackList?.addChangeListener { results ->
updatedFeedbackList(results)
}

return fragmentFeedbackListBinding.root
}

Expand All @@ -53,6 +53,11 @@ class FeedbackListFragment : Fragment(), OnFeedbackSubmittedListener {
if (userModel?.isManager() == true) list = mRealm.where(RealmFeedback::class.java).findAll()
val adapterFeedback = AdapterFeedback(requireActivity(), list)
fragmentFeedbackListBinding.rvFeedback.adapter = adapterFeedback

val itemCount = feedbackList?.size ?: 0
showNoData(fragmentFeedbackListBinding.tvMessage, itemCount, "feedback")

updateTextViewsVisibility(itemCount)
}

override fun onDestroy() {
Expand All @@ -74,11 +79,25 @@ class FeedbackListFragment : Fragment(), OnFeedbackSubmittedListener {
updatedFeedbackList(updatedList)
})
}

private fun updatedFeedbackList(updatedList: RealmResults<RealmFeedback>?) {
activity?.runOnUiThread {
val adapterFeedback = updatedList?.let { AdapterFeedback(requireActivity(), it) }
fragmentFeedbackListBinding.rvFeedback.adapter = adapterFeedback
adapterFeedback?.notifyDataSetChanged()

val itemCount = updatedList?.size ?: 0
showNoData(fragmentFeedbackListBinding.tvMessage, itemCount, "feedback")
updateTextViewsVisibility(itemCount)
}
}

private fun updateTextViewsVisibility(itemCount: Int) {
val visibility = if (itemCount == 0) View.GONE else View.VISIBLE
fragmentFeedbackListBinding.tvTitle.visibility = visibility
fragmentFeedbackListBinding.tvType.visibility = visibility
fragmentFeedbackListBinding.tvPriority.visibility = visibility
fragmentFeedbackListBinding.tvStatus.visibility = visibility
fragmentFeedbackListBinding.tvOpenDate.visibility = visibility
}
}
77 changes: 50 additions & 27 deletions app/src/main/java/org/ole/planet/myplanet/utilities/CameraUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,28 @@ import android.content.pm.PackageManager
import android.graphics.ImageFormat
import android.graphics.SurfaceTexture
import android.hardware.camera2.*
import android.hardware.camera2.params.OutputConfiguration
import android.hardware.camera2.params.SessionConfiguration
import android.media.ImageReader
import android.os.Build
import android.os.Handler
import android.os.HandlerThread
import android.util.Size
import android.view.Surface
import androidx.core.content.ContextCompat
import java.io.File
import java.io.FileOutputStream
import java.util.*
import java.util.concurrent.Executors

object CameraUtils {
private var cameraDevice: CameraDevice? = null
private var captureSession: CameraCaptureSession? = null
private var imageReader: ImageReader? = null
private var backgroundHandler: Handler
private var backgroundThread: HandlerThread
private var backgroundThread: HandlerThread = HandlerThread("CameraBackground")

@JvmStatic
fun CapturePhoto(context: Context, callback: ImageCaptureCallback) {
fun capturePhoto(context: Context, callback: ImageCaptureCallback) {
if (ContextCompat.checkSelfPermission(
context,
Manifest.permission.CAMERA
Expand All @@ -48,11 +52,7 @@ object CameraUtils {
captureBuilder?.addTarget(imageReader!!.surface)
captureBuilder?.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE)

val captureCallback = object : CameraCaptureSession.CaptureCallback() {
override fun onCaptureCompleted(session: CameraCaptureSession, request: CaptureRequest, result: TotalCaptureResult) {
super.onCaptureCompleted(session, request, result)
}
}
val captureCallback = object : CameraCaptureSession.CaptureCallback() {}

captureSession?.stopRepeating()
captureSession?.abortCaptures()
Expand Down Expand Up @@ -83,13 +83,6 @@ object CameraUtils {
val manager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager
try {
val cameraId = manager.cameraIdList[0] // Assuming we want to use the first (rear) camera
val characteristics = manager.getCameraCharacteristics(cameraId)
val map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)
val largest = Collections.max(
listOf(*map!!.getOutputSizes(ImageFormat.JPEG)),
CompareSizesByArea()
)
val reader = ImageReader.newInstance(largest.width, largest.height, ImageFormat.JPEG, 2)
manager.openCamera(cameraId, object : CameraDevice.StateCallback() {
override fun onOpened(camera: CameraDevice) {
cameraDevice = camera
Expand Down Expand Up @@ -117,9 +110,10 @@ object CameraUtils {
val surface = Surface(texture)
val captureRequestBuilder = cameraDevice!!.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW)
captureRequestBuilder.addTarget(surface)
cameraDevice!!.createCaptureSession(
listOf(surface),
object : CameraCaptureSession.StateCallback() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val outputConfigurations = listOf(OutputConfiguration(surface))
val executor = Executors.newSingleThreadExecutor()
val stateCallback = object : CameraCaptureSession.StateCallback() {
override fun onConfigured(session: CameraCaptureSession) {
if (cameraDevice == null) return
captureSession = session
Expand All @@ -139,9 +133,44 @@ object CameraUtils {
}

override fun onConfigureFailed(session: CameraCaptureSession) {}
},
backgroundHandler
)
}

val sessionConfiguration = SessionConfiguration(
SessionConfiguration.SESSION_REGULAR,
outputConfigurations,
executor,
stateCallback
)

cameraDevice!!.createCaptureSession(sessionConfiguration)
} else {
@Suppress("DEPRECATION")
cameraDevice!!.createCaptureSession(
listOf(surface),
object : CameraCaptureSession.StateCallback() {
override fun onConfigured(session: CameraCaptureSession) {
if (cameraDevice == null) return
captureSession = session
try {
captureRequestBuilder.set(
CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE
)
captureSession!!.setRepeatingRequest(
captureRequestBuilder.build(),
null,
backgroundHandler
)
} catch (e: CameraAccessException) {
e.printStackTrace()
}
}

override fun onConfigureFailed(session: CameraCaptureSession) {}
},
backgroundHandler
)
}
} catch (e: CameraAccessException) {
e.printStackTrace()
}
Expand All @@ -151,13 +180,7 @@ object CameraUtils {
fun onImageCapture(fileUri: String?)
}

private class CompareSizesByArea : Comparator<Size> {
override fun compare(lhs: Size, rhs: Size): Int {
return java.lang.Long.signum(lhs.width.toLong() * lhs.height - rhs.width.toLong() * rhs.height)
}
}
init {
backgroundThread = HandlerThread("CameraBackground")
backgroundThread.start()
backgroundHandler = Handler(backgroundThread.looper)
}
Expand Down
Loading

0 comments on commit d922fc7

Please sign in to comment.