mirror of
				https://github.com/johrpan/musicus_mobile.git
				synced 2025-10-26 18:57: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/isolate.dart'; | ||||||
| import 'package:moor/moor.dart'; | import 'package:moor/moor.dart'; | ||||||
| import 'package:moor_ffi/moor_ffi.dart'; | import 'package:moor_ffi/moor_ffi.dart'; | ||||||
|  | import 'package:musicus_client/musicus_client.dart'; | ||||||
| import 'package:musicus_database/musicus_database.dart'; | import 'package:musicus_database/musicus_database.dart'; | ||||||
| import 'package:path/path.dart' as p; | import 'package:path/path.dart' as p; | ||||||
| import 'package:path_provider/path_provider.dart' as pp; | import 'package:path_provider/path_provider.dart' as pp; | ||||||
|  | import 'package:rxdart/rxdart.dart'; | ||||||
| import 'package:shared_preferences/shared_preferences.dart'; | import 'package:shared_preferences/shared_preferences.dart'; | ||||||
| 
 | 
 | ||||||
| import 'music_library.dart'; | import 'music_library.dart'; | ||||||
|  | @ -86,6 +88,10 @@ class BackendState extends State<Backend> { | ||||||
| 
 | 
 | ||||||
|   BackendStatus status = BackendStatus.loading; |   BackendStatus status = BackendStatus.loading; | ||||||
|   Database db; |   Database db; | ||||||
|  | 
 | ||||||
|  |   final musicusServerUrl = BehaviorSubject<String>(); | ||||||
|  |   MusicusClient client; | ||||||
|  | 
 | ||||||
|   String musicLibraryUri; |   String musicLibraryUri; | ||||||
|   MusicLibrary ml; |   MusicLibrary ml; | ||||||
| 
 | 
 | ||||||
|  | @ -113,6 +119,12 @@ class BackendState extends State<Backend> { | ||||||
|     db = Database.connect(dbConnection); |     db = Database.connect(dbConnection); | ||||||
| 
 | 
 | ||||||
|     _shPref = await SharedPreferences.getInstance(); |     _shPref = await SharedPreferences.getInstance(); | ||||||
|  |     final url = _shPref.getString('musicusServerUrl'); | ||||||
|  |     musicusServerUrl.add(url); | ||||||
|  |     if (url != null) { | ||||||
|  |       client = MusicusClient(url); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     musicLibraryUri = _shPref.getString('musicLibraryUri'); |     musicLibraryUri = _shPref.getString('musicLibraryUri'); | ||||||
| 
 | 
 | ||||||
|     _loadMusicLibrary(); |     _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 |   @override | ||||||
|   void dispose() { |   void dispose() { | ||||||
|     super.dispose(); |     super.dispose(); | ||||||
|  |     client.dispose(); | ||||||
|     _moorIsolate.shutdownAll(); |     _moorIsolate.shutdownAll(); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -21,6 +21,52 @@ class SettingsScreen extends StatelessWidget { | ||||||
|               backend.chooseMusicLibraryUri(); |               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 |     sdk: flutter | ||||||
|   moor: |   moor: | ||||||
|   moor_ffi: |   moor_ffi: | ||||||
|  |   musicus_client: | ||||||
|  |     path: ../client | ||||||
|   musicus_database: |   musicus_database: | ||||||
|     path: ../database |     path: ../database | ||||||
|   musicus_player: |   musicus_player: | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Elias Projahn
						Elias Projahn