2017-06-06 03:32:48 +00:00
|
|
|
import { Component, ViewChild } from '@angular/core';
|
|
|
|
import { Nav, Platform } from 'ionic-angular';
|
|
|
|
import { StatusBar } from '@ionic-native/status-bar';
|
|
|
|
import { SplashScreen } from '@ionic-native/splash-screen';
|
2017-06-06 23:42:08 +00:00
|
|
|
import { Storage } from '@ionic/storage';
|
2017-06-17 14:57:10 +00:00
|
|
|
import { Device } from '@ionic-native/device';
|
2017-06-06 03:32:48 +00:00
|
|
|
|
2017-06-06 23:42:08 +00:00
|
|
|
import { LoginPage } from '../pages/login/login';
|
2017-06-10 13:55:32 +00:00
|
|
|
import { StreamPage } from '../pages/stream/stream';
|
|
|
|
|
2017-06-06 23:42:08 +00:00
|
|
|
import * as pnut from 'pnut-butter';
|
2017-06-06 03:32:48 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
templateUrl: 'app.html'
|
|
|
|
})
|
|
|
|
export class MyApp {
|
|
|
|
@ViewChild(Nav) nav: Nav;
|
|
|
|
|
2017-06-17 14:57:10 +00:00
|
|
|
rootPage: any = StreamPage;
|
2017-06-06 03:32:48 +00:00
|
|
|
|
2017-06-10 15:24:38 +00:00
|
|
|
pages: Array<{title: string, component: any, params: Object}>;
|
2017-06-06 03:32:48 +00:00
|
|
|
|
2017-06-17 14:57:10 +00:00
|
|
|
constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen,
|
|
|
|
private storage: Storage, private device: Device) {
|
2017-06-06 03:32:48 +00:00
|
|
|
this.initializeApp();
|
|
|
|
|
|
|
|
// used for an example of ngFor and navigation
|
|
|
|
this.pages = [
|
2017-06-20 05:05:39 +00:00
|
|
|
{ title: 'Timeline', component: StreamPage, params: {stream: 'personal'} },
|
|
|
|
{ title: 'Mentions', component: StreamPage, params: {stream: 'mentions'} },
|
2017-06-25 13:47:38 +00:00
|
|
|
{ title: 'Global', component: StreamPage, params: {stream: 'global'} },
|
2017-06-20 05:05:39 +00:00
|
|
|
{ title: 'Bookmarks', component: StreamPage, params: {stream: 'bookmarks'} },
|
|
|
|
{ title: 'Logout', component: {}, params: {}},
|
2017-06-06 03:32:48 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
initializeApp() {
|
2017-06-06 23:42:08 +00:00
|
|
|
console.log('--- initializeApp ---');
|
2017-06-17 14:57:10 +00:00
|
|
|
|
2017-06-06 23:42:08 +00:00
|
|
|
|
2017-06-06 03:32:48 +00:00
|
|
|
this.platform.ready().then(() => {
|
|
|
|
// Okay, so the platform is ready and our plugins are available.
|
|
|
|
// Here you can do any higher level native things you might need.
|
2017-06-17 14:57:10 +00:00
|
|
|
|
|
|
|
this.storage.get('token').then((val) => {
|
|
|
|
if (val.length > 1) {
|
|
|
|
pnut.token = val;
|
|
|
|
this.nav.setRoot(StreamPage, {stream: 'personal'});
|
|
|
|
}
|
|
|
|
}).catch(err => {
|
|
|
|
console.log('ERROR: ' + err);
|
|
|
|
this.nav.setRoot(LoginPage);
|
|
|
|
});
|
|
|
|
|
2017-06-06 03:32:48 +00:00
|
|
|
this.statusBar.styleDefault();
|
|
|
|
this.splashScreen.hide();
|
2017-06-17 14:57:10 +00:00
|
|
|
console.log('---');
|
|
|
|
console.log(this.device.platform);
|
|
|
|
console.log('---');
|
2017-06-06 03:32:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
openPage(page) {
|
|
|
|
// Reset the content nav to have just this page
|
|
|
|
// we wouldn't want the back button to show in this scenario
|
2017-06-20 05:05:39 +00:00
|
|
|
if (page.title === 'Logout') {
|
|
|
|
this.storage.remove('token');
|
|
|
|
this.nav.setRoot(LoginPage);
|
|
|
|
} else {
|
|
|
|
this.nav.setRoot(page.component, page.params);
|
|
|
|
}
|
2017-06-06 03:32:48 +00:00
|
|
|
}
|
2017-06-06 23:42:08 +00:00
|
|
|
|
2017-06-06 03:32:48 +00:00
|
|
|
}
|