<commit_before>/*
 * Copyright 2011 <NAME>
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package ru.elifantiev.android.timespan;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

public class TimeSpanGroupEditActivity extends Activity {

    final static String GROUP_SPEC_EXTRA = "ru.elifantiev.android.timespan.GROUP_SPEC_EXTRA";
    final static String SHOW_HELP = "ru.elifantiev.android.timespan.SHOW_HELP";
    final static int DIALOG_HELP = 1;
    private TimeSpanGroupEditor groupEditor;
    private String initialGroup = "0:0-1440";

    @Override
    public void onBackPressed() {
        final TimeSpanGroup g = groupEditor.getValue();
        if(!initialGroup.equals(g.toString())) {
            if(g.getDayMask() == 0) {
                Toast.makeText(this, R.string.selectDays, Toast.LENGTH_LONG).show();
            } else {
                new AlertDialog.Builder(this)
                    .setMessage(getString(R.string.saveChanges))
                    .setCancelable(false)
                    .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            Intent result = new Intent();
                            result.putExtra(GROUP_SPEC_EXTRA, g.toString());
                            setResult(RESULT_OK, result);
                            finish();
                        }
                    })
                    .setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                            finish();
                        }
                    })
                    .create()
                    .show();
            }
        }
        else
            finish();
    }

    @Override
    protected Dialog onCreateDialog(int id) {
        Dialog dialog = null;
        if(id == DIALOG_HELP) {
            dialog = new Dialog(getApplicationContext());

            dialog.setContentView(R.layout.help_dialog);
            dialog.setTitle(getString(R.string.edit_help_title));

        }<commit_msg>Changed time span saving sequence<commit_after>/*
 * Copyright 2011 <NAME>
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package ru.elifantiev.android.timespan;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

public class TimeSpanGroupEditActivity extends Activity {

    final static String GROUP_SPEC_EXTRA = "ru.elifantiev.android.timespan.GROUP_SPEC_EXTRA";
    final static String SHOW_HELP = "ru.elifantiev.android.timespan.SHOW_HELP";
    final static int DIALOG_HELP = 1;
    private TimeSpanGroupEditor groupEditor;
    private String initialGroup = "0:0-1440";

    @Override
    public void onBackPressed() {
        final TimeSpanGroup g = groupEditor.getValue();
        if(!initialGroup.equals(g.toString())) {
            new AlertDialog.Builder(this)
                .setMessage(getString(R.string.saveChanges))
                .setCancelable(false)
                .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        if(g.getDayMask() == 0) {
                            Toast.makeText(
                                    TimeSpanGroupEditActivity.this,
                                    R.string.selectDays,
                                    Toast.LENGTH_LONG).show();
                        } else {
                            Intent result = new Intent();
                            result.putExtra(GROUP_SPEC_EXTRA, g.toString());
                            setResult(RESULT_OK, result);
                            finish();
                        }
                    }
                })
                .setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                        finish();
                    }
                })
                .create()
                .show();
        }
        else
            finish();
    }

    @Override
    protected Dialog onCreateDialog(int id) {
        Dialog dialog = null;
        if(id == DIALOG_HELP) {
            dialog = new Dialog(getApplicationContext());

            dialog.setContentView(R.layout.help_dialog);
            dialog.setTitle(getString(R.string.edit_help_title));

        }
{'fraction_non_alphanumeric': 0.08618103017169529, 'fraction_numerical': 0.005334222370395066, 'mean_word_length': 1.8612303290414878, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4230133', 'n_tokens_mistral': 1533, 'n_tokens_neox': 1450, 'n_words': 389}