Skip to content

Commit

Permalink
Update Export screen to show more accurate log data
Browse files Browse the repository at this point in the history
This is a pretty update to how the Export screen works and how the
log data is modified.

The Export screen component was rewritten as a functional component
in order to take advantage of hooks. The use for the hooks is to
update the log data details when the Export component comes in to
focus. The old version would only update the data once since the
component would mount and never unmount leading to stale data. The
new Export component will update the log details each time the view
comes in to focus. The log details have now been broken up in to
3 sections: Total time the log covers, Number of points logged, and
Time since last updated.

The LocationService has been updated with a new class called
LocationData. This take the old saveLocation method and makes it
an instance method on the LocationData class. This also allows
access to the location data that is in memory in order for the
Export screen to show more accurate details. The LocationService
has been updated to use this new class when saving the location
data.
  • Loading branch information
thetimbanks committed Mar 27, 2020
1 parent df02c39 commit 476ac48
Show file tree
Hide file tree
Showing 14 changed files with 617 additions and 196 deletions.
94 changes: 45 additions & 49 deletions app/helpers/convertPointsToString.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,47 @@
export function convertPointsToString(count) {
// For testing Manually override count
// count = 3000

// Get minutes
let tot_mins = count * 5;

// Calculate days
let days = tot_mins / 60 / 24;
let rdays = Math.floor(days);

// Calculate Hours
let hours = (days - rdays) * 24;
let rhours = Math.floor(hours);

// Calculate Minutes
let minutes = (hours - rhours) * 60;
let rminutes = Math.round(minutes);

if (rdays > 0) {
if (rdays > 1) {
if (rhours > 1) {
return (
rdays + ' days, ' + rhours + ' hours and ' + rminutes + ' minutes.'
);
} else {
return (
rdays + ' days, ' + rhours + ' hour and ' + rminutes + ' minutes.'
);
}
} else {
if (rhours > 1) {
return (
rdays + ' day, ' + rhours + ' hours and ' + rminutes + ' minutes.'
);
} else {
return (
rdays + ' day, ' + rhours + ' hour and ' + rminutes + ' minutes.'
);
}
}
} else if (rhours > 0) {
if (rhours > 1) {
return rhours + ' hours and ' + rminutes + ' minutes.';
} else {
return rhours + ' hour and ' + rminutes + ' minutes.';
}
} else {
return rminutes + ' minutes.';
import pluralize from 'pluralize';
import languages from './../locales/languages';

export function timeSincePoint(point) {
if (!point) {
return languages.t('label.no_data');
}

const pointDays = point ? daysDifferenceFromNow(point.time) : null;
const pointHours = point ? hoursDifferenceFromNow(point.time) : null;
const pointMinutes = point ? minutesDifferenceFromNow(point.time) : null;
const pointTime = [
pointDays > 0 ? pluralize('day', pointDays, true) : null,
pointHours > 0 ? pluralize('hour', pointHours, true) : null,
pointMinutes > 0
? pluralize('minute', pointMinutes, true)
: languages.t('label.less_than_one_minute'),
]
.filter(item => item)
.join(' ');

return pointTime;
}

function daysDifferenceFromNow(timestamp) {
var difference = now() - timestamp;
var daysDifference = Math.floor(difference / 1000 / 60 / 60 / 24);
return daysDifference;
}

function hoursDifferenceFromNow(timestamp) {
var difference = now() - timestamp;
var hoursDifference = Math.floor(difference / 1000 / 60 / 60);
return hoursDifference % 24;
}

function minutesDifferenceFromNow(timestamp) {
var difference = now() - timestamp;
var minutesDifference = Math.floor(difference / 1000 / 60);

return minutesDifference % 60;
}

function now() {
let nowUTC = new Date().toISOString();
return Date.parse(nowUTC);
}
9 changes: 7 additions & 2 deletions app/locales/de/exportscreen.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
"export_para_1":"You can share your location trail with anyone using the Share button below. Once you press the button it will ask you with whom and how you want to share it.",
"export_para_2":"Location is shared as a simple list of times and coordinates, no other identifying information.",
"share":"SHARE",
"data_hint":"Log has data of"
}
"data_hint":"Log has data of",
"data_covers":"Total time the log covers:",
"data_count":"Number of points logged:",
"data_last_updated":"Time since last updated:",
"no_data": "No data",
"less_than_one_minute": "less than 1 minute"
}
7 changes: 6 additions & 1 deletion app/locales/en/exportscreen.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
"export_para_1":"You can share your location trail with anyone using the Share button below. Once you press the button it will ask you with whom and how you want to share it.",
"export_para_2":"Location is shared as a simple list of times and coordinates, no other identifying information.",
"share":"SHARE",
"data_hint":"Log has data of"
"data_hint":"Log has data of",
"data_covers":"Total time the log covers:",
"data_count":"Number of points logged:",
"data_last_updated":"Time since last updated:",
"no_data": "No data",
"less_than_one_minute": "less than 1 minute"
}
9 changes: 7 additions & 2 deletions app/locales/fr/exportscreen.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
"export_para_1":"You can share your location trail with anyone using the Share button below. Once you press the button it will ask you with whom and how you want to share it.",
"export_para_2":"Location is shared as a simple list of times and coordinates, no other identifying information.",
"share":"SHARE",
"data_hint":"Log has data of"
}
"data_hint":"Log has data of",
"data_covers":"Total time the log covers:",
"data_count":"Number of points logged:",
"data_last_updated":"Time since last updated:",
"no_data": "No data",
"less_than_one_minute": "less than 1 minute"
}
9 changes: 7 additions & 2 deletions app/locales/hi/exportscreen.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
"export_para_1":"आप नीचे दिए गए शेयर बटन का उपयोग करके किसी के साथ भी अपना लोकेशन ट्रेल शेयर कर सकते हैं। बटन दबाते ही यह आपसे पूछेगा कि आप इसे किससे और कैसे शेयर करना चाहते हैं।",
"export_para_2":"स्थान को समय और निर्देशांक की एक सरल सूची के रूप में शेयर किया जाता है, कोई अन्य पहचान करने वाली जानकारी नहीं।",
"share":"शेयर",
"data_hint":"लॉग का डेटा:"
}
"data_hint":"लॉग का डेटा:",
"data_covers":"Total time the log covers:",
"data_count":"Number of points logged:",
"data_last_updated":"Time since last updated:",
"no_data": "No data",
"less_than_one_minute": "less than 1 minute"
}
7 changes: 6 additions & 1 deletion app/locales/it/exportscreen.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
"export_para_1":"Puoi condividere i tuoi movimenti con chiunque, premendo il tasto CONDIVIDI. Una volta premuto il tasto, l'applicazione ti chiederà con chi e come vuoi condividere le informazioni.",
"export_para_2":"La posizione è condivisa come una semplice lista di date e coordinate, senza alcuna informazione che possa permettere l'identificazione dell'utente.",
"share":"CONDIVIDI",
"data_hint":"Log contiene dati di"
"data_hint":"Log contiene dati di",
"data_covers":"Total time the log covers:",
"data_count":"Number of points logged:",
"data_last_updated":"Time since last updated:",
"no_data": "No data",
"less_than_one_minute": "less than 1 minute"
}
7 changes: 6 additions & 1 deletion app/locales/mr/exportscreen.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
"export_para_1": "आपण खाली दिलेले शेयर बटण वापरून कुणाबरोबर ही आपली लोकेशन हिस्टरी शेयर करू शकता. बटण दाबले की आपल्याला लोकेशन हिस्टरी कुणाबरोबर आणि कशी शेयर करायची याबाबत सूचना मिळेल.",
"export_para_2": "लोकेशन हिस्टरी ही फक्त वेळ आणि लोकेशन कोऑर्डीनेटच्या स्वरूपात शेयर केली जात आहे. तुमची कोणतीही वैयक्तिक / खाजगी माहिती शेयर केली जात नाही.",
"share": "शेयर",
"data_hint": "लॉग चा डेटा:"
"data_hint": "लॉग चा डेटा:",
"data_covers":"Total time the log covers:",
"data_count":"Number of points logged:",
"data_last_updated":"Time since last updated:",
"no_data": "No data",
"less_than_one_minute": "less than 1 minute"
}
9 changes: 7 additions & 2 deletions app/locales/nl/exportscreen.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
"export_para_1":"Je kunt jouw locatiehistorie met iedereen delen via de knop Deel hieronder. Zodra je op de knop drukt, wordt je gevraagd met wie en hoe je deze wilt delen.",
"export_para_2":"Je locatiehistorie wordt gedeeld als een eenvoudige lijst met tijden en coördinaten, zonder andere identificerende informatie.",
"share":"DEEL",
"data_hint":"Log bevat data van"
}
"data_hint":"Log bevat data van",
"data_covers":"Total time the log covers:",
"data_count":"Number of points logged:",
"data_last_updated":"Time since last updated:",
"no_data": "No data",
"less_than_one_minute": "less than 1 minute"
}
9 changes: 7 additions & 2 deletions app/locales/pt/exportscreen.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
"export_para_1":"Você pode compartilhar o seu histórico de localização com qualquer pessoa usando o botão de Compartilhar. Depois de pressionar o botão, você escolhe com quem e como deseja compartilhar.",
"export_para_2":"Seu histórico de localização é compartilhado como uma lista simples de horários e coordenadas sem nenhuma outra informação de identificação.",
"share":"COMPARTILHAR",
"data_hint":"Registros de"
}
"data_hint":"Registros de",
"data_covers":"Total time the log covers:",
"data_count":"Number of points logged:",
"data_last_updated":"Time since last updated:",
"no_data": "No data",
"less_than_one_minute": "less than 1 minute"
}
7 changes: 6 additions & 1 deletion app/locales/pt_BR/exportscreen.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
"export_para_1":"Você pode compartilhar sua trilha de localização com qualquer pessoa usando o botão Compartilhar abaixo. Depois de pressionar o botão, ele perguntará com quem e como você deseja compartilhá-lo.",
"export_para_2":"O local é compartilhado como uma lista simples de horários e coordenadas, nenhuma outra informação de identificação.",
"share":"COMPARTILHAR",
"data_hint":"Registro possui dados de"
"data_hint":"Registro possui dados de",
"data_covers":"Total time the log covers:",
"data_count":"Number of points logged:",
"data_last_updated":"Time since last updated:",
"no_data": "No data",
"less_than_one_minute": "less than 1 minute"
}
Loading

0 comments on commit 476ac48

Please sign in to comment.