Compare commits

...

370 Commits

Author SHA1 Message Date
Shadowfacts 14e8c11f02
Bump build number and update changelog 2020-09-16 19:19:40 -04:00
Shadowfacts 9d9ea565f1
Fix crash opening Preferences with deleted accounts 2020-09-16 17:52:00 -04:00
Shadowfacts 99db842411
Fix content warning not being copied when replying 2020-09-16 17:41:27 -04:00
Shadowfacts 184fe49c0f
Fix visibility not being copied when replying 2020-09-16 17:32:01 -04:00
Shadowfacts 4719342a06
Bump build number and update changelog 2020-09-15 22:22:20 -04:00
Shadowfacts 6df5f7fb08
Add preferences for auto-expanding CW'd posts and disabling long post
collapsing

See #105
2020-09-15 21:37:08 -04:00
Shadowfacts 02135aa0de
Use inset list style for preferences on iOS 14 2020-09-15 20:48:53 -04:00
Shadowfacts be5a4c03a6
Fix attachments not being posted in the correct order. 2020-09-14 23:29:31 -04:00
Shadowfacts 2c1ba7926e
Support JSON request bodies 2020-09-14 23:25:26 -04:00
Shadowfacts 911e66a159
Allow more browsing of instance public timelines
Closes #74
2020-09-13 15:51:08 -04:00
Shadowfacts ab4bcfa50f
Fix profile screen title not being set 2020-09-13 15:34:45 -04:00
Shadowfacts b94bfca406
Fix crash tapping attachments on instance public timelines 2020-09-13 13:55:33 -04:00
Shadowfacts 7999ecafd0
Update SheetController 2020-09-13 13:27:52 -04:00
Shadowfacts 1c6e464a4c
Start Compose screen tests 2020-09-13 13:19:56 -04:00
Shadowfacts acd01a81cc
More UI tests for onboarding/my profile 2020-09-12 22:16:58 -04:00
Shadowfacts 8ac3deb55a
Remove old file 2020-09-12 22:04:41 -04:00
Shadowfacts 5e9cc430c6
Use cross fade transitions for displaying gallery and asset picker if
Reduce Motion/Prefer Cross Fade is enabled

Closes #108
2020-09-12 13:25:59 -04:00
Shadowfacts 0b6ef6517b
Fix gallery action buttons not being centered in device "ears" on iPhone
XR and 11
2020-09-12 12:01:16 -04:00
Shadowfacts 34a01094f7
Fix gallery expand animation description not starting at correct
position

Safe are insets weren't being taken into account when hiding the
controls, because the toVC had not yet been added to the container view
and thus didn't have anything to receive insets from.
2020-09-12 12:01:16 -04:00
Shadowfacts 95b215c6b5
Add Clear Image Cache option to Advanced prefs 2020-09-12 12:01:16 -04:00
Shadowfacts e21dceb3b3
Tweak gallery spring animation parameters 2020-09-12 12:01:16 -04:00
Shadowfacts 9534f19262
Show BlurHash previews of attachments 2020-09-12 12:01:08 -04:00
Shadowfacts e44ae29775
Improve asset picker opening animation 2020-09-10 23:24:24 -04:00
Shadowfacts a5b30c4243
Update PLCrashReporter 2020-09-10 23:24:14 -04:00
Shadowfacts 479ca23e00
Tweak follow request notification cells 2020-09-10 22:54:01 -04:00
Shadowfacts 5b03e0cf12
Fix follow notifications not showing names for users without explicit
display names
2020-09-09 18:45:38 -04:00
Shadowfacts 7c4bbfd730
Improve compose posting error messages 2020-09-09 18:33:59 -04:00
Shadowfacts e19a6528ad
Improve gallery expand animation
Use spring timing, slide in top/bottom controls
2020-09-08 23:41:15 -04:00
Shadowfacts f5110c773a
Tweak default font sizes 2020-09-07 18:49:25 -04:00
Shadowfacts fe1db72f19
Fix save draft sheet showing even when draft had no content 2020-09-07 17:15:18 -04:00
Shadowfacts b4ddb8f533
Fix safe area on Compose screen not including keyboard on iOS 13 2020-09-07 17:05:50 -04:00
Shadowfacts 9a4ddfea3f
Fix Compose reply scroll effect not working on iOS 13 2020-09-07 16:56:06 -04:00
Shadowfacts dd8a196630
Show custom emoji in display names on Compose screen 2020-09-07 15:22:06 -04:00
Shadowfacts 3da7aacb35
Fix visiblity context menu in main text view accessory not updating 2020-09-07 14:46:17 -04:00
Shadowfacts 39c8162931
Prevent attempting to add an attachment when the possibility would be
invalid
2020-09-07 14:44:56 -04:00
Shadowfacts fe95cb9e1a
Replace Draw Something context menu item with dedicated button
Fixes add attachment button not working on iOS 13. Adding a context menu
to a Button inside a List on iOS 13 prevents the button from ever
recognizing taps.
2020-09-07 14:41:31 -04:00
Shadowfacts ec2d510be2
Fix crash when opening Compose screen on iOS 13 2020-09-06 23:27:43 -04:00
Shadowfacts 262aadf807
Fix very bad performance when laying out Compose reply view
Using a non-scrolling UITextView wrapped in SwiftUI combined with the
old hack of fixing its layout by passing the view controller's width
down to the wrapped view caused very slow layouts, resulting in
significant lag when typing into the main text view of the compose
screen.
2020-09-06 22:47:02 -04:00
Shadowfacts 9dce94c014
Fix acounts not updating locally
Fix reblogged statuses potentially not updating
2020-09-06 16:03:03 -04:00
Shadowfacts d008b882cb
Use context menu for visibility on iOS 14 2020-08-31 23:07:41 -04:00
Shadowfacts 3d13df87f0
Add pointer interaction to main status favorites/reblogs buttons 2020-08-31 21:40:18 -04:00
Shadowfacts f0582739cc
Re-add Compose button to Profile screen
Add menu with Direct Message option
2020-08-31 21:39:36 -04:00
Shadowfacts 4c82b1a341
Rewrite Compose screen in SwiftUI 2020-08-31 19:28:50 -04:00
Shadowfacts b55a96d649
Fix crash when resizing split view on iPad if Explore search controller
hadn't been created yet
2020-08-30 19:57:32 -04:00
Shadowfacts 77ac8cbe40
Bump deployment target to iOS 13.4 2020-08-30 19:28:11 -04:00
Shadowfacts e026c9a6c6
Bump build number and update changelog 2020-08-17 19:06:56 -04:00
Shadowfacts 3937dde2bf
Fix crash when selecting attachments on iOS 13 2020-08-17 18:52:54 -04:00
Shadowfacts 95ebca04d2
Disable automatic GIF playback in low-power mode 2020-08-16 19:14:32 -04:00
Shadowfacts 0986fa285e
Fix crash due to leaked table view cell 2020-08-16 15:07:59 -04:00
Shadowfacts 1cd3e6adf9
Show custom emoji in profile field names 2020-08-16 15:07:55 -04:00
Shadowfacts 722b81dad9
Group appearance prefs into sections 2020-08-16 14:58:10 -04:00
Shadowfacts 059f7307b3
Let system uppercase section headers 2020-08-16 14:58:02 -04:00
Shadowfacts ee20c95a5d
Prevent link activation when outside character 2020-08-16 14:52:08 -04:00
Shadowfacts be81ffb61f
Allow display names to shrink to fit available width 2020-08-16 14:49:44 -04:00
Shadowfacts 08e0c3769f
Make link preview background opaque 2020-08-16 14:45:01 -04:00
Shadowfacts 6d7c9fd553
Make tap targets on status action buttons larger 2020-08-16 14:41:30 -04:00
Shadowfacts 9b04b75949
Prevent potential race condition when loading additional statuses 2020-08-16 10:29:31 -04:00
Shadowfacts 273b74ddfb
Bump build number and update changelog 2020-08-15 22:10:44 -04:00
Shadowfacts ae055f1ffd
Remove debug code 2020-08-15 18:00:47 -04:00
Shadowfacts eef9b96a1a
Fix crash when showing profile for uncached account 2020-08-15 18:00:18 -04:00
Shadowfacts 29aed65b99
Fix crash if profile header view outlives VC 2020-08-15 17:59:14 -04:00
Shadowfacts 090746f292
Disallow opening universal links from Open in Safari context menu action 2020-08-15 17:48:58 -04:00
Shadowfacts af300a3559
Remove unused TuskerNavigationDelegate customization points 2020-08-15 17:47:33 -04:00
Shadowfacts 79eb23ef5d
Remove unused preference 2020-08-15 17:43:31 -04:00
Shadowfacts 60565f9625
Fix crash if status table view cell outlives VC 2020-08-15 17:37:56 -04:00
Shadowfacts 70bedf17a8
Set app category 2020-08-15 17:36:23 -04:00
Shadowfacts 392e51eb3e
Remove unnecessary prefernces change notification 2020-08-15 17:31:24 -04:00
Shadowfacts 86d5a73c85
Change menu item order
Open in Safari should be the closest to the user's finger when tapping a
menu button
2020-08-15 17:20:09 -04:00
Shadowfacts eaefa366b7
Fix displaying images on iOS 14 2020-08-15 17:03:02 -04:00
Shadowfacts 79b23127e9
Fix crash on refreshing 2020-08-15 14:15:38 -04:00
Shadowfacts f9b85c87b4
Fix crash on launch due to unloaded sidebar VC 2020-08-15 13:55:47 -04:00
Shadowfacts 260bedcf10
Fix retain cycle between status cells and menu actions 2020-07-07 23:23:39 -04:00
Shadowfacts fe09c5e522
Switch asset picker to use diffable data sources 2020-07-06 18:16:18 -04:00
Shadowfacts 985d30a401 Add background to image descriptions so they're visible against light backgrounds
Closes #102
2020-07-06 17:48:19 -04:00
Shadowfacts 794594805c Prevent needlessly prefetching non-image attachments 2020-07-06 00:00:55 -04:00
Shadowfacts 1c708732f2 Exclude iOS 14-specific code from compilation on Xcode 11 to allow building for TestFlight 2020-07-06 00:00:51 -04:00
Shadowfacts db30471011 Fix not being able to refresh timelines 2020-07-05 16:30:16 -04:00
Shadowfacts 2825345c7e Add switching between Posts, Posts and Replies, and Media pages of user profiles
Closes #103
2020-07-05 16:17:56 -04:00
Shadowfacts f3d01c47c3 Merge branch 'develop-xcode-12' into ios-14 2020-07-04 11:21:00 -04:00
Shadowfacts caab5e357a Fix crash loading audio attachment uploaded on Mastodon
Closes #104
2020-07-03 22:13:49 -04:00
Shadowfacts 2916d7a72d Add tapping the active tab bar item to scroll to top
Closes #106
2020-07-03 19:36:52 -04:00
Shadowfacts d190636fbd Fix Preferences button not appearing (again) 2020-07-03 19:36:08 -04:00
Shadowfacts 4e4701ead5 Use SwiftSoup from SPM instead of Git submodule 2020-07-03 19:09:58 -04:00
Shadowfacts b07efc150c Use App Group for user defaults 2020-07-03 18:54:21 -04:00
Shadowfacts 19fa12391d Fix Preferences button not appearing 2020-07-03 18:53:19 -04:00
Shadowfacts c55ea2e005 More link context menu preview tweaks 2020-07-03 18:52:35 -04:00
Shadowfacts 47dc00ab8f Fix sometimes broken masking of text view link preview animations 2020-07-03 18:52:23 -04:00
Shadowfacts fdcdbced38 Limit context menu previews in ContentTextView to link's text line rects 2020-07-03 18:50:37 -04:00
Shadowfacts e70a84274e Fix showing instance public timeline 2020-07-03 18:50:22 -04:00
Shadowfacts 641ab765a7 Fix crash when displaying search results 2020-07-03 18:50:05 -04:00
Shadowfacts 986fc5b833 Prevent crash when displaying accounts with no pinned statuses 2020-07-03 18:49:55 -04:00
Shadowfacts cf5b97d9c8 Fix crash showing custom instance on iOS 14 2020-07-03 18:49:28 -04:00
Shadowfacts 7f0fd119c5 Use App Group for user defaults 2020-07-03 18:45:37 -04:00
Shadowfacts b2c7735256 Fix Preferences button not appearing 2020-07-03 18:44:38 -04:00
Shadowfacts 1d815d6cd6 More link context menu preview tweaks 2020-07-03 17:01:52 -04:00
Shadowfacts f86d3a0ed1 Fix sometimes broken masking of text view link preview animations 2020-07-01 00:01:36 -04:00
Shadowfacts 864fd77ecc Sync active tab and navigation stack between split view/tab bar controllers 2020-06-29 22:21:03 -04:00
Shadowfacts 78da04162f Fix missing file from project.pbxproj 2020-06-29 21:47:11 -04:00
Shadowfacts 40a742139b Fix menu state getting out of sync with bookmarked/muted state 2020-06-27 13:13:04 -04:00
Shadowfacts 8bbc572fa7 Replace more with share button for timeline status swipe actions 2020-06-27 10:47:31 -04:00
Shadowfacts 2a8e970738 Use context menus as primary actions for 'More Actions' buttons on >= iOS 14 2020-06-27 00:22:14 -04:00
Shadowfacts 3abb5972b9 Limit context menu previews in ContentTextView to link's text line rects 2020-06-25 10:42:46 -04:00
Shadowfacts 0c06d91f6b Fix showing instance public timeline 2020-06-24 16:41:01 -04:00
Shadowfacts 6cf6db6a8d Add sidebar on iPadOS 14 2020-06-24 16:40:45 -04:00
Shadowfacts fb11e36467 Fix crash when displaying search results 2020-06-24 15:42:56 -04:00
Shadowfacts 0fa87e9177 Prevent crash when displaying accounts with no pinned statuses 2020-06-23 22:21:50 -04:00
Shadowfacts 5cb84e271a Prefer ephemeral sessions in ASWebAuthneticationSession 2020-06-23 21:35:14 -04:00
Shadowfacts 50f1a9a7de Change ComposeDrawingViewController to use drawingPolicy on iOS 14 2020-06-23 19:33:14 -04:00
Shadowfacts 154fc7cd02 Fix ASWebAuthenticationSession usage in Catalyst 2020-06-23 19:32:30 -04:00
Shadowfacts 01d765fa45 Enable Catalyst 2020-06-23 19:32:04 -04:00
Shadowfacts 04aad1252a Use SwiftSoup from SPM instead of Git submodule 2020-06-23 19:31:32 -04:00
Shadowfacts 43779e42df Fix crash showing custom instance on iOS 14 2020-06-23 19:27:34 -04:00
Shadowfacts a5a2cd147e
Fix attachment blur view missing corner radius 2020-06-22 21:03:08 -04:00
Shadowfacts 0e91fc239d
Fix missing anchor for Compose screen visibility popover 2020-06-22 09:53:20 -04:00
Shadowfacts 0e5aab75df
Bump build number 2020-06-21 19:32:47 -04:00
Shadowfacts c715d11fc2
Add CHANGELOG.md 2020-06-21 19:32:08 -04:00
Shadowfacts 8010e86711
Change attachment views to be 16:9 2020-06-21 16:01:34 -04:00
Shadowfacts a41d27f18c
Move status action buttons back below attachments 2020-06-21 16:01:34 -04:00
Shadowfacts 083add273b
Prevent audio from other apps pausing when showing gifv attachments
Fixes #101
2020-06-21 16:01:29 -04:00
Shadowfacts 64365bdf2b
Fix compose attachments being cut off at the bottom of the safe area 2020-06-21 10:31:40 -04:00
Shadowfacts 6adcad63b3
Add crash report helper 2020-06-20 23:11:35 -04:00
Shadowfacts 393a134648
Don't show Follow activity for user's own account 2020-06-19 23:00:59 -04:00
Shadowfacts ba3e9e7491
Fix compose attachment description text view not expanding to fit text 2020-06-19 19:46:08 -04:00
Shadowfacts 920f926b48
Add text recognition image description for image attachments 2020-06-19 19:14:24 -04:00
Shadowfacts 6e27399e10
Fix loading additional statuses on profiles not working
This was a regression introduced in
d27bddb2ca which removed the didSet
handlers which called reloadData on the pinnedStatuses/timelineSegments
property without adding the appropriate insertRows calls where they were
modified.
2020-06-18 22:39:04 -04:00
Shadowfacts c3c19b1994
Fix pin image still showing on statuses after cell reuse 2020-06-18 22:23:19 -04:00
Shadowfacts 1f40cc9928
Show controls/description for gifv attachments
See #98
2020-06-17 23:33:48 -04:00
Shadowfacts 66020b7847
Add preference for always showing status visiblity icon 2020-06-17 18:00:13 -04:00
Shadowfacts 00bf99334f
Add preference for status reply icons 2020-06-17 17:45:34 -04:00
Shadowfacts 3aef7d4d93
Organize Preferences.swift 2020-06-17 17:40:36 -04:00
Shadowfacts a901af6be9
Merge branch 'private-beta' into develop 2020-06-16 23:19:33 -04:00
Shadowfacts b623e348c2 Fix crash when opening compose screen before initial network requests completed 2020-06-16 23:13:46 -04:00
Shadowfacts 056346cee9
Add reply indicator to statuses in timelines 2020-06-16 23:06:36 -04:00
Shadowfacts 30c04b49e7
Add visibility indicator to statuses 2020-06-16 23:00:39 -04:00
Shadowfacts 848022ec6e
Disable reblog button for private posts 2020-06-16 22:47:30 -04:00
Shadowfacts 39e847bda8
Fix reblog label showing incorrect account 2020-06-16 22:47:04 -04:00
Shadowfacts 5d751cd994
Prevent redundant status database lookups 2020-06-15 23:22:45 -04:00
Shadowfacts d27bddb2ca Fix profile header image not showing up on first load
The issue occurred because the profile header would kick off a request
upon loading, then the profile table would request the initial set of
statuses shortly thereafter which would result in reloadData being called
which would cancel the request without removing the group, so the request
generated by the newly-reloaded header cell would attach a callback to
the cancelled request, resulting in the header image never displaying.
2020-06-15 22:34:42 -04:00
Shadowfacts 36326e4469
Make network requests in viewWillAppear instead of viewDidLoad 2020-06-15 19:41:51 -04:00
Shadowfacts 6b7904ed52
Improve profile field layout 2020-06-15 19:02:09 -04:00
Shadowfacts 61c6d63c67
Fix profile fields not displaying
Closes #96
2020-06-15 18:36:04 -04:00
Shadowfacts c0316f55ef
Fix crash when sharing large image on iPad 2020-06-15 18:29:04 -04:00
Shadowfacts 803ba50f53
Add pointer interaction to remove attachment, large image share/dismiss buttons 2020-06-15 18:26:56 -04:00
Shadowfacts 5d0c59e863
Prompt for Photos access before showing asset picker 2020-06-15 18:15:05 -04:00
Shadowfacts c7b4d00da7
Fix race condition loading bookmarks 2020-06-15 18:02:07 -04:00
Shadowfacts f2a8b91769
Provide metadata to UIActivityViewController
Closes #56
2020-05-14 22:43:56 -04:00
Shadowfacts ce464dfb9f
Add mute/unmute conversation status activities
Closes #70
2020-05-14 22:43:47 -04:00
Shadowfacts d4bf289716
Fx more actions not workign 2020-05-14 22:43:37 -04:00
Shadowfacts cf48e4e973
Bump build number 2020-05-13 21:21:57 -04:00
Shadowfacts 2eaeaf3277
Fix previewing gifv attacments 2020-05-13 21:20:22 -04:00
Shadowfacts d396eb0823
Change background CoreData context to be a child of the main context so
that updates on the background context propogate up to the view context
on save
2020-05-13 19:49:35 -04:00
Shadowfacts 35a510e8ed
Add cache reset button to Advanced Preferences 2020-05-13 18:58:11 -04:00
Shadowfacts 0582812563
Remove strong references to MastodonController 2020-05-13 18:57:04 -04:00
Shadowfacts e581f384e4
Fix account descriptions being squashed in the follows list 2020-05-12 22:24:51 -04:00
Shadowfacts c42a48ee12
Fix header images not displaying 2020-05-12 22:05:57 -04:00
Shadowfacts 1c9b1b9ac3
Add support (sort of) for gifv attachments
See #98
2020-05-12 21:46:08 -04:00
Shadowfacts 82ad3b9fc4
Add reference counting for accounts
Closes #97
2020-05-11 22:03:17 -04:00
Shadowfacts 0a89dd3041
Don't double update accounts
Adding a status to the cache will also cache the status' account
2020-05-11 18:27:54 -04:00
Shadowfacts 40863ef130
Fix crash when opening more options for status in instance public timeline 2020-05-11 17:58:43 -04:00
Shadowfacts cd78287a87
Fix crash when viewing instance public timelines
Use a CoreData in-memory store for public timelines.
2020-05-11 17:57:50 -04:00
Shadowfacts 04496aca1d
Apply avatar style to local account avatar images 2020-05-10 19:30:19 -04:00
Shadowfacts 5a098df931
Fix crash when searching 2020-05-10 15:47:50 -04:00
Shadowfacts 9812d4aff2
Prevent double-decrementing reference count for conversation main status 2020-05-10 15:08:45 -04:00
Shadowfacts f4f2a5546c
Prevent race in status action account list 2020-05-10 15:04:22 -04:00
Shadowfacts b220948e2b
Only initialize NSManagedObjectModel once
Prevents CoreData warnings when switching accounts and constructing a
second MastodonCachePersistentStore
2020-05-10 14:54:43 -04:00
Shadowfacts 866edc472d
Show avatar and instance domain in account list in Preferences 2020-05-10 14:54:20 -04:00
Shadowfacts 88e4f52b5d
Fix crash when adding account
Adding a UserData.LocalAccountInfo with a nil username while the
PreferencesView is on screen will cause a crash, since it triggers a
Combine publish upon which the PreferencesView expects to be able to
display the username of all accounts.
2020-05-10 14:41:07 -04:00
Shadowfacts 98529ca5af
Remove notifications from the bottom when scrolling up notifications list 2020-05-10 12:56:03 -04:00
Shadowfacts 6d8c5f632c
Fix scroll-to-top sometimes not scrolling all the way to the top 2020-05-10 12:56:01 -04:00
Shadowfacts 4fdafa893e
Add drawing attachments using PencilKit 2020-05-09 22:14:48 -04:00
Shadowfacts 9f75106706
Fix crash when opening statuses in Safari 2020-05-09 13:31:07 -04:00
Shadowfacts bbd7d82620
Fix test in ContentTextView not being de-selectable 2020-05-07 21:46:59 -04:00
Shadowfacts 02088b1f55
Remove MastodonCache 🎉 2020-05-06 23:29:57 -04:00
Shadowfacts 1e41c8fa17
Remove MastodonCache usgae from XCBActions 2020-05-06 23:05:15 -04:00
Shadowfacts ebbfc7a132
Fix race condition on loading notifications 2020-05-06 19:32:32 -04:00
Shadowfacts aa625a41f5
Merge branch 'develop' into coredata 2020-05-06 19:18:58 -04:00
Shadowfacts 7fb92c9ce3
Prevent avatars in action notification group cell from overflowing 2020-05-06 19:18:47 -04:00
Shadowfacts 90bc9b91de
Add AccountProtocol and StatusProtocol
Provides a single interfaces for API and CoreData statuses and accounts
2020-05-06 18:40:12 -04:00
Shadowfacts d6c506488b
Replace a bunch of MastodonCache uses with CoreData 2020-05-02 19:52:35 -04:00
Shadowfacts 5786c24846
Fix statuses/accounts updating 2020-05-02 12:45:28 -04:00
Shadowfacts 2cba168804
Fix account cells using old cache 2020-04-27 19:33:36 -04:00
Shadowfacts 49d00bb1b0
Fix swipe actions not showing up 2020-04-27 19:32:16 -04:00
Shadowfacts ee5e049355
Use CoreData for bookmarks and search results 2020-04-27 19:25:41 -04:00
Shadowfacts f53474ac90
Use CoreData for notifications screen 2020-04-27 19:20:09 -04:00
Shadowfacts fa1daa682f
Convert profile VC to use CoreData objects
Does not yet remove old statuses when scrolling up, like timeline VC
2020-04-13 22:51:21 -04:00
Shadowfacts 030bee1948
Convert conversation VC to use CoreData models 2020-04-13 22:51:15 -04:00
Shadowfacts ed37b16463
Start adding CoreData-based "reference" counting for statuses
Prune old statuses that aren't likely to be shown again when scrolling
in timeline table view
2020-04-12 23:08:33 -04:00
Shadowfacts 2c8ba878b7
Start converting UI to use CoreData backed objects instead of API
objects directly
2020-04-12 12:54:27 -04:00
Shadowfacts a0e95d4577
Remove unnecessary attachment decoding code
For some reason, creating a URL from a string decoded from the container
was producing URL objects that could not be round-tripped through
PropertyListEncoder/Decoder. Decoding a URL directly from the container
works correctly.
2020-04-12 12:52:51 -04:00
Shadowfacts 465aedd43f
Make account info username optional
Onboarding view controller needs to set the account info object on the
mastodon controller before calling getOwnAccount since getOwnAccount
will upsert the user's account into the persistent container, which
requires the account info to exist to create a unique-per-account
identifier.
2020-04-12 11:14:10 -04:00
Shadowfacts 102fe6ed91
Convert API objects to CoreData models and save them 2020-04-11 22:23:31 -04:00
Shadowfacts 7deb4fc5b4
Add LazilyDecoding for CoreData embedded objects 2020-04-11 15:35:00 -04:00
Shadowfacts 2a419eb87c
Add basic Status/Account CoreData model 2020-04-11 15:32:25 -04:00
Shadowfacts fcab6818b0
Hide large image source view during expand/shrink animation 2020-03-25 23:10:48 -04:00
Shadowfacts 80cf1850dd
Add trackpad/magic mouse support for navigation controller interactive push gesture 2020-03-25 22:29:32 -04:00
Shadowfacts e612964464
Allow scrolling w/ trackpad/magic mouse to dismiss gallery 2020-03-25 22:12:26 -04:00
Shadowfacts 49a437583e
Fix incorrect large image size during expand/shrink animation in some
cases
2020-03-25 22:09:00 -04:00
Shadowfacts 8a513186aa
Add pointer interactions status buttons and profile header more button 2020-03-24 23:02:40 -04:00
Shadowfacts d9517047d7
Fix previewing video/audio attachments 2020-03-20 22:48:28 -04:00
Shadowfacts bef3388fe8
Move attachment view corner radius to individual views
Masking the container makes context menu interactions look weird
2020-03-20 22:34:50 -04:00
Shadowfacts 2e8241d734
Move attachment context menu interaction to AttachmentView 2020-03-20 22:28:23 -04:00
Shadowfacts c9c001d403
Improve attachment previewing
- Set correct preview size
- Don't show controls
2020-03-20 22:13:04 -04:00
Shadowfacts 4ce8de280e
Bump build number 2020-03-17 21:58:14 -04:00
Shadowfacts 4018d39312
Fix double gestures in attachments gallery 2020-03-17 21:56:29 -04:00
Shadowfacts ae416bb604
Prevent crash if BaseStatusTableViewCell is leaked
If prefernces change and the the view controller the cell belongs to is dealloced, the
mastodonController will be nil, previously causing a crash.
2020-03-17 21:44:06 -04:00
Shadowfacts 5e9caf9179
Use LoadingLargeImageViewController for account avatar/header
Prevents crash when tapping unloaded avatar/header images
2020-03-17 21:42:09 -04:00
Shadowfacts 3bbbb05083
Rename AttachmentsViewController to LoadingLargeImageViewController and
make non-specific to attachments
2020-03-17 21:24:15 -04:00
Shadowfacts bd3e74c611
Remove unnecessary XIB 2020-03-17 21:07:44 -04:00
Shadowfacts 2e8c416e04
Merge gallery and large image animations 2020-03-17 21:05:45 -04:00
Shadowfacts 955f9e5916
Fix attachment descriptions not being set correctly 2020-03-17 21:03:29 -04:00
Shadowfacts 17f15db32d
Don't round bottom corners of asset picker
Corner radius doesn't match that used on 2019 iPad Pro, so rounding the
bottom corners results in the view controller beneath the asset picker
showing through in some split-screen configurations
2020-03-16 20:50:16 -04:00
Shadowfacts 1a11dd2a69
Present asset picker as popover in regular horizontal size class 2020-03-16 20:45:51 -04:00
Shadowfacts b5fa0bceab
Fix pasting using compose app shortcut while app isn't running 2020-03-16 19:09:25 -04:00
Shadowfacts c224d11417
Allow pasting and drag/dropping video attachments on compose screen 2020-03-16 19:05:58 -04:00
Shadowfacts bebf47f05c
Prevent incompatible items from being pasted on compose screen 2020-03-16 17:31:43 -04:00
Shadowfacts e76b719c6a
Add context menu previews to explore VC 2020-03-15 23:54:04 -04:00
Shadowfacts 478c7b7a23
Fix crash when long-presing add attachment button 2020-03-15 22:59:43 -04:00
Shadowfacts e3cc0df283
Remove unnecessary URL escaping 2020-03-15 21:09:11 -04:00
Shadowfacts 9ed05de3ee
Add compose attachments preview 2020-03-15 14:25:02 -04:00
Shadowfacts 64f41ea2b7
Fix crash when updating timeline status cell timestamp 2020-03-15 12:17:19 -04:00
Shadowfacts 9af4118dfc
Show truncated note in account cell 2020-03-15 11:56:41 -04:00
Shadowfacts 64a8f6d733
Reorganize code 2020-03-15 11:43:41 -04:00
Shadowfacts ca76568c79
Remove old code 2020-03-15 11:40:28 -04:00
Shadowfacts 18e91feb00
Fix requires attachment descriptions preference not working 2020-03-15 11:39:35 -04:00
Shadowfacts c5d2e9af68
Fix preferences/drafts not saving on iPad in some circumstances 2020-03-15 11:26:30 -04:00
Shadowfacts 0691c3b9d6
Fix asset preview size 2020-03-14 23:32:54 -04:00
Shadowfacts 1ccb450477
Support dragging and dropping attachments in the compose view controller
Allos dragging in attachments from other apps and drag/dropping with the
compose VC to reorder attachments
2020-03-14 20:08:36 -04:00
Shadowfacts 7117ce6320
Support pasting images to create attachments
Closes #91
2020-03-14 16:46:50 -04:00
Shadowfacts 34dccf1f37
Extract compose attachments into separate VC 2020-03-14 15:47:15 -04:00
Shadowfacts a3303dc8fb
Use same order for status and account preview actions 2020-03-11 22:54:38 -04:00
Shadowfacts d15fa2199e
Fix attachments container more view not beign removed on cell reuse
Closes #92
2020-03-11 22:49:53 -04:00
Shadowfacts fadddeda7f
Fix crash when deleting draft
Closes #94
2020-03-11 22:18:31 -04:00
Shadowfacts b232bec80f
Show custom emojis in content warnings
Closes #95
2020-03-11 21:56:35 -04:00
Shadowfacts 1b19a13b05
Decode status cards 2020-03-04 21:14:58 -05:00
Shadowfacts cd5b4c1145
Remove old code 2020-03-02 22:31:37 -05:00
Shadowfacts b61418e062
Bump build 2020-03-02 19:45:14 -05:00
Shadowfacts c7746d3084
Add unknown notification fallback
Closes #90
2020-03-02 19:44:10 -05:00
Shadowfacts 315ea39682
Fix crash in silent action prefs 2020-03-02 19:44:10 -05:00
Shadowfacts 44fbbd6a80
Revert "Fix custom emojis in display namesnot showing in conversation main"
This reverts commit 73da828e7cec09bcfbe65295bbd2f02e3b719ff6.

