<commit_before>package wybren_erik.hanzespel.activiy;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;

import wybren_erik.hanzespel.R;
import wybren_erik.hanzespel.controller.Intervention;
import wybren_erik.hanzespel.dialog.ArrivedDialog;
import wybren_erik.hanzespel.dialog.GameAlmostOverDialog;
import wybren_erik.hanzespel.dialog.GameFinishedDialog;
import wybren_erik.hanzespel.dialog.InterventionDialog;
import wybren_erik.hanzespel.dialog.RulesDialog;
import wybren_erik.hanzespel.fragments.HandelFragment;
import wybren_erik.hanzespel.fragments.MapFragment;
import wybren_erik.hanzespel.fragments.StatusFragment;
import wybren_erik.hanzespel.interfaces.BoatListener;
import wybren_erik.hanzespel.interfaces.GameListener;
import wybren_erik.hanzespel.interfaces.InterventionListener;
import wybren_erik.hanzespel.model.Boat;
import wybren_erik.hanzespel.model.Game;
import wybren_erik.hanzespel.model.InventoryModel;

public class MainActivity extends AppCompatActivity implements BoatListener, InterventionListener, GameListener {

    private StatusFragment statusFragment;
    private HandelFragment handelFragment;
    private MapFragment mapFragment;
    private Fragment currentFragment;
    private ArrivedDialog arrivedDialog;
    private RulesDialog rulesDialog;
    private InterventionDialog interventionDialog = new InterventionDialog();
    private GameFinishedDialog endGameDialog = new GameFinishedDialog();
    private GameAlmostOverDialog almostEndGameDialog = new GameAlmostOverDialog();
    private BottomNavigationView navigation;
    private Uri intervention = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    private Ringtone r;

    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            Fragment newFragment;
            switch (item.getItemId()) {
                case R.id.navigation_status:
                    newFragment = statusFragment;
                    transaction.replace(R.id.main_fragment, newFragment);
                    if (currentFragment != newFragment) {
                        transaction.remove(currentFragment);
                        currentFragment = newFragment;
                    }
                    break;
                case R.id.navigation_handel:
                    newFragment = handelFragment;
                    transaction.replace(R.id.main_fragment, newFragment);
                    if (currentFragment != newFragment) {
                        transaction.remove(currentFragment);
                        currentFragment = newFragment;
                    }
                    break;
                case R.id.navigation_map:
                    newFragment = mapFragment;
                    transaction.replace(R.id.main_fragment, newFragment);
                    if (currentFragment != newFragment) {
                        transaction.remove(currentFragment);
                        currentFragment = newFragment;
                    }
                    break;
            }
            transaction.commit();
            return true;
        }
    };


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        // Set own menu bar view as menu bar
        inflater.inflate(R.menu.default_bar, menu);
        return true;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
        Boat.addListener(this);
        Intervention.addListener(this);
        Game.addListener(this);

        r = RingtoneManager.getRingtone(getApplicationContext(), intervention);


        navigation = (BottomNavigationView) findViewById(R.id.navigation);
        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

        statusFragment = new StatusFragment();
        handelFragment = new HandelFragment();
        mapFragment = new MapFragment();
        arrivedDialog = new ArrivedDialog();
        rulesDialog = new RulesDialog();

        rulesDialog.show(getSupportFragmentManager(), "rules_dialog");

        transaction.add(R.id.main_fragment, statusFragment);
        currentFragment = statusFragment;
        transaction.commit();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            // Add actions to menu bar
            case R.id.action_help:
                rulesDialog.show(getSupportFragmentManager(), "rules_dialog");
                break;
            case R.id.action_info:
                rulesDialog.show(getSupportFragmentManager(), "rules_dialog");
                break;
            default:
                super.onOptionsItemSelected(item);
        }
        return true;
    }

    @Override
    public void onBackPressed() {
        // Do nothing
    }

    @Override
    public void onDepart(long travelTime) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        currentFragment = statusFragment;
        transaction.replace(R.id.main_fragment, statusFragment);
        transaction.commit();
    }

    @Override
    public void onArrive() {
        try {
            r.play();
        } catch (Exception e) {
            e.printStackTrace();
        }
        arrivedDialog.show(getSupportFragmentManager(), "arrivedDialog");
        FragmentTransaction t = getSupportFragmentManager().beginTransaction();
        currentFragment = statusFragment;
        t.replace(R.id.main_fragment, handelFragment);
        t.commit();

    }

    @Override
    public void onArrivalTimeChanged(long timeUntilArrival) {
        // Ignored
    }

    @Override
    public void pirateship() {
        interventionDialog.text = "U bent aangevallen door een piratenschip! \n " +
                "U verliest een deel van uw lading.";
        try {
            r.play();
        } catch (Exception e) {
            e.printStackTrace();
        }
        interventionDialog.show(getSupportFragmentManager(), "interventionDialog");
    }<commit_msg>Added Dock intervention.<commit_after>package wybren_erik.hanzespel.activiy;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import wybren_erik.hanzespel.City;
