CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-tns-platform-declarations

Platform-specific TypeScript declarations for NativeScript for accessing native objects

84

1.23x
Overview
Eval results
Files

task.mdevals/scenario-6/

Temperature Storage System

Build a temperature storage system for a NativeScript Android application that properly handles native type conversions.

Requirements

Create a temperature storage utility that interacts with Android's SharedPreferences system. The utility should:

  1. Convert Celsius temperatures to Fahrenheit using a simple formula
  2. Store temperature readings as floating-point values in SharedPreferences (use key "last_temperature")
  3. Store temperature timestamps as long integers in milliseconds in SharedPreferences (use key "last_timestamp")
  4. Retrieve stored temperature and timestamp values from SharedPreferences

Important: Android's SharedPreferences methods require specific Java primitive types. JavaScript numbers must be properly converted to Android's native float and long types when calling SharedPreferences methods like putFloat(), getFloat(), putLong(), and getLong().

Implementation

@generates

API

/**
 * Converts Celsius temperature to Fahrenheit
 * @param celsius Temperature in Celsius
 * @returns Temperature in Fahrenheit
 */
export function celsiusToFahrenheit(celsius: number): number;

/**
 * Saves a temperature reading with timestamp to Android SharedPreferences
 * @param context Android context
 * @param temperature Temperature value to save
 * @param timestamp Timestamp in milliseconds
 */
export function saveTemperature(context: any, temperature: number, timestamp: number): void;

/**
 * Retrieves the last saved temperature from Android SharedPreferences
 * @param context Android context
 * @returns The last saved temperature or null if none exists
 */
export function getLastTemperature(context: any): number | null;

/**
 * Retrieves the timestamp of the last saved temperature
 * @param context Android context
 * @returns The timestamp in milliseconds or null if none exists
 */
export function getLastTimestamp(context: any): number | null;

Test Cases

  • Converting 0°C returns 32°F @test
  • Converting 100°C returns 212°F @test
  • Converting -40°C returns -40°F @test
  • Saving and retrieving a temperature with decimal precision (36.6) works correctly @test
  • Saving and retrieving a large timestamp value (1735689600000) works correctly @test

Dependencies { .dependencies }

tns-platform-declarations { .dependency }

Provides TypeScript declarations for accessing Android native APIs, including primitive type conversion utilities.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-tns-platform-declarations

tile.json