success in GetProfiles: rework profiles manager view, pull profiles to FlwtchState and rework init a lot
This commit is contained in:
parent
c2aa0dfb4a
commit
28a9ffa17f
|
@ -52,6 +52,7 @@ class MainActivity: FlutterActivity() {
|
|||
Log.i("MainActivity.kt", " appDir: '" + appDir + "' torPath: '" + torPath + "'")
|
||||
Cwtch.startCwtch(appDir, torPath)
|
||||
}
|
||||
"GetProfiles" -> result.success(Cwtch.getProfiles())
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -1,5 +1,5 @@
|
|||
abstract class Cwtch {
|
||||
void Start();
|
||||
Future<void> Start();
|
||||
|
||||
void SelectProfile(String onion);
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ class CwtchFfi implements Cwtch {
|
|||
library = DynamicLibrary.open("libCwtch.so");
|
||||
}
|
||||
|
||||
void Start() {
|
||||
Future<void> Start() {
|
||||
String home = "";
|
||||
Map<String, String> envVars = Platform.environment;
|
||||
if (Platform.isLinux) {
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'dart:async';
|
||||
|
@ -18,31 +20,20 @@ class CwtchGomobile implements Cwtch {
|
|||
static const appInfoPlatform = const MethodChannel('test.flutter.dev/applicationInfo');
|
||||
static const cwtchPlatform = const MethodChannel('cwtch');
|
||||
|
||||
var androidLibraryDir = "";
|
||||
var androidHomeDirectory = "";
|
||||
Future<String> androidLibraryDir;
|
||||
Future<Directory> androidHomeDirectory;
|
||||
|
||||
CwtchGomobile() {
|
||||
print("CwtchGomobile()");
|
||||
/*getApplicationDocumentsDirectory().then((directory) =>
|
||||
{
|
||||
print("androidHomeDir = $directory"),
|
||||
androidHomeDirectory = directory.path
|
||||
});
|
||||
|
||||
appInfoPlatform.invokeMethod('getNativeLibDir').then((value) =>
|
||||
{
|
||||
print("nativeLibraryDir = $value"),
|
||||
androidLibraryDir = value
|
||||
});*/
|
||||
print("gomobile.dart: CwtchGomobile()");
|
||||
androidHomeDirectory = getApplicationDocumentsDirectory();
|
||||
androidLibraryDir = appInfoPlatform.invokeMethod('getNativeLibDir');
|
||||
}
|
||||
|
||||
void Start() async {
|
||||
var androidHome = getApplicationDocumentsDirectory();
|
||||
var androidLibDir = appInfoPlatform.invokeMethod('getNativeLibDir');
|
||||
|
||||
var cwtchDir = path.join((await androidHome).path, ".cwtch/dev/");
|
||||
String torPath = path.join(await androidLibDir, "libtor.so");
|
||||
print("gomobile.dart: Start($cwtchDir, $torPath)");
|
||||
Future<void> Start() async {
|
||||
print("gomobile.dart: Start()...");
|
||||
var cwtchDir = path.join((await androidHomeDirectory).path, ".cwtch/dev/");
|
||||
String torPath = path.join(await androidLibraryDir, "libtor.so");
|
||||
print("gomobile.dart: Start invokeMethod Start($cwtchDir, $torPath)...");
|
||||
cwtchPlatform.invokeMethod("Start", {"appDir": cwtchDir, "torPath": torPath});
|
||||
}
|
||||
|
||||
|
@ -58,6 +49,7 @@ class CwtchGomobile implements Cwtch {
|
|||
}
|
||||
|
||||
Future<String> GetProfiles() {
|
||||
print("gomobile.dart: GetProfiles()");
|
||||
return cwtchPlatform.invokeMethod("GetProfiles");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import 'dart:collection';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_app/cwtch/ffi.dart';
|
||||
import 'package:flutter_app/cwtch/gomobile.dart';
|
||||
|
@ -5,6 +8,7 @@ import 'package:provider/provider.dart';
|
|||
import 'cwtch/cwtch.dart';
|
||||
import 'model.dart';
|
||||
import 'views/profilemgrview.dart';
|
||||
import 'views/splashView.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'dart:io' show Platform;
|
||||
import 'package:path/path.dart' as path;
|
||||
|
@ -23,50 +27,81 @@ class FlwtchState extends State<Flwtch> {
|
|||
final TextStyle biggerFont = const TextStyle(fontSize: 18);
|
||||
|
||||
Cwtch cwtch;
|
||||
bool cwtchInit = false;
|
||||
AppModel appStatus;
|
||||
|
||||
HashMap<String, ProfileModel> profiles;
|
||||
|
||||
|
||||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
cwtchInit = false;
|
||||
profiles = new HashMap<String, ProfileModel>();
|
||||
|
||||
print("FlwtchState.initState()");
|
||||
|
||||
if (Platform.isAndroid) {
|
||||
cwtch = CwtchGomobile();
|
||||
} else {
|
||||
cwtch = CwtchFfi();
|
||||
}
|
||||
cwtch.Start().then((val) {
|
||||
setState(() {
|
||||
cwtchInit = true;
|
||||
loadProfiles();
|
||||
});
|
||||
});
|
||||
|
||||
appStatus = AppModel(cwtch: cwtch);
|
||||
// Timing issue? Start may not have inited cwtch yet when we ask for getProfiles...
|
||||
}
|
||||
|
||||
void loadProfiles() {
|
||||
cwtch.GetProfiles().then((jsonProfiles) {
|
||||
print("got profiles: $jsonProfiles");
|
||||
setState(() {
|
||||
Map<String, dynamic> _profiles = jsonDecode(jsonProfiles);
|
||||
_profiles.forEach((onion, nick) {
|
||||
print(" profile $nick $onion");
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
appStatus = AppModel(cwtch: cwtch);
|
||||
cwtch.Start();
|
||||
|
||||
return Provider<FlwtchState>(
|
||||
create: (_) => this,
|
||||
child: MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
theme: ThemeData(
|
||||
// This is the theme of your application.
|
||||
//
|
||||
// Try running your application with "flutter run". You'll see the
|
||||
// application has a blue toolbar. Then, without quitting the app, try
|
||||
// changing the primarySwatch below to Colors.green and then invoke
|
||||
// "hot reload" (press "r" in the console where you ran "flutter run",
|
||||
// or simply save your changes to "hot reload" in a Flutter IDE).
|
||||
// Notice that the counter didn't reset back to zero; the application
|
||||
// is not restarted.
|
||||
primarySwatch: Colors.blue,
|
||||
// This makes the visual density adapt to the platform that you run
|
||||
// the app on. For desktop platforms, the controls will be smaller and
|
||||
// closer together (more dense) than on mobile platforms.
|
||||
visualDensity: VisualDensity.adaptivePlatformDensity,
|
||||
primaryColor: Color(0xFF4B3557),
|
||||
canvasColor: Color(0xFFB09CBC),
|
||||
accentColor: Color(0xFFD01972),
|
||||
),
|
||||
home: ProfileMgrView(),
|
||||
));
|
||||
print("FlwtchState.build() cwtchInit: $cwtchInit");
|
||||
return Provider<FlwtchState>(
|
||||
create: (_) => this,
|
||||
child: MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
theme: ThemeData(
|
||||
// This is the theme of your application.
|
||||
//
|
||||
// Try running your application with "flutter run". You'll see the
|
||||
// application has a blue toolbar. Then, without quitting the app, try
|
||||
// changing the primarySwatch below to Colors.green and then invoke
|
||||
// "hot reload" (press "r" in the console where you ran "flutter run",
|
||||
// or simply save your changes to "hot reload" in a Flutter IDE).
|
||||
// Notice that the counter didn't reset back to zero; the application
|
||||
// is not restarted.
|
||||
primarySwatch: Colors.blue,
|
||||
// This makes the visual density adapt to the platform that you run
|
||||
// the app on. For desktop platforms, the controls will be smaller and
|
||||
// closer together (more dense) than on mobile platforms.
|
||||
visualDensity: VisualDensity.adaptivePlatformDensity,
|
||||
primaryColor: Color(0xFF4B3557),
|
||||
canvasColor: Color(0xFFB09CBC),
|
||||
accentColor: Color(0xFFD01972),
|
||||
),
|
||||
home: cwtchInit == true ? ProfileMgrView() : SplashView(),
|
||||
));
|
||||
}
|
||||
}
|
|
@ -15,31 +15,10 @@ class ProfileMgrView extends StatefulWidget {
|
|||
}
|
||||
|
||||
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) {
|
||||
|
||||
String jsonProfiles = Provider.of<FlwtchState>(context).cwtch.GetProfiles();
|
||||
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);
|
||||
});
|
||||
}
|
||||
print("ProfileMgrViewState.build()");
|
||||
//HashMap<String, ProfileModel> _profiles = Provider.of<FlwtchState>(context).profiles;
|
||||
|
||||
return Scaffold (
|
||||
appBar: AppBar(
|
||||
|
@ -66,11 +45,11 @@ class _ProfileMgrViewState extends State<ProfileMgrView> {
|
|||
}
|
||||
|
||||
String getNick(String profile, String contact) {
|
||||
return contact == profile ? "me" : _profiles[profile].contacts[contact].nickname;
|
||||
return contact == profile ? "me" : Provider.of<FlwtchState>(context).profiles[profile].contacts[contact].nickname;
|
||||
}
|
||||
|
||||
Widget _buildProfileManager() {
|
||||
final tiles = _profiles.values.map(
|
||||
final tiles = Provider.of<FlwtchState>(context).profiles.values.map(
|
||||
(ProfileModel profile) {
|
||||
return ListTile(
|
||||
title: Text(
|
||||
|
|
Loading…
Reference in New Issue