Fixes #89
2020-03-02 19:44:10 -05:00
Shadowfacts fa4b5d3542
Fix custom emojis not being shown in display names when scrolling
quickly

If the emojiIdentifier didn't change, the emojis wouldn't be re-added
even after the text had been reset.
2020-03-02 19:44:10 -05:00
Shadowfacts de02c73957
Fix custom emojis in display namesnot showing in conversation main
statuses

Caused by the cell updating it's UI multiple times in quick succession.
As a workaround, prevent the main cell from being reloaded.
2020-03-02 19:44:10 -05:00
Shadowfacts 2cebb6bd7d
Show custom emojis in display names (where possible) 2020-03-02 19:44:09 -05:00
Shadowfacts 53707593a6
Show custom emojis in display names (where possible) 2020-03-01 19:40:32 -05:00
Shadowfacts 244659c262
Fix intermittent crash
If a status in a conversation view controller creates a work item to
update the timestamp in 1 minute, but the view controller is deinit'd
before that time elapses, the mastodonController instance will be nil,
resulting in a crash.

The DispatchWorkItems's are cancelled by the respective cell deinit
methods. But if the work item has already begun, cancelling it has no
effect, potentially leading to a crash in the conditions described above
are true. Using a weak reference to self fixes this.

Additionally, don't unnecessarily recreate the work items every time.
They don't capture any local variables, only self, so nothing changes.
2020-03-01 18:33:44 -05:00
Shadowfacts d4ca39761e
Change version, disable UI test web server temporarily 2020-03-01 18:23:10 -05:00
Shadowfacts f87944b47e
Add app icon 2020-03-01 13:11:09 -05:00
Shadowfacts af821081b0
Temporary fix for crash that occurs when switching accounts immediately
after adding a new one
2020-02-29 17:36:54 -05:00
Shadowfacts 804636dcbb
Don't show warning when loading draft on top of for empty statuses
Closes #87
2020-02-28 19:50:04 -05:00
Shadowfacts 5bed38f661
Show gallery instead of large image when previewing status attachments
Fixes crash when attempting to preview audio/video attachments
2020-02-28 19:47:38 -05:00
Shadowfacts 56de0ab359
Update profile header to always reflect most recently cached data 2020-02-28 19:47:31 -05:00
Shadowfacts 387623a309
Remove old code 2020-02-28 19:24:14 -05:00
Shadowfacts 70bca052c4
Tweak notification grouping
Notifications that are of the same type but are separated by a groupable
notification of a different type are now considered groupable. For
example:

favorite 1 (status 1)
reblog 1 (status 1)
favorite 2 (status 1)
reblog 2 (status 1)
mention 1
reblog 3 (status 1)

will be grouped into:

favorite 1, 2 (status 1)
reblog 1, 2 (status 1)
mention 1
reblog 3 (status 1)
2020-02-28 19:21:39 -05:00
Shadowfacts d9bae42f81
Prevent empty drafts from being saved 2020-02-22 15:43:17 -05:00
Shadowfacts a814ee37cc
Update SheetController
Fixes image picker losing velocity during dismiss animation
2020-02-22 15:29:42 -05:00
Shadowfacts 1a8e84f5fa
Reorganize behavior preferences 2020-02-22 13:19:31 -05:00
Shadowfacts 1f56823a17
Add preference to disable gif animation in timelines 2020-02-22 13:12:28 -05:00
Shadowfacts 65d57df949
Add interacting pushing to navigation controllers
Allows people to move forward in the navigation stack after popping
(making popping a non-destructive action).
2020-02-19 22:07:12 -05:00
Shadowfacts 8be7480755
Change bundle identifier and signing account 2020-02-08 17:54:04 -05:00
Shadowfacts d7953470e3
Add rudimentary support for audio attachments
Closes #7
2020-01-26 18:50:45 -05:00
Shadowfacts 8c7bebcce8
Fix large image controls being positioned incorrectly on notched-devices
when opening via a context menu preview.

The constraints for the top controls were being set only once, but when
showing a large image in the contxt menu preview window, the top inset
safe area is 0 and didn't become 44 (the value for notched devices)
until the preview was expanded.

Fixes #86
2020-01-26 18:28:46 -05:00
Shadowfacts 20c602f911
Disable row insertion animations 2020-01-26 18:23:18 -05:00
Shadowfacts f2e08e96f3
Improve large image/gallery animation handling when images aren't loaded 2020-01-25 22:29:12 -05:00
Shadowfacts d1913d7e69
Change white background when loading attachment to black 2020-01-25 22:09:00 -05:00
Shadowfacts f9a62ec3f3
Fix crash when tapping unloaded image attachment 2020-01-25 22:03:21 -05:00
Shadowfacts 26c99a1a35
Improve scroll perform when loading new rows into table views
Instead of reloading the whole table view, only insert the rows for
statuses/notifications that were added.
2020-01-25 11:11:48 -05:00
Shadowfacts 6757031dcb
Hide context menus and swipe actions on instance public timelines 2020-01-25 10:44:31 -05:00
Shadowfacts 7c207efa07
Tweak More swipe action to be in-line with system appearance 2020-01-25 10:44:12 -05:00
Shadowfacts 81256b7a96
Only show local posts on public instance timelines 2020-01-25 10:37:22 -05:00
Shadowfacts 5a6c12c5a7 Fix missing context menu actions on follow notifications for only one person 2020-01-25 10:30:04 -05:00
Shadowfacts d6ae51c02f Improve ImageCache loading
Keep track of the number of requests and only cancel the underlying
URLSessionTask if there are no concrete requsts remaining.

Closes #81
2020-01-25 10:30:04 -05:00
Shadowfacts 3220436893
Merge branch 'multiple-accounts' 2020-01-23 22:36:42 -05:00
Shadowfacts 62408fc4bd
Merge branch 'master' into multiple-accounts 2020-01-22 22:30:30 -05:00
Shadowfacts 1d169bec67
Fix statuses showing incorrect timestamps when switching accounts 2020-01-22 22:30:05 -05:00
Shadowfacts 4abda02b76
Only show drafts from current account 2020-01-22 22:27:58 -05:00
Shadowfacts e9db3fa0ac
Collapse whitespace according to CSS spec after converting HTML to
attributed string

Fixes #27
2020-01-21 21:28:14 -05:00
Shadowfacts 59277ec64f
Change drafts to store which accounts was used to create them
When loading a draft:

If the draft was created from a different account than the current one:
    If the draft was in reply to a status, don't allow it to be loaded.
    If the draft was not in reply to a status, prompt the user whether
    or not to load the draft.
If the draft was in reply to a different status than the current one:
    Prompt the user whether or not to load the draft.
Otherwise, load the draft.

Draft replies created from other accounts can't be loaded from different
accounts because the status for inReplyToID of the draft will have a
different instance-local ID if the two accounts are on different
instances.

See #16
2020-01-20 15:26:25 -05:00
Shadowfacts 08086f1b18
Fix compose reply view missing MastodonController instance 2020-01-20 15:25:23 -05:00
Shadowfacts 12b6623113
Merge branch 'master' into multiple-accounts 2020-01-20 12:16:11 -05:00
Shadowfacts cece8825ad
Fix decoding Account.moved on Mastodon 2020-01-20 12:10:10 -05:00
Shadowfacts f9ffb240ef
Fix decoding Hashtag.History on Mastodon 2020-01-20 12:07:30 -05:00
Shadowfacts 79f44c9b58
Change recommended instance selector to store categories as strings
instead of enum

Additional categories can be added, which would cause a crash when
decoding.
As the category isn't used for anything, storing it as an enum value is
not necessary.
2020-01-20 11:56:43 -05:00
Shadowfacts ff97b0f76d
Change saved hashtags/instances to be per-account
See #16
2020-01-20 11:48:47 -05:00
Shadowfacts 26f1aafa15
Unify SavedHashtagsManager and SavedInstancesManager 2020-01-20 11:20:39 -05:00
Shadowfacts c99a724bf3
Fix instance public timelines crashing
The instance timeline controller needs to store a strong reference to
the instance-specific MastodonController since the timeline VC only
holds a weak reference, and unlike normal screens, the scene session
doesn't hold onto the MastodonController for other instances.
2020-01-20 11:18:55 -05:00
Shadowfacts f7421d83ef
Add preference to mention reblogger when replying to a reblogged status 2020-01-19 23:48:36 -05:00
Shadowfacts 7934bc15ac
Split Composing prefs into Composing and Replying 2020-01-19 23:23:31 -05:00
Shadowfacts 3aa5aa1bc0
Fix weird crashes when switching accounts 2020-01-19 23:16:36 -05:00
Shadowfacts ee252c02e9
Fix retain cycle in timeline cell cache observers
The use an unowned reference to self because when the cell is deinit'd,
the Combine observers will be cancelled.
2020-01-19 23:14:51 -05:00
Shadowfacts 2f630f2f8f
Fix retain cycle between MastodonController/MastodonCache
The cache should only store a weak reference to the controller, so that
when the controller is deinit'd the cache is as well.
2020-01-19 23:14:13 -05:00
Shadowfacts 8eb6f6f573
Fix retain cycle in timestamp updating code
The timestamp update work item shouldn't retain a reference to the cell.
It can be unowned because when the cell is deinit'd, the work item will
be cancelled.
2020-01-19 23:10:52 -05:00
Shadowfacts 32e89f2c16
Fix retain cycles with TuskerNavigationDelegate
TuskerNavigationDelegate is now class-bound and only weak references to
it are stored.
2020-01-19 23:02:07 -05:00
Shadowfacts c45dd99088
Clean up account switching code 2020-01-19 11:52:06 -05:00
Shadowfacts 863867c522
Add logging in to additional accounts and switching accounts via Preferences
See #16
2020-01-18 22:45:06 -05:00
Shadowfacts 08c84688cf
Change recommended instance selector to store categories as strings
instead of enum

Additional categories can be added, which would cause a crash when
decoding.
As the category isn't used for anything, storing it as an enum value is
not necessary.
2020-01-18 22:42:20 -05:00
Shadowfacts 66fe861442
Merge branch 'master' into multiple-accounts 2020-01-18 19:33:01 -05:00
Shadowfacts 11f9642cba
Actually fix link interaction 2020-01-18 19:32:39 -05:00
Shadowfacts 6421d4dc12
Merge branch 'master' into multiple-accounts 2020-01-18 18:56:36 -05:00
Shadowfacts 38085eee37
Fix not being able to collapse/expand statuses
Instead of simply returning the content text view from hitTest(_:with:),
we need to call the super method so that the system still performs its
own checks.
2020-01-18 18:38:00 -05:00
Shadowfacts e19364abdf
Fix content text view text color in dark mode 2020-01-18 18:21:01 -05:00
Shadowfacts fa358a3e97
Remove xtra padding from content text view 2020-01-18 16:27:18 -05:00
Shadowfacts 5d86b35672
Enable text selection in conversation main status 2020-01-18 16:18:32 -05:00
Shadowfacts 784c71342d
Fix preformatted text not being displayed correctly 2020-01-18 16:05:44 -05:00
Shadowfacts b5a41badcc
Replace content labels with text views
UITextView uses TextKit internally, unlike UILabel, so no additional
code is needed to keep the TextKit and view representations of the text
in sync since they are one and the same. This means that detecting which
character was tapped in a content text view is much more accurate, which
means link handling is substantially imrpoved.

Fixes #20
2020-01-18 16:05:00 -05:00
Shadowfacts 23de131290
Add preference to require attachment descriptions before posting
Closes #76
2020-01-17 21:55:21 -05:00
Shadowfacts 8178a1f339
Fix crash when tapping more actions buttons on iPad
Fixes #78
2020-01-17 21:29:53 -05:00
Shadowfacts 53702a8324
Add pinned status refreshing
Closes #82
2020-01-17 21:13:17 -05:00
Shadowfacts bb86e1aafd
Allow rotaion in the attachment gallery
Closes #77
2020-01-07 22:19:38 -05:00
Shadowfacts db4312ee34
Fix refreshing multiple times with no new data not working
When the requested range has no results, no pagination data is returned,
so the existing `newer` request range is replaced with nil. As there
was no new data, the existing request range is still correct and should
not be replaced.

Fixes #75
2020-01-07 21:54:19 -05:00
Shadowfacts 3928b2e88a
Store an array of logged-in accounts internally, get the active
MastodonController from the current UIScene

See #16
2020-01-07 21:29:15 -05:00
Shadowfacts 8dba15ca17
Switch to scene-based lifecycle events
See #16
2020-01-07 18:39:19 -05:00
Shadowfacts ec2062ad42
Fix not being able to sign into Mastodon instances not in the
recommended list
2020-01-06 22:14:17 -05:00
Shadowfacts 1e066ac28e
Add installation instructions to readme 2020-01-06 20:35:11 -05:00
Shadowfacts 29e0128a55
Fix broken file paths 2020-01-06 20:27:58 -05:00
Shadowfacts 0255483f97
Make MastodonCache specific to each API controller
See #16
2020-01-05 19:54:28 -05:00
Shadowfacts e3be424f5a
Fix instance public timelines not loading 2020-01-05 19:45:12 -05:00
Shadowfacts 2bdcb9b7f8
Replace global shared MastodonController instance with (mostly)
dependency injection

The places still using the .shared property are cases where there is no
view controller from which to (easily) get the appropriate instance,
such as user activity and X-Callback-URL handling. These uses will need
to be revisited once there are multiple MastodonControllers.

See #16
2020-01-05 15:25:07 -05:00
Shadowfacts a18bcac8b8
Pachyderm: Change Client request methods to be static, like all other
models

Tusker: Add run method to MastodonController and no-longer expose API
client object
2020-01-05 14:00:39 -05:00
Shadowfacts 787dc9f24f
Fix crash decoding statuses sent from certain applications
If an application provides its URL as an empty string, decoding it would
cause throw an error because Foundation's URL class does not accept
empty strings. Instead, during parsing, consume the invalid URL and
replace it with a `nil` app URL.
2020-01-04 23:13:55 -05:00
Shadowfacts ad09e36907
Show follow requsts in notifications w/ accept/reject buttons
Closes #64
2020-01-04 23:13:23 -05:00
Shadowfacts c31916d67e
Remove references to old images 2020-01-04 23:04:45 -05:00
Shadowfacts 05cc3fd6d9
Add pinning/unpinning statuses
Closes #69
2020-01-04 19:31:35 -05:00
Shadowfacts b70256c525
Remove old icons 2020-01-04 19:22:16 -05:00
Shadowfacts 3ecbb1895c
Replace GMImagePicker with custom asset picker based on SheetController
Fixes #23
Closes #50
2020-01-04 16:25:15 -05:00
Shadowfacts b2956b6118
Convert HEIC images to JPEG before upload
Fixes #60
2019-12-31 16:41:56 -05:00
Shadowfacts 6ef643e374
Fix custom instances not showing up when typed into the instance
selector search field

With Combine Cancellables are automatically cancelled on deinit, so the
instance selector needs to hold on to a reference to pipeline
cancellable for its lifetime, otherwise it's cancelled immediately after
creation.

Closes #59
2019-12-31 11:45:34 -05:00
Shadowfacts 18c3c3c434
More UI testing setup and API mocks 2019-12-31 11:40:56 -05:00
Shadowfacts b9e359ba83
Fix custom instance domains not being parsed correctly 2019-12-31 00:13:09 -05:00
Shadowfacts edb86fc503
Add theme toggle separate from system appearance
Closes #67
2019-12-31 00:12:18 -05:00
Shadowfacts 49f58cf955
Initial UI testing setup 2019-12-30 16:00:14 -05:00
Shadowfacts 377b5f5c85
Add ability to save and view instance public timelines 2019-12-19 22:55:41 -05:00
Shadowfacts f92a2acc97
Show list edit screen immediately upon creation 2019-12-19 21:37:47 -05:00
Shadowfacts ae6a0513e4
Add local saved hashtags
Closes #66
2019-12-19 21:20:29 -05:00
Shadowfacts 6831ab5385
Pachyderm: Fix request bodies form parameters not being percent-escaped
Fixes #65
2019-12-18 21:59:08 -05:00
Shadowfacts afc2bfcf6b
Add list editing 2019-12-17 22:56:53 -05:00
Shadowfacts 76a7c5bdf8
Add list deletion 2019-12-17 21:40:08 -05:00
Shadowfacts 19f15d8fa9
Add list creation 2019-12-17 21:18:32 -05:00
Shadowfacts 270cbc2a6c
Add lists to Explore tab
Closes #63
2019-12-17 21:10:30 -05:00
Shadowfacts 036791bd39
Replace Search tab with Explore tab
- Search controller (functionally the same, presents results on top of
explore menu)
- Add bookmarks screen

See #63
2019-12-17 00:22:25 -05:00
Shadowfacts 382decd7da
Fix search section titles 2019-12-16 22:23:12 -05:00
Shadowfacts 05d79d5d03
Use same nav delegate more options for context menu share sheet 2019-12-14 13:36:05 -05:00
Shadowfacts 4c0607af79
Add (un)bookmarking to status more options 2019-12-14 12:40:50 -05:00
Shadowfacts eb6cfba9aa
Fix tablel view cells being re-selected on aborted nav swipe back 2019-12-14 11:59:31 -05:00
Shadowfacts c26657bafa
Use synchronized MastodonCache to prevent race condition crashes 2019-12-14 11:31:14 -05:00
Shadowfacts 0c78af7d4f
Store in reply to status in drafts 2019-12-14 11:30:35 -05:00
Shadowfacts 681cdb8bb5
Fix automatically created drafts not being deleted after successful post
The newly created draft needs to be set to the compose VC's currentDraft
so that it gets removed after the status is successfully created.

Also, save the drafts to disk after saving a draft so that crashes don't
cause draft loss.
2019-11-28 22:26:37 -05:00
Shadowfacts 06442b5629
Fix controls in large image/gallery not hiding/showing on zoom
Closes #58
2019-11-28 21:51:24 -05:00
Shadowfacts d5232c0b03
Fix content warning label always showing in conversation main status
When the conversation was opened, the status state of the main status
would already be known, so the CW label wasn't getting updated or
hidden/shown.
2019-11-28 21:22:13 -05:00
Shadowfacts 7140590ccf
Fix covnerstaion expand/collapse button not working on all statuses 2019-11-28 18:58:47 -05:00
Shadowfacts b47b08fa95
Store status collapse state in containing view controller
Also, copy the state between screens, so e.g. expanding a status in the
timeline and then opening that conversation already has that status
expanded.

This intentionally doesn't store the sensitive attachment visibility
state, since showing text when not necessary is less dangerous than for
images. (Possibly a preference for this in the future?)

Closes #55
2019-11-28 18:36:58 -05:00
Shadowfacts 24a1e7ceb9
Unify most of TimelineStatus and ConverastionMainStatus cell code
Closes #54
2019-11-19 12:08:11 -05:00
Shadowfacts 8fb3b211b6
Add button to conversation table view to collapse/expand all posts
This needs a refactor once StatusTableViewCell and
ConversationMainStatusTableViewCell are merged. See #54
2019-11-18 22:28:47 -05:00
Shadowfacts da6ff67a51
Add notification dismissal context menu actions
Closes #49

This is a workaround for UIKit's built-in suggested context menu actions
not working as expected, and should be replaced with the system thing if
it becomes possible.
2019-11-17 18:49:48 -05:00
Shadowfacts a92d9ddc6f
Automatically collapse long (> 500 chars) statuses
Closes #12
2019-11-17 18:36:19 -05:00
Shadowfacts eb8afdaab8
Change how pin icon is displayed on statuses 2019-11-17 15:28:58 -05:00
Shadowfacts d4fa2f36e3
Remove send message from profile share menu 2019-11-17 15:19:20 -05:00
Shadowfacts 4cfe5e0fa5
Change action notification line limit to 3 2019-11-17 15:16:58 -05:00
Shadowfacts 975fb23292
Possibly fix crash when reblogger account is cached 2019-11-17 14:46:14 -05:00
Shadowfacts 85812d774d
Fix crash when trying to open context menu for attachment that hasn't yet loaded 2019-11-17 14:45:38 -05:00
Shadowfacts 150adeb581
Use custom navigation controller for preferences to override
viewWillDisappear method and send preferences changed notification

Workaround for #36
2019-11-17 14:31:07 -05:00
Shadowfacts 81a5fce602
Add preference to always blur media 2019-11-17 12:52:42 -05:00
Shadowfacts 6ce96764f3
Use visual effect views for sensitive media hide button so the button is
visible regardless of the image color
2019-11-17 12:28:21 -05:00
Shadowfacts 42a0a8890c
Tweak profile header more button appearance 2019-11-17 11:33:49 -05:00
Shadowfacts 56d4a6690f
Fix crash when displaying posts with more than 4 attachments 2019-11-17 11:32:35 -05:00
Shadowfacts c91a7baaa6
Show pinned posts on profiles
Closes #53
2019-11-17 11:14:33 -05:00
Shadowfacts af65aa88e0
Don't use suggested actions in context menus 2019-11-17 10:19:50 -05:00
Shadowfacts c85836eda6
Add preferences for using in-app vs out of app Safari and using Reader Mode for in-app 2019-11-14 19:53:27 -05:00
Shadowfacts 5076aec54e
Use ObservedObject for binding to prefs in SwiftUI instead of custom property wrappers 2019-11-14 19:53:00 -05:00
Shadowfacts b4d41ac9b7
Fix crash in compose screen 2019-09-28 00:37:43 -04:00
Shadowfacts 1808aaa3e8
A bunch of VoiceOver/Voice Control stuff 2019-09-26 22:32:51 -04:00
Shadowfacts 5ebf651f76
Revert "Use correct ISO 8601 date decoder"
This reverts commit 5da357ee9c.
2019-09-26 18:39:48 -04:00
313 changed files with 16781 additions and 9250 deletions

9
.gitmodules vendored
View File

@ -1,9 +1,12 @@
[submodule "SwiftSoup"]
path = SwiftSoup
url = git://github.com/scinfu/SwiftSoup.git
[submodule "Cache"] [submodule "Cache"]
path = Cache path = Cache
url = git@github.com:hyperoslo/Cache.git url = git@github.com:hyperoslo/Cache.git
[submodule "Gifu"] [submodule "Gifu"]
path = Gifu path = Gifu
url = git://github.com/kaishin/Gifu.git url = git://github.com/kaishin/Gifu.git
[submodule "Embassy"]
path = Embassy
url = https://github.com/envoy/Embassy.git
[submodule "Ambassador"]
path = Ambassador
url = https://github.com/envoy/Ambassador.git

1
Ambassador Submodule

@ -0,0 +1 @@
Subproject commit 4fe264af51e0dd7228486c604750909e368241a7

View File

