Commit Graph

24 Commits

Author SHA1 Message Date
Christophe Beyls 65af26993b
Optimize I/O code using Okio (#4366)
This pull request takes advantage of the Okio library to simplify, fix
or improve performance of some I/O related code in Tusky.

- Return early or throw `FileNotFoundException` early in case
`contentResolver.openInputStream()` returns `null` instead of throwing
`NullPointerException` later. Change the signature of
`Closeable.closeQuietly()` to only accept a non-null `Closeable`.
- Reimplement `Uri.copyToFile()` using Okio. This takes advantage of the
built-in high-performance buffers of the library so a buffer doesn't
need to be allocated or managed manually. The new implementation also
makes sure that the input and output streams are always closed, as the
original code could in some cases return without properly closing a
stream.
- Reimplement `ProgressRequestBody` as `Uri.asRequestBody()` (adding to
the existing extension functions available in the Okio library to create
a `RequestBody`). The new implementation uses Okio's `Buffer` instead of
a manually managed byte array, which allows to avoid copying bytes from
one buffer to the next. The max number of bytes read at once was
increased from 2K to 8K to improve performance. Avoid division by zero
in case `contentLength` is `0`. Finally, this implementation now takes a
`Uri` as input instead of an `InputStream`, because a `RequestBody` must
be replayable in case Okio retries the request, and an `InputStream` can
only be used once.
2024-04-10 21:52:55 +02:00
Zongle Wang 1acae50845
Convert some sealed classes to interfaces (#4347)
There is no non-abstract field in them, we can just fall back to
interfaces.
2024-03-29 20:11:53 +01:00
Konrad Pozniak 5192fb08a5
upgrade ktlint plugin to 12.0.3 (#4169)
There are some new rules, I think they mostly make sense, except for the
max line length which I had to disable because we are over it in a lot
of places.

---------

Co-authored-by: Goooler <wangzongler@gmail.com>
2024-01-04 17:00:55 +01:00
Levi Bard f99cb6d1d5
Fix lint warnings (#4019)
Clears the baseline of issues in our code, and resolves most of the
straightforward warnings from the report
2023-09-13 09:20:53 +02:00
Konrad Pozniak d839f18267
update ktlint plugin to 11.3.1, format code (#3442) 2023-03-13 13:16:39 +01:00
Nik Clayton b8f4de9922
Sniff MIME type for audio/video files before upload (#3190)
MIME type detection for files based on extensions (the `getType()` method)
returns incorrect results from DownloadProvider and FileProvider for (at
least) .m4a files.

Investigation details are in https://github.com/tuskyapp/Tusky/issues/3189

Be safe, and use `MediaMetadataRetriever` to sniff the content of the files
to determine the correct type.

Fixes https://github.com/tuskyapp/Tusky/issues/3189
2023-01-21 14:54:40 +01:00
Konrad Pozniak abca91a420
Handoff media upload (#2947)
* handoff media upload to SendStatusService

* fix bugd

* improve code

* don't check processing state when upload returned 200
2022-12-29 19:58:23 +01:00
mcclure 7684f06938
Add UI for image-attachment "focus" (#2620)
* Attempt-zero implementation of a "focus" feature for image attachments. Choose "Set focus" in the attachment menu, tap once to select focus point (no visual feedback currently), tap "OK". Works in tests.

* Remove code duplication between 'update description' and 'update focus'

* Fix ktlint/bitrise failures

* Make updateMediaItem private

* When focus is set on a post attachment the preview focuses correctly. ProgressImageView now inherits from MediaPreviewImageView.

* Replace use of PointF for Focus where focus is represented, fix ktlint

* Substitute 'focus' for 'focus point' in strings

* First attempt draw focus point. Only updates on initial load. Modeled on code from RoundedCorners builtin from Glide

* Redraw focus after each tap

* Dark curtain where focus isn't (now looks like mastosoc)

* Correct ktlint for FocusDialog

* draft: switch to overlay for focus indicator

* Draw focus circle, but ImageView and FocusIndicatorView seem to share a single canvas

* Switch focus circle to path approach

* Correctly scale, save and load focuses. Clamp to visible area. Focus editor looks and feels right

* ktlint fixes and comments

* Focus indicator drawing should use device-independent pixels

* Shrink focus window when it gets unattractively tall (no linting, misbehaves on wide aspect ratio screens)

* Correct max-height behavior for screens in landscape mode

* Focus attachment result is are flipped on x axis; fix this

* Correctly thread focus through on scheduled posts, redrafted posts, and drafts (but draft focus is lost on post)

* More focus ktlint fixes

* Fix specific case where a draft is given a focus, then deleted, then posted in that order

* Fix accidental file change in focus PR

* ktLint fix

* Fix property style warnings in focus

* Fix remaining style warnings from focus PR

Co-authored-by: Conny Duck <k.pozniak@gmx.at>
2022-09-21 20:28:06 +02:00
QuirkyPony 17fb93626c
adapt file size error messages to show real instance upload limit (#2630)
* remove megabyte counts from file size error messages

The file size limits depend on the server; change strings to reflect that.

* show real file size limits instead of assuming Mastodon defaults

* correct previous commit

* correct previous commit (again)

* remove megabyte counts from file size error messages

The file size limits depend on the server; change strings to reflect that.

* Translated using Weblate (Galician)

Currently translated at 100.0% (489 of 489 strings)

Co-authored-by: XoseM <xosem@disroot.org>
Translate-URL: https://weblate.tusky.app/projects/tusky/tusky/gl/
Translation: Tusky/Tusky

* Translated using Weblate (Finnish)

Currently translated at 5.5% (1 of 18 strings)

Translation: Tusky/Tusky description
Translate-URL: https://weblate.tusky.app/projects/tusky/tusky-app/fi/

* correct previous commit

correct previous commit (again)

fixed type error caused by previous commits

* fix lint error...

* Update strings.xml

* improve code, calculate correct max size and format it

Co-authored-by: Laura <the-ceo-of-antifa@protonmail.com>
Co-authored-by: XoseM <xosem@disroot.org>
Co-authored-by: Konrad Pozniak <k.pozniak@gmx.at>
2022-08-05 18:55:13 +02:00
Konrad Pozniak 1b6a0908f6
Handle even more instance defaults (#2612)
* handle media size instance limits

* remove unused attributes from Instance entity

* support max_media_attachments

* support pleroma field limits, remove max_bio_chars support

* improve field input margin

* fix tests

* MAX_ACCOUNT_FIELDS -> DEFAULT_MAX_ACCOUNT_FIELDS

* improve "add field" button behavior

* fix copy paste mistake in AccountFieldEditAdapter

* refactor sendStatus to be a suspending function
2022-07-26 20:24:50 +02:00
Konrad Pozniak 62c4cfde89
improve media upload error messages (#2602) 2022-06-30 20:51:05 +02:00
tobi 530eb61505
Use NetworkResult in MediaUploadApi (#2577) 2022-06-06 16:04:33 +02:00
mcclure 00c139190e
Ability to crop images attached to posts (#2531)
* First attachment crop attempt: Can crop in place, but does not delete/replace on server so has no effect

* Attachment crop feature works

* ktlint fixes on attachment crop patch

* Upgrade Android-Image-Cropper to 4.2.1

* An error message should be displayed if attachment cropping fails and it is not because the user intentionally cancelled.

* Remove 2 of the 3 "state passing" variables by using MediaUtils

* Cropper should use content uri (MIME type bearing) and setOutputCompressFormat so that PNGs reach the server safely.

* Change to crop requested by Conny: Store inflight cropImageItemOld in view model

* Change to crop requested by Conny: Sort cropImage with the other contracts

* ktlint fixes on attachment crop patch (again)
2022-05-22 21:01:14 +02:00
Konrad Pozniak ce5ec15ff1
increase timeout for media uploads (#2489) 2022-05-01 17:16:22 +02:00
Konrad Pozniak d2bfceae7b
refactor compose & announcements to coroutines (#2446)
* refactor compose & announcements to coroutines

* fix code formatting

* add javadoc to InstanceInfoRepository

* fix comments in ImageDownsizer

* remove unused Either extensions

* add explicit return type for InstanceInfoRepository.getEmojis

* make ComposeViewModel.pickMedia return Result

* cleanup code in ImageDownsizer
2022-04-21 18:46:21 +02:00
Konrad Pozniak c47804997c
Improve handling of shared media (#2388)
* support file:// uris

* support subjects on image shares

* improve code

* improve code

* improve code
2022-03-28 18:39:05 +02:00
Konrad Pozniak eea81d7106
use POST api/v2/media to upload media (#2327) 2022-02-25 18:57:18 +01:00
Konrad Pozniak e29567c9ec
Cleanup dagger setup (#2300)
* cleanup dagger setup

* fix tests

* fix ktlint

* cleanup FragmentBuildersModule
2022-01-23 20:24:55 +01:00
Konrad Pozniak 16ffcca748
add ktlint plugin to project and apply default code style (#2209)
* add ktlint plugin to project and apply default code style

* some manual adjustments, fix wildcard imports

* update CONTRIBUTING.md

* fix formatting
2021-06-28 21:13:24 +02:00
Konrad Pozniak 40b24cd242
migrate to RxJava3 (#2146)
* migrate to RxJava3

* remove unused import
2021-05-16 19:53:27 +02:00
Konrad Pozniak 940d6d395a
Drafts v2 (#2032)
* cleanup warnings, reorganize some code

* move ComposeAutoCompleteAdapter to compose package

* composeOptions doesn't need to be a class member

* add DraftsActivity and DraftsViewModel

* drafts

* remove unnecessary Unit in ComposeViewModel

* add schema/25.json

* fix db migration

* drafts

* cleanup code

* fix compose activity rotation bug

* fix media descriptions getting lost when restoring a draft

* improve deleting drafts

* fix ComposeActivityTest

* improve draft layout for almost empty drafts

* reformat code

* show toast when opening reply to deleted toot

* improve item_draft layout
2021-01-21 18:57:09 +01:00
kyori19 e6b7d2ff9c
Fix large media uploading (#1800) 2020-05-21 14:50:19 +02:00
Levi Bard 9dccd06a06 Add support for uploading audio attachments (#1630)
* Add support for audio attachments.
Partially addresses #1337

* Register Tusky as a target for audio sharing

* Use icon with textColorTertiary for audio preview
2020-01-16 19:05:52 +01:00
Ivan Kupalov 8770fbe986 ComposeActivity refactor (#1541)
* Convert ComposeActivity to Kotlin

* More ComposeActivity cleanups

* Move ComposeActivity to it's own package

* Remove ComposeActivity.IntentBuilder

* Re-do part of the media downsizing/uploading

* Add sending of status to ViewModel, draft media descriptions

* Allow uploading video, update description after uploading

* Enable camera, enable upload cancelling

* Cleanup of ComposeActivity

* Extract CaptionDialog, extract ComposeActivity methods

* Fix handling of redrafted media

* Add initial state and media uploading out of Activity

* Change ComposeOptions.mentionedUsernames to be Set rather than List

We probably don't want repeated usernames when we are writing a post
and Set provides such guarantee for free plus it tells it to the
callers. The only disadvantage is lack of order but it shouldn't be a
problem.

* Add combineOptionalLiveData. Add docs.

It it useful for nullable LiveData's. I think we cannot differentiate
between value not being set and value being null so I just added the
variant without null check.

* Add poll support to Compose.

* cleanup code

* move more classes into compose package

* cleanup code

* fix button behavior

* add error handling for media upload

* add caching for instance data again

* merge develop

* fix scheduled toots

* delete unused string

* cleanup ComposeActivity

* fix restoring media from drafts

* make media upload code a little bit clearer

* cleanup autocomplete search code

* avoid duplicate object creation in SavedTootActivity

* perf: avoid unnecessary work when initializing ComposeActivity

* add license header to new files

* use small toot button on bigger displays

* fix ComposeActivityTest

* fix bad merge

* use Singles.zip instead of Single.zip
2019-12-19 19:09:40 +01:00