-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
323 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,3 +49,5 @@ target/ | |
|
||
# Generated messages | ||
*/**/messages/ | ||
|
||
.vscode |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import 'dart:developer' as dev; | ||
|
||
import 'package:bloc/bloc.dart'; | ||
import 'package:fixnum/fixnum.dart'; | ||
import 'package:meta/meta.dart'; | ||
|
||
import 'package:anime_kanri/messages/nyaa_search.pb.dart' as nyaa_search; | ||
import 'package:rinf/rinf.dart'; | ||
|
||
part 'get_torrents_event.dart'; | ||
part 'get_torrents_state.dart'; | ||
|
||
class GetTorrentsBloc extends Bloc<GetTorrentsEvent, GetTorrentsState> { | ||
GetTorrentsBloc() : super(GetTorrentsInitial()) { | ||
on<GetTorrents>((event, emit) async { | ||
emit(GetTorrentsLoading()); | ||
dev.log('start loading'); | ||
try { | ||
if (event.search.isNotEmpty) { | ||
final requestMessage = nyaa_search.ReadRequest( | ||
searchInput: event.search, | ||
pageInput: Int64(event.page), | ||
); | ||
final rustRequest = RustRequest( | ||
resource: nyaa_search.ID, | ||
operation: RustOperation.Read, | ||
message: requestMessage.writeToBuffer(), | ||
); | ||
|
||
final rustResponse = await requestToRust(rustRequest); | ||
|
||
if (rustResponse.message == null) { | ||
emit(GetTorrentsFailure('Rust Message is null')); | ||
return; | ||
} | ||
|
||
final responseMessage = nyaa_search.ReadResponse.fromBuffer( | ||
rustResponse.message!, | ||
); | ||
|
||
dev.log('successfully load'); | ||
emit(GetTorrentsSuccess(responseMessage)); | ||
} else { | ||
emit(GetTorrentsInitial()); | ||
} | ||
} catch (e) { | ||
dev.log(e.toString()); | ||
emit(GetTorrentsFailure(e.toString())); | ||
rethrow; | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
part of 'get_torrents_bloc.dart'; | ||
|
||
@immutable | ||
sealed class GetTorrentsEvent {} | ||
|
||
class GetTorrents extends GetTorrentsEvent { | ||
GetTorrents(this.search, this.page); | ||
|
||
final String search; | ||
final int page; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
part of 'get_torrents_bloc.dart'; | ||
|
||
@immutable | ||
sealed class GetTorrentsState {} | ||
|
||
final class GetTorrentsInitial extends GetTorrentsState {} | ||
|
||
final class GetTorrentsLoading extends GetTorrentsState {} | ||
|
||
final class GetTorrentsFailure extends GetTorrentsState { | ||
GetTorrentsFailure(this.errorMsg); | ||
|
||
final String errorMsg; | ||
} | ||
|
||
final class GetTorrentsSuccess extends GetTorrentsState { | ||
GetTorrentsSuccess(this.searchInfo); | ||
|
||
final nyaa_search.ReadResponse searchInfo; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:anime_kanri/messages/nyaa_search.pb.dart' as nyaa_rsearch; | ||
import 'package:flutter/services.dart'; | ||
|
||
class TorrentItem extends StatelessWidget { | ||
const TorrentItem({required this.torrent, super.key}); | ||
|
||
final nyaa_rsearch.Torrent torrent; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Card( | ||
elevation: 0, | ||
color: Theme.of(context).colorScheme.surfaceVariant, | ||
child: Padding( | ||
padding: const EdgeInsets.all(8.0), | ||
child: Row( | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
children: [ | ||
Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Text( | ||
torrent.name, | ||
overflow: TextOverflow.clip, | ||
), | ||
Text( | ||
'Seeders : ${torrent.seeders.toString()}', | ||
style: const TextStyle( | ||
color: Colors.green, | ||
), | ||
), | ||
Text( | ||
'Leechers : ${torrent.leechers.toString()}', | ||
style: const TextStyle( | ||
color: Colors.red, | ||
), | ||
), | ||
Text( | ||
'Approved : ${torrent.approved.toString()}', | ||
style: const TextStyle( | ||
color: Colors.green, | ||
), | ||
), | ||
], | ||
), | ||
Column( | ||
children: [ | ||
TextButton( | ||
onPressed: () async { | ||
await Clipboard.setData( | ||
ClipboardData(text: torrent.magnetLink), | ||
); | ||
}, | ||
child: const Text('Copy Magnetlink'), | ||
), | ||
TextButton( | ||
onPressed: () async { | ||
await Clipboard.setData( | ||
ClipboardData(text: torrent.torrentFile), | ||
); | ||
}, | ||
child: const Text('Copy Torrent link'), | ||
), | ||
], | ||
) | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.