2020-12-26 12:10:54 +01:00
|
|
|
package com.h.pixeldroid.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
|
|
|
|
import android.content.*
|
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
|
2021-01-09 16:19:26 +01:00
|
|
|
import android.os.Build
|
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.os.Bundle
|
2021-01-09 16:19:26 +01:00
|
|
|
import android.os.Environment
|
|
|
|
import android.provider.MediaStore
|
2020-06-03 16:32:02 +02:00
|
|
|
import android.provider.OpenableColumns
|
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
|
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
|
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
|
2020-12-29 22:35:45 +01:00
|
|
|
import androidx.lifecycle.lifecycleScope
|
2021-01-09 16:19:26 +01:00
|
|
|
import com.google.android.material.snackbar.Snackbar
|
2020-12-26 12:10:54 +01:00
|
|
|
import com.h.pixeldroid.MainActivity
|
|
|
|
import com.h.pixeldroid.R
|
2021-01-13 01:28:08 +01:00
|
|
|
import com.h.pixeldroid.databinding.ActivityPostCreationBinding
|
2020-12-26 12:10:54 +01:00
|
|
|
import com.h.pixeldroid.postCreation.camera.CameraActivity
|
2021-01-12 17:16:37 +01:00
|
|
|
import com.h.pixeldroid.postCreation.carousel.CarouselItem
|
|
|
|
import com.h.pixeldroid.postCreation.carousel.ImageCarousel
|
2021-01-25 00:02:03 +01:00
|
|
|
import com.h.pixeldroid.postCreation.photoEdit.PhotoEditActivity
|
|
|
|
import com.h.pixeldroid.utils.BaseActivity
|
|
|
|
import com.h.pixeldroid.utils.api.PixelfedAPI
|
2020-12-26 12:10:54 +01:00
|
|
|
import com.h.pixeldroid.utils.api.objects.Attachment
|
2021-02-05 19:06:57 +01:00
|
|
|
import com.h.pixeldroid.utils.db.entities.InstanceDatabaseEntity
|
2021-01-25 00:02:03 +01:00
|
|
|
import com.h.pixeldroid.utils.db.entities.UserDatabaseEntity
|
2020-05-21 19:31:41 +02:00
|
|
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
|
|
|
import io.reactivex.disposables.Disposable
|
|
|
|
import io.reactivex.schedulers.Schedulers
|
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 okhttp3.MultipartBody
|
2020-12-29 22:35:45 +01:00
|
|
|
import retrofit2.HttpException
|
2021-01-09 16:19:26 +01:00
|
|
|
import java.io.File
|
2020-12-29 22:35:45 +01:00
|
|
|
import java.io.IOException
|
2021-01-09 16:19:26 +01:00
|
|
|
import java.io.OutputStream
|
|
|
|
import java.text.SimpleDateFormat
|
|
|
|
import java.util.*
|
|
|
|
import kotlin.collections.ArrayList
|
2021-02-05 19:06:57 +01:00
|
|
|
import kotlin.properties.Delegates
|
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-12-28 20:53:24 +01:00
|
|
|
private const val TAG = "Post Creation Activity"
|
|
|
|
private const val MORE_PICTURES_REQUEST_CODE = 0xffff
|
2020-10-04 23:27:06 +02:00
|
|
|
|
2021-01-10 22:30:35 +01:00
|
|
|
data class PhotoData(
|
|
|
|
var imageUri: Uri,
|
|
|
|
var uploadId: String? = null,
|
2021-01-25 00:02:03 +01:00
|
|
|
var progress: Int? = null,
|
|
|
|
var imageDescription: String? = 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
|
|
|
|
2020-12-20 18:39:50 +01:00
|
|
|
class PostCreationActivity : BaseActivity() {
|
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
|
|
|
|
|
|
|
private lateinit var accessToken: String
|
|
|
|
private lateinit var pixelfedAPI: PixelfedAPI
|
2020-06-05 23:49:28 +02:00
|
|
|
|
2021-02-05 19:06:57 +01:00
|
|
|
private var albumLimit by Delegates.notNull<Int>()
|
|
|
|
|
2020-06-05 23:49:28 +02:00
|
|
|
private var positionResult = 0
|
2020-05-19 09:49:34 +02:00
|
|
|
private var user: UserDatabaseEntity? = null
|
|
|
|
|
2021-01-10 22:30:35 +01:00
|
|
|
private val photoData: ArrayList<PhotoData> = ArrayList()
|
2020-05-21 19:31:41 +02:00
|
|
|
|
2021-01-13 01:28:08 +01:00
|
|
|
private lateinit var binding: ActivityPostCreationBinding
|
|
|
|
|
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()
|
|
|
|
|
|
|
|
val instance: InstanceDatabaseEntity = user?.run {
|
|
|
|
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
|
|
|
|
2021-02-05 19:06:57 +01:00
|
|
|
binding.postTextInputLayout.counterMaxLength = instance.maxStatusChars
|
2020-05-19 09:49:34 +02:00
|
|
|
|
2021-02-05 19:06:57 +01:00
|
|
|
albumLimit = instance.albumLimit
|
2020-10-05 13:21:59 +02:00
|
|
|
|
2021-02-05 19:06:57 +01:00
|
|
|
// get image URIs
|
|
|
|
intent.clipData?.let { addPossibleImages(it) }
|
2020-05-19 09:49:34 +02:00
|
|
|
|
|
|
|
accessToken = user?.accessToken.orEmpty()
|
2020-07-26 20:56:01 +02:00
|
|
|
pixelfedAPI = apiHolder.api ?: apiHolder.setDomainToCurrentUser(db)
|
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
|
|
|
|
2021-01-13 22:46:00 +01:00
|
|
|
val carousel: ImageCarousel = binding.carousel
|
2021-01-25 00:02:03 +01:00
|
|
|
carousel.addData(photoData.map { CarouselItem(it.imageUri) })
|
2021-01-12 17:16:37 +01:00
|
|
|
carousel.layoutCarouselCallback = {
|
|
|
|
if(it){
|
|
|
|
// Became a carousel
|
2021-01-13 01:28:08 +01:00
|
|
|
binding.toolbar3.visibility = VISIBLE
|
2021-01-12 17:16:37 +01:00
|
|
|
} else {
|
|
|
|
// Became a grid
|
2021-01-13 01:28:08 +01:00
|
|
|
binding.toolbar3.visibility = INVISIBLE
|
2021-01-12 17:16:37 +01:00
|
|
|
}
|
|
|
|
}
|
2021-02-06 17:31:56 +01:00
|
|
|
carousel.maxEntries = albumLimit
|
2021-01-12 17:16:37 +01:00
|
|
|
carousel.addPhotoButtonCallback = {
|
|
|
|
addPhoto(applicationContext)
|
|
|
|
}
|
2021-01-25 00:02:03 +01:00
|
|
|
carousel.updateDescriptionCallback = { position: Int, description: String ->
|
|
|
|
photoData[position].imageDescription = description
|
|
|
|
}
|
2020-06-05 23:49:28 +02:00
|
|
|
|
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 {
|
2021-01-10 22:30:35 +01:00
|
|
|
if (validateDescription() && photoData.isNotEmpty()) 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 {
|
2021-01-13 01:28:08 +01:00
|
|
|
binding.uploadError.visibility = View.GONE
|
2021-01-10 22:30:35 +01:00
|
|
|
photoData.forEach {
|
|
|
|
it.uploadId = null
|
|
|
|
it.progress = null
|
|
|
|
}
|
2020-05-21 19:31:41 +02:00
|
|
|
upload()
|
|
|
|
}
|
2021-01-09 16:19:26 +01:00
|
|
|
|
2021-01-13 22:46:00 +01:00
|
|
|
binding.editPhotoButton.setOnClickListener {
|
2021-01-10 22:30:35 +01:00
|
|
|
carousel.currentPosition.takeIf { it != -1 }?.let { currentPosition ->
|
|
|
|
edit(currentPosition)
|
|
|
|
}
|
2021-01-09 16:19:26 +01:00
|
|
|
}
|
|
|
|
|
2021-01-13 22:46:00 +01:00
|
|
|
binding.addPhotoButton.setOnClickListener {
|
2021-01-12 17:16:37 +01:00
|
|
|
addPhoto(it.context)
|
2021-01-09 16:19:26 +01:00
|
|
|
}
|
|
|
|
|
2021-01-13 22:46:00 +01:00
|
|
|
binding.savePhotoButton.setOnClickListener {
|
2021-01-10 22:30:35 +01:00
|
|
|
carousel.currentPosition.takeIf { it != -1 }?.let { currentPosition ->
|
|
|
|
savePicture(it, currentPosition)
|
|
|
|
}
|
|
|
|
}
|
2021-01-09 16:19:26 +01:00
|
|
|
|
|
|
|
|
2021-01-13 22:46:00 +01:00
|
|
|
binding.removePhotoButton.setOnClickListener {
|
2021-01-10 22:30:35 +01:00
|
|
|
carousel.currentPosition.takeIf { it != -1 }?.let { currentPosition ->
|
|
|
|
photoData.removeAt(currentPosition)
|
2021-01-25 00:02:03 +01:00
|
|
|
carousel.addData(photoData.map { CarouselItem(it.imageUri, it.imageDescription) })
|
2021-02-06 17:31:56 +01:00
|
|
|
binding.addPhotoButton.isEnabled = true
|
2021-01-09 16:19:26 +01:00
|
|
|
}
|
2021-01-10 22:30:35 +01:00
|
|
|
}
|
|
|
|
}
|
2021-01-09 16:19:26 +01:00
|
|
|
|
2021-02-05 19:06:57 +01:00
|
|
|
/**
|
|
|
|
* Will add as many images as possible to [photoData], from the [clipData], and if
|
|
|
|
* ([photoData].size + [clipData].itemCount) > [albumLimit] then it will only add as many images
|
|
|
|
* as are legal (if any) and a dialog will be shown to the user alerting them of this fact.
|
|
|
|
*/
|
|
|
|
private fun addPossibleImages(clipData: ClipData){
|
|
|
|
var count = clipData.itemCount
|
|
|
|
if(count + photoData.size > albumLimit){
|
|
|
|
AlertDialog.Builder(this).apply {
|
|
|
|
setMessage(getString(R.string.total_exceeds_album_limit).format(albumLimit))
|
|
|
|
setNegativeButton(android.R.string.ok) { _, _ -> }
|
|
|
|
}.show()
|
|
|
|
count = count.coerceAtMost(albumLimit - photoData.size)
|
|
|
|
}
|
2021-02-06 17:31:56 +01:00
|
|
|
if (count + photoData.size >= albumLimit) {
|
|
|
|
// Disable buttons to add more images
|
|
|
|
binding.addPhotoButton.isEnabled = false
|
|
|
|
}
|
2021-02-05 19:06:57 +01:00
|
|
|
for (i in 0 until count) {
|
|
|
|
clipData.getItemAt(i).uri.let {
|
|
|
|
photoData.add(PhotoData(it))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-12 17:16:37 +01:00
|
|
|
private fun addPhoto(context: Context){
|
|
|
|
val intent = Intent(context, CameraActivity::class.java)
|
|
|
|
this@PostCreationActivity.startActivityForResult(intent, MORE_PICTURES_REQUEST_CODE)
|
|
|
|
}
|
|
|
|
|
2021-01-10 22:30:35 +01:00
|
|
|
private fun savePicture(button: View, currentPosition: Int) {
|
|
|
|
val name = SimpleDateFormat("yyyy-MM-dd-HH-mm-ss-SSS", Locale.US)
|
|
|
|
.format(System.currentTimeMillis()) + ".png"
|
|
|
|
val pair = getOutputFile(name)
|
|
|
|
val outputStream: OutputStream = pair.first
|
|
|
|
val path: String = pair.second
|
2021-01-09 16:19:26 +01:00
|
|
|
|
2021-01-10 22:30:35 +01:00
|
|
|
contentResolver.openInputStream(photoData[currentPosition].imageUri)!!.use { input ->
|
|
|
|
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(
|
|
|
|
this,
|
|
|
|
arrayOf(path.toUri().toFile().absolutePath),
|
|
|
|
null
|
|
|
|
) { path, uri ->
|
|
|
|
if (uri == null) {
|
|
|
|
Log.e(
|
|
|
|
"NEW IMAGE SCAN FAILED",
|
|
|
|
"Tried to scan $path, but it failed"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Snackbar.make(
|
|
|
|
button, getString(R.string.save_image_success),
|
|
|
|
Snackbar.LENGTH_LONG
|
|
|
|
).show()
|
2021-01-09 16:19:26 +01:00
|
|
|
}
|
2021-01-10 22:30:35 +01:00
|
|
|
|
2021-01-09 16:19:26 +01:00
|
|
|
private fun getOutputFile(name: String): Pair<OutputStream, String> {
|
|
|
|
val outputStream: OutputStream
|
|
|
|
val path: String
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
|
|
val resolver: ContentResolver = contentResolver
|
|
|
|
val contentValues = ContentValues()
|
|
|
|
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, name)
|
|
|
|
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "image/png")
|
|
|
|
contentValues.put(
|
|
|
|
MediaStore.MediaColumns.RELATIVE_PATH,
|
|
|
|
Environment.DIRECTORY_PICTURES
|
|
|
|
)
|
|
|
|
val imageUri: Uri =
|
|
|
|
resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues)!!
|
|
|
|
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
|
|
|
|
2020-10-05 13:21:59 +02:00
|
|
|
private fun validateDescription(): 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
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-10-04 23:27:06 +02:00
|
|
|
/**
|
2021-01-13 01:28:08 +01:00
|
|
|
* Uploads the images that are in the [photoData] array.
|
|
|
|
* Keeps track of them in the [PhotoData.progress] (for the upload progress), and the
|
|
|
|
* [PhotoData.uploadId] (for the list of ids of the uploads).
|
2020-10-04 23:27:06 +02:00
|
|
|
*/
|
2021-01-10 22:30:35 +01:00
|
|
|
private fun upload() {
|
2020-10-04 23:27:06 +02:00
|
|
|
enableButton(false)
|
2021-01-13 01:28:08 +01:00
|
|
|
binding.uploadProgressBar.visibility = View.VISIBLE
|
|
|
|
binding.uploadCompletedTextview.visibility = View.INVISIBLE
|
|
|
|
binding.removePhotoButton.isEnabled = false
|
|
|
|
binding.editPhotoButton.isEnabled = false
|
|
|
|
binding.addPhotoButton.isEnabled = false
|
2020-10-04 23:27:06 +02:00
|
|
|
|
2021-01-13 01:28:08 +01:00
|
|
|
for (data: PhotoData in photoData) {
|
2021-01-10 22:30:35 +01:00
|
|
|
val imageUri = data.imageUri
|
2020-06-05 23:49:28 +02:00
|
|
|
val imageInputStream = contentResolver.openInputStream(imageUri)!!
|
|
|
|
|
|
|
|
val size =
|
|
|
|
if (imageUri.toString().startsWith("content")) {
|
|
|
|
contentResolver.query(imageUri, null, null, null, null)
|
|
|
|
?.use { cursor ->
|
|
|
|
/* Get the column indexes of the data in the Cursor,
|
|
|
|
* move to the first row in the Cursor, get the data,
|
|
|
|
* and display it.
|
|
|
|
*/
|
|
|
|
val sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE)
|
|
|
|
cursor.moveToFirst()
|
|
|
|
cursor.getLong(sizeIndex)
|
|
|
|
} ?: 0
|
|
|
|
} else {
|
|
|
|
imageUri.toFile().length()
|
|
|
|
}
|
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
|
|
|
val imagePart = ProgressRequestBody(imageInputStream, size)
|
|
|
|
val requestBody = MultipartBody.Builder()
|
|
|
|
.setType(MultipartBody.FORM)
|
|
|
|
.addFormDataPart("file", System.currentTimeMillis().toString(), imagePart)
|
|
|
|
.build()
|
|
|
|
|
|
|
|
val sub = imagePart.progressSubject
|
|
|
|
.subscribeOn(Schedulers.io())
|
|
|
|
.subscribe { percentage ->
|
2021-01-10 22:30:35 +01:00
|
|
|
data.progress = percentage.toInt()
|
2021-01-13 01:28:08 +01:00
|
|
|
binding.uploadProgressBar.progress =
|
2021-01-10 22:30:35 +01:00
|
|
|
photoData.sumBy { it.progress ?: 0 } / photoData.size
|
2020-06-05 23:49:28 +02:00
|
|
|
}
|
2020-05-21 19:31:41 +02:00
|
|
|
|
2020-06-05 23:49:28 +02:00
|
|
|
var postSub: Disposable? = null
|
2021-01-25 18:54:55 +01:00
|
|
|
|
|
|
|
val description = data.imageDescription?.let { MultipartBody.Part.createFormData("description", it) }
|
|
|
|
|
|
|
|
|
|
|
|
val inter = pixelfedAPI.mediaUpload("Bearer $accessToken", description, requestBody.parts[0])
|
2020-06-05 23:49:28 +02:00
|
|
|
|
|
|
|
postSub = inter
|
|
|
|
.subscribeOn(Schedulers.io())
|
|
|
|
.observeOn(AndroidSchedulers.mainThread())
|
|
|
|
.subscribe(
|
|
|
|
{ attachment: Attachment ->
|
2021-01-10 22:30:35 +01:00
|
|
|
data.progress = 0
|
|
|
|
data.uploadId = attachment.id!!
|
2020-06-05 23:49:28 +02:00
|
|
|
},
|
|
|
|
{ e ->
|
2021-01-13 01:28:08 +01:00
|
|
|
binding.uploadError.visibility = View.VISIBLE
|
2020-06-05 23:49:28 +02:00
|
|
|
e.printStackTrace()
|
|
|
|
postSub?.dispose()
|
|
|
|
sub.dispose()
|
|
|
|
},
|
|
|
|
{
|
2021-01-10 22:30:35 +01:00
|
|
|
data.progress = 100
|
2021-01-25 18:18:56 +01:00
|
|
|
if(photoData.all{it.progress == 100 && it.uploadId != null}){
|
2021-01-13 01:28:08 +01:00
|
|
|
binding.uploadProgressBar.visibility = View.GONE
|
|
|
|
binding.uploadCompletedTextview.visibility = View.VISIBLE
|
2021-01-10 22:30:35 +01:00
|
|
|
post()
|
2020-06-05 23:49:28 +02:00
|
|
|
}
|
|
|
|
postSub?.dispose()
|
|
|
|
sub.dispose()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
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
|
|
|
private fun post() {
|
2021-01-13 01:28:08 +01:00
|
|
|
val description = binding.newPostDescriptionInputField.text.toString()
|
2020-05-21 19:31:41 +02:00
|
|
|
enableButton(false)
|
2020-12-29 22:35:45 +01:00
|
|
|
lifecycleScope.launchWhenCreated {
|
|
|
|
try {
|
|
|
|
pixelfedAPI.postStatus(
|
|
|
|
authorization = "Bearer $accessToken",
|
|
|
|
statusText = description,
|
2021-01-10 22:30:35 +01:00
|
|
|
media_ids = photoData.mapNotNull { it.uploadId }.toList()
|
2020-12-29 22:35:45 +01:00
|
|
|
)
|
|
|
|
Toast.makeText(applicationContext,getString(R.string.upload_post_success),
|
|
|
|
Toast.LENGTH_SHORT).show()
|
|
|
|
val intent = Intent(this@PostCreationActivity, MainActivity::class.java)
|
|
|
|
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
|
|
|
startActivity(intent)
|
|
|
|
} catch (exception: IOException) {
|
|
|
|
Toast.makeText(applicationContext,getString(R.string.upload_post_error),
|
|
|
|
Toast.LENGTH_SHORT).show()
|
|
|
|
Log.e(TAG, exception.toString())
|
2020-05-21 19:31:41 +02:00
|
|
|
enableButton(true)
|
2020-12-29 22:35:45 +01:00
|
|
|
} catch (exception: HttpException) {
|
2020-05-21 15:22:57 +02:00
|
|
|
Toast.makeText(applicationContext,getString(R.string.upload_post_failed),
|
|
|
|
Toast.LENGTH_SHORT).show()
|
2020-12-29 22:35:45 +01:00
|
|
|
Log.e(TAG, exception.response().toString() + exception.message().toString())
|
|
|
|
enableButton(true)
|
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-12-29 22:35:45 +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
|
|
|
}
|
2020-06-05 23:49:28 +02:00
|
|
|
|
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){
|
2021-01-13 01:28:08 +01:00
|
|
|
binding.postingProgressBar.visibility = View.GONE
|
|
|
|
binding.postCreationSendButton.visibility = View.VISIBLE
|
2020-10-04 23:27:06 +02:00
|
|
|
} else {
|
2021-01-13 01:28:08 +01:00
|
|
|
binding.postingProgressBar.visibility = View.VISIBLE
|
|
|
|
binding.postCreationSendButton.visibility = View.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-01-10 22:30:35 +01:00
|
|
|
private fun edit(position: Int) {
|
2020-06-05 23:49:28 +02:00
|
|
|
positionResult = position
|
|
|
|
|
|
|
|
val intent = Intent(this, PhotoEditActivity::class.java)
|
2021-01-10 22:30:35 +01:00
|
|
|
.putExtra("picture_uri", photoData[position].imageUri)
|
2020-06-05 23:49:28 +02:00
|
|
|
.putExtra("no upload", false)
|
|
|
|
startActivityForResult(intent, positionResult)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data)
|
|
|
|
if (requestCode == positionResult) {
|
|
|
|
if (resultCode == Activity.RESULT_OK && data != null) {
|
2021-01-10 22:30:35 +01:00
|
|
|
photoData[positionResult].imageUri = data.getStringExtra("result")!!.toUri()
|
2021-01-09 16:19:26 +01:00
|
|
|
|
2021-01-25 00:02:03 +01:00
|
|
|
binding.carousel.addData(photoData.map { CarouselItem(it.imageUri, it.imageDescription) })
|
2021-01-09 16:19:26 +01:00
|
|
|
|
2021-01-10 22:30:35 +01:00
|
|
|
photoData[positionResult].progress = null
|
|
|
|
photoData[positionResult].uploadId = null
|
2021-01-09 16:19:26 +01:00
|
|
|
} else if(resultCode != Activity.RESULT_CANCELED){
|
2020-06-05 23:49:28 +02:00
|
|
|
Toast.makeText(applicationContext, "Error while editing", Toast.LENGTH_SHORT).show()
|
|
|
|
}
|
2020-10-04 23:27:06 +02:00
|
|
|
} else if (requestCode == MORE_PICTURES_REQUEST_CODE) {
|
|
|
|
|
2021-02-05 19:06:57 +01:00
|
|
|
if (resultCode == Activity.RESULT_OK && data?.clipData != null) {
|
|
|
|
data.clipData?.let {
|
|
|
|
addPossibleImages(it)
|
2020-10-04 23:27:06 +02:00
|
|
|
}
|
2021-01-09 16:19:26 +01:00
|
|
|
|
2021-01-25 00:02:03 +01:00
|
|
|
binding.carousel.addData(photoData.map { CarouselItem(it.imageUri, it.imageDescription) })
|
2021-01-09 16:19:26 +01:00
|
|
|
} else if(resultCode != Activity.RESULT_CANCELED){
|
2020-10-04 23:27:06 +02:00
|
|
|
Toast.makeText(applicationContext, "Error while adding images", Toast.LENGTH_SHORT).show()
|
|
|
|
}
|
2020-06-05 23:49:28 +02:00
|
|
|
}
|
|
|
|
}
|
2020-10-04 23:27:06 +02:00
|
|
|
}
|