<commit_before>/*  Copyright (C) 2015-2020 <NAME>, <NAME>, <NAME>, Dikay900, <NAME>

    This file is part of Gadgetbridge.

    Gadgetbridge is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Gadgetbridge is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.activities.charts;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.github.mikephil.charting.charts.Chart;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;


public class ActivityListingChartFragment extends AbstractChartFragment {
    protected static final Logger LOG = LoggerFactory.getLogger(ActivityListingChartFragment.class);
    int tsDataFrom;
    private View rootView;
    private List<? extends ActivitySample> activitySamples;
    private ActivityListingAdapter stepListAdapter;
    private TextView stepsDateView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_steps_list, container, false);

        ListView stepsList = rootView.findViewById(R.id.itemListView);
        stepListAdapter = new ActivityListingAdapter(getContext());
        stepsList.setAdapter(stepListAdapter);
        stepsDateView = rootView.findViewById(R.id.stepsDateView);
        LOG.debug("PETR " + getHost());
        try {
            getChartsHost().getClass().getMethod("enableSwipeRefresh").invoke(false);
        } catch (Exception e) {
            LOG.debug("dsda", e);
        }
        //device.getClass().getMethod("cancelBondProcess").invoke(device);

        //refresh();
        return rootView;
    }

    @Override
    public String getTitle() {
        return "Steps list";
    }


    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action.equals(ChartsHost.REFRESH)) {
            // TODO: use LimitLines to visualize smart alarms?
            //refresh();
        } else {
            super.onReceive(context, intent);
        }
    }


    @Override
    protected ChartsData refreshInBackground(ChartsHost chartsHost, DBHandler db, GBDevice device) {
        //trying to fit found peg into square hole of the Gb Charts fragment system
        //get the data
        activitySamples = getSamples(db, device);
        return null;
    }

    @Override
    protected void updateChartsnUIThread(ChartsData chartsData) {
        //top displays selected date
        stepsDateView.setText(DateTimeUtils.formatDate(new Date(tsDataFrom * 1000L)));
        //calculate active sessions
        StepAnalysis stepAnalysis = new StepAnalysis();
        if (activitySamples != null) {
            List<StepAnalysis.StepSession> stepSessions = stepAnalysis.calculateStepSessions(activitySamples);
            if (stepSessions.toArray().length == 0) {
                stepSessions = create_empty_record();
            }
            //push to the adapter
            stepListAdapter.setItems(stepSessions, true);
        }
    }

    @Override
    protected void renderCharts() {

    }

    @Override
    protected void setupLegend(Chart chart) {

    }

    @Override
    protected List<? extends ActivitySample> getSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
        Calendar day = Calendar.getInstance();
        day.setTimeInMillis(tsTo * 1000L); //we need today initially, which is the end of the time range
        day.set(Calendar.HOUR_OF_DAY, 0); //and we set time for the start and end of the same day
        day.set(Calendar.MINUTE, 0);
        day.set(Calendar.SECOND, 0);

        tsFrom = (int) (day.getTimeInMillis() / 1000);
        tsTo = tsFrom + 24 * 60 * 60 - 1;
        tsDataFrom = tsFrom;
        return getAllSamples(db, device, tsFrom, tsTo);
    }

    private List<StepAnalysis.StepSession> create_empty_record() {
        //have an "Unknown Activity" in the list in case there are no active sessions
        List<StepAnalysis.StepSession> result = new ArrayList<>();
        int tsTo = tsDataFrom + 24 * 60 * 60 - 1;
        result.add(new StepAnalysis.StepSession(new Date(tsDataFrom * 1000L), new Date(tsTo * 1000L), 0, 0, ActivityKind.TYPE_UNKNOWN));
        return result;
    }


}
<commit_msg>Remove testing reflection code trying to disable pull to refresh in Activity List<commit_after>/*  Copyright (C) 2015-2020 <NAME>, <NAME>, <NAME>, Dikay900, <NAME>

    This file is part of Gadgetbridge.

    Gadgetbridge is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Gadgetbridge is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.activities.charts;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.github.mikephil.charting.charts.Chart;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;


public class ActivityListingChartFragment extends AbstractChartFragment {
    protected static final Logger LOG = LoggerFactory.getLogger(ActivityListingChartFragment.class);
    int tsDataFrom;
    private View rootView;
    private List<? extends ActivitySample> activitySamples;
    private ActivityListingAdapter stepListAdapter;
    private TextView stepsDateView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        rootView = inflater.inflate(R.layout.fragment_steps_list, container, false);

        ListView stepsList = rootView.findViewById(R.id.itemListView);
        stepListAdapter = new ActivityListingAdapter(getContext());
        stepsList.setAdapter(stepListAdapter);
        stepsDateView = rootView.findViewById(R.id.stepsDateView);
        //refresh();
        return rootView;
    }

    @Override
    public String getTitle() {
        return "Steps list";
    }


    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action.equals(ChartsHost.REFRESH)) {
            // TODO: use LimitLines to visualize smart alarms?
            //refresh();
        } else {
            super.onReceive(context, intent);
        }
    }


    @Override
    protected ChartsData refreshInBackground(ChartsHost chartsHost, DBHandler db, GBDevice device) {
        //trying to fit found peg into square hole of the Gb Charts fragment system
        //get the data
        activitySamples = getSamples(db, device);
        return null;
    }

    @Override
    protected void updateChartsnUIThread(ChartsData chartsData) {
        //top displays selected date
        stepsDateView.setText(DateTimeUtils.formatDate(new Date(tsDataFrom * 1000L)));
        //calculate active sessions
        StepAnalysis stepAnalysis = new StepAnalysis();
        if (activitySamples != null) {
            List<StepAnalysis.StepSession> stepSessions = stepAnalysis.calculateStepSessions(activitySamples);
            if (stepSessions.toArray().length == 0) {
                stepSessions = create_empty_record();
            }
            //push to the adapter
            stepListAdapter.setItems(stepSessions, true);
        }
    }

    @Override
    protected void renderCharts() {

    }

    @Override
    protected void setupLegend(Chart chart) {

    }

    @Override
    protected List<? extends ActivitySample> getSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
        Calendar day = Calendar.getInstance();
        day.setTimeInMillis(tsTo * 1000L); //we need today initially, which is the end of the time range
        day.set(Calendar.HOUR_OF_DAY, 0); //and we set time for the start and end of the same day
        day.set(Calendar.MINUTE, 0);
        day.set(Calendar.SECOND, 0);

        tsFrom = (int) (day.getTimeInMillis() / 1000);
        tsTo = tsFrom + 24 * 60 * 60 - 1;
        tsDataFrom = tsFrom;
        return getAllSamples(db, device, tsFrom, tsTo);
    }

    private List<StepAnalysis.StepSession> create_empty_record() {
        //have an "Unknown Activity" in the list in case there are no active sessions
        List<StepAnalysis.StepSession> result = new ArrayList<>();
        int tsTo = tsDataFrom + 24 * 60 * 60 - 1;
        result.add(new StepAnalysis.StepSession(new Date(tsDataFrom * 1000L), new Date(tsTo * 1000L), 0, 0, ActivityKind.TYPE_UNKNOWN));
        return result;
    }


}

{'fraction_non_alphanumeric': 0.08453303802141011, 'fraction_numerical': 0.009966777408637873, 'mean_word_length': 3.141001146350783, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6445798', 'n_tokens_mistral': 3097, 'n_tokens_neox': 2943, 'n_words': 870}