TubiRadioButton.java

Overview

`TubiRadioButton.java` defines a custom Android UI component, `TubiRadioButton`, extending `LinearLayout`. It encapsulates a radio button with an associated text label, providing a reusable and data-binding-friendly radio button widget for the Tubi TV application.

This custom view manages its own layout inflation, data binding, and checked state, making it easier to integrate consistent radio button functionality into the app’s user interface. It exposes methods to set the label text and to query or change the checked state programmatically.


Detailed Documentation

Class: TubiRadioButton

**Package:** `com.tubitv.media.views`

**Superclass:** `LinearLayout`

A compound view wrapping a single radio button and its label. Handles inflation of the radio button layout from XML, manages checked state toggling on clicks, and allows setting/getting the label text via resource IDs or strings.


Fields

Field Name

Type

Description

`private boolean isAttachedToWindow`

`boolean`

Tracks whether this view is currently attached to the window. Useful for lifecycle awareness.

`private ViewTubiRadioButtonBinding mBinding`

`ViewTubiRadioButtonBinding`

Data-binding generated binding class instance, linking UI elements in the inflated layout.


Constructors

TubiRadioButton(Context context)


TubiRadioButton(Context context, AttributeSet attrs)


TubiRadioButton(Context context, AttributeSet attrs, int defStyleAttr)


Lifecycle Methods

void onAttachedToWindow()


void onDetachedFromWindow()


Private Methods

void initLayout()


Public Methods

void setText(@StringRes int textResId)


void setText(@NonNull String text)


boolean isChecked()


void setChecked(boolean checked)


Important Implementation Details


Interaction with Other Parts of the System


Usage Example

// Creating programmatically
TubiRadioButton radioButton = new TubiRadioButton(context);
radioButton.setText("Option A");
radioButton.setChecked(true);
radioButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // Handle radio button clicked
    }
});

Visual Diagram

classDiagram
    class TubiRadioButton {
        -boolean isAttachedToWindow
        -ViewTubiRadioButtonBinding mBinding
        +TubiRadioButton(Context)
        +TubiRadioButton(Context, AttributeSet)
        +TubiRadioButton(Context, AttributeSet, int)
        +void onAttachedToWindow()
        +void onDetachedFromWindow()
        -void initLayout()
        +void setText(int)
        +void setText(String)
        +boolean isChecked()
        +void setChecked(boolean)
    }
    TubiRadioButton --|> LinearLayout
    TubiRadioButton ..> ViewTubiRadioButtonBinding : uses

Summary

`TubiRadioButton` is a lightweight, reusable Android UI component representing a radio button with an associated text label. It leverages Android Data Binding for layout inflation and UI management, handles its own checked state toggling, and exposes clear APIs for setting text and checked state. This class integrates seamlessly into the Tubi app’s UI layer, promoting code reuse and consistent styling of radio buttons throughout the application.