<commit_before>package com.benoitletondor.easybudgetapp.view.welcome;


import android.os.Bundle;
import android.app.Fragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.benoitletondor.easybudgetapp.R;
import com.benoitletondor.easybudgetapp.helper.CurrencyHelper;
import com.benoitletondor.easybudgetapp.model.Expense;
import com.benoitletondor.easybudgetapp.model.db.DB;

import java.util.Date;

/**
 * Onboarding step 3 fragment
 *
 * @author <NAME>
 */
public class Onboarding3Fragment extends OnboardingFragment
{
    private TextView moneyTextView;
    private EditText amountEditText;
    private Button nextButton;

// -------------------------------------->

    /**
     * Required empty public constructor
     */
    public Onboarding3Fragment()
    {

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        // Inflate the layout for this fragment
        View v = inflater.inflate(R.layout.fragment_onboarding3, container, false);

        DB db = getDB();

        int amount = 0;
        if( db != null )
        {
            amount = db.getBalanceForDay(new Date());
        }

        moneyTextView = (TextView) v.findViewById(R.id.onboarding_screen3_initial_amount_money_tv);
        setCurrency();

        amountEditText = (EditText) v.findViewById(R.id.onboarding_screen3_initial_amount_et);
        amountEditText.setText(String.valueOf(amount));
        amountEditText.addTextChangedListener(new TextWatcher()
        {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after)
            {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count)
            {

            }

            @Override
            public void afterTextChanged(Editable s)
            {
                setButtonText();
            }
        });

        nextButton = (Button) v.findViewById(R.id.onboarding_screen3_next_button);
        nextButton.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                DB db = getDB();
                if (db != null)
                {
                    int currentBalance = db.getBalanceForDay(new Date());
                    int newBalance = Integer.valueOf(amountEditText.getText().toString());

                    if (newBalance == currentBalance)
                    {
                        // Nothing to do, balance hasn't change
                        return;
                    }

                    int diff = newBalance - currentBalance;

                    final Expense expense = new Expense(getResources().getString(R.string.adjust_balance_expense_title), -diff, new Date());
                    db.persistExpense(expense);
                }

                next(v);
            }
        });
        setButtonText();

        return v;
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser)
    {
        super.setUserVisibleHint(isVisibleToUser);

        if( isVisibleToUser ) // Update values on display
        {
            setCurrency();
            setButtonText();
        }
    }

    @Override
    public int getStatusBarColor()
    {
        return R.color.onboarding_3_statusbar;
    }

// -------------------------------------->

    private void setCurrency()<commit_msg>Remove keyboard after onboarding 3<commit_after>package com.benoitletondor.easybudgetapp.view.welcome;


import android.content.Context;
import android.os.Bundle;
import android.app.Fragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.benoitletondor.easybudgetapp.R;
import com.benoitletondor.easybudgetapp.helper.CurrencyHelper;
import com.benoitletondor.easybudgetapp.helper.Logger;
import com.benoitletondor.easybudgetapp.model.Expense;
import com.benoitletondor.easybudgetapp.model.db.DB;

import java.util.Date;

/**
 * Onboarding step 3 fragment
 *
 * @author <NAME>
 */
public class Onboarding3Fragment extends OnboardingFragment
{
    private TextView moneyTextView;
    private EditText amountEditText;
    private Button nextButton;

// -------------------------------------->

    /**
     * Required empty public constructor
     */
    public Onboarding3Fragment()
    {

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        // Inflate the layout for this fragment
        View v = inflater.inflate(R.layout.fragment_onboarding3, container, false);

        DB db = getDB();

        int amount = 0;
        if( db != null )
        {
            amount = db.getBalanceForDay(new Date());
        }

        moneyTextView = (TextView) v.findViewById(R.id.onboarding_screen3_initial_amount_money_tv);
        setCurrency();

        amountEditText = (EditText) v.findViewById(R.id.onboarding_screen3_initial_amount_et);
        amountEditText.setText(String.valueOf(amount));
        amountEditText.addTextChangedListener(new TextWatcher()
        {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after)
            {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count)
            {

            }

            @Override
            public void afterTextChanged(Editable s)
            {
                setButtonText();
            }
        });

        nextButton = (Button) v.findViewById(R.id.onboarding_screen3_next_button);
        nextButton.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                DB db = getDB();
                if (db != null)
                {
                    int currentBalance = db.getBalanceForDay(new Date());
                    int newBalance = Integer.valueOf(amountEditText.getText().toString());

                    if (newBalance != currentBalance)
                    {
                        int diff = newBalance - currentBalance;

                        final Expense expense = new Expense(getResources().getString(R.string.adjust_balance_expense_title), -diff, new Date());
                        db.persistExpense(expense);
                    }
                }

                // Hide keyboard
                try
                {
                    InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(amountEditText.getWindowToken(), 0);
                }
                catch(Exception e)
                {
                    Logger.error("Error while hiding keyboard", e);
                }

                next(v);
            }
        });
        setButtonText();

        return v;
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser)
    {
        super.setUserVisibleHint(isVisibleToUser);

        if( isVisibleToUser ) // Update values on display
        {
            setCurrency();
            setButtonText();
        }
    }

    @Override
    public int getStatusBarColor()
    {
        return R.color.onboarding_3_statusbar;
    }

// -------------------------------------->

    private void setCurrency()
{'fraction_non_alphanumeric': 0.10319969647148097, 'fraction_numerical': 0.0025294043252813963, 'mean_word_length': 1.8914076782449725, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '7666120', 'n_tokens_mistral': 2143, 'n_tokens_neox': 2004, 'n_words': 420}