From ea36ea599969951b28233b48db30e33843534504 Mon Sep 17 00:00:00 2001 From: PhantomPainX Date: Wed, 16 Aug 2023 20:11:50 -0400 Subject: [PATCH] feat: update to subjects --- src/app/app.component.ts | 10 +- .../embeds-popover.component.ts | 1 + .../core/services/sharing/sharing.service.ts | 43 +++++++- src/app/modals/settings/settings.page.ts | 6 +- .../web-video-player.page.html | 2 +- .../web-video-player.page.scss | 32 +++++- src/app/pages/admin/admin.page.html | 6 ++ src/app/pages/admin/admin.page.ts | 7 +- src/app/pages/auth/register/register.page.ts | 6 +- src/app/pages/auth/signin/signin.page.ts | 28 +++--- src/app/pages/episode/episode.page.ts | 12 ++- src/app/pages/home/home.page.scss | 2 +- src/app/pages/home/home.page.ts | 26 +---- src/app/pages/profile/profile.page.ts | 3 +- .../seen-episodes-history.page.ts | 24 ++--- src/app/services/mysql-database.service.ts | 13 ++- src/app/services/profile/profile.service.ts | 3 +- src/app/services/theme/theme.service.ts | 8 +- src/app/services/utils.service.ts | 2 +- .../video-player/video-player.service.ts | 99 +++++++++++++------ src/app/tablinks/tablinks.page.ts | 6 +- src/theme/variables.scss | 1 + 22 files changed, 219 insertions(+), 121 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 7668504..980130d 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -77,7 +77,7 @@ export class AppComponent { // } // }); - this.recentlyLoggedSubscription = this.database.recentlyLogged$.subscribe(async (logged) => { + this.recentlyLoggedSubscription = this.sharingService.getRecentlyLogged().subscribe(async (logged) => { if (logged) { this.loggedVerification(); } @@ -298,26 +298,26 @@ export class AppComponent { } addColorSchemeListener() { - this.themeChangedSubscription = this.themeService.themeChanged$.subscribe(async (darkTheme) => { + this.themeChangedSubscription = this.sharingService.getThemeChanged().subscribe(async (darkTheme) => { if (darkTheme) { document.body.classList.remove('light'); document.body.classList.add('dark'); if (this.platform.is('android')) { StatusBar.setStyle({ style: Style.Dark }); - StatusBar.setBackgroundColor({ color: '#141414' }); + StatusBar.setBackgroundColor({ color: '#0d1c35' }); } } else { document.body.classList.remove('dark'); document.body.classList.add('light'); if (this.platform.is('android')) { StatusBar.setStyle({ style: Style.Light }); - StatusBar.setBackgroundColor({ color: '#ffffff' }); + StatusBar.setBackgroundColor({ color: '#f9f9f9' }); } } }); this.localStorage.getSettings().then(settings => { if (settings) { - this.themeService.themeChanged$.emit(settings.darkTheme); + this.sharingService.emitThemeChanged(settings.darkTheme); console.log("settings.darkTheme", settings.darkTheme); } }); diff --git a/src/app/components/embeds-popover/embeds-popover.component.ts b/src/app/components/embeds-popover/embeds-popover.component.ts index 92467db..e17f8a4 100644 --- a/src/app/components/embeds-popover/embeds-popover.component.ts +++ b/src/app/components/embeds-popover/embeds-popover.component.ts @@ -142,6 +142,7 @@ export class EmbedsPopoverComponent implements OnInit { } else { this.webCompatible = this.embeds; this.optionValue = 'web'; + this.buttonsClickable = true; } } diff --git a/src/app/core/services/sharing/sharing.service.ts b/src/app/core/services/sharing/sharing.service.ts index a48827a..436f2b2 100644 --- a/src/app/core/services/sharing/sharing.service.ts +++ b/src/app/core/services/sharing/sharing.service.ts @@ -7,12 +7,53 @@ import { Subject } from 'rxjs'; export class SharingService { private userExtraSubject = new Subject(); + private recentlyLoggedSubject = new Subject(); + private seenEpisodeSubject = new Subject(); + private themeChangedSubject = new Subject(); + private episodeTimeSeenSubject = new Subject(); + private autoplayPreferencesSubject = new Subject(); + constructor() { } getUserExtra() { return this.userExtraSubject; } - emitUserExtra(value: boolean) { + emitUserExtraChange(value: boolean) { this.userExtraSubject.next(value); } + + getRecentlyLogged() { + return this.recentlyLoggedSubject; + } + emitRecentlyLoggedChange(value: boolean) { + this.recentlyLoggedSubject.next(value); + } + + getSeenEpisode() { + return this.seenEpisodeSubject; + } + emitSeenEpisodeChange(value: boolean) { + this.seenEpisodeSubject.next(value); + } + + getThemeChanged() { + return this.themeChangedSubject; + } + emitThemeChanged(value: boolean) { + this.themeChangedSubject.next(value); + } + + getEpisodeTimeSeen() { + return this.episodeTimeSeenSubject; + } + emitEpisodeTimeSeenChanged(value: boolean) { + this.episodeTimeSeenSubject.next(value); + } + + getAutoplayPreferences() { + return this.autoplayPreferencesSubject; + } + emitAutoplayPreferencesChanged(value: any) { + this.autoplayPreferencesSubject.next(value); + } } diff --git a/src/app/modals/settings/settings.page.ts b/src/app/modals/settings/settings.page.ts index 40d2e09..b164c56 100644 --- a/src/app/modals/settings/settings.page.ts +++ b/src/app/modals/settings/settings.page.ts @@ -1,8 +1,8 @@ import { Component, ElementRef, OnInit, ViewChild } from '@angular/core'; import { NavController, Platform } from '@ionic/angular'; +import { SharingService } from 'src/app/core/services/sharing/sharing.service'; import { Settings } from 'src/app/interfaces/settings'; import { PreferencesService } from 'src/app/services/preferences/preferences.service'; -import { ThemeService } from 'src/app/services/theme/theme.service'; @Component({ selector: 'app-settings', @@ -20,7 +20,7 @@ export class SettingsPage implements OnInit { @ViewChild('toolbar', { read: ElementRef }) toolbar: ElementRef; constructor(public navCtrl: NavController, public platform: Platform, public localStorage: PreferencesService, - private themeService: ThemeService) { + private sharingService: SharingService) { } @@ -69,7 +69,7 @@ export class SettingsPage implements OnInit { } else if (value == 'darkTheme') { settings.darkTheme = checked; this.darkThemeToggle = checked; - this.themeService.changeTheme(checked); + this.sharingService.emitThemeChanged(checked); } this.localStorage.setSettings(settings); diff --git a/src/app/modals/web-video-player/web-video-player.page.html b/src/app/modals/web-video-player/web-video-player.page.html index 462482d..fb4041c 100644 --- a/src/app/modals/web-video-player/web-video-player.page.html +++ b/src/app/modals/web-video-player/web-video-player.page.html @@ -1,6 +1,6 @@ - Reproductor PWA + Reproductor Web diff --git a/src/app/modals/web-video-player/web-video-player.page.scss b/src/app/modals/web-video-player/web-video-player.page.scss index 5abfe53..75428d0 100644 --- a/src/app/modals/web-video-player/web-video-player.page.scss +++ b/src/app/modals/web-video-player/web-video-player.page.scss @@ -33,22 +33,37 @@ } .boxPlayer { - background-color: var(--ion-card-background); // padding: 0 0 20px 0; border-radius: 10px; + :host-context(body.light) & { + background-color: #f4f4f4; + } + + :host-context(body.dark) & { + background-color: var(--ion-card-background); + } + .iframeContainer { position: relative; overflow: hidden; - background-color: #2e3a4d; width: 100%; padding-top: 56.25%; + border-radius: 5px 5px 0 0; + + :host-context(body.light) & { + background-color: #f4f4f4; + } + + :host-context(body.dark) & { + background-color: #2e3a4d; + } &::before { content: "Selecciona un video"; position: absolute; display: flex; - color: #cfcfcf; + color: #aeaeae; top: 0; width: 100%; height: 100%; @@ -71,8 +86,15 @@ .buttons { ion-toolbar { - --background: var(--ion-card-background); - --border-radius: 50px; + border-radius: 0 0 10px 10px; + + :host-context(body.light) & { + --background: #d7d7d7; + } + + :host-context(body.dark) & { + --background: var(--ion-card-background); + } } } } diff --git a/src/app/pages/admin/admin.page.html b/src/app/pages/admin/admin.page.html index 0572147..3436afa 100644 --- a/src/app/pages/admin/admin.page.html +++ b/src/app/pages/admin/admin.page.html @@ -5,6 +5,12 @@ + + + + + + diff --git a/src/app/pages/admin/admin.page.ts b/src/app/pages/admin/admin.page.ts index 8b5bd40..824132b 100644 --- a/src/app/pages/admin/admin.page.ts +++ b/src/app/pages/admin/admin.page.ts @@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core'; import { Platform } from '@ionic/angular'; import { PrivateUser } from 'src/app/classes/private-user/private-user'; import { PreferencesService } from 'src/app/services/preferences/preferences.service'; +import { VideoPlayerService } from 'src/app/services/video-player/video-player.service'; @Component({ selector: 'app-admin', @@ -12,7 +13,7 @@ export class AdminPage implements OnInit { public user: PrivateUser; public isLogged: boolean = true; - constructor(public platform: Platform, public localStorage: PreferencesService) { } + constructor(public platform: Platform, public localStorage: PreferencesService, private videoPlayerService: VideoPlayerService) { } ngOnInit() { this.platform.ready().then(async () => { @@ -23,4 +24,8 @@ export class AdminPage implements OnInit { }); } + public playRadio() { + this.videoPlayerService.playRadio(); + } + } diff --git a/src/app/pages/auth/register/register.page.ts b/src/app/pages/auth/register/register.page.ts index 41a8417..a28da06 100644 --- a/src/app/pages/auth/register/register.page.ts +++ b/src/app/pages/auth/register/register.page.ts @@ -13,6 +13,7 @@ import { UtilsService } from 'src/app/services/utils.service'; import { NativeBiometric } from "@capgo/capacitor-native-biometric"; import { environment } from 'src/environments/environment.prod'; +import { SharingService } from 'src/app/core/services/sharing/sharing.service'; @Component({ selector: 'app-register', @@ -35,7 +36,8 @@ export class RegisterPage implements OnInit { public modalCtrl: ModalController, public localStorage: PreferencesService, public profileService: ProfileService, - public alertCtrl: AlertController) { + public alertCtrl: AlertController, + private sharingService: SharingService) { this.formRegister = this.formBuilder.group({ username: ['', [ @@ -197,7 +199,7 @@ export class RegisterPage implements OnInit { this.localStorage.setGuest(false); this.setUserBioCredentials(this.formRegister.value.email, this.formRegister.value.password); - this.database.recentlyLogged$.emit(true); + this.sharingService.emitRecentlyLoggedChange(true); this.modalCtrl.dismiss({ success: true }); } else { diff --git a/src/app/pages/auth/signin/signin.page.ts b/src/app/pages/auth/signin/signin.page.ts index b72ce15..a3efe70 100644 --- a/src/app/pages/auth/signin/signin.page.ts +++ b/src/app/pages/auth/signin/signin.page.ts @@ -15,6 +15,7 @@ import { Subscription } from 'rxjs'; import { NativeBiometric, BiometricOptions } from "@capgo/capacitor-native-biometric"; import { environment } from 'src/environments/environment.prod'; import { ForgotPasswordPage } from '../forgot-password/forgot-password.page'; +import { SharingService } from 'src/app/core/services/sharing/sharing.service'; @Component({ selector: 'app-signin', @@ -45,7 +46,8 @@ export class SigninPage implements OnInit { public platform: Platform, public modalCtrl: ModalController, public localStorage: PreferencesService, - public alertCtrl: AlertController) { + public alertCtrl: AlertController, + private sharingService: SharingService) { this.formLogin = this.formBuilder.group({ email: ['', [ @@ -213,7 +215,7 @@ export class SigninPage implements OnInit { this.localStorage.setLogged(true); this.localStorage.setGuest(false); - this.database.recentlyLogged$.emit(true); + this.sharingService.emitRecentlyLoggedChange(true); this.modalCtrl.dismiss({ success: true }); } else { const modal = await this.modalCtrl.create({ @@ -229,7 +231,7 @@ export class SigninPage implements OnInit { this.localStorage.setLogged(true); this.localStorage.setGuest(false); - this.database.recentlyLogged$.emit(true); + this.sharingService.emitRecentlyLoggedChange(true); this.modalCtrl.dismiss({ success: true }); } } @@ -257,7 +259,7 @@ export class SigninPage implements OnInit { this.localStorage.setLogged(true); this.localStorage.setGuest(false); - this.database.recentlyLogged$.emit(true); + this.sharingService.emitRecentlyLoggedChange(true); this.modalCtrl.dismiss({ success: true }); } else { const modal = await this.modalCtrl.create({ @@ -273,7 +275,7 @@ export class SigninPage implements OnInit { this.localStorage.setLogged(true); this.localStorage.setGuest(false); - this.database.recentlyLogged$.emit(true); + this.sharingService.emitRecentlyLoggedChange(true); this.modalCtrl.dismiss({ success: true }); } } @@ -386,7 +388,7 @@ export class SigninPage implements OnInit { this.setUserBioCredentials(this.formLogin.value.email, this.formLogin.value.password); } - this.database.recentlyLogged$.emit(true); + this.sharingService.emitRecentlyLoggedChange(true); this.modalCtrl.dismiss({ success: true }); } else { const modal = await this.modalCtrl.create({ @@ -405,7 +407,7 @@ export class SigninPage implements OnInit { this.setUserBioCredentials(this.formLogin.value.email, this.formLogin.value.password); } - this.database.recentlyLogged$.emit(true); + this.sharingService.emitRecentlyLoggedChange(true); this.modalCtrl.dismiss({ success: true }); } } @@ -435,7 +437,7 @@ export class SigninPage implements OnInit { this.setUserBioCredentials(this.formLogin.value.email, this.formLogin.value.password); } - this.database.recentlyLogged$.emit(true); + this.sharingService.emitRecentlyLoggedChange(true); this.modalCtrl.dismiss({ success: true }); } else { const modal = await this.modalCtrl.create({ @@ -454,7 +456,7 @@ export class SigninPage implements OnInit { this.setUserBioCredentials(this.formLogin.value.email, this.formLogin.value.password); } - this.database.recentlyLogged$.emit(true); + this.sharingService.emitRecentlyLoggedChange(true); this.modalCtrl.dismiss({ success: true }); } } @@ -589,7 +591,7 @@ export class SigninPage implements OnInit { this.localStorage.setLogged(true); this.localStorage.setGuest(false); - this.database.recentlyLogged$.emit(true); + this.sharingService.emitRecentlyLoggedChange(true); this.modalCtrl.dismiss({ success: true }); } else { const modal = await this.modalCtrl.create({ @@ -605,7 +607,7 @@ export class SigninPage implements OnInit { this.localStorage.setLogged(true); this.localStorage.setGuest(false); - this.database.recentlyLogged$.emit(true); + this.sharingService.emitRecentlyLoggedChange(true); this.modalCtrl.dismiss({ success: true }); } } @@ -632,7 +634,7 @@ export class SigninPage implements OnInit { this.localStorage.setLogged(true); this.localStorage.setGuest(false); - this.database.recentlyLogged$.emit(true); + this.sharingService.emitRecentlyLoggedChange(true); this.modalCtrl.dismiss({ success: true }); } else { const modal = await this.modalCtrl.create({ @@ -648,7 +650,7 @@ export class SigninPage implements OnInit { this.localStorage.setLogged(true); this.localStorage.setGuest(false); - this.database.recentlyLogged$.emit(true); + this.sharingService.emitRecentlyLoggedChange(true); this.modalCtrl.dismiss({ success: true }); } } diff --git a/src/app/pages/episode/episode.page.ts b/src/app/pages/episode/episode.page.ts index 794df71..d62ab6d 100644 --- a/src/app/pages/episode/episode.page.ts +++ b/src/app/pages/episode/episode.page.ts @@ -16,6 +16,7 @@ import { WebVideoPlayerPage } from 'src/app/modals/web-video-player/web-video-pl import { VideoPlayerService } from 'src/app/services/video-player/video-player.service'; import { AutoplayService } from 'src/app/services/autoplay/autoplay.service'; import { Domains } from 'src/app/components/embeds-popover/domains'; +import { SharingService } from 'src/app/core/services/sharing/sharing.service'; @Component({ selector: 'app-episode', @@ -61,7 +62,7 @@ export class EpisodePage implements OnInit { public utils: UtilsService, public platform: Platform, public localStorage: PreferencesService, public admob: AdsService, public differs: KeyValueDiffers, public actionSheetCtrl: ActionSheetController, private videoPlayerService: VideoPlayerService, private toastCtrl: ToastController, - private autoplayService: AutoplayService) { + private autoplayService: AutoplayService, private sharingService: SharingService) { this.mediaUrl = this.database.animeMedia; } @@ -69,7 +70,7 @@ export class EpisodePage implements OnInit { this.platform.ready().then(async () => { - this.recentlySawVideoSubscription = this.videoPlayerService.recentlySawVideo$.subscribe(async (data) => { + this.recentlySawVideoSubscription = this.sharingService.getAutoplayPreferences().subscribe((data) => { console.log("sub receltrysawvideo: ", data); if (data.episode.nextEpisode && this.autoplay) { @@ -121,7 +122,7 @@ export class EpisodePage implements OnInit { this.objDiffer[elt] = this.differs.find(elt).create(); }); - this.toggleSeenEpisodeSubscription = this.database.toggleSeenEpisode$.subscribe(() => { + this.toggleSeenEpisodeSubscription = this.sharingService.getSeenEpisode().subscribe(() => { //hay que esperar 1 ms para que se actualice el episodio setTimeout(() => { this.checkNextToSeeEpisode(); @@ -430,7 +431,10 @@ export class EpisodePage implements OnInit { testAutoPlay() { this.anime.episodios[0].nextEpisode = this.anime.episodios[1]; - this.videoPlayerService.recentlySawVideo$.emit({ + // this.videoPlayerService.recentlySawVideo$.emit({ + // episode: this.anime.episodios[0], + // }); + this.sharingService.emitAutoplayPreferencesChanged({ episode: this.anime.episodios[0], }); } diff --git a/src/app/pages/home/home.page.scss b/src/app/pages/home/home.page.scss index bf86da2..7a0f172 100644 --- a/src/app/pages/home/home.page.scss +++ b/src/app/pages/home/home.page.scss @@ -55,7 +55,7 @@ ion-header { width: 30px; height: 30px; border-radius: 50%; - border: 0.5px solid rgb(202, 202, 202); + border: 1px solid rgb(202, 202, 202); img { border-radius: 50%; diff --git a/src/app/pages/home/home.page.ts b/src/app/pages/home/home.page.ts index 29e0223..572943d 100644 --- a/src/app/pages/home/home.page.ts +++ b/src/app/pages/home/home.page.ts @@ -153,34 +153,19 @@ export class HomePage implements OnInit { this.token = this.user.token; this.profileImage = this.fixImage(this.user.user_extra.avatar); this.obtainNextToSee(); - // document.addEventListener('itemInserted', this.func, false); - this.episodeTimeSeenChangedSubscription = this.videoPlayerService.episodeTimeSeenChanged$.subscribe(async () => { - this.zone.run(() => { - this.obtainNextToSee(); - }); - }); - this.toggleSeenEpisodeSubscription = this.database.toggleSeenEpisode$.subscribe(async () => { - this.zone.run(() => { - this.obtainNextToSee(); - }); + this.toggleSeenEpisodeSubscription = this.sharingService.getSeenEpisode().subscribe(async () => { + this.obtainNextToSee(); }); } else { - this.recentlyLoggedSubscription = this.database.recentlyLogged$.subscribe(async (logged) => { + this.recentlyLoggedSubscription = this.sharingService.getRecentlyLogged().subscribe(async (logged) => { this.isLogged = logged; if (this.isLogged) { this.user = await this.localStorage.getUser(); this.token = this.user.token; this.profileImage = this.fixImage(this.user.user_extra.avatar); this.obtainNextToSee(); - this.episodeTimeSeenChangedSubscription = this.videoPlayerService.episodeTimeSeenChanged$.subscribe(async () => { - this.zone.run(() => { - this.obtainNextToSee(); - }); - }); - this.toggleSeenEpisodeSubscription = this.database.toggleSeenEpisode$.subscribe(async () => { - this.zone.run(() => { - this.obtainNextToSee(); - }); + this.toggleSeenEpisodeSubscription = this.sharingService.getSeenEpisode().subscribe(async () => { + this.obtainNextToSee(); }); this.recentlyLoggedSubscription.unsubscribe(); } @@ -188,7 +173,6 @@ export class HomePage implements OnInit { } this.updatedUserExtraSubscription = this.sharingService.getUserExtra().subscribe(async (updated) => { - console.log("updatedUserExtraSubscription: ", updated) if (updated) { const oldImage = this.fixImage(this.profileImage); const temp_user = await this.localStorage.getUser(); diff --git a/src/app/pages/profile/profile.page.ts b/src/app/pages/profile/profile.page.ts index b2e430d..ee37b7b 100644 --- a/src/app/pages/profile/profile.page.ts +++ b/src/app/pages/profile/profile.page.ts @@ -226,6 +226,7 @@ export class ProfilePage implements OnInit { this.formProfile.controls.email.setValue(this.user.email); this.user = await this.localStorage.getUser(); + this.sharingService.emitUserExtraChange(true); if (showToast) { await this.utils.showToast('Cuenta sincronizada', 1, true); @@ -348,7 +349,7 @@ export class ProfilePage implements OnInit { this.utils.showToast(response.message, 2, true); this.staticImage = this.image; await this.syncUser(false); - this.sharingService.emitUserExtra(true); + this.sharingService.emitUserExtraChange(true); //this.profileService.updatedUserExtra$.emit(true); } else { this.image = this.staticImage; diff --git a/src/app/pages/seen-episodes-history/seen-episodes-history.page.ts b/src/app/pages/seen-episodes-history/seen-episodes-history.page.ts index d881d91..2824eef 100644 --- a/src/app/pages/seen-episodes-history/seen-episodes-history.page.ts +++ b/src/app/pages/seen-episodes-history/seen-episodes-history.page.ts @@ -10,6 +10,7 @@ import { EpisodePage } from '../episode/episode.page'; import { WebVideoPlayerPage } from 'src/app/modals/web-video-player/web-video-player.page'; import { VideoPlayerService } from 'src/app/services/video-player/video-player.service'; import { Subscription } from 'rxjs'; +import { SharingService } from 'src/app/core/services/sharing/sharing.service'; @Component({ selector: 'app-seen-episodes-history', @@ -46,7 +47,8 @@ export class SeenEpisodesHistoryPage implements OnInit { private navCtrl: NavController, private localStorage: PreferencesService, private videoPlayerService: VideoPlayerService, - public zone: NgZone + public zone: NgZone, + private sharingService: SharingService ) { } ngOnInit() { @@ -56,10 +58,8 @@ export class SeenEpisodesHistoryPage implements OnInit { const user = await this.localStorage.getUser(); this.token = user.token; - this.episodeTimeSeenChangedSubscription = this.videoPlayerService.episodeTimeSeenChanged$.subscribe(async () => { - this.zone.run(() => { - this.getResults(this.sortName); - }); + this.episodeTimeSeenChangedSubscription = this.sharingService.getEpisodeTimeSeen().subscribe(async () => { + this.getResults(this.sortName); }); } else { this.navCtrl.navigateRoot('/signin'); @@ -71,28 +71,20 @@ export class SeenEpisodesHistoryPage implements OnInit { } ngOnDestroy() { - if (this.episodeTimeSeenChangedSubscription) { - this.episodeTimeSeenChangedSubscription.unsubscribe(); - } + // if (this.episodeTimeSeenChangedSubscription) { + // this.episodeTimeSeenChangedSubscription.unsubscribe(); + // } } private async getResults(ordering: string) : Promise { await this.database.getSeenEpisodesHistory(1, ordering, this.token).then(data => { this.results = data.results; - console.log(this.results); this.totalResults = data.count; this.pagination = { 'actualPage': 1, 'hasNextPage': data.next != null, } - // this.results = []; - // console.log(this.results); - // this.totalResults = 0; - // this.pagination = { - // 'actualPage': 1, - // 'hasNextPage': false, - // } }); // no hay catch porque los errores se controlan en el servicio if (this.results.length == 0) { diff --git a/src/app/services/mysql-database.service.ts b/src/app/services/mysql-database.service.ts index cd8bafa..caed528 100644 --- a/src/app/services/mysql-database.service.ts +++ b/src/app/services/mysql-database.service.ts @@ -6,8 +6,8 @@ import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth'; import { PreferencesService } from './preferences/preferences.service'; // import { FirebaseMessaging } from '@capacitor-firebase/messaging'; import { environment } from 'src/environments/environment.prod'; -import { EventEmitter } from '@angular/core'; import { Settings } from '../interfaces/settings'; +import { SharingService } from '../core/services/sharing/sharing.service'; // import { CapacitorHttp } from '@capacitor/core'; @@ -59,12 +59,11 @@ export class MysqlDatabaseService { public amrCheckAndroidVersion: boolean = false; public amrGetSeenEpisodesHistory: boolean = false; - public recentlyLogged$: EventEmitter = new EventEmitter(); - public toggleSeenEpisode$: EventEmitter = new EventEmitter(); constructor( public utils: UtilsService, - public localStorage: PreferencesService + public localStorage: PreferencesService, + private sharingService: SharingService ) { } getCookie(name) { @@ -872,13 +871,13 @@ export class MysqlDatabaseService { }).then(async response => { if (response.status == 201) { resolve(true); - this.toggleSeenEpisode$.emit(true); + this.sharingService.emitSeenEpisodeChange(true); } else if (response.status == 200) { resolve(true) - this.toggleSeenEpisode$.emit(true); + this.sharingService.emitSeenEpisodeChange(true); } else if (response.status == 204) { resolve(false); - this.toggleSeenEpisode$.emit(false); + this.sharingService.emitSeenEpisodeChange(true); } else if (response.status == 403) { const data = await response.json(); diff --git a/src/app/services/profile/profile.service.ts b/src/app/services/profile/profile.service.ts index ead1cb6..17862d7 100644 --- a/src/app/services/profile/profile.service.ts +++ b/src/app/services/profile/profile.service.ts @@ -1,4 +1,4 @@ -import { EventEmitter, Injectable } from '@angular/core'; +import { Injectable } from '@angular/core'; import { PrivateUser } from 'src/app/classes/private-user/private-user'; import { environment } from 'src/environments/environment.prod'; import { UtilsService } from '../utils.service'; @@ -14,7 +14,6 @@ export class ProfileService { public amrDeleteUserData: boolean = false; public amrUpdateUserExtra: boolean = false; - public updatedUserExtra$: EventEmitter = new EventEmitter(); constructor(public utils: UtilsService) { } diff --git a/src/app/services/theme/theme.service.ts b/src/app/services/theme/theme.service.ts index ed96a76..726a757 100644 --- a/src/app/services/theme/theme.service.ts +++ b/src/app/services/theme/theme.service.ts @@ -6,10 +6,10 @@ import { EventEmitter } from '@angular/core'; }) export class ThemeService { - public themeChanged$: EventEmitter = new EventEmitter(); + // public themeChanged$: EventEmitter = new EventEmitter(); constructor() { } - public changeTheme(darkTheme: boolean) { - this.themeChanged$.emit(darkTheme); - } + // public changeTheme(darkTheme: boolean) { + // this.themeChanged$.emit(darkTheme); + // } } diff --git a/src/app/services/utils.service.ts b/src/app/services/utils.service.ts index 9ed7717..2344599 100644 --- a/src/app/services/utils.service.ts +++ b/src/app/services/utils.service.ts @@ -115,7 +115,7 @@ export class UtilsService { StatusBar.setBackgroundColor({ color: "#0d1c35" }); } else { StatusBar.setStyle({ style: Style.Light }); - StatusBar.setBackgroundColor({ color: "#FFFFFF" }); + StatusBar.setBackgroundColor({ color: "#f9f9f9" }); } } } diff --git a/src/app/services/video-player/video-player.service.ts b/src/app/services/video-player/video-player.service.ts index 28a04c9..a1146ba 100644 --- a/src/app/services/video-player/video-player.service.ts +++ b/src/app/services/video-player/video-player.service.ts @@ -8,39 +8,37 @@ import { MysqlDatabaseService } from '../mysql-database.service'; import { PreferencesService } from '../preferences/preferences.service'; import { environment } from 'src/environments/environment.prod'; import { Settings } from 'src/app/interfaces/settings'; +import { SharingService } from 'src/app/core/services/sharing/sharing.service'; @Injectable({ providedIn: 'root' }) export class VideoPlayerService { - public capacitorVideoPlayer: any = CapacitorVideoPlayer; - @ViewChild('toolbar', { read: ElementRef }) toolbar: ElementRef; + private capacitorVideoPlayer: any = CapacitorVideoPlayer; + @ViewChild('toolbar', { read: ElementRef }) private toolbar: ElementRef; // [IMPORTANTE] Como es un servicio, se necesitan controlar las variables de forma manual // no tiene ciclo de vida como un componente - public domain: string = environment.root_url; - public seconds: number = 0; - public interval: any; - public videoDuration: number = 0.0; - public seenSeconds: number = 0.0; // variable que guarda los segundos vistos del episodio - public readyHandler: any; - public endHandler: any; - public exitHandler: any; - public needSeek: boolean = false; - public seekTime: number = 0; - public episodeWasMarkedAsSeen: boolean = false; - - public episodeTimeSeenChanged$: EventEmitter = new EventEmitter(); - public recentlySawVideo$: EventEmitter = new EventEmitter(); - - constructor(public screenOrientation: ScreenOrientation, public platform: Platform, public utils: UtilsService, - public database: MysqlDatabaseService, public localStorage: PreferencesService, - public zone: NgZone, public alertCtrl: AlertController) { + private domain: string = environment.root_url; + private seconds: number = 0; + private interval: any; + private videoDuration: number = 0.0; + private seenSeconds: number = 0.0; // variable que guarda los segundos vistos del episodio + private readyHandler: any; + private endHandler: any; + private exitHandler: any; + private needSeek: boolean = false; + private seekTime: number = 0; + private episodeWasMarkedAsSeen: boolean = false; + + constructor(private screenOrientation: ScreenOrientation, private platform: Platform, private utils: UtilsService, + private database: MysqlDatabaseService, private localStorage: PreferencesService, + private zone: NgZone, private alertCtrl: AlertController, private sharingService: SharingService) { } - async toggleEpisode(episode: any, token: string) { + private async toggleEpisode(episode: any, token: string) { this.database.toggleSeenEpisode(token, episode.id).then((added) => { if (added) { @@ -51,7 +49,7 @@ export class VideoPlayerService { }); } - async nativePlayer(video: any, subtitleUrl: string, title: string, smallTitle: string, image: string, episode: any, isLogged: boolean, user: any, + public async nativePlayer(video: any, subtitleUrl: string, title: string, smallTitle: string, image: string, episode: any, isLogged: boolean, user: any, settings: Settings, providerName: string, videoProviderDomains: any, videoProviderQuality: string) { const loader = await this.utils.createIonicLoader("Por favor espera..."); @@ -107,7 +105,7 @@ export class VideoPlayerService { } - async executePlayer(video: any, subtitleUrl: string, title: string, smallTitle: string, image: string, episode: any, isLogged: boolean, user: any, + private async executePlayer(video: any, subtitleUrl: string, title: string, smallTitle: string, image: string, episode: any, isLogged: boolean, user: any, settings: Settings, providerName: string, videoProviderDomains: any, videoProviderQuality: string) { this.episodeWasMarkedAsSeen = false; @@ -119,7 +117,7 @@ export class VideoPlayerService { headers: video.headers, title: title, smallTitle: smallTitle, - accentColor: "#f0b400", + accentColor: "#64fada", chromecast: settings.chromecastEnabled, artwork: image, pipEnabled: settings.pipEnabled @@ -180,7 +178,10 @@ export class VideoPlayerService { videoProviderDomains, videoProviderQuality ).then(() => { - this.recentlySawVideo$.emit({ + // this.recentlySawVideo$.emit({ + // episode: episode + // }); + this.sharingService.emitAutoplayPreferencesChanged({ episode: episode }); }); @@ -200,7 +201,7 @@ export class VideoPlayerService { episode.seconds_seen.episode = episode.id; if (!this.episodeWasMarkedAsSeen) { - this.episodeTimeSeenChanged$.emit(true); + this.sharingService.emitEpisodeTimeSeenChanged(true); } }); }); @@ -260,7 +261,7 @@ export class VideoPlayerService { episode.seconds_seen.episode = episode.id; if (!this.episodeWasMarkedAsSeen) { - this.episodeTimeSeenChanged$.emit(true); + this.sharingService.emitEpisodeTimeSeenChanged(true); } }); }); @@ -294,7 +295,10 @@ export class VideoPlayerService { videoProviderDomains, videoProviderQuality ).then(() => { - this.recentlySawVideo$.emit({ + // this.recentlySawVideo$.emit({ + // episode: episode + // }); + this.sharingService.emitAutoplayPreferencesChanged({ episode: episode }); }); @@ -314,13 +318,46 @@ export class VideoPlayerService { } - removeAllListeners() { + public playRadio() { + let options: capVideoPlayerOptions = { + mode: 'fullscreen', + url: 'https://thisisamazing.tv/live.m3u8', + playerId: 'player32', + title: 'Music Live Radio', + smallTitle: 'thisisamazing.tv', + accentColor: "#64fada", + chromecast: true, + artwork: 'https://img.freepik.com/premium-photo/music-mind-music-abstract-art-created-with-generative-ai-technology_545448-15311.jpg', + pipEnabled: true + } + this.capacitorVideoPlayer.initPlayer(options).then(() => { + this.capacitorVideoPlayer.play({playerId: 'player32'}).then(async () => { + if (this.platform.is('android')) { + this.screenOrientation.unlock(); + } + + this.exitHandler = await this.capacitorVideoPlayer.addListener('jeepCapVideoPlayerExit', () => { + if (this.platform.is('android')) { + this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT); + } + }); + + this.endHandler = await this.capacitorVideoPlayer.addListener('jeepCapVideoPlayerEnded', () => { + if (this.platform.is('android')) { + this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT); + } + }); + }); + }); + } + + private removeAllListeners() { this.readyHandler.remove(); this.exitHandler.remove(); this.endHandler.remove(); } - getSeenEpisodeTime(episode: number, token: string) { + private getSeenEpisodeTime(episode: number, token: string) { return new Promise((resolve, reject) => { const url = this.domain + '/api/v1/seen-episode-time/?episode=' + episode; fetch(url, { @@ -341,7 +378,7 @@ export class VideoPlayerService { }); } - postSeenEpisodeTime(episode: number, token: string, seconds: number, total_seconds: number) { + private postSeenEpisodeTime(episode: number, token: string, seconds: number, total_seconds: number) { return new Promise((resolve, reject) => { const url = this.domain + '/api/v1/seen-episode-time/'; fetch(url, { diff --git a/src/app/tablinks/tablinks.page.ts b/src/app/tablinks/tablinks.page.ts index c86e19e..6702794 100644 --- a/src/app/tablinks/tablinks.page.ts +++ b/src/app/tablinks/tablinks.page.ts @@ -19,6 +19,7 @@ import { CommentsService } from '../services/comments/comments.service'; import { MysqlDatabaseService } from 'src/app/services/mysql-database.service'; import { ProfileService } from '../services/profile/profile.service'; import { UserGroups } from '../classes/user-groups/user-groups'; +import { SharingService } from '../core/services/sharing/sharing.service'; export type TabSchema = { routerPath: string; @@ -70,9 +71,10 @@ export class TablinksPage implements OnInit { constructor(public localStorage: PreferencesService, public platform: Platform, public routerOutlet: IonRouterOutlet, public alertCtrl: AlertController, public utils: UtilsService, public navCtrl: NavController, public fMessagingServer: ServerService, public commentsService: CommentsService, - public modalCtrl: ModalController, public profileService: ProfileService, public database: MysqlDatabaseService) { + public modalCtrl: ModalController, public profileService: ProfileService, public database: MysqlDatabaseService, + private sharingService: SharingService) { - this.recentlyLoggedSubscription = this.database.recentlyLogged$.subscribe(async (logged) => { + this.recentlyLoggedSubscription = this.sharingService.getRecentlyLogged().subscribe(async (logged) => { if (logged) { this.loggedVerification(); } diff --git a/src/theme/variables.scss b/src/theme/variables.scss index f4f09c4..a18107b 100644 --- a/src/theme/variables.scss +++ b/src/theme/variables.scss @@ -296,6 +296,7 @@ body.light { * ------------------------------------------- */ + --ion-toolbar-background: #f9f9f9; .md body { --ion-tab-bar-background: #f6f6f6; }