.class public final Ldev/maelstrom/ykit/settings/YkitSettingsToggle;
.super Landroid/widget/FrameLayout;
.source "SourceFile"

.method public constructor <init>(Landroid/content/Context;Landroid/util/AttributeSet;)V
    .locals 10

    invoke-direct {p0, p1, p2}, Landroid/widget/FrameLayout;-><init>(Landroid/content/Context;Landroid/util/AttributeSet;)V

    # Inflate layout
    invoke-static {p1}, Landroid/view/LayoutInflater;->from(Landroid/content/Context;)Landroid/view/LayoutInflater;
    move-result-object v0
    sget v1, Lcom/tumblr/R$layout;->b5:I # 0x7f0e0237 / list_item_setting_boolean
    const/4 v2, 0x1
    invoke-virtual {v0, v1, p0, v2}, Landroid/view/LayoutInflater;->inflate(ILandroid/view/ViewGroup;Z)Landroid/view/View;

    # Get title
    const-string v4, "title"
    const v5, 0x0
    invoke-interface {p2, v5, v4}, Landroid/util/AttributeSet;->getAttributeValue(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    move-result-object v1

    # Get subtitle
    const-string v4, "subtitle"
    const v5, 0x0
    invoke-interface {p2, v5, v4}, Landroid/util/AttributeSet;->getAttributeValue(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    move-result-object v2

    # Get bound field name
    const-string v4, "bindSetting"
    const v5, 0x0
    invoke-interface {p2, v5, v4}, Landroid/util/AttributeSet;->getAttributeValue(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    move-result-object v3

    move-object v0, p0 # Move this to v0

    const-class p0, Ldev/maelstrom/ykit/settings/YkitCurrentSettings; # Use p0 for YkitCurrentSettings.class because it's now free for us to use
    invoke-virtual {p0, v3}, Ljava/lang/Class;->getField(Ljava/lang/String;)Ljava/lang/reflect/Field;
    move-result-object v3

    invoke-direct/range {v0 .. v3}, Ldev/maelstrom/ykit/settings/YkitSettingsToggle;->initToggle(Ljava/lang/String;Ljava/lang/String;Ljava/lang/reflect/Field;)Lq90/b;

    return-void
.end method


# initToggle(String title, String subtitle, Field boundSettingField) -> TMToggleHolder
.method private initToggle(Ljava/lang/String;Ljava/lang/String;Ljava/lang/reflect/Field;)Lq90/b;
    .locals 7

    # v0 - View
    # v1 - TMToggleContainer
    # v2 - Integer
    # v3 - Boolean
    # v4 - Listener
    # v5 - toggleHelper

    # Get inner RelativeLayout from container
    const v2, 0x0
    invoke-virtual {p0, v2}, Landroid/view/ViewGroup;->getChildAt(I)Landroid/view/View;
    move-result-object p0

    # Create holder for toggle
    new-instance v1, Lq90/b; # TMToggleContainer
    invoke-direct {v1, p0}, Lq90/b;-><init>(Landroid/view/View;)V

    # Set text for the toggle
    iget-object v0, v1, Lq90/b;->z:Landroid/widget/TextView; # title
    invoke-virtual {v0, p1}, Landroid/widget/TextView;->setText(Ljava/lang/CharSequence;)V

    # Set subtitle for the toggle
    iget-object v0, v1, Lq90/b;->x:Landroid/widget/TextView; # subtitle
    invoke-virtual {v0, p2}, Landroid/widget/TextView;->setText(Ljava/lang/CharSequence;)V
    # Enable the subtitle
    const v2, 0x0
    invoke-virtual {v0, v2}, Landroid/view/View;->setVisibility(I)V

    # Enable the toggle
    iget-object v0, v1, Lq90/b;->w:Lcom/tumblr/components/smartswitch/SmartSwitch;
    const v3, 0x1
    invoke-virtual {v0, v3}, Landroid/view/View;->setEnabled(Z)V

    # Set the toggle's current value
    const v6, 0x0 # null
    invoke-virtual {p3, v6}, Ljava/lang/reflect/Field;->getBoolean(Ljava/lang/Object;)Z
    move-result v3
    invoke-virtual {v0, v3}, Lcom/tumblr/components/smartswitch/SmartSwitch;->G(Z)V # setCheckedWithoutUpdate

    # Add event listener for toggle
    new-instance v4, Ldev/maelstrom/ykit/settings/YkitSettingsActivity$UpdateSetting2;
    invoke-direct {v4, p3}, Ldev/maelstrom/ykit/settings/YkitSettingsActivity$UpdateSetting2;-><init>(Ljava/lang/reflect/Field;)V
    invoke-virtual {v0, v4}, Lcom/tumblr/components/smartswitch/SmartSwitch;->setOnCheckedChangeListener(Landroid/widget/CompoundButton$OnCheckedChangeListener;)V

    # Toggle fix (Tapping elsewhere on the row otherwise doesn't toggle the switch for some reason)
    new-instance v5, Ldev/maelstrom/ykit/settings/YkitSettingsActivity$toggleHelper;
    invoke-direct {v5, v0}, Ldev/maelstrom/ykit/settings/YkitSettingsActivity$toggleHelper;-><init>(Lcom/tumblr/components/smartswitch/SmartSwitch;)V
    invoke-virtual {p0, v5}, Landroid/view/View;->setOnClickListener(Landroid/view/View$OnClickListener;)V

    return-object v1
.end method