import { Observable } from 'rxjs' ; import { getNativeApplication } from '@nativescript/core/application' ; import { ActionBar } from '@nativescript/core/ui/action-bar' ; import { TextField } from '@nativescript/core/ui/text-field' ; import { Color } from '@nativescript/core/color' ; import { ad } from '@nativescript/core/utils/utils' ; import { AFTERVIEWINIT_DELAY } from '../shared/constants' ; export function getDateStr ( date ) { const year = date . getFullYear ( ) ; const month = ( ( date . getMonth ( ) + 1 < 10 ) ? '0' : '' ) + ( date . getMonth ( ) + 1 ) ; const day = ( ( date . getDate ( ) < 10 ) ? '0' : '' ) + date . getDate ( ) ; return `${ year }-${ month }-${ day }` ; } export function getTodayStr ( ) { return getDateStr ( new Date ( ) ) ; } export function showKeyboard ( textField ) { setTimeout ( ( ) => { textField . focus ( ) ; } , AFTERVIEWINIT_DELAY ) ; } export function getColor ( name ) { const app = getNativeApplication ( ) ; const resources = app . getResources ( ) ; const colorId = resources . getIdentifier ( name , 'color' , app . getPackageName ( ) ) ; const color = new Color ( resources . getColor ( colorId ) ) ; return color ; } export function getAppVersion ( ) { const context = ad . getApplicationContext ( ) ; const packageManager = context . getPackageManager ( ) ; return packageManager . getPackageInfo ( context . getPackageName ( ) , 0 ) . versionName ; } export function setIconColor ( icon , color ) { if ( color === null ) { icon . setColorFilter ( null ) ; } else { icon . setColorFilter ( android . graphics . Color . parseColor ( color ) , android . graphics . PorterDuff . Mode . SRC_ATOP ) ; } } export function configureSaveButton ( actionBar , statusChanges ) { statusChanges . subscribe ( ( ) => { setTimeout ( ( ) => { actionBar . update ( ) ; } , 0 ) ; } ) ; }