@ -1,91 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="210mm"
height="297mm"
viewBox="0 0 210 297"
version="1.1"
id="svg4592"
inkscape:version="0.92.2 5c3e80d, 2017-08-06"
sodipodi:docname="Download.svg">
<defs
id="defs4586" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.979899"
inkscape:cx="166.13768"
inkscape:cy="136.01503"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="2560"
inkscape:window-height="1395"
inkscape:window-x="1920"
inkscape:window-y="1"
inkscape:window-maximized="1" />
<metadata
id="metadata4589">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<rect
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:2.7641871;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect5166"
width="100"
height="10"
x="-45"
y="302"
ry="4.9918189" />
<rect
transform="matrix(-0.70710679,-0.70710677,-0.70710679,0.70710677,0,0)"
ry="4.4665961"
y="199.22142"
x="-214.47757"
height="8.9331923"
width="66.99894"
id="rect5164"
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:2.46821165;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<rect
transform="matrix(0,1,1,0,0,0)"
ry="4.4665961"
y="0"
x="212"
height="8.9331923"
width="85"
id="rect5168"
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:2.78008413;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<rect
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:2.46821189;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect5162"
width="66.99894"
height="8.9331923"
x="141.1559"
y="205.54411"
ry="4.4665961"
transform="matrix(-0.70710679,0.70710677,0.70710679,0.70710677,0,0)" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -1,73 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="210mm"
height="297mm"
viewBox="0 0 210 297"
version="1.1"
id="svg1007"
inkscape:version="0.92.2 5c3e80d, 2017-08-06"
sodipodi:docname="Favorite.svg">
<defs
id="defs1001" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.98994949"
inkscape:cx="293.05888"
inkscape:cy="341.92599"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="2560"
inkscape:window-height="1395"
inkscape:window-x="1920"
inkscape:window-y="1"
inkscape:window-maximized="1" />
<metadata
id="metadata1004">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<path
sodipodi:type="star"
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:2.64583325;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke markers fill"
id="path1571"
sodipodi:sides="5"
sodipodi:cx="68.784126"
sodipodi:cy="238.46798"
sodipodi:r1="72.331841"
sodipodi:r2="30.379374"
sodipodi:arg1="0.94281504"
sodipodi:arg2="1.5711336"
inkscape:flatsided="false"
inkscape:rounded="0"
inkscape:randomized="0"
d="M 111.27998,297.00001 68.77388,268.84736 26.248805,296.97133 39.888461,247.84598 -6.6077817e-8,216.09302 50.935869,213.88454 68.80852,166.13615 l 17.840442,47.76043 50.934368,2.24284 -39.90987,31.72605 z"
inkscape:transform-center-x="-0.0075377331"
inkscape:transform-center-y="-6.8999101" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -1,78 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="210mm"
height="297mm"
viewBox="0 0 210 297"
version="1.1"
id="svg5214"
inkscape:version="0.92.2 5c3e80d, 2017-08-06"
sodipodi:docname="Link.svg">
<defs
id="defs5208" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="2.8"
inkscape:cx="166.9267"
inkscape:cy="23.876042"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="2560"
inkscape:window-height="1395"
inkscape:window-x="1920"
inkscape:window-y="1"
inkscape:window-maximized="1" />
<metadata
id="metadata5211">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<ellipse
cy="308.6665"
cx="68.333336"
id="circle5763"
style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:9;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
rx="24.99999"
ry="25.000156" />
<circle
style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:9;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path5218"
cx="28.333334"
cy="268.66666"
r="25" />
<rect
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:3.61034346;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect5767"
width="65"
height="12.5"
x="206.42897"
y="164.74048"
ry="6.25"
transform="rotate(45)" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -1,84 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="80"
height="40"
viewBox="0 0 21.166666 10.583334"
version="1.1"
id="svg1623"
inkscape:version="0.92.2 5c3e80d, 2017-08-06"
sodipodi:docname="More.svg">
<defs
id="defs1617" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="5.6"
inkscape:cx="83.737701"
inkscape:cy="47.564201"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="2560"
inkscape:window-height="1395"
inkscape:window-x="1920"
inkscape:window-y="1"
inkscape:window-maximized="1"
units="px" />
<metadata
id="metadata1620">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-286.41665)">
<rect
style="fill:#000000;fill-opacity:0;stroke:none;stroke-width:2.73260474;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke markers fill"
id="rect2326"
width="21.166668"
height="10.583334"
x="6.9388939e-18"
y="286.41666" />
<circle
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.15993595;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke markers fill"
id="path2187"
cx="2.6458333"
cy="291.70831"
r="2.6458333" />
<circle
cy="291.70831"
cx="-10.583333"
id="circle2189"
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.15993595;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke markers fill"
transform="scale(-1,1)"
r="2.6458333" />
<circle
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.15993595;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke markers fill"
id="circle2191"
cx="18.520834"
cy="291.70831"
r="2.6458333" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -1,115 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="793.70081"
height="1122.5197"
viewBox="0 0 210 297"
version="1.1"
id="svg886"
inkscape:version="0.92.2 5c3e80d, 2017-08-06"
sodipodi:docname="Reblog.svg"
enable-background="new">
<defs
id="defs880">
<filter
inkscape:collect="always"
style="color-interpolation-filters:sRGB"
id="filter2010">
<feBlend
inkscape:collect="always"
mode="multiply"
in2="BackgroundImage"
id="feBlend2012" />
</filter>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="2.12"
inkscape:cx="426.6819"
inkscape:cy="222.48454"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
units="px"
inkscape:snap-bbox="true"
inkscape:bbox-paths="true"
inkscape:bbox-nodes="true"
inkscape:snap-bbox-edge-midpoints="true"
inkscape:snap-bbox-midpoints="true"
showguides="true"
inkscape:guide-bbox="true"
inkscape:window-width="2560"
inkscape:window-height="1395"
inkscape:window-x="1920"
inkscape:window-y="1"
inkscape:window-maximized="1"
inkscape:lockguides="false"
inkscape:pagecheckerboard="false">
<sodipodi:guide
position="100.46678,110.57587"
orientation="0,1"
id="guide1767"
inkscape:locked="false" />
<sodipodi:guide
position="39.817226,99.415325"
orientation="1,0"
id="guide1773"
inkscape:locked="false" />
<sodipodi:guide
position="107.95499,89.359277"
orientation="0,1"
id="guide1987"
inkscape:locked="false" />
<sodipodi:guide
position="79.634452,79.589293"
orientation="-0.70563567,-0.70857484"
id="guide1999"
inkscape:locked="false" />
<sodipodi:guide
position="70.763562,8.6713087"
orientation="0,1"
id="guide904"
inkscape:locked="false" />
</sodipodi:namedview>
<metadata
id="metadata883">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
style="opacity:0.92000002;filter:url(#filter2010)">
<path
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:4.54638195;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke markers fill"
d="m 159.65664,296.99998 39.81721,-39.65184 h -29.05972 v -49.56596 h -0.005 c 0.003,0 0.005,-0.003 0.005,-0.005 V 186.4343 c 0,-0.003 -0.002,-0.005 -0.005,-0.005 h -54.66849 c -8e-4,0 -0.001,-0.003 -0.003,-0.003 H 75.53562 l 21.441585,21.35219 h 18.756475 c 7.9e-4,0 7.9e-4,0.003 0.002,0.003 h 33.16389 v 49.56617 h -29.05973 z"
id="path1592"
inkscape:connector-curvature="0" />
<path
inkscape:connector-curvature="0"
id="path1716"
d="M 39.817206,177.75866 0,217.4105 h 29.059724 v 49.56596 h 0.0047 c -0.0026,0 -0.0047,0.003 -0.0047,0.005 v 21.34288 c 0,0.003 0.0021,0.005 0.0047,0.005 h 54.668491 c 7.93e-4,0 0.0013,0.003 0.0026,0.003 H 123.93823 L 102.49665,266.97932 H 83.740169 c -7.94e-4,0 -7.94e-4,-0.003 -0.0016,-0.003 H 50.574691 V 217.4105 h 29.059724 z"
style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:4.54638195;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke markers fill" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -1,78 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="793.70081"
height="1122.5197"
viewBox="0 0 210 297"
version="1.1"
id="svg8"
sodipodi:docname="Reply.svg"
inkscape:version="0.92.2 5c3e80d, 2017-08-06">
<defs
id="defs2">
<inkscape:path-effect
effect="powerstroke"
id="path-effect821"
is_visible="true"
offset_points="0,0.13229166"
sort_points="true"
interpolator_type="CubicBezierJohan"
interpolator_beta="0.2"
start_linecap_type="zerowidth"
linejoin_type="extrp_arc"
miter_limit="4"
end_linecap_type="zerowidth" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1"
inkscape:cx="134.7614"
inkscape:cy="56.711221"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
units="px"
inkscape:measure-start="46.669,115.435"
inkscape:measure-end="64.166,149.577"
inkscape:window-width="2560"
inkscape:window-height="1395"
inkscape:window-x="1920"
inkscape:window-y="1"
inkscape:window-maximized="1" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<path
style="fill:#000000;fill-opacity:1;stroke:#000000;stroke-width:0.26310158px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 0.20308372,275.78816 20.85866428,-18.46405 -4.77e-4,14.33185 c 0,0 41.110218,1.57695 31.919391,25.03042 2.746954,-16.26972 -31.82696,-14.6095 -31.82696,-14.6095 l -0.184082,14.75226 z"
id="path825"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccccc" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

138
CHANGELOG.md Normal file
View File

