-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove margin at the bottom of PostCaptureTab Signed-off-by: James Chien <[email protected]> * Add sharable_copy download fallback; add ShareService Signed-off-by: James Chien <[email protected]> * Improve backButton click event readability Signed-off-by: James Chien <[email protected]> * Fix broken back navigation from sending-post-capture page Use first() and untilDestroyed() to make sure the subscription terminates after the navigation. Zombie subscription is horrible 🧟 Signed-off-by: James Chien <[email protected]> * Refresh PostCapture whenever navigated and focused Refresh PostCapture whenever navigated to /home and focus on PostCaptureTab. When the PostCaptureTab is initially created, it doesn't need the navigation event (use startwith to force the first emitting), so landing on home page and go to PostCaptureTab can work correctly, as well as when the PostCaptureTab component is destoryed and re-created. Signed-off-by: James Chien <[email protected]> * Fix race condition caused by multiple subscription Use single observable to handle next-page data loading. The first batch of fetching is considered as well, so all relevant race conditions should be fixed now. However, the code is a bit messy. Need refactoring later. Signed-off-by: James Chien <[email protected]>
- Loading branch information
Showing
9 changed files
with
197 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 1 addition & 6 deletions
7
...ures/home/capture-tab/capture-details/sending-post-capture/sending-post-capture.page.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
src/app/features/home/post-capture-tab/post-capture-tab.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
.tab-content-post { | ||
margin-bottom: 128px; | ||
|
||
virtual-scroller { | ||
width: 100vw; | ||
height: 100vh; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { SharedTestingModule } from '../../shared-testing.module'; | ||
import { ShareService } from './share.service'; | ||
|
||
describe('ShareService', () => { | ||
let service: ShareService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ imports: [SharedTestingModule] }); | ||
service = TestBed.inject(ShareService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Plugins } from '@capacitor/core'; | ||
import mergeImages from 'merge-images'; | ||
import { concatMap, map } from 'rxjs/operators'; | ||
import { blobToBase64 } from '../../../utils/encoding/encoding'; | ||
import { | ||
DiaBackendAsset, | ||
DiaBackendAssetRepository, | ||
} from '../dia-backend/asset/dia-backend-asset-repository.service'; | ||
import { ImageStore } from '../image-store/image-store.service'; | ||
const { Share } = Plugins; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class ShareService { | ||
private readonly defaultSharingFrame = '/assets/image/new-year-frame.png'; | ||
private readonly defaultMimetype = 'image/jpeg'; | ||
private readonly defaultShareText = '#CaptureApp #OnlyTruePhotos'; | ||
|
||
constructor( | ||
private readonly diaBackendAssetRepository: DiaBackendAssetRepository, | ||
private readonly imageStore: ImageStore | ||
) {} | ||
|
||
async share(asset: DiaBackendAsset) { | ||
const dataUri = await this.getSharableCopy(asset).catch(() => | ||
this.getSharableCopyFallback(asset) | ||
); | ||
const fileUrl = await this.createFileUrl(dataUri); | ||
return Share.share({ | ||
text: this.defaultShareText, | ||
url: fileUrl, | ||
}); | ||
} | ||
|
||
private async createFileUrl(dataUri: string) { | ||
const base64 = dataUri.split(',')[1]; | ||
const index = await this.imageStore.write(base64, this.defaultMimetype); | ||
return this.imageStore.getUri(index); | ||
} | ||
|
||
private async getSharableCopy(asset: DiaBackendAsset) { | ||
return mergeImages( | ||
[asset.sharable_copy, this.defaultSharingFrame], | ||
// @ts-ignore | ||
{ format: this.defaultMimetype, crossOrigin: 'Anonymous' } | ||
); | ||
} | ||
|
||
// WORKAROUND: Use this fallback as a workaround for S3 CORS issue | ||
private async getSharableCopyFallback(asset: DiaBackendAsset) { | ||
const dataUri = await this.diaBackendAssetRepository | ||
.downloadFile$(asset.id, 'sharable_copy') | ||
.pipe( | ||
concatMap(blobToBase64), | ||
map(imageBase64 => `data:image/jpeg;base64,${imageBase64}`) | ||
) | ||
.toPromise(); | ||
return mergeImages( | ||
[dataUri, this.defaultSharingFrame], | ||
// @ts-ignore | ||
{ format: this.defaultMimetype, crossOrigin: 'Anonymous' } | ||
); | ||
} | ||
} |