mirror of
https://github.com/ChronosX88/wind.git
synced 2024-11-09 09:11:00 +00:00
Implement newsgroup list loading in sidebar
This commit is contained in:
parent
3b21f987d7
commit
b6a8a9fa96
146
lib/main.dart
146
lib/main.dart
@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:wind/newsgroup_list_view.dart';
|
||||||
import 'package:wind/nntp_client.dart';
|
import 'package:wind/nntp_client.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
@ -12,15 +13,6 @@ class MyApp extends StatelessWidget {
|
|||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: 'Wind',
|
title: 'Wind',
|
||||||
theme: ThemeData(
|
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.indigo,
|
primarySwatch: Colors.indigo,
|
||||||
),
|
),
|
||||||
home: MyHomePage(title: 'Wind'),
|
home: MyHomePage(title: 'Wind'),
|
||||||
@ -31,15 +23,6 @@ class MyApp extends StatelessWidget {
|
|||||||
class MyHomePage extends StatefulWidget {
|
class MyHomePage extends StatefulWidget {
|
||||||
MyHomePage({Key? key, required this.title}) : super(key: key);
|
MyHomePage({Key? key, required this.title}) : super(key: key);
|
||||||
|
|
||||||
// This widget is the home page of your application. It is stateful, meaning
|
|
||||||
// that it has a State object (defined below) that contains fields that affect
|
|
||||||
// how it looks.
|
|
||||||
|
|
||||||
// This class is the configuration for the state. It holds the values (in this
|
|
||||||
// case the title) provided by the parent (in this case the App widget) and
|
|
||||||
// used by the build method of the State. Fields in a Widget subclass are
|
|
||||||
// always marked "final".
|
|
||||||
|
|
||||||
final String title;
|
final String title;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -47,11 +30,13 @@ class MyHomePage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _MyHomePageState extends State<MyHomePage> {
|
class _MyHomePageState extends State<MyHomePage> {
|
||||||
|
late NNTPClient nntpClient;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
var client = NNTPClient("localhost:1120");
|
nntpClient = NNTPClient("localhost:1120");
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -85,16 +70,9 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
fontWeight: FontWeight.bold, fontSize: 20),
|
fontWeight: FontWeight.bold, fontSize: 20),
|
||||||
)),
|
)),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListView(children: [
|
child: Builder(
|
||||||
ListTile(
|
builder: (context) =>
|
||||||
title: Text(
|
NewsgroupListView(nntpClient))),
|
||||||
"test.group",
|
|
||||||
),
|
|
||||||
subtitle: Text("Description of the group"),
|
|
||||||
onTap: () => {},
|
|
||||||
)
|
|
||||||
]),
|
|
||||||
)
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -112,64 +90,64 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
|
|
||||||
class ThreadsListView extends StatefulWidget {
|
class ThreadsListView extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() => _ThreadsListViewState();
|
State<StatefulWidget> createState() => ThreadsListViewState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ThreadsListViewState extends State<ThreadsListView> {
|
class ThreadsListViewState extends State<ThreadsListView> {
|
||||||
|
String currentGroup = "no group selected";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(Object context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(width: 640, child: Center(child: Text(currentGroup)));
|
||||||
width: 640,
|
}
|
||||||
child: ListView(
|
}
|
||||||
children: [
|
|
||||||
SizedBox(height: 10),
|
class ThreadListItemView extends StatelessWidget {
|
||||||
Card(
|
@override
|
||||||
elevation: 5,
|
Widget build(BuildContext context) {
|
||||||
child: InkWell(
|
return Card(
|
||||||
splashColor: Colors.indigo.withAlpha(30),
|
elevation: 5,
|
||||||
onTap: () => {},
|
child: InkWell(
|
||||||
child: Column(
|
splashColor: Colors.indigo.withAlpha(30),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
onTap: () => {},
|
||||||
mainAxisSize: MainAxisSize.min,
|
child: Column(
|
||||||
children: [
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
Container(
|
mainAxisSize: MainAxisSize.min,
|
||||||
child: Text(
|
children: [
|
||||||
"A question for those who watched The Matrix in 1999.",
|
Container(
|
||||||
style: TextStyle(
|
child: Text(
|
||||||
fontWeight: FontWeight.bold, fontSize: 21),
|
"A question for those who watched The Matrix in 1999.",
|
||||||
),
|
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 21),
|
||||||
margin: EdgeInsets.only(top: 16, left: 16, right: 16),
|
),
|
||||||
),
|
margin: EdgeInsets.only(top: 16, left: 16, right: 16),
|
||||||
Container(
|
),
|
||||||
child: Row(
|
Container(
|
||||||
children: [
|
child: Row(
|
||||||
Text(
|
children: [
|
||||||
"@sample_user",
|
Text(
|
||||||
style: TextStyle(
|
"@sample_user",
|
||||||
fontWeight: FontWeight.normal,
|
style: TextStyle(
|
||||||
color: Colors.blue,
|
fontWeight: FontWeight.normal,
|
||||||
fontSize: 15),
|
color: Colors.blue,
|
||||||
),
|
fontSize: 15),
|
||||||
SizedBox(width: 5),
|
),
|
||||||
Text(
|
SizedBox(width: 5),
|
||||||
"14/04/22 Чтв 00:57:52",
|
Text(
|
||||||
style: TextStyle(fontSize: 15),
|
"14/04/22 Чтв 00:57:52",
|
||||||
),
|
style: TextStyle(fontSize: 15),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
margin: EdgeInsets.only(
|
),
|
||||||
top: 5, bottom: 2, left: 16, right: 16),
|
margin: EdgeInsets.only(top: 5, bottom: 2, left: 16, right: 16),
|
||||||
),
|
),
|
||||||
Container(
|
Container(
|
||||||
child: Text(
|
child: Text(
|
||||||
"So I'm 16 years old, and I finally watched the first Matrix movie yesterday, and I found it amazing. Everything about it was wonderful. Anyway, I watched it with my mom and she was gushing over it again, telling me about how it blew her away when she watched it in the theaters when it came out.\nAnd that inspired me to ask this question. To any of you in this subreddit who watched the movie when it was released, do you have any fond memories or stories about your experience in the theater that you can tell me about?\nI'd really like to hear them. 👍",
|
"So I'm 16 years old, and I finally watched the first Matrix movie yesterday, and I found it amazing. Everything about it was wonderful. Anyway, I watched it with my mom and she was gushing over it again, telling me about how it blew her away when she watched it in the theaters when it came out.\nAnd that inspired me to ask this question. To any of you in this subreddit who watched the movie when it was released, do you have any fond memories or stories about your experience in the theater that you can tell me about?\nI'd really like to hear them. 👍",
|
||||||
style: TextStyle(fontSize: 17)),
|
style: TextStyle(fontSize: 17)),
|
||||||
margin: EdgeInsets.all(16),
|
margin: EdgeInsets.all(16),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)),
|
|
||||||
],
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
41
lib/newsgroup_list_view.dart
Normal file
41
lib/newsgroup_list_view.dart
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:wind/nntp_client.dart';
|
||||||
|
|
||||||
|
class NewsgroupListView extends StatelessWidget {
|
||||||
|
final NNTPClient client;
|
||||||
|
|
||||||
|
NewsgroupListView(this.client);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return FutureBuilder<List<GroupInfo>>(
|
||||||
|
future: _fetchList(),
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.hasData) {
|
||||||
|
List<GroupInfo> data = snapshot.data!;
|
||||||
|
return _newgroupListView(data);
|
||||||
|
} else if (snapshot.hasError) {
|
||||||
|
return Text("${snapshot.error}");
|
||||||
|
}
|
||||||
|
return Center(child: CircularProgressIndicator());
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List<GroupInfo>> _fetchList() async {
|
||||||
|
return await client.getNewsGroupList();
|
||||||
|
}
|
||||||
|
|
||||||
|
ListView _newgroupListView(List<GroupInfo> data) {
|
||||||
|
return ListView.builder(
|
||||||
|
itemCount: data.length,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
return ListTile(
|
||||||
|
style: ListTileStyle.drawer,
|
||||||
|
title: Text(data[index].name),
|
||||||
|
subtitle: Text(data[index].description),
|
||||||
|
onTap: () => {});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -17,7 +17,7 @@ class NNTPClient {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var command = commandQueue.removeFirst();
|
var command = commandQueue.removeFirst();
|
||||||
var resp = data as String;
|
var resp = data.toString();
|
||||||
var respLines = resp.split("\r\n");
|
var respLines = resp.split("\r\n");
|
||||||
respLines.removeWhere((element) => element == "");
|
respLines.removeWhere((element) => element == "");
|
||||||
var respCode = int.parse(respLines[0].split(" ")[0]);
|
var respCode = int.parse(respLines[0].split(" ")[0]);
|
||||||
@ -38,6 +38,44 @@ class NNTPClient {
|
|||||||
var result = await cmd.response;
|
var result = await cmd.response;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<List<GroupInfo>> getNewsGroupList() async {
|
||||||
|
List<GroupInfo> l = [];
|
||||||
|
|
||||||
|
var groupMap = {};
|
||||||
|
|
||||||
|
await _sendCommand("LIST", ["NEWSGROUPS"]).then((value) {
|
||||||
|
value.lines.removeAt(0);
|
||||||
|
value.lines.removeLast();
|
||||||
|
value.lines.forEach((element) {
|
||||||
|
var firstSpace = element.indexOf(" ");
|
||||||
|
var name = element.substring(0, firstSpace);
|
||||||
|
groupMap.addAll({
|
||||||
|
name: {"desc": element.substring(firstSpace + 1)}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await _sendCommand("LIST", ["ACTIVE"]).then((value) {
|
||||||
|
value.lines.removeAt(0);
|
||||||
|
value.lines.removeLast();
|
||||||
|
value.lines.forEach((element) {
|
||||||
|
var splitted = element.split(" ");
|
||||||
|
var name = splitted[0];
|
||||||
|
var high = splitted[1];
|
||||||
|
var low = splitted[2];
|
||||||
|
groupMap[name]["high"] = high;
|
||||||
|
groupMap[name]["low"] = low;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
groupMap.forEach((key, value) {
|
||||||
|
l.add(GroupInfo(key, value["desc"], int.parse(value["low"]),
|
||||||
|
int.parse(value["high"])));
|
||||||
|
});
|
||||||
|
|
||||||
|
return l;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _NNTPCommand {
|
class _NNTPCommand {
|
||||||
@ -65,3 +103,12 @@ class _CommandResponse {
|
|||||||
|
|
||||||
_CommandResponse(this.responseCode, this.lines);
|
_CommandResponse(this.responseCode, this.lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class GroupInfo {
|
||||||
|
final String name;
|
||||||
|
final String description;
|
||||||
|
final int lowWater;
|
||||||
|
final int highWater;
|
||||||
|
|
||||||
|
GroupInfo(this.name, this.description, this.lowWater, this.highWater);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user