Skip to content

Commit

Permalink
Changed layout of MainPage. Added workout filter for MainPage.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrescher2006 committed Jul 11, 2018
1 parent 3138c0d commit f3a25dd
Show file tree
Hide file tree
Showing 20 changed files with 519 additions and 343 deletions.
4 changes: 3 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ This application orginates from a fork of Rena by Simoma: https://github.com/Sim

Credits go to:
- Messagebox: Kimmo Lindholm, https://github.com/kimmoli/paint/blob/master/qml/components/Messagebox.qml
- Localization: Caballlero, atlochowski, eson57, niemisenjussi
- Filtered ListView: https://github.com/oKcerG/SortFilterProxyModel
- Localization: Caballlero, atlochowski, eson57, niemisenjussi, martonmiklos, d9h20f, carmenfdezb
- Sports-Tracker support: niemisenjussi
- Strava support: piggz

Workout icons are from here: https://de.icons8.com/ They are under this license: https://creativecommons.org/licenses/by-nd/3.0/
Filtered ListView is under MIT license: https://github.com/oKcerG/SortFilterProxyModel/blob/master/LICENSE

License: GNU General Public License (GNU GPLv3)

Expand Down
Binary file added qml/img/circle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added qml/img/trophy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
201 changes: 149 additions & 52 deletions qml/pages/MainPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ Page
allowedOrientations: settings.recordPagePortrait ? Orientation.Portrait : Orientation.All

property bool bLockFirstPageLoad: true
property bool bLockOnCompleted : true;
property int iLoadFileGPX: 0
property int iGPXFiles: 100
property bool bLoadingFiles: false

property string sWorkoutDuration: ""
property string sWorkoutDistance: ""
property string sWorkoutCount: ""

property int iCurrentWorkout: 0

Expand All @@ -45,6 +47,24 @@ Page
id: trackLoader
}

function fncSetWorkoutFilter()
{
sWorkoutDistance = (settings.measureSystem === 0) ? (SharedResources.arrayLookupWorkoutFilterMainPageTableByName[settings.workoutTypeMainPage].iDistance/1000).toFixed(2) + "km" : JSTools.fncConvertDistanceToImperial(SharedResources.arrayLookupWorkoutTableByName[settings.workoutTypeMainPage].iDistance/1000).toFixed(2) + "mi";

var iDuration = SharedResources.arrayLookupWorkoutFilterMainPageTableByName[settings.workoutTypeMainPage].iDuration;
iDuration = Math.floor(iDuration);
var hours = iDuration / (60*60);
hours = Math.floor(hours);
var minutes = (iDuration - hours*60*60) / 60;
minutes = Math.floor(minutes);
var seconds = iDuration - hours*60*60 - minutes*60;
seconds = Math.floor(seconds);

sWorkoutDuration = (JSTools.fncPadZeros(hours, 2)).toString() + "h " + (JSTools.fncPadZeros(minutes, 2)).toString() + "m " + (JSTools.fncPadZeros(seconds, 2)).toString() + "s";

sWorkoutCount = (SharedResources.arrayLookupWorkoutFilterMainPageTableByName[settings.workoutTypeMainPage].iWorkouts).toString();
}

function fncCheckAutosave()
{

Expand Down Expand Up @@ -116,6 +136,7 @@ Page
//This is loaded only the first time the page is displayed
if (status === PageStatus.Active && bLockFirstPageLoad)
{
bLockOnCompleted = true;
bLockFirstPageLoad = false;
console.log("First Active MainPage");

Expand Down Expand Up @@ -160,12 +181,14 @@ Page
bPebbleConnected = id_PebbleWatchComm.isConnected();
}

//Set workout filter image and combobox
imgWorkoutImage.source = SharedResources.arrayLookupWorkoutFilterMainPageTableByName[settings.workoutTypeMainPage].icon;
cmbWorkoutFilter.currentIndex = SharedResources.arrayWorkoutTypesFilterMainPage.map(function(e) { return e.name; }).indexOf(settings.workoutTypeMainPage);

//On start of App load acceleration array file
id_HistoryModel.loadAccelerationFile();
//Check if there are more GPX files and add those files to the m_trackList array
//id_HistoryModel.readDirectory();
//Go through trackList array and load all GPX files which have ready==false
//id_HistoryModel.loadAllTracks();

bLockOnCompleted = false;
}