import wybren_erik.hanzespel.Location;
import wybren_erik.hanzespel.R;
import wybren_erik.hanzespel.controller.Intervention;
import wybren_erik.hanzespel.dialog.ArrivedDialog;
import wybren_erik.hanzespel.dialog.GameAlmostOverDialog;
import wybren_erik.hanzespel.dialog.GameFinishedDialog;
import wybren_erik.hanzespel.dialog.InterventionDialog;
import wybren_erik.hanzespel.dialog.RulesDialog;
import wybren_erik.hanzespel.fragments.HandelFragment;
import wybren_erik.hanzespel.fragments.MapFragment;
import wybren_erik.hanzespel.fragments.StatusFragment;
import wybren_erik.hanzespel.interfaces.BoatListener;
import wybren_erik.hanzespel.interfaces.GameListener;
import wybren_erik.hanzespel.interfaces.InterventionListener;
import wybren_erik.hanzespel.model.Boat;
import wybren_erik.hanzespel.model.Game;
import wybren_erik.hanzespel.model.InventoryModel;

public class MainActivity extends AppCompatActivity implements BoatListener, InterventionListener, GameListener {

    private StatusFragment statusFragment;
    private HandelFragment handelFragment;
    private MapFragment mapFragment;
    private Fragment currentFragment;
    private ArrivedDialog arrivedDialog;
    private RulesDialog rulesDialog;
    private InterventionDialog interventionDialog = new InterventionDialog();
    private GameFinishedDialog endGameDialog = new GameFinishedDialog();
    private GameAlmostOverDialog almostEndGameDialog = new GameAlmostOverDialog();
    private BottomNavigationView navigation;
    private Uri intervention = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    private Ringtone r;
    private static ScheduledExecutorService executor;

    private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
            = new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            Fragment newFragment;
            switch (item.getItemId()) {
                case R.id.navigation_status:
                    newFragment = statusFragment;
                    transaction.replace(R.id.main_fragment, newFragment);
                    if (currentFragment != newFragment) {
                        transaction.remove(currentFragment);
                        currentFragment = newFragment;
                    }
                    break;
                case R.id.navigation_handel:
                    newFragment = handelFragment;
                    transaction.replace(R.id.main_fragment, newFragment);
                    if (currentFragment != newFragment) {
                        transaction.remove(currentFragment);
                        currentFragment = newFragment;
                    }
                    break;
                case R.id.navigation_map:
                    newFragment = mapFragment;
                    transaction.replace(R.id.main_fragment, newFragment);
                    if (currentFragment != newFragment) {
                        transaction.remove(currentFragment);
                        currentFragment = newFragment;
                    }
                    break;
            }
            transaction.commit();
            return true;
        }
    };


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        // Set own menu bar view as menu bar
        inflater.inflate(R.menu.default_bar, menu);
        return true;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_main);
        Boat.addListener(this);
        Intervention.addListener(this);
        Game.addListener(this);

        r = RingtoneManager.getRingtone(getApplicationContext(), intervention);

        executor = Executors.newSingleThreadScheduledExecutor();


        navigation = (BottomNavigationView) findViewById(R.id.navigation);
        navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

        statusFragment = new StatusFragment();
        handelFragment = new HandelFragment();
        mapFragment = new MapFragment();
        arrivedDialog = new ArrivedDialog();
        rulesDialog = new RulesDialog();

        rulesDialog.show(getSupportFragmentManager(), "rules_dialog");

        transaction.add(R.id.main_fragment, statusFragment);
        currentFragment = statusFragment;
        transaction.commit();
    }

    Runnable dockIntervention = new Runnable() {
        @Override
        public void run() {
            if (!Boat.getInstance().getLocation().equals(Location.KAMPEN)){
                interventionDialog.text = "U bent de haven uitgetrapt. U wordt teruggestuurd naar kampen.";
                Boat.getInstance().goToCity(new City(Location.KAMPEN));
                try {
                    r.play();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                interventionDialog.show(getSupportFragmentManager(), "interventionDialog");
            }
        }
    };

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            // Add actions to menu bar
            case R.id.action_help:
                rulesDialog.show(getSupportFragmentManager(), "rules_dialog");
                break;
            case R.id.action_info:
                rulesDialog.show(getSupportFragmentManager(), "rules_dialog");
                break;
            default:
                super.onOptionsItemSelected(item);
        }
        return true;
    }

    @Override
    public void onBackPressed() {
        // Do nothing
    }

    @Override
    public void onDepart(long travelTime) {
        executor.shutdownNow();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        currentFragment = statusFragment;
        transaction.replace(R.id.main_fragment, statusFragment);
        transaction.commit();
    }

    @Override
    public void onArrive() {
       executor.schedule(dockIntervention, 5, TimeUnit.MINUTES);
        try {
            r.play();
        } catch (Exception e) {
            e.printStackTrace();
        }
        arrivedDialog.show(getSupportFragmentManager(), "arrivedDialog");
        FragmentTransaction t = getSupportFragmentManager().beginTransaction();
        currentFragment = statusFragment;
        t.replace(R.id.main_fragment, handelFragment);
        t.commit();

    }

    @Override
    public void onArrivalTimeChanged(long timeUntilArrival) {
        // Ignored
    }

    @Override
    public void pirateship() {
        interventionDialog.text = "U bent aangevallen door een piratenschip! \n " +
                "U verliest een deel van uw lading.";
        try {
            r.play();
        } catch (Exception e) {
            e.printStackTrace();
        }
        interventionDialog.show(getSupportFragmentManager(), "interventionDialog");
    }
{'fraction_non_alphanumeric': 0.0797269448737764, 'fraction_numerical': 0.00045079855744461616, 'mean_word_length': 2.72130361849988, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1087952', 'n_tokens_mistral': 4013, 'n_tokens_neox': 3807, 'n_words': 739}