| @@ -5,6 +5,7 @@ import { DomSanitizer } from '@angular/platform-browser'; | |||
| import { NewsService, IMAGE_BASE_URL } from '../services/news.service'; | |||
| import { ToastService } from '../services/toast.service'; | |||
| import { SocialSharing } from '@ionic-native/social-sharing/ngx'; | |||
| import { Platform } from '@ionic/angular'; | |||
| @Component({ | |||
| selector: 'app-home-details', | |||
| @@ -22,7 +23,8 @@ export class HomeDetailsPage implements OnInit { | |||
| private dom:DomSanitizer, | |||
| private newsService: NewsService, | |||
| private toastService: ToastService, | |||
| private socialSharing: SocialSharing | |||
| private socialSharing: SocialSharing, | |||
| private platform: Platform | |||
| ) { } | |||
| getUrl(url) { | |||
| @@ -48,7 +50,12 @@ export class HomeDetailsPage implements OnInit { | |||
| if (type === 'news') { | |||
| this.newsService.getArticleDetails(alias_title).then((data: any) => { | |||
| this.newsDetails = JSON.parse(data.data)['content'].data; | |||
| if (this.platform.is('android') || this.platform.is('capacitor')) { | |||
| this.newsDetails = JSON.parse(data.data)['content'].data; | |||
| } else { | |||
| this.newsDetails = data.content.data; | |||
| } | |||
| }, (err) => { | |||
| console.log(err); | |||
| @@ -59,7 +66,12 @@ export class HomeDetailsPage implements OnInit { | |||
| if (type === 'videos') { | |||
| this.newsService.getVideoDetails(alias_title).then((data: any) => { | |||
| this.newsDetails = JSON.parse(data.data)['content'].data; | |||
| if (this.platform.is('android') || this.platform.is('capacitor')) { | |||
| this.newsDetails = JSON.parse(data.data)['content'].data; | |||
| } else { | |||
| this.newsDetails = data.content.data; | |||
| } | |||
| }, (err) => { | |||
| console.log(err); | |||
| @@ -70,7 +82,12 @@ export class HomeDetailsPage implements OnInit { | |||
| if (type === 'gallery') { | |||
| this.newsService.getGalleryDetails(alias_title).then((data: any) => { | |||
| this.newsDetails = JSON.parse(data.data)['content'].data; | |||
| if (this.platform.is('android') || this.platform.is('capacitor')) { | |||
| this.newsDetails = JSON.parse(data.data)['content'].data; | |||
| } else { | |||
| this.newsDetails = data.content.data; | |||
| } | |||
| }, (err) => { | |||
| console.log(err); | |||
| @@ -4,8 +4,8 @@ import { Router } from '@angular/router'; | |||
| import { NewsService, IMAGE_BASE_URL } from '../services/news.service'; | |||
| import { ToastService } from '../services/toast.service'; | |||
| import { DomSanitizer } from '@angular/platform-browser'; | |||
| import { Uptime } from '@ionic-native/uptime/ngx'; | |||
| import { SocialSharing } from '@ionic-native/social-sharing/ngx'; | |||
| import { Platform } from '@ionic/angular'; | |||
| @Component({ | |||
| selector: 'app-home', | |||
| @@ -41,8 +41,8 @@ export class HomePage implements OnInit { | |||
| private newsService: NewsService, | |||
| private toastService: ToastService, | |||
| private dom: DomSanitizer, | |||
| private uptime: Uptime, | |||
| private socialSharing: SocialSharing | |||
| private socialSharing: SocialSharing, | |||
| private platform: Platform | |||
| ) { } | |||
| transformYourHtml(htmlTextWithStyle) { | |||
| @@ -54,27 +54,40 @@ export class HomePage implements OnInit { | |||
| } | |||
| ngOnInit() { | |||
| this.uptime.getUptime(true) | |||
| .then(uptime => this.myuptime = uptime) | |||
| .catch(error => console.log(error)); | |||
| this.newsService.getArticles().then((data: any) => { | |||
| // alert(JSON.stringify()); | |||
| this.newsData = JSON.parse(data.data)['content'].items; | |||
| if (this.platform.is('android') || this.platform.is('capacitor')) { | |||
| this.newsData = JSON.parse(data.data)['content'].items; | |||
| } else { | |||
| this.newsData = data.content.items; | |||
| } | |||
| }, (err) => { | |||
| console.log(err); | |||
| this.toastService.presentToastWithOptions("Failed to get News data", "danger"); | |||
| }); | |||
| this.newsService.getVideos().then((data: any) => { | |||
| this.videoData = JSON.parse(data.data)['content'].items; | |||
| if (this.platform.is('android') || this.platform.is('capacitor')) { | |||
| this.videoData = JSON.parse(data.data)['content'].items; | |||
| } else { | |||
| this.videoData = data.content.items; | |||
| } | |||
| }, (err) => { | |||
| this.toastService.presentToastWithOptions("Failed to get Videos data", "danger"); | |||
| }); | |||
| this.newsService.getGalleries().then((data: any) => { | |||
| this.galleryData = JSON.parse(data.data)['content'].items; | |||
| if (this.platform.is('android') || this.platform.is('capacitor')) { | |||
| this.galleryData = JSON.parse(data.data)['content'].items; | |||
| } else { | |||
| this.galleryData = data.content.items; | |||
| } | |||
| }, (err) => { | |||
| console.log(err); | |||
| this.toastService.presentToastWithOptions("Failed to get Gallery data", "danger"); | |||
| @@ -1,5 +1,7 @@ | |||
| import { Injectable } from '@angular/core'; | |||
| import { HTTP } from '@ionic-native/http/ngx'; | |||
| import { HttpClient } from '@angular/common/http'; | |||
| import { Platform } from '@ionic/angular'; | |||
| export const IMAGE_BASE_URL: string = 'https://www.punjabkingsipl.in/static-assets/waf-images/'; | |||
| @@ -8,30 +10,56 @@ export const IMAGE_BASE_URL: string = 'https://www.punjabkingsipl.in/static-asse | |||
| }) | |||
| export class NewsService { | |||
| constructor( | |||
| private http: HTTP | |||
| private http: HTTP, | |||
| private httpClient: HttpClient, | |||
| private platform: Platform | |||
| ) { } | |||
| getArticles() { | |||
| return this.http.get('https://www.punjabkingsipl.in/api/listing?entities=4&otherent=1,8021&pgnum=1&inum=10&pgsize=10', {}, {}); | |||
| if (this.platform.is('android') || this.platform.is('capacitor')) { | |||
| return this.http.get('https://www.punjabkingsipl.in/api/listing?entities=4&otherent=1,8021&pgnum=1&inum=10&pgsize=10', {}, {}); | |||
| } else { | |||
| return this.httpClient.get('https://www.punjabkingsipl.in/api/listing?entities=4&otherent=1,8021&pgnum=1&inum=10&pgsize=10').toPromise(); | |||
| } | |||
| } | |||
| getArticleDetails(title_alias_from_listing_api: string) { | |||
| return this.http.get('https://www.punjabkingsipl.in/api/article/' + title_alias_from_listing_api + '?is_app=1', {}, {}); | |||
| if (this.platform.is('android') || this.platform.is('capacitor')) { | |||
| return this.http.get('https://www.punjabkingsipl.in/api/article/' + title_alias_from_listing_api + '?is_app=1', {}, {}); | |||
| } else { | |||
| return this.httpClient.get('https://www.punjabkingsipl.in/api/article/' + title_alias_from_listing_api + '?is_app=1').toPromise(); | |||
| } | |||
| } | |||
| getVideos() { | |||
| return this.http.get('https://www.punjabkingsipl.in/api/listing?entities=3,4&otherent=&pgnum=1&inum=10&pgsize=10', {}, {}); | |||
| if (this.platform.is('android') || this.platform.is('capacitor')) { | |||
| return this.http.get('https://www.punjabkingsipl.in/api/listing?entities=3,4&otherent=&pgnum=1&inum=10&pgsize=10', {}, {}); | |||
| } else { | |||
| return this.httpClient.get('https://www.punjabkingsipl.in/api/listing?entities=3,4&otherent=&pgnum=1&inum=10&pgsize=10').toPromise(); | |||
| } | |||
| } | |||
| getVideoDetails(title_alias_from_listing_api: string) { | |||
| return this.http.get('https://www.punjabkingsipl.in/api/video/' + title_alias_from_listing_api, {}, {}); | |||
| if (this.platform.is('android') || this.platform.is('capacitor')) { | |||
| return this.http.get('https://www.punjabkingsipl.in/api/video/' + title_alias_from_listing_api, {}, {}); | |||
| } else { | |||
| return this.httpClient.get('https://www.punjabkingsipl.in/api/video/' + title_alias_from_listing_api).toPromise(); | |||
| } | |||
| } | |||
| getGalleries() { | |||
| return this.http.get('https://www.punjabkingsipl.in/api/listing?entities=2,4&otherent=&pgnum=1&inum=10&pgsize=10', {}, {}); | |||
| if (this.platform.is('android') || this.platform.is('capacitor')) { | |||
| return this.http.get('https://www.punjabkingsipl.in/api/listing?entities=2,4&otherent=&pgnum=1&inum=10&pgsize=10', {}, {}); | |||
| } else { | |||
| return this.httpClient.get('https://www.punjabkingsipl.in/api/listing?entities=2,4&otherent=&pgnum=1&inum=10&pgsize=10').toPromise(); | |||
| } | |||
| } | |||
| getGalleryDetails(title_alias_from_listing_api: string) { | |||
| return this.http.get('https://www.punjabkingsipl.in/api/photo/' + title_alias_from_listing_api, {}, {}); | |||
| if (this.platform.is('android') || this.platform.is('capacitor')) { | |||
| return this.http.get('https://www.punjabkingsipl.in/api/photo/' + title_alias_from_listing_api, {}, {}); | |||
| } else { | |||
| return this.httpClient.get('https://www.punjabkingsipl.in/api/photo/' + title_alias_from_listing_api).toPromise(); | |||
| } | |||
| } | |||
| } | |||