Skip to content

Commit

Permalink
All-Time Stats Preview Elements (#149)
Browse files Browse the repository at this point in the history
**Describe the pull request**
- Adding in #90 

**Link to the the issue**
- #90
  • Loading branch information
Trim0500 authored Mar 27, 2024
2 parents bb20294 + 7fb3739 commit 8ba1399
Show file tree
Hide file tree
Showing 10 changed files with 312 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,17 @@
<activity android:name=".settings.SettingsActivity" />
<activity android:name=".settings.SettingsCustomLayoutListActivity" />
<activity android:name=".settings.SettingsCustomLayoutEditActivity" />
<activity android:name=".ui.aggregatedStatistics.StatisticsPreviewActivity"
android:exported="true"/>
<activity android:name=".ui.aggregatedStatistics.StatisticsActivity"
android:exported="true">
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->

<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
</activity>

<activity
android:name=".ShowErrorActivity"
android:excludeFromRecents="true"
Expand Down
79 changes: 79 additions & 0 deletions src/main/java/de/dennisguse/opentracks/Getters&Setters
Original file line number Diff line number Diff line change
@@ -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;
}

}
15 changes: 14 additions & 1 deletion src/main/java/de/dennisguse/opentracks/stats/MockupData.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<TrackStatistics> getTrackStatistics() {
List<TrackStatistics> trackStatisticsArray = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,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);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class StatisticsActivity extends AbstractActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

MockupData mockupData = new MockupData();
MockupData mockupData = (MockupData) getIntent().getSerializableExtra("data");
List<TrackStatistics> trackStatistics = mockupData.getTrackStatistics();

TextView totalDistance = findViewById(R.id.totalTrackDistId);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<MockupData> 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();

}
}
Original file line number Diff line number Diff line change
@@ -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<StatisticsPreviewAdapter.ViewHolder> {
private List<MockupData> list = new ArrayList<>();

public StatisticsPreviewAdapter(List<MockupData> 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> 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);
}
}
}
10 changes: 10 additions & 0 deletions src/main/res/drawable/stats_item_border.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners
android:radius="2dp"
android:topRightRadius="0dp"
android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp" />
<stroke
android:width="1dp"
android:color="@android:color/darker_gray"/>
</shape>
42 changes: 42 additions & 0 deletions src/main/res/layout/stats_preview.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp"
android:orientation="vertical"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="1dp">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/seasonPreviews"
android:layout_width="409dp"
android:layout_height="600dp">

</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>

<TextView
android:id="@+id/SkiTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="129dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="129dp"
android:text="Seasons"
android:textAlignment="center"
android:textColor="#A43F20"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.517"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Ski Season Stats" />

</androidx.constraintlayout.widget.ConstraintLayout>
36 changes: 36 additions & 0 deletions src/main/res/layout/stats_preview_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/statsPreviewItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="-1dp"
android:background="@drawable/stats_item_border"
android:orientation="horizontal"
android:paddingTop="0dp"
android:paddingBottom="0dp">

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/stats_item_border"
android:orientation="vertical">

<TextView
android:id="@+id/seasonPreviewData"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="15dp"
android:text="SEASON"
android:textSize="24sp" />

<TextView
android:id="@+id/seasonPreview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="15dp"
android:text="0 days | 0m | 0 runs" />
</LinearLayout>

</LinearLayout>

0 comments on commit 8ba1399

Please sign in to comment.