2021-04-22 11:47:18 +02:00
|
|
|
package org.pixeldroid.app.postCreation
|
Feature/post creation (#83)
* added perm and features for cameraS, gps and external storage
* added camera activity accessible from main activity
* added button to redirect to camera activity
* implementing callback flow to use camera
* working camera
* added texture view for camera display
* added camera activity
* implemented texture listener
* camera not working, flow done, no feedback implemented
* camera working
* refactored code, still an activity
* added private to internal function, better error function handling
* deleted camera activity
* added camera fragment
* added camera fragment
* refactored camera as fragment
* necessary dependencies for fragment testing
* initial camera fragment test
* corrected access to activity form fragment
* Added state changes and termination
* added lines to test, to test coverage
* Removed unsupported state STARTED state transition
* Added basic tests to test code coverage
* use layout for tests, to trigger permissions requirements
* grant camera permission to app in camera test
* replaced null handlers by proper function getter
* changed layout, added takePictureButton
* using expresso to get code coverage on camea
* take picture flow not finished
* dummy change to camera test to perform new build
* added connection flow before test to reach main activity
* can take a picture and put it to ImageView
* replaced button text with images
* smaller buttons
* test camera fragment buttons
* added orientation handler
* changed icon to make travis happy
* test new espresso config for travis
* removed useless rule
* deleted useless val
* added layout ID's
* moved swipes from Before to Tests, and thread sleep
* stoped swiping, now tests from fragment directly
* start post creation flow
* use Uri when taking photo, can now go back from picture preview
* adjusted test and flow idea
* tests on displayed UI elements for the post creation fragment
* refactor camera fragment into transition new post fragemnt
* finished first phase: get a picture Uri
* fixed lint error found by travis CI
* added global timeout to test
* test the new way of test
* refactor new way of testing
* added in-app camera view and linked everything to the final flow + started API to post
* strugling on the upload media part
* upload image on server implemented
* post upload implemented
* added API call to get max_toot_chars and correct def of a post description
* fixed some tests
* fix tests: clicking on tabs make the app crash because of the camera fragment
* comment problematic chunk of code while samuel tries to fix it
* switch minimumsdk to api 24
* Revert "switch minimumsdk to api 24"
This reverts commit 24ce46dd82038b59732fd958e5e071ded39cd549.
* deactivited live camera for API 23
* tests for post creation fragment UI elements
* remove worthless UI testing and add gallery intent test
* removed camera intent for now
* some refactor
* lint error and more refactor
* more refactor on merge from master
* refactor and test for PostCreationActivity
* Revert "refactor and test for PostCreationActivity"
This reverts commit a0c146bcc545cdc3792df4806e6b0c908bd18747.
* Revert "Revert "refactor and test for PostCreationActivity""
This reverts commit 147a9ed80d5f9c9e3c38b5a977786bfb39eeb1b6.
* permissions correction for test
* updtated test
* fix a test and refactor
* relink correct fragment
* save picture locally
* test post button
* requested changes
* fixed required changes
* Revert "fixed required changes"
This reverts commit 405a9d4d1af05353e30028e60041cc1c97569c1b.
* redo change request
* added /media api response to mockserver
Co-authored-by: Andrea Clement <samuel.dietz@epfl.ch>
2020-04-24 12:44:12 +02:00
|
|
|
|
2020-06-05 23:49:28 +02:00
|
|
|
import android.app.Activity
|
2021-02-05 19:06:57 +01:00
|
|
|
import android.app.AlertDialog
|
2022-07-10 13:42:19 +02:00
|
|
|
import android.content.ContentResolver
|
|
|
|
import android.content.ContentValues
|
|
|
|
import android.content.Intent
|
2021-01-09 16:19:26 +01:00
|
|
|
import android.media.MediaScannerConnection
|
Feature/post creation (#83)
* added perm and features for cameraS, gps and external storage
* added camera activity accessible from main activity
* added button to redirect to camera activity
* implementing callback flow to use camera
* working camera
* added texture view for camera display
* added camera activity
* implemented texture listener
* camera not working, flow done, no feedback implemented
* camera working
* refactored code, still an activity
* added private to internal function, better error function handling
* deleted camera activity
* added camera fragment
* added camera fragment
* refactored camera as fragment
* necessary dependencies for fragment testing
* initial camera fragment test
* corrected access to activity form fragment
* Added state changes and termination
* added lines to test, to test coverage
* Removed unsupported state STARTED state transition
* Added basic tests to test code coverage
* use layout for tests, to trigger permissions requirements
* grant camera permission to app in camera test
* replaced null handlers by proper function getter
* changed layout, added takePictureButton
* using expresso to get code coverage on camea
* take picture flow not finished
* dummy change to camera test to perform new build
* added connection flow before test to reach main activity
* can take a picture and put it to ImageView
* replaced button text with images
* smaller buttons
* test camera fragment buttons
* added orientation handler
* changed icon to make travis happy
* test new espresso config for travis
* removed useless rule
* deleted useless val
* added layout ID's
* moved swipes from Before to Tests, and thread sleep
* stoped swiping, now tests from fragment directly
* start post creation flow
* use Uri when taking photo, can now go back from picture preview
* adjusted test and flow idea
* tests on displayed UI elements for the post creation fragment
* refactor camera fragment into transition new post fragemnt
* finished first phase: get a picture Uri
* fixed lint error found by travis CI
* added global timeout to test
* test the new way of test
* refactor new way of testing
* added in-app camera view and linked everything to the final flow + started API to post
* strugling on the upload media part
* upload image on server implemented
* post upload implemented
* added API call to get max_toot_chars and correct def of a post description
* fixed some tests
* fix tests: clicking on tabs make the app crash because of the camera fragment
* comment problematic chunk of code while samuel tries to fix it
* switch minimumsdk to api 24
* Revert "switch minimumsdk to api 24"
This reverts commit 24ce46dd82038b59732fd958e5e071ded39cd549.
* deactivited live camera for API 23
* tests for post creation fragment UI elements
* remove worthless UI testing and add gallery intent test
* removed camera intent for now
* some refactor
* lint error and more refactor
* more refactor on merge from master
* refactor and test for PostCreationActivity
* Revert "refactor and test for PostCreationActivity"
This reverts commit a0c146bcc545cdc3792df4806e6b0c908bd18747.
* Revert "Revert "refactor and test for PostCreationActivity""
This reverts commit 147a9ed80d5f9c9e3c38b5a977786bfb39eeb1b6.
* permissions correction for test
* updtated test
* fix a test and refactor
* relink correct fragment
* save picture locally
* test post button
* requested changes
* fixed required changes
* Revert "fixed required changes"
This reverts commit 405a9d4d1af05353e30028e60041cc1c97569c1b.
* redo change request
* added /media api response to mockserver
Co-authored-by: Andrea Clement <samuel.dietz@epfl.ch>
2020-04-24 12:44:12 +02:00
|
|
|
import android.net.Uri
|
2022-06-18 22:21:19 +02:00
|
|
|
import android.os.*
|
2021-01-09 16:19:26 +01:00
|
|
|
import android.provider.MediaStore
|
Feature/post creation (#83)
* added perm and features for cameraS, gps and external storage
* added camera activity accessible from main activity
* added button to redirect to camera activity
* implementing callback flow to use camera
* working camera
* added texture view for camera display
* added camera activity
* implemented texture listener
* camera not working, flow done, no feedback implemented
* camera working
* refactored code, still an activity
* added private to internal function, better error function handling
* deleted camera activity
* added camera fragment
* added camera fragment
* refactored camera as fragment
* necessary dependencies for fragment testing
* initial camera fragment test
* corrected access to activity form fragment
* Added state changes and termination
* added lines to test, to test coverage
* Removed unsupported state STARTED state transition
* Added basic tests to test code coverage
* use layout for tests, to trigger permissions requirements
* grant camera permission to app in camera test
* replaced null handlers by proper function getter
* changed layout, added takePictureButton
* using expresso to get code coverage on camea
* take picture flow not finished
* dummy change to camera test to perform new build
* added connection flow before test to reach main activity
* can take a picture and put it to ImageView
* replaced button text with images
* smaller buttons
* test camera fragment buttons
* added orientation handler
* changed icon to make travis happy
* test new espresso config for travis
* removed useless rule
* deleted useless val
* added layout ID's
* moved swipes from Before to Tests, and thread sleep
* stoped swiping, now tests from fragment directly
* start post creation flow
* use Uri when taking photo, can now go back from picture preview
* adjusted test and flow idea
* tests on displayed UI elements for the post creation fragment
* refactor camera fragment into transition new post fragemnt
* finished first phase: get a picture Uri
* fixed lint error found by travis CI
* added global timeout to test
* test the new way of test
* refactor new way of testing
* added in-app camera view and linked everything to the final flow + started API to post
* strugling on the upload media part
* upload image on server implemented
* post upload implemented
* added API call to get max_toot_chars and correct def of a post description
* fixed some tests
* fix tests: clicking on tabs make the app crash because of the camera fragment
* comment problematic chunk of code while samuel tries to fix it
* switch minimumsdk to api 24
* Revert "switch minimumsdk to api 24"
This reverts commit 24ce46dd82038b59732fd958e5e071ded39cd549.
* deactivited live camera for API 23
* tests for post creation fragment UI elements
* remove worthless UI testing and add gallery intent test
* removed camera intent for now
* some refactor
* lint error and more refactor
* more refactor on merge from master
* refactor and test for PostCreationActivity
* Revert "refactor and test for PostCreationActivity"
This reverts commit a0c146bcc545cdc3792df4806e6b0c908bd18747.
* Revert "Revert "refactor and test for PostCreationActivity""
This reverts commit 147a9ed80d5f9c9e3c38b5a977786bfb39eeb1b6.
* permissions correction for test
* updtated test
* fix a test and refactor
* relink correct fragment
* save picture locally
* test post button
* requested changes
* fixed required changes
* Revert "fixed required changes"
This reverts commit 405a9d4d1af05353e30028e60041cc1c97569c1b.
* redo change request
* added /media api response to mockserver
Co-authored-by: Andrea Clement <samuel.dietz@epfl.ch>
2020-04-24 12:44:12 +02:00
|
|
|
import android.util.Log
|
2020-06-05 23:49:28 +02:00
|
|
|
import android.view.View
|
2021-01-12 17:16:37 +01:00
|
|
|
import android.view.View.INVISIBLE
|
|
|
|
import android.view.View.VISIBLE
|
2022-07-28 19:35:21 +02:00
|
|
|
import android.view.View.GONE
|
Feature/post creation (#83)
* added perm and features for cameraS, gps and external storage
* added camera activity accessible from main activity
* added button to redirect to camera activity
* implementing callback flow to use camera
* working camera
* added texture view for camera display
* added camera activity
* implemented texture listener
* camera not working, flow done, no feedback implemented
* camera working
* refactored code, still an activity
* added private to internal function, better error function handling
* deleted camera activity
* added camera fragment
* added camera fragment
* refactored camera as fragment
* necessary dependencies for fragment testing
* initial camera fragment test
* corrected access to activity form fragment
* Added state changes and termination
* added lines to test, to test coverage
* Removed unsupported state STARTED state transition
* Added basic tests to test code coverage
* use layout for tests, to trigger permissions requirements
* grant camera permission to app in camera test
* replaced null handlers by proper function getter
* changed layout, added takePictureButton
* using expresso to get code coverage on camea
* take picture flow not finished
* dummy change to camera test to perform new build
* added connection flow before test to reach main activity
* can take a picture and put it to ImageView
* replaced button text with images
* smaller buttons
* test camera fragment buttons
* added orientation handler
* changed icon to make travis happy
* test new espresso config for travis
* removed useless rule
* deleted useless val
* added layout ID's
* moved swipes from Before to Tests, and thread sleep
* stoped swiping, now tests from fragment directly
* start post creation flow
* use Uri when taking photo, can now go back from picture preview
* adjusted test and flow idea
* tests on displayed UI elements for the post creation fragment
* refactor camera fragment into transition new post fragemnt
* finished first phase: get a picture Uri
* fixed lint error found by travis CI
* added global timeout to test
* test the new way of test
* refactor new way of testing
* added in-app camera view and linked everything to the final flow + started API to post
* strugling on the upload media part
* upload image on server implemented
* post upload implemented
* added API call to get max_toot_chars and correct def of a post description
* fixed some tests
* fix tests: clicking on tabs make the app crash because of the camera fragment
* comment problematic chunk of code while samuel tries to fix it
* switch minimumsdk to api 24
* Revert "switch minimumsdk to api 24"
This reverts commit 24ce46dd82038b59732fd958e5e071ded39cd549.
* deactivited live camera for API 23
* tests for post creation fragment UI elements
* remove worthless UI testing and add gallery intent test
* removed camera intent for now
* some refactor
* lint error and more refactor
* more refactor on merge from master
* refactor and test for PostCreationActivity
* Revert "refactor and test for PostCreationActivity"
This reverts commit a0c146bcc545cdc3792df4806e6b0c908bd18747.
* Revert "Revert "refactor and test for PostCreationActivity""
This reverts commit 147a9ed80d5f9c9e3c38b5a977786bfb39eeb1b6.
* permissions correction for test
* updtated test
* fix a test and refactor
* relink correct fragment
* save picture locally
* test post button
* requested changes
* fixed required changes
* Revert "fixed required changes"
This reverts commit 405a9d4d1af05353e30028e60041cc1c97569c1b.
* redo change request
* added /media api response to mockserver
Co-authored-by: Andrea Clement <samuel.dietz@epfl.ch>
2020-04-24 12:44:12 +02:00
|
|
|
import android.widget.Toast
|
2021-03-21 13:03:58 +01:00
|
|
|
import androidx.activity.result.ActivityResult
|
2021-04-22 00:07:05 +02:00
|
|
|
import androidx.activity.result.ActivityResultLauncher
|
2021-03-21 13:03:58 +01:00
|
|
|
import androidx.activity.result.contract.ActivityResultContracts
|
2022-06-18 22:21:19 +02:00
|
|
|
import androidx.activity.viewModels
|
2020-06-03 16:32:02 +02:00
|
|
|
import androidx.core.net.toFile
|
2021-01-09 16:19:26 +01:00
|
|
|
import androidx.core.net.toUri
|
2022-06-18 22:21:19 +02:00
|
|
|
import androidx.core.os.HandlerCompat
|
2022-06-19 13:02:05 +02:00
|
|
|
import androidx.core.widget.doAfterTextChanged
|
|
|
|
import androidx.lifecycle.Lifecycle
|
2020-12-29 22:35:45 +01:00
|
|
|
import androidx.lifecycle.lifecycleScope
|
2022-06-19 13:02:05 +02:00
|
|
|
import androidx.lifecycle.repeatOnLifecycle
|
2022-06-18 22:21:19 +02:00
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
|
import com.arthenica.ffmpegkit.*
|
2021-01-09 16:19:26 +01:00
|
|
|
import com.google.android.material.snackbar.Snackbar
|
2022-06-19 13:02:05 +02:00
|
|
|
import kotlinx.coroutines.launch
|
2021-04-22 11:47:18 +02:00
|
|
|
import org.pixeldroid.app.R
|
|
|
|
import org.pixeldroid.app.databinding.ActivityPostCreationBinding
|
|
|
|
import org.pixeldroid.app.postCreation.camera.CameraActivity
|
|
|
|
import org.pixeldroid.app.postCreation.carousel.CarouselItem
|
|
|
|
import org.pixeldroid.app.postCreation.photoEdit.PhotoEditActivity
|
2022-06-18 22:21:19 +02:00
|
|
|
import org.pixeldroid.app.postCreation.photoEdit.VideoEditActivity
|
2022-07-10 13:42:19 +02:00
|
|
|
import org.pixeldroid.app.utils.BaseThemedWithoutBarActivity
|
2021-04-22 11:47:18 +02:00
|
|
|
import org.pixeldroid.app.utils.db.entities.InstanceDatabaseEntity
|
|
|
|
import org.pixeldroid.app.utils.db.entities.UserDatabaseEntity
|
2022-08-21 00:31:36 +02:00
|
|
|
import org.pixeldroid.app.utils.ffmpegCompliantUri
|
2022-06-19 14:28:00 +02:00
|
|
|
import org.pixeldroid.app.utils.fileExtension
|
2022-07-27 15:55:33 +02:00
|
|
|
import org.pixeldroid.app.utils.getMimeType
|
2021-01-09 16:19:26 +01:00
|
|
|
import java.io.File
|
|
|
|
import java.io.OutputStream
|
|
|
|
import java.text.SimpleDateFormat
|
|
|
|
import java.util.*
|
2022-06-18 22:21:19 +02:00
|
|
|
import kotlin.math.roundToInt
|
|
|
|
|
Feature/post creation (#83)
* added perm and features for cameraS, gps and external storage
* added camera activity accessible from main activity
* added button to redirect to camera activity
* implementing callback flow to use camera
* working camera
* added texture view for camera display
* added camera activity
* implemented texture listener
* camera not working, flow done, no feedback implemented
* camera working
* refactored code, still an activity
* added private to internal function, better error function handling
* deleted camera activity
* added camera fragment
* added camera fragment
* refactored camera as fragment
* necessary dependencies for fragment testing
* initial camera fragment test
* corrected access to activity form fragment
* Added state changes and termination
* added lines to test, to test coverage
* Removed unsupported state STARTED state transition
* Added basic tests to test code coverage
* use layout for tests, to trigger permissions requirements
* grant camera permission to app in camera test
* replaced null handlers by proper function getter
* changed layout, added takePictureButton
* using expresso to get code coverage on camea
* take picture flow not finished
* dummy change to camera test to perform new build
* added connection flow before test to reach main activity
* can take a picture and put it to ImageView
* replaced button text with images
* smaller buttons
* test camera fragment buttons
* added orientation handler
* changed icon to make travis happy
* test new espresso config for travis
* removed useless rule
* deleted useless val
* added layout ID's
* moved swipes from Before to Tests, and thread sleep
* stoped swiping, now tests from fragment directly
* start post creation flow
* use Uri when taking photo, can now go back from picture preview
* adjusted test and flow idea
* tests on displayed UI elements for the post creation fragment
* refactor camera fragment into transition new post fragemnt
* finished first phase: get a picture Uri
* fixed lint error found by travis CI
* added global timeout to test
* test the new way of test
* refactor new way of testing
* added in-app camera view and linked everything to the final flow + started API to post
* strugling on the upload media part
* upload image on server implemented
* post upload implemented
* added API call to get max_toot_chars and correct def of a post description
* fixed some tests
* fix tests: clicking on tabs make the app crash because of the camera fragment
* comment problematic chunk of code while samuel tries to fix it
* switch minimumsdk to api 24
* Revert "switch minimumsdk to api 24"
This reverts commit 24ce46dd82038b59732fd958e5e071ded39cd549.
* deactivited live camera for API 23
* tests for post creation fragment UI elements
* remove worthless UI testing and add gallery intent test
* removed camera intent for now
* some refactor
* lint error and more refactor
* more refactor on merge from master
* refactor and test for PostCreationActivity
* Revert "refactor and test for PostCreationActivity"
This reverts commit a0c146bcc545cdc3792df4806e6b0c908bd18747.
* Revert "Revert "refactor and test for PostCreationActivity""
This reverts commit 147a9ed80d5f9c9e3c38b5a977786bfb39eeb1b6.
* permissions correction for test
* updtated test
* fix a test and refactor
* relink correct fragment
* save picture locally
* test post button
* requested changes
* fixed required changes
* Revert "fixed required changes"
This reverts commit 405a9d4d1af05353e30028e60041cc1c97569c1b.
* redo change request
* added /media api response to mockserver
Co-authored-by: Andrea Clement <samuel.dietz@epfl.ch>
2020-04-24 12:44:12 +02:00
|
|
|
|
2022-06-19 13:02:05 +02:00
|
|
|
const val TAG = "Post Creation Activity"
|
2020-10-04 23:27:06 +02:00
|
|
|
|
2021-01-10 22:30:35 +01:00
|
|
|
data class PhotoData(
|
2022-02-16 13:01:32 +01:00
|
|
|
var imageUri: Uri,
|
|
|
|
var size: Long,
|
|
|
|
var uploadId: String? = null,
|
|
|
|
var progress: Int? = null,
|
|
|
|
var imageDescription: String? = null,
|
|
|
|
var video: Boolean,
|
2022-06-18 22:21:19 +02:00
|
|
|
var videoEncodeProgress: Int? = null,
|
2021-01-10 22:30:35 +01:00
|
|
|
)
|
Feature/post creation (#83)
* added perm and features for cameraS, gps and external storage
* added camera activity accessible from main activity
* added button to redirect to camera activity
* implementing callback flow to use camera
* working camera
* added texture view for camera display
* added camera activity
* implemented texture listener
* camera not working, flow done, no feedback implemented
* camera working
* refactored code, still an activity
* added private to internal function, better error function handling
* deleted camera activity
* added camera fragment
* added camera fragment
* refactored camera as fragment
* necessary dependencies for fragment testing
* initial camera fragment test
* corrected access to activity form fragment
* Added state changes and termination
* added lines to test, to test coverage
* Removed unsupported state STARTED state transition
* Added basic tests to test code coverage
* use layout for tests, to trigger permissions requirements
* grant camera permission to app in camera test
* replaced null handlers by proper function getter
* changed layout, added takePictureButton
* using expresso to get code coverage on camea
* take picture flow not finished
* dummy change to camera test to perform new build
* added connection flow before test to reach main activity
* can take a picture and put it to ImageView
* replaced button text with images
* smaller buttons
* test camera fragment buttons
* added orientation handler
* changed icon to make travis happy
* test new espresso config for travis
* removed useless rule
* deleted useless val
* added layout ID's
* moved swipes from Before to Tests, and thread sleep
* stoped swiping, now tests from fragment directly
* start post creation flow
* use Uri when taking photo, can now go back from picture preview
* adjusted test and flow idea
* tests on displayed UI elements for the post creation fragment
* refactor camera fragment into transition new post fragemnt
* finished first phase: get a picture Uri
* fixed lint error found by travis CI
* added global timeout to test
* test the new way of test
* refactor new way of testing
* added in-app camera view and linked everything to the final flow + started API to post
* strugling on the upload media part
* upload image on server implemented
* post upload implemented
* added API call to get max_toot_chars and correct def of a post description
* fixed some tests
* fix tests: clicking on tabs make the app crash because of the camera fragment
* comment problematic chunk of code while samuel tries to fix it
* switch minimumsdk to api 24
* Revert "switch minimumsdk to api 24"
This reverts commit 24ce46dd82038b59732fd958e5e071ded39cd549.
* deactivited live camera for API 23
* tests for post creation fragment UI elements
* remove worthless UI testing and add gallery intent test
* removed camera intent for now
* some refactor
* lint error and more refactor
* more refactor on merge from master
* refactor and test for PostCreationActivity
* Revert "refactor and test for PostCreationActivity"
This reverts commit a0c146bcc545cdc3792df4806e6b0c908bd18747.
* Revert "Revert "refactor and test for PostCreationActivity""
This reverts commit 147a9ed80d5f9c9e3c38b5a977786bfb39eeb1b6.
* permissions correction for test
* updtated test
* fix a test and refactor
* relink correct fragment
* save picture locally
* test post button
* requested changes
* fixed required changes
* Revert "fixed required changes"
This reverts commit 405a9d4d1af05353e30028e60041cc1c97569c1b.
* redo change request
* added /media api response to mockserver
Co-authored-by: Andrea Clement <samuel.dietz@epfl.ch>
2020-04-24 12:44:12 +02:00
|
|
|
|
2022-07-10 13:42:19 +02:00
|
|
|
class PostCreationActivity : BaseThemedWithoutBarActivity() {
|
Feature/post creation (#83)
* added perm and features for cameraS, gps and external storage
* added camera activity accessible from main activity
* added button to redirect to camera activity
* implementing callback flow to use camera
* working camera
* added texture view for camera display
* added camera activity
* implemented texture listener
* camera not working, flow done, no feedback implemented
* camera working
* refactored code, still an activity
* added private to internal function, better error function handling
* deleted camera activity
* added camera fragment
* added camera fragment
* refactored camera as fragment
* necessary dependencies for fragment testing
* initial camera fragment test
* corrected access to activity form fragment
* Added state changes and termination
* added lines to test, to test coverage
* Removed unsupported state STARTED state transition
* Added basic tests to test code coverage
* use layout for tests, to trigger permissions requirements
* grant camera permission to app in camera test
* replaced null handlers by proper function getter
* changed layout, added takePictureButton
* using expresso to get code coverage on camea
* take picture flow not finished
* dummy change to camera test to perform new build
* added connection flow before test to reach main activity
* can take a picture and put it to ImageView
* replaced button text with images
* smaller buttons
* test camera fragment buttons
* added orientation handler
* changed icon to make travis happy
* test new espresso config for travis
* removed useless rule
* deleted useless val
* added layout ID's
* moved swipes from Before to Tests, and thread sleep
* stoped swiping, now tests from fragment directly
* start post creation flow
* use Uri when taking photo, can now go back from picture preview
* adjusted test and flow idea
* tests on displayed UI elements for the post creation fragment
* refactor camera fragment into transition new post fragemnt
* finished first phase: get a picture Uri
* fixed lint error found by travis CI
* added global timeout to test
* test the new way of test
* refactor new way of testing
* added in-app camera view and linked everything to the final flow + started API to post
* strugling on the upload media part
* upload image on server implemented
* post upload implemented
* added API call to get max_toot_chars and correct def of a post description
* fixed some tests
* fix tests: clicking on tabs make the app crash because of the camera fragment
* comment problematic chunk of code while samuel tries to fix it
* switch minimumsdk to api 24
* Revert "switch minimumsdk to api 24"
This reverts commit 24ce46dd82038b59732fd958e5e071ded39cd549.
* deactivited live camera for API 23
* tests for post creation fragment UI elements
* remove worthless UI testing and add gallery intent test
* removed camera intent for now
* some refactor
* lint error and more refactor
* more refactor on merge from master
* refactor and test for PostCreationActivity
* Revert "refactor and test for PostCreationActivity"
This reverts commit a0c146bcc545cdc3792df4806e6b0c908bd18747.
* Revert "Revert "refactor and test for PostCreationActivity""
This reverts commit 147a9ed80d5f9c9e3c38b5a977786bfb39eeb1b6.
* permissions correction for test
* updtated test
* fix a test and refactor
* relink correct fragment
* save picture locally
* test post button
* requested changes
* fixed required changes
* Revert "fixed required changes"
This reverts commit 405a9d4d1af05353e30028e60041cc1c97569c1b.
* redo change request
* added /media api response to mockserver
Co-authored-by: Andrea Clement <samuel.dietz@epfl.ch>
2020-04-24 12:44:12 +02:00
|
|
|
|
2020-05-19 09:49:34 +02:00
|
|
|
private var user: UserDatabaseEntity? = null
|
2021-02-07 22:55:34 +01:00
|
|
|
private lateinit var instance: InstanceDatabaseEntity
|
2020-05-19 09:49:34 +02:00
|
|
|
|
2021-01-13 01:28:08 +01:00
|
|
|
private lateinit var binding: ActivityPostCreationBinding
|
|
|
|
|
2022-06-18 22:21:19 +02:00
|
|
|
private val resultHandler: Handler = HandlerCompat.createAsync(Looper.getMainLooper())
|
|
|
|
|
2022-06-19 13:02:05 +02:00
|
|
|
private lateinit var model: PostCreationViewModel
|
2022-06-18 22:21:19 +02:00
|
|
|
|
|
|
|
|
Feature/post creation (#83)
* added perm and features for cameraS, gps and external storage
* added camera activity accessible from main activity
* added button to redirect to camera activity
* implementing callback flow to use camera
* working camera
* added texture view for camera display
* added camera activity
* implemented texture listener
* camera not working, flow done, no feedback implemented
* camera working
* refactored code, still an activity
* added private to internal function, better error function handling
* deleted camera activity
* added camera fragment
* added camera fragment
* refactored camera as fragment
* necessary dependencies for fragment testing
* initial camera fragment test
* corrected access to activity form fragment
* Added state changes and termination
* added lines to test, to test coverage
* Removed unsupported state STARTED state transition
* Added basic tests to test code coverage
* use layout for tests, to trigger permissions requirements
* grant camera permission to app in camera test
* replaced null handlers by proper function getter
* changed layout, added takePictureButton
* using expresso to get code coverage on camea
* take picture flow not finished
* dummy change to camera test to perform new build
* added connection flow before test to reach main activity
* can take a picture and put it to ImageView
* replaced button text with images
* smaller buttons
* test camera fragment buttons
* added orientation handler
* changed icon to make travis happy
* test new espresso config for travis
* removed useless rule
* deleted useless val
* added layout ID's
* moved swipes from Before to Tests, and thread sleep
* stoped swiping, now tests from fragment directly
* start post creation flow
* use Uri when taking photo, can now go back from picture preview
* adjusted test and flow idea
* tests on displayed UI elements for the post creation fragment
* refactor camera fragment into transition new post fragemnt
* finished first phase: get a picture Uri
* fixed lint error found by travis CI
* added global timeout to test
* test the new way of test
* refactor new way of testing
* added in-app camera view and linked everything to the final flow + started API to post
* strugling on the upload media part
* upload image on server implemented
* post upload implemented
* added API call to get max_toot_chars and correct def of a post description
* fixed some tests
* fix tests: clicking on tabs make the app crash because of the camera fragment
* comment problematic chunk of code while samuel tries to fix it
* switch minimumsdk to api 24
* Revert "switch minimumsdk to api 24"
This reverts commit 24ce46dd82038b59732fd958e5e071ded39cd549.
* deactivited live camera for API 23
* tests for post creation fragment UI elements
* remove worthless UI testing and add gallery intent test
* removed camera intent for now
* some refactor
* lint error and more refactor
* more refactor on merge from master
* refactor and test for PostCreationActivity
* Revert "refactor and test for PostCreationActivity"
This reverts commit a0c146bcc545cdc3792df4806e6b0c908bd18747.
* Revert "Revert "refactor and test for PostCreationActivity""
This reverts commit 147a9ed80d5f9c9e3c38b5a977786bfb39eeb1b6.
* permissions correction for test
* updtated test
* fix a test and refactor
* relink correct fragment
* save picture locally
* test post button
* requested changes
* fixed required changes
* Revert "fixed required changes"
This reverts commit 405a9d4d1af05353e30028e60041cc1c97569c1b.
* redo change request
* added /media api response to mockserver
Co-authored-by: Andrea Clement <samuel.dietz@epfl.ch>
2020-04-24 12:44:12 +02:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
2021-01-13 01:28:08 +01:00
|
|
|
binding = ActivityPostCreationBinding.inflate(layoutInflater)
|
|
|
|
setContentView(binding.root)
|
2020-05-15 09:23:06 +02:00
|
|
|
|
2021-02-05 19:06:57 +01:00
|
|
|
user = db.userDao().getActiveUser()
|
|
|
|
|
2021-02-07 22:55:34 +01:00
|
|
|
instance = user?.run {
|
2021-02-05 19:06:57 +01:00
|
|
|
db.instanceDao().getAll().first { instanceDatabaseEntity ->
|
|
|
|
instanceDatabaseEntity.uri.contains(instance_uri)
|
2020-10-04 23:27:06 +02:00
|
|
|
}
|
2021-02-05 19:06:57 +01:00
|
|
|
} ?: InstanceDatabaseEntity("", "")
|
Feature/post creation (#83)
* added perm and features for cameraS, gps and external storage
* added camera activity accessible from main activity
* added button to redirect to camera activity
* implementing callback flow to use camera
* working camera
* added texture view for camera display
* added camera activity
* implemented texture listener
* camera not working, flow done, no feedback implemented
* camera working
* refactored code, still an activity
* added private to internal function, better error function handling
* deleted camera activity
* added camera fragment
* added camera fragment
* refactored camera as fragment
* necessary dependencies for fragment testing
* initial camera fragment test
* corrected access to activity form fragment
* Added state changes and termination
* added lines to test, to test coverage
* Removed unsupported state STARTED state transition
* Added basic tests to test code coverage
* use layout for tests, to trigger permissions requirements
* grant camera permission to app in camera test
* replaced null handlers by proper function getter
* changed layout, added takePictureButton
* using expresso to get code coverage on camea
* take picture flow not finished
* dummy change to camera test to perform new build
* added connection flow before test to reach main activity
* can take a picture and put it to ImageView
* replaced button text with images
* smaller buttons
* test camera fragment buttons
* added orientation handler
* changed icon to make travis happy
* test new espresso config for travis
* removed useless rule
* deleted useless val
* added layout ID's
* moved swipes from Before to Tests, and thread sleep
* stoped swiping, now tests from fragment directly
* start post creation flow
* use Uri when taking photo, can now go back from picture preview
* adjusted test and flow idea
* tests on displayed UI elements for the post creation fragment
* refactor camera fragment into transition new post fragemnt
* finished first phase: get a picture Uri
* fixed lint error found by travis CI
* added global timeout to test
* test the new way of test
* refactor new way of testing
* added in-app camera view and linked everything to the final flow + started API to post
* strugling on the upload media part
* upload image on server implemented
* post upload implemented
* added API call to get max_toot_chars and correct def of a post description
* fixed some tests
* fix tests: clicking on tabs make the app crash because of the camera fragment
* comment problematic chunk of code while samuel tries to fix it
* switch minimumsdk to api 24
* Revert "switch minimumsdk to api 24"
This reverts commit 24ce46dd82038b59732fd958e5e071ded39cd549.
* deactivited live camera for API 23
* tests for post creation fragment UI elements
* remove worthless UI testing and add gallery intent test
* removed camera intent for now
* some refactor
* lint error and more refactor
* more refactor on merge from master
* refactor and test for PostCreationActivity
* Revert "refactor and test for PostCreationActivity"
This reverts commit a0c146bcc545cdc3792df4806e6b0c908bd18747.
* Revert "Revert "refactor and test for PostCreationActivity""
This reverts commit 147a9ed80d5f9c9e3c38b5a977786bfb39eeb1b6.
* permissions correction for test
* updtated test
* fix a test and refactor
* relink correct fragment
* save picture locally
* test post button
* requested changes
* fixed required changes
* Revert "fixed required changes"
This reverts commit 405a9d4d1af05353e30028e60041cc1c97569c1b.
* redo change request
* added /media api response to mockserver
Co-authored-by: Andrea Clement <samuel.dietz@epfl.ch>
2020-04-24 12:44:12 +02:00
|
|
|
|
2022-06-19 13:02:05 +02:00
|
|
|
val _model: PostCreationViewModel by viewModels { PostCreationViewModelFactory(application, intent.clipData!!, instance) }
|
|
|
|
model = _model
|
2020-05-19 09:49:34 +02:00
|
|
|
|
2022-06-19 13:02:05 +02:00
|
|
|
model.getPhotoData().observe(this) { newPhotoData ->
|
|
|
|
// update UI
|
|
|
|
binding.carousel.addData(
|
|
|
|
newPhotoData.map {
|
|
|
|
CarouselItem(it.imageUri, it.imageDescription, it.video, it.videoEncodeProgress)
|
|
|
|
}
|
|
|
|
)
|
2021-01-12 17:16:37 +01:00
|
|
|
}
|
2022-06-19 13:02:05 +02:00
|
|
|
|
|
|
|
lifecycleScope.launch {
|
|
|
|
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
|
|
|
model.uiState.collect { uiState ->
|
|
|
|
uiState.userMessage?.let {
|
|
|
|
AlertDialog.Builder(binding.root.context).apply {
|
|
|
|
setMessage(it)
|
|
|
|
setNegativeButton(android.R.string.ok) { _, _ -> }
|
|
|
|
}.show()
|
|
|
|
|
|
|
|
// Notify the ViewModel the message is displayed
|
|
|
|
model.userMessageShown()
|
|
|
|
}
|
|
|
|
binding.addPhotoButton.isEnabled = uiState.addPhotoButtonEnabled
|
|
|
|
enableButton(uiState.postCreationSendButtonEnabled)
|
|
|
|
binding.uploadProgressBar.visibility = if(uiState.uploadProgressBarVisible) VISIBLE else INVISIBLE
|
|
|
|
binding.uploadProgressBar.progress = uiState.uploadProgress
|
|
|
|
binding.uploadCompletedTextview.visibility = if(uiState.uploadCompletedTextviewVisible) VISIBLE else INVISIBLE
|
|
|
|
binding.removePhotoButton.isEnabled = uiState.removePhotoButtonEnabled
|
|
|
|
binding.editPhotoButton.isEnabled = uiState.editPhotoButtonEnabled
|
|
|
|
binding.uploadError.visibility = if(uiState.uploadErrorVisible) VISIBLE else INVISIBLE
|
|
|
|
binding.uploadErrorTextExplanation.visibility = if(uiState.uploadErrorExplanationVisible) VISIBLE else INVISIBLE
|
|
|
|
|
|
|
|
binding.toolbarPostCreation.visibility = if(uiState.isCarousel) VISIBLE else INVISIBLE
|
|
|
|
binding.carousel.layoutCarousel = uiState.isCarousel
|
|
|
|
|
|
|
|
|
|
|
|
binding.uploadErrorTextExplanation.text = uiState.uploadErrorExplanationText
|
|
|
|
|
|
|
|
uiState.newEncodingJobPosition?.let { position ->
|
|
|
|
uiState.newEncodingJobMuted?.let { muted ->
|
|
|
|
uiState.newEncodingJobVideoStart?.let { videoStart ->
|
|
|
|
uiState.newEncodingJobVideoEnd?.let { videoEnd ->
|
|
|
|
startEncoding(position, muted, videoStart, videoEnd)
|
|
|
|
model.encodingStarted()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-12 17:16:37 +01:00
|
|
|
}
|
2022-06-19 13:02:05 +02:00
|
|
|
binding.newPostDescriptionInputField.doAfterTextChanged {
|
|
|
|
model.newPostDescriptionChanged(binding.newPostDescriptionInputField.text)
|
2021-01-25 00:02:03 +01:00
|
|
|
}
|
2022-06-19 13:02:05 +02:00
|
|
|
binding.postTextInputLayout.counterMaxLength = instance.maxStatusChars
|
2020-06-05 23:49:28 +02:00
|
|
|
|
2022-06-19 13:02:05 +02:00
|
|
|
binding.carousel.apply {
|
|
|
|
layoutCarouselCallback = { model.becameCarousel(it)}
|
|
|
|
maxEntries = instance.albumLimit
|
|
|
|
addPhotoButtonCallback = {
|
|
|
|
addPhoto()
|
|
|
|
}
|
|
|
|
updateDescriptionCallback = { position: Int, description: String ->
|
|
|
|
model.updateDescription(position, description)
|
|
|
|
}
|
|
|
|
}
|
2020-05-21 19:31:41 +02:00
|
|
|
// get the description and send the post
|
2021-01-13 22:46:00 +01:00
|
|
|
binding.postCreationSendButton.setOnClickListener {
|
2022-06-19 13:02:05 +02:00
|
|
|
if (validatePost() && model.isNotEmpty()) model.upload()
|
Feature/post creation (#83)
* added perm and features for cameraS, gps and external storage
* added camera activity accessible from main activity
* added button to redirect to camera activity
* implementing callback flow to use camera
* working camera
* added texture view for camera display
* added camera activity
* implemented texture listener
* camera not working, flow done, no feedback implemented
* camera working
* refactored code, still an activity
* added private to internal function, better error function handling
* deleted camera activity
* added camera fragment
* added camera fragment
* refactored camera as fragment
* necessary dependencies for fragment testing
* initial camera fragment test
* corrected access to activity form fragment
* Added state changes and termination
* added lines to test, to test coverage
* Removed unsupported state STARTED state transition
* Added basic tests to test code coverage
* use layout for tests, to trigger permissions requirements
* grant camera permission to app in camera test
* replaced null handlers by proper function getter
* changed layout, added takePictureButton
* using expresso to get code coverage on camea
* take picture flow not finished
* dummy change to camera test to perform new build
* added connection flow before test to reach main activity
* can take a picture and put it to ImageView
* replaced button text with images
* smaller buttons
* test camera fragment buttons
* added orientation handler
* changed icon to make travis happy
* test new espresso config for travis
* removed useless rule
* deleted useless val
* added layout ID's
* moved swipes from Before to Tests, and thread sleep
* stoped swiping, now tests from fragment directly
* start post creation flow
* use Uri when taking photo, can now go back from picture preview
* adjusted test and flow idea
* tests on displayed UI elements for the post creation fragment
* refactor camera fragment into transition new post fragemnt
* finished first phase: get a picture Uri
* fixed lint error found by travis CI
* added global timeout to test
* test the new way of test
* refactor new way of testing
* added in-app camera view and linked everything to the final flow + started API to post
* strugling on the upload media part
* upload image on server implemented
* post upload implemented
* added API call to get max_toot_chars and correct def of a post description
* fixed some tests
* fix tests: clicking on tabs make the app crash because of the camera fragment
* comment problematic chunk of code while samuel tries to fix it
* switch minimumsdk to api 24
* Revert "switch minimumsdk to api 24"
This reverts commit 24ce46dd82038b59732fd958e5e071ded39cd549.
* deactivited live camera for API 23
* tests for post creation fragment UI elements
* remove worthless UI testing and add gallery intent test
* removed camera intent for now
* some refactor
* lint error and more refactor
* more refactor on merge from master
* refactor and test for PostCreationActivity
* Revert "refactor and test for PostCreationActivity"
This reverts commit a0c146bcc545cdc3792df4806e6b0c908bd18747.
* Revert "Revert "refactor and test for PostCreationActivity""
This reverts commit 147a9ed80d5f9c9e3c38b5a977786bfb39eeb1b6.
* permissions correction for test
* updtated test
* fix a test and refactor
* relink correct fragment
* save picture locally
* test post button
* requested changes
* fixed required changes
* Revert "fixed required changes"
This reverts commit 405a9d4d1af05353e30028e60041cc1c97569c1b.
* redo change request
* added /media api response to mockserver
Co-authored-by: Andrea Clement <samuel.dietz@epfl.ch>
2020-04-24 12:44:12 +02:00
|
|
|
}
|
2020-06-05 23:49:28 +02:00
|
|
|
|
2020-05-21 19:31:41 +02:00
|
|
|
// Button to retry image upload when it fails
|
2021-01-13 22:46:00 +01:00
|
|
|
binding.retryUploadButton.setOnClickListener {
|
2022-06-19 13:02:05 +02:00
|
|
|
model.resetUploadStatus()
|
|
|
|
model.upload()
|
2020-05-21 19:31:41 +02:00
|
|
|
}
|
2021-01-09 16:19:26 +01:00
|
|
|
|
2021-01-13 22:46:00 +01:00
|
|
|
binding.editPhotoButton.setOnClickListener {
|
2022-06-19 13:02:05 +02:00
|
|
|
binding.carousel.currentPosition.takeIf { it != RecyclerView.NO_POSITION }?.let { currentPosition ->
|
2021-01-10 22:30:35 +01:00
|
|
|
edit(currentPosition)
|
|
|
|
}
|
2021-01-09 16:19:26 +01:00
|
|
|
}
|
|
|
|
|
2021-01-13 22:46:00 +01:00
|
|
|
binding.addPhotoButton.setOnClickListener {
|
2021-03-21 13:03:58 +01:00
|
|
|
addPhoto()
|
2021-01-09 16:19:26 +01:00
|
|
|
}
|
|
|
|
|
2021-01-13 22:46:00 +01:00
|
|
|
binding.savePhotoButton.setOnClickListener {
|
2022-06-19 13:02:05 +02:00
|
|
|
binding.carousel.currentPosition.takeIf { it != RecyclerView.NO_POSITION }?.let { currentPosition ->
|
2021-01-10 22:30:35 +01:00
|
|
|
savePicture(it, currentPosition)
|
|
|
|
}
|
|
|
|
}
|
2021-01-09 16:19:26 +01:00
|
|
|
|
|
|
|
|
2021-01-13 22:46:00 +01:00
|
|
|
binding.removePhotoButton.setOnClickListener {
|
2022-06-19 13:02:05 +02:00
|
|
|
binding.carousel.currentPosition.takeIf { it != RecyclerView.NO_POSITION }?.let { currentPosition ->
|
|
|
|
model.removeAt(currentPosition)
|
|
|
|
model.cancelEncode(currentPosition)
|
2021-02-05 19:06:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-21 13:03:58 +01:00
|
|
|
private val addPhotoResultContract = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
|
|
|
if (result.resultCode == Activity.RESULT_OK && result.data?.clipData != null) {
|
|
|
|
result.data?.clipData?.let {
|
2022-06-19 13:02:05 +02:00
|
|
|
model.setImages(model.addPossibleImages(it))
|
2021-03-21 13:03:58 +01:00
|
|
|
}
|
|
|
|
} else if (result.resultCode != Activity.RESULT_CANCELED) {
|
2022-07-28 19:35:21 +02:00
|
|
|
Toast.makeText(applicationContext, R.string.add_images_error, Toast.LENGTH_SHORT).show()
|
2021-03-21 13:03:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun addPhoto(){
|
|
|
|
addPhotoResultContract.launch(
|
|
|
|
Intent(this, CameraActivity::class.java)
|
|
|
|
)
|
2021-01-12 17:16:37 +01:00
|
|
|
}
|
|
|
|
|
2021-01-10 22:30:35 +01:00
|
|
|
private fun savePicture(button: View, currentPosition: Int) {
|
2022-06-19 14:28:00 +02:00
|
|
|
val originalUri = model.getPhotoData().value!![currentPosition].imageUri
|
|
|
|
|
|
|
|
val pair = getOutputFile(originalUri)
|
2021-01-10 22:30:35 +01:00
|
|
|
val outputStream: OutputStream = pair.first
|
|
|
|
val path: String = pair.second
|
2021-01-09 16:19:26 +01:00
|
|
|
|
2022-06-19 14:28:00 +02:00
|
|
|
contentResolver.openInputStream(originalUri)!!.use { input ->
|
2021-01-10 22:30:35 +01:00
|
|
|
outputStream.use { output ->
|
|
|
|
input.copyTo(output)
|
|
|
|
}
|
2021-01-09 16:19:26 +01:00
|
|
|
}
|
|
|
|
|
2021-01-10 22:30:35 +01:00
|
|
|
if(path.startsWith("file")) {
|
|
|
|
MediaScannerConnection.scanFile(
|
2021-02-07 22:55:34 +01:00
|
|
|
this,
|
|
|
|
arrayOf(path.toUri().toFile().absolutePath),
|
|
|
|
null
|
2021-01-10 22:30:35 +01:00
|
|
|
) { path, uri ->
|
|
|
|
if (uri == null) {
|
|
|
|
Log.e(
|
2021-02-07 22:55:34 +01:00
|
|
|
"NEW IMAGE SCAN FAILED",
|
|
|
|
"Tried to scan $path, but it failed"
|
2021-01-10 22:30:35 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Snackbar.make(
|
2021-02-07 22:55:34 +01:00
|
|
|
button, getString(R.string.save_image_success),
|
|
|
|
Snackbar.LENGTH_LONG
|
2021-01-10 22:30:35 +01:00
|
|
|
).show()
|
2021-01-09 16:19:26 +01:00
|
|
|
}
|
2021-01-10 22:30:35 +01:00
|
|
|
|
2022-06-19 14:28:00 +02:00
|
|
|
private fun getOutputFile(uri: Uri): Pair<OutputStream, String> {
|
|
|
|
val extension = uri.fileExtension(contentResolver)
|
|
|
|
|
|
|
|
val name = SimpleDateFormat("yyyy-MM-dd-HH-mm-ss-SSS", Locale.US)
|
|
|
|
.format(System.currentTimeMillis()) + ".$extension"
|
|
|
|
|
2021-01-09 16:19:26 +01:00
|
|
|
val outputStream: OutputStream
|
|
|
|
val path: String
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
|
|
val resolver: ContentResolver = contentResolver
|
2022-07-27 15:55:33 +02:00
|
|
|
val type = uri.getMimeType(contentResolver)
|
2021-01-09 16:19:26 +01:00
|
|
|
val contentValues = ContentValues()
|
|
|
|
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, name)
|
2022-06-19 14:28:00 +02:00
|
|
|
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, type)
|
2021-01-09 16:19:26 +01:00
|
|
|
contentValues.put(
|
2021-02-07 22:55:34 +01:00
|
|
|
MediaStore.MediaColumns.RELATIVE_PATH,
|
|
|
|
Environment.DIRECTORY_PICTURES
|
2021-01-09 16:19:26 +01:00
|
|
|
)
|
2022-07-27 15:55:33 +02:00
|
|
|
val store =
|
|
|
|
if (type.startsWith("video")) MediaStore.Video.Media.EXTERNAL_CONTENT_URI
|
|
|
|
else MediaStore.Images.Media.EXTERNAL_CONTENT_URI
|
|
|
|
val imageUri: Uri = resolver.insert(store, contentValues)!!
|
2021-01-09 16:19:26 +01:00
|
|
|
path = imageUri.toString()
|
|
|
|
outputStream = resolver.openOutputStream(Objects.requireNonNull(imageUri))!!
|
|
|
|
} else {
|
|
|
|
@Suppress("DEPRECATION") val imagesDir =
|
|
|
|
Environment.getExternalStoragePublicDirectory(getString(R.string.app_name))
|
|
|
|
imagesDir.mkdir()
|
|
|
|
val file = File(imagesDir, name)
|
|
|
|
path = Uri.fromFile(file).toString()
|
|
|
|
outputStream = file.outputStream()
|
|
|
|
}
|
|
|
|
return Pair(outputStream, path)
|
2020-05-21 19:31:41 +02:00
|
|
|
}
|
|
|
|
|
2021-01-09 16:19:26 +01:00
|
|
|
|
2022-06-18 22:21:19 +02:00
|
|
|
private fun validatePost(): Boolean {
|
2021-01-13 22:46:00 +01:00
|
|
|
binding.postTextInputLayout.run {
|
|
|
|
val content = editText?.length() ?: 0
|
|
|
|
if (content > counterMaxLength) {
|
|
|
|
// error, too many characters
|
2021-01-25 11:52:27 +01:00
|
|
|
error = resources.getQuantityString(R.plurals.description_max_characters, counterMaxLength, counterMaxLength)
|
2021-01-13 22:46:00 +01:00
|
|
|
return false
|
|
|
|
}
|
Feature/post creation (#83)
* added perm and features for cameraS, gps and external storage
* added camera activity accessible from main activity
* added button to redirect to camera activity
* implementing callback flow to use camera
* working camera
* added texture view for camera display
* added camera activity
* implemented texture listener
* camera not working, flow done, no feedback implemented
* camera working
* refactored code, still an activity
* added private to internal function, better error function handling
* deleted camera activity
* added camera fragment
* added camera fragment
* refactored camera as fragment
* necessary dependencies for fragment testing
* initial camera fragment test
* corrected access to activity form fragment
* Added state changes and termination
* added lines to test, to test coverage
* Removed unsupported state STARTED state transition
* Added basic tests to test code coverage
* use layout for tests, to trigger permissions requirements
* grant camera permission to app in camera test
* replaced null handlers by proper function getter
* changed layout, added takePictureButton
* using expresso to get code coverage on camea
* take picture flow not finished
* dummy change to camera test to perform new build
* added connection flow before test to reach main activity
* can take a picture and put it to ImageView
* replaced button text with images
* smaller buttons
* test camera fragment buttons
* added orientation handler
* changed icon to make travis happy
* test new espresso config for travis
* removed useless rule
* deleted useless val
* added layout ID's
* moved swipes from Before to Tests, and thread sleep
* stoped swiping, now tests from fragment directly
* start post creation flow
* use Uri when taking photo, can now go back from picture preview
* adjusted test and flow idea
* tests on displayed UI elements for the post creation fragment
* refactor camera fragment into transition new post fragemnt
* finished first phase: get a picture Uri
* fixed lint error found by travis CI
* added global timeout to test
* test the new way of test
* refactor new way of testing
* added in-app camera view and linked everything to the final flow + started API to post
* strugling on the upload media part
* upload image on server implemented
* post upload implemented
* added API call to get max_toot_chars and correct def of a post description
* fixed some tests
* fix tests: clicking on tabs make the app crash because of the camera fragment
* comment problematic chunk of code while samuel tries to fix it
* switch minimumsdk to api 24
* Revert "switch minimumsdk to api 24"
This reverts commit 24ce46dd82038b59732fd958e5e071ded39cd549.
* deactivited live camera for API 23
* tests for post creation fragment UI elements
* remove worthless UI testing and add gallery intent test
* removed camera intent for now
* some refactor
* lint error and more refactor
* more refactor on merge from master
* refactor and test for PostCreationActivity
* Revert "refactor and test for PostCreationActivity"
This reverts commit a0c146bcc545cdc3792df4806e6b0c908bd18747.
* Revert "Revert "refactor and test for PostCreationActivity""
This reverts commit 147a9ed80d5f9c9e3c38b5a977786bfb39eeb1b6.
* permissions correction for test
* updtated test
* fix a test and refactor
* relink correct fragment
* save picture locally
* test post button
* requested changes
* fixed required changes
* Revert "fixed required changes"
This reverts commit 405a9d4d1af05353e30028e60041cc1c97569c1b.
* redo change request
* added /media api response to mockserver
Co-authored-by: Andrea Clement <samuel.dietz@epfl.ch>
2020-04-24 12:44:12 +02:00
|
|
|
}
|
2022-06-19 13:02:05 +02:00
|
|
|
if(model.getPhotoData().value?.all { it.videoEncodeProgress == null } == false){
|
2022-06-18 22:21:19 +02:00
|
|
|
AlertDialog.Builder(this).apply {
|
|
|
|
setMessage(R.string.still_encoding)
|
|
|
|
setNegativeButton(android.R.string.ok) { _, _ -> }
|
|
|
|
}.show()
|
|
|
|
return false
|
|
|
|
}
|
Feature/post creation (#83)
* added perm and features for cameraS, gps and external storage
* added camera activity accessible from main activity
* added button to redirect to camera activity
* implementing callback flow to use camera
* working camera
* added texture view for camera display
* added camera activity
* implemented texture listener
* camera not working, flow done, no feedback implemented
* camera working
* refactored code, still an activity
* added private to internal function, better error function handling
* deleted camera activity
* added camera fragment
* added camera fragment
* refactored camera as fragment
* necessary dependencies for fragment testing
* initial camera fragment test
* corrected access to activity form fragment
* Added state changes and termination
* added lines to test, to test coverage
* Removed unsupported state STARTED state transition
* Added basic tests to test code coverage
* use layout for tests, to trigger permissions requirements
* grant camera permission to app in camera test
* replaced null handlers by proper function getter
* changed layout, added takePictureButton
* using expresso to get code coverage on camea
* take picture flow not finished
* dummy change to camera test to perform new build
* added connection flow before test to reach main activity
* can take a picture and put it to ImageView
* replaced button text with images
* smaller buttons
* test camera fragment buttons
* added orientation handler
* changed icon to make travis happy
* test new espresso config for travis
* removed useless rule
* deleted useless val
* added layout ID's
* moved swipes from Before to Tests, and thread sleep
* stoped swiping, now tests from fragment directly
* start post creation flow
* use Uri when taking photo, can now go back from picture preview
* adjusted test and flow idea
* tests on displayed UI elements for the post creation fragment
* refactor camera fragment into transition new post fragemnt
* finished first phase: get a picture Uri
* fixed lint error found by travis CI
* added global timeout to test
* test the new way of test
* refactor new way of testing
* added in-app camera view and linked everything to the final flow + started API to post
* strugling on the upload media part
* upload image on server implemented
* post upload implemented
* added API call to get max_toot_chars and correct def of a post description
* fixed some tests
* fix tests: clicking on tabs make the app crash because of the camera fragment
* comment problematic chunk of code while samuel tries to fix it
* switch minimumsdk to api 24
* Revert "switch minimumsdk to api 24"
This reverts commit 24ce46dd82038b59732fd958e5e071ded39cd549.
* deactivited live camera for API 23
* tests for post creation fragment UI elements
* remove worthless UI testing and add gallery intent test
* removed camera intent for now
* some refactor
* lint error and more refactor
* more refactor on merge from master
* refactor and test for PostCreationActivity
* Revert "refactor and test for PostCreationActivity"
This reverts commit a0c146bcc545cdc3792df4806e6b0c908bd18747.
* Revert "Revert "refactor and test for PostCreationActivity""
This reverts commit 147a9ed80d5f9c9e3c38b5a977786bfb39eeb1b6.
* permissions correction for test
* updtated test
* fix a test and refactor
* relink correct fragment
* save picture locally
* test post button
* requested changes
* fixed required changes
* Revert "fixed required changes"
This reverts commit 405a9d4d1af05353e30028e60041cc1c97569c1b.
* redo change request
* added /media api response to mockserver
Co-authored-by: Andrea Clement <samuel.dietz@epfl.ch>
2020-04-24 12:44:12 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-05-21 19:31:41 +02:00
|
|
|
private fun enableButton(enable: Boolean = true){
|
2021-01-13 01:28:08 +01:00
|
|
|
binding.postCreationSendButton.isEnabled = enable
|
2020-05-21 19:31:41 +02:00
|
|
|
if(enable){
|
2022-07-28 19:35:21 +02:00
|
|
|
binding.postingProgressBar.visibility = GONE
|
|
|
|
binding.postCreationSendButton.visibility = VISIBLE
|
2020-10-04 23:27:06 +02:00
|
|
|
} else {
|
2022-07-28 19:35:21 +02:00
|
|
|
binding.postingProgressBar.visibility = VISIBLE
|
|
|
|
binding.postCreationSendButton.visibility = GONE
|
2020-05-21 19:31:41 +02:00
|
|
|
}
|
Feature/post creation (#83)
* added perm and features for cameraS, gps and external storage
* added camera activity accessible from main activity
* added button to redirect to camera activity
* implementing callback flow to use camera
* working camera
* added texture view for camera display
* added camera activity
* implemented texture listener
* camera not working, flow done, no feedback implemented
* camera working
* refactored code, still an activity
* added private to internal function, better error function handling
* deleted camera activity
* added camera fragment
* added camera fragment
* refactored camera as fragment
* necessary dependencies for fragment testing
* initial camera fragment test
* corrected access to activity form fragment
* Added state changes and termination
* added lines to test, to test coverage
* Removed unsupported state STARTED state transition
* Added basic tests to test code coverage
* use layout for tests, to trigger permissions requirements
* grant camera permission to app in camera test
* replaced null handlers by proper function getter
* changed layout, added takePictureButton
* using expresso to get code coverage on camea
* take picture flow not finished
* dummy change to camera test to perform new build
* added connection flow before test to reach main activity
* can take a picture and put it to ImageView
* replaced button text with images
* smaller buttons
* test camera fragment buttons
* added orientation handler
* changed icon to make travis happy
* test new espresso config for travis
* removed useless rule
* deleted useless val
* added layout ID's
* moved swipes from Before to Tests, and thread sleep
* stoped swiping, now tests from fragment directly
* start post creation flow
* use Uri when taking photo, can now go back from picture preview
* adjusted test and flow idea
* tests on displayed UI elements for the post creation fragment
* refactor camera fragment into transition new post fragemnt
* finished first phase: get a picture Uri
* fixed lint error found by travis CI
* added global timeout to test
* test the new way of test
* refactor new way of testing
* added in-app camera view and linked everything to the final flow + started API to post
* strugling on the upload media part
* upload image on server implemented
* post upload implemented
* added API call to get max_toot_chars and correct def of a post description
* fixed some tests
* fix tests: clicking on tabs make the app crash because of the camera fragment
* comment problematic chunk of code while samuel tries to fix it
* switch minimumsdk to api 24
* Revert "switch minimumsdk to api 24"
This reverts commit 24ce46dd82038b59732fd958e5e071ded39cd549.
* deactivited live camera for API 23
* tests for post creation fragment UI elements
* remove worthless UI testing and add gallery intent test
* removed camera intent for now
* some refactor
* lint error and more refactor
* more refactor on merge from master
* refactor and test for PostCreationActivity
* Revert "refactor and test for PostCreationActivity"
This reverts commit a0c146bcc545cdc3792df4806e6b0c908bd18747.
* Revert "Revert "refactor and test for PostCreationActivity""
This reverts commit 147a9ed80d5f9c9e3c38b5a977786bfb39eeb1b6.
* permissions correction for test
* updtated test
* fix a test and refactor
* relink correct fragment
* save picture locally
* test post button
* requested changes
* fixed required changes
* Revert "fixed required changes"
This reverts commit 405a9d4d1af05353e30028e60041cc1c97569c1b.
* redo change request
* added /media api response to mockserver
Co-authored-by: Andrea Clement <samuel.dietz@epfl.ch>
2020-04-24 12:44:12 +02:00
|
|
|
|
2020-05-21 19:31:41 +02:00
|
|
|
}
|
|
|
|
|
2021-04-22 00:07:05 +02:00
|
|
|
private val editResultContract: ActivityResultLauncher<Intent> = registerForActivityResult(ActivityResultContracts.StartActivityForResult()){
|
2021-03-21 13:03:58 +01:00
|
|
|
result: ActivityResult? ->
|
|
|
|
if (result?.resultCode == Activity.RESULT_OK && result.data != null) {
|
2021-04-22 00:07:05 +02:00
|
|
|
val position: Int = result.data!!.getIntExtra(PhotoEditActivity.PICTURE_POSITION, 0)
|
2022-06-19 13:02:05 +02:00
|
|
|
model.modifyAt(position, result.data!!)
|
2022-07-28 19:35:21 +02:00
|
|
|
?: Toast.makeText(applicationContext, R.string.error_editing, Toast.LENGTH_SHORT).show()
|
2021-03-21 13:03:58 +01:00
|
|
|
} else if(result?.resultCode != Activity.RESULT_CANCELED){
|
2022-07-28 19:35:21 +02:00
|
|
|
Toast.makeText(applicationContext, R.string.error_editing, Toast.LENGTH_SHORT).show()
|
2020-06-05 23:49:28 +02:00
|
|
|
}
|
|
|
|
}
|
2021-03-21 13:03:58 +01:00
|
|
|
|
2022-06-18 22:21:19 +02:00
|
|
|
/**
|
|
|
|
* @param muted should audio tracks be removed in the output
|
|
|
|
* @param videoStart when we want to start the video, in seconds, or null if we
|
|
|
|
* don't want to remove the start
|
|
|
|
* @param videoEnd when we want to end the video, in seconds, or null if we
|
|
|
|
* don't want to remove the end
|
|
|
|
*/
|
|
|
|
private fun startEncoding(position: Int, muted: Boolean, videoStart: Float?, videoEnd: Float?) {
|
2022-06-19 13:02:05 +02:00
|
|
|
val originalUri = model.getPhotoData().value!![position].imageUri
|
2022-06-18 22:21:19 +02:00
|
|
|
|
|
|
|
// Having a meaningful suffix is necessary so that ffmpeg knows what to put in output
|
2022-06-19 14:28:00 +02:00
|
|
|
val suffix = originalUri.fileExtension(contentResolver)
|
2022-08-21 00:32:14 +02:00
|
|
|
val file = File.createTempFile("temp_video", ".$suffix", cacheDir)
|
|
|
|
//val file = File.createTempFile("temp_video", ".webm", cacheDir)
|
2022-06-19 13:02:05 +02:00
|
|
|
model.trackTempFile(file)
|
2022-06-18 22:21:19 +02:00
|
|
|
val fileUri = file.toUri()
|
2022-08-21 00:31:36 +02:00
|
|
|
val outputVideoPath = ffmpegCompliantUri(fileUri)
|
2022-06-18 22:21:19 +02:00
|
|
|
|
2022-06-19 13:02:05 +02:00
|
|
|
val inputUri = model.getPhotoData().value!![position].imageUri
|
2022-06-18 22:21:19 +02:00
|
|
|
|
2022-08-21 00:31:36 +02:00
|
|
|
val ffmpegCompliantUri: String = ffmpegCompliantUri(inputUri)
|
2022-06-18 22:21:19 +02:00
|
|
|
|
2022-08-21 00:31:36 +02:00
|
|
|
val mediaInformation: MediaInformation? = FFprobeKit.getMediaInformation(ffmpegCompliantUri(inputUri)).mediaInformation
|
2022-06-18 22:21:19 +02:00
|
|
|
val totalVideoDuration = mediaInformation?.duration?.toFloatOrNull()
|
|
|
|
|
2022-08-21 00:31:36 +02:00
|
|
|
val mutedString = if(muted) "-an" else null
|
|
|
|
val startString: List<String?> = if(videoStart != null) listOf("-ss", "$videoStart") else listOf(null, null)
|
2022-06-18 22:21:19 +02:00
|
|
|
|
2022-08-21 00:31:36 +02:00
|
|
|
val endString: List<String?> = if(videoEnd != null) listOf("-to", "${videoEnd - (videoStart ?: 0f)}") else listOf(null, null)
|
2022-06-18 22:21:19 +02:00
|
|
|
|
2022-08-21 00:31:36 +02:00
|
|
|
val session: FFmpegSession =
|
|
|
|
FFmpegKit.executeWithArgumentsAsync(listOfNotNull(startString[0], startString[1], "-i", ffmpegCompliantUri, endString[0], endString[1], "-c", "copy", mutedString, "-y", outputVideoPath).toTypedArray(),
|
2022-06-18 22:21:19 +02:00
|
|
|
//val session: FFmpegSession = FFmpegKit.executeAsync("$startString -i $inputSafePath $endString -c:v libvpx-vp9 -c:a copy -an -y $outputVideoPath",
|
|
|
|
{ session ->
|
|
|
|
val returnCode = session.returnCode
|
|
|
|
if (ReturnCode.isSuccess(returnCode)) {
|
|
|
|
fun successResult() {
|
|
|
|
// Hide progress indicator in carousel
|
|
|
|
binding.carousel.updateProgress(null, position, false)
|
2022-06-19 13:02:05 +02:00
|
|
|
val (imageSize, _) = outputVideoPath.toUri().let {
|
|
|
|
model.setUriAtPosition(it, position)
|
|
|
|
model.getSizeAndVideoValidate(it, position)
|
2022-06-18 22:21:19 +02:00
|
|
|
}
|
2022-06-19 13:02:05 +02:00
|
|
|
model.setVideoEncodeAtPosition(position, null)
|
|
|
|
model.setSizeAtPosition(imageSize, position)
|
2022-06-18 22:21:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
val post = resultHandler.post {
|
|
|
|
successResult()
|
|
|
|
}
|
|
|
|
if(!post) {
|
|
|
|
Log.e(TAG, "Failed to post changes, trying to recover in 100ms")
|
|
|
|
resultHandler.postDelayed({successResult()}, 100)
|
|
|
|
}
|
|
|
|
Log.d(TAG, "Encode completed successfully in ${session.duration} milliseconds")
|
|
|
|
} else {
|
|
|
|
resultHandler.post {
|
|
|
|
binding.carousel.updateProgress(null, position, error = true)
|
2022-06-19 13:02:05 +02:00
|
|
|
model.setVideoEncodeAtPosition(position, null)
|
2022-06-18 22:21:19 +02:00
|
|
|
}
|
|
|
|
Log.e(TAG, "Encode failed with state ${session.state} and rc $returnCode.${session.failStackTrace}")
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ log -> Log.d("PostCreationActivityEncoding", log.message) }
|
|
|
|
) { statistics: Statistics? ->
|
|
|
|
|
|
|
|
val timeInMilliseconds: Int? = statistics?.time
|
|
|
|
timeInMilliseconds?.let {
|
|
|
|
if (timeInMilliseconds > 0) {
|
|
|
|
val completePercentage = totalVideoDuration?.let {
|
|
|
|
val newTotalDuration = it - (videoStart ?: 0f) - (it - (videoEnd ?: it))
|
|
|
|
timeInMilliseconds / (10*newTotalDuration)
|
|
|
|
}
|
|
|
|
resultHandler.post {
|
|
|
|
completePercentage?.let {
|
2022-06-19 13:02:05 +02:00
|
|
|
val rounded: Int = it.roundToInt()
|
|
|
|
model.setVideoEncodeAtPosition(position, rounded)
|
2022-06-18 22:21:19 +02:00
|
|
|
binding.carousel.updateProgress(rounded, position, false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Log.d(TAG, "Encoding video: %$completePercentage.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-06-19 13:02:05 +02:00
|
|
|
model.registerNewFFmpegSession(position, session.sessionId)
|
2022-06-18 22:21:19 +02:00
|
|
|
}
|
|
|
|
|
2021-03-21 13:03:58 +01:00
|
|
|
private fun edit(position: Int) {
|
2022-06-10 23:41:29 +02:00
|
|
|
val intent = Intent(
|
|
|
|
this,
|
2022-06-19 13:02:05 +02:00
|
|
|
if(model.getPhotoData().value!![position].video) VideoEditActivity::class.java else PhotoEditActivity::class.java
|
2022-06-10 23:41:29 +02:00
|
|
|
)
|
2022-06-19 13:02:05 +02:00
|
|
|
.putExtra(PhotoEditActivity.PICTURE_URI, model.getPhotoData().value!![position].imageUri)
|
2022-06-10 23:41:29 +02:00
|
|
|
.putExtra(PhotoEditActivity.PICTURE_POSITION, position)
|
|
|
|
|
|
|
|
editResultContract.launch(intent)
|
|
|
|
|
2021-03-21 13:03:58 +01:00
|
|
|
}
|
2020-10-04 23:27:06 +02:00
|
|
|
}
|