Skip to content

Commit

Permalink
fixed build issue
Browse files Browse the repository at this point in the history
  • Loading branch information
CGQAQ committed Jul 30, 2021
1 parent 246534c commit 8526977
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 211 deletions.
2 changes: 1 addition & 1 deletion lib/api/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FictionContent {
// https://cn.ttkan.co/novel/user/page_direct?novel_id=jiansong-danshuiluyu&page=760
final url =
"https://cn.ttkan.co/novel/user/page_direct?novel_id=$novelID&page=$chapterID";
final content = await Http.get(url);
final content = await Http.get(Uri.parse(url));
final dom = parse(content.body);
final fictionTitle = dom
.querySelectorAll(
Expand Down
9 changes: 5 additions & 4 deletions lib/api/detail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class NovelDetail {
static Future<NovelDetail> from(String novelID,
{Language language = Language.ChineseSimplified}) async {
final baseUrl = "https://cn.ttkan.co/novel/chapters/";
final res = await Http.get(baseUrl + novelID);
final res = await Http.get(Uri.parse(baseUrl + novelID));
final dom = parse(res.body);
final novelDetail = NovelDetail();
novelDetail.coverUrl = dom
Expand All @@ -50,11 +50,12 @@ class NovelDetail {
}
novelDetail.description = dom
.querySelector(
"#__layout > div > div:nth-child(2) > div > div.description > p")
"#__layout > div > div:nth-child(2) > div > div.description")
.querySelector("p")
.text;

final res2 = await Http.get(
"https://cn.ttkan.co/api/nq/amp_novel_chapters?${language == Language.ChineseSimplified ? "language=cn" : ""}&novel_id=$novelID");
final res2 = await Http.get(Uri.parse(
"https://cn.ttkan.co/api/nq/amp_novel_chapters?${language == Language.ChineseSimplified ? "language=cn" : ""}&novel_id=$novelID"));

final result = JsonDecoder().convert(res2.body)["items"].map((it) {
return Chapter(it["chapter_name"], it["chapter_id"].toString());
Expand Down
9 changes: 5 additions & 4 deletions lib/api/recommendation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Recommendation {

static Future<Recommendation> create() async {
final url = "https://cn.ttkan.co/";
final res = await Http.get(url);
final res = await Http.get(Uri.parse(url));
final dom = parse(res.body);
final recommends = dom
.querySelectorAll(".rank_frame > div:not(.rank_title) > a")
Expand All @@ -57,8 +57,9 @@ class Recommendation {
.toList();

final categoryRecommends =
dom.querySelectorAll(".frame_body > .pure-g > div").map((e) {
final category = e.querySelector("h2").text.trim();
dom.querySelectorAll(".frame_body > .pure-g > div.hot_cell").map((e) {
final element = e.querySelector("h2");
final category = element.text.trim();
final headerDom = e.querySelector("li").querySelector("a");
final headerDetail =
e.querySelectorAll("li div p").map((e) => e.text).toList();
Expand Down Expand Up @@ -87,6 +88,6 @@ class Recommendation {
}

main() async {
await Recommendation.create();
final reco = await Recommendation.create();
print("hello");
}
2 changes: 1 addition & 1 deletion lib/api/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Language getLanguageFromString(String s) {
Future<List<Novel>> search(String keyword,
{Language language = Language.ChineseTraditional}) async {
final url = (language == Language.ChineseSimplified ? api_cn : api) + keyword;
final res = await Http.get(url);
final res = await Http.get(Uri.parse(url));

final selector = "#__layout > div > div.frame_body > div.pure-g > div";

Expand Down
2 changes: 1 addition & 1 deletion lib/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ CREATE TABLE IF NOT EXISTS $_historyTable (
result["chapter_title"],
result["fiction_id"],
result["chapter_id"],
result["content"].split("\n"));
(result["content"] as String).split("\n"));
}

Future<int> cacheIfNotCached(FictionContent fictionContent) async {
Expand Down
178 changes: 86 additions & 92 deletions lib/pages/fictionrecommand.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:ui';

import 'package:fiction_reader/api/recommendation.dart';
import 'package:fiction_reader/main.dart';
Expand All @@ -17,7 +18,6 @@ class _FictionRecommendationState extends State<FictionRecommendation> {

@override
void initState() {
// TODO: implement initState
super.initState();
Recommendation.create()
.then((value) => _recommendationController.add(value));
Expand All @@ -29,6 +29,85 @@ class _FictionRecommendationState extends State<FictionRecommendation> {
_jumpToDetail(id);
}

List<Widget> _listItem(Recommendation recommend) {
return recommend.categoryRecommends
.asMap()
.map(
(i, e) => MapEntry(
i,
ListView.builder(
itemCount: recommend.categoryRecommends[i].items.length + 1,
itemBuilder: (_, index) {
if (index == 0) {
final data = recommend.categoryRecommends[i].header;
return SizedBox(
height: 100,
child: InkWell(
onTap: () {
_jumpToDetail(data.fictionId);
},
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.only(right: 8),
child: Image.network(data.imageUrl),
),
Expanded(
child: Column(
children: [
Row(
crossAxisAlignment:
CrossAxisAlignment.baseline,
textBaseline: TextBaseline.ideographic,
children: [
Text(
data.title,
style: TextStyle(fontSize: 20),
),
SizedBox(
width: 8,
),
Text(data.author),
]),
Text(
data.description,
overflow: TextOverflow.ellipsis,
),
],
),
)
],
),
),
),
);
} else {
return InkWell(
onTap: () {
_jumpToDetail(recommend
.categoryRecommends[i].items[index - 1].fictionId);
},
child: Padding(
padding: EdgeInsets.all(8),
child: Text(
recommend.categoryRecommends[i].items[index - 1].title,
style: TextStyle(fontSize: 20),
),
),
);
}
},
),
),
)
.values
.toList();
}

@override
Widget build(BuildContext context) {
return Container(
Expand All @@ -48,7 +127,11 @@ class _FictionRecommendationState extends State<FictionRecommendation> {
final data = recommend.recommends[index];
return Stack(
children: [
Image.network(data.novelIMG),
Image.network(
data.novelIMG,
height: 130,
width: 98,
),
Positioned.fill(
child: Material(
color: Colors.transparent,
Expand Down Expand Up @@ -92,96 +175,7 @@ class _FictionRecommendationState extends State<FictionRecommendation> {
),
Expanded(
child: TabBarView(
children: [
...recommend.categoryRecommends
.asMap()
.map(
(i, e) => MapEntry(
i,
ListView.builder(
itemCount: recommend.categoryRecommends[i]
.items.length +
1,
itemBuilder: (_, index) {
if (index == 0) {
final data = recommend
.categoryRecommends[i].header;
return IntrinsicHeight(
child: InkWell(
onTap: () {
_jumpToDetail(data.fictionId);
},
child: Padding(
padding:
const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
children: [
Image.network(
data.imageUrl),
Expanded(
child: Column(
children: [
Row(
crossAxisAlignment:
CrossAxisAlignment
.baseline,
textBaseline:
TextBaseline
.ideographic,
children: [
Text(
data.title,
style: TextStyle(
fontSize:
20),
),
SizedBox(
width: 8,
),
Text(data
.author),
]),
Text(
data.description,
overflow:
TextOverflow
.ellipsis,
),
],
),
)
],
),
),
),
);
} else {
return InkWell(
onTap: () {
_jumpToDetail(recommend
.categoryRecommends[i]
.items[index - 1]
.fictionId);
},
child: Padding(
padding: EdgeInsets.all(8),
child: Text(
recommend.categoryRecommends[i]
.items[index - 1].title,
style: TextStyle(fontSize: 20),
),
),
);
}
},
),
),
)
.values,
],
children: [...this._listItem(recommend)],
),
)
],
Expand Down
Loading

0 comments on commit 8526977

Please sign in to comment.