Guest User

Untitled

a guest
Jan 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. export class IdomeroPage {
  2. timeInSeconds: number;
  3.  
  4. time: number;
  5. remainingTime: number;
  6. runTimer: boolean;
  7. hasStarted: boolean;
  8. hasFinished: boolean;
  9. displayTime: string;
  10. userido:number;
  11. constructor(public navCtrl: NavController, public navParams: NavParams,private vibration: Vibration,private storage: Storage) {
  12. }
  13.  
  14. ionViewDidEnter() {
  15. }
  16.  
  17. ionViewWillEnter(){
  18. this.storage.get(‘idomerouserido’).then((val)=>{
  19. if(val!=null){
  20. this.userido=parseInt(val);
  21. console.log(“if ág eleje”,this.userido);
  22. } else{
  23. console.log(“else ág”)
  24. this.userido=10;
  25. }});
  26. }
  27.  
  28. idomeroBeallitasok(){
  29. this.navCtrl.push(IdomerobeallitasokPage);
  30. }
  31.  
  32. ngOnInit() {
  33. this.initTimer();
  34. }
  35.  
  36. initTimer() {
  37. if (!this.timeInSeconds) { this.timeInSeconds = this.userido*60; }
  38.  
  39. this.time = this.timeInSeconds;
  40. this.runTimer = false;
  41. this.hasStarted = false;
  42. this.hasFinished = false;
  43. this.remainingTime = this.timeInSeconds;
  44.  
  45. this.displayTime = this.getSecondsAsDigitalClock(this.remainingTime);
  46. }
  47.  
  48. startTimer() {
  49. this.runTimer = true;
  50. this.hasStarted = true;
  51. this.timerTick();
  52. }
  53.  
  54. pauseTimer() {
  55. this.runTimer = false;
  56. }
  57.  
  58. resumeTimer() {
  59. this.startTimer();
  60. }
  61.  
  62. timerTick() {
  63. setTimeout(() => {
  64.  
  65. if (!this.runTimer) { return; }
  66. this.remainingTime--;
  67. this.displayTime = this.getSecondsAsDigitalClock(this.remainingTime);
  68. if (this.remainingTime > 0) {
  69. this.timerTick();
  70. }
  71. else {
  72. this.hasFinished = true;
  73. this.vibration.vibrate(1000);
  74. this.vibration.vibrate(1000);
  75.  
  76. }
  77. }, 1000);
  78. }
  79.  
  80. getSecondsAsDigitalClock(inputSeconds: number) {
  81. var sec_num = parseInt(inputSeconds.toString(), 10);
  82. var hours = Math.floor(sec_num / 3600);
  83. var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
  84. var seconds = sec_num - (hours * 3600) - (minutes * 60);
  85. var hoursString = ‘’;
  86. var minutesString = ‘’;
  87. var secondsString = ‘’;
  88. hoursString = (hours < 10) ? “0” + hours : hours.toString();
  89. minutesString = (minutes < 10) ? “0” + minutes : minutes.toString();
  90. secondsString = (seconds < 10) ? “0” + seconds : seconds.toString();
  91. return hoursString + ‘:’ + minutesString + ‘:’ + secondsString;
  92. }
  93. }
Add Comment
Please, Sign In to add comment