<commit_before>package org.commcare.dalvik.activities;

import org.commcare.android.adapters.AppManagerAdapter;
import org.commcare.android.util.SessionUnavailableException;
import org.commcare.dalvik.R;
import org.commcare.dalvik.application.CommCareApplication;
import org.commcare.dalvik.services.CommCareSessionService;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;

/**
 * 
 * The activity that starts up when a user launches into the app manager.
 * Displays a list of all installed apps, each of which can be clicked to launch
 * the SingleAppManagerAcitivity for that app. Also includes a button for
 * installing new apps.
 * 
 * @author amstone326
 * 
 */

public class AppManagerActivity extends Activity implements OnItemClickListener {

    public static final String KEY_LAUNCH_FROM_MANAGER = "from_manager";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.app_manager);
        ((ListView) this.findViewById(R.id.apps_list_view)).setOnItemClickListener(this);
    }

    private void refreshView() {
        ListView lv = (ListView) findViewById(R.id.apps_list_view);
        lv.setAdapter(new AppManagerAdapter(this, android.R.layout.simple_list_item_1, 
                CommCareApplication._().appRecordArray()));
    }

    public void onResume() {
        super.onResume();
        refreshView();
    }

    public void installAppClicked(View v) {
        try {
            CommCareSessionService s = CommCareApplication._().getSession();
            if (s.isActive()) {
                triggerLogoutWarning();
            } else {
                installApp();
            }
        } catch (SessionUnavailableException e) {
            installApp();
        }
    }

    public void installApp() {
        CommCareApplication._().logout();
        Intent i = new Intent(getApplicationContext(), CommCareSetupActivity.class);
        i.putExtra(KEY_LAUNCH_FROM_MANAGER, true);
        this.startActivityForResult(i, CommCareHomeActivity.INIT_APP);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        switch (requestCode) {
        case CommCareHomeActivity.INIT_APP:
            Log.i("HERE", "Back in ManagerActivity from INIT_APP");
            boolean installFailed = intent.getBooleanExtra(CommCareSetupActivity.KEY_INSTALL_FAILED,
                    false);
            if (resultCode == RESULT_OK && !installFailed) {
                if (!CommCareApplication._().getCurrentApp().areResourcesValidated()) {
                    Log.i("HERE", "going to VerificationActivity from ManagerActivity");
                    Intent i = new Intent(this, CommCareVerificationActivity.class);
                    i.putExtra(KEY_LAUNCH_FROM_MANAGER, true);
                    this.startActivityForResult(i, CommCareHomeActivity.MISSING_MEDIA_ACTIVITY);
                } else {
                    Toast.makeText(this, "New app installed successfully", Toast.LENGTH_LONG).show();
                }
            } else {
                Toast.makeText(this, "No app was installed!", Toast.LENGTH_LONG).show();
            }
            break;
        case CommCareHomeActivity.MISSING_MEDIA_ACTIVITY:
            Log.i("HERE", "Back in ManagerActivity from MISSING_MEDIA_ACTIVITY");
            if (resultCode == RESULT_CANCELED) {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle("Media Not Verified");
                builder.setMessage(R.string.skipped_verification_warning)
                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }

                    });
                AlertDialog dialog = builder.create();
                dialog.show();
            } else if (resultCode == RESULT_OK) {
                Toast.makeText(this, "Media Validated!", Toast.LENGTH_LONG).show();
            }
            break;
        }
    }

    @Override<commit_msg>remove comments and spelling fix<commit_after>package org.commcare.dalvik.activities;

import org.commcare.android.adapters.AppManagerAdapter;
import org.commcare.android.util.SessionUnavailableException;
import org.commcare.dalvik.R;
import org.commcare.dalvik.application.CommCareApplication;
import org.commcare.dalvik.services.CommCareSessionService;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;

/**
 * 
 * The activity that starts up when a user launches into the app manager.
 * Displays a list of all installed apps, each of which can be clicked to launch
 * the SingleAppManagerActivity for that app. Also includes a button for
 * installing new apps.
 * 
 * @author amstone326
 * 
 */

public class AppManagerActivity extends Activity implements OnItemClickListener {

    public static final String KEY_LAUNCH_FROM_MANAGER = "from_manager";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.app_manager);
        ((ListView) this.findViewById(R.id.apps_list_view)).setOnItemClickListener(this);
    }

    private void refreshView() {
        ListView lv = (ListView) findViewById(R.id.apps_list_view);
        lv.setAdapter(new AppManagerAdapter(this, android.R.layout.simple_list_item_1, 
                CommCareApplication._().appRecordArray()));
    }

    public void onResume() {
        super.onResume();
        refreshView();
    }

    public void installAppClicked(View v) {
        try {
            CommCareSessionService s = CommCareApplication._().getSession();
            if (s.isActive()) {
                triggerLogoutWarning();
            } else {
                installApp();
            }
        } catch (SessionUnavailableException e) {
            installApp();
        }
    }

    public void installApp() {
        CommCareApplication._().logout();
        Intent i = new Intent(getApplicationContext(), CommCareSetupActivity.class);
        i.putExtra(KEY_LAUNCH_FROM_MANAGER, true);
        this.startActivityForResult(i, CommCareHomeActivity.INIT_APP);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        switch (requestCode) {
        case CommCareHomeActivity.INIT_APP:
            boolean installFailed = intent.getBooleanExtra(CommCareSetupActivity.KEY_INSTALL_FAILED,
                    false);
            if (resultCode == RESULT_OK && !installFailed) {
                if (!CommCareApplication._().getCurrentApp().areResourcesValidated()) {
                    Intent i = new Intent(this, CommCareVerificationActivity.class);
                    i.putExtra(KEY_LAUNCH_FROM_MANAGER, true);
                    this.startActivityForResult(i, CommCareHomeActivity.MISSING_MEDIA_ACTIVITY);
                } else {
                    Toast.makeText(this, "New app installed successfully", Toast.LENGTH_LONG).show();
                }
            } else {
                Toast.makeText(this, "No app was installed!", Toast.LENGTH_LONG).show();
            }
            break;
        case CommCareHomeActivity.MISSING_MEDIA_ACTIVITY:
            if (resultCode == RESULT_CANCELED) {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle("Media Not Verified");
                builder.setMessage(R.string.skipped_verification_warning)
                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }

                    });
                AlertDialog dialog = builder.create();
                dialog.show();
            } else if (resultCode == RESULT_OK) {
                Toast.makeText(this, "Media Validated!", Toast.LENGTH_LONG).show();
            }
            break;
        }
    }

    @Override
{'fraction_non_alphanumeric': 0.09107406147215606, 'fraction_numerical': 0.0009073380968583418, 'mean_word_length': 2.439157566302652, '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': '416356', 'n_tokens_mistral': 2384, 'n_tokens_neox': 2232, 'n_words': 481}