Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add library screen #13

Merged
merged 3 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update login screen and API service
  • Loading branch information
jdk-21 committed Dec 17, 2023
commit e45fb5bdd677ac71eb4576079e664641404cf967
124 changes: 66 additions & 58 deletions lib/screens/login_screen.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:jellyflix/providers/auth_provider.dart';
import 'package:jellyflix/screens/home_screen.dart';
import 'package:flutter/material.dart';
Expand All @@ -17,72 +18,79 @@ class LoginScreen extends HookConsumerWidget {
child: SingleChildScrollView(
child: SizedBox(
width: 400,
child: Column(
children: [
Text("Jellyflix",
style: Theme.of(context).textTheme.displaySmall),
const Text(
"Another Jellyfin Client",
),
const SizedBox(
height: 20,
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: TextField(
controller: serverAddress,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Server Address',
hintText: 'http://'),
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: [
Text("Jellyflix",
style: Theme.of(context).textTheme.displaySmall),
const Text(
"Another Jellyfin Client",
),
const SizedBox(
height: 20,
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: TextField(
controller: serverAddress,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Server Address',
hintText: 'http://'),
),
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: TextField(
controller: userName,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'User Name',
Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: TextField(
controller: userName,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'User Name',
),
),
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: TextField(
obscureText: true,
controller: password,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Password',
Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: TextField(
obscureText: true,
controller: password,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Password',
),
),
),
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: SizedBox(
height: 45,
width: 100,
child: FilledButton(
onPressed: () async {
try {
await ref.read(authProvider).login(
serverAddress.text, userName.text, password.text);
if (context.mounted) {
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => const HomeScreen()));
Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: SizedBox(
height: 45,
width: 100,
child: FilledButton(
onPressed: () async {
try {
await ref.read(authProvider).login(
serverAddress.text, userName.text, password.text);
if (context.mounted) {
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => const HomeScreen()));
}
} catch (e) {
// TODO: show error message to user
print(e);
}
} catch (e) {
// TODO: show error message to user
print(e);
}
},
child: const Text("Login"),
},
child: const Text("Login"),
),
),
),
),
],
kIsWeb
? const Text(
"This is a demo version of Jellyflix. To use it, you can use the following credentials: \n\nServer Address: https://demo.jellyfin.org/stable \nUser Name: demo \nand empty password \n\n")
: const SizedBox(),
],
),
),
),
)),
Expand Down
14 changes: 10 additions & 4 deletions lib/services/api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class ApiService {
"Authorization":
"MediaBrowser Client=\"AnotherJellyfinClient\", Device=\"notset\", DeviceId=\"Unknown Device Id\", Version=\"10.8.11\"",
"Content-Type": "application/json",
"Origin": "http://192.168.179.21:8096",
"Connection": "keep-alive",
};

Expand All @@ -32,6 +31,7 @@ class ApiService {

headers["Authorization"] =
"${headers["Authorization"]!}, Token=\"${response.data!.accessToken!}\"";
headers["Origin"] = baseUrl;
_baseUrl = baseUrl;
_user = User(
id: response.data!.user!.id,
Expand All @@ -50,7 +50,12 @@ class ApiService {

NetworkImage getImage(String id, ImageType type) {
String url = "$_baseUrl/Items/$id/Images/${type.name}";
return NetworkImage(url, headers: headers);
try {
return NetworkImage(url, headers: headers);
} catch (e) {
return NetworkImage("https://www.jellyfin.org/images/logo-color.svg",
headers: headers);
}
}

Future getContinueWatching() async {
Expand Down Expand Up @@ -83,8 +88,9 @@ class ApiService {
}

Future getMediaFolders() async {
var response =
await _jellyfinApi!.getLibraryApi().getMediaFolders(headers: headers);
var response = await _jellyfinApi!
.getUserViewsApi()
.getUserViews(userId: _user!.id!, headers: headers);

return response.data!;
}
Expand Down
1 change: 0 additions & 1 deletion lib/services/auth_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class AuthService {
rethrow;
}
}
await _apiService.login(serverAdress, username, password);
await _secureStorageService.write("username", username);
await _secureStorageService.write("password", password);
await _secureStorageService.write("serverAdress", serverAdress);
Expand Down