mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 10:47:25 +01:00
mobile: Add Musicus client
The settings screen now contains a tile to change the URL of the Musicus server.
This commit is contained in:
parent
8ca510e041
commit
d2a8363f6f
3 changed files with 76 additions and 0 deletions
|
|
@ -6,9 +6,11 @@ import 'package:flutter/widgets.dart';
|
|||
import 'package:moor/isolate.dart';
|
||||
import 'package:moor/moor.dart';
|
||||
import 'package:moor_ffi/moor_ffi.dart';
|
||||
import 'package:musicus_client/musicus_client.dart';
|
||||
import 'package:musicus_database/musicus_database.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:path_provider/path_provider.dart' as pp;
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'music_library.dart';
|
||||
|
|
@ -86,6 +88,10 @@ class BackendState extends State<Backend> {
|
|||
|
||||
BackendStatus status = BackendStatus.loading;
|
||||
Database db;
|
||||
|
||||
final musicusServerUrl = BehaviorSubject<String>();
|
||||
MusicusClient client;
|
||||
|
||||
String musicLibraryUri;
|
||||
MusicLibrary ml;
|
||||
|
||||
|
|
@ -113,6 +119,12 @@ class BackendState extends State<Backend> {
|
|||
db = Database.connect(dbConnection);
|
||||
|
||||
_shPref = await SharedPreferences.getInstance();
|
||||
final url = _shPref.getString('musicusServerUrl');
|
||||
musicusServerUrl.add(url);
|
||||
if (url != null) {
|
||||
client = MusicusClient(url);
|
||||
}
|
||||
|
||||
musicLibraryUri = _shPref.getString('musicLibraryUri');
|
||||
|
||||
_loadMusicLibrary();
|
||||
|
|
@ -145,9 +157,25 @@ class BackendState extends State<Backend> {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> setMusicusServer(String serverUrl) async {
|
||||
final url = serverUrl.isNotEmpty ? serverUrl : null;
|
||||
await _shPref.setString('musicusServerUrl', url);
|
||||
|
||||
if (client != null) {
|
||||
client.dispose();
|
||||
}
|
||||
|
||||
if (url != null) {
|
||||
client = MusicusClient(url);
|
||||
}
|
||||
|
||||
musicusServerUrl.add(url);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
client.dispose();
|
||||
_moorIsolate.shutdownAll();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,52 @@ class SettingsScreen extends StatelessWidget {
|
|||
backend.chooseMusicLibraryUri();
|
||||
},
|
||||
),
|
||||
StreamBuilder<String>(
|
||||
stream: backend.musicusServerUrl,
|
||||
builder: (context, snapshot) {
|
||||
return ListTile(
|
||||
leading: Icon(Icons.router),
|
||||
title: Text('Musicus server'),
|
||||
subtitle: Text(snapshot.data ?? 'Set server URL'),
|
||||
onTap: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
final controller = TextEditingController();
|
||||
|
||||
if (snapshot.data != null) {
|
||||
controller.text = snapshot.data;
|
||||
}
|
||||
|
||||
return AlertDialog(
|
||||
title: Text('Musicus server'),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Server URL',
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
onPressed: () {
|
||||
backend.setMusicusServer(controller.text);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: Text('SET'),
|
||||
),
|
||||
FlatButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: Text('CANCEL'),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ dependencies:
|
|||
sdk: flutter
|
||||
moor:
|
||||
moor_ffi:
|
||||
musicus_client:
|
||||
path: ../client
|
||||
musicus_database:
|
||||
path: ../database
|
||||
musicus_player:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue