Skip to content

Commit

Permalink
fix json error
Browse files Browse the repository at this point in the history
  • Loading branch information
Notsfsssf committed Apr 26, 2021
1 parent aac3f3f commit 832dbdb
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 239 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ android {
applicationId packageName
minSdkVersion 21
targetSdkVersion 30
versionCode 10004063
versionName "0.4.7 X "
versionCode 10004070
versionName "0.4.7 Los"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand Down
4 changes: 2 additions & 2 deletions lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/

class Constants {
static String tagName = "0.4.6";
static String tagName = "0.4.7";

// static bool isGooglePlay =
// bool.fromEnvironment("IS_GOOGLEPLAY", defaultValue: false);//为何没用啊咕鸽?
static bool isGooglePlay = false;
static bool isGooglePlay = true;
static int type = 0;
static String? code_verifier = null;
}
5 changes: 0 additions & 5 deletions lib/models/bookmark.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ class BookmarkRsp {

factory BookmarkRsp.fromJson(Map<String, dynamic> json) => _$BookmarkRspFromJson(json);
Map<String, dynamic> toJson() => _$BookmarkRspToJson(this);

@override
String toString() {
return json.encode(this);
}
}

@JsonSerializable()
Expand Down
125 changes: 22 additions & 103 deletions lib/models/spotlight_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,42 @@
// To parse this JSON data, do
//
// final spotlightResponse = spotlightResponseFromJson(jsonString);
import 'dart:convert';
import 'package:json_annotation/json_annotation.dart';

SpotlightResponse spotlightResponseFromJson(String str) =>
SpotlightResponse.fromJson(json.decode(str));

String spotlightResponseToJson(SpotlightResponse data) =>
json.encode(data.toJson());
part 'spotlight_response.g.dart';

@JsonSerializable()
class SpotlightResponse {
@JsonKey(name: 'spotlight_articles')
List<SpotlightArticle> spotlightArticles;
String nextUrl;
@JsonKey(name: 'next_url')
String? nextUrl;

SpotlightResponse({
required this.spotlightArticles,
required this.nextUrl,
this.nextUrl,
});

SpotlightResponse copyWith({
List<SpotlightArticle>? spotlightArticles,
String? nextUrl,
}) =>
SpotlightResponse(
spotlightArticles: spotlightArticles ?? this.spotlightArticles,
nextUrl: nextUrl ?? this.nextUrl,
);

factory SpotlightResponse.fromJson(Map<String, dynamic> json) =>
SpotlightResponse(
spotlightArticles: List<SpotlightArticle>.from(
json["spotlight_articles"]
.map((x) => SpotlightArticle.fromJson(x))),
nextUrl: json["next_url"],
);
_$SpotlightResponseFromJson(json);

Map<String, dynamic> toJson() => {
"spotlight_articles":
List<dynamic>.from(spotlightArticles.map((x) => x.toJson())),
"next_url": nextUrl,
};
Map<String, dynamic> toJson() => _$SpotlightResponseToJson(this);
}

@JsonSerializable()
class SpotlightArticle {
int id;
String title;
@JsonKey(name: 'pure_title')
String pureTitle;
@JsonKey(name: 'thumbnail')
String thumbnail;
@JsonKey(name: 'article_url')
String articleUrl;
@JsonKey(name: 'publish_date')
DateTime publishDate;
Category? category;
SubcategoryLabel? subcategoryLabel;
// Category? category;
// @JsonKey(name: 'subcategory_label')
// SubcategoryLabel? subcategoryLabel;

SpotlightArticle({
required this.id,
Expand All @@ -75,79 +61,12 @@ class SpotlightArticle {
required this.thumbnail,
required this.articleUrl,
required this.publishDate,
required this.category,
required this.subcategoryLabel,
// this.category,
// required this.subcategoryLabel,
});

SpotlightArticle copyWith({
required int id,
required String title,
required String pureTitle,
required String thumbnail,
required String articleUrl,
required DateTime publishDate,
Category? category,
SubcategoryLabel? subcategoryLabel,
}) =>
SpotlightArticle(
id: id,
title: title,
pureTitle: pureTitle,
thumbnail: thumbnail,
articleUrl: articleUrl,
publishDate: publishDate,
category: category ?? this.category,
subcategoryLabel: subcategoryLabel ?? this.subcategoryLabel,
);

factory SpotlightArticle.fromJson(Map<String, dynamic> json) =>
SpotlightArticle(
id: json["id"],
title: json["title"],
pureTitle: json["pure_title"],
thumbnail: json["thumbnail"],
articleUrl: json["article_url"],
publishDate: DateTime.parse(json["publish_date"]),
category: categoryValues.map[json["category"]],
subcategoryLabel: subcategoryLabelValues.map[json["subcategory_label"]],
);

Map<String, dynamic> toJson() => {
"id": id,
"title": title,
"pure_title": pureTitle,
"thumbnail": thumbnail,
"article_url": articleUrl,
"publish_date": publishDate.toIso8601String(),
"category": categoryValues.reverse[category],
"subcategory_label": subcategoryLabelValues.reverse[subcategoryLabel],
};
}

enum Category { SPOTLIGHT, INSPIRATION }
_$SpotlightArticleFromJson(json);

final categoryValues = EnumValues(
{"inspiration": Category.INSPIRATION, "spotlight": Category.SPOTLIGHT});

enum SubcategoryLabel { EMPTY, SUBCATEGORY_LABEL, PURPLE }

final subcategoryLabelValues = EnumValues({
"イラスト": SubcategoryLabel.EMPTY,
"おすすめ": SubcategoryLabel.PURPLE,
"マンガ": SubcategoryLabel.SUBCATEGORY_LABEL
});

class EnumValues<T> {
Map<String, T> map;

Map<T, String>? reverseMap;

EnumValues(this.map);

Map<T, String> get reverse {
if (reverseMap == null) {
reverseMap = map.map((k, v) => new MapEntry(v, k));
}
return reverseMap!;
}
}
Map<String, dynamic> toJson() => _$SpotlightArticleToJson(this);
}
40 changes: 7 additions & 33 deletions lib/models/tags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,28 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import 'dart:convert' show json;

import 'package:json_annotation/json_annotation.dart';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';

part 'tags.g.dart';

@JsonSerializable()
class AutoWords {
List<Tags> tags;

AutoWords({
required this.tags,
});

factory AutoWords.fromJson(jsonRes) {
List<Tags> tags = [];
for (var item in jsonRes['tags']) {
if (item != null) {
tags.add(Tags.fromJson(item));
}
}
return AutoWords(
tags: tags,
);
}

Map<String, dynamic> toJson() => {
'tags': tags,
};
factory AutoWords.fromJson(Map<String, dynamic> json) =>
_$AutoWordsFromJson(json);

@override
String toString() {
return json.encode(this);
}
Map<String, dynamic> toJson() => _$AutoWordsToJson(this);
}

@JsonSerializable()
class Tags {
String name;
String? translated_name;
Expand All @@ -59,20 +44,9 @@ class Tags {
this.translated_name,
});

factory Tags.fromJson(jsonRes) => Tags(
name: jsonRes['name'],
translated_name: jsonRes['translated_name'],
);
factory Tags.fromJson(Map<String, dynamic> json) => _$TagsFromJson(json);

Map<String, dynamic> toJson() => {
'name': name,
'translated_name': translated_name,
};

@override
String toString() {
return json.encode(this);
}
Map<String, dynamic> toJson() => _$TagsToJson(this);
}

