Skip to content

Commit

Permalink
background services code
Browse files Browse the repository at this point in the history
  • Loading branch information
bulgariamitko committed Nov 22, 2024
1 parent 9fe5684 commit d252e25
Show file tree
Hide file tree
Showing 5 changed files with 260 additions and 127 deletions.
Binary file modified .DS_Store
Binary file not shown.
20 changes: 20 additions & 0 deletions Custom Functions/convert-timestamp-datetime.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// YouTube channel - https://www.youtube.com/@flutterflowexpert
// paid video - https://www.youtube.com/watch?v=idXHYU0co5Y
// Join the Klaturov army - https://www.youtube.com/@flutterflowexpert/join
// Support my work - https://github.com/sponsors/bulgariamitko
// Website - https://bulgariamitko.github.io/flutterflowtutorials/
// You can book me as FF mentor - https://calendly.com/bulgaria_mitko
// GitHub repo - https://github.com/bulgariamitko/flutterflowtutorials
// Discord channel - https://discord.gg/G69hSUqEeU

DateTime convertTimestampIntoDateTime(String timestampDate) {
/// MODIFY CODE ONLY BELOW THIS LINE
// Parse the timestamp string as milliseconds since epoch
int timestamp = int.parse(timestampDate);

// Convert milliseconds to DateTime object
return DateTime.fromMillisecondsSinceEpoch(timestamp);

/// MODIFY CODE ONLY ABOVE THIS LINE
}
61 changes: 42 additions & 19 deletions Packages/call_log/read-phone-log.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// YouTube channel - https://www.youtube.com/@flutterflowexpert
// paid video - https://www.youtube.com/watch?v=oJDkoYfVA1g
// widgets - Cg9Db2x1bW5fd2ZjOWVlcHUS0AEKD0J1dHRvbl9qNTZ4MTN4bhgJIn1KeAoZCg1HZXQgUGhvbmUgbG9nOgYI/////w9ABRkAAAAAAAAIQDEAAAAAAABEQEkAAAAAAADwP1ICEAFaAggAciQJAAAAAAAAIEARAAAAAAAAIEAZAAAAAAAAIEAhAAAAAAAAIEB6EgkAAAAAAAA4QBkAAAAAAAA4QPoDAGIAigE5EjMKCHRvbDhyaDF2EifSARkKFQoMcmVhZFBob25lTG9nEgV4ZDhyYiIAqgIIN3Zi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ARcKEwoKbWFpbkFjdGlvbhIFNXV3amciAKoCCHR6a2l6cWN5GgIIARgEIgciAhAB+gMA
// paid video - https://www.youtube.com/watch?v=idXHYU0co5Y
// Join the Klaturov army - https://www.youtube.com/@flutterflowexpert/join
// Support my work - https://github.com/sponsors/bulgariamitko
// Website - https://bulgariamitko.github.io/flutterflowtutorials/
Expand All @@ -11,27 +10,51 @@
import 'package:call_log/call_log.dart';
import 'package:permission_handler/permission_handler.dart';

Future readPhoneLog() async {
if (await Permission.phone.request().isGranted) {
Future<void> getOldPhoneCalls(
Future Function(PhoneCallStruct oldCall) oldPhoneCall) async {
print('Starting to retrieve old phone calls...');

// Initialize Flutter binding
WidgetsFlutterBinding.ensureInitialized();

// Request permission if not already granted
print('Checking phone permission...');
var status = await Permission.phone.status;
if (!status.isGranted) {
status = await Permission.phone.request();
print('Permission status after request: $status');
if (!status.isGranted) {
print('Phone permission denied');
return;
}
}
print('Phone permission granted');

try {
// Get all call log entries
print('Retrieving call log entries...');
Iterable<CallLogEntry> entries = await CallLog.get();
print('Found ${entries.length} call log entries');

entries.forEach((entry) {
// Converting enum to string
String callType =
CallType.values[entry.callType!.index].toString().split('.').last;
// Process each call log entry
for (final entry in entries) {
print('Processing call entry: ${entry.number}');

// Converting the integer timestamp (milliseconds since epoch) to DateTime
DateTime date = DateTime.fromMillisecondsSinceEpoch(entry.timestamp ?? 0);
final oldCallData = PhoneCallStruct(
type: CallType.values[entry.callType!.index].toString().split('.').last,
number: entry.number ?? '',
timestamp: entry.timestamp.toString(),
duration: entry.duration.toString(),
);

// Formatting timestamp to string
String timestamp = DateFormat('yyyy-MM-dd – kk:mm').format(date);
print(
'Executing callback for call: ${oldCallData.type} - ${oldCallData.number}');
await oldPhoneCall(oldCallData);
}

FFAppState().update(() {
FFAppState().type = callType;
FFAppState().number = entry.number ?? '';
FFAppState().duration = entry.duration.toString();
FFAppState().timestamp = timestamp;
});
});
print('Finished processing all old calls');
} catch (e) {
print('Error retrieving old calls: $e');
rethrow;
}
}
Loading

0 comments on commit d252e25

Please sign in to comment.