<commit_before>package com.team_clicker.idlefarmer;

import android.content.DialogInterface;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.team_clicker.idlefarmer.adapter.CerealAdapter;
import com.team_clicker.idlefarmer.model.Cereal;
import com.team_clicker.idlefarmer.runnable.CerealRun;
import com.team_clicker.idlefarmer.runnable.Counter;
import com.team_clicker.idlefarmer.service.GameService;
import com.team_clicker.idlefarmer.view.CerealView;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Timer;

/**

 * An example full-screen activity that shows and hides the system UI (i.e.

 * status bar and navigation/system bar) with user interaction.

 */

public class MainActivity extends AppCompatActivity {
    public final static int MESSAGE_MONEY = 1;
    public final static int MESSAGE_PB = 2;

    private List<Timer> timers = new ArrayList<>();
    private GameService service = new GameService(this);
    private boolean firstTime = false;
    private List<ProgressBar> progressBars;
    private Counter counter;
    private Thread threadCounter;

    private TextView tvMoney;
    private ListView listViewCereals;
    private Button buttonLevel;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        tvMoney = (TextView) findViewById(R.id.valueMoney);

        listViewCereals = (ListView)findViewById(R.id.cereals);
        listViewCereals.setOnItemClickListener(cerealClick);

        buttonLevel = (Button) findViewById(R.id.addLevel);
        buttonLevel.setOnClickListener(buttonLevelClick);

        progressBars = new ArrayList<>();
        counter = new Counter(handler);
        threadCounter = new Thread(counter);
        threadCounter.start();
    }

    @Override
    protected void onPause() {
        super.onPause();

        Calendar now = Calendar.getInstance();

        service.getGame().setDbtIdle(now.getTimeInMillis());

        for(Timer timer : timers){
            timer.cancel();
        }

        service.saveGame();
    }

    @Override
    protected void onResume() {
        super.onResume();

        service.init();

        if(service.getGame().getDbtIdle() > 0){
            Calendar now = Calendar.getInstance();
            long diffSeconds = (now.getTimeInMillis() - service.getGame().getDbtIdle()) / 1000;
            double moneyEarns = diffSeconds * service.getGame().getEarnBySeconds();

            dialog(moneyEarns);

            service.getGame().addMoney(moneyEarns);
        }

        setTextMoneyTV(service.getGame().getMoney());

        for(Cereal cereal : service.getGame().getCereals()){
            if(cereal.getLevel() > 0){
                Timer timer = new Timer();
                timer.schedule(new CerealRun(cereal, service.getGame(), handler), 0, cereal.getGrowthTime()*1000);
                timers.add(timer);
            }
        }

        List<Cereal> cerealsList = service.getGame().getCereals();
        List<CerealView> cerealViewList = new ArrayList<>();
        for(Cereal cereal : cerealsList){
            cerealViewList.add(new CerealView(cereal, cereal.getCurrentPrice()));
        }

        CerealAdapter adapter = new CerealAdapter(getApplicationContext(), cerealViewList);
        listViewCereals.setAdapter(adapter);
    }

    private AdapterView.OnItemClickListener cerealClick = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            CerealView entry = (CerealView)parent.getAdapter().getItem(position);

            if(service.getGame().getMoney() >= entry.getCereal().getCurrentPrice()){
                int level = 1;
                if(buttonLevel.getText().equals("+ 10")){
                    level = 10;
                } else if(buttonLevel.getText().equals("+ 25")){
                    level = 25;
                }

                entry.getCereal().setLevel(entry.getCereal().getLevel() + level);

                if(entry.getCereal().getLevel() == 1){
                    Timer timer = new Timer();
                    timer.schedule(new CerealRun(entry.getCereal(), service.getGame(), handler), 0, entry.getCereal().getGrowthTime()*1000);
                    timers.add(timer);
                }

                service.getGame().removeMoney(entry.getCereal().getCurrentPrice());
                service.updateCereal(entry.getCereal());

                entry.setPriceDisplayed(entry.getCereal().getCurrentPrice());

                setTextMoneyTV(service.getGame().getMoney());

                listViewCereals.invalidateViews();

                listViewCereals.refreshDrawableState();
            }
        }
    };

    private View.OnClickListener buttonLevelClick = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int level = 1;<commit_msg>Fix Bug Money When add multiple level<commit_after>package com.team_clicker.idlefarmer;

