Skip to content

Commit

Permalink
Merge pull request #78 from Picard4/main
Browse files Browse the repository at this point in the history
Accepting main changes
  • Loading branch information
Picard4 authored Apr 28, 2024
2 parents 189dee8 + 876e946 commit 91e5597
Show file tree
Hide file tree
Showing 34 changed files with 1,817 additions and 216 deletions.
10 changes: 0 additions & 10 deletions .idea/migrations.xml

This file was deleted.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.2.2'
classpath 'com.google.gms:google-services:4.4.1'
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 @@ -33,6 +33,7 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!-- <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> -->
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission
android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
Expand Down Expand Up @@ -66,7 +67,8 @@
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/OpenTracksTheme">
android:theme="@style/OpenTracksTheme"
android:requestLegacyExternalStorage="true">
<activity
android:name=".ui.aggregatedStatistics.dailyStats.DailyStatsActivity"
android:exported="false" />
Expand Down Expand Up @@ -391,6 +393,8 @@
<activity
android:name=".SeasonalActivity"
android:exported="false" />
<activity android:name=".TrackViewGearActivity"
android:exported="false" />
<provider
android:name=".data.ShareContentProvider"
android:authorities="${applicationId}.content"
Expand Down
49 changes: 29 additions & 20 deletions src/main/java/de/dennisguse/opentracks/SeasonalActivity.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
package de.dennisguse.opentracks;

import static android.app.PendingIntent.getActivity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.chrono.ChronoLocalDate;
import java.util.List;

import de.dennisguse.opentracks.data.TrackSelection;
import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.databinding.ActivitySeasonalBinding;
import de.dennisguse.opentracks.ui.aggregatedStatistics.StatisticsActivity;
import de.dennisguse.opentracks.ui.aggregatedStatistics.AggregatedStatisticsAdapter;
import de.dennisguse.opentracks.ui.aggregatedStatistics.AggregatedStatisticsModel;

import static android.app.PendingIntent.getActivity;

import android.os.Bundle;


/**
Expand All @@ -22,44 +30,45 @@
* @author Woo Jun Ann, Zachary Therrien
* */
public class SeasonalActivity extends AbstractActivity {
public static final String EXTRA_TRACK_IDS = "track_ids";
private final TrackSelection selection = new TrackSelection();
private ActivitySeasonalBinding viewBinding;
private AggregatedStatisticsModel viewModel;
private AggregatedStatisticsAdapter adapter;
private RecyclerView seasonsRecyclerView;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("Seasonal Activity!");
setTitle("Seasonal Activity");
seasonsRecyclerView = findViewById(R.id.seasons_recyclerView);

GoToIndividualSite(findViewById(R.id.activity_game_answer1_btn));
GoToIndividualSite(findViewById(R.id.activity_game_answer2_btn));
GoToAllTimeStats(findViewById(R.id.activity_game_answer3_btn));
GoToIndividualSite(findViewById(R.id.Winter2022_Button));
GoToIndividualSite(findViewById(R.id.Winter2023_Button));
GoToIndividualSite(findViewById(R.id.Winter2024_Button));
GoToAllTimeStats(findViewById(R.id.LifeTime_button));

setSupportActionBar(viewBinding.bottomAppBarLayout.bottomAppBar);
}

