<commit_before>﻿import { TimePickerBase, getValidTime, timeProperty, hourProperty, minuteProperty } from "./time-picker-common";

export * from "./time-picker-common";

@Interfaces([android.widget.TimePicker.OnTimeChangedListener])
class TimeChangedListener extends java.lang.Object implements android.widget.TimePicker.OnTimeChangedListener {
    constructor(public owner: WeakRef<TimePicker>) {
        super();
        return global.__native(this);
    }

    onTimeChanged(picker: android.widget.TimePicker, hour: number, minute: number): void {
        let timePicker = this.owner.get();
        if (timePicker) {
            let validTime = getValidTime(timePicker, hour, minute);
            timePicker._setNativeValueSilently(validTime.hour, validTime.minute);
            timePicker.nativePropertyChanged(timeProperty, new Date(0, 0, 0, validTime.hour, validTime.minute));
        }
    }
}

export class TimePicker extends TimePickerBase {
    public _timePicker: android.widget.TimePicker;
    private _listener: android.widget.TimePicker.OnTimeChangedListener;

    public _createUI() {
        this._timePicker = new android.widget.TimePicker(this._context);
        this._listener = this._listener || new TimeChangedListener(new WeakRef(this));
        this._timePicker.setOnTimeChangedListener(this._listener);

        let c = java.util.Calendar.getInstance();
        if (this.hour === 0) {
            this.hour = c.get(java.util.Calendar.HOUR_OF_DAY);
        }

        if (this.minute === 0) {
            this.minute = c.get(java.util.Calendar.MINUTE);
        }

        let validTime = getValidTime(this, this.hour, this.minute);
        this._setNativeValueSilently(validTime.hour, validTime.minute);
    }

    public _setNativeValueSilently(hour: number, minute: number) {
        if (this.android) {
            this.android.setOnTimeChangedListener(null);

            this.android.setCurrentHour(new java.lang.Integer(hour));
            this.android.setCurrentMinute(new java.lang.Integer(minute));

            this.minute = minute;
            this.hour = hour;

            this.android.setOnTimeChangedListener(this._listener);
        }
    }

    public _setNativeTime() {
        this._setNativeValueSilently(this.hour, this.minute);
    }

    get [timeProperty.native](): Date {
        let nativeView = this._timePicker;
        return new Date(0, 0, 0, nativeView.getCurrentHour().intValue(), nativeView.getCurrentMinute().intValue());
    }
    set [timeProperty.native](value: Date) {
        this._setNativeValueSilently(this.hour, this.minute);
    }

    get [minuteProperty.native](): number {
        return this._timePicker.getCurrentMinute().intValue();
    }
    set [minuteProperty.native](value: number) {
        this._setNativeValueSilently(this.hour, value);
    }

    get [hourProperty.native](): number {
        return this._timePicker.getCurrentHour().intValue()
    }
    set [hourProperty.native](value: number) {
        this._setNativeValueSilently(value, this.minute);
    }
}<commit_msg>Fix TimePicker for Android<commit_after>﻿import { TimePickerBase, getValidTime, timeProperty, hourProperty, minuteProperty } from "./time-picker-common";

export * from "./time-picker-common";

@Interfaces([android.widget.TimePicker.OnTimeChangedListener])
class TimeChangedListener extends java.lang.Object implements android.widget.TimePicker.OnTimeChangedListener {
    constructor(public owner: WeakRef<TimePicker>) {
        super();
        return global.__native(this);
    }

    onTimeChanged(picker: android.widget.TimePicker, hour: number, minute: number): void {
        let timePicker = this.owner.get();
        if (timePicker) {
            let validTime = getValidTime(timePicker, hour, minute);
            timePicker._setNativeValueSilently(validTime.hour, validTime.minute);
            timePicker.nativePropertyChanged(timeProperty, new Date(0, 0, 0, validTime.hour, validTime.minute));
        }
    }
}

export class TimePicker extends TimePickerBase {
    private _android: android.widget.TimePicker;
    private _listener: android.widget.TimePicker.OnTimeChangedListener;

    public _createUI() {
        this._android = new android.widget.TimePicker(this._context);
        this._listener = this._listener || new TimeChangedListener(new WeakRef(this));
        this._android.setOnTimeChangedListener(this._listener);

        let c = java.util.Calendar.getInstance();
        if (this.hour === 0) {
            this.hour = c.get(java.util.Calendar.HOUR_OF_DAY);
        }

        if (this.minute === 0) {
            this.minute = c.get(java.util.Calendar.MINUTE);
        }

        let validTime = getValidTime(this, this.hour, this.minute);
        this._setNativeValueSilently(validTime.hour, validTime.minute);
    }

    get android(): android.widget.TimePicker {
        return this._android;
    }

    public _setNativeValueSilently(hour: number, minute: number) {
        if (this._android) {
            this._android.setOnTimeChangedListener(null);

            this._android.setCurrentHour(new java.lang.Integer(hour));
            this._android.setCurrentMinute(new java.lang.Integer(minute));

            this.minute = minute;
            this.hour = hour;

            this._android.setOnTimeChangedListener(this._listener);
        }
    }

    public _setNativeTime() {
        this._setNativeValueSilently(this.hour, this.minute);
    }

    get [timeProperty.native](): Date {
        let nativeView = this._android;
        return new Date(0, 0, 0, nativeView.getCurrentHour().intValue(), nativeView.getCurrentMinute().intValue());
    }
    set [timeProperty.native](value: Date) {
        this._setNativeValueSilently(this.hour, this.minute);
    }

    get [minuteProperty.native](): number {
        return this._android.getCurrentMinute().intValue();
    }
    set [minuteProperty.native](value: number) {
        this._setNativeValueSilently(this.hour, value);
    }

    get [hourProperty.native](): number {
        return this._android.getCurrentHour().intValue()
    }
    set [hourProperty.native](value: number) {
        this._setNativeValueSilently(value, this.minute);
    }
}
{'fraction_non_alphanumeric': 0.11735270379338177, 'fraction_numerical': 0.00258272800645682, 'mean_word_length': 3.052321778940484, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1559534', 'n_tokens_mistral': 1758, 'n_tokens_neox': 1721, 'n_words': 310}