Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull Request to Push Resolved Issue #77 Implementations to Main Branch #164

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.2.2'
classpath 'com.android.tools.build:gradle:8.3.1'
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
android:exported="false"
android:label="@string/title_activity_leaderboard"
android:theme="@style/OpenTracksTheme.NoActionBar" />
<activity
android:name=".ui.menuStatistics.MenuStatisticsActivity"
android:exported="false" />
<activity
android:name=".settings.MaintenanceInfo"
android:exported="true" />
Expand Down Expand Up @@ -369,7 +372,8 @@
android:launchMode="singleInstance"
android:process=":crash" />
<activity android:name=".ui.aggregatedStatistics.StatisticsActivity"
android:exported="true">
android:exported="true"
tools:ignore="DuplicateActivity">
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@
import de.dennisguse.opentracks.settings.SettingsActivity;
import de.dennisguse.opentracks.share.ShareUtils;
import de.dennisguse.opentracks.ui.aggregatedStatistics.ConfirmDeleteDialogFragment;
import de.dennisguse.opentracks.ui.aggregatedStatistics.dailyStats.DailyStatsActivity;
import de.dennisguse.opentracks.ui.intervals.IntervalsFragment;
import de.dennisguse.opentracks.ui.markers.MarkerListActivity;
import de.dennisguse.opentracks.ui.menuStatistics.MenuStatisticsActivity;
import de.dennisguse.opentracks.util.IntentDashboardUtils;
import de.dennisguse.opentracks.util.IntentUtils;

Expand Down Expand Up @@ -212,6 +214,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
return true;
}

if (item.getItemId() == R.id.filter) {
startActivity(IntentUtils.newIntent(this, MenuStatisticsActivity.class));
return true;
}

if (item.getItemId() == R.id.track_detail_menu_show_on_map) {
IntentDashboardUtils.showTrackOnMap(this, false, trackId);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import de.dennisguse.opentracks.services.handlers.GpsStatusValue;
import de.dennisguse.opentracks.settings.PreferencesUtils;
import de.dennisguse.opentracks.settings.SettingsActivity;
import de.dennisguse.opentracks.ui.menuStatistics.MenuStatisticsActivity;
import de.dennisguse.opentracks.ui.intervals.IntervalsFragment;
import de.dennisguse.opentracks.ui.markers.MarkerEditActivity;
import de.dennisguse.opentracks.ui.markers.MarkerListActivity;
Expand Down Expand Up @@ -267,6 +268,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
return true;
}

if (item.getItemId() == R.id.filter) {
startActivity(IntentUtils.newIntent(this, MenuStatisticsActivity.class));
return true;
}

