Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

11 changes: 11 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
buildscript {
ext.kotlin_version = '2.0.10'

repositories {
google()
mavenCentral()
}

dependencies {
// Add the Android Gradle Plugin classpath
classpath 'com.android.tools.build:gradle:8.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
Expand Down
1 change: 1 addition & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
org.gradle.jvmargs=-Xmx4G -XX:+HeapDumpOnOutOfMemoryError
android.useAndroidX=true
android.enableJetifier=true
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
3 changes: 2 additions & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip

51 changes: 36 additions & 15 deletions lib/classes/global.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import '../database/database_helper.dart';
import '../p2p/adhoc_housekeeping.dart';
import 'msg.dart';


class Global extends ChangeNotifier {
static RSAPrivateKey? myPrivateKey;
static RSAPublicKey? myPublicKey;
Expand All @@ -28,16 +27,19 @@ class Global extends ChangeNotifier {
static Map<String, dynamic> cache = {};
static final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();

static double fileTransferProgress = 0.0; // Progress percentage
static double transferSpeed = 0.0; // Speed in bytes/second
static int estimatedTimeRemaining = 0; // Time in seconds
static bool isTransferActive = false;

void sentToConversations(Msg msg, String converser, {bool addToTable = true}) {

static var profileNameStream;

void sentToConversations(Msg msg, String converser, {bool addToTable = true}) {
conversations.putIfAbsent(converser, () => {});
conversations[converser]![msg.id] = msg;
if (addToTable) {
insertIntoConversationsTable(msg, converser);
}

notifyListeners();
broadcast(scaffoldKey.currentContext!);
}
Expand All @@ -49,13 +51,19 @@ class Global extends ChangeNotifier {
print("Received Message: $message");
}


if (message['type'] == 'file') {
String filePath = await decodeAndStoreFile(
message['data'], message['fileName']);

//file decoding and saving
if (message['type'] == 'voice' || message['type'] == 'file') {
final String filePath = await decodeAndStoreFile(
message['data'],
message['fileName'],
isVoice: message['type'] == 'voice',
);

conversations.putIfAbsent(sender, () => {});
if (!conversations[sender]!.containsKey(decodedMessage['id'])) {
print("Adding to conversations");
Expand All @@ -72,8 +80,7 @@ class Global extends ChangeNotifier {
insertIntoConversationsTable(msg, sender);
notifyListeners();
}
}
else {
} else {
conversations.putIfAbsent(sender, () => {});
if (!conversations[sender]!.containsKey(decodedMessage['id'])) {
var msg = Msg(
Expand All @@ -89,14 +96,10 @@ class Global extends ChangeNotifier {
Future<String> decodeAndStoreFile(String encodedFile, String fileName, {bool isVoice = false}) async {
Uint8List fileBytes = base64.decode(encodedFile);

//to send files encrypted using RSA
// Uint8List fileData = rsaDecrypt(Global.myPrivateKey!, fileBytes);

Directory documents ;
Directory documents;
if (Platform.isAndroid) {
documents = (await getExternalStorageDirectory())!;
}
else {
} else {
documents = await getApplicationDocumentsDirectory();
}

Expand All @@ -115,15 +118,33 @@ class Global extends ChangeNotifier {
print("File saved at: $path");
}
return path;
}
else {
} else {
throw const FileSystemException('Storage permission not granted');
}
}

void updateFileTransferProgress(int bytesTransferred, int totalBytes) {
fileTransferProgress = (bytesTransferred / totalBytes) * 100;

void updateDevices(List<Device> devices) {
// Calculate transfer speed
transferSpeed = bytesTransferred / 1024; // Speed in KB/s

// Estimate time remaining
estimatedTimeRemaining =
((totalBytes - bytesTransferred) / transferSpeed).round();

notifyListeners();
}

void resetFileTransferProgress() {
fileTransferProgress = 0.0;
transferSpeed = 0.0;
estimatedTimeRemaining = 0;
isTransferActive = false;
notifyListeners();
}

void updateDevices(List<Device> devices) {
this.devices = devices;
notifyListeners();
}
Expand Down
Loading