src/services/app-rating.service.ts
Methods |
|
constructor(preference: SharedPreferences, fileCtrl: File)
|
|||||||||
Defined in src/services/app-rating.service.ts:7
|
|||||||||
Parameters :
|
checkInitialDate |
checkInitialDate()
|
Defined in src/services/app-rating.service.ts:14
|
Returns :
void
|
Private Async checkRateLaterCount |
checkRateLaterCount()
|
Defined in src/services/app-rating.service.ts:47
|
Returns :
unknown
|
Private createFolder | ||||
createFolder(rate)
|
||||
Defined in src/services/app-rating.service.ts:31
|
||||
Parameters :
Returns :
void
|
Private Async increaseRateLaterClickedCount | ||||
increaseRateLaterClickedCount(value)
|
||||
Defined in src/services/app-rating.service.ts:58
|
||||
Parameters :
Returns :
unknown
|
Async rateLaterClickedCount |
rateLaterClickedCount()
|
Defined in src/services/app-rating.service.ts:43
|
Returns :
unknown
|
setEndStoreRate | ||||
setEndStoreRate(rate)
|
||||
Defined in src/services/app-rating.service.ts:27
|
||||
Parameters :
Returns :
void
|
Private setInitialDate |
setInitialDate()
|
Defined in src/services/app-rating.service.ts:22
|
Returns :
void
|
Private writeFile | ||||
writeFile(rate)
|
||||
Defined in src/services/app-rating.service.ts:38
|
||||
Parameters :
Returns :
void
|
import { Injectable, Inject } from '@angular/core';
import { SharedPreferences } from 'sunbird-sdk';
import { PreferenceKey, StoreRating } from '../app/app.constant';
import { File } from '@ionic-native/file/ngx';
@Injectable()
export class AppRatingService {
constructor(
@Inject('SHARED_PREFERENCES') private preference: SharedPreferences,
private fileCtrl: File
) { }
checkInitialDate() {
this.preference.getString(PreferenceKey.APP_RATING_DATE).toPromise().then(res => {
if (!res) {
this.setInitialDate();
}
});
}
private setInitialDate() {
const presentDate = window.dayjs().format();
this.preference.putString(PreferenceKey.APP_RATING_DATE, String(presentDate)).toPromise().then();
}
setEndStoreRate(rate) {
this.createFolder(rate);
}
private createFolder(rate) {
this.fileCtrl.createDir(cordova.file.dataDirectory, StoreRating.FOLDER_NAME, true)
.then(() => {
this.writeFile(rate);
});
}
private writeFile(rate) {
this.fileCtrl.writeFile(cordova.file.dataDirectory + '/' + StoreRating.FOLDER_NAME,
StoreRating.FILE_NAME, StoreRating.FILE_TEXT + ' = ' + rate, { replace: true }).then(() => { });
}
async rateLaterClickedCount() {
return await this.checkRateLaterCount();
}
private async checkRateLaterCount() {
return this.preference.getString(PreferenceKey.APP_RATE_LATER_CLICKED).toPromise().then(async (val) => {
if (val) {
const incrementValue = Number(val) + 1;
await this.increaseRateLaterClickedCount(incrementValue);
return incrementValue;
}
return this.increaseRateLaterClickedCount(1);
});
}
private async increaseRateLaterClickedCount(value) {
return this.preference.putString(PreferenceKey.APP_RATE_LATER_CLICKED, String(value)).toPromise().then(() => value);
}
}