import android.content.DialogInterface;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.team_clicker.idlefarmer.adapter.CerealAdapter;
import com.team_clicker.idlefarmer.model.Cereal;
import com.team_clicker.idlefarmer.runnable.CerealRun;
import com.team_clicker.idlefarmer.runnable.Counter;
import com.team_clicker.idlefarmer.service.GameService;
import com.team_clicker.idlefarmer.view.CerealView;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Timer;

/**

 * An example full-screen activity that shows and hides the system UI (i.e.

 * status bar and navigation/system bar) with user interaction.

 */

public class MainActivity extends AppCompatActivity {
    public final static int MESSAGE_MONEY = 1;
    public final static int MESSAGE_PB = 2;

    private List<Timer> timers = new ArrayList<>();
    private GameService service = new GameService(this);
    private boolean firstTime = false;
    private List<ProgressBar> progressBars;
    private Counter counter;
    private Thread threadCounter;

    private TextView tvMoney;
    private ListView listViewCereals;
    private Button buttonLevel;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        tvMoney = (TextView) findViewById(R.id.valueMoney);

        listViewCereals = (ListView)findViewById(R.id.cereals);
        listViewCereals.setOnItemClickListener(cerealClick);

        buttonLevel = (Button) findViewById(R.id.addLevel);
        buttonLevel.setOnClickListener(buttonLevelClick);

        progressBars = new ArrayList<>();
        counter = new Counter(handler);
        threadCounter = new Thread(counter);
        threadCounter.start();
    }

    @Override
    protected void onPause() {
        super.onPause();

        Calendar now = Calendar.getInstance();

        service.getGame().setDbtIdle(now.getTimeInMillis());

        for(Timer timer : timers){
            timer.cancel();
        }

        service.saveGame();
    }

    @Override
    protected void onResume() {
        super.onResume();

        service.init();

        if(service.getGame().getDbtIdle() > 0){
            Calendar now = Calendar.getInstance();
            long diffSeconds = (now.getTimeInMillis() - service.getGame().getDbtIdle()) / 1000;
            double moneyEarns = diffSeconds * service.getGame().getEarnBySeconds();

            dialog(moneyEarns);

            service.getGame().addMoney(moneyEarns);
        }

        setTextMoneyTV(service.getGame().getMoney());

        for(Cereal cereal : service.getGame().getCereals()){
            if(cereal.getLevel() > 0){
                Timer timer = new Timer();
                timer.schedule(new CerealRun(cereal, service.getGame(), handler), 0, cereal.getGrowthTime()*1000);
                timers.add(timer);
            }
        }

        List<Cereal> cerealsList = service.getGame().getCereals();
        List<CerealView> cerealViewList = new ArrayList<>();
        for(Cereal cereal : cerealsList){
            cerealViewList.add(new CerealView(cereal, cereal.getCurrentPrice()));
        }

        CerealAdapter adapter = new CerealAdapter(getApplicationContext(), cerealViewList);
        listViewCereals.setAdapter(adapter);
    }

    private AdapterView.OnItemClickListener cerealClick = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            CerealView entry = (CerealView)parent.getAdapter().getItem(position);

            if(service.getGame().getMoney() >= entry.getPriceDisplayed()){
                int level = 1;
                if(buttonLevel.getText().equals("+ 10")){
                    level = 10;
                } else if(buttonLevel.getText().equals("+ 25")){
                    level = 25;
                }

                entry.getCereal().setLevel(entry.getCereal().getLevel() + level);

                if(entry.getCereal().getLevel() == 1){
                    Timer timer = new Timer();
                    timer.schedule(new CerealRun(entry.getCereal(), service.getGame(), handler), 0, entry.getCereal().getGrowthTime()*1000);
                    timers.add(timer);
                }

                service.getGame().removeMoney(entry.getPriceDisplayed());
                service.updateCereal(entry.getCereal());

                entry.calculateNewPriceToDisplay(level);

                setTextMoneyTV(service.getGame().getMoney());

                listViewCereals.invalidateViews();

                listViewCereals.refreshDrawableState();
            }
        }
    };

    private View.OnClickListener buttonLevelClick = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int level = 1;
{'fraction_non_alphanumeric': 0.10918300347059376, 'fraction_numerical': 0.005815589531938842, 'mean_word_length': 2.7214659685863873, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, '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': '6015981', 'n_tokens_mistral': 3130, 'n_tokens_neox': 2861, 'n_words': 571}