messages view and some basic refactoring #1
433
lib/main.dart
433
lib/main.dart
|
@ -1,72 +1,40 @@
|
|||
import 'dart:ffi';
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:io' show Platform;
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'model.dart' as model;
|
||||
import 'dart:collection';
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'model.dart';
|
||||
import 'views/profilemgrview.dart';
|
||||
|
||||
typedef start_cwtch_function = Void Function(Pointer<Utf8> str, Int32 length);
|
||||
typedef StartCwtchFn = void Function(Pointer<Utf8> dir, int len);
|
||||
void main() => runApp(Flwtch());
|
||||
|
||||
typedef access_cwtch_eventbus_function = Void Function();
|
||||
typedef NextEventFn = void Function();
|
||||
class Flwtch extends StatefulWidget {
|
||||
final Key flwtch = GlobalKey();
|
||||
|
||||
|
||||
typedef get_json_blob_void_function = Pointer<Utf8> Function();
|
||||
typedef GetJsonBlobVoidFn = Pointer<Utf8> Function();
|
||||
|
||||
typedef get_json_blob_string_function = Pointer<Utf8> Function(Pointer<Utf8> str, Int32 length);
|
||||
typedef GetJsonBlobStringFn = Pointer<Utf8> Function(Pointer<Utf8> str,int len);
|
||||
|
||||
|
||||
class ProfileModel {
|
||||
String onion;
|
||||
String nickname;
|
||||
String creationDate;
|
||||
HashMap<String, ContactModel> contacts;
|
||||
@override
|
||||
FlwtchState createState() => FlwtchState();
|
||||
}
|
||||
|
||||
class ContactModel {
|
||||
String onion;
|
||||
String nickname;
|
||||
bool isGroup;
|
||||
bool isBlocked;
|
||||
String status;
|
||||
List<MessageModel> messages;
|
||||
class FlwtchState extends State<Flwtch> {
|
||||
final TextStyle biggerFont = const TextStyle(fontSize: 18);
|
||||
|
||||
ContactModel({this.onion, this.nickname, this.status});
|
||||
|
||||
}
|
||||
|
||||
class MessageModel {
|
||||
String from;
|
||||
String message;
|
||||
String timestamp;
|
||||
}
|
||||
|
||||
|
||||
void main() => runApp(MyApp());
|
||||
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
// This widget is the root of your application.
|
||||
DynamicLibrary library;
|
||||
AppModel appStatus;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
var library = DynamicLibrary.open("libCwtch.so");
|
||||
library = DynamicLibrary.open("libCwtch.so");
|
||||
appStatus = AppModel(library: library);
|
||||
|
||||
var startCwtchC = library.lookup<NativeFunction<start_cwtch_function>>("StartCwtch");
|
||||
// ignore: non_constant_identifier_names
|
||||
final StartCwtch = startCwtchC.asFunction<StartCwtchFn>();
|
||||
|
||||
var cwtchDir = "/home/sarah/.cwtch/dev/";
|
||||
var cwtchDir = "/home/erinn/.cwtch/dev/";
|
||||
StartCwtch(Utf8.toUtf8(cwtchDir), cwtchDir.length);
|
||||
|
||||
|
||||
return MaterialApp(
|
||||
return Provider<FlwtchState>(
|
||||
create: (_) => this,
|
||||
child: MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
theme: ThemeData(
|
||||
// This is the theme of your application.
|
||||
|
@ -87,366 +55,7 @@ class MyApp extends StatelessWidget {
|
|||
canvasColor: Color(0xFFB09CBC),
|
||||
accentColor: Color(0xFFD01972),
|
||||
),
|
||||
home:RandomWords(title: 'Cwtch App', library:library, appStatus: model.AppModel(library: library)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class RandomWords extends StatefulWidget {
|
||||
|
||||
RandomWords({Key key, this.title, this.library, this.appStatus}) : super(key: key);
|
||||
|
||||
// This widget is the home page of your application. It is stateful, meaning
|
||||
// that it has a State object (defined below) that contains fields that affect
|
||||
// how it looks.
|
||||
|
||||
// This class is the configuration for the state. It holds the values (in this
|
||||
// case the title) provided by the parent (in this case the App widget) and
|
||||
// used by the build method of the State. Fields in a Widget subclass are
|
||||
// always marked "final".
|
||||
|
||||
final String title;
|
||||
final DynamicLibrary library;
|
||||
final model.AppModel appStatus;
|
||||
|
||||
@override
|
||||
_RandomWordsState createState() => _RandomWordsState();
|
||||
}
|
||||
|
||||
class _RandomWordsState extends State<RandomWords> {
|
||||
HashMap<String, ProfileModel> _profiles;
|
||||
String currentlySelectedProfile = "";
|
||||
String currentlySelectedConversation = "";
|
||||
|
||||
// example stuff
|
||||
final TextStyle _biggerFont = const TextStyle(fontSize: 18);
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
if (_profiles == null) {
|
||||
_profiles = new HashMap<String, ProfileModel>();
|
||||
}
|
||||
|
||||
if (_profiles.length < 1) {
|
||||
|
||||
var getProfilesC = widget.library.lookup<NativeFunction<get_json_blob_void_function>>("GetProfiles");
|
||||
final GetProfiles = getProfilesC.asFunction<GetJsonBlobVoidFn>();
|
||||
|
||||
|
||||
|
||||
Pointer<Utf8> jsonProfilesBytes = GetProfiles();
|
||||
String jsonProfiles = Utf8.fromUtf8(jsonProfilesBytes);
|
||||
print(jsonProfiles);
|
||||
|
||||
Map<String, dynamic> profiles = jsonDecode(jsonProfiles);
|
||||
|
||||
profiles.forEach((onion,nick) {
|
||||
ProfileModel profile1 = new ProfileModel();
|
||||
profile1.onion = onion;
|
||||
profile1.nickname = nick;
|
||||
profile1.creationDate = "4 jan 2020";
|
||||
|
||||
profile1.contacts = new HashMap<String, ContactModel>();
|
||||
|
||||
|
||||
|
||||
|
||||
_profiles.putIfAbsent(profile1.onion, () => profile1);
|
||||
});
|
||||
|
||||
// ProfileModel profile1 = new ProfileModel();
|
||||
// profile1.onion = "xyzonion";
|
||||
// profile1.nickname = "Erinn";
|
||||
// profile1.creationDate = "4 jan 2020";
|
||||
// profile1.contacts = new HashMap<String, ContactModel>();
|
||||
// ProfileModel profile2 = new ProfileModel();
|
||||
// profile2.onion = "baphonion";
|
||||
// profile2.nickname = "Baphomet";
|
||||
// profile2.creationDate = "6 jan 2020";
|
||||
// profile2.contacts = new HashMap<String, ContactModel>();
|
||||
//
|
||||
// ContactModel contactErinn = new ContactModel();
|
||||
// contactErinn.onion = profile1.onion;
|
||||
// contactErinn.nickname = profile1.nickname;
|
||||
// MessageModel m0 = new MessageModel();
|
||||
// m0.from = contactErinn.onion;
|
||||
// m0.message = "hello baphomet!!";
|
||||
// m0.timestamp = "7 jan 2020";
|
||||
// MessageModel m1 = new MessageModel();
|
||||
// m1.from = profile2.onion;
|
||||
// m1.message = "well hi there! can't believe this worked!";
|
||||
// m1.timestamp = "7 jan 2020";
|
||||
// contactErinn.messages = <MessageModel>[];
|
||||
// contactErinn.messages.add(m0);
|
||||
// contactErinn.messages.add(m1);
|
||||
|
||||
// profile2.contacts.putIfAbsent(contactErinn.onion, () => contactErinn);
|
||||
// _profiles.putIfAbsent(profile1.onion, () => profile1);
|
||||
// _profiles.putIfAbsent(profile2.onion, () => profile2);
|
||||
}
|
||||
|
||||
return Scaffold (
|
||||
appBar: AppBar(
|
||||
title: Text('Profiles'),
|
||||
actions: [
|
||||
IconButton(icon: Icon(Icons.list)),
|
||||
],
|
||||
),
|
||||
body: _buildProfileManager(),//_buildSuggestions(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void _pushContactList() {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Contacts for ' + currentlySelectedProfile),
|
||||
),
|
||||
body: _buildContactList(),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContactList() {
|
||||
|
||||
var getContactsC = widget.library.lookup<NativeFunction<get_json_blob_string_function>>("GetContacts");
|
||||
final GetContacts = getContactsC.asFunction<GetJsonBlobStringFn>();
|
||||
|
||||
|
||||
|
||||
|
||||
return StreamBuilder<String>(
|
||||
stream: widget.appStatus.contactEvents(),
|
||||
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
|
||||
|
||||
|
||||
|
||||
Pointer<Utf8> jsonContactBytes = GetContacts(Utf8.toUtf8(currentlySelectedProfile), currentlySelectedProfile.length);
|
||||
String jsonContacts = Utf8.fromUtf8(jsonContactBytes);
|
||||
print(jsonContacts);
|
||||
List<dynamic> contacts = jsonDecode(jsonContacts);
|
||||
|
||||
Map<String, ContactModel> _contacts = new HashMap<String, ContactModel>();
|
||||
contacts.forEach((onion) {
|
||||
_contacts.putIfAbsent(onion['onion'], () => ContactModel(onion: onion['onion'], nickname: onion['name'], status: onion['status']));
|
||||
});
|
||||
|
||||
// Map<String, ContactModel> _contacts = _profiles[currentlySelectedProfile].contacts;
|
||||
final tiles = _contacts.values.map(
|
||||
(ContactModel contact) {
|
||||
return ListTile(
|
||||
title: Text(
|
||||
contact.nickname,
|
||||
style: _biggerFont,
|
||||
),
|
||||
subtitle: Text(contact.status),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
|
||||
currentlySelectedConversation = contact.onion;
|
||||
_pushMessageView();
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
final divided = ListTile.divideTiles(
|
||||
context: context,
|
||||
tiles: tiles,
|
||||
).toList();
|
||||
|
||||
return ListView(children: divided);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _pushMessageView() {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Convo: ' + currentlySelectedConversation),
|
||||
),
|
||||
body: _buildMessageView(),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String getNick(String profile, String contact) {
|
||||
return contact == profile ? "me" : _profiles[profile].contacts[contact].nickname;
|
||||
}
|
||||
|
||||
Widget _buildMessageView() {
|
||||
List<MessageModel> _contacts = _profiles[currentlySelectedProfile].contacts[currentlySelectedConversation].messages;
|
||||
final tiles = _contacts.map(
|
||||
(MessageModel m) {
|
||||
return ListTile(
|
||||
title: Text(
|
||||
getNick(currentlySelectedProfile, m.from),
|
||||
),
|
||||
subtitle: Text(
|
||||
m.message,
|
||||
style: _biggerFont,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
final divided = ListTile.divideTiles(
|
||||
context: context,
|
||||
tiles: tiles,
|
||||
).toList();
|
||||
|
||||
return ListView(children: divided);
|
||||
}
|
||||
|
||||
Widget _buildProfileManager() {
|
||||
final tiles = _profiles.values.map(
|
||||
(ProfileModel profile) {
|
||||
return ListTile(
|
||||
title: Text(
|
||||
profile.nickname,
|
||||
style: _biggerFont,
|
||||
),
|
||||
subtitle: Text(profile.onion),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
|
||||
var selectProfileC = widget.library.lookup<NativeFunction<get_json_blob_string_function>>("SelectProfile");
|
||||
final SelectProfile = selectProfileC.asFunction<GetJsonBlobStringFn>();
|
||||
|
||||
SelectProfile(Utf8.toUtf8(profile.onion), profile.onion.length);
|
||||
|
||||
currentlySelectedConversation = "";
|
||||
currentlySelectedProfile = profile.onion;
|
||||
_pushContactList();
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
final divided = ListTile.divideTiles(
|
||||
context: context,
|
||||
tiles: tiles,
|
||||
).toList();
|
||||
|
||||
return ListView(children: divided);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
MyHomePage({Key key, this.title, this.library, this.appStatus}) : super(key: key);
|
||||
|
||||
// This widget is the home page of your application. It is stateful, meaning
|
||||
// that it has a State object (defined below) that contains fields that affect
|
||||
// how it looks.
|
||||
|
||||
// This class is the configuration for the state. It holds the values (in this
|
||||
// case the title) provided by the parent (in this case the App widget) and
|
||||
// used by the build method of the State. Fields in a Widget subclass are
|
||||
// always marked "final".
|
||||
|
||||
final String title;
|
||||
final DynamicLibrary library;
|
||||
final model.AppModel appStatus;
|
||||
|
||||
@override
|
||||
_MyHomePageState createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int _counter = 0;
|
||||
|
||||
void _incrementCounter() {
|
||||
setState(() {
|
||||
|
||||
|
||||
var nextEventC = widget.library.lookup<NativeFunction<access_cwtch_eventbus_function>>("NextEvent");
|
||||
final NextEvent = nextEventC.asFunction<NextEventFn>();
|
||||
|
||||
|
||||
// This call to setState tells the Flutter framework that something has
|
||||
// changed in this State, which causes it to rerun the build method below
|
||||
// so that the display can reflect the updated values. If we changed
|
||||
// _counter without calling setState(), then the build method would not be
|
||||
// called again, and so nothing would appear to happen.
|
||||
NextEvent();
|
||||
_counter = 1;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// This method is rerun every time setState is called, for instance as done
|
||||
// by the _incrementCounter method above.
|
||||
//
|
||||
// The Flutter framework has been optimized to make rerunning build methods
|
||||
// fast, so that you can just rebuild anything that needs updating rather
|
||||
// than having to individually change instances of widgets.
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
// Here we take the value from the MyHomePage object that was created by
|
||||
// the App.build method, and use it to set our appbar title.
|
||||
title: Text(widget.title),
|
||||
),
|
||||
body: Center(
|
||||
// Center is a layout widget. It takes a single child and positions it
|
||||
// in the middle of the parent.
|
||||
child: Column(
|
||||
// Column is also a layout widget. It takes a list of children and
|
||||
// arranges them vertically. By default, it sizes itself to fit its
|
||||
// children horizontally, and tries to be as tall as its parent.
|
||||
//
|
||||
// Invoke "debug painting" (press "p" in the console, choose the
|
||||
// "Toggle Debug Paint" action from the Flutter Inspector in Android
|
||||
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
|
||||
// to see the wireframe for each widget.
|
||||
//
|
||||
// Column has various properties to control how it sizes itself and
|
||||
// how it positions its children. Here we use mainAxisAlignment to
|
||||
// center the children vertically; the main axis here is the vertical
|
||||
// axis because Columns are vertical (the cross axis would be
|
||||
// horizontal).
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
StreamBuilder<String>(
|
||||
stream: widget.appStatus.torStatus(),
|
||||
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
|
||||
return Text(
|
||||
snapshot.hasData ?
|
||||
snapshot.data : "Tor not yet Connected",
|
||||
style: Theme
|
||||
.of(context)
|
||||
.textTheme
|
||||
.headline4,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _incrementCounter,
|
||||
tooltip: 'Increment',
|
||||
child: Icon(Icons.add),
|
||||
), // This trailing comma makes auto-formatting nicer for build methods.
|
||||
);
|
||||
home: ProfileMgrView(),
|
||||
));
|
||||
}
|
||||
}
|
|
@ -1,21 +1,44 @@
|
|||
import 'dart:ffi';
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'dart:collection';
|
||||
|
||||
////////////////////
|
||||
/// UI State ///
|
||||
////////////////////
|
||||
|
||||
class ProfileModel {
|
||||
String onion;
|
||||
String nickname;
|
||||
String creationDate;
|
||||
HashMap<String, ContactModel> contacts;
|
||||
}
|
||||
|
||||
class ContactModel {
|
||||
String onion;
|
||||
String nickname;
|
||||
bool isGroup;
|
||||
bool isBlocked;
|
||||
String status;
|
||||
|
||||
ContactModel({this.onion, this.nickname, this.status});
|
||||
}
|
||||
|
||||
/////////////
|
||||
/// ACN ///
|
||||
/////////////
|
||||
|
||||
typedef acn_events_function = Pointer<Utf8> Function();
|
||||
typedef ACNEventsFn = Pointer<Utf8> Function();
|
||||
|
||||
|
||||
|
||||
class AppModel {
|
||||
|
||||
final DynamicLibrary library;
|
||||
AppModel({this.library});
|
||||
|
||||
Stream<String> contactEvents() async* {
|
||||
var acnEventsC = library.lookup<NativeFunction<acn_events_function>>(
|
||||
"ContactEvents");
|
||||
// ignore: non_constant_identifier_names
|
||||
final ContactEvents = acnEventsC.asFunction<ACNEventsFn>();
|
||||
|
||||
while (true) {
|
||||
|
@ -34,6 +57,7 @@ class AppModel {
|
|||
Stream<String> torStatus() async* {
|
||||
var acnEventsC = library.lookup<NativeFunction<acn_events_function>>(
|
||||
"ACNEvents");
|
||||
// ignore: non_constant_identifier_names
|
||||
final ACNEvents = acnEventsC.asFunction<ACNEventsFn>();
|
||||
|
||||
while (true) {
|
||||
|
@ -47,3 +71,27 @@ class AppModel {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////
|
||||
/// Cwtch API ///
|
||||
/////////////////////
|
||||
|
||||
typedef start_cwtch_function = Void Function(Pointer<Utf8> str, Int32 length);
|
||||
typedef StartCwtchFn = void Function(Pointer<Utf8> dir, int len);
|
||||
|
||||
typedef access_cwtch_eventbus_function = Void Function();
|
||||
typedef NextEventFn = void Function();
|
||||
|
||||
typedef get_json_blob_void_function = Pointer<Utf8> Function();
|
||||
typedef GetJsonBlobVoidFn = Pointer<Utf8> Function();
|
||||
|
||||
typedef get_json_blob_string_function = Pointer<Utf8> Function(Pointer<Utf8> str, Int32 length);
|
||||
typedef GetJsonBlobStringFn = Pointer<Utf8> Function(Pointer<Utf8> str,int len);
|
||||
|
||||
//func NumMessages(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int) (n C.int) {
|
||||
typedef get_int_from_str_str_function = Int32 Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32);
|
||||
typedef GetIntFromStrStrFn = int Function(Pointer<Utf8>, int, Pointer<Utf8>, int);
|
||||
|
||||
//func GetMessage(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int, message_index C.int) *C.char {
|
||||
typedef get_json_blob_from_str_str_int_function = Pointer<Utf8> Function(Pointer<Utf8>, Int32, Pointer<Utf8>, Int32, Int32);
|
||||
typedef GetJsonBlobFromStrStrIntFn = Pointer<Utf8> Function(Pointer<Utf8>, int, Pointer<Utf8>, int, int);
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
import 'dart:collection';
|
||||
import 'dart:convert';
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../main.dart';
|
||||
import 'messageview.dart';
|
||||
import '../model.dart';
|
||||
|
||||
class ContactsView extends StatefulWidget {
|
||||
const ContactsView({Key key, this.flwtch, this.profileOnion}) : super(key: key);
|
||||
final GlobalKey<FlwtchState> flwtch;
|
||||
final String profileOnion;
|
||||
|
||||
@override
|
||||
_ContactsViewState createState() => _ContactsViewState();
|
||||
}
|
||||
|
||||
class _ContactsViewState extends State<ContactsView> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Contacts for ' + widget.profileOnion),
|
||||
),
|
||||
body: _buildContactList(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Widget _buildContactList() {
|
||||
var getContactsC = Provider.of<FlwtchState>(context).library.lookup<NativeFunction<get_json_blob_string_function>>("GetContacts");
|
||||
// ignore: non_constant_identifier_names
|
||||
final GetContacts = getContactsC.asFunction<GetJsonBlobStringFn>();
|
||||
|
||||
return StreamBuilder<String>(
|
||||
stream: Provider.of<FlwtchState>(context).appStatus.contactEvents(),
|
||||
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
|
||||
Pointer<Utf8> jsonContactBytes = GetContacts(Utf8.toUtf8(widget.profileOnion), widget.profileOnion.length);
|
||||
String jsonContacts = Utf8.fromUtf8(jsonContactBytes);
|
||||
print(jsonContacts);
|
||||
List<dynamic> contacts = jsonDecode(jsonContacts);
|
||||
|
||||
Map<String, ContactModel> _contacts = new HashMap<String, ContactModel>();
|
||||
contacts.forEach((onion) {
|
||||
_contacts.putIfAbsent(onion['onion'], () => ContactModel(onion: onion['onion'], nickname: onion['name'], status: onion['status']));
|
||||
});
|
||||
|
||||
// Map<String, ContactModel> _contacts = _profiles[currentlySelectedProfile].contacts;
|
||||
final tiles = _contacts.values.map(
|
||||
(ContactModel contact) {
|
||||
return ListTile(
|
||||
title: Text(
|
||||
contact.nickname,
|
||||
style: Provider.of<FlwtchState>(context).biggerFont,
|
||||
),
|
||||
subtitle: Text(contact.status),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_pushMessageView(contact.onion);
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
final divided = ListTile.divideTiles(
|
||||
context: context,
|
||||
tiles: tiles,
|
||||
).toList();
|
||||
|
||||
return ListView(children: divided);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _pushMessageView(String handle) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (BuildContext context) {
|
||||
return Provider(
|
||||
create: (_) => Provider.of<FlwtchState>(context),
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('Convo: ' + widget.profileOnion),
|
||||
),
|
||||
body: MessageView(profileOnion: widget.profileOnion, conversationHandle: handle),
|
||||
));
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../main.dart';
|
||||
import '../model.dart';
|
||||
|
||||
class MessageView extends StatefulWidget {
|
||||
const MessageView({Key key, this.flwtch, this.profileOnion, this.conversationHandle}) : super(key: key);
|
||||
final GlobalKey<FlwtchState> flwtch;
|
||||
final String profileOnion;
|
||||
final String conversationHandle;
|
||||
|
||||
@override
|
||||
_MessageViewState createState() => _MessageViewState();
|
||||
}
|
||||
|
||||
class _MessageViewState extends State<MessageView> {
|
||||
int conversationNumMessages = 0;
|
||||
Timer timer;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _buildMessageView(context);
|
||||
}
|
||||
|
||||
Widget _buildMessageView(BuildContext context) {
|
||||
var numMessagesC = Provider.of<FlwtchState>(context).library.lookup<NativeFunction<get_int_from_str_str_function>>("NumMessages");
|
||||
// ignore: non_constant_identifier_names
|
||||
final NumMessages = numMessagesC.asFunction<GetIntFromStrStrFn>();
|
||||
var getMessageC = Provider.of<FlwtchState>(context).library.lookup<NativeFunction<get_json_blob_from_str_str_int_function>>("GetMessage");
|
||||
// ignore: non_constant_identifier_names
|
||||
final GetMessage = getMessageC.asFunction<GetJsonBlobFromStrStrIntFn>();
|
||||
|
||||
_updateMessageCount(context, NumMessages);
|
||||
timer = Timer.periodic(Duration(seconds: 1), (Timer t) => _updateMessageCount(context, NumMessages));
|
||||
|
||||
|
||||
return ProxyProvider0(
|
||||
update: (_, __) => MessageCounter(conversationNumMessages),
|
||||
child: ListView.builder(
|
||||
itemCount: conversationNumMessages,
|
||||
itemBuilder: (context, index) {
|
||||
Pointer<Utf8> jsonMessageBytes = GetMessage(
|
||||
Utf8.toUtf8(widget.profileOnion), widget.profileOnion.length,
|
||||
Utf8.toUtf8(widget.conversationHandle), widget.conversationHandle.length,
|
||||
index);
|
||||
String jsonMessage = Utf8.fromUtf8(jsonMessageBytes);
|
||||
//print(jsonMessage);
|
||||
dynamic messageWrapper = jsonDecode(jsonMessage);
|
||||
dynamic message = jsonDecode(messageWrapper['Message']);
|
||||
|
||||
return ListTile(
|
||||
title: Text(message['d']),
|
||||
subtitle: Row(
|
||||
children: [Text(messageWrapper['Timestamp']), messageWrapper['Acknowledged'] ? Icon(Icons.check_circle_outline) : Icon(Icons.hourglass_bottom_outlined)],
|
||||
));
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
Future _updateMessageCount(BuildContext context, GetIntFromStrStrFn cfn) async {
|
||||
setState(() {
|
||||
conversationNumMessages = cfn(
|
||||
Utf8.toUtf8(widget.profileOnion), widget.profileOnion.length,
|
||||
Utf8.toUtf8(widget.conversationHandle),
|
||||
widget.conversationHandle.length,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class MessageCounter {
|
||||
MessageCounter(this.x);
|
||||
int x = 0;
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:ffi';
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../main.dart';
|
||||
import '../model.dart';
|
||||
import 'dart:collection';
|
||||
|
||||
import 'contactsview.dart';
|
||||
|
||||
class ProfileMgrView extends StatefulWidget {
|
||||
@override
|
||||
_ProfileMgrViewState createState() => _ProfileMgrViewState();
|
||||
}
|
||||
|
||||
class _ProfileMgrViewState extends State<ProfileMgrView> {
|
||||
HashMap<String, ProfileModel> _profiles;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_profiles == null) {
|
||||
_profiles = new HashMap<String, ProfileModel>();
|
||||
}
|
||||
|
||||
if (_profiles.length < 1) {
|
||||
var getProfilesC = Provider.of<FlwtchState>(context).library.lookup<NativeFunction<get_json_blob_void_function>>("GetProfiles");
|
||||
// ignore: non_constant_identifier_names
|
||||
final GetProfiles = getProfilesC.asFunction<GetJsonBlobVoidFn>();
|
||||
|
||||
Pointer<Utf8> jsonProfilesBytes = GetProfiles();
|
||||
String jsonProfiles = Utf8.fromUtf8(jsonProfilesBytes);
|
||||
print(jsonProfiles);
|
||||
|
||||
Map<String, dynamic> profiles = jsonDecode(jsonProfiles);
|
||||
|
||||
profiles.forEach((onion,nick) {
|
||||
ProfileModel profile1 = new ProfileModel();
|
||||
profile1.onion = onion;
|
||||
profile1.nickname = nick;
|
||||
profile1.creationDate = "4 jan 2020";
|
||||
profile1.contacts = new HashMap<String, ContactModel>();
|
||||
|
||||
_profiles.putIfAbsent(profile1.onion, () => profile1);
|
||||
});
|
||||
}
|
||||
|
||||
return Scaffold (
|
||||
appBar: AppBar(
|
||||
title: Text('Profiles'),
|
||||
actions: [
|
||||
IconButton(icon: Icon(Icons.list), onPressed: () { },),
|
||||
],
|
||||
),
|
||||
body: _buildProfileManager(),//_buildSuggestions(),
|
||||
);
|
||||
}
|
||||
|
||||
void _pushContactList(String profile) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (BuildContext context) {
|
||||
return Provider(
|
||||
create: (_) => Provider.of<FlwtchState>(context),
|
||||
child: ContactsView(profileOnion: profile),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String getNick(String profile, String contact) {
|
||||
return contact == profile ? "me" : _profiles[profile].contacts[contact].nickname;
|
||||
}
|
||||
|
||||
Widget _buildProfileManager() {
|
||||
final tiles = _profiles.values.map(
|
||||
(ProfileModel profile) {
|
||||
return ListTile(
|
||||
title: Text(
|
||||
profile.nickname,
|
||||
style: Provider.of<FlwtchState>(context).biggerFont,
|
||||
),
|
||||
subtitle: Text(profile.onion),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
var selectProfileC = Provider.of<FlwtchState>(context).library.lookup<NativeFunction<get_json_blob_string_function>>("SelectProfile");
|
||||
// ignore: non_constant_identifier_names
|
||||
final SelectProfile = selectProfileC.asFunction<GetJsonBlobStringFn>();
|
||||
|
||||
SelectProfile(Utf8.toUtf8(profile.onion), profile.onion.length);
|
||||
_pushContactList(profile.onion);
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
final divided = ListTile.divideTiles(
|
||||
context: context,
|
||||
tiles: tiles,
|
||||
).toList();
|
||||
|
||||
return ListView(children: divided);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
import 'dart:ffi';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../main.dart';
|
||||
import '../model.dart';
|
||||
|
||||
class TorStatusLabel extends StatefulWidget {
|
||||
@override
|
||||
_TorStatusState createState() => _TorStatusState();
|
||||
}
|
||||
|
||||
class _TorStatusState extends State<TorStatusLabel> {
|
||||
String status = "";
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Builder(
|
||||
builder: (context2) => StreamBuilder<String>(
|
||||
stream: Provider.of<FlwtchState>(context).appStatus.torStatus(),
|
||||
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
|
||||
return Text(
|
||||
snapshot.hasData ?
|
||||
snapshot.data : "Tor not yet Connected",
|
||||
style: Theme
|
||||
.of(context)
|
||||
.textTheme
|
||||
.headline4,
|
||||
);
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
void _incrementCounter() {
|
||||
setState(() {
|
||||
var nextEventC = Provider.of<FlwtchState>(context).library.lookup<NativeFunction<access_cwtch_eventbus_function>>("NextEvent");
|
||||
// ignore: non_constant_identifier_names
|
||||
final NextEvent = nextEventC.asFunction<NextEventFn>();
|
||||
NextEvent();
|
||||
});
|
||||
}
|
||||
}
|
15
pubspec.lock
15
pubspec.lock
|
@ -88,6 +88,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.3.0-nullsafety.6"
|
||||
nested:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: nested
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.0.4"
|
||||
path:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -95,6 +102,13 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.8.0-nullsafety.3"
|
||||
provider:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: provider
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.3.2+3"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
|
@ -158,3 +172,4 @@ packages:
|
|||
version: "2.1.0-nullsafety.5"
|
||||
sdks:
|
||||
dart: ">=2.12.0-0.0 <3.0.0"
|
||||
flutter: ">=1.16.0"
|
||||
|
|
|
@ -23,6 +23,7 @@ environment:
|
|||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
provider: "4.3.2+3"
|
||||
|
||||
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
|
|
Loading…
Reference in New Issue