@ -0,0 +1,138 @@
# Changelog
## 2020.1 (10)
This build is a hotfix for a couple pressing issues. The changelog for the previous build is included below.
Bugfixes:
- Fix crash when opening Preferences while signed in with a deleted account
- Fix visibility and content warning not being copied when replying to a post
## 2020.1 (9)
The marquee feature of this build is the new and improved Compose screen. It's been rewritten to use SwiftUI, is significantly more resilient to data loss, and now shows the toolbar when the main text field is not focused. It also turns out Apple is surprise-releasing iOS 14 very soon (or possibly already has, depending when you're reading this). For those who were not already on the beta train, iOS 14 brings a number of new features including a sidebar on iPadOS and lots and lots of context menus (a home screen widget is coming Soon™).
Known Issues:
- Pasting images to create attachments when composing a post is not currently supported due to an iOS bug (#109)
- Full-size previews do not display in context menus for attachments on the Compose screen due to an iOS issue (#110)
Features/Improvements:
- Rewrite Compose screen using SwiftUI
- Prevent draft posts being lost if the app crahes or is killed by the system while composing
- Show toolbar while post content is not being edited
- Save post visibility in drafts
- Move Draw Something action out of the context menu
- iOS 14: Use context menus for setting post visibility
- Show BlurHash previews for attachments on Mastodon
- Add Expand All Content Warnings preference (Preferences -> Behavior)
- Add Collapse Long Posts preference (Preferences -> Behavior)
- Improve image gallery opening animation
- Use fade in/out animations for opening/closing gallery and attachment picker when the Reduce Motion system setting is enabled
- iOS 14: Also requires the "Prefer Cross Fade" setting be enabled
- Slightly reduce default status font sizes
- Add "Direct Message" context menu action to Compose button on profile screen
- Allow viewing attachments and navigating through posts/accounts on instance public timelines
Bugfixes:
- Fix errors when uploading attachments not displaying
- Fix attachments not posting in the correct, user-specified order
- Fix accounts displaying with outdated information (avatars, display names, etc.)
- Fix Compose not showing button on profile screen
- Fix navigation title not being set on profile screen
- Fix follow notifications not showing names for users without display names set
- iPadOS 14: Fix crash when resizing app in split view mode
## 2020.1 (8)
This is just an emergency build to fix crashes on iOS 13 when selecting attachments. The changelog of the previous build is included below.
Features/Improvements:
- Enlarge tap targets on status reply/favorite/reblog/more buttons
- Disable automatic GIF playback when Low Power Mode is enabled
- Show custom emoji in user profile field names
Bugfixes:
- Fix crash when attempting to add attachments on iOS 13
- Fix potential crashes
## 2020.1 (7)
This is the first update since WWDC and the introduction of iOS 14. As such, most of the focus has been on fixing iOS 14-specific problems. However, there are still a couple new features, both for those on the iOS 14 beta and those not.
Features/Improvements:
- Add toggle between Posts, Posts and Replies, and Media on user profiles
- Remove 'Show Replies in Profiles' preference
- Limit link preview animation to only link text
- Add additional context menu actions for statuses, accounts, and hashtags
- Add semi-translucent background to image descriptions, so they're legible against light images
- iPadOS 14: Add sidebar
- When using multitasking on iPad and switching in and out of "compact" mode, the active tab as well as the navigation history for all tabs will be transferred between the sidebar and tab bar modes.
- iOS 14: Use context menus on status/account '...' buttons
- iOS 14: Replace 'More' status swipe action with 'Share'
Bugfixes:
- Fix crash when attempting to change post visibility on iPad
- Fix attachment view corners not being rounded
- Fix crash when viewing instance public timelines
- Fix Preferences button not appearing on My Profile tab
- Fix tapping current tab bar item not scrolling to top
- Fix crash showing audio attachments on Mastodon
- Fix timeline refreshing forever
- Set app category (fixes usage not being categorized correctly under Screen Time)
- iOS 14: Fix crash when searching for instances
- iOS 14: Fix crash when displaying accounts with no pinned posts
- iOS 14: Fix crash when displaying search results
## 2020.1 (6)
This is the pre-WWDC update with lots of bugfixes and some small features. There will likely be another build this week to fix any pressing issues that arise from iOS 14.
Features/Improvements:
- Add mute/unmute conversation status action
- iPadOS: Add pointer interactions to remove attachment button, gallery view share/dismiss buttons
- Disable reblog button for direct/followers-only posts
- On Pleroma, the reblog button is still enabled for your own followers-only posts to match Pleroma's "Boost to original audience" feature.
- Add preference to always display status visibilities below account avatars
- Add preference to show reply indicators for statuses in timelines
- Show share/dismiss controls and image description for gifv attachments
- 'Share' is currently disabled for gifv attachments, it will be enabled in a future build
- Add crash report helper
- If the app detects that it crashed the last time it was running, it will allow you to review the crash report and email it to me
- Add Recognize Text context menu option for images on the Compose screen
- This uses iOS' builtin Vision framework to perform on-device OCR and generate an image description from the recognized text
- Tweak attachment previews to always have a 16:9 aspect ratio
Bugfixes:
- Fix account/status More actions not working
- Improve share sheet loading speed
- Fix crash when loading bookmarks
- Prompt for Photos access before showing photo picker. Prevents empty sheet displaying.
- Fix profile fields not displaying and improve layout
- Fix profile header image not displaying the first time an account is loaded
- Don't show Follow action for your own account
- Fix attachments on the Compose screen being cut-off above the home indicator on iPhone X-style devices
- Fix audio being played by other apps pausing when displaying a gifv attachment on Mastodon
## 2020.1 (5)
The main focus of this update has been switching to using CoreData internally to cache/synchronize the most up-to-date versions of all statuses. Currently, this does not provide any new functionality, however, it lays the groundwork for several significant features coming in the future, including multiple window support on iPadOS and state restoration/persistence between launches.
Even though there aren't a huge number of new features in this build, a great deal has changed under the hood. As such, this build may suffer somewhat in the stability department. Please bear with me and report any issues you encounter; you can send me a message on the fediverse, email me at me@shadowfacts.net, or file an issue on the project issue tracker at https://git.shadowfacts.net/shadowfacts/Tusker/issues. Thank you!
Features:
- iPadOS: Add pointer interactions to status action buttons and profile header button
- iPadOS: Allow scrolling w/ trackpad/magic mouse to dismiss attachment gallery
- iPadOS: Enable interactive push gesture with trackpad/magic mouse
- Add drawing attachments using PencilKit
- Long-press to open context menu on the 'Add Attachment' button on the Compose screen, select 'Draw Something'
- Supports Apple Pencil on iPad, including tilt and pressure sensitivity
- Add avatar and instance domain in accounts switcher in Preferences
- Show gifv attachments on Mastodon
- Currently doesn't show attachment description or share/close buttons
- Add 'Clear Cache' option to Preferences -> Advanced for debugging
Bugfixes:
- Fix size of attachment previews in context menu
- Fix previewing audio/video attachments
- Fix incorrect image size during attachment expand/shrink animation
- Prevent avatars in grouped action notification from overflowing the cell and hiding the timestamp
- Fix text in conversation main statuses not being de-selectable
- Fix scroll-to-top sometimes not scrolling all the way to the top
- Fix account profile descriptions being squashed in the follow notification account list

1
Embassy Submodule

@ -0,0 +1 @@
Subproject commit 189436100c00efbf5fb2653fe7972a9371db0a91

View File

@ -1,32 +0,0 @@
//
// GMAlbumsViewCell.h
// GMPhotoPicker
//
// Created by Guillermo Muntaner Perelló on 22/09/14.
// Copyright (c) 2014 Guillermo Muntaner Perelló. All rights reserved.
//
#include <UIKit/UIKit.h>
#include <Photos/Photos.h>
@interface GMAlbumsViewCell : UITableViewCell
@property (strong) PHFetchResult *assetsFetchResults;
@property (strong) PHAssetCollection *assetCollection;
//The labels
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *infoLabel;
//The imageView
@property (nonatomic, strong) UIImageView *imageView1;
@property (nonatomic, strong) UIImageView *imageView2;
@property (nonatomic, strong) UIImageView *imageView3;
//Video additional information
@property (nonatomic, strong) UIImageView *videoIcon;
@property (nonatomic, strong) UIImageView *slowMoIcon;
@property (nonatomic, strong) UIView *gradientView;
@property (nonatomic, strong) CAGradientLayer *gradient;
//Selection overlay
- (void)setVideoLayout:(BOOL)isVideo;
@end

View File

@ -1,131 +0,0 @@
//
// GMAlbumsViewCell.m
// GMPhotoPicker
//
// Created by Guillermo Muntaner Perelló on 22/09/14.
// Copyright (c) 2014 Guillermo Muntaner Perelló. All rights reserved.
//
#import "GMAlbumsViewCell.h"
#import "GMAlbumsViewController.h"
#import "GMImagePickerController.h"
#import <QuartzCore/QuartzCore.h>
@implementation GMAlbumsViewCell
- (void)awakeFromNib
{
[super awakeFromNib];
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
{
// self.isAccessibilityElement = YES;
self.contentView.backgroundColor = [UIColor clearColor];
self.backgroundColor = [UIColor clearColor];
self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// Border width of 1 pixel:
float borderWidth = 1.0/[UIScreen mainScreen].scale;
// ImageView
_imageView3 = [UIImageView new];
_imageView3.contentMode = UIViewContentModeScaleAspectFill;
_imageView3.frame = CGRectMake(kAlbumLeftToImageSpace+4, 8, kAlbumThumbnailSize3.width, kAlbumThumbnailSize3.height );
[_imageView3.layer setBorderColor: [[UIColor whiteColor] CGColor]];
[_imageView3.layer setBorderWidth: borderWidth];
_imageView3.clipsToBounds = YES;
_imageView3.translatesAutoresizingMaskIntoConstraints = YES;
_imageView3.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
[self.contentView addSubview:_imageView3];
// ImageView
_imageView2 = [UIImageView new];
_imageView2.contentMode = UIViewContentModeScaleAspectFill;
_imageView2.frame = CGRectMake(kAlbumLeftToImageSpace+2, 8+2, kAlbumThumbnailSize2.width, kAlbumThumbnailSize2.height );
[_imageView2.layer setBorderColor: [[UIColor whiteColor] CGColor]];
[_imageView2.layer setBorderWidth: borderWidth];
_imageView2.clipsToBounds = YES;
_imageView2.translatesAutoresizingMaskIntoConstraints = YES;
_imageView2.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
[self.contentView addSubview:_imageView2];
// ImageView
_imageView1 = [UIImageView new];
_imageView1.contentMode = UIViewContentModeScaleAspectFill;
_imageView1.frame = CGRectMake(kAlbumLeftToImageSpace, 8+4, kAlbumThumbnailSize1.width, kAlbumThumbnailSize1.height );
[_imageView1.layer setBorderColor: [[UIColor whiteColor] CGColor]];
[_imageView1.layer setBorderWidth: borderWidth];
_imageView1.clipsToBounds = YES;
_imageView1.translatesAutoresizingMaskIntoConstraints = YES;
_imageView1.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
[self.contentView addSubview:_imageView1];
// The video gradient, label & icon
UIColor *topGradient = [UIColor colorWithRed:0.00 green:0.00 blue:0.00 alpha:0.0];
UIColor *midGradient = [UIColor colorWithRed:0.00 green:0.00 blue:0.00 alpha:0.33];
UIColor *botGradient = [UIColor colorWithRed:0.00 green:0.00 blue:0.00 alpha:0.75];
_gradientView = [[UIView alloc] initWithFrame: CGRectMake(0.0f, kAlbumThumbnailSize1.height-kAlbumGradientHeight, kAlbumThumbnailSize1.width, kAlbumGradientHeight)];
_gradient = [CAGradientLayer layer];
_gradient.frame = _gradientView.bounds;
_gradient.colors = [NSArray arrayWithObjects:(id)[topGradient CGColor], (id)[midGradient CGColor], (id)[botGradient CGColor], nil];
_gradient.locations = @[ @0.0f, @0.5f, @1.0f ];
[_gradientView.layer insertSublayer:_gradient atIndex:0];
_gradientView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
_gradientView.translatesAutoresizingMaskIntoConstraints = YES;
[self.imageView1 addSubview:_gradientView];
_gradientView.hidden = YES;
// VideoIcon
_videoIcon = [UIImageView new];
_videoIcon.contentMode = UIViewContentModeScaleAspectFill;
_videoIcon.frame = CGRectMake(3,kAlbumThumbnailSize1.height - 4 - 8, 15, 8 );
_videoIcon.image = [UIImage imageNamed:@"GMVideoIcon" inBundle:[NSBundle bundleForClass:GMAlbumsViewCell.class] compatibleWithTraitCollection:nil];
_videoIcon.clipsToBounds = YES;
_videoIcon.translatesAutoresizingMaskIntoConstraints = YES;
_videoIcon.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
[self.imageView1 addSubview:_videoIcon];
_videoIcon.hidden = NO;
// TextLabel
self.textLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:17.0];
self.textLabel.numberOfLines = 1;
self.detailTextLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:14.0];
self.detailTextLabel.numberOfLines = 1;
}
return self;
}
-(void)layoutSubviews {
[super layoutSubviews];
self.textLabel.frame = CGRectMake(kAlbumLeftToImageSpace + kAlbumThumbnailSize1.width + kAlbumImageToTextSpace,self.textLabel.frame.origin.y,self.contentView.frame.size.width - kAlbumLeftToImageSpace - kAlbumThumbnailSize1.width - 8, self.textLabel.frame.size.height);
self.detailTextLabel.frame = CGRectMake(kAlbumLeftToImageSpace + kAlbumThumbnailSize1.width + kAlbumImageToTextSpace,self.detailTextLabel.frame.origin.y,self.contentView.frame.size.width - kAlbumLeftToImageSpace - kAlbumThumbnailSize1.width - 8 - kAlbumImageToTextSpace, self.detailTextLabel.frame.size.height);
}
- (void)setVideoLayout:(BOOL)isVideo
{
// TODO : Add additional icons for slowmo, burst, etc...
if (isVideo) {
_videoIcon.hidden = NO;
_gradientView.hidden = NO;
} else {
_videoIcon.hidden = YES;
_gradientView.hidden = YES;
}
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end

View File

@ -1,32 +0,0 @@
//
// GMAlbumsViewController.h
// GMPhotoPicker
//
// Created by Guillermo Muntaner Perelló on 19/09/14.
// Copyright (c) 2014 Guillermo Muntaner Perelló. All rights reserved.
//
#import <UIKit/UIKit.h>
// Measuring IOS8 Photos APP at @2x (iPhone5s):
// The rows are 180px/90pts
// Left image border is 21px/10.5pts
// Separation between image and text is 42px/21pts (double the previouse one)
// The bigger image measures 139px/69.5pts including 1px/0.5pts white border.
// The second image measures 131px/65.6pts including 1px/0.5pts white border. Only 3px/1.5pts visible
// The third image measures 123px/61.5pts including 1px/0.5pts white border. Only 3px/1.5pts visible
static int kAlbumRowHeight = 90;
static int kAlbumLeftToImageSpace = 10;
static int kAlbumImageToTextSpace = 21;
static float const kAlbumGradientHeight = 20.0f;
static CGSize const kAlbumThumbnailSize1 = {70.0f , 70.0f};
static CGSize const kAlbumThumbnailSize2 = {66.0f , 66.0f};
static CGSize const kAlbumThumbnailSize3 = {62.0f , 62.0f};
@interface GMAlbumsViewController : UITableViewController
- (void)selectAllAlbumsCell;
@end

View File

@ -1,416 +0,0 @@
//
// GMAlbumsViewController.m
// GMPhotoPicker
//
// Created by Guillermo Muntaner Perelló on 19/09/14.
// Copyright (c) 2014 Guillermo Muntaner Perelló. All rights reserved.
//
#import "GMImagePickerController.h"
#import "GMAlbumsViewController.h"
#import "GMGridViewCell.h"
#import "GMGridViewController.h"
#import "GMAlbumsViewCell.h"
#include <Photos/Photos.h>
@interface GMAlbumsViewController() <PHPhotoLibraryChangeObserver>
@property (strong,nonatomic) NSArray *collectionsFetchResults;
@property (strong,nonatomic) NSArray *collectionsLocalizedTitles;
@property (strong,nonatomic) NSArray *collectionsFetchResultsAssets;
@property (strong,nonatomic) NSArray *collectionsFetchResultsTitles;
@property (nonatomic, weak) GMImagePickerController *picker;
@property (strong,nonatomic) PHCachingImageManager *imageManager;
@end
@implementation GMAlbumsViewController
- (id)init
{
if (self = [super initWithStyle:UITableViewStylePlain]) {
self.preferredContentSize = kPopoverContentSize;
}
return self;
}
static NSString *const AllPhotosReuseIdentifier = @"AllPhotosCell";
static NSString *const CollectionCellReuseIdentifier = @"CollectionCell";
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [self.picker pickerBackgroundColor];
// Navigation bar customization
if (self.picker.customNavigationBarPrompt) {
self.navigationItem.prompt = self.picker.customNavigationBarPrompt;
}
self.imageManager = [[PHCachingImageManager alloc] init];
// Table view aspect
self.tableView.rowHeight = kAlbumRowHeight;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
// Buttons
NSDictionary *barButtonItemAttributes = @{NSFontAttributeName: [UIFont fontWithName:self.picker.pickerFontName size:self.picker.pickerFontHeaderSize]};
NSString *cancelTitle = self.picker.customCancelButtonTitle ? self.picker.customCancelButtonTitle : NSLocalizedStringFromTableInBundle(@"picker.navigation.cancel-button", @"GMImagePicker", [NSBundle bundleForClass:GMImagePickerController.class], @"Cancel");
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:cancelTitle
style:UIBarButtonItemStylePlain
target:self.picker
action:@selector(dismiss:)];
if (self.picker.useCustomFontForNavigationBar) {
[self.navigationItem.leftBarButtonItem setTitleTextAttributes:barButtonItemAttributes forState:UIControlStateNormal];
[self.navigationItem.leftBarButtonItem setTitleTextAttributes:barButtonItemAttributes forState:UIControlStateSelected];
}
if (self.picker.allowsMultipleSelection) {
NSString *doneTitle = self.picker.customDoneButtonTitle ? self.picker.customDoneButtonTitle : NSLocalizedStringFromTableInBundle(@"picker.navigation.done-button", @"GMImagePicker", [NSBundle bundleForClass:GMImagePickerController.class], @"Done");
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:doneTitle
style:UIBarButtonItemStyleDone
target:self.picker
action:@selector(finishPickingAssets:)];
if (self.picker.useCustomFontForNavigationBar) {
[self.navigationItem.rightBarButtonItem setTitleTextAttributes:barButtonItemAttributes forState:UIControlStateNormal];
[self.navigationItem.rightBarButtonItem setTitleTextAttributes:barButtonItemAttributes forState:UIControlStateSelected];
}
self.navigationItem.rightBarButtonItem.enabled = (self.picker.autoDisableDoneButton ? self.picker.selectedAssets.count > 0 : TRUE);
}
// Bottom toolbar
self.toolbarItems = self.picker.toolbarItems;
// Title
if (!self.picker.title) {
self.title = NSLocalizedStringFromTableInBundle(@"picker.navigation.title", @"GMImagePicker", [NSBundle bundleForClass:GMImagePickerController.class], @"Navigation bar default title");
} else {
self.title = self.picker.title;
}
// Fetch PHAssetCollections:
PHFetchResult *topLevelUserCollections = [PHCollectionList fetchTopLevelUserCollectionsWithOptions:nil];
PHFetchResult *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
self.collectionsFetchResults = @[topLevelUserCollections, smartAlbums];
self.collectionsLocalizedTitles = @[NSLocalizedStringFromTableInBundle(@"picker.table.smart-albums-header", @"GMImagePicker", [NSBundle bundleForClass:GMImagePickerController.class], @"Smart Albums"),NSLocalizedStringFromTableInBundle(@"picker.table.user-albums-header", @"GMImagePicker", [NSBundle bundleForClass:GMImagePickerController.class], @"Albums")];
[self updateFetchResults];
// Register for changes
[[PHPhotoLibrary sharedPhotoLibrary] registerChangeObserver:self];
if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
{
self.edgesForExtendedLayout = UIRectEdgeNone;
}
}
- (void)dealloc
{
[[PHPhotoLibrary sharedPhotoLibrary] unregisterChangeObserver:self];
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return self.picker.pickerStatusBarStyle;
}
- (void)selectAllAlbumsCell {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self tableView:self.tableView didSelectRowAtIndexPath:indexPath];
}
-(void)updateFetchResults
{
//What I do here is fetch both the albums list and the assets of each album.
//This way I have acces to the number of items in each album, I can load the 3
//thumbnails directly and I can pass the fetched result to the gridViewController.
self.collectionsFetchResultsAssets=nil;
self.collectionsFetchResultsTitles=nil;
//Fetch PHAssetCollections:
PHFetchResult *topLevelUserCollections = [self.collectionsFetchResults objectAtIndex:0];
PHFetchResult *smartAlbums = [self.collectionsFetchResults objectAtIndex:1];
//All album: Sorted by descending creation date.
NSMutableArray *allFetchResultArray = [[NSMutableArray alloc] init];
NSMutableArray *allFetchResultLabel = [[NSMutableArray alloc] init];
{
PHFetchOptions *options = [[PHFetchOptions alloc] init];
options.predicate = [NSPredicate predicateWithFormat:@"mediaType in %@", self.picker.mediaTypes];
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
PHFetchResult *assetsFetchResult = [PHAsset fetchAssetsWithOptions:options];
[allFetchResultArray addObject:assetsFetchResult];
[allFetchResultLabel addObject:NSLocalizedStringFromTableInBundle(@"picker.table.all-photos-label", @"GMImagePicker", [NSBundle bundleForClass:GMImagePickerController.class], @"All photos")];
}
//User albums:
NSMutableArray *userFetchResultArray = [[NSMutableArray alloc] init];
NSMutableArray *userFetchResultLabel = [[NSMutableArray alloc] init];
for(PHCollection *collection in topLevelUserCollections)
{
if ([collection isKindOfClass:[PHAssetCollection class]])
{
PHFetchOptions *options = [[PHFetchOptions alloc] init];
options.predicate = [NSPredicate predicateWithFormat:@"mediaType in %@", self.picker.mediaTypes];
PHAssetCollection *assetCollection = (PHAssetCollection *)collection;
//Albums collections are allways PHAssetCollectionType=1 & PHAssetCollectionSubtype=2
PHFetchResult *assetsFetchResult = [PHAsset fetchAssetsInAssetCollection:assetCollection options:options];
[userFetchResultArray addObject:assetsFetchResult];
[userFetchResultLabel addObject:collection.localizedTitle];
}
}
//Smart albums: Sorted by descending creation date.
NSMutableArray *smartFetchResultArray = [[NSMutableArray alloc] init];
NSMutableArray *smartFetchResultLabel = [[NSMutableArray alloc] init];
for(PHCollection *collection in smartAlbums)
{
if ([collection isKindOfClass:[PHAssetCollection class]])
{
PHAssetCollection *assetCollection = (PHAssetCollection *)collection;
//Smart collections are PHAssetCollectionType=2;
if(self.picker.customSmartCollections && [self.picker.customSmartCollections containsObject:@(assetCollection.assetCollectionSubtype)])
{
PHFetchOptions *options = [[PHFetchOptions alloc] init];
options.predicate = [NSPredicate predicateWithFormat:@"mediaType in %@", self.picker.mediaTypes];
options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
PHFetchResult *assetsFetchResult = [PHAsset fetchAssetsInAssetCollection:assetCollection options:options];
if(assetsFetchResult.count>0)
{
[smartFetchResultArray addObject:assetsFetchResult];
[smartFetchResultLabel addObject:collection.localizedTitle];
}
}
}
}
self.collectionsFetchResultsAssets= @[allFetchResultArray,smartFetchResultArray,userFetchResultArray];
self.collectionsFetchResultsTitles= @[allFetchResultLabel,smartFetchResultLabel,userFetchResultLabel];
}
#pragma mark - Accessors
- (GMImagePickerController *)picker
{
return (GMImagePickerController *)self.navigationController.parentViewController;
}
#pragma mark - Rotation
- (BOOL)shouldAutorotate
{
return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return (NSInteger)self.collectionsFetchResultsAssets.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
PHFetchResult *fetchResult = self.collectionsFetchResultsAssets[(NSUInteger)section];
return (NSInteger)fetchResult.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
GMAlbumsViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[GMAlbumsViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Increment the cell's tag
NSInteger currentTag = cell.tag + 1;
cell.tag = currentTag;
// Set the label
cell.textLabel.font = [UIFont fontWithName:self.picker.pickerFontName size:self.picker.pickerFontHeaderSize];
cell.textLabel.text = (self.collectionsFetchResultsTitles[(NSUInteger)indexPath.section])[(NSUInteger)indexPath.row];
cell.textLabel.textColor = self.picker.pickerTextColor;
// Retrieve the pre-fetched assets for this album:
PHFetchResult *assetsFetchResult = (self.collectionsFetchResultsAssets[(NSUInteger)indexPath.section])[(NSUInteger)indexPath.row];
// Display the number of assets
if (self.picker.displayAlbumsNumberOfAssets) {
cell.detailTextLabel.font = [UIFont fontWithName:self.picker.pickerFontName size:self.picker.pickerFontNormalSize];
cell.detailTextLabel.text = [self tableCellSubtitle:assetsFetchResult];
cell.detailTextLabel.textColor = self.picker.pickerTextColor;
}
// Set the 3 images (if exists):
if ([assetsFetchResult count] > 0) {
CGFloat scale = [UIScreen mainScreen].scale;
//Compute the thumbnail pixel size:
CGSize tableCellThumbnailSize1 = CGSizeMake(kAlbumThumbnailSize1.width*scale, kAlbumThumbnailSize1.height*scale);
PHAsset *asset = assetsFetchResult[0];
[cell setVideoLayout:(asset.mediaType==PHAssetMediaTypeVideo)];
[self.imageManager requestImageForAsset:asset
targetSize:tableCellThumbnailSize1
contentMode:PHImageContentModeAspectFill
options:nil
resultHandler:^(UIImage *result, NSDictionary *info) {
if (cell.tag == currentTag) {
cell.imageView1.image = result;
}
}];
// Second & third images:
// TODO: Only preload the 3pixels height visible frame!
if ([assetsFetchResult count] > 1) {
//Compute the thumbnail pixel size:
CGSize tableCellThumbnailSize2 = CGSizeMake(kAlbumThumbnailSize2.width*scale, kAlbumThumbnailSize2.height*scale);
PHAsset *asset = assetsFetchResult[1];
[self.imageManager requestImageForAsset:asset
targetSize:tableCellThumbnailSize2
contentMode:PHImageContentModeAspectFill
options:nil
resultHandler:^(UIImage *result, NSDictionary *info) {
if (cell.tag == currentTag) {
cell.imageView2.image = result;
}
}];
} else {
cell.imageView2.image = nil;
}
if ([assetsFetchResult count] > 2) {
CGSize tableCellThumbnailSize3 = CGSizeMake(kAlbumThumbnailSize3.width*scale, kAlbumThumbnailSize3.height*scale);
PHAsset *asset = assetsFetchResult[2];
[self.imageManager requestImageForAsset:asset
targetSize:tableCellThumbnailSize3
contentMode:PHImageContentModeAspectFill
options:nil
resultHandler:^(UIImage *result, NSDictionary *info) {
if (cell.tag == currentTag) {
cell.imageView3.image = result;
}
}];
} else {
cell.imageView3.image = nil;
}
} else {
[cell setVideoLayout:NO];
cell.imageView3.image = [UIImage imageNamed:@"GMEmptyFolder"];
cell.imageView2.image = [UIImage imageNamed:@"GMEmptyFolder"];
cell.imageView1.image = [UIImage imageNamed:@"GMEmptyFolder"];
}
return cell;
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
// Init the GMGridViewController
GMGridViewController *gridViewController = [[GMGridViewController alloc] initWithPicker:[self picker]];
// Set the title
gridViewController.title = cell.textLabel.text;
// Use the prefetched assets!
gridViewController.assetsFetchResults = [[_collectionsFetchResultsAssets objectAtIndex:(NSUInteger)indexPath.section] objectAtIndex:(NSUInteger)indexPath.row];
// Remove selection so it looks better on slide in
[tableView deselectRowAtIndexPath:indexPath animated:true];
// Push GMGridViewController
[self.navigationController pushViewController:gridViewController animated:YES];
}
-(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
// header.contentView.backgroundColor = [UIColor clearColor];
// header.backgroundView.backgroundColor = [UIColor clearColor];
// Default is a bold font, but keep this styled as a normal font
header.textLabel.font = [UIFont fontWithName:self.picker.pickerFontName size:self.picker.pickerFontNormalSize];
header.textLabel.textColor = self.picker.pickerTextColor;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
//Tip: Returning nil hides the section header!
NSString *title = nil;
if (section > 0) {
// Only show title for non-empty sections:
PHFetchResult *fetchResult = self.collectionsFetchResultsAssets[(NSUInteger)section];
if (fetchResult.count > 0) {
title = self.collectionsLocalizedTitles[(NSUInteger)(section - 1)];
}
}
return title;
}
#pragma mark - PHPhotoLibraryChangeObserver
- (void)photoLibraryDidChange:(PHChange *)changeInstance
{
// Call might come on any background queue. Re-dispatch to the main queue to handle it.
dispatch_async(dispatch_get_main_queue(), ^{
NSMutableArray *updatedCollectionsFetchResults = nil;
for (PHFetchResult *collectionsFetchResult in self.collectionsFetchResults) {
PHFetchResultChangeDetails *changeDetails = [changeInstance changeDetailsForFetchResult:collectionsFetchResult];
if (changeDetails) {
if (!updatedCollectionsFetchResults) {
updatedCollectionsFetchResults = [self.collectionsFetchResults mutableCopy];
}
[updatedCollectionsFetchResults replaceObjectAtIndex:[self.collectionsFetchResults indexOfObject:collectionsFetchResult] withObject:[changeDetails fetchResultAfterChanges]];
}
}
// This only affects to changes in albums level (add/remove/edit album)
if (updatedCollectionsFetchResults) {
self.collectionsFetchResults = updatedCollectionsFetchResults;
}
// However, we want to update if photos are added, so the counts of items & thumbnails are updated too.
// Maybe some checks could be done here , but for now is OKey.
[self updateFetchResults];
[self.tableView reloadData];
});
}
#pragma mark - Cell Subtitle
- (NSString *)tableCellSubtitle:(PHFetchResult*)assetsFetchResult
{
// Just return the number of assets. Album app does this:
return [NSString stringWithFormat:@"%ld", (long)[assetsFetchResult count]];
}
@end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -1,32 +0,0 @@
//
// GMGridViewCell.h
// GMPhotoPicker
//
// Created by Guillermo Muntaner Perelló on 19/09/14.
// Copyright (c) 2014 Guillermo Muntaner Perelló. All rights reserved.
//
#include <UIKit/UIKit.h>
#include <Photos/Photos.h>
@interface GMGridViewCell : UICollectionViewCell
@property (nonatomic, strong) PHAsset *asset;
//The imageView
@property (nonatomic, strong) UIImageView *imageView;
//Video additional information
@property (nonatomic, strong) UIImageView *videoIcon;
@property (nonatomic, strong) UILabel *videoDuration;
@property (nonatomic, strong) UIView *gradientView;
@property (nonatomic, strong) CAGradientLayer *gradient;
//Selection overlay
@property (nonatomic) BOOL shouldShowSelection;
@property (nonatomic, strong) UIView *coverView;
@property (nonatomic, strong) UIButton *selectedButton;
@property (nonatomic, assign, getter = isEnabled) BOOL enabled;
- (void)bind:(PHAsset *)asset;
@end

View File

@ -1,176 +0,0 @@
//
// GMGridViewCell.m
// GMPhotoPicker
//
// Created by Guillermo Muntaner Perelló on 19/09/14.
// Copyright (c) 2014 Guillermo Muntaner Perelló. All rights reserved.
//
#import "GMGridViewCell.h"
@interface GMGridViewCell ()
@end
@implementation GMGridViewCell
static UIFont *titleFont;
static CGFloat titleHeight;
static UIImage *videoIcon;
static UIColor *titleColor;
static UIImage *checkedIcon;
static UIColor *selectedColor;
static UIColor *disabledColor;
+ (void)initialize
{
titleFont = [UIFont systemFontOfSize:12];
titleHeight = 20.0f;
videoIcon = [UIImage imageNamed:@"GMImagePickerVideo"];
titleColor = [UIColor whiteColor];
checkedIcon = [UIImage imageNamed:@"CTAssetsPickerChecked"];
selectedColor = [UIColor colorWithWhite:1 alpha:0.3];
disabledColor = [UIColor colorWithWhite:1 alpha:0.9];
}
- (void)awakeFromNib
{
[super awakeFromNib];
self.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
self.contentView.translatesAutoresizingMaskIntoConstraints = YES;
}
- (id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.opaque = NO;
self.enabled = YES;
CGFloat cellSize = self.contentView.bounds.size.width;
// The image view
_imageView = [UIImageView new];
_imageView.frame = CGRectMake(0, 0, cellSize, cellSize);
_imageView.contentMode = UIViewContentModeScaleAspectFill;
/*if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
_imageView.contentMode = UIViewContentModeScaleAspectFit;
}
else
{
_imageView.contentMode = UIViewContentModeScaleAspectFill;
}*/
_imageView.clipsToBounds = YES;
_imageView.translatesAutoresizingMaskIntoConstraints = NO;
_imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self addSubview:_imageView];
// The video gradient, label & icon
float x_offset = 4.0f;
UIColor *topGradient = [UIColor colorWithRed:0.00 green:0.00 blue:0.00 alpha:0.0];
UIColor *botGradient = [UIColor colorWithRed:0.00 green:0.00 blue:0.00 alpha:0.8];
_gradientView = [[UIView alloc] initWithFrame: CGRectMake(0.0f, self.bounds.size.height-titleHeight, self.bounds.size.width, titleHeight)];
_gradient = [CAGradientLayer layer];
_gradient.frame = _gradientView.bounds;
_gradient.colors = [NSArray arrayWithObjects:(id)[topGradient CGColor], (id)[botGradient CGColor], nil];
[_gradientView.layer insertSublayer:_gradient atIndex:0];
_gradientView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
_gradientView.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:_gradientView];
_gradientView.hidden = YES;
_videoIcon = [UIImageView new];
_videoIcon.frame = CGRectMake(x_offset, self.bounds.size.height-titleHeight, self.bounds.size.width-2*x_offset, titleHeight);
_videoIcon.contentMode = UIViewContentModeLeft;
_videoIcon.image = [UIImage imageNamed:@"GMVideoIcon" inBundle:[NSBundle bundleForClass:GMGridViewCell.class] compatibleWithTraitCollection:nil];
_videoIcon.translatesAutoresizingMaskIntoConstraints = NO;
_videoIcon.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
[self addSubview:_videoIcon];
_videoIcon.hidden = YES;
_videoDuration = [UILabel new];
_videoDuration.font = titleFont;
_videoDuration.textColor = titleColor;
_videoDuration.textAlignment = NSTextAlignmentRight;
_videoDuration.frame = CGRectMake(x_offset, self.bounds.size.height-titleHeight, self.bounds.size.width-2*x_offset, titleHeight);
_videoDuration.contentMode = UIViewContentModeRight;
_videoDuration.translatesAutoresizingMaskIntoConstraints = NO;
_videoDuration.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
[self addSubview:_videoDuration];
_videoDuration.hidden = YES;
// Selection overlay & icon
_coverView = [[UIView alloc] initWithFrame:self.bounds];
_coverView.translatesAutoresizingMaskIntoConstraints = NO;
_coverView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
_coverView.backgroundColor = [UIColor colorWithRed:0.24 green:0.47 blue:0.85 alpha:0.6];
[self addSubview:_coverView];
_coverView.hidden = YES;
_selectedButton = [UIButton buttonWithType:UIButtonTypeCustom];
_selectedButton.frame = CGRectMake(2*self.bounds.size.width/3, 0*self.bounds.size.width/3, self.bounds.size.width/3, self.bounds.size.width/3);
_selectedButton.contentMode = UIViewContentModeTopRight;
_selectedButton.adjustsImageWhenHighlighted = NO;
[_selectedButton setImage:nil forState:UIControlStateNormal];
_selectedButton.translatesAutoresizingMaskIntoConstraints = NO;
_selectedButton.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[_selectedButton setImage:[UIImage imageNamed:@"GMSelected" inBundle:[NSBundle bundleForClass:GMGridViewCell.class] compatibleWithTraitCollection:nil] forState:UIControlStateSelected];
_selectedButton.hidden = NO;
_selectedButton.userInteractionEnabled = NO;
[self addSubview:_selectedButton];
}
// Note: the views above are created in case this is toggled per cell, on the fly, etc.!
self.shouldShowSelection = YES;
return self;
}
// Required to resize the CAGradientLayer because it does not support auto resizing.
- (void)layoutSubviews {
[super layoutSubviews];
_gradient.frame = _gradientView.bounds;
}
- (void)bind:(PHAsset *)asset
{
self.asset = asset;
if (self.asset.mediaType == PHAssetMediaTypeVideo) {
_videoIcon.hidden = NO;
_videoDuration.hidden = NO;
_gradientView.hidden = NO;
_videoDuration.text = [self getDurationWithFormat:self.asset.duration];
} else {
_videoIcon.hidden = YES;
_videoDuration.hidden = YES;
_gradientView.hidden = YES;
}
}
// Override setSelected
- (void)setSelected:(BOOL)selected
{
[super setSelected:selected];
if (!self.shouldShowSelection) {
return;
}
_coverView.hidden = !selected;
_selectedButton.selected = selected;
}
-(NSString*)getDurationWithFormat:(NSTimeInterval)duration
{
NSInteger ti = (NSInteger)duration;
NSInteger seconds = ti % 60;
NSInteger minutes = (ti / 60) % 60;
//NSInteger hours = (ti / 3600);
return [NSString stringWithFormat:@"%02ld:%02ld", (long)minutes, (long)seconds];
}
@end

View File

@ -1,21 +0,0 @@
//
// GMGridViewController.h
// GMPhotoPicker
//
// Created by Guillermo Muntaner Perelló on 19/09/14.
// Copyright (c) 2014 Guillermo Muntaner Perelló. All rights reserved.
//
#import "GMImagePickerController.h"
#include <UIKit/UIKit.h>
#include <Photos/Photos.h>
@interface GMGridViewController : UICollectionViewController
@property (strong,nonatomic) PHFetchResult *assetsFetchResults;
-(id)initWithPicker:(GMImagePickerController *)picker;
@end

View File