if (item.getItemId() == R.id.track_detail_insert_marker) {
Intent intent = IntentUtils
.newIntent(this, MarkerEditActivity.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,34 @@ public List<Track> getTracks() {
return tracks;
}

//Returns list of tracks done within a given period of time
public List<Track> getTracks(Instant startTime, Instant endTime) {
// Convert the Instant objects to milliseconds since epoch
long startTimeMillis = startTime.toEpochMilli();
long endTimeMillis = endTime.toEpochMilli();

// Define the selection and selectionArgs for the query
String selection = TracksColumns.STARTTIME + " >= ? AND " + TracksColumns.STOPTIME + " <= ?";
String[] selectionArgs = new String[] { String.valueOf(startTimeMillis), String.valueOf(endTimeMillis) };

// Query the database for tracks within the time period
Cursor cursor = contentResolver.query(TracksColumns.CONTENT_URI, null, selection, selectionArgs, null);

// Create a list to hold the resulting tracks
List<Track> tracks = new ArrayList<>();

// Iterate over the results and create Track objects
if (cursor != null) {
while (cursor.moveToNext()) {
Track track = createTrack(cursor);
tracks.add(track);
}
cursor.close();
}

return tracks;
}

public List<Track> getTracks(ContentProviderSelectionInterface selection) {
SelectionData selectionData = selection.buildSelection();
ArrayList<Track> tracks = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import android.widget.Spinner;

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


import de.dennisguse.opentracks.R;
import de.dennisguse.opentracks.AbstractActivity;
import de.dennisguse.opentracks.databinding.DailyStatsBinding;
Expand All @@ -26,16 +24,16 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Create and populate the spin_metrics spinner with Metric enums.
Spinner spin_metrics = (Spinner)findViewById(R.id.daily_metric);
Spinner spin_metrics = findViewById(R.id.daily_metric);
ArrayAdapter<Metric> array_metrics = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, Metric.values());
spin_metrics.setAdapter(array_metrics);

// Create and populate the spin_freq spinner with Metric enums.
Spinner spin_freq = (Spinner)findViewById(R.id.daily_data_point);
Spinner spin_freq = findViewById(R.id.daily_data_point);
ArrayAdapter<Frequency> array_freq = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, Frequency.values());
spin_freq.setAdapter(array_freq);

line_chart = (LineChart) findViewById(R.id.dailyChart);
line_chart = findViewById(R.id.dailyChart);

// Attach one listener to both spinners
spin_metrics.setOnItemSelectedListener(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package de.dennisguse.opentracks.ui.menuStatistics;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;

import de.dennisguse.opentracks.R;

// This is an enum class named GraphChoice.
public enum GraphChoice {
// These are the enum constants and each has a display name and a drawable resource associated with it.
DAY("Day", R.drawable.baseline_today_24),
WEEK("Week", R.drawable.baseline_calendar_view_week_24),
MONTH("Month", R.drawable.baseline_calendar_month_24),
SEASON("Season", R.drawable.baseline_season_24);

// This is a private final field for the display name of the enum constant.
private final String displayName;
// This is a private final field for the drawable resource of the enum constant.
@DrawableRes
private final int drawableRes;

// This is the constructor for the enum constants.
GraphChoice(String displayName, @DrawableRes int drawableRes) {
this.displayName = displayName;
this.drawableRes = drawableRes;
}

// This method overrides the toString method and returns the display name of the enum constant.
@NonNull
@Override
public String toString() {
return displayName;
}

// This method returns the drawable resource of the enum constant.
@DrawableRes
public int getDrawableRes() {
return drawableRes;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package de.dennisguse.opentracks.ui.menuStatistics;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;

// This class is an ArrayAdapter for GraphChoice objects.
public class GraphChoiceAdapter extends ArrayAdapter<GraphChoice> {

// Constructor for the GraphChoiceAdapter class.
public GraphChoiceAdapter(Context context, GraphChoice[] choices) {
super(context, 0, choices);
}

// This method is used to provide a view for the dropdown menu.
@Override
public View getDropDownView(int position, View convertView, @NonNull ViewGroup parent) {
return createViewFromResource(position, convertView, parent);
}

// This method is used to provide a view for the adapter.
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
return createViewFromResource(position, convertView, parent);
}

// This method is used to create a view from the given resource.
private View createViewFromResource(int position, View convertView, ViewGroup parent) {
View view;
// If convertView is null, inflate a new view.
if (convertView == null) {
view = LayoutInflater.from(getContext()).inflate(android.R.layout.simple_spinner_item, parent, false);
} else {
// Otherwise, reuse the convertView.
view = convertView;
}

// Get the GraphChoice item for the current position.
GraphChoice choice = getItem(position);
// Find the TextView in the view.
TextView textView = view.findViewById(android.R.id.text1);
// Set the text of the TextView to the string representation of the GraphChoice item.
assert choice != null;
textView.setText(choice.toString());
// Set the drawable for the TextView.
textView.setCompoundDrawablesWithIntrinsicBounds(choice.getDrawableRes(), 0, 0, 0);
// Set the padding for the drawable.
int padding = (int) (10 * getContext().getResources().getDisplayMetrics().density);
textView.setCompoundDrawablePadding(padding);

// Return the view.
return view;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.dennisguse.opentracks.ui.menuStatistics;

import com.github.mikephil.charting.formatter.ValueFormatter;
import java.util.Locale;

// This class extends the ValueFormatter class from the MPAndroidChart library.
public class IntegerValueFormatter extends ValueFormatter {

// This method overrides the getFormattedValue method of the ValueFormatter class.
@Override
public String getFormattedValue(float value) {
// It formats the float value as an integer string using the default locale.
// The float value is first cast to an integer before formatting.
return String.format(Locale.getDefault(), "%d", (int) value);
}
}
Loading