//This is loaded everytime the page is displayed
Expand Down Expand Up @@ -207,27 +230,44 @@ Page
target: id_HistoryModel
onSigLoadingFinished: //This is called from C++ if the loading of the GPX files is ready
{
console.log("Workout rowCount: " + id_HistoryModel.rowCount());
console.log("Workout distance: " + id_HistoryModel.rDistance());
console.log("Workout duration: " + id_HistoryModel.iDuration());
//console.log("Workout rowCount: " + id_HistoryModel.rowCount());

sWorkoutDuration = id_HistoryModel.sDuration();
//Reset model for ListView
historyList.model = undefined;
//Set new model for ListView from c++
historyList.model = id_HistoryModel;

if (settings.measureSystem === 0)
sWorkoutDistance = (id_HistoryModel.rDistance() / 1000).toFixed(1);
else
sWorkoutDistance = (JSTools.fncConvertDistanceToImperial(id_HistoryModel.rDistance()/1000)).toFixed(1);
var sWorkoutCurrent, fDistanceCurrent, iDurationCurrent
//Go through all workouts
for (var i = 0; i < id_HistoryModel.rowCount(); i++)
{
sWorkoutCurrent = id_HistoryModel.workouttypeAt(i);
iDurationCurrent = id_HistoryModel.durationAt(i);
fDistanceCurrent = id_HistoryModel.distanceAt(i);

historyList.model = undefined;
historyList.model = id_HistoryModel;
//console.log("workout: " + sWorkoutCurrent + ", duration : " + iDurationCurrent + ", distance: " + fDistanceCurrent);

if (sWorkoutCurrent === "" || iDurationCurrent === 0 || fDistanceCurrent === 0)
continue;

SharedResources.arrayLookupWorkoutFilterMainPageTableByName[sWorkoutCurrent].iDistance = SharedResources.arrayLookupWorkoutFilterMainPageTableByName[sWorkoutCurrent].iDistance + fDistanceCurrent;
SharedResources.arrayLookupWorkoutFilterMainPageTableByName[sWorkoutCurrent].iDuration = SharedResources.arrayLookupWorkoutFilterMainPageTableByName[sWorkoutCurrent].iDuration + iDurationCurrent;
SharedResources.arrayLookupWorkoutFilterMainPageTableByName[sWorkoutCurrent].iWorkouts++;

SharedResources.arrayLookupWorkoutFilterMainPageTableByName["allworkouts"].iDistance = SharedResources.arrayLookupWorkoutFilterMainPageTableByName["allworkouts"].iDistance + fDistanceCurrent;
SharedResources.arrayLookupWorkoutFilterMainPageTableByName["allworkouts"].iDuration = SharedResources.arrayLookupWorkoutFilterMainPageTableByName["allworkouts"].iDuration + iDurationCurrent;
SharedResources.arrayLookupWorkoutFilterMainPageTableByName["allworkouts"].iWorkouts++;
}

fncSetWorkoutFilter();

bLoadingFiles = false;

fncCheckAutosave();
}
onDataChanged: //This is called from C++ if the loading of one GPX file is ready
{
console.log("Track loading finished!!!");
//console.log("Track loading finished!!!");
iLoadFileGPX++;
}
onSigAmountGPXFiles:
Expand Down Expand Up @@ -296,65 +336,144 @@ Page
PageHeader
{
id: pageHeader
title: qsTr("Welcome to Laufhelden")
title: "Laufhelden"
}

