• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import Log from '../../../../../../../../common/src/main/ets/default/Log';
17import SwitchUserManager from '../../../../../../../../common/src/main/ets/default/SwitchUserManager';
18import { FASlotName } from '../../../../../../../../common/src/main/ets/default/Constants';
19import { TintContentInfo, getOrCreateTintContentInfo
20} from '../../../../../../../../common/src/main/ets/default/TintStateManager';
21import createOrGet from '../../../../../../../../common/src/main/ets/default/SingleInstanceHelper';
22import { LocationData } from '../common/Constants';
23import LocationService from '../model/LocationService';
24
25const TAG = 'LocationVM';
26
27export class LocationVM {
28  mIsStart = false;
29  mLocationData: LocationData = {
30    ...new LocationData()
31  };
32  mLocationStatus:SubscribedAbstractProperty<boolean>;
33  mTintContentInfo: TintContentInfo = getOrCreateTintContentInfo(FASlotName.LOCATION);
34
35  constructor() {
36    Log.showDebug(TAG, 'constructor');
37  }
38
39  initViewModel(): void {
40    if (this.mIsStart) {
41      return;
42    };
43    Log.showInfo(TAG, 'initViewModel ');
44    this.mIsStart = true;
45    SwitchUserManager.getInstance().registerListener(this);
46    LocationService.registerListener(this);
47    LocationService.startService();
48  }
49
50  userChange():void{
51    LocationService.getServiceState()
52  }
53
54  updateServiceState(state: boolean): void {
55    Log.showInfo(TAG, `updateServiceState, state: ${state} `);
56    AppStorage.SetOrCreate(TAG + '_LocationData', state)
57  }
58
59  enableLocation(): void {
60    Log.showInfo(TAG, 'enableLocation');
61    LocationService.enableLocation();
62  }
63
64  disableLocation(): void {
65    Log.showInfo(TAG, 'disableLocation');
66    LocationService.disableLocation();
67  }
68
69  getTintContentInfo(): TintContentInfo {
70    return this.mTintContentInfo;
71  }
72}
73
74let sLocationVM = createOrGet(LocationVM, TAG);
75
76export default sLocationVM;