<commit_before>package com.adafruit.bluefruit.le.connect.app.settings;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.adafruit.bluefruit.le.connect.R;
import com.adafruit.bluefruit.le.connect.app.update.ApplicationFilesFragmentDialog;
import com.adafruit.bluefruit.le.connect.app.update.DfuService;
import com.adafruit.bluefruit.le.connect.app.update.FirmwareUpdater;
import com.adafruit.bluefruit.le.connect.app.update.ReleasesParser;
import com.adafruit.bluefruit.le.connect.ble.BleManager;
import com.adafruit.bluefruit.le.connect.ui.utils.ExpandableHeightListView;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ConnectedSettingsActivity extends AppCompatActivity implements FirmwareUpdater.FirmwareUpdaterListener, ApplicationFilesFragmentDialog.ApplicationFilesDialogListener {
    // Log
    private final static String TAG = ConnectedSettingsActivity.class.getSimpleName();

    // Activity request codes (used for onActivityResult)
    private static final int kActivityRequestCode_SelectFile_Hex = 0;
    private static final int kActivityRequestCode_SelectFile_Ini = 1;

    // UI
    private View mUpdatesWaitView;
    private View mUpdatesWaitIndicatorView;
    private TextView mUpdatesWaitTextView;

    private View mFirmwareReleasesView;
    private Button mCustomFirmwareButton;
    private ExpandableHeightListView mFirmwareReleasesListView;
    private ReleasesListAdapter mFirmwareReleasesListAdapter;

    private View mBootloaderReleasesView;
    private Button mCustomBootloaderButton;
    private ExpandableHeightListView mBootloaderReleasesListView;
    private ReleasesListAdapter mBootloaderReleasesListAdapter;

    // Data
    private FirmwareUpdater mFirmwareUpdater;
    private boolean mIsUpdating;
    private ReleasesParser.BoardInfo mBoardRelease;
    private FirmwareUpdater.DeviceInfoData mDeviceInfoData;
    private boolean mShowBetaVersions;

    private ApplicationFilesFragmentDialog mApplicationFilesDialog;


    private DataFragment mRetainedDataFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_connected_settings);

        // Set parent for navigation
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);

        // Restore state
        restoreRetainedDataFragment();

        // UI
        mUpdatesWaitView = findViewById(R.id.updatesWaitView);
        mUpdatesWaitIndicatorView = findViewById(R.id.updatesWaitIndicatorView);
        mUpdatesWaitTextView = (TextView) findViewById(R.id.updatesWaitTextView);

        mFirmwareReleasesView = findViewById(R.id.firmwareReleasesView);
        mCustomFirmwareButton = (Button) findViewById(R.id.customFirmwareButton);
        mFirmwareReleasesListView = (ExpandableHeightListView) findViewById(R.id.firmwareReleasesListView);
        mFirmwareReleasesListView.setExpanded(true);
        mFirmwareReleasesListAdapter = new ReleasesListAdapter(ConnectedSettingsActivity.this, mBoardRelease == null ? null : mBoardRelease.firmwareReleases, mShowBetaVersions);      // mBoardRelease is still null here (except if we are restoring the activity because onConfigChanges)
        mFirmwareReleasesListView.setAdapter(mFirmwareReleasesListAdapter);

        mBootloaderReleasesView = findViewById(R.id.bootloaderReleasesView);
        mCustomBootloaderButton = (Button) findViewById(R.id.customBootloaderButton);
        mBootloaderReleasesListView = (ExpandableHeightListView) findViewById(R.id.bootloaderReleasesListView);
        mBootloaderReleasesListView.setExpanded(true);
        mBootloaderReleasesListAdapter = new ReleasesListAdapter(ConnectedSettingsActivity.this, mBoardRelease == null ? null : mBoardRelease.bootloaderReleases, mShowBetaVersions);      // mBoardRelease is still null here (except if we are restoring the activity because onConfigChanges)
        mBootloaderReleasesListView.setAdapter(mBootloaderReleasesListAdapter);

        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        mShowBetaVersions = sharedPreferences.getBoolean("pref_showbetaversions", false);

        // Start
        if (mDeviceInfoData == null) {      // only do this check the first time
            // Force clear current command queue to prevent a weird state where the executor is waiting for actions that never finish
            BleManager bleManager = BleManager.getInstance(this);
            bleManager.clearExecutor();

            mFirmwareUpdater.checkFirmwareUpdatesForTheCurrentConnectedDevice();            // continues on onFirmwareUpdatesChecked
        }<commit_msg>* Fixed bug: Firmware Updater screen hides beta versions when the device is rotated<commit_after>package com.adafruit.bluefruit.le.connect.app.settings;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.adafruit.bluefruit.le.connect.R;
