Skip to content

Commit

Permalink
feat: update to subjects
Browse files Browse the repository at this point in the history
  • Loading branch information
PhantomPainX committed Aug 17, 2023
1 parent b633f82 commit ea36ea5
Show file tree
Hide file tree
Showing 22 changed files with 219 additions and 121 deletions.
10 changes: 5 additions & 5 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export class EmbedsPopoverComponent implements OnInit {
} else {
this.webCompatible = this.embeds;
this.optionValue = 'web';
this.buttonsClickable = true;
}
}

Expand Down
43 changes: 42 additions & 1 deletion src/app/core/services/sharing/sharing.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,53 @@ import { Subject } from 'rxjs';
export class SharingService {

private userExtraSubject = new Subject<boolean>();
private recentlyLoggedSubject = new Subject<boolean>();
private seenEpisodeSubject = new Subject<boolean>();
private themeChangedSubject = new Subject<boolean>();
private episodeTimeSeenSubject = new Subject<boolean>();
private autoplayPreferencesSubject = new Subject<any>();

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);
}
}
6 changes: 3 additions & 3 deletions src/app/modals/settings/settings.page.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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) {

}

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/app/modals/web-video-player/web-video-player.page.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ion-header mode="ios" collapse="fade">
<ion-toolbar #toolbar>
<ion-title>Reproductor PWA</ion-title>
<ion-title>Reproductor Web</ion-title>
<ion-buttons slot="end" mode="md">
<ion-button color="primary" (click)="closeModal()">
<ion-icon slot="icon-only" name="close-outline"></ion-icon>
Expand Down
32 changes: 27 additions & 5 deletions src/app/modals/web-video-player/web-video-player.page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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%;
Expand All @@ -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);
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/app/pages/admin/admin.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
<ion-buttons slot="start">
<ion-back-button color="primary" defaultHref="/tablinks/home" icon="chevron-back-outline"></ion-back-button>
</ion-buttons>

<ion-buttons slot="end">
<ion-button (click)="playRadio()">
<ion-icon slot="icon-only" name="radio-outline"></ion-icon>
</ion-button>
</ion-buttons>
</ion-toolbar>
</ion-header>

Expand Down
7 changes: 6 additions & 1 deletion src/app/pages/admin/admin.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 () => {
Expand All @@ -23,4 +24,8 @@ export class AdminPage implements OnInit {
});
}

public playRadio() {
this.videoPlayerService.playRadio();
}

}
6 changes: 4 additions & 2 deletions src/app/pages/auth/register/register.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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: ['', [
Expand Down Expand Up @@ -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 {
Expand Down
28 changes: 15 additions & 13 deletions src/app/pages/auth/signin/signin.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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: ['', [
Expand Down Expand Up @@ -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({
Expand All @@ -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 });
}
}
Expand Down Expand Up @@ -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({
Expand All @@ -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 });
}
}
Expand Down Expand Up @@ -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({
Expand All @@ -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 });
}
}
Expand Down Expand Up @@ -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({
Expand All @@ -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 });
}
}
Expand Down Expand Up @@ -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({
Expand All @@ -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 });
}
}
Expand All @@ -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({
Expand All @@ -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 });
}
}
Expand Down
Loading

0 comments on commit ea36ea5

Please sign in to comment.