Adding a long press action on episodes

This commit is contained in:
Zoe Roux 2021-01-01 19:21:22 +01:00
parent d11cff9176
commit 1efeab69bb
5 changed files with 51 additions and 4 deletions

View File

@ -47,6 +47,7 @@ import { InfiniteScrollModule } from "ngx-infinite-scroll";
import { ShowGridComponent } from "./components/show-grid/show-grid.component";
import { MatBadgeModule } from "@angular/material/badge";
import { StartupService } from "./services/startup.service";
import { LongPressDirective } from './misc/long-press.directive';
@NgModule({
@ -69,7 +70,8 @@ import { StartupService } from "./services/startup.service";
FormatTimePipe,
BufferToWidthPipe,
VolumeToButtonPipe,
SupportedButtonPipe
SupportedButtonPipe,
LongPressDirective
],
imports: [
BrowserModule,

View File

@ -1,12 +1,13 @@
<div class="root">
<div class="episodes" #scrollView
(scroll)="onScroll()" infinite-scroll (scrolled)="this.episodes?.loadNext(this.client)"
[horizontal]="true" [scrollWindow]="false">
[horizontal]="true" [scrollWindow]="false"
appLongPress (longPressed)="this.openMenu()">
<a *ngFor="let episode of this.episodes?.items"
routerLink="/watch/{{episode.slug}}" href="/watch/{{episode.slug}}"
class="episode" #itemsDom>
<button mat-icon-button class="moreBtn" [matMenuTriggerFor]="more" [matMenuTriggerData]="{episode: episode}"
tabindex="-1"
<button mat-icon-button class="moreBtn" tabindex="-1"
[matMenuTriggerFor]="more" [matMenuTriggerData]="{episode: episode}"
(click)="$event.stopImmediatePropagation(); $event.preventDefault()">
<mat-icon>more_vert</mat-icon>
</button>

View File

@ -152,6 +152,7 @@
.moreBtn
{
display: block;
-webkit-touch-callout: none;
}
> div

View File

@ -0,0 +1,43 @@
import { Directive, Output, EventEmitter, HostListener, HostBinding } from "@angular/core";
@Directive({
selector: `[appLongPress]`
})
export class LongPressDirective
{
@Output() longPressed = new EventEmitter();
timer: NodeJS.Timeout = null;
@HostBinding('class.longpress')
get longPress(): boolean
{
return this.timer !== null;
}
@HostListener("touchstart", ["$event"])
@HostListener("mousedown", ["$event"])
start(): void
{
this.timer = setTimeout(() => {
this.longPressed.emit();
}, 500);
}
@HostListener("touchend", ["$event"])
@HostListener("mouseup", ["$event"])
end(): void
{
clearTimeout(this.timer);
this.timer = null;
}
@HostListener("contextmenu", ["$event"])
context(event): void
{
event.preventDefault();
}
@HostBinding("style.-webkit-touch-callout")
defaultLongTouchEvent: string = "none";
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 99 KiB

After

Width:  |  Height:  |  Size: 15 KiB