private void GoToIndividualSite(Button button)
{
button.setOnClickListener(view ->
{
private void GoToIndividualSite(Button button) {
button.setOnClickListener(view -> {
Intent intent = new Intent(SeasonalActivity.this, SeasonalActivityPerSeason.class);
intent.putExtra("seasonTitle", button.getText());
startActivity(intent);
});
}

private void GoToAllTimeStats(Button button) {
button.setOnClickListener(view ->
{
Intent intent = new Intent(SeasonalActivity.this, StatisticsActivity.class);
button.setOnClickListener(view -> {
Intent intent = new Intent(SeasonalActivity.this, SeasonalActivityPerSeason.class);
intent.putExtra("seasonTitle", button.getText());
startActivity(intent);
});
}

@Override
protected View getRootView()
{
protected View getRootView() {
viewBinding = ActivitySeasonalBinding.inflate(getLayoutInflater());
return viewBinding.getRoot();
}
Expand Down
102 changes: 78 additions & 24 deletions src/main/java/de/dennisguse/opentracks/SeasonalActivityPerSeason.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,117 @@
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toolbar;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.google.android.material.appbar.MaterialToolbar;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Objects;

import de.dennisguse.opentracks.data.TrackSelection;
import de.dennisguse.opentracks.databinding.ActivitySeasonalBinding;
import de.dennisguse.opentracks.databinding.ActivitySeasonalPerSeasonBinding;
import de.dennisguse.opentracks.ui.aggregatedStatistics.AggregatedStatisticsAdapter;
import de.dennisguse.opentracks.ui.aggregatedStatistics.AggregatedStatisticsModel;
import de.dennisguse.opentracks.ui.aggregatedStatistics.DummyDataGenerator;
import de.dennisguse.opentracks.ui.aggregatedStatistics.FilterDialogFragment;

public class SeasonalActivityPerSeason extends AbstractActivity
{
public class SeasonalActivityPerSeason extends AbstractActivity {
private final TrackSelection selection = new TrackSelection();
private AggregatedStatisticsModel viewModel;
private AggregatedStatisticsAdapter adapter;
private ActivitySeasonalPerSeasonBinding viewBinding;
private LocalDateTime from;
private LocalDateTime to;
@Override
protected void onCreate(Bundle savedInstanceState)
{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

EdgeToEdge.enable(this);
setContentView(R.layout.activity_seasonal_per_season);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});

Bundle data = getIntent().getExtras();

if (data != null)
{
changeTitle(data.getString("seasonTitle"));
}

LinearLayoutManager layoutManager = new LinearLayoutManager(this);
adapter = new AggregatedStatisticsAdapter(this, null);
viewBinding.aggregatedRecyclerView.setLayoutManager(layoutManager);
viewBinding.aggregatedRecyclerView.setAdapter(adapter);
viewModel = new ViewModelProvider(this).get(AggregatedStatisticsModel.class);
selection.addActivityType("skiing");

if(data != null && !Objects.equals(data.getString("seasonTitle"), getResources().getString(R.string.Life_Time_Data))){
setFromToDate(data.getString("seasonTitle"));
selection.addDateRange(from.atZone(ZoneId.systemDefault()).toInstant(), to.atZone(ZoneId.systemDefault()).toInstant());
viewModel.updateSelection(selection);
}

viewModel.getAggregatedStats(selection).observe(this, aggregatedStatistics -> {
if (aggregatedStatistics != null) {
adapter.swapData(aggregatedStatistics);
}
checkListEmpty();
});

setSupportActionBar(viewBinding.bottomAppBarLayout.bottomAppBar);
}

private void checkListEmpty() {
if (adapter.getItemCount() == 0) {
viewBinding.aggregatedRecyclerView.setVisibility(View.GONE);
viewBinding.seasonPerSeasonEmptyText.setVisibility(View.VISIBLE);
} else {
viewBinding.aggregatedRecyclerView.setVisibility(View.VISIBLE);
viewBinding.seasonPerSeasonEmptyText.setVisibility(View.GONE);
}
}
private void MakeYesNoButton(Button button)
{

private void MakeYesNoButton(Button button) {
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle("Heading to " + button.getText()).setMessage("Is this okay?")
.setPositiveButton("Yes", (dialogInterface, i) -> {
// Do stuff
})
.setNegativeButton("No", (dialogInterface, i) -> dialogInterface.cancel());
}
private void changeTitle(String newTitle)
{
newTitle = newTitle.replaceAll("_", " ");
setContentView(R.layout.activity_seasonal_per_season);
TextView tv = (TextView)findViewById(R.id.pageTitle);
tv.setText(newTitle);
tv.setTextSize(32);

private void changeTitle(String newTitle) {
MaterialToolbar materialToolbar = (MaterialToolbar)findViewById(R.id.season_materialtoolbar);
materialToolbar.setTitle(newTitle);
}

@Override
protected View getRootView()
{
protected View getRootView() {
viewBinding = ActivitySeasonalPerSeasonBinding.inflate(getLayoutInflater());
return viewBinding.getRoot();
}

private void setFromToDate(String title){
if(Objects.equals(title, getResources().getString(R.string.Winter_2024))){
from = LocalDateTime.of(2024, 1, 1, 0, 0);
to = LocalDateTime.of(2024, 4, 8, 23, 59);
}
else if(Objects.equals(title, getResources().getString(R.string.Winter_2023))){
from = LocalDateTime.of(2023, 1, 1, 0, 0);
to = LocalDateTime.of(2023, 4, 8, 23, 59);
}
else if(Objects.equals(title, getResources().getString(R.string.Winter_2022))){
from = LocalDateTime.of(2022, 1, 1, 0, 0);
to = LocalDateTime.of(2022, 4, 8, 23, 59);
}
}
}
4 changes: 4 additions & 0 deletions src/main/java/de/dennisguse/opentracks/TrackEditActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ protected void onCreate(Bundle bundle) {
activityType = track.getActivityType();
}

if (activityType != ActivityType.SKIING) {
viewBinding.fields.trackEditGear.setVisibility(View.INVISIBLE);
}

setActivityTypeIcon(activityType);
viewBinding.fields.trackEditActivityTypeIcon.setOnClickListener(v -> ChooseActivityTypeDialogFragment.showDialog(getSupportFragmentManager(), this, viewBinding.fields.trackEditActivityType.getText().toString()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ protected void onCreate(Bundle savedInstanceState) {
viewBinding.friendsButton.setOnClickListener((view)->startActivity(IntentUtils.newIntent(this, FriendsActivity.class)));
viewBinding.profileButton.setOnClickListener((view)->startActivity(IntentUtils.newIntent(this, ProfileActivity.class)));
viewBinding.aggregatedStatsButton.setOnClickListener((view) -> startActivity(IntentUtils.newIntent(this, AggregatedStatisticsActivity.class)));
viewBinding.aggregatedSeasonalStatsButton.setOnClickListener((view) -> startActivity(IntentUtils.newIntent(this, SeasonalActivity.class)));
viewBinding.gearButton.setOnClickListener((view) -> startActivity(IntentUtils.newIntent(this, TrackViewGearActivity.class)));
viewBinding.leaderboardButton.setOnClickListener((view) -> startActivity(IntentUtils.newIntent(this, LeaderboardActivity.class)));
viewBinding.sensorStartButton.setOnClickListener((view) -> {
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/de/dennisguse/opentracks/TrackStoppedActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import java.util.UUID;

import java.util.UUID;

import de.dennisguse.opentracks.data.ContentProviderUtils;
import de.dennisguse.opentracks.data.interfaces.JSONSerializable;
import de.dennisguse.opentracks.data.models.ActivityType;
Expand Down Expand Up @@ -56,6 +58,21 @@ protected void onCreate(Bundle savedInstanceState) {
ContentProviderUtils contentProviderUtils = new ContentProviderUtils(this);
Track track = contentProviderUtils.getTrack(trackId);

//Temporary code to illustrate JSON serialization and loading of Track model
//TODO! - Remove
//Assignee - Jean Robatto

// final String JSON_SERIALIZER_LOG_TAG = "JSONSerializerTest";
//
// final String trackJSONString = track.toJSON();
// Log.i(JSON_SERIALIZER_LOG_TAG, trackJSONString);
//
// final Track trackCopy = JSONSerializable.fromJSON(trackJSONString, Track.class);
// Log.i(JSON_SERIALIZER_LOG_TAG, trackCopy.toString());
// Log.i(JSON_SERIALIZER_LOG_TAG, trackCopy.getName());

//End

viewBinding.trackEditName.setText(track.getName());

viewBinding.trackEditActivityType.setText(track.getActivityTypeLocalized());
Expand Down Expand Up @@ -117,7 +134,13 @@ private void storeTrackMetaData(ContentProviderUtils contentProviderUtils, Track

//Save run on the external DB
//NOTE - The UI should be augmented to display success/failure to the user
FirestoreCRUDUtil.getInstance().createEntry(CRUDConstants.RUNS_TABLE, track.getUuid().toString(), track.toJSON(), null);
//TODO: The next line should not be commented out
//FirestoreCRUDUtil.getInstance().createEntry(CRUDConstants.RUNS_TABLE, track.getUuid().toString(), track.toJSON(), null);

//Save run on the external DB
//NOTE - The UI should be augmented to display success/failure to the user
//TODO: The next line should not be commented out
//FirestoreCRUDUtil.getInstance().createEntry(CRUDConstants.RUNS_TABLE, track.getUuid().toString(), track.toJSON(), null);

TrackUtils.updateTrack(TrackStoppedActivity.this, track, viewBinding.trackEditName.getText().toString(),
viewBinding.trackEditActivityType.getText().toString(), viewBinding.trackEditDescription.getText().toString(),
Expand Down
Loading

0 comments on commit 91e5597

Please sign in to comment.