Item
{
id: itmMainHeaderArea
width: parent.width
height: (mainPage.height - pageHeader.height) / 4
//color: "red"

Row
Item
{
width: parent.width
height: parent.height / 3
visible: !bLoadingFiles

Image
{
id: imgWorkoutImage
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
height: parent.width / 14
width: parent.width / 14
fillMode: Image.PreserveAspectFit
}
ComboBox
{
id: cmbWorkoutFilter
//width: (parent.width / 20) * 19
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
label: qsTr("Filter:")
menu: ContextMenu
{
Repeater
{
id: idRepeaterFilterWorkout
model: SharedResources.arrayWorkoutTypesFilterMainPage;
MenuItem { text: modelData.labeltext }
}
}
onCurrentItemChanged:
{
if (bLockOnCompleted)
return;

imgWorkoutImage.source = SharedResources.arrayWorkoutTypesFilterMainPage[currentIndex].icon;
settings.workoutTypeMainPage = SharedResources.arrayWorkoutTypesFilterMainPage[currentIndex].name;

fncSetWorkoutFilter();
}
}
}
Item
{
anchors.bottom: parent.bottom
width: parent.width
height: (parent.height / 3) *2
visible: !bLoadingFiles

Item
{
width: parent.width / 2
width: parent.height
height: parent.height

Label
{
id: id_LBL_WorkoutCount
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.topMargin: 32
text: historyList.count === 0 ? qsTr("No earlier workouts") : sWorkoutCount;
font.pixelSize: 42
}
Label
{
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.bottomMargin: 32
text: qsTr("workouts")
font.pixelSize: 26
}

Image
{
anchors.fill: parent
source: "../img/circle.png"
}
}
Item
{
width: parent.width - parent.height
height: parent.height / 2
anchors.top: parent.top
anchors.left: parent.left
anchors.leftMargin: parent.height

Image
{
source: "../img/length.png"
height: parent.height
width: parent.height
anchors.leftMargin: Theme.paddingSmall
anchors.leftMargin: Theme.paddingLarge
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
}
Label
{
anchors.left: parent.left
anchors.leftMargin: parent.height + Theme.paddingMedium
anchors.leftMargin: parent.height + Theme.paddingLarge + Theme.paddingSmall
anchors.verticalCenter: parent.verticalCenter
x: Theme.paddingLarge
truncationMode: TruncationMode.Fade
text: (settings.measureSystem === 0) ? sWorkoutDistance + "km" : sWorkoutDistance + "mi"
text: sWorkoutDistance
color: Theme.highlightColor
}
}
Item
{
width: parent.width / 2
height: parent.height
width: parent.width - parent.height
height: parent.height / 2
anchors.top: parent.top
anchors.topMargin: parent.height / 2
anchors.left: parent.left
anchors.leftMargin: parent.height

Image
{
id: idIMGTime
source: "../img/time.png"
height: parent.height
width: parent.height
anchors.leftMargin: Theme.paddingLarge
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
}
Label
{
anchors.left: parent.left
anchors.leftMargin: parent.height + Theme.paddingMedium
anchors.leftMargin: parent.height + Theme.paddingLarge + Theme.paddingSmall
anchors.verticalCenter: parent.verticalCenter
x: Theme.paddingLarge
truncationMode: TruncationMode.Fade
Expand All @@ -364,18 +483,6 @@ Page
}
}

Label
{
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.bottomMargin: Theme.paddingSmall
id: id_LBL_WorkoutCount
truncationMode: TruncationMode.Fade
text: historyList.count === 0 ? qsTr("No earlier workouts") : qsTr("Workouts: ") + (historyList.count).toString();
color: Theme.highlightColor
visible: !bLoadingFiles
}

ProgressBar
{
id: progressBarWaitLoadGPX
Expand All @@ -385,18 +492,7 @@ Page
label: qsTr("Loading GPX files...")
value: iLoadFileGPX
visible: bLoadingFiles
}

Separator
{
color: Theme.highlightColor
anchors
{
left: parent.left
right: parent.right
bottom: parent.bottom
}
}
}
}

SilicaListView
Expand All @@ -405,6 +501,7 @@ Page
height: ((mainPage.height - pageHeader.height) / 4) * 3
id: historyList
model: id_HistoryModel
clip: true

delegate: ListItem
{
Expand All @@ -417,6 +514,7 @@ Page
{
text: qsTr("Remove workout")
onClicked: remorseAction(qsTr("Removing workout..."), listItem.deleteTrack)

}
MenuItem
{
Expand Down Expand Up @@ -473,7 +571,6 @@ Page
id_HistoryModel.removeTrack(index);
}


Image
{
id: workoutImage
Expand All @@ -492,7 +589,7 @@ Page
anchors.top: parent.top
truncationMode: TruncationMode.Fade
text: name==="" ? qsTr("(Unnamed track)") : name
color: listItem.highlighted ? Theme.highlightColor : Theme.primaryColor
color: listItem.highlighted ? Theme.highlightColor : Theme.primaryColor
}
Label
{
Expand Down
Loading

0 comments on commit f3a25dd

Please sign in to comment.