@JsonSerializable()
Expand Down
52 changes: 18 additions & 34 deletions lib/models/ugoira_metadata_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,28 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import 'dart:convert';
import 'package:json_annotation/json_annotation.dart';

UgoiraMetadataResponse ugoiraMetadataResponseFromJson(String str) =>
UgoiraMetadataResponse.fromJson(json.decode(str));

String ugoiraMetadataResponseToJson(UgoiraMetadataResponse data) =>
json.encode(data.toJson());
part 'ugoira_metadata_response.g.dart';

@JsonSerializable()
class UgoiraMetadataResponse {
@JsonKey(name: 'ugoira_metadata')
UgoiraMetadata ugoiraMetadata;

UgoiraMetadataResponse({
required this.ugoiraMetadata,
});

factory UgoiraMetadataResponse.fromJson(Map<String, dynamic> json) =>
UgoiraMetadataResponse(
ugoiraMetadata: UgoiraMetadata.fromJson(json["ugoira_metadata"]),
);
_$UgoiraMetadataResponseFromJson(json);

Map<String, dynamic> toJson() => {
"ugoira_metadata": ugoiraMetadata.toJson(),
};
Map<String, dynamic> toJson() => _$UgoiraMetadataResponseToJson(this);
}

@JsonSerializable()
class UgoiraMetadata {
@JsonKey(name: 'zip_urls')
ZipUrls zipUrls;
List<Frame> frames;

Expand All @@ -47,17 +43,13 @@ class UgoiraMetadata {
required this.frames,
});

factory UgoiraMetadata.fromJson(Map<String, dynamic> json) => UgoiraMetadata(
zipUrls: ZipUrls.fromJson(json["zip_urls"]),
frames: List<Frame>.from(json["frames"].map((x) => Frame.fromJson(x))),
);
factory UgoiraMetadata.fromJson(Map<String, dynamic> json) =>
_$UgoiraMetadataFromJson(json);

Map<String, dynamic> toJson() => {
"zip_urls": zipUrls.toJson(),
"frames": List<dynamic>.from(frames.map((x) => x.toJson())),
};
Map<String, dynamic> toJson() => _$UgoiraMetadataToJson(this);
}

@JsonSerializable()
class Frame {
String file;
int delay;
Expand All @@ -67,29 +59,21 @@ class Frame {
required this.delay,
});

factory Frame.fromJson(Map<String, dynamic> json) => Frame(
file: json["file"],
delay: json["delay"],
);
factory Frame.fromJson(Map<String, dynamic> json) => _$FrameFromJson(json);

Map<String, dynamic> toJson() => {
"file": file,
"delay": delay,
};
Map<String, dynamic> toJson() => _$FrameToJson(this);
}

@JsonSerializable()
class ZipUrls {
String medium;

ZipUrls({
required this.medium,
});

factory ZipUrls.fromJson(Map<String, dynamic> json) => ZipUrls(
medium: json["medium"],
);
factory ZipUrls.fromJson(Map<String, dynamic> json) =>
_$ZipUrlsFromJson(json);

Map<String, dynamic> toJson() => {
"medium": medium,
};
Map<String, dynamic> toJson() => _$ZipUrlsToJson(this);
}
Loading

0 comments on commit 832dbdb

Please sign in to comment.