From 714b6c4dd90506ed572d21b6d0407b6e8bc55a29 Mon Sep 17 00:00:00 2001 From: hadiwehbi10 <99916477+hadiwehbi10@users.noreply.github.com> Date: Mon, 25 Mar 2024 15:24:14 -0400 Subject: [PATCH 1/3] Create Getters&Setters These are created for Storing user maintenance data --- .../de/dennisguse/opentracks/Getters&Setters | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/main/java/de/dennisguse/opentracks/Getters&Setters diff --git a/src/main/java/de/dennisguse/opentracks/Getters&Setters b/src/main/java/de/dennisguse/opentracks/Getters&Setters new file mode 100644 index 000000000..755466ec3 --- /dev/null +++ b/src/main/java/de/dennisguse/opentracks/Getters&Setters @@ -0,0 +1,79 @@ +import java.time.LocalDate; + +public class UserMaintenanceData { + private int sharpeningInterval; + private double baseAngle; + private double edgeAngle; + private LocalDate lastSharpeningDate; + private int waxingInterval; + private String waxType; + private LocalDate lastWaxingDate; + + // Constructor + public UserMaintenanceData(int sharpeningInterval, double baseAngle, double edgeAngle, LocalDate lastSharpeningDate, int waxingInterval, String waxType, LocalDate lastWaxingDate) { + this.sharpeningInterval = sharpeningInterval; + this.baseAngle = baseAngle; + this.edgeAngle = edgeAngle; + this.lastSharpeningDate = lastSharpeningDate; + this.waxingInterval = waxingInterval; + this.waxType = waxType; + this.lastWaxingDate = lastWaxingDate; + } + + // Getters and Setters + public int getSharpeningInterval() { + return sharpeningInterval; + } + + public void setSharpeningInterval(int sharpeningInterval) { + this.sharpeningInterval = sharpeningInterval; + } + + public double getBaseAngle() { + return baseAngle; + } + + public void setBaseAngle(double baseAngle) { + this.baseAngle = baseAngle; + } + + public double getEdgeAngle() { + return edgeAngle; + } + + public void setEdgeAngle(double edgeAngle) { + this.edgeAngle = edgeAngle; + } + + public LocalDate getLastSharpeningDate() { + return lastSharpeningDate; + } + + public void setLastSharpeningDate(LocalDate lastSharpeningDate) { + this.lastSharpeningDate = lastSharpeningDate; + } + + public int getWaxingInterval() { + return waxingInterval; + } + + public void setWaxingInterval(int waxingInterval) { + this.waxingInterval = waxingInterval; + } +public String getWaxType() { + return waxType; + } + + public void setWaxType(String waxType) { + this.waxType = waxType; + } + + public LocalDate getLastWaxingDate() { + return lastWaxingDate; + } + + public void setLastWaxingDate(LocalDate lastWaxingDate) { + this.lastWaxingDate = lastWaxingDate; + } + +} From e8ca949ac0c20032c4d06171af1653a01d84a08f Mon Sep 17 00:00:00 2001 From: GL34 <144085043+GL34@users.noreply.github.com.> Date: Mon, 25 Mar 2024 23:13:08 -0400 Subject: [PATCH 2/3] Statistics preview page. --- src/main/AndroidManifest.xml | 9 ++- .../opentracks/stats/MockupData.java | 15 +++- .../opentracks/stats/OverallStatistics.java | 2 +- .../AggregatedStatisticsActivity.java | 2 +- .../StatisticsActivity.java | 5 +- .../StatisticsPreviewActivity.java | 40 ++++++++++ .../StatisticsPreviewAdapter.java | 78 +++++++++++++++++++ src/main/res/drawable/stats_item_border.xml | 10 +++ src/main/res/layout/stats_preview.xml | 42 ++++++++++ src/main/res/layout/stats_preview_item.xml | 36 +++++++++ 10 files changed, 229 insertions(+), 10 deletions(-) create mode 100644 src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/StatisticsPreviewActivity.java create mode 100644 src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/StatisticsPreviewAdapter.java create mode 100644 src/main/res/drawable/stats_item_border.xml create mode 100644 src/main/res/layout/stats_preview.xml create mode 100644 src/main/res/layout/stats_preview_item.xml diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 6f81de1f8..cd3d1236d 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -77,10 +77,11 @@ limitations under the License. android:supportsRtl="true" android:theme="@style/OpenTracksTheme"> - + - + + --> @@ -375,6 +376,8 @@ limitations under the License. + diff --git a/src/main/java/de/dennisguse/opentracks/stats/MockupData.java b/src/main/java/de/dennisguse/opentracks/stats/MockupData.java index 167bb1c35..739a2e117 100644 --- a/src/main/java/de/dennisguse/opentracks/stats/MockupData.java +++ b/src/main/java/de/dennisguse/opentracks/stats/MockupData.java @@ -4,10 +4,23 @@ import java.time.Instant; import java.util.ArrayList; import java.util.List; +import java.io.Serializable; import de.dennisguse.opentracks.data.models.*; -public class MockupData { +public class MockupData implements Serializable { + private int season; + public MockupData(int season){ + this.season = season; + } + + public MockupData(){ + this.season = 0; + } + + public int getSeason() { + return season; + } public List getTrackStatistics() { List trackStatisticsArray = new ArrayList<>(); diff --git a/src/main/java/de/dennisguse/opentracks/stats/OverallStatistics.java b/src/main/java/de/dennisguse/opentracks/stats/OverallStatistics.java index a02578644..c7cc388a9 100644 --- a/src/main/java/de/dennisguse/opentracks/stats/OverallStatistics.java +++ b/src/main/java/de/dennisguse/opentracks/stats/OverallStatistics.java @@ -28,7 +28,7 @@ public class OverallStatistics { // Static field that stores singleton instance private static OverallStatistics instance; - protected OverallStatistics() { + public OverallStatistics() { this.totalRunsOverall = 50; this.totalSkiDaysOverall = 25; this.totalTrackDistanceOverall = Distance.ofKilometer(500); diff --git a/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/AggregatedStatisticsActivity.java b/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/AggregatedStatisticsActivity.java index 41c91c9dd..ecbca42e5 100644 --- a/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/AggregatedStatisticsActivity.java +++ b/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/AggregatedStatisticsActivity.java @@ -79,7 +79,7 @@ protected void onCreate(Bundle savedInstanceState) { button1 = (Button) (findViewById(R.id.StatsButtonId)); button1.setOnClickListener(view -> { - Intent intent = new Intent(AggregatedStatisticsActivity.this, StatisticsActivity.class); + Intent intent = new Intent(AggregatedStatisticsActivity.this, StatisticsPreviewActivity.class); startActivity(intent); }); } diff --git a/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/StatisticsActivity.java b/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/StatisticsActivity.java index a86f72654..d49459f95 100644 --- a/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/StatisticsActivity.java +++ b/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/StatisticsActivity.java @@ -1,18 +1,15 @@ package de.dennisguse.opentracks.ui.aggregatedStatistics; import android.os.Bundle; -import android.view.View; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; import java.util.List; -import de.dennisguse.opentracks.AbstractActivity; import de.dennisguse.opentracks.R; import de.dennisguse.opentracks.stats.MockupData; import de.dennisguse.opentracks.stats.TrackStatistics; -import de.dennisguse.opentracks.databinding.StatsBinding; public class StatisticsActivity extends AppCompatActivity { @@ -22,7 +19,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.stats); - MockupData mockupData = new MockupData(); + MockupData mockupData = (MockupData) getIntent().getSerializableExtra("data"); List trackStatistics = mockupData.getTrackStatistics(); TrackStatistics summary = TrackStatistics.sumOfTotalStats(trackStatistics); TextView totalDistance = findViewById(R.id.totalTrackDistId); diff --git a/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/StatisticsPreviewActivity.java b/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/StatisticsPreviewActivity.java new file mode 100644 index 000000000..465c96170 --- /dev/null +++ b/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/StatisticsPreviewActivity.java @@ -0,0 +1,40 @@ +package de.dennisguse.opentracks.ui.aggregatedStatistics; + +import android.os.Bundle; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import java.util.ArrayList; +import java.util.List; + +import de.dennisguse.opentracks.R; +import de.dennisguse.opentracks.stats.MockupData; + +public class StatisticsPreviewActivity extends AppCompatActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.stats_preview); + + MockupData mockupData1 = new MockupData(2022); // example 2022-2023 + MockupData mockupData2 = new MockupData(2023); // example 2023-2024 + + List seasons = new ArrayList<>(); + + RecyclerView previews = findViewById(R.id.seasonPreviews); + LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); + linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); + previews.setLayoutManager(linearLayoutManager); + + StatisticsPreviewAdapter previewAdapter = new StatisticsPreviewAdapter(seasons); + previews.setAdapter(previewAdapter); + + seasons.add(mockupData1); + seasons.add(mockupData2); + + previewAdapter.notifyDataSetChanged(); + + } +} diff --git a/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/StatisticsPreviewAdapter.java b/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/StatisticsPreviewAdapter.java new file mode 100644 index 000000000..56ad7e529 --- /dev/null +++ b/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/StatisticsPreviewAdapter.java @@ -0,0 +1,78 @@ +package de.dennisguse.opentracks.ui.aggregatedStatistics; + +import android.content.Intent; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import java.util.ArrayList; +import java.util.List; + +import de.dennisguse.opentracks.R; +import de.dennisguse.opentracks.stats.MockupData; +import de.dennisguse.opentracks.stats.TrackStatistics; +public class StatisticsPreviewAdapter extends RecyclerView.Adapter { + private List list = new ArrayList<>(); + + public StatisticsPreviewAdapter(List mList){ + this.list = mList; + } + + public int getItemCount(){ + return list.size(); + } + + @NonNull + @Override + public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int position){ + + View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.stats_preview_item, viewGroup, false); + + v.setOnClickListener(new RecyclerView.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(v.getContext(), StatisticsActivity.class); + intent.putExtra("data", list.get(position)); + v.getContext().startActivity(intent); + } + }); + + return new ViewHolder(v); + } + + public void onBindViewHolder(@NonNull ViewHolder holder, int i){ + MockupData data = list.get(i); + + int year = data.getSeason(); + List trackStatistics = data.getTrackStatistics(); + TrackStatistics summary = TrackStatistics.sumOfTotalStats(trackStatistics); + + holder.previewInfo.setText(String.valueOf(year) + " - " + String.valueOf(year+1)); // TODO: do this the right way : | + + String days = String.valueOf(summary.getTotalSkiDaysSeason()); + String distance = String.valueOf(summary.getTotalDistance().toM()); + String runs = String.valueOf(summary.getTotalRunsSeason()); + + holder.season.setText(days + " days | " + distance + "m | " + runs + " runs"); + } + + @Override + public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) { + super.onAttachedToRecyclerView(recyclerView); + } + + public static class ViewHolder extends RecyclerView.ViewHolder { + TextView season; + TextView previewInfo; + + ViewHolder(@NonNull View itemView) { + super(itemView); + season = itemView.findViewById(R.id.seasonPreview); + previewInfo = itemView.findViewById(R.id.seasonPreviewData); + } + } +} diff --git a/src/main/res/drawable/stats_item_border.xml b/src/main/res/drawable/stats_item_border.xml new file mode 100644 index 000000000..e9c9db419 --- /dev/null +++ b/src/main/res/drawable/stats_item_border.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/src/main/res/layout/stats_preview.xml b/src/main/res/layout/stats_preview.xml new file mode 100644 index 000000000..206a11aa1 --- /dev/null +++ b/src/main/res/layout/stats_preview.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/res/layout/stats_preview_item.xml b/src/main/res/layout/stats_preview_item.xml new file mode 100644 index 000000000..2e7c152ae --- /dev/null +++ b/src/main/res/layout/stats_preview_item.xml @@ -0,0 +1,36 @@ + + + + + + + + + + \ No newline at end of file From 7fb3739b5982ddbf3c847d49e667e96dab2aeb38 Mon Sep 17 00:00:00 2001 From: Tristan Lafleur <70395022+Trim0500@users.noreply.github.com> Date: Wed, 27 Mar 2024 14:01:44 -0400 Subject: [PATCH 3/3] Update OverallStatistics.java --- .../java/de/dennisguse/opentracks/stats/OverallStatistics.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/dennisguse/opentracks/stats/OverallStatistics.java b/src/main/java/de/dennisguse/opentracks/stats/OverallStatistics.java index c7cc388a9..a02578644 100644 --- a/src/main/java/de/dennisguse/opentracks/stats/OverallStatistics.java +++ b/src/main/java/de/dennisguse/opentracks/stats/OverallStatistics.java @@ -28,7 +28,7 @@ public class OverallStatistics { // Static field that stores singleton instance private static OverallStatistics instance; - public OverallStatistics() { + protected OverallStatistics() { this.totalRunsOverall = 50; this.totalSkiDaysOverall = 25; this.totalTrackDistanceOverall = Distance.ofKilometer(500);