<commit_before>/*
 * Copyright (c) 2014. The Trustees of Indiana University.
 *
 * This version of the code is licensed under the MPL 2.0 Open Source license with additional
 * healthcare disclaimer. If the user is an entity intending to commercialize any application
 * that uses this code in a for-profit venture, please contact the copyright holder.
 */

package com.muzima.view.preferences;

import android.content.Intent;
import android.os.CountDownTimer;
import com.muzima.MuzimaApplication;
import com.muzima.service.TimeoutPreferenceService;
import com.muzima.view.login.LoginActivity;

public class MuzimaTimer extends CountDownTimer {

    private MuzimaApplication muzimaApplication;
    private static MuzimaTimer muzimaTimer;

    private MuzimaTimer(long millisInFuture, long countDownInterval, MuzimaApplication muzimaApplication) {
        super(millisInFuture, countDownInterval);
        this.muzimaApplication = muzimaApplication;
    }

    public static MuzimaTimer getTimer(MuzimaApplication muzimaApplication) {
        if (muzimaTimer == null) {
            int timeout = new TimeoutPreferenceService(muzimaApplication).getTimeout();
            muzimaTimer = new MuzimaTimer(getTimeInMillis(timeout) , getTimeInMillis(timeout), muzimaApplication);
        }
        return muzimaTimer;
    }


    public MuzimaTimer resetTimer(int timeOutInMin) {
        muzimaTimer.cancel();
        muzimaTimer = new MuzimaTimer(getTimeInMillis(timeOutInMin), getTimeInMillis(timeOutInMin), muzimaApplication);
        muzimaTimer.start();
        return muzimaTimer;
    }

    @Override
    public void onTick(long l) {
    }


    @Override
    public void onFinish() {
        logOut();
    }

    public void restart() {
        this.cancel();
        this.start();
    }

    private void logOut()
    {
        boolean isRunningInBackground = muzimaApplication.isRunningInBackground();
        muzimaApplication.logOut();
        if(!isRunningInBackground) {<commit_msg>MUZIMA-313 - Remove timeout value during initial wizard setup<commit_after>/*
 * Copyright (c) 2014. The Trustees of Indiana University.
 *
 * This version of the code is licensed under the MPL 2.0 Open Source license with additional
 * healthcare disclaimer. If the user is an entity intending to commercialize any application
 * that uses this code in a for-profit venture, please contact the copyright holder.
 */

package com.muzima.view.preferences;

import android.content.Intent;
import android.os.CountDownTimer;
import com.muzima.MuzimaApplication;
import com.muzima.service.TimeoutPreferenceService;
import com.muzima.service.WizardFinishPreferenceService;
import com.muzima.view.login.LoginActivity;

public class MuzimaTimer extends CountDownTimer {

    private MuzimaApplication muzimaApplication;
    private static MuzimaTimer muzimaTimer;

    private MuzimaTimer(long millisInFuture, long countDownInterval, MuzimaApplication muzimaApplication) {
        super(millisInFuture, countDownInterval);
        this.muzimaApplication = muzimaApplication;
    }

    public static MuzimaTimer getTimer(MuzimaApplication muzimaApplication) {
        if (muzimaTimer == null) {
            int timeout = new TimeoutPreferenceService(muzimaApplication).getTimeout();
            muzimaTimer = new MuzimaTimer(getTimeInMillis(timeout) , getTimeInMillis(timeout), muzimaApplication);
        }
        return muzimaTimer;
    }


    public MuzimaTimer resetTimer(int timeOutInMin) {
        muzimaTimer.cancel();
        muzimaTimer = new MuzimaTimer(getTimeInMillis(timeOutInMin), getTimeInMillis(timeOutInMin), muzimaApplication);
        muzimaTimer.start();
        return muzimaTimer;
    }

    @Override
    public void onTick(long l) {
    }


    @Override
    public void onFinish() {
        logOut();
    }

    public void restart() {
        this.cancel();
        this.start();
    }

    private void logOut()
    {
        boolean isRunningInBackground = muzimaApplication.isRunningInBackground();
        boolean isWizardComplete = new WizardFinishPreferenceService(muzimaApplication).isWizardFinished();
        if (isWizardComplete) {
            muzimaApplication.logOut();
        }
        if(!isRunningInBackground && isWizardComplete) {
{'fraction_non_alphanumeric': 0.07540521494009866, 'fraction_numerical': 0.0035236081747709656, 'mean_word_length': 3.578494623655914, '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': '6985000', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1180, 'n_words': 298}