@ -1,611 +0,0 @@
//
// GMGridViewController.m
// GMPhotoPicker
//
// Created by Guillermo Muntaner Perelló on 19/09/14.
// Copyright (c) 2014 Guillermo Muntaner Perelló. All rights reserved.
//
#import "GMGridViewController.h"
#import "GMImagePickerController.h"
#import "GMAlbumsViewController.h"
#import "GMGridViewCell.h"
#include <Photos/Photos.h>
//Helper methods
@implementation NSIndexSet (Convenience)
- (NSArray *)aapl_indexPathsFromIndexesWithSection:(NSUInteger)section {
NSMutableArray *indexPaths = [NSMutableArray arrayWithCapacity:self.count];
[self enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
[indexPaths addObject:[NSIndexPath indexPathForItem:(NSInteger)idx inSection:(NSInteger)section]];
}];
return indexPaths;
}
@end
@implementation UICollectionView (Convenience)
- (NSArray *)aapl_indexPathsForElementsInRect:(CGRect)rect {
NSArray *allLayoutAttributes = [self.collectionViewLayout layoutAttributesForElementsInRect:rect];
if (allLayoutAttributes.count == 0) { return nil; }
NSMutableArray *indexPaths = [NSMutableArray arrayWithCapacity:allLayoutAttributes.count];
for (UICollectionViewLayoutAttributes *layoutAttributes in allLayoutAttributes) {
NSIndexPath *indexPath = layoutAttributes.indexPath;
[indexPaths addObject:indexPath];
}
return indexPaths;
}
@end
@interface GMImagePickerController ()
- (void)finishPickingAssets:(id)sender;
- (void)dismiss:(id)sender;
- (NSString *)toolbarTitle;
- (UIView *)noAssetsView;
@end
@interface GMGridViewController () <PHPhotoLibraryChangeObserver>
@property (nonatomic, weak) GMImagePickerController *picker;
@property (strong,nonatomic) PHCachingImageManager *imageManager;
@property (assign, nonatomic) CGRect previousPreheatRect;
@end
static CGSize AssetGridThumbnailSize;
NSString * const GMGridViewCellIdentifier = @"GMGridViewCellIdentifier";
@implementation GMGridViewController
{
CGFloat screenWidth;
CGFloat screenHeight;
UICollectionViewFlowLayout *portraitLayout;
UICollectionViewFlowLayout *landscapeLayout;
}
-(id)initWithPicker:(GMImagePickerController *)picker
{
//Custom init. The picker contains custom information to create the FlowLayout
self.picker = picker;
//Ipad popover is not affected by rotation!
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
screenWidth = CGRectGetWidth(picker.view.bounds);
screenHeight = CGRectGetHeight(picker.view.bounds);
}
else
{
if(UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation))
{
screenHeight = CGRectGetWidth(picker.view.bounds);
screenWidth = CGRectGetHeight(picker.view.bounds);
}
else
{
screenWidth = CGRectGetWidth(picker.view.bounds);
screenHeight = CGRectGetHeight(picker.view.bounds);
}
}
UICollectionViewFlowLayout *layout = [self collectionViewFlowLayoutForOrientation:[UIApplication sharedApplication].statusBarOrientation];
if (self = [super initWithCollectionViewLayout:layout])
{
//Compute the thumbnail pixel size:
CGFloat scale = [UIScreen mainScreen].scale;
//NSLog(@"This is @%fx scale device", scale);
if(scale >= 3)
{
scale = 2;
}
AssetGridThumbnailSize = CGSizeMake(layout.itemSize.width * scale, layout.itemSize.height * scale);
self.collectionView.allowsMultipleSelection = picker.allowsMultipleSelection;
[self.collectionView registerClass:GMGridViewCell.class
forCellWithReuseIdentifier:GMGridViewCellIdentifier];
self.preferredContentSize = kPopoverContentSize;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self setupViews];
// Navigation bar customization
if (self.picker.customNavigationBarPrompt) {
self.navigationItem.prompt = self.picker.customNavigationBarPrompt;
}
self.imageManager = [[PHCachingImageManager alloc] init];
[self resetCachedAssets];
[[PHPhotoLibrary sharedPhotoLibrary] registerChangeObserver:self];
if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)])
{
self.edgesForExtendedLayout = UIRectEdgeNone;
}
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setupButtons];
[self setupToolbar];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self updateCachedAssets];
}
- (void)dealloc
{
[self resetCachedAssets];
[[PHPhotoLibrary sharedPhotoLibrary] unregisterChangeObserver:self];
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return self.picker.pickerStatusBarStyle;
}
#pragma mark - Rotation
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return;
}
UICollectionViewFlowLayout *layout = [self collectionViewFlowLayoutForOrientation:toInterfaceOrientation];
//Update the AssetGridThumbnailSize:
CGFloat scale = [UIScreen mainScreen].scale;
AssetGridThumbnailSize = CGSizeMake(layout.itemSize.width * scale, layout.itemSize.height * scale);
[self resetCachedAssets];
//This is optional. Reload visible thumbnails:
for (GMGridViewCell *cell in [self.collectionView visibleCells]) {
NSInteger currentTag = cell.tag;
[self.imageManager requestImageForAsset:cell.asset
targetSize:AssetGridThumbnailSize
contentMode:PHImageContentModeAspectFill
options:nil
resultHandler:^(UIImage *result, NSDictionary *info)
{
// Only update the thumbnail if the cell tag hasn't changed. Otherwise, the cell has been re-used.
if (cell.tag == currentTag) {
[cell.imageView setImage:result];
}
}];
}
[self.collectionView setCollectionViewLayout:layout animated:YES];
}
#pragma mark - Setup
- (void)setupViews
{
self.collectionView.backgroundColor = [UIColor clearColor];
self.view.backgroundColor = [self.picker pickerBackgroundColor];
}
- (void)setupButtons
{
if (self.picker.allowsMultipleSelection) {
NSString *doneTitle = self.picker.customDoneButtonTitle ? self.picker.customDoneButtonTitle : NSLocalizedStringFromTableInBundle(@"picker.navigation.done-button", @"GMImagePicker", [NSBundle bundleForClass:GMImagePickerController.class], @"Done");
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:doneTitle
style:UIBarButtonItemStyleDone
target:self.picker
action:@selector(finishPickingAssets:)];
self.navigationItem.rightBarButtonItem.enabled = (self.picker.autoDisableDoneButton ? self.picker.selectedAssets.count > 0 : TRUE);
} else {
NSString *cancelTitle = self.picker.customCancelButtonTitle ? self.picker.customCancelButtonTitle : NSLocalizedStringFromTableInBundle(@"picker.navigation.cancel-button", @"GMImagePicker", [NSBundle bundleForClass:GMImagePickerController.class], @"Cancel");
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:cancelTitle
style:UIBarButtonItemStyleDone
target:self.picker
action:@selector(dismiss:)];
}
if (self.picker.useCustomFontForNavigationBar) {
if (self.picker.useCustomFontForNavigationBar) {
NSDictionary* barButtonItemAttributes = @{NSFontAttributeName: [UIFont fontWithName:self.picker.pickerFontName size:self.picker.pickerFontHeaderSize]};
[self.navigationItem.rightBarButtonItem setTitleTextAttributes:barButtonItemAttributes forState:UIControlStateNormal];
[self.navigationItem.rightBarButtonItem setTitleTextAttributes:barButtonItemAttributes forState:UIControlStateSelected];
}
}
}
- (void)setupToolbar
{
self.toolbarItems = self.picker.toolbarItems;
}
#pragma mark - Collection View Layout
- (UICollectionViewFlowLayout *)collectionViewFlowLayoutForOrientation:(UIInterfaceOrientation)orientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
if(!portraitLayout)
{
portraitLayout = [[UICollectionViewFlowLayout alloc] init];
portraitLayout.minimumInteritemSpacing = self.picker.minimumInteritemSpacing;
int cellTotalUsableWidth = (int)(screenWidth - (self.picker.colsInPortrait-1)*self.picker.minimumInteritemSpacing);
portraitLayout.itemSize = CGSizeMake(cellTotalUsableWidth/self.picker.colsInPortrait, cellTotalUsableWidth/self.picker.colsInPortrait);
double cellTotalUsedWidth = (double)portraitLayout.itemSize.width*self.picker.colsInPortrait;
double spaceTotalWidth = (double)screenWidth-cellTotalUsedWidth;
double spaceWidth = spaceTotalWidth/(double)(self.picker.colsInPortrait-1);
portraitLayout.minimumLineSpacing = spaceWidth;
}
return portraitLayout;
}
else
{
if(UIInterfaceOrientationIsLandscape(orientation))
{
if(!landscapeLayout)
{
landscapeLayout = [[UICollectionViewFlowLayout alloc] init];
landscapeLayout.minimumInteritemSpacing = self.picker.minimumInteritemSpacing;
int cellTotalUsableWidth = (int)(screenHeight - (self.picker.colsInLandscape-1)*self.picker.minimumInteritemSpacing);
landscapeLayout.itemSize = CGSizeMake(cellTotalUsableWidth/self.picker.colsInLandscape, cellTotalUsableWidth/self.picker.colsInLandscape);
double cellTotalUsedWidth = (double)landscapeLayout.itemSize.width*self.picker.colsInLandscape;
double spaceTotalWidth = (double)screenHeight-cellTotalUsedWidth;
double spaceWidth = spaceTotalWidth/(double)(self.picker.colsInLandscape-1);
landscapeLayout.minimumLineSpacing = spaceWidth;
}
return landscapeLayout;
}
else
{
if(!portraitLayout)
{
portraitLayout = [[UICollectionViewFlowLayout alloc] init];
portraitLayout.minimumInteritemSpacing = self.picker.minimumInteritemSpacing;
int cellTotalUsableWidth = (int)(screenWidth - (self.picker.colsInPortrait-1) * self.picker.minimumInteritemSpacing);
portraitLayout.itemSize = CGSizeMake(cellTotalUsableWidth/self.picker.colsInPortrait, cellTotalUsableWidth/self.picker.colsInPortrait);
double cellTotalUsedWidth = (double)portraitLayout.itemSize.width*self.picker.colsInPortrait;
double spaceTotalWidth = (double)screenWidth-cellTotalUsedWidth;
double spaceWidth = spaceTotalWidth/(double)(self.picker.colsInPortrait-1);
portraitLayout.minimumLineSpacing = spaceWidth;
}
return portraitLayout;
}
}
}
#pragma mark - Collection View Data Source
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
GMGridViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:GMGridViewCellIdentifier
forIndexPath:indexPath];
// Increment the cell's tag
NSInteger currentTag = cell.tag + 1;
cell.tag = currentTag;
PHAsset *asset = self.assetsFetchResults[(NSUInteger)indexPath.item];
/*if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
NSLog(@"Image manager: Requesting FIT image for iPad");
[self.imageManager requestImageForAsset:asset
targetSize:AssetGridThumbnailSize
contentMode:PHImageContentModeAspectFit
options:nil
resultHandler:^(UIImage *result, NSDictionary *info) {
// Only update the thumbnail if the cell tag hasn't changed. Otherwise, the cell has been re-used.
if (cell.tag == currentTag) {
[cell.imageView setImage:result];
}
}];
}
else*/
{
//NSLog(@"Image manager: Requesting FILL image for iPhone");
[self.imageManager requestImageForAsset:asset
targetSize:AssetGridThumbnailSize
contentMode:PHImageContentModeAspectFill
options:nil
resultHandler:^(UIImage *result, NSDictionary *info) {
// Only update the thumbnail if the cell tag hasn't changed. Otherwise, the cell has been re-used.
if (cell.tag == currentTag) {
[cell.imageView setImage:result];
}
}];
}
[cell bind:asset];
cell.shouldShowSelection = self.picker.allowsMultipleSelection;
// Optional protocol to determine if some kind of assets can't be selected (pej long videos, etc...)
if ([self.picker.delegate respondsToSelector:@selector(assetsPickerController:shouldEnableAsset:)]) {
cell.enabled = [self.picker.delegate assetsPickerController:self.picker shouldEnableAsset:asset];
} else {
cell.enabled = YES;
}
// Setting `selected` property blocks further deselection. Have to call selectItemAtIndexPath too. ( ref: http://stackoverflow.com/a/17812116/1648333 )
if ([self.picker.selectedAssets containsObject:asset]) {
cell.selected = YES;
[collectionView selectItemAtIndexPath:indexPath animated:NO scrollPosition:UICollectionViewScrollPositionNone];
} else {
cell.selected = NO;
}
return cell;
}
#pragma mark - Collection View Delegate
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
PHAsset *asset = self.assetsFetchResults[(NSUInteger)indexPath.item];
GMGridViewCell *cell = (GMGridViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
if (!cell.isEnabled) {
return NO;
} else if ([self.picker.delegate respondsToSelector:@selector(assetsPickerController:shouldSelectAsset:)]) {
return [self.picker.delegate assetsPickerController:self.picker shouldSelectAsset:asset];
} else {
return YES;
}
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
PHAsset *asset = self.assetsFetchResults[(NSUInteger)indexPath.item];
[self.picker selectAsset:asset];
if ([self.picker.delegate respondsToSelector:@selector(assetsPickerController:didSelectAsset:)]) {
[self.picker.delegate assetsPickerController:self.picker didSelectAsset:asset];
}
}
- (BOOL)collectionView:(UICollectionView *)collectionView shouldDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
PHAsset *asset = self.assetsFetchResults[(NSUInteger)indexPath.item];
if ([self.picker.delegate respondsToSelector:@selector(assetsPickerController:shouldDeselectAsset:)]) {
return [self.picker.delegate assetsPickerController:self.picker shouldDeselectAsset:asset];
} else {
return YES;
}
}
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
PHAsset *asset = self.assetsFetchResults[(NSUInteger)indexPath.item];
[self.picker deselectAsset:asset];
if ([self.picker.delegate respondsToSelector:@selector(assetsPickerController:didDeselectAsset:)]) {
[self.picker.delegate assetsPickerController:self.picker didDeselectAsset:asset];
}
}
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
PHAsset *asset = self.assetsFetchResults[(NSUInteger)indexPath.item];
if ([self.picker.delegate respondsToSelector:@selector(assetsPickerController:shouldHighlightAsset:)]) {
return [self.picker.delegate assetsPickerController:self.picker shouldHighlightAsset:asset];
} else {
return YES;
}
}
- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
PHAsset *asset = self.assetsFetchResults[(NSUInteger)indexPath.item];
if ([self.picker.delegate respondsToSelector:@selector(assetsPickerController:didHighlightAsset:)]) {
[self.picker.delegate assetsPickerController:self.picker didHighlightAsset:asset];
}
}
- (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
PHAsset *asset = self.assetsFetchResults[(NSUInteger)indexPath.item];
if ([self.picker.delegate respondsToSelector:@selector(assetsPickerController:didUnhighlightAsset:)]) {
[self.picker.delegate assetsPickerController:self.picker didUnhighlightAsset:asset];
}
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
NSInteger count = (NSInteger)self.assetsFetchResults.count;
return count;
}
#pragma mark - PHPhotoLibraryChangeObserver
- (void)photoLibraryDidChange:(PHChange *)changeInstance
{
// Call might come on any background queue. Re-dispatch to the main queue to handle it.
dispatch_async(dispatch_get_main_queue(), ^{
// check if there are changes to the assets (insertions, deletions, updates)
PHFetchResultChangeDetails *collectionChanges = [changeInstance changeDetailsForFetchResult:self.assetsFetchResults];
if (collectionChanges) {
// get the new fetch result
self.assetsFetchResults = [collectionChanges fetchResultAfterChanges];
UICollectionView *collectionView = self.collectionView;
if (![collectionChanges hasIncrementalChanges] || [collectionChanges hasMoves]) {
// we need to reload all if the incremental diffs are not available
[collectionView reloadData];
} else {
// if we have incremental diffs, tell the collection view to animate insertions and deletions
[collectionView performBatchUpdates:^{
NSIndexSet *removedIndexes = [collectionChanges removedIndexes];
if ([removedIndexes count]) {
[collectionView deleteItemsAtIndexPaths:[removedIndexes aapl_indexPathsFromIndexesWithSection:0]];
}
NSIndexSet *insertedIndexes = [collectionChanges insertedIndexes];
if ([insertedIndexes count]) {
[collectionView insertItemsAtIndexPaths:[insertedIndexes aapl_indexPathsFromIndexesWithSection:0]];
if (self.picker.showCameraButton && self.picker.autoSelectCameraImages) {
for (NSIndexPath *path in [insertedIndexes aapl_indexPathsFromIndexesWithSection:0]) {
[self collectionView:collectionView didSelectItemAtIndexPath:path];
}
}
}
NSIndexSet *changedIndexes = [collectionChanges changedIndexes];
if ([changedIndexes count]) {
[collectionView reloadItemsAtIndexPaths:[changedIndexes aapl_indexPathsFromIndexesWithSection:0]];
}
} completion:NULL];
}
[self resetCachedAssets];
}
});
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[self updateCachedAssets];
}
#pragma mark - Asset Caching
- (void)resetCachedAssets
{
[self.imageManager stopCachingImagesForAllAssets];
self.previousPreheatRect = CGRectZero;
}
- (void)updateCachedAssets
{
BOOL isViewVisible = [self isViewLoaded] && [[self view] window] != nil;
if (!isViewVisible) { return; }
// The preheat window is twice the height of the visible rect
CGRect preheatRect = self.collectionView.bounds;
preheatRect = CGRectInset(preheatRect, 0.0f, -0.5f * CGRectGetHeight(preheatRect));
// If scrolled by a "reasonable" amount...
CGFloat delta = ABS(CGRectGetMidY(preheatRect) - CGRectGetMidY(self.previousPreheatRect));
if (delta > CGRectGetHeight(self.collectionView.bounds) / 3.0f) {
// Compute the assets to start caching and to stop caching.
NSMutableArray *addedIndexPaths = [NSMutableArray array];
NSMutableArray *removedIndexPaths = [NSMutableArray array];
[self computeDifferenceBetweenRect:self.previousPreheatRect andRect:preheatRect removedHandler:^(CGRect removedRect) {
NSArray *indexPaths = [self.collectionView aapl_indexPathsForElementsInRect:removedRect];
[removedIndexPaths addObjectsFromArray:indexPaths];
} addedHandler:^(CGRect addedRect) {
NSArray *indexPaths = [self.collectionView aapl_indexPathsForElementsInRect:addedRect];
[addedIndexPaths addObjectsFromArray:indexPaths];
}];
NSArray *assetsToStartCaching = [self assetsAtIndexPaths:addedIndexPaths];
NSArray *assetsToStopCaching = [self assetsAtIndexPaths:removedIndexPaths];
[self.imageManager startCachingImagesForAssets:assetsToStartCaching
targetSize:AssetGridThumbnailSize
contentMode:PHImageContentModeAspectFill
options:nil];
[self.imageManager stopCachingImagesForAssets:assetsToStopCaching
targetSize:AssetGridThumbnailSize
contentMode:PHImageContentModeAspectFill
options:nil];
self.previousPreheatRect = preheatRect;
}
}
- (void)computeDifferenceBetweenRect:(CGRect)oldRect andRect:(CGRect)newRect removedHandler:(void (^)(CGRect removedRect))removedHandler addedHandler:(void (^)(CGRect addedRect))addedHandler
{
if (CGRectIntersectsRect(newRect, oldRect)) {
CGFloat oldMaxY = CGRectGetMaxY(oldRect);
CGFloat oldMinY = CGRectGetMinY(oldRect);
CGFloat newMaxY = CGRectGetMaxY(newRect);
CGFloat newMinY = CGRectGetMinY(newRect);
if (newMaxY > oldMaxY) {
CGRect rectToAdd = CGRectMake(newRect.origin.x, oldMaxY, newRect.size.width, (newMaxY - oldMaxY));
addedHandler(rectToAdd);
}
if (oldMinY > newMinY) {
CGRect rectToAdd = CGRectMake(newRect.origin.x, newMinY, newRect.size.width, (oldMinY - newMinY));
addedHandler(rectToAdd);
}
if (newMaxY < oldMaxY) {
CGRect rectToRemove = CGRectMake(newRect.origin.x, newMaxY, newRect.size.width, (oldMaxY - newMaxY));
removedHandler(rectToRemove);
}
if (oldMinY < newMinY) {
CGRect rectToRemove = CGRectMake(newRect.origin.x, oldMinY, newRect.size.width, (newMinY - oldMinY));
removedHandler(rectToRemove);
}
} else {
addedHandler(newRect);
removedHandler(oldRect);
}
}
- (NSArray *)assetsAtIndexPaths:(NSArray *)indexPaths
{
if (indexPaths.count == 0) { return nil; }
NSMutableArray *assets = [NSMutableArray arrayWithCapacity:indexPaths.count];
for (NSIndexPath *indexPath in indexPaths) {
PHAsset *asset = self.assetsFetchResults[(NSUInteger)indexPath.item];
[assets addObject:asset];
}
return assets;
}
@end

View File

@ -1,24 +0,0 @@
//
// GMImagePicker.h
// GMImagePicker
//
// Created by Shadowfacts on 1/14/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
#import <UIKit/UIKit.h>
//! Project version number for GMImagePicker.
FOUNDATION_EXPORT double GMImagePickerVersionNumber;
//! Project version string for GMImagePicker.
FOUNDATION_EXPORT const unsigned char GMImagePickerVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <GMImagePicker/PublicHeader.h>
#import <GMImagePicker/GMImagePickerController.h>
#import <GMImagePicker/GMAlbumsViewCell.h>
#import <GMImagePicker/GMAlbumsViewController.h>
#import <GMImagePicker/GMGridViewCell.h>
#import <GMImagePicker/GMGridViewController.h>

View File

@ -1,332 +0,0 @@
//
// GMImagePickerController.h
// GMPhotoPicker
//
// Created by Guillermo Muntaner Perelló on 19/09/14.
// Copyright (c) 2014 Guillermo Muntaner Perelló. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <Photos/Photos.h>
//This is the default image picker size!
//static CGSize const kPopoverContentSize = {320, 480};
//However, the iPad is 1024x768 so it can allow popups up to 768!
static CGSize const kPopoverContentSize = {480, 720};
@protocol GMImagePickerControllerDelegate;
/**
* A controller that allows picking multiple photos and videos from user's photo library.
*/
@interface GMImagePickerController : UIViewController
/**
* The assets pickers delegate object.
*/
@property (nonatomic, weak) id <GMImagePickerControllerDelegate> delegate;
/**
* It contains the selected `PHAsset` objects. The order of the objects is the selection order.
*
* You can add assets before presenting the picker to show the user some preselected assets.
*/
@property (nonatomic, strong) NSMutableArray *selectedAssets;
/** UI Customizations **/
/**
* Determines which smart collections are displayed (int array of enum: PHAssetCollectionSubtypeSmartAlbum)
* The default smart collections are:
* - Favorites
* - RecentlyAdded
* - Videos
* - SlomoVideos
* - Timelapses
* - Bursts
* - Panoramas
*/
@property (nonatomic, strong) NSArray* customSmartCollections;
/**
* Determines which media types are allowed (int array of enum: PHAssetMediaType)
* This defaults to all media types (view, audio and images)
* This can override customSmartCollections behavior (ie, remove video-only smart collections)
*/
@property (nonatomic, strong) NSArray* mediaTypes;
/**
* If set, it displays a this string instead of the localised default of "Done" on the done button. Note also that this
* is not used when a single selection is active since the selection of the chosen photo closes the VC thus rendering
* the button pointless.
*/
@property (nonatomic) NSString* customDoneButtonTitle;
/**
* If set, it displays this string instead of the localised default of "Cancel" on the cancel button
*/
@property (nonatomic) NSString* customCancelButtonTitle;
/**
* If set, it displays a prompt in the navigation bar
*/
@property (nonatomic) NSString* customNavigationBarPrompt;
/**
* Determines whether or not a toolbar with info about user selection is shown.
* The InfoToolbar is visible by default.
*/
@property (nonatomic) BOOL displaySelectionInfoToolbar;
/**
* Determines whether or not the number of assets is shown in the Album list.
* The number of assets is visible by default.
*/
@property (nonatomic, assign) BOOL displayAlbumsNumberOfAssets;
/**
* Automatically disables the "Done" button if nothing is selected. Defaults to YES.
*/
@property (nonatomic, assign) BOOL autoDisableDoneButton;
/**
* Use the picker either for miltiple image selections, or just a single selection. In the case of a single selection
* the VC is closed on selection so the Done button is neither displayed or used. Default is YES.
*/
@property (nonatomic, assign) BOOL allowsMultipleSelection;
/**
* In the case where allowsMultipleSelection = NO, set this to YES to have the user confirm their selection. Default is NO.
*/
@property (nonatomic, assign) BOOL confirmSingleSelection;
/**
* If set, it displays this string (if confirmSingleSelection = YES) instead of the localised default.
*/
@property (nonatomic) NSString *confirmSingleSelectionPrompt;
/**
* True to always show the toolbar, with a camera button allowing new photos to be taken. False to auto show/hide the
* toolbar, and have no camera button. Default is false. If true, this renders displaySelectionInfoToolbar a no-op.
*/
@property (nonatomic, assign) BOOL showCameraButton;
/**
* True to auto select the image(s) taken with the camera if showCameraButton = YES. In the case of allowsMultipleSelection = YES,
* this will trigger the selection handler too.
*/
@property (nonatomic, assign) BOOL autoSelectCameraImages;
/**
* If set, the user is allowed to edit captured still images
*/
@property (nonatomic, assign) BOOL allowsEditingCameraImages;
/**
* Grid customizations:
*
* - colsInPortrait: Number of columns in portrait (3 by default)
* - colsInLandscape: Number of columns in landscape (5 by default)
* - minimumInteritemSpacing: Horizontal and vertical minimum space between grid cells (2.0 by default)
*/
@property (nonatomic) NSInteger colsInPortrait;
@property (nonatomic) NSInteger colsInLandscape;
@property (nonatomic) double minimumInteritemSpacing;
/**
* UI customizations:
*
* - pickerBackgroundColor: The colour for all backgrounds; behind the table and cells. Defaults to [UIColor whiteColor]
* - pickerTextColor: The color for text in the views. This needs to work with pickerBackgroundColor! Default of darkTextColor
* - toolbarBackgroundColor: The background color of the toolbar. Defaults to nil.
* - toolbarBarTintColor: The color for the background tint of the toolbar. Defaults to nil.
* - toolbarTextColor: The color of the text on the toolbar
* - toolbarTintColor: The tint colour used for any buttons on the toolbar
* - navigationBarBackgroundColor: The background of the navigation bar. Defaults to nil.
* - navigationBarBarTintColor: The color for the background tint of the navigation bar. Defaults to nil.
* - navigationBarTextColor: The color for the text in the navigation bar. Defaults to [UIColor darkTextColor]
* - navigationBarTintColor: The tint color used for any buttons on the navigation Bar
* - pickerFontName: The font to use everywhere. Defaults to HelveticaNeue. It is advised if you set this to check, and possibly set, appropriately the custom font sizes. For font information, check http://www.iosfonts.com/
* - pickerFontName: The font to use everywhere. Defaults to HelveticaNeue-Bold. It is advised if you set this to check, and possibly set, appropriately the custom font sizes.
* - pickerFontNormalSize: The size of the custom font used in most places. Defaults to 14.0f
* - pickerFontHeaderSize: The size of the custom font for album names. Defaults to 17.0f
* - pickerStatusBarsStyle: On iPhones this will matter if custom navigation bar colours are being used. Defaults to UIStatusBarStyleDefault
* - useCustomFontForNavigationBar: True to use the custom font (or it's default) in the navigation bar, false to leave to iOS Defaults.
* - arrangeSmartCollectionsFirst: True will put the users smart collections above their albums, false will set it opposite. Default is NO.
*/
@property (nonatomic, strong) UIColor *pickerBackgroundColor;
@property (nonatomic, strong) UIColor *pickerTextColor;
@property (nonatomic, strong) UIColor *toolbarBackgroundColor;
@property (nonatomic, strong) UIColor *toolbarBarTintColor;
@property (nonatomic, strong) UIColor *toolbarTextColor;
@property (nonatomic, strong) UIColor *toolbarTintColor;
@property (nonatomic, strong) UIColor *navigationBarBackgroundColor;
@property (nonatomic, strong) UIColor *navigationBarBarTintColor;
@property (nonatomic, strong) UIColor *navigationBarTextColor;
@property (nonatomic, strong) UIColor *navigationBarTintColor;
@property (nonatomic, strong) NSString *pickerFontName;
@property (nonatomic, strong) NSString *pickerBoldFontName;
@property (nonatomic) CGFloat pickerFontNormalSize;
@property (nonatomic) CGFloat pickerFontHeaderSize;
@property (nonatomic) UIStatusBarStyle pickerStatusBarStyle;
@property (nonatomic) BOOL useCustomFontForNavigationBar;
@property (nonatomic) BOOL arrangeSmartCollectionsFirst;
/**
* A reference to the navigation controller used to manage the whole picking process
*/
@property (nonatomic, strong) UINavigationController *navigationController;
/**
* Managing Asset Selection
*/
- (void)selectAsset:(PHAsset *)asset;
- (void)deselectAsset:(PHAsset *)asset;
/**
* User finish Actions
*/
- (void)dismiss:(id)sender;
- (void)finishPickingAssets:(id)sender;
@end
@protocol GMImagePickerControllerDelegate <NSObject>
/**
* @name Closing the Picker
*/
/**
* Tells the delegate that the user finish picking photos or videos.
* @param picker The controller object managing the assets picker interface.
* @param assets An array containing picked PHAssets objects.
*/
- (void)assetsPickerController:(GMImagePickerController *)picker didFinishPickingAssets:(NSArray *)assets;
@optional
/**
* Tells the delegate that the user cancelled the pick operation.
* @param picker The controller object managing the assets picker interface.
*/
- (void)assetsPickerControllerDidCancel:(GMImagePickerController *)picker;
/**
* @name Enabling Assets
*/
/**
* Ask the delegate if the specified asset should be shown.
*
* @param picker The controller object managing the assets picker interface.
* @param asset The asset to be shown.
*
* @return `YES` if the asset should be shown or `NO` if it should not.
*/
- (BOOL)assetsPickerController:(GMImagePickerController *)picker shouldShowAsset:(PHAsset *)asset;
/**
* Ask the delegate if the specified asset should be enabled for selection.
*
* @param picker The controller object managing the assets picker interface.
* @param asset The asset to be enabled.
*
* @return `YES` if the asset should be enabled or `NO` if it should not.
*/
- (BOOL)assetsPickerController:(GMImagePickerController *)picker shouldEnableAsset:(PHAsset *)asset;
/**
* @name Managing the Selected Assets
*/
/**
* Asks the delegate if the specified asset should be selected.
*
* @param picker The controller object managing the assets picker interface.
* @param asset The asset to be selected.
*
* @return `YES` if the asset should be selected or `NO` if it should not.
*
*/
- (BOOL)assetsPickerController:(GMImagePickerController *)picker shouldSelectAsset:(PHAsset *)asset;
/**
* Tells the delegate that the asset was selected.
*
* @param picker The controller object managing the assets picker interface.
* @param asset The asset that was selected.
*
*/
- (void)assetsPickerController:(GMImagePickerController *)picker didSelectAsset:(PHAsset *)asset;
/**
* Asks the delegate if the specified asset should be deselected.
*
* @param picker The controller object managing the assets picker interface.
* @param asset The asset to be deselected.
*
* @return `YES` if the asset should be deselected or `NO` if it should not.
*
*/
- (BOOL)assetsPickerController:(GMImagePickerController *)picker shouldDeselectAsset:(PHAsset *)asset;
/**
* Tells the delegate that the item at the specified path was deselected.
*
* @param picker The controller object managing the assets picker interface.
* @param asset The asset that was deselected.
*
*/
- (void)assetsPickerController:(GMImagePickerController *)picker didDeselectAsset:(PHAsset *)asset;
/**
* @name Managing Asset Highlighting
*/
/**
* Asks the delegate if the specified asset should be highlighted.
*
* @param picker The controller object managing the assets picker interface.
* @param asset The asset to be highlighted.
*
* @return `YES` if the asset should be highlighted or `NO` if it should not.
*/
- (BOOL)assetsPickerController:(GMImagePickerController *)picker shouldHighlightAsset:(PHAsset *)asset;
/**
* Tells the delegate that asset was highlighted.
*
* @param picker The controller object managing the assets picker interface.
* @param asset The asset that was highlighted.
*
*/
- (void)assetsPickerController:(GMImagePickerController *)picker didHighlightAsset:(PHAsset *)asset;
/**
* Tells the delegate that the highlight was removed from the asset.
*
* @param picker The controller object managing the assets picker interface.
* @param asset The asset that had its highlight removed.
*
*/
- (void)assetsPickerController:(GMImagePickerController *)picker didUnhighlightAsset:(PHAsset *)asset;
@end

View File