import com.adafruit.bluefruit.le.connect.app.update.ApplicationFilesFragmentDialog;
import com.adafruit.bluefruit.le.connect.app.update.DfuService;
import com.adafruit.bluefruit.le.connect.app.update.FirmwareUpdater;
import com.adafruit.bluefruit.le.connect.app.update.ReleasesParser;
import com.adafruit.bluefruit.le.connect.ble.BleManager;
import com.adafruit.bluefruit.le.connect.ui.utils.ExpandableHeightListView;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ConnectedSettingsActivity extends AppCompatActivity implements FirmwareUpdater.FirmwareUpdaterListener, ApplicationFilesFragmentDialog.ApplicationFilesDialogListener {
    // Log
    private final static String TAG = ConnectedSettingsActivity.class.getSimpleName();

    // Activity request codes (used for onActivityResult)
    private static final int kActivityRequestCode_SelectFile_Hex = 0;
    private static final int kActivityRequestCode_SelectFile_Ini = 1;

    // UI
    private View mUpdatesWaitView;
    private View mUpdatesWaitIndicatorView;
    private TextView mUpdatesWaitTextView;

    private View mFirmwareReleasesView;
    private Button mCustomFirmwareButton;
    private ExpandableHeightListView mFirmwareReleasesListView;
    private ReleasesListAdapter mFirmwareReleasesListAdapter;

    private View mBootloaderReleasesView;
    private Button mCustomBootloaderButton;
    private ExpandableHeightListView mBootloaderReleasesListView;
    private ReleasesListAdapter mBootloaderReleasesListAdapter;

    // Data
    private FirmwareUpdater mFirmwareUpdater;
    private boolean mIsUpdating;
    private ReleasesParser.BoardInfo mBoardRelease;
    private FirmwareUpdater.DeviceInfoData mDeviceInfoData;
    private boolean mShowBetaVersions;

    private ApplicationFilesFragmentDialog mApplicationFilesDialog;


    private DataFragment mRetainedDataFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_connected_settings);

        // Set parent for navigation
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);

        // Restore state
        restoreRetainedDataFragment();

        // Read settings
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        mShowBetaVersions = sharedPreferences.getBoolean("pref_showbetaversions", false);

        // UI
        mUpdatesWaitView = findViewById(R.id.updatesWaitView);
        mUpdatesWaitIndicatorView = findViewById(R.id.updatesWaitIndicatorView);
        mUpdatesWaitTextView = (TextView) findViewById(R.id.updatesWaitTextView);

        mFirmwareReleasesView = findViewById(R.id.firmwareReleasesView);
        mCustomFirmwareButton = (Button) findViewById(R.id.customFirmwareButton);
        mFirmwareReleasesListView = (ExpandableHeightListView) findViewById(R.id.firmwareReleasesListView);
        mFirmwareReleasesListView.setExpanded(true);
        mFirmwareReleasesListAdapter = new ReleasesListAdapter(ConnectedSettingsActivity.this, mBoardRelease == null ? null : mBoardRelease.firmwareReleases, mShowBetaVersions);      // mBoardRelease is still null here (except if we are restoring the activity because onConfigChanges)
        mFirmwareReleasesListView.setAdapter(mFirmwareReleasesListAdapter);

        mBootloaderReleasesView = findViewById(R.id.bootloaderReleasesView);
        mCustomBootloaderButton = (Button) findViewById(R.id.customBootloaderButton);
        mBootloaderReleasesListView = (ExpandableHeightListView) findViewById(R.id.bootloaderReleasesListView);
        mBootloaderReleasesListView.setExpanded(true);
        mBootloaderReleasesListAdapter = new ReleasesListAdapter(ConnectedSettingsActivity.this, mBoardRelease == null ? null : mBoardRelease.bootloaderReleases, mShowBetaVersions);      // mBoardRelease is still null here (except if we are restoring the activity because onConfigChanges)
        mBootloaderReleasesListView.setAdapter(mBootloaderReleasesListAdapter);

        // Start
        if (mDeviceInfoData == null) {      // only do this check the first time
            // Force clear current command queue to prevent a weird state where the executor is waiting for actions that never finish
            BleManager bleManager = BleManager.getInstance(this);
            bleManager.clearExecutor();

            mFirmwareUpdater.checkFirmwareUpdatesForTheCurrentConnectedDevice();            // continues on onFirmwareUpdatesChecked
        }
{'fraction_non_alphanumeric': 0.06758608092063202, 'fraction_numerical': 0.0007306603342771029, 'mean_word_length': 4.796717840127052, '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': '2410124', 'n_tokens_mistral': 2990, 'n_tokens_neox': 2859, 'n_words': 595}