@ -1,388 +0,0 @@
//
// GMImagePickerController.m
// GMPhotoPicker
//
// Created by Guillermo Muntaner Perelló on 19/09/14.
// Copyright (c) 2014 Guillermo Muntaner Perelló. All rights reserved.
//
#import <MobileCoreServices/MobileCoreServices.h>
#import "GMImagePickerController.h"
#import "GMAlbumsViewController.h"
#import <Photos/Photos.h>
@interface GMImagePickerController () <UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIAlertViewDelegate>
@end
@implementation GMImagePickerController
- (id)init
{
if (self = [super init]) {
_selectedAssets = [[NSMutableArray alloc] init];
// Default values:
_displaySelectionInfoToolbar = YES;
_displayAlbumsNumberOfAssets = YES;
_autoDisableDoneButton = YES;
_allowsMultipleSelection = YES;
_confirmSingleSelection = NO;
_showCameraButton = NO;
// Grid configuration:
_colsInPortrait = 3;
_colsInLandscape = 5;
_minimumInteritemSpacing = 2.0;
// Sample of how to select the collections you want to display:
_customSmartCollections = @[@(PHAssetCollectionSubtypeSmartAlbumFavorites),
@(PHAssetCollectionSubtypeSmartAlbumRecentlyAdded),
@(PHAssetCollectionSubtypeSmartAlbumVideos),
@(PHAssetCollectionSubtypeSmartAlbumSlomoVideos),
@(PHAssetCollectionSubtypeSmartAlbumTimelapses),
@(PHAssetCollectionSubtypeSmartAlbumBursts),
@(PHAssetCollectionSubtypeSmartAlbumPanoramas)];
// If you don't want to show smart collections, just put _customSmartCollections to nil;
//_customSmartCollections=nil;
// Which media types will display
_mediaTypes = @[@(PHAssetMediaTypeAudio),
@(PHAssetMediaTypeVideo),
@(PHAssetMediaTypeImage)];
self.preferredContentSize = kPopoverContentSize;
// UI Customisation
_pickerBackgroundColor = [UIColor whiteColor];
_pickerTextColor = [UIColor darkTextColor];
_pickerFontName = @"HelveticaNeue";
_pickerBoldFontName = @"HelveticaNeue-Bold";
_pickerFontNormalSize = 14.0f;
_pickerFontHeaderSize = 17.0f;
_navigationBarBackgroundColor = [UIColor whiteColor];
_navigationBarTextColor = [UIColor darkTextColor];
_navigationBarTintColor = [UIColor darkTextColor];
_toolbarBarTintColor = [UIColor whiteColor];
_toolbarTextColor = [UIColor darkTextColor];
_toolbarTintColor = [UIColor darkTextColor];
_pickerStatusBarStyle = UIStatusBarStyleDefault;
[self setupNavigationController];
}
return self;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// Ensure nav and toolbar customisations are set. Defaults are in place, but the user may have changed them
self.view.backgroundColor = _pickerBackgroundColor;
_navigationController.toolbar.translucent = YES;
_navigationController.toolbar.barTintColor = _toolbarBarTintColor;
_navigationController.toolbar.tintColor = _toolbarTintColor;
_navigationController.navigationBar.backgroundColor = _navigationBarBackgroundColor;
_navigationController.navigationBar.tintColor = _navigationBarTintColor;
NSDictionary *attributes;
if (_useCustomFontForNavigationBar) {
attributes = @{NSForegroundColorAttributeName : _navigationBarTextColor,
NSFontAttributeName : [UIFont fontWithName:_pickerBoldFontName size:_pickerFontHeaderSize]};
} else {
attributes = @{NSForegroundColorAttributeName : _navigationBarTextColor};
}
_navigationController.navigationBar.titleTextAttributes = attributes;
[self updateToolbar];
}
- (UIStatusBarStyle)preferredStatusBarStyle {
return _pickerStatusBarStyle;
}
#pragma mark - Setup Navigation Controller
- (void)setupNavigationController
{
GMAlbumsViewController *albumsViewController = [[GMAlbumsViewController alloc] init];
_navigationController = [[UINavigationController alloc] initWithRootViewController:albumsViewController];
_navigationController.delegate = self;
[_navigationController.navigationBar setTranslucent:NO];
[_navigationController willMoveToParentViewController:self];
[_navigationController.view setFrame:self.view.frame];
[self.view addSubview:_navigationController.view];
[self addConstraintsToChildViewControllersView:_navigationController.view];
[self addChildViewController:_navigationController];
[_navigationController didMoveToParentViewController:self];
}
- (void)addConstraintsToChildViewControllersView:(UIView *)view {
view.translatesAutoresizingMaskIntoConstraints = NO;
NSArray * hConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[view]-0-|" options:0 metrics:0 views:NSDictionaryOfVariableBindings(view)];
NSLayoutConstraint * topConstraint = [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.topLayoutGuide attribute:NSLayoutAttributeBottom multiplier:1 constant:0];
NSLayoutConstraint * bottomConstraint = [NSLayoutConstraint constraintWithItem:view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:view.superview attribute:NSLayoutAttributeBottom multiplier:1 constant:0];
[view.superview addConstraints:@[topConstraint,bottomConstraint]];
[view.superview addConstraints:hConstraints];
}
#pragma mark - UIAlertViewDelegate
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
// Only if OK was pressed do we want to completge the selection
[self finishPickingAssets:self];
}
}
#pragma mark - Select / Deselect Asset
- (void)selectAsset:(PHAsset *)asset
{
[self.selectedAssets insertObject:asset atIndex:self.selectedAssets.count];
[self updateDoneButton];
if (!self.allowsMultipleSelection) {
if (self.confirmSingleSelection) {
NSString *message = self.confirmSingleSelectionPrompt ? self.confirmSingleSelectionPrompt : [NSString stringWithFormat:NSLocalizedStringFromTableInBundle(@"picker.confirm.message", @"GMImagePicker", [NSBundle bundleForClass:GMImagePickerController.class], @"Do you want to select the image you tapped on?")];
[[[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:NSLocalizedStringFromTableInBundle(@"picker.confirm.title", @"GMImagePicker", [NSBundle bundleForClass:GMImagePickerController.class], @"Are You Sure?")]
message:message
delegate:self
cancelButtonTitle:[NSString stringWithFormat:NSLocalizedStringFromTableInBundle(@"picker.action.no", @"GMImagePicker", [NSBundle bundleForClass:GMImagePickerController.class], @"No")]
otherButtonTitles:[NSString stringWithFormat:NSLocalizedStringFromTableInBundle(@"picker.action.yes", @"GMImagePicker", [NSBundle bundleForClass:GMImagePickerController.class], @"Yes")], nil] show];
} else {
[self finishPickingAssets:self];
}
} else if (self.displaySelectionInfoToolbar || self.showCameraButton) {
[self updateToolbar];
}
}
- (void)deselectAsset:(PHAsset *)asset
{
[self.selectedAssets removeObjectAtIndex:[self.selectedAssets indexOfObject:asset]];
if (self.selectedAssets.count == 0) {
[self updateDoneButton];
}
if (self.displaySelectionInfoToolbar || self.showCameraButton) {
[self updateToolbar];
}
}
- (void)updateDoneButton
{
if (!self.allowsMultipleSelection) {
return;
}
UINavigationController *nav = (UINavigationController *)self.childViewControllers[0];
for (UIViewController *viewController in nav.viewControllers) {
viewController.navigationItem.rightBarButtonItem.enabled = (self.autoDisableDoneButton ? self.selectedAssets.count > 0 : TRUE);
}
}
- (void)updateToolbar
{
if (!self.allowsMultipleSelection && !self.showCameraButton) {
return;
}
UINavigationController *nav = (UINavigationController *)self.childViewControllers[0];
for (UIViewController *viewController in nav.viewControllers) {
NSUInteger index = 1;
if (_showCameraButton) {
index++;
}
[[viewController.toolbarItems objectAtIndex:index] setTitleTextAttributes:[self toolbarTitleTextAttributes] forState:UIControlStateNormal];
[[viewController.toolbarItems objectAtIndex:index] setTitleTextAttributes:[self toolbarTitleTextAttributes] forState:UIControlStateDisabled];
[[viewController.toolbarItems objectAtIndex:index] setTitle:[self toolbarTitle]];
[viewController.navigationController setToolbarHidden:(self.selectedAssets.count == 0 && !self.showCameraButton) animated:YES];
}
}
#pragma mark - User finish Actions
- (void)dismiss:(id)sender
{
if ([self.delegate respondsToSelector:@selector(assetsPickerControllerDidCancel:)]) {
[self.delegate assetsPickerControllerDidCancel:self];
}
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
- (void)finishPickingAssets:(id)sender
{
if ([self.delegate respondsToSelector:@selector(assetsPickerController:didFinishPickingAssets:)]) {
[self.delegate assetsPickerController:self didFinishPickingAssets:self.selectedAssets];
}
}
#pragma mark - Toolbar Title
- (NSPredicate *)predicateOfAssetType:(PHAssetMediaType)type
{
return [NSPredicate predicateWithBlock:^BOOL(PHAsset *asset, NSDictionary *bindings) {
return (asset.mediaType == type);
}];
}
- (NSString *)toolbarTitle
{
if (self.selectedAssets.count == 0) {
return nil;
}
NSPredicate *photoPredicate = [self predicateOfAssetType:PHAssetMediaTypeImage];
NSPredicate *videoPredicate = [self predicateOfAssetType:PHAssetMediaTypeVideo];
NSInteger nImages = [self.selectedAssets filteredArrayUsingPredicate:photoPredicate].count;
NSInteger nVideos = [self.selectedAssets filteredArrayUsingPredicate:videoPredicate].count;
if (nImages > 0 && nVideos > 0) {
return [NSString stringWithFormat:NSLocalizedStringFromTableInBundle(@"picker.selection.multiple-items", @"GMImagePicker", [NSBundle bundleForClass:GMImagePickerController.class], @"%@ Items Selected" ), @(nImages + nVideos)];
} else if (nImages > 1) {
return [NSString stringWithFormat:NSLocalizedStringFromTableInBundle(@"picker.selection.multiple-photos", @"GMImagePicker", [NSBundle bundleForClass:GMImagePickerController.class], @"%@ Photos Selected"), @(nImages)];
} else if (nImages == 1) {
return NSLocalizedStringFromTableInBundle(@"picker.selection.single-photo", @"GMImagePicker", [NSBundle bundleForClass:GMImagePickerController.class], @"1 Photo Selected" );
} else if (nVideos > 1) {
return [NSString stringWithFormat:NSLocalizedStringFromTableInBundle(@"picker.selection.multiple-videos", @"GMImagePicker", [NSBundle bundleForClass:GMImagePickerController.class], @"%@ Videos Selected"), @(nVideos)];
} else if (nVideos == 1) {
return NSLocalizedStringFromTableInBundle(@"picker.selection.single-video", @"GMImagePicker", [NSBundle bundleForClass:GMImagePickerController.class], @"1 Video Selected");
} else {
return nil;
}
}
#pragma mark - Toolbar Items
- (void)cameraButtonPressed:(UIBarButtonItem *)button
{
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Camera!"
message:@"Sorry, this device does not have a camera."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
return;
}
// This allows the selection of the image taken to be better seen if the user is not already in that VC
if (self.autoSelectCameraImages && [self.navigationController.topViewController isKindOfClass:[GMAlbumsViewController class]]) {
[((GMAlbumsViewController *)self.navigationController.topViewController) selectAllAlbumsCell];
}
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = @[(NSString *)kUTTypeImage];
picker.allowsEditing = self.allowsEditingCameraImages;
picker.delegate = self;
picker.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popPC = picker.popoverPresentationController;
popPC.permittedArrowDirections = UIPopoverArrowDirectionAny;
popPC.barButtonItem = button;
[self showViewController:picker sender:button];
}
- (NSDictionary *)toolbarTitleTextAttributes {
return @{NSForegroundColorAttributeName : _toolbarTextColor,
NSFontAttributeName : [UIFont fontWithName:_pickerFontName size:_pickerFontHeaderSize]};
}
- (UIBarButtonItem *)titleButtonItem
{
UIBarButtonItem *title = [[UIBarButtonItem alloc] initWithTitle:self.toolbarTitle
style:UIBarButtonItemStylePlain
target:nil
action:nil];
NSDictionary *attributes = [self toolbarTitleTextAttributes];
[title setTitleTextAttributes:attributes forState:UIControlStateNormal];
[title setTitleTextAttributes:attributes forState:UIControlStateDisabled];
[title setEnabled:NO];
return title;
}
- (UIBarButtonItem *)spaceButtonItem
{
return [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
}
- (UIBarButtonItem *)cameraButtonItem
{
return [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(cameraButtonPressed:)];
}
- (NSArray *)toolbarItems
{
UIBarButtonItem *camera = [self cameraButtonItem];
UIBarButtonItem *title = [self titleButtonItem];
UIBarButtonItem *space = [self spaceButtonItem];
NSMutableArray *items = [[NSMutableArray alloc] init];
if (_showCameraButton) {
[items addObject:camera];
}
[items addObject:space];
[items addObject:title];
[items addObject:space];
return [NSArray arrayWithArray:items];
}
#pragma mark - Camera Delegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
[picker.presentingViewController dismissViewControllerAnimated:YES completion:nil];
NSString *mediaType = info[UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = info[UIImagePickerControllerEditedImage] ? : info[UIImagePickerControllerOriginalImage];
UIImageWriteToSavedPhotosAlbum(image,
self,
@selector(image:finishedSavingWithError:contextInfo:),
nil);
}
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
-(void)image:(UIImage *)image finishedSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Image Not Saved"
message:@"Sorry, unable to save the new image!"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
// Note: The image view will auto refresh as the photo's are being observed in the other VCs
}
@end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 158 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 194 B

View File

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
</dict>
</plist>

2
Gifu

@ -1 +1 @@
Subproject commit ed572f53ce58b8e23499abeb3a926033cbe480f7 Subproject commit 9b1a6461aa3b5f66cb0ed3a50c5523db0b4fb007

View File

@ -26,12 +26,26 @@ public class Client {
public var timeoutInterval: TimeInterval = 60 public var timeoutInterval: TimeInterval = 60
lazy var decoder: JSONDecoder = { static let decoder: JSONDecoder = {
let decoder = JSONDecoder() let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .iso8601 let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SZ"
formatter.timeZone = TimeZone(abbreviation: "UTC")
formatter.locale = Locale(identifier: "en_US_POSIX")
decoder.dateDecodingStrategy = .formatted(formatter)
return decoder return decoder
}() }()
static let encoder: JSONEncoder = {
let encoder = JSONEncoder()
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SZ"
formatter.timeZone = TimeZone(abbreviation: "UTC")
formatter.locale = Locale(identifier: "en_US_POSIX")
encoder.dateEncodingStrategy = .formatted(formatter)
return encoder
}()
public init(baseURL: URL, accessToken: String? = nil, session: URLSession = .shared) { public init(baseURL: URL, accessToken: String? = nil, session: URLSession = .shared) {
self.baseURL = baseURL self.baseURL = baseURL
self.accessToken = accessToken self.accessToken = accessToken
@ -46,29 +60,24 @@ public class Client {
let task = session.dataTask(with: request) { data, response, error in let task = session.dataTask(with: request) { data, response, error in
if let error = error { if let error = error {
completion(.failure(error)) completion(.failure(.networkError(error)))
return return
} }
guard let data = data, guard let data = data,
let response = response as? HTTPURLResponse else { let response = response as? HTTPURLResponse else {
completion(.failure(Error.invalidResponse)) completion(.failure(.invalidResponse))
return return
} }
guard response.statusCode == 200 else { guard response.statusCode == 200 else {
let mastodonError = try? self.decoder.decode(MastodonError.self, from: data) let mastodonError = try? Client.decoder.decode(MastodonError.self, from: data)
let error = mastodonError.flatMap { Error.mastodonError($0.description) } ?? Error.unknownError let error: Error = mastodonError.flatMap { .mastodonError($0.description) } ?? .unexpectedStatus(response.statusCode)
completion(.failure(error)) completion(.failure(error))
return return
} }
guard let result = try? self.decoder.decode(Result.self, from: data) else { guard let result = try? Client.decoder.decode(Result.self, from: data) else {
completion(.failure(Error.invalidModel)) completion(.failure(.invalidModel))
return return
} }
if var result = result as? ClientModel {
result.client = self
} else if var result = result as? [ClientModel] {
result.client = self
}
let pagination = response.allHeaderFields["Link"].flatMap { $0 as? String }.flatMap(Pagination.init) let pagination = response.allHeaderFields["Link"].flatMap { $0 as? String }.flatMap(Pagination.init)
completion(.success(result, pagination)) completion(.success(result, pagination))
@ -93,7 +102,7 @@ public class Client {
// MARK: - Authorization // MARK: - Authorization
public func registerApp(name: String, redirectURI: String, scopes: [Scope], website: URL? = nil, completion: @escaping Callback<RegisteredApplication>) { public func registerApp(name: String, redirectURI: String, scopes: [Scope], website: URL? = nil, completion: @escaping Callback<RegisteredApplication>) {
let request = Request<RegisteredApplication>(method: .post, path: "/api/v1/apps", body: .parameters([ let request = Request<RegisteredApplication>(method: .post, path: "/api/v1/apps", body: ParametersBody([
"client_name" => name, "client_name" => name,
"redirect_uris" => redirectURI, "redirect_uris" => redirectURI,
"scopes" => scopes.scopeString, "scopes" => scopes.scopeString,
@ -110,7 +119,7 @@ public class Client {
} }
public func getAccessToken(authorizationCode: String, redirectURI: String, completion: @escaping Callback<LoginSettings>) { public func getAccessToken(authorizationCode: String, redirectURI: String, completion: @escaping Callback<LoginSettings>) {
let request = Request<LoginSettings>(method: .post, path: "/oauth/token", body: .parameters([ let request = Request<LoginSettings>(method: .post, path: "/oauth/token", body: ParametersBody([
"client_id" => clientID, "client_id" => clientID,
"client_secret" => clientSecret, "client_secret" => clientSecret,
"grant_type" => "authorization_code", "grant_type" => "authorization_code",
@ -126,32 +135,32 @@ public class Client {
} }
// MARK: - Self // MARK: - Self
public func getSelfAccount() -> Request<Account> { public static func getSelfAccount() -> Request<Account> {
return Request<Account>(method: .get, path: "/api/v1/accounts/verify_credentials") return Request<Account>(method: .get, path: "/api/v1/accounts/verify_credentials")
} }
public func getFavourites() -> Request<[Status]> { public static func getFavourites() -> Request<[Status]> {
return Request<[Status]>(method: .get, path: "/api/v1/favourites") return Request<[Status]>(method: .get, path: "/api/v1/favourites")
} }
public func getRelationships(accounts: [String]? = nil) -> Request<[Relationship]> { public static func getRelationships(accounts: [String]? = nil) -> Request<[Relationship]> {
return Request<[Relationship]>(method: .get, path: "/api/v1/accounts/relationships", queryParameters: "id" => accounts) return Request<[Relationship]>(method: .get, path: "/api/v1/accounts/relationships", queryParameters: "id" => accounts)
} }
public func getInstance() -> Request<Instance> { public static func getInstance() -> Request<Instance> {
return Request<Instance>(method: .get, path: "/api/v1/instance") return Request<Instance>(method: .get, path: "/api/v1/instance")
} }
public func getCustomEmoji() -> Request<[Emoji]> { public static func getCustomEmoji() -> Request<[Emoji]> {
return Request<[Emoji]>(method: .get, path: "/api/v1/custom_emojis") return Request<[Emoji]>(method: .get, path: "/api/v1/custom_emojis")
} }
// MARK: - Accounts // MARK: - Accounts
public func getAccount(id: String) -> Request<Account> { public static func getAccount(id: String) -> Request<Account> {
return Request<Account>(method: .get, path: "/api/v1/accounts/\(id)") return Request<Account>(method: .get, path: "/api/v1/accounts/\(id)")
} }
public func searchForAccount(query: String, limit: Int? = nil, following: Bool? = nil) -> Request<[Account]> { public static func searchForAccount(query: String, limit: Int? = nil, following: Bool? = nil) -> Request<[Account]> {
return Request<[Account]>(method: .get, path: "/api/v1/accounts/search", queryParameters: [ return Request<[Account]>(method: .get, path: "/api/v1/accounts/search", queryParameters: [
"q" => query, "q" => query,
"limit" => limit, "limit" => limit,
@ -160,33 +169,33 @@ public class Client {
} }
// MARK: - Blocks // MARK: - Blocks
public func getBlocks() -> Request<[Account]> { public static func getBlocks() -> Request<[Account]> {
return Request<[Account]>(method: .get, path: "/api/v1/blocks") return Request<[Account]>(method: .get, path: "/api/v1/blocks")
} }
public func getDomainBlocks() -> Request<[String]> { public static func getDomainBlocks() -> Request<[String]> {
return Request<[String]>(method: .get, path: "api/v1/domain_blocks") return Request<[String]>(method: .get, path: "api/v1/domain_blocks")
} }
public func block(domain: String) -> Request<Empty> { public static func block(domain: String) -> Request<Empty> {
return Request<Empty>(method: .post, path: "/api/v1/domain_blocks", body: .parameters([ return Request<Empty>(method: .post, path: "/api/v1/domain_blocks", body: ParametersBody([
"domain" => domain "domain" => domain
])) ]))
} }
public func unblock(domain: String) -> Request<Empty> { public static func unblock(domain: String) -> Request<Empty> {
return Request<Empty>(method: .delete, path: "/api/v1/domain_blocks", body: .parameters([ return Request<Empty>(method: .delete, path: "/api/v1/domain_blocks", body: ParametersBody([
"domain" => domain "domain" => domain
])) ]))
} }
// MARK: - Filters // MARK: - Filters
public func getFilters() -> Request<[Filter]> { public static func getFilters() -> Request<[Filter]> {
return Request<[Filter]>(method: .get, path: "/api/v1/filters") return Request<[Filter]>(method: .get, path: "/api/v1/filters")
} }
public func createFilter(phrase: String, context: [Filter.Context], irreversible: Bool? = nil, wholeWord: Bool? = nil, expiresAt: Date? = nil) -> Request<Filter> { public static func createFilter(phrase: String, context: [Filter.Context], irreversible: Bool? = nil, wholeWord: Bool? = nil, expiresAt: Date? = nil) -> Request<Filter> {
return Request<Filter>(method: .post, path: "/api/v1/filters", body: .parameters([ return Request<Filter>(method: .post, path: "/api/v1/filters", body: ParametersBody([
"phrase" => phrase, "phrase" => phrase,
"irreversible" => irreversible, "irreversible" => irreversible,
"whole_word" => wholeWord, "whole_word" => wholeWord,
@ -194,55 +203,55 @@ public class Client {
] + "context" => context.contextStrings)) ] + "context" => context.contextStrings))
} }
public func getFilter(id: String) -> Request<Filter> { public static func getFilter(id: String) -> Request<Filter> {
return Request<Filter>(method: .get, path: "/api/v1/filters/\(id)") return Request<Filter>(method: .get, path: "/api/v1/filters/\(id)")
} }
// MARK: - Follows // MARK: - Follows
public func getFollowRequests(range: RequestRange = .default) -> Request<[Account]> { public static func getFollowRequests(range: RequestRange = .default) -> Request<[Account]> {
var request = Request<[Account]>(method: .get, path: "/api/v1/follow_requests") var request = Request<[Account]>(method: .get, path: "/api/v1/follow_requests")
request.range = range request.range = range
return request return request
} }
public func getFollowSuggestions() -> Request<[Account]> { public static func getFollowSuggestions() -> Request<[Account]> {
return Request<[Account]>(method: .get, path: "/api/v1/suggestions") return Request<[Account]>(method: .get, path: "/api/v1/suggestions")
} }
public func followRemote(acct: String) -> Request<Account> { public static func followRemote(acct: String) -> Request<Account> {
return Request<Account>(method: .post, path: "/api/v1/follows", body: .parameters(["uri" => acct])) return Request<Account>(method: .post, path: "/api/v1/follows", body: ParametersBody(["uri" => acct]))
} }
// MARK: - Lists // MARK: - Lists
public func getLists() -> Request<[List]> { public static func getLists() -> Request<[List]> {
return Request<[List]>(method: .get, path: "/api/v1/lists") return Request<[List]>(method: .get, path: "/api/v1/lists")
} }
public func getList(id: String) -> Request<List> { public static func getList(id: String) -> Request<List> {
return Request<List>(method: .get, path: "/api/v1/lists/\(id)") return Request<List>(method: .get, path: "/api/v1/lists/\(id)")
} }
public func createList(title: String) -> Request<List> { public static func createList(title: String) -> Request<List> {
return Request<List>(method: .post, path: "/api/v1/lists", body: .parameters(["title" => title])) return Request<List>(method: .post, path: "/api/v1/lists", body: ParametersBody(["title" => title]))
} }
// MARK: - Media // MARK: - Media
public func upload(attachment: FormAttachment, description: String? = nil, focus: (Float, Float)? = nil) -> Request<Attachment> { public static func upload(attachment: FormAttachment, description: String? = nil, focus: (Float, Float)? = nil) -> Request<Attachment> {
return Request<Attachment>(method: .post, path: "/api/v1/media", body: .formData([ return Request<Attachment>(method: .post, path: "/api/v1/media", body: FormDataBody([
"description" => description, "description" => description,
"focus" => focus "focus" => focus
], attachment)) ], attachment))
} }
// MARK: - Mutes // MARK: - Mutes
public func getMutes(range: RequestRange) -> Request<[Account]> { public static func getMutes(range: RequestRange) -> Request<[Account]> {
var request = Request<[Account]>(method: .get, path: "/api/v1/mutes") var request = Request<[Account]>(method: .get, path: "/api/v1/mutes")
request.range = range request.range = range
return request return request
} }
// MARK: - Notifications // MARK: - Notifications
public func getNotifications(excludeTypes: [Notification.Kind], range: RequestRange = .default) -> Request<[Notification]> { public static func getNotifications(excludeTypes: [Notification.Kind], range: RequestRange = .default) -> Request<[Notification]> {
var request = Request<[Notification]>(method: .get, path: "/api/v1/notifications", queryParameters: var request = Request<[Notification]>(method: .get, path: "/api/v1/notifications", queryParameters:
"exclude_types" => excludeTypes.map { $0.rawValue } "exclude_types" => excludeTypes.map { $0.rawValue }
) )
@ -250,24 +259,24 @@ public class Client {
return request return request
} }
public func clearNotifications() -> Request<Empty> { public static func clearNotifications() -> Request<Empty> {
return Request<Empty>(method: .post, path: "/api/v1/notifications/clear") return Request<Empty>(method: .post, path: "/api/v1/notifications/clear")
} }
// MARK: - Reports // MARK: - Reports
public func getReports() -> Request<[Report]> { public static func getReports() -> Request<[Report]> {
return Request<[Report]>(method: .get, path: "/api/v1/reports") return Request<[Report]>(method: .get, path: "/api/v1/reports")
} }
public func report(account: Account, statuses: [Status], comment: String) -> Request<Report> { public static func report(account: Account, statuses: [Status], comment: String) -> Request<Report> {
return Request<Report>(method: .post, path: "/api/v1/reports", body: .parameters([ return Request<Report>(method: .post, path: "/api/v1/reports", body: ParametersBody([
"account_id" => account.id, "account_id" => account.id,
"comment" => comment "comment" => comment
] + "status_ids" => statuses.map { $0.id })) ] + "status_ids" => statuses.map { $0.id }))
} }
// MARK: - Search // MARK: - Search
public func search(query: String, resolve: Bool? = nil, limit: Int? = nil) -> Request<SearchResults> { public static func search(query: String, resolve: Bool? = nil, limit: Int? = nil) -> Request<SearchResults> {
return Request<SearchResults>(method: .get, path: "/api/v2/search", queryParameters: [ return Request<SearchResults>(method: .get, path: "/api/v2/search", queryParameters: [
"q" => query, "q" => query,
"resolve" => resolve, "resolve" => resolve,
@ -276,11 +285,11 @@ public class Client {
} }
// MARK: - Statuses // MARK: - Statuses
public func getStatus(id: String) -> Request<Status> { public static func getStatus(id: String) -> Request<Status> {
return Request<Status>(method: .get, path: "/api/v1/statuses/\(id)") return Request<Status>(method: .get, path: "/api/v1/statuses/\(id)")
} }
public func createStatus(text: String, public static func createStatus(text: String,
contentType: StatusContentType = .plain, contentType: StatusContentType = .plain,
inReplyTo: String? = nil, inReplyTo: String? = nil,
media: [Attachment]? = nil, media: [Attachment]? = nil,
@ -288,7 +297,7 @@ public class Client {
spoilerText: String? = nil, spoilerText: String? = nil,
visibility: Status.Visibility? = nil, visibility: Status.Visibility? = nil,
language: String? = nil) -> Request<Status> { language: String? = nil) -> Request<Status> {
return Request<Status>(method: .post, path: "/api/v1/statuses", body: .parameters([ return Request<Status>(method: .post, path: "/api/v1/statuses", body: ParametersBody([
"status" => text, "status" => text,
"content_type" => contentType.mimeType, "content_type" => contentType.mimeType,
"in_reply_to_id" => inReplyTo, "in_reply_to_id" => inReplyTo,
@ -300,19 +309,47 @@ public class Client {
} }
// MARK: - Timelines // MARK: - Timelines
public func getStatuses(timeline: Timeline, range: RequestRange = .default) -> Request<[Status]> { public static func getStatuses(timeline: Timeline, range: RequestRange = .default) -> Request<[Status]> {
return timeline.request(range: range) return timeline.request(range: range)
} }
// MARK: Bookmarks
public static func getBookmarks(range: RequestRange = .default) -> Request<[Status]> {
var request = Request<[Status]>(method: .get, path: "/api/v1/bookmarks")
request.range = range
return request
}
} }
extension Client { extension Client {
public enum Error: Swift.Error { public enum Error: LocalizedError {
case unknownError case networkError(Swift.Error)
case unexpectedStatus(Int)
case invalidRequest case invalidRequest
case invalidResponse case invalidResponse
case invalidModel case invalidModel
case mastodonError(String) case mastodonError(String)
public var localizedDescription: String {
switch self {
case .networkError(let error):
return "Network Error: \(error.localizedDescription)"
// todo: support more status codes
case .unexpectedStatus(413):
return "HTTP 413: Payload Too Large"
case .unexpectedStatus(let code):
return "HTTP Code \(code)"
case .invalidRequest:
return "Invalid Request"
case .invalidResponse:
return "Invalid Response"
case .invalidModel:
return "Invalid Model"
case .mastodonError(let error):
return "Server Error: \(error)"
}
}
} }
} }

View File

@ -1,39 +0,0 @@
//
// ClientModel.swift
// Pachyderm
//
// Created by Shadowfacts on 9/9/18.
// Copyright © 2018 Shadowfacts. All rights reserved.
//
import Foundation
protocol ClientModel {
var client: Client! { get set }
}
extension Array where Element == ClientModel {
var client: Client! {
get {
return first?.client
}
set {
for var el in self {
el.client = newValue
}
}
}
}
extension Array where Element: ClientModel {
var client: Client! {
get {
return first?.client
}
set {
for var el in self {
el.client = newValue
}
}
}
}

View File

@ -8,7 +8,7 @@
import Foundation import Foundation
public class Account: Decodable { public final class Account: AccountProtocol, Decodable {
public let id: String public let id: String
public let username: String public let username: String
public let acct: String public let acct: String
@ -26,15 +26,50 @@ public class Account: Decodable {
public let headerStatic: URL public let headerStatic: URL
public private(set) var emojis: [Emoji] public private(set) var emojis: [Emoji]
public let moved: Bool? public let moved: Bool?
public let fields: [Field]? public let movedTo: Account?
public let fields: [Field]
public let bot: Bool? public let bot: Bool?
public static func authorizeFollowRequest(_ account: Account) -> Request<Empty> { public required init(from decoder: Decoder) throws {
return Request<Empty>(method: .post, path: "/api/v1/follow_requests/\(account.id)/authorize") let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decode(String.self, forKey: .id)
self.username = try container.decode(String.self, forKey: .username)
self.acct = try container.decode(String.self, forKey: .acct)
self.displayName = try container.decode(String.self, forKey: .displayName)
self.locked = try container.decode(Bool.self, forKey: .locked)
self.createdAt = try container.decode(Date.self, forKey: .createdAt)
self.followersCount = try container.decode(Int.self, forKey: .followersCount)
self.followingCount = try container.decode(Int.self, forKey: .followingCount)
self.statusesCount = try container.decode(Int.self, forKey: .statusesCount)
self.note = try container.decode(String.self, forKey: .note)
self.url = try container.decode(URL.self, forKey: .url)
self.avatar = try container.decode(URL.self, forKey: .avatar)
self.avatarStatic = try container.decode(URL.self, forKey: .avatarStatic)
self.header = try container.decode(URL.self, forKey: .header)
self.headerStatic = try container.decode(URL.self, forKey: .headerStatic)
self.emojis = try container.decode([Emoji].self, forKey: .emojis)
self.fields = (try? container.decode([Field].self, forKey: .fields)) ?? []
self.bot = try? container.decode(Bool.self, forKey: .bot)
if let moved = try? container.decode(Bool.self, forKey: .moved) {
self.moved = moved
self.movedTo = nil
} else if let account = try? container.decode(Account.self, forKey: .moved) {
self.moved = true
self.movedTo = account
} else {
self.moved = false
self.movedTo = nil
}
} }
public static func rejectFollowRequest(_ account: Account) -> Request<Empty> { public static func authorizeFollowRequest(_ account: Account) -> Request<Relationship> {
return Request<Empty>(method: .post, path: "/api/v1/follow_requests/\(account.id)/reject") return Request<Relationship>(method: .post, path: "/api/v1/follow_requests/\(account.id)/authorize")
}
public static func rejectFollowRequest(_ account: Account) -> Request<Relationship> {
return Request<Relationship>(method: .post, path: "/api/v1/follow_requests/\(account.id)/reject")
} }
public static func removeFromFollowRequests(_ account: Account) -> Request<Empty> { public static func removeFromFollowRequests(_ account: Account) -> Request<Empty> {
@ -80,7 +115,7 @@ public class Account: Decodable {
} }
public static func mute(_ account: Account, notifications: Bool? = nil) -> Request<Relationship> { public static func mute(_ account: Account, notifications: Bool? = nil) -> Request<Relationship> {
return Request<Relationship>(method: .post, path: "/api/v1/accounts/\(account.id)/mute", body: .parameters([ return Request<Relationship>(method: .post, path: "/api/v1/accounts/\(account.id)/mute", body: ParametersBody([
"notifications" => notifications "notifications" => notifications
])) ]))
} }

View File

@ -12,6 +12,19 @@ public class Application: Decodable {
public let name: String public let name: String
public let website: URL? public let website: URL?
public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.name = try container.decode(String.self, forKey: .name)
if let websiteStr = try container.decodeIfPresent(String.self, forKey: .website),
let url = URL(string: websiteStr) {
self.website = url
} else {
self.website = nil
}
}
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case name case name
case website case website

View File

@ -8,18 +8,19 @@
import Foundation import Foundation
public class Attachment: Decodable { public class Attachment: Codable {
public let id: String public let id: String
public let kind: Kind public let kind: Kind
public let url: URL public let url: URL
public let remoteURL: URL? public let remoteURL: URL?
public let previewURL: URL public let previewURL: URL?
public let textURL: URL? public let textURL: URL?
public let meta: Metadata? public let meta: Metadata?
public let description: String? public let description: String?
public let blurHash: String?
public static func update(_ attachment: Attachment, focus: (Float, Float)?, description: String?) -> Request<Attachment> { public static func update(_ attachment: Attachment, focus: (Float, Float)?, description: String?) -> Request<Attachment> {
return Request<Attachment>(method: .put, path: "/api/v1/media/\(attachment.id)", body: .formData([ return Request<Attachment>(method: .put, path: "/api/v1/media/\(attachment.id)", body: FormDataBody([
"description" => (description ?? attachment.description), "description" => (description ?? attachment.description),
"focus" => focus "focus" => focus
], nil)) ], nil))
@ -29,20 +30,13 @@ public class Attachment: Decodable {
let container = try decoder.container(keyedBy: CodingKeys.self) let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decode(String.self, forKey: .id) self.id = try container.decode(String.self, forKey: .id)
self.kind = try container.decode(Kind.self, forKey: .kind) self.kind = try container.decode(Kind.self, forKey: .kind)
self.url = URL(lenient: try container.decode(String.self, forKey: .url))! self.url = try container.decode(URL.self, forKey: .url)
if let remote = try? container.decode(String.self, forKey: .remoteURL) { self.previewURL = try? container.decode(URL?.self, forKey: .previewURL)
self.remoteURL = URL(lenient: remote.replacingOccurrences(of: " ", with: "%20")) self.remoteURL = try? container.decode(URL?.self, forKey: .remoteURL)
} else { self.textURL = try? container.decode(URL?.self, forKey: .textURL)
self.remoteURL = nil self.meta = try? container.decode(Metadata?.self, forKey: .meta)
} self.description = try? container.decode(String?.self, forKey: .description)
self.previewURL = URL(lenient: try container.decode(String.self, forKey: .previewURL).replacingOccurrences(of: " ", with: "%20"))! self.blurHash = try? container.decode(String?.self, forKey: .blurHash)
if let text = try? container.decode(String.self, forKey: .textURL) {
self.textURL = URL(lenient: text.replacingOccurrences(of: " ", with: "%20"))
} else {
self.textURL = nil
}
self.meta = try? container.decode(Metadata.self, forKey: .meta)
self.description = try? container.decode(String.self, forKey: .description)
} }
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
@ -54,11 +48,12 @@ public class Attachment: Decodable {
case textURL = "text_url" case textURL = "text_url"
case meta case meta
case description case description
case blurHash = "blurhash"
} }
} }
extension Attachment { extension Attachment {
public enum Kind: String, Decodable { public enum Kind: String, Codable {
case image case image
case video case video
case gifv case gifv
@ -68,7 +63,7 @@ extension Attachment {
} }
extension Attachment { extension Attachment {
public class Metadata: Decodable { public struct Metadata: Codable {
public let length: String? public let length: String?
public let duration: Float? public let duration: Float?
public let audioEncoding: String? public let audioEncoding: String?
@ -99,7 +94,7 @@ extension Attachment {
} }
} }
public class ImageMetadata: Decodable { public struct ImageMetadata: Codable {
public let width: Int? public let width: Int?
public let height: Int? public let height: Int?
public let size: String? public let size: String?
@ -113,14 +108,3 @@ extension Attachment {
} }
} }
} }
fileprivate extension URL {
private static let allowedChars = CharacterSet.urlHostAllowed.union(.urlPathAllowed).union(.urlQueryAllowed)
init?(lenient string: String) {
guard let escaped = string.addingPercentEncoding(withAllowedCharacters: URL.allowedChars) else {
return nil
}
self.init(string: escaped)
}
}

View File

@ -22,6 +22,23 @@ public class Card: Decodable {
public let width: Int? public let width: Int?
public let height: Int? public let height: Int?
public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.url = try container.decode(URL.self, forKey: .url)
self.title = try container.decode(String.self, forKey: .title)
self.description = try container.decode(String.self, forKey: .description)
self.kind = try container.decode(Kind.self, forKey: .kind)
self.image = try? container.decode(URL.self, forKey: .image)
self.authorName = try? container.decode(String.self, forKey: .authorName)
self.authorURL = try? container.decode(URL.self, forKey: .authorURL)
self.providerName = try? container.decode(String.self, forKey: .providerName)
self.providerURL = try? container.decode(URL.self, forKey: .providerURL)
self.html = try? container.decode(String.self, forKey: .html)
self.width = try? container.decode(Int.self, forKey: .width)
self.height = try? container.decode(Int.self, forKey: .height)
}
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case url case url
case title case title

View File

@ -8,7 +8,7 @@
import Foundation import Foundation
public class Emoji: Decodable { public class Emoji: Codable {
public let shortcode: String public let shortcode: String
public let url: URL public let url: URL
public let staticURL: URL public let staticURL: URL

View File

@ -23,7 +23,7 @@ public class Filter: Decodable {
} }
public static func update(_ filter: Filter, phrase: String? = nil, context: [Context]? = nil, irreversible: Bool? = nil, wholeWord: Bool? = nil, expiresAt: Date? = nil) -> Request<Filter> { public static func update(_ filter: Filter, phrase: String? = nil, context: [Context]? = nil, irreversible: Bool? = nil, wholeWord: Bool? = nil, expiresAt: Date? = nil) -> Request<Filter> {
return Request<Filter>(method: .put, path: "/api/v1/filters/\(filter.id)", body: .parameters([ return Request<Filter>(method: .put, path: "/api/v1/filters/\(filter.id)", body: ParametersBody([
"phrase" => (phrase ?? filter.phrase), "phrase" => (phrase ?? filter.phrase),
"irreversible" => (irreversible ?? filter.irreversible), "irreversible" => (irreversible ?? filter.irreversible),
"whole_word" => (wholeWord ?? filter.wholeWord), "whole_word" => (wholeWord ?? filter.wholeWord),

View File

@ -8,7 +8,7 @@
import Foundation import Foundation
public class Hashtag: Decodable { public class Hashtag: Codable {
public let name: String public let name: String
public let url: URL public let url: URL
public let history: [History]? public let history: [History]?
@ -27,11 +27,44 @@ public class Hashtag: Decodable {
} }
extension Hashtag { extension Hashtag {
public class History: Decodable { public class History: Codable {
public let day: Date public let day: Date
public let uses: Int public let uses: Int
public let accounts: Int public let accounts: Int
public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
if let day = try? container.decode(Date.self, forKey: .day) {
self.day = day
} else if let unixTimestamp = try? container.decode(Double.self, forKey: .day) {
self.day = Date(timeIntervalSince1970: unixTimestamp)
} else if let str = try? container.decode(String.self, forKey: .day),
let unixTimestamp = Double(str) {
self.day = Date(timeIntervalSince1970: unixTimestamp)
} else {
throw DecodingError.dataCorruptedError(forKey: .day, in: container, debugDescription: "day must be either date or UNIX timestamp")
}
if let uses = try? container.decode(Int.self, forKey: .uses) {
self.uses = uses
} else if let str = try? container.decode(String.self, forKey: .uses),
let uses = Int(str) {
self.uses = uses
} else {
throw DecodingError.dataCorruptedError(forKey: .uses, in: container, debugDescription: "uses must either be int or string containing int")
}
if let accounts = try? container.decode(Int.self, forKey: .accounts) {
self.accounts = accounts
} else if let str = try? container.decode(String.self, forKey: .accounts),
let accounts = Int(str) {
self.accounts = accounts
} else {
throw DecodingError.dataCorruptedError(forKey: .accounts, in: container, debugDescription: "accounts must either be int or string containing int")
}
}
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case day case day
case uses case uses
@ -42,7 +75,7 @@ extension Hashtag {
extension Hashtag: Equatable, Hashable { extension Hashtag: Equatable, Hashable {
public static func ==(lhs: Hashtag, rhs: Hashtag) -> Bool { public static func ==(lhs: Hashtag, rhs: Hashtag) -> Bool {
return lhs.url == rhs.url return lhs.name == rhs.name
} }
public func hash(into hasher: inout Hasher) { public func hash(into hasher: inout Hasher) {

View File

@ -8,10 +8,22 @@
import Foundation import Foundation
public class List: Decodable { public class List: Decodable, Equatable, Hashable {
public let id: String public let id: String
public let title: String public let title: String
public var timeline: Timeline {
return .list(id: id)
}
public static func ==(lhs: List, rhs: List) -> Bool {
return lhs.id == rhs.id
}
public func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
public static func getAccounts(_ list: List, range: RequestRange = .default) -> Request<[Account]> { public static func getAccounts(_ list: List, range: RequestRange = .default) -> Request<[Account]> {
var request = Request<[Account]>(method: .get, path: "/api/v1/lists/\(list.id)/accounts") var request = Request<[Account]>(method: .get, path: "/api/v1/lists/\(list.id)/accounts")
request.range = range request.range = range
@ -19,22 +31,22 @@ public class List: Decodable {
} }
public static func update(_ list: List, title: String) -> Request<List> { public static func update(_ list: List, title: String) -> Request<List> {
return Request<List>(method: .put, path: "/api/v1/lists/\(list.id)", body: .parameters(["title" => title])) return Request<List>(method: .put, path: "/api/v1/lists/\(list.id)", body: ParametersBody(["title" => title]))
} }
public static func delete(_ list: List) -> Request<Empty> { public static func delete(_ list: List) -> Request<Empty> {
return Request<Empty>(method: .delete, path: "/api/v1/lists/\(list.id)") return Request<Empty>(method: .delete, path: "/api/v1/lists/\(list.id)")
} }
public static func add(_ list: List, accounts: [Account]) -> Request<Empty> { public static func add(_ list: List, accounts accountIDs: [String]) -> Request<Empty> {
return Request<Empty>(method: .post, path: "/api/v1/lists/\(list.id)/accounts", body: .parameters( return Request<Empty>(method: .post, path: "/api/v1/lists/\(list.id)/accounts", body: ParametersBody(
"account_ids" => accounts.map { $0.id } "account_ids" => accountIDs
)) ))
} }
public static func remove(_ list: List, accounts: [Account]) -> Request<Empty> { public static func remove(_ list: List, accounts accountIDs: [String]) -> Request<Empty> {
return Request<Empty>(method: .delete, path: "/api/v1/lists/\(list.id)/accounts", body: .parameters( return Request<Empty>(method: .delete, path: "/api/v1/lists/\(list.id)/accounts", body: ParametersBody(
"account_ids" => accounts.map { $0.id } "account_ids" => accountIDs
)) ))
} }

View File

@ -8,7 +8,7 @@
import Foundation import Foundation
public class Mention: Decodable { public class Mention: Codable {
public let url: URL public let url: URL
public let username: String public let username: String
public let acct: String public let acct: String

View File

@ -15,8 +15,26 @@ public class Notification: Decodable {
public let account: Account public let account: Account
public let status: Status? public let status: Status?
public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decode(String.self, forKey: .id)
if let kind = try? container.decode(Kind.self, forKey: .kind) {
self.kind = kind
} else {
self.kind = .unknown
}
self.createdAt = try container.decode(Date.self, forKey: .createdAt)
self.account = try container.decode(Account.self, forKey: .account)
if container.contains(.status) {
self.status = try container.decode(Status.self, forKey: .status)
} else {
self.status = nil
}
}
public static func dismiss(id notificationID: String) -> Request<Empty> { public static func dismiss(id notificationID: String) -> Request<Empty> {
return Request<Empty>(method: .post, path: "/api/v1/notifications/dismiss", body: .parameters([ return Request<Empty>(method: .post, path: "/api/v1/notifications/dismiss", body: ParametersBody([
"id" => notificationID "id" => notificationID
])) ]))
} }
@ -36,6 +54,8 @@ extension Notification {
case reblog case reblog
case favourite case favourite
case follow case follow
case followRequest = "follow_request"
case unknown
} }
} }

View File

@ -0,0 +1,33 @@
//
// AccountProtocol.swift
// Pachyderm
//
// Created by Shadowfacts on 4/11/20.
// Copyright © 2020 Shadowfacts. All rights reserved.
//
import Foundation
public protocol AccountProtocol {
associatedtype Account: AccountProtocol
var id: String { get }
var username: String { get }
var acct: String { get }
var displayName: String { get }
var locked: Bool { get }
var createdAt: Date { get }
var followersCount: Int { get }
var followingCount: Int { get }
var statusesCount: Int { get }
var note: String { get }
var url: URL { get }
var avatar: URL { get }
var header: URL { get }
var moved: Bool? { get }
var bot: Bool? { get }
var movedTo: Account? { get }
var emojis: [Emoji] { get }
var fields: [Pachyderm.Account.Field] { get }
}

View File

@ -0,0 +1,38 @@
//
// StatusProtocol.swift
// Pachyderm
//
// Created by Shadowfacts on 4/11/20.
// Copyright © 2020 Shadowfacts. All rights reserved.
//
import Foundation
public protocol StatusProtocol {
associatedtype Status: StatusProtocol
associatedtype Account: AccountProtocol
var id: String { get }
var uri: String { get }
var inReplyToID: String? { get }
var inReplyToAccountID: String? { get }
var content: String { get }
var createdAt: Date { get }
var reblogsCount: Int { get }
var favouritesCount: Int { get }
var reblogged: Bool { get }
var favourited: Bool { get }
var sensitive: Bool { get }
var spoilerText: String { get }
var visibility: Pachyderm.Status.Visibility { get }
var applicationName: String? { get }
var pinned: Bool? { get }
var bookmarked: Bool? { get }
var account: Account { get }
var reblog: Status? { get }
var attachments: [Attachment] { get }
var emojis: [Emoji] { get }
var hashtags: [Hashtag] { get }
var mentions: [Mention] { get }
}

View File

@ -8,7 +8,7 @@
import Foundation import Foundation
public class Status: Decodable { public final class Status: /*StatusProtocol,*/ Decodable {
public let id: String public let id: String
public let uri: String public let uri: String
public let url: URL? public let url: URL?
@ -35,23 +35,27 @@ public class Status: Decodable {
public let application: Application? public let application: Application?
public let language: String? public let language: String?
public let pinned: Bool? public let pinned: Bool?
public let bookmarked: Bool?
public let card: Card?
public static func getContext(_ status: Status) -> Request<ConversationContext> { public var applicationName: String? { application?.name }
return Request<ConversationContext>(method: .get, path: "/api/v1/statuses/\(status.id)/context")
public static func getContext(_ statusID: String) -> Request<ConversationContext> {
return Request<ConversationContext>(method: .get, path: "/api/v1/statuses/\(statusID)/context")
} }
public static func getCard(_ status: Status) -> Request<Card> { public static func getCard(_ status: Status) -> Request<Card> {
return Request<Card>(method: .get, path: "/api/v1/statuses/\(status.id)/card") return Request<Card>(method: .get, path: "/api/v1/statuses/\(status.id)/card")
} }
public static func getFavourites(_ status: Status, range: RequestRange = .default) -> Request<[Account]> { public static func getFavourites(_ statusID: String, range: RequestRange = .default) -> Request<[Account]> {
var request = Request<[Account]>(method: .get, path: "/api/v1/statuses/\(status.id)/favourited_by") var request = Request<[Account]>(method: .get, path: "/api/v1/statuses/\(statusID)/favourited_by")
request.range = range request.range = range
return request return request
} }
public static func getReblogs(_ status: Status, range: RequestRange = .default) -> Request<[Account]> { public static func getReblogs(_ statusID: String, range: RequestRange = .default) -> Request<[Account]> {
var request = Request<[Account]>(method: .get, path: "/api/v1/statuses/\(status.id)/reblogged_by") var request = Request<[Account]>(method: .get, path: "/api/v1/statuses/\(statusID)/reblogged_by")
request.range = range request.range = range
return request return request
} }
@ -60,36 +64,44 @@ public class Status: Decodable {
return Request<Empty>(method: .delete, path: "/api/v1/statuses/\(status.id)") return Request<Empty>(method: .delete, path: "/api/v1/statuses/\(status.id)")
} }
public static func reblog(_ status: Status) -> Request<Status> { public static func reblog(_ statusID: String) -> Request<Status> {
return Request<Status>(method: .post, path: "/api/v1/statuses/\(status.id)/reblog") return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/reblog")
} }
public static func unreblog(_ status: Status) -> Request<Status> { public static func unreblog(_ statusID: String) -> Request<Status> {
return Request<Status>(method: .post, path: "/api/v1/statuses/\(status.id)/unreblog") return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/unreblog")
} }
public static func favourite(_ status: Status) -> Request<Status> { public static func favourite(_ statusID: String) -> Request<Status> {
return Request<Status>(method: .post, path: "/api/v1/statuses/\(status.id)/favourite") return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/favourite")
} }
public static func unfavourite(_ status: Status) -> Request<Status> { public static func unfavourite(_ statusID: String) -> Request<Status> {
return Request<Status>(method: .post, path: "/api/v1/statuses/\(status.id)/unfavourite") return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/unfavourite")
} }
public static func pin(_ status: Status) -> Request<Status> { public static func pin(_ statusID: String) -> Request<Status> {
return Request<Status>(method: .post, path: "/api/v1/statuses/\(status.id)/pin") return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/pin")
} }
public static func unpin(_ status: Status) -> Request<Status> { public static func unpin(_ statusID: String) -> Request<Status> {
return Request<Status>(method: .post, path: "/api/v1/statuses/\(status.id)/unpin") return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/unpin")
} }
public static func muteConversation(_ status: Status) -> Request<Status> { public static func bookmark(_ statusID: String) -> Request<Status> {
return Request<Status>(method: .post, path: "/api/v1/statuses/\(status.id)/mute") return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/bookmark")
} }
public static func unmuteConversation(_ status: Status) -> Request<Status> { public static func unbookmark(_ statusID: String) -> Request<Status> {
return Request<Status>(method: .post, path: "/api/v1/statuses/\(status.id)/unmute") return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/unbookmark")
}
public static func muteConversation(_ statusID: String) -> Request<Status> {
return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/mute")
}
public static func unmuteConversation(_ statusID: String) -> Request<Status> {
return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/unmute")
} }
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
@ -118,6 +130,8 @@ public class Status: Decodable {
case application case application
case language case language
case pinned case pinned
case bookmarked
case card
} }
} }

View File

@ -33,7 +33,7 @@ extension Timeline {
} }
func request(range: RequestRange) -> Request<[Status]> { func request(range: RequestRange) -> Request<[Status]> {
var request = Request<[Status]>(method: .get, path: endpoint) var request: Request<[Status]> = Request<[Status]>(method: .get, path: endpoint)
if case .public(true) = self { if case .public(true) = self {
request.queryParameters.append("local" => true) request.queryParameters.append("local" => true)
} }

View File

@ -8,56 +8,82 @@
import Foundation import Foundation
enum Body { protocol Body {
case parameters([Parameter]?) var mimeType: String? { get }
case formData([Parameter]?, FormAttachment?) var data: Data? { get }
case empty
} }
extension Body { struct EmptyBody: Body {
private static let boundary: String = "PachydermBoundary" var mimeType: String? { nil }
var data: Data? { nil }
}
struct ParametersBody: Body {
let parameters: [Parameter]?
init(_ parmaeters: [Parameter]?) {
self.parameters = parmaeters
}
var mimeType: String? {
if parameters == nil || parameters!.isEmpty {
return nil
}
return "application/x-www-form-urlencoded; charset=utf-8"
}
var data: Data? { var data: Data? {
switch self {
case let .parameters(parameters):
return parameters?.urlEncoded.data(using: .utf8) return parameters?.urlEncoded.data(using: .utf8)
case let .formData(parameters, attachment): }
}
struct FormDataBody: Body {
private static let boundary = "PachydermBoundary"
let parameters: [Parameter]?
let attachment: FormAttachment?
init(_ parameters: [Parameter]?, _ attachment: FormAttachment?) {
self.parameters = parameters
self.attachment = attachment
}
var mimeType: String? {
if parameters == nil && attachment == nil {
return nil
}
return "multipart/form-data; boundary=\(FormDataBody.boundary)"
}
var data: Data? {
var data = Data() var data = Data()
parameters?.forEach { param in parameters?.forEach { param in
guard let value = param.value else { return } guard let value = param.value else { return }
data.append("--\(Body.boundary)\r\n") data.append("--\(FormDataBody.boundary)\r\n")
data.append("Content-Disposition: form-data; name=\"\(param.name)\"\r\n\r\n") data.append("Content-Disposition: form-data; name=\"\(param.name)\"\r\n\r\n")
data.append("\(value)\r\n") data.append("\(value)\r\n")
} }
if let attachment = attachment { if let attachment = attachment {
data.append("--\(Body.boundary)\r\n") data.append("--\(FormDataBody.boundary)\r\n")
data.append("Content-Disposition: form-data; name=\"file\"; filename=\"\(attachment.fileName)\"\r\n") data.append("Content-Disposition: form-data; name=\"file\"; filename=\"\(attachment.fileName)\"\r\n")
data.append("Content-Type: \(attachment.mimeType)\r\n\r\n") data.append("Content-Type: \(attachment.mimeType)\r\n\r\n")
data.append(attachment.data) data.append(attachment.data)
data.append("\r\n") data.append("\r\n")
} }
data.append("--\(Body.boundary)--\r\n") data.append("--\(FormDataBody.boundary)--\r\n")
return data return data
case .empty:
return nil
} }
} }
var mimeType: String? { struct JsonBody<T: Encodable>: Body {
switch self { let value: T
case let .parameters(parameters):
if parameters == nil { init(_ value: T) {
return nil self.value = value
}
return "application/x-www-form-urlencoded; charset=utf-8"
case let .formData(parameters, attachment):
if parameters == nil && attachment == nil {
return nil
}
return "multipart/form-data; boundary=\(Body.boundary)"
case .empty:
return nil
}
} }
var mimeType: String? { "application/json" }
var data: Data? { try? Client.encoder.encode(value) }
} }

View File

@ -67,8 +67,11 @@ extension Parameter: CustomStringConvertible {
extension Array where Element == Parameter { extension Array where Element == Parameter {
var urlEncoded: String { var urlEncoded: String {
return compactMap { return compactMap {
guard let value = $0.value else { return nil } guard let value = $0.value,
return "\($0.name)=\(value)" let escapedValue = value.addingPercentEncoding(withAllowedCharacters: .alphanumerics) else {
return nil
}
return "\($0.name)=\(escapedValue)"
}.joined(separator: "&") }.joined(separator: "&")
} }

View File

@ -14,7 +14,7 @@ public struct Request<ResultType: Decodable> {
let body: Body let body: Body
var queryParameters: [Parameter] var queryParameters: [Parameter]
init(method: Method, path: String, body: Body = .empty, queryParameters: [Parameter] = []) { init(method: Method, path: String, body: Body = EmptyBody(), queryParameters: [Parameter] = []) {
self.method = method self.method = method
self.path = path self.path = path
self.body = body self.body = body

View File

@ -10,5 +10,5 @@ import Foundation
public enum Response<Result: Decodable> { public enum Response<Result: Decodable> {
case success(Result, Pagination?) case success(Result, Pagination?)
case failure(Error) case failure(Client.Error)
} }

View File

@ -22,16 +22,16 @@ public class InstanceSelector {
let request = URLRequest(url: url) let request = URLRequest(url: url)
let task = URLSession.shared.dataTask(with: request) { (data, response, error) in let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
if let error = error { if let error = error {
completion(.failure(error)) completion(.failure(.networkError(error)))
return return
} }
guard let data = data, guard let data = data,
let response = response as? HTTPURLResponse else { let response = response as? HTTPURLResponse else {
completion(.failure(Client.Error.invalidResponse)) completion(.failure(.invalidResponse))
return return
} }
guard response.statusCode == 200 else { guard response.statusCode == 200 else {
completion(.failure(Client.Error.unknownError)) completion(.failure(.unexpectedStatus(response.statusCode)))
return return
} }
guard let result = try? decoder.decode([Instance].self, from: data) else { guard let result = try? decoder.decode([Instance].self, from: data) else {
@ -51,7 +51,7 @@ public extension InstanceSelector {
public let description: String public let description: String
public let proxiedThumbnailURL: URL public let proxiedThumbnailURL: URL
public let language: String public let language: String
public let category: Category public let category: String
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case domain case domain
@ -62,20 +62,3 @@ public extension InstanceSelector {
} }
} }
} }
public extension InstanceSelector {
enum Category: String, Codable {
// source: https://source.joinmastodon.org/mastodon/joinmastodon/blob/master/src/Wizard.js#L108
case general
case regional
case art
case journalism
case activism
case lgbt
case games
case tech
case adult
case furry
case food
}
}

View File

@ -9,30 +9,42 @@
import Foundation import Foundation
public class NotificationGroup { public class NotificationGroup {
public let notificationIDs: [String] public let notifications: [Notification]
public let id: String public let id: String
public let kind: Notification.Kind public let kind: Notification.Kind
public let statusState: StatusState?
init?(notifications: [Notification]) { init?(notifications: [Notification]) {
guard !notifications.isEmpty else { return nil } guard !notifications.isEmpty else { return nil }
self.notificationIDs = notifications.map { $0.id } self.notifications = notifications
self.id = notifications.first!.id self.id = notifications.first!.id
self.kind = notifications.first!.kind self.kind = notifications.first!.kind
if kind == .mention {
self.statusState = .unknown
} else {
self.statusState = nil
}
} }
public static func createGroups(notifications: [Notification], only allowedTypes: [Notification.Kind]) -> [NotificationGroup] { public static func createGroups(notifications: [Notification], only allowedTypes: [Notification.Kind]) -> [NotificationGroup] {
return notifications.reduce(into: [[Notification]]()) { (groups, notification) in var groups = [[Notification]]()
if allowedTypes.contains(notification.kind), for notification in notifications {
let lastGroup = groups.last, if allowedTypes.contains(notification.kind) {
let firstStatus = lastGroup.first, if let lastGroup = groups.last, let firstNotification = lastGroup.first, firstNotification.kind == notification.kind, firstNotification.status?.id == notification.status?.id {
firstStatus.kind == notification.kind,
firstStatus.status?.id == notification.status?.id {
groups[groups.count - 1].append(notification) groups[groups.count - 1].append(notification)
} else { continue
} else if groups.count >= 2 {
let secondToLastGroup = groups[groups.count - 2]
if allowedTypes.contains(groups[groups.count - 1][0].kind), let firstNotification = secondToLastGroup.first, firstNotification.kind == notification.kind, firstNotification.status?.id == notification.status?.id {
groups[groups.count - 2].append(notification)
continue
}
}
}
groups.append([notification]) groups.append([notification])
} }
}.map { return groups.map {
NotificationGroup(notifications: $0)! NotificationGroup(notifications: $0)!
} }
} }

View File

@ -0,0 +1,40 @@
//
// StatusState.swift
// Pachyderm
//
// Created by Shadowfacts on 11/24/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
import Foundation
public class StatusState: Equatable, Hashable {
public var collapsible: Bool?
public var collapsed: Bool?
public var unknown: Bool {
collapsible == nil || collapsed == nil
}
public init(collapsible: Bool?, collapsed: Bool?) {
self.collapsible = collapsible
self.collapsed = collapsed
}
public func copy() -> StatusState {
return StatusState(collapsible: self.collapsible, collapsed: self.collapsed)
}
public func hash(into hasher: inout Hasher) {
hasher.combine(collapsible)
hasher.combine(collapsed)
}
public static var unknown: StatusState {
StatusState(collapsible: nil, collapsed: nil)
}
public static func == (lhs: StatusState, rhs: StatusState) -> Bool {
lhs.collapsible == rhs.collapsible && lhs.collapsed == rhs.collapsed
}
}

View File

@ -1,3 +1,15 @@
# Tusker # Tusker
Tusker is a WIP iOS app for Mastodon and Pleroma. Tusker is a WIP iOS app for Mastodon and Pleroma.
## Installing for Development
Xcode 11 is required, macOS Mojave or later should work (only macOS Catalina is regularly tested).
1. Clone the project: `git clone https://git.shadowfacts.net/shadowfacts/Tusker.git`
2. Change directory into the project: `cd Tusker`
3. Clone the submodules: `git submodule init && git submodule update`
4. Open `Tusker.xcworkspace` in Xcode.
5. Change the code signing identity to your own.
6. Change the bundle identifier to something unique.
7. Select a target in the Tusker scheme and build & run.

@ -1 +0,0 @@
Subproject commit f445c9067d28346e828e615e2b43cb07b20bca35

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<Scheme <Scheme
LastUpgradeVersion = "1020" LastUpgradeVersion = "1020"
version = "1.3"> version = "1.7">
<BuildAction <BuildAction
parallelizeBuildables = "YES" parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"> buildImplicitDependencies = "YES">
@ -47,6 +47,9 @@
BlueprintName = "TuskerUITests" BlueprintName = "TuskerUITests"
ReferencedContainer = "container:Tusker.xcodeproj"> ReferencedContainer = "container:Tusker.xcodeproj">
</BuildableReference> </BuildableReference>
<DeviceAppData
resolvedPath = "../BlankSlate.xcappdata">
</DeviceAppData>
</TestableReference> </TestableReference>
<TestableReference <TestableReference
skipped = "NO"> skipped = "NO">
@ -59,17 +62,6 @@
</BuildableReference> </BuildableReference>
</TestableReference> </TestableReference>
</Testables> </Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D6D4DDCB212518A000E1C4BB"
BuildableName = "Tusker.app"
BlueprintName = "Tusker"
ReferencedContainer = "container:Tusker.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction> </TestAction>
<LaunchAction <LaunchAction
buildConfiguration = "Debug" buildConfiguration = "Debug"
@ -91,8 +83,12 @@
ReferencedContainer = "container:Tusker.xcodeproj"> ReferencedContainer = "container:Tusker.xcodeproj">
</BuildableReference> </BuildableReference>
</BuildableProductRunnable> </BuildableProductRunnable>
<AdditionalOptions> <CommandLineArguments>
</AdditionalOptions> <CommandLineArgument
argument = "-com.apple.CoreData.ConcurrencyDebug 1"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
</LaunchAction> </LaunchAction>
<ProfileAction <ProfileAction
buildConfiguration = "Release" buildConfiguration = "Release"

View File

@ -5,12 +5,18 @@
location = "container:Tusker.xcodeproj"> location = "container:Tusker.xcodeproj">
</FileRef> </FileRef>
<FileRef <FileRef
location = "group:Cache/Cache.xcodeproj"> location = "group:BlankSlate.xcappdata">
</FileRef> </FileRef>
<FileRef <FileRef
location = "group:SwiftSoup/SwiftSoup.xcodeproj"> location = "group:Cache/Cache.xcodeproj">
</FileRef> </FileRef>
<FileRef <FileRef
location = "group:Gifu/Gifu.xcodeproj"> location = "group:Gifu/Gifu.xcodeproj">
</FileRef> </FileRef>
<FileRef
location = "group:Embassy/Embassy.xcodeproj">
</FileRef>
<FileRef
location = "group:Ambassador/Ambassador.xcodeproj">
</FileRef>
</Workspace> </Workspace>

View File

@ -0,0 +1,34 @@
{
"object": {
"pins": [
{
"package": "PLCrashReporter",
"repositoryURL": "https://github.com/microsoft/plcrashreporter",
"state": {
"branch": null,
"revision": "6b7ca9a2faad6ea990ff60b0a3ee4fdf3db59150",
"version": "1.7.2"
}
},
{
"package": "SheetController",
"repositoryURL": "https://git.shadowfacts.net/shadowfacts/SheetController.git",
"state": {
"branch": "master",
"revision": "aa0f5192eaf19d01c89dbfa9ec5878a700376f23",
"version": null
}
},
{
"package": "SwiftSoup",
"repositoryURL": "https://github.com/scinfu/SwiftSoup.git",
"state": {
"branch": null,
"revision": "774dc9c7213085db8aa59595e27c1cd22e428904",
"version": "2.3.2"
}
}
]
},
"version": 1
}

View File

@ -7,25 +7,24 @@
// //
import UIKit import UIKit
import Pachyderm
class AccountActivity: UIActivity { class AccountActivity: MastodonActivity {
override class var activityCategory: UIActivity.Category { override class var activityCategory: UIActivity.Category {
return .action return .action
} }
var account: Account? var account: AccountMO?
override func canPerform(withActivityItems activityItems: [Any]) -> Bool { override func canPerform(withActivityItems activityItems: [Any]) -> Bool {
for case is Account in activityItems { for case is AccountMO in activityItems {
return true return true
} }
return false return false
} }
override func prepare(withActivityItems activityItems: [Any]) { override func prepare(withActivityItems activityItems: [Any]) {
for case let account as Account in activityItems { for case let account as AccountMO in activityItems {
self.account = account self.account = account
return return
} }

View File

@ -28,10 +28,8 @@ class FollowAccountActivity: AccountActivity {
UIImpactFeedbackGenerator(style: .medium).impactOccurred() UIImpactFeedbackGenerator(style: .medium).impactOccurred()
let request = Account.follow(account.id) let request = Account.follow(account.id)
MastodonController.client.run(request) { (response) in mastodonController.run(request) { (response) in
if case let .success(relationship, _) = response { if case .failure(_) = response {
MastodonCache.add(relationship: relationship)
} else {
// todo: display error message // todo: display error message
UINotificationFeedbackGenerator().notificationOccurred(.error) UINotificationFeedbackGenerator().notificationOccurred(.error)
fatalError() fatalError()

View File

@ -28,7 +28,9 @@ class SendMessageActivity: AccountActivity {
override var activityViewController: UIViewController? { override var activityViewController: UIViewController? {
guard let account = account else { return nil } guard let account = account else { return nil }
return UINavigationController(rootViewController: ComposeViewController(mentioningAcct: account.acct)) let draft = mastodonController.createDraft(mentioningAcct: account.acct)
let compose = ComposeHostingController(draft: draft, mastodonController: mastodonController)
return UINavigationController(rootViewController: compose)
} }
} }

View File

@ -28,10 +28,8 @@ class UnfollowAccountActivity: AccountActivity {
UIImpactFeedbackGenerator(style: .medium).impactOccurred() UIImpactFeedbackGenerator(style: .medium).impactOccurred()
let request = Account.unfollow(account.id) let request = Account.unfollow(account.id)
MastodonController.client.run(request) { (response) in mastodonController.run(request) { (response) in
if case let .success(relationship, _) = response { if case .failure(_) = response {
MastodonCache.add(relationship: relationship)
} else {
// todo: display error message // todo: display error message
UINotificationFeedbackGenerator().notificationOccurred(.error) UINotificationFeedbackGenerator().notificationOccurred(.error)
fatalError() fatalError()

View File

@ -0,0 +1,39 @@
//
// AccountActivityItemSource.swift
// Tusker
//
// Created by Shadowfacts on 5/14/20.
// Copyright © 2020 Shadowfacts. All rights reserved.
//
import UIKit
import LinkPresentation
class AccountActivityItemSource: NSObject, UIActivityItemSource {
let account: AccountMO
init(_ account: AccountMO) {
self.account = account
}
func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
return account
}
func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? {
return account
}
func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? {
let metadata = LPLinkMetadata()
metadata.originalURL = account.url
metadata.url = account.url
metadata.title = "\(account.displayName) (@\(account.username)@\(account.url.host!)"
if let data = ImageCache.avatars.get(account.avatar),
let image = UIImage(data: data) {
metadata.iconProvider = NSItemProvider(object: image)
}
return metadata
}
}

View File

@ -0,0 +1,16 @@
//
// MastodonActivity.swift
// Tusker
//
// Created by Shadowfacts on 1/5/20.
// Copyright © 2020 Shadowfacts. All rights reserved.
//
import UIKit
class MastodonActivity: UIActivity {
var mastodonController: MastodonController {
let scene = UIApplication.shared.activeOrBackgroundScene!
return scene.session.mastodonController!
}
}

View File

@ -36,10 +36,10 @@ class OpenInSafariActivity: UIActivity {
activityDidFinish(true) activityDidFinish(true)
} }
static func completionHandler(viewController: UIViewController, url: URL) -> UIActivityViewController.CompletionWithItemsHandler { static func completionHandler(navigator: TuskerNavigationDelegate, url: URL) -> UIActivityViewController.CompletionWithItemsHandler {
return { (activityType, _, _, _) in return { (activityType, _, _, _) in
if activityType == .openInSafari { if activityType == .openInSafari {
viewController.present(SFSafariViewController(url: url), animated: true) navigator.show(SFSafariViewController(url: url))
} }
} }
} }

View File

@ -0,0 +1,41 @@
//
// BookmarkStatusActivity.swift
// Tusker
//
// Created by Shadowfacts on 12/14/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
import UIKit
import Pachyderm
class BookmarkStatusActivity: StatusActivity {
override var activityType: UIActivity.ActivityType? {
return .bookmarkStatus
}
override var activityTitle: String? {
return NSLocalizedString("Bookmark", comment: "bookmark status activity title")
}
override var activityImage: UIImage? {
return UIImage(systemName: "bookmark")
}
override func perform() {
guard let status = status else { return }
let request = Status.bookmark(status.id)
mastodonController.run(request) { (response) in
if case let .success(status, _) = response {
self.mastodonController.persistentContainer.addOrUpdate(status: status, incrementReferenceCount: false)
} else {
// todo: display error message
UINotificationFeedbackGenerator().notificationOccurred(.error)
fatalError()
}
}
}
}

View File

@ -0,0 +1,40 @@
//
// MuteConversationActivity.swift
// Tusker
//
// Created by Shadowfacts on 5/14/20.
// Copyright © 2020 Shadowfacts. All rights reserved.
//
import UIKit
import Pachyderm
class MuteConversationActivity: StatusActivity {
override var activityType: UIActivity.ActivityType? {
return .muteConversation
}
override var activityTitle: String? {
return NSLocalizedString("Mute Conversation", comment: "mute conversation activity title")
}
override var activityImage: UIImage? {
return UIImage(systemName: "speaker.slash")
}
override func perform() {
guard let status = status else { return }
let request = Status.muteConversation(status.id)
mastodonController.run(request) { (response) in
if case let .success(status, _) = response {
self.mastodonController.persistentContainer.addOrUpdate(status: status, incrementReferenceCount: false)
} else {
// todo: display error message
UINotificationFeedbackGenerator().notificationOccurred(.error)
fatalError()
}
}
}
}

View File

@ -0,0 +1,39 @@
//
// PinStatusActivity.swift
// Tusker
//
// Created by Shadowfacts on 1/4/20.
// Copyright © 2020 Shadowfacts. All rights reserved.
//
import UIKit
import Pachyderm
class PinStatusActivity: StatusActivity {
override var activityType: UIActivity.ActivityType? {
return .pinStatus
}
override var activityTitle: String? {
return NSLocalizedString("Pin", comment: "pin status activity title")
}
override var activityImage: UIImage? {
return UIImage(systemName: "pin")
}
override func perform() {
guard let status = status else { return }
let request = Status.pin(status.id)
mastodonController.run(request) { (response) in
if case let .success(status, _) = response {
self.mastodonController.persistentContainer.addOrUpdate(status: status, incrementReferenceCount: false)
} else {
// todo: display error message
UINotificationFeedbackGenerator().notificationOccurred(.error)
fatalError()
}
}
}
}

View File

@ -0,0 +1,33 @@
//
// StatusActivity.swift
// Tusker
//
// Created by Shadowfacts on 12/14/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
import UIKit
class StatusActivity: MastodonActivity {
override class var activityCategory: UIActivity.Category {
return .action
}
var status: StatusMO?
override func canPerform(withActivityItems activityItems: [Any]) -> Bool {
for case is StatusMO in activityItems {
return true
}
return false
}
override func prepare(withActivityItems activityItems: [Any]) {
for case let status as StatusMO in activityItems {
self.status = status
return
}
}
}

View File

@ -0,0 +1,41 @@
//
// UnbookmarkStatusActivity.swift
// Tusker
//
// Created by Shadowfacts on 12/14/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
import UIKit
import Pachyderm
class UnbookmarkStatusActivity: StatusActivity {
override var activityType: UIActivity.ActivityType? {
return .unbookmarkStatus
}
override var activityTitle: String? {
return NSLocalizedString("Unbookmark", comment: "unbookmark status activity title")
}
override var activityImage: UIImage? {
return UIImage(systemName: "bookmark.fill")
}
override func perform() {
guard let status = status else { return }
let request = Status.unbookmark(status.id)
mastodonController.run(request) { (response) in
if case let .success(status, _) = response {
self.mastodonController.persistentContainer.addOrUpdate(status: status, incrementReferenceCount: false)
} else {
// todo: display error message
UINotificationFeedbackGenerator().notificationOccurred(.error)
fatalError()
}
}
}
}

View File

@ -0,0 +1,40 @@
//
// UnmuteConversationActivity.swift
// Tusker
//
// Created by Shadowfacts on 5/14/20.
// Copyright © 2020 Shadowfacts. All rights reserved.
//
import UIKit
import Pachyderm
class UnmuteConversationActivity: StatusActivity {
override var activityType: UIActivity.ActivityType? {
return .unmuteConversation
}
override var activityTitle: String? {
return NSLocalizedString("Unmute Conversation", comment: "unmute conversation activity title")
}
override var activityImage: UIImage? {
return UIImage(systemName: "speaker")
}
override func perform() {
guard let status = status else { return }
let request = Status.unmuteConversation(status.id)
mastodonController.run(request) { (response) in
if case let .success(status, _) = response {
self.mastodonController.persistentContainer.addOrUpdate(status: status, incrementReferenceCount: false)
} else {
// todo: display error message
UINotificationFeedbackGenerator().notificationOccurred(.error)
fatalError()
}
}
}
}

View File

@ -0,0 +1,39 @@
//
// UnpinStatusActivity.swift
// Tusker
//
// Created by Shadowfacts on 1/4/20.
// Copyright © 2020 Shadowfacts. All rights reserved.
//
import UIKit
import Pachyderm
class UnpinStatusActivity: StatusActivity {
override var activityType: UIActivity.ActivityType? {
return .unpinStatus
}
override var activityTitle: String? {
return NSLocalizedString("Unpin", comment: "unpin status activity title")
}
override var activityImage: UIImage? {
return UIImage(systemName: "pin.slash")
}
override func perform() {
guard let status = status else { return }
let request = Status.unpin(status.id)
mastodonController.run(request) { (response) in
if case let .success(status, _) = response {
self.mastodonController.persistentContainer.addOrUpdate(status: status, incrementReferenceCount: false)
} else {
// todo: display error message
UINotificationFeedbackGenerator().notificationOccurred(.error)
fatalError()
}
}
}
}

View File

@ -0,0 +1,42 @@
//
// StatusActivityItemSource.swift
// Tusker
//
// Created by Shadowfacts on 5/14/20.
// Copyright © 2020 Shadowfacts. All rights reserved.
//
import UIKit
import LinkPresentation
import SwiftSoup
class StatusActivityItemSource: NSObject, UIActivityItemSource {
let status: StatusMO
init(_ status: StatusMO) {
self.status = status
}
func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
return status
}
func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? {
return status
}
func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? {
let metadata = LPLinkMetadata()
metadata.originalURL = status.url!
metadata.url = status.url!
let doc = try! SwiftSoup.parse(status.content)
let content = try! doc.text()
metadata.title = "\(status.account.displayName): \"\(content)\""
if let data = ImageCache.avatars.get(status.account.avatar),
let image = UIImage(data: data) {
metadata.iconProvider = NSItemProvider(object: image)
}
return metadata
}
}

View File

@ -18,5 +18,11 @@ extension UIActivity.ActivityType {
static let unfollowAccount = UIActivity.ActivityType("\(Bundle.main.bundleIdentifier!).unfollow_account") static let unfollowAccount = UIActivity.ActivityType("\(Bundle.main.bundleIdentifier!).unfollow_account")
// Status // Status
static let bookmarkStatus = UIActivity.ActivityType("\(Bundle.main.bundleIdentifier!).bookmark_status")
static let unbookmarkStatus = UIActivity.ActivityType("\(Bundle.main.bundleIdentifier!).unbookmark_status")
static let pinStatus = UIActivity.ActivityType("\(Bundle.main.bundleIdentifier!).pin_status")
static let unpinStatus = UIActivity.ActivityType("\(Bundle.main.bundleIdentifier!).unpin_status")
static let muteConversation = UIActivity.ActivityType("\(Bundle.main.bundleIdentifier!).mute_conversation")
static let unmuteConversation = UIActivity.ActivityType("\(Bundle.main.bundleIdentifier!).unmute_conversation")
} }

View File

@ -7,114 +7,41 @@
// //
import UIKit import UIKit
import CrashReporter
@UIApplicationMain @UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate { class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow? static private(set) var crashReporter: PLCrashReporter!
static var pendingCrashReport: PLCrashReport?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
#if !DEBUG
setupCrashReporter()
#endif
AppShortcutItem.createItems(for: application) AppShortcutItem.createItems(for: application)
window = UIWindow(frame: UIScreen.main.bounds) DispatchQueue.global(qos: .userInitiated).async {
AudioSessionHelper.disable()
if LocalData.shared.onboardingComplete { AudioSessionHelper.setDefault()
showAppUI()
} else {
showOnboardingUI()
}
NotificationCenter.default.addObserver(self, selector: #selector(onUserLoggedOut), name: .userLoggedOut, object: nil)
window!.makeKeyAndVisible()
if let shortcutItem = launchOptions?[.shortcutItem] as? UIApplicationShortcutItem {
_ = AppShortcutItem.handle(shortcutItem)
} }
return true return true
} }
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { private func setupCrashReporter() {
if url.host == "x-callback-url" { let config = PLCrashReporterConfig(signalHandlerType: .BSD, symbolicationStrategy: .all)
return XCBManager.handle(url: url) AppDelegate.crashReporter = PLCrashReporter(configuration: config)
} else if var components = URLComponents(url: url, resolvingAgainstBaseURL: false),
let tabBarController = window!.rootViewController as? MainTabBarViewController,
let navigationController = tabBarController.viewControllers?[3] as? UINavigationController,
let searchController = navigationController.viewControllers.first as? SearchTableViewController {
components.scheme = "https" if AppDelegate.crashReporter.hasPendingCrashReport() {
let data = try! AppDelegate.crashReporter.loadPendingCrashReportDataAndReturnError()
AppDelegate.crashReporter.purgePendingCrashReport()
let report = try! PLCrashReport(data: data)
tabBarController.selectedIndex = 3 AppDelegate.pendingCrashReport = report
navigationController.popToRootViewController(animated: false)
searchController.loadViewIfNeeded()
let query = components.url!.absoluteString
searchController.searchController.searchBar.text = query
searchController.performSearch(query: query)
return true
}
return false
} }
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { AppDelegate.crashReporter.enable()
return userActivity.handleResume()
}
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
completionHandler(AppShortcutItem.handle(shortcutItem))
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
Preferences.save()
DraftsManager.save()
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
func showAppUI() {
MastodonController.createClient()
MastodonController.getOwnAccount()
MastodonController.getOwnInstance()
let tabBarController = MainTabBarViewController()
window!.rootViewController = tabBarController
}
func showOnboardingUI() {
let onboarding = OnboardingViewController()
onboarding.onboardingDelegate = self
window!.rootViewController = onboarding
}
@objc func onUserLoggedOut() {
showOnboardingUI()
}
}
extension AppDelegate: OnboardingViewControllerDelegate {
func didFinishOnboarding() {
LocalData.shared.onboardingComplete = true
showAppUI()
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 580 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 917 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Some files were not shown because too many files have changed in this diff Show More