mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 10:17:16 +08:00
apis: port to null safety
This commit is contained in:
@ -1,18 +1,14 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
|
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
|
|
||||||
typedef OAuthCallback = void Function(GitHostException);
|
typedef OAuthCallback = void Function(GitHostException?);
|
||||||
|
|
||||||
abstract class GitHost {
|
abstract class GitHost {
|
||||||
void init(OAuthCallback oAuthCallback);
|
void init(OAuthCallback oAuthCallback);
|
||||||
Future launchOAuthScreen();
|
Future launchOAuthScreen();
|
||||||
|
|
||||||
Future<UserInfo> getUserInfo();
|
Future<UserInfo?> getUserInfo();
|
||||||
Future<List<GitHostRepo>> listRepos();
|
Future<List<GitHostRepo>> listRepos();
|
||||||
Future<GitHostRepo> createRepo(String name);
|
Future<GitHostRepo> createRepo(String name);
|
||||||
Future<GitHostRepo> getRepo(String name);
|
Future<GitHostRepo> getRepo(String name);
|
||||||
@ -25,9 +21,9 @@ class UserInfo {
|
|||||||
final String username;
|
final String username;
|
||||||
|
|
||||||
UserInfo({
|
UserInfo({
|
||||||
@required this.name,
|
required this.name,
|
||||||
@required this.email,
|
required this.email,
|
||||||
@required this.username,
|
required this.username,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,31 +34,31 @@ class GitHostRepo {
|
|||||||
final String description;
|
final String description;
|
||||||
|
|
||||||
final String cloneUrl;
|
final String cloneUrl;
|
||||||
final DateTime updatedAt;
|
final DateTime? updatedAt;
|
||||||
|
|
||||||
final bool private;
|
final bool? private;
|
||||||
final int stars;
|
final int? stars;
|
||||||
final int forks;
|
final int? forks;
|
||||||
final String language;
|
final String? language;
|
||||||
final int issues;
|
final int? issues;
|
||||||
final String license;
|
final String? license;
|
||||||
|
|
||||||
final List<String> tags;
|
final List<String> tags;
|
||||||
|
|
||||||
GitHostRepo({
|
GitHostRepo({
|
||||||
@required this.name,
|
required this.name,
|
||||||
@required this.username,
|
required this.username,
|
||||||
@required this.fullName,
|
required this.fullName,
|
||||||
@required this.description,
|
required this.description,
|
||||||
@required this.cloneUrl,
|
required this.cloneUrl,
|
||||||
@required this.updatedAt,
|
required this.updatedAt,
|
||||||
@required this.private,
|
required this.private,
|
||||||
@required this.stars,
|
required this.stars,
|
||||||
@required this.forks,
|
required this.forks,
|
||||||
@required this.language,
|
required this.language,
|
||||||
@required this.issues,
|
required this.issues,
|
||||||
@required this.tags,
|
required this.tags,
|
||||||
@required this.license,
|
required this.license,
|
||||||
});
|
});
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
@ -94,7 +90,7 @@ class GitHostRepo {
|
|||||||
int get hashCode => toJson().hashCode;
|
int get hashCode => toJson().hashCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
var _mapEquals = (const MapEquality()).equals;
|
final _mapEquals = (const MapEquality()).equals;
|
||||||
|
|
||||||
class GitHostException implements Exception {
|
class GitHostException implements Exception {
|
||||||
static const OAuthFailed = GitHostException("OAuthFailed");
|
static const OAuthFailed = GitHostException("OAuthFailed");
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'githost.dart';
|
import 'githost.dart';
|
||||||
import 'github.dart';
|
import 'github.dart';
|
||||||
import 'gitlab.dart';
|
import 'gitlab.dart';
|
||||||
@ -13,7 +11,7 @@ enum GitHostType {
|
|||||||
Custom,
|
Custom,
|
||||||
}
|
}
|
||||||
|
|
||||||
GitHost createGitHost(GitHostType type) {
|
GitHost? createGitHost(GitHostType type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case GitHostType.GitHub:
|
case GitHostType.GitHub:
|
||||||
return GitHub();
|
return GitHub();
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
@ -104,7 +102,7 @@ class GitHub implements GitHost {
|
|||||||
response.statusCode.toString() +
|
response.statusCode.toString() +
|
||||||
": " +
|
": " +
|
||||||
response.body);
|
response.body);
|
||||||
return null;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
List<dynamic> list = jsonDecode(response.body);
|
List<dynamic> list = jsonDecode(response.body);
|
||||||
@ -164,7 +162,7 @@ class GitHub implements GitHost {
|
|||||||
throw GitHostException.MissingAccessCode;
|
throw GitHostException.MissingAccessCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
var userInfo = await getUserInfo();
|
var userInfo = await (getUserInfo() as FutureOr<UserInfo>);
|
||||||
var owner = userInfo.username;
|
var owner = userInfo.username;
|
||||||
var url = Uri.parse("https://api.github.com/repos/$owner/$name");
|
var url = Uri.parse("https://api.github.com/repos/$owner/$name");
|
||||||
|
|
||||||
@ -222,11 +220,11 @@ class GitHub implements GitHost {
|
|||||||
|
|
||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
GitHostRepo repoFromJson(Map<String, dynamic> parsedJson) {
|
GitHostRepo repoFromJson(Map<String, dynamic> parsedJson) {
|
||||||
DateTime updatedAt;
|
DateTime? updatedAt;
|
||||||
try {
|
try {
|
||||||
updatedAt = DateTime.parse(parsedJson['updated_at'].toString());
|
updatedAt = DateTime.parse(parsedJson['updated_at'].toString());
|
||||||
} catch (e) {
|
} catch (e, st) {
|
||||||
Log.e(e);
|
Log.e("github repoFromJson", ex: e, stacktrace: st);
|
||||||
}
|
}
|
||||||
var licenseMap = parsedJson['license'];
|
var licenseMap = parsedJson['license'];
|
||||||
var fullName = parsedJson['full_name'].toString();
|
var fullName = parsedJson['full_name'].toString();
|
||||||
@ -263,7 +261,7 @@ class GitHub implements GitHost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<UserInfo> getUserInfo() async {
|
Future<UserInfo?> getUserInfo() async {
|
||||||
if (_accessCode.isEmpty) {
|
if (_accessCode.isEmpty) {
|
||||||
throw GitHostException.MissingAccessCode;
|
throw GitHostException.MissingAccessCode;
|
||||||
}
|
}
|
||||||
@ -283,7 +281,7 @@ class GitHub implements GitHost {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> map = jsonDecode(response.body);
|
Map<String, dynamic>? map = jsonDecode(response.body);
|
||||||
if (map == null || map.isEmpty) {
|
if (map == null || map.isEmpty) {
|
||||||
Log.d("Github getUserInfo: jsonDecode Failed " +
|
Log.d("Github getUserInfo: jsonDecode Failed " +
|
||||||
response.statusCode.toString() +
|
response.statusCode.toString() +
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
@ -21,7 +19,7 @@ class GitLab implements GitHost {
|
|||||||
"faf33c3716faf05bfb701b1b31e36c83a23c3ec2d7161f4ff00fba2275524d09";
|
"faf33c3716faf05bfb701b1b31e36c83a23c3ec2d7161f4ff00fba2275524d09";
|
||||||
|
|
||||||
var _platform = const MethodChannel('gitjournal.io/git');
|
var _platform = const MethodChannel('gitjournal.io/git');
|
||||||
var _accessCode = "";
|
String? _accessCode = "";
|
||||||
var _stateOAuth = "";
|
var _stateOAuth = "";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -43,7 +41,7 @@ class GitLab implements GitHost {
|
|||||||
if (state != _stateOAuth) {
|
if (state != _stateOAuth) {
|
||||||
Log.d("GitLab: OAuth State incorrect");
|
Log.d("GitLab: OAuth State incorrect");
|
||||||
Log.d("Required State: " + _stateOAuth);
|
Log.d("Required State: " + _stateOAuth);
|
||||||
Log.d("Actual State: " + state);
|
Log.d("Actual State: " + state!);
|
||||||
callback(GitHostException.OAuthFailed);
|
callback(GitHostException.OAuthFailed);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -72,7 +70,7 @@ class GitLab implements GitHost {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<GitHostRepo>> listRepos() async {
|
Future<List<GitHostRepo>> listRepos() async {
|
||||||
if (_accessCode.isEmpty) {
|
if (_accessCode!.isEmpty) {
|
||||||
throw GitHostException.MissingAccessCode;
|
throw GitHostException.MissingAccessCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +88,7 @@ class GitLab implements GitHost {
|
|||||||
response.statusCode.toString() +
|
response.statusCode.toString() +
|
||||||
": " +
|
": " +
|
||||||
response.body);
|
response.body);
|
||||||
return null;
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
List<dynamic> list = jsonDecode(response.body);
|
List<dynamic> list = jsonDecode(response.body);
|
||||||
@ -107,7 +105,7 @@ class GitLab implements GitHost {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<GitHostRepo> createRepo(String name) async {
|
Future<GitHostRepo> createRepo(String name) async {
|
||||||
if (_accessCode.isEmpty) {
|
if (_accessCode!.isEmpty) {
|
||||||
throw GitHostException.MissingAccessCode;
|
throw GitHostException.MissingAccessCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,11 +144,11 @@ class GitLab implements GitHost {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<GitHostRepo> getRepo(String name) async {
|
Future<GitHostRepo> getRepo(String name) async {
|
||||||
if (_accessCode.isEmpty) {
|
if (_accessCode!.isEmpty) {
|
||||||
throw GitHostException.MissingAccessCode;
|
throw GitHostException.MissingAccessCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
var userInfo = await getUserInfo();
|
var userInfo = await (getUserInfo() as FutureOr<UserInfo>);
|
||||||
var repo = userInfo.username + '%2F' + name;
|
var repo = userInfo.username + '%2F' + name;
|
||||||
var url = Uri.parse(
|
var url = Uri.parse(
|
||||||
"https://gitlab.com/api/v4/projects/$repo?access_token=$_accessCode");
|
"https://gitlab.com/api/v4/projects/$repo?access_token=$_accessCode");
|
||||||
@ -172,7 +170,7 @@ class GitLab implements GitHost {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future addDeployKey(String sshPublicKey, String repo) async {
|
Future addDeployKey(String sshPublicKey, String repo) async {
|
||||||
if (_accessCode.isEmpty) {
|
if (_accessCode!.isEmpty) {
|
||||||
throw GitHostException.MissingAccessCode;
|
throw GitHostException.MissingAccessCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,11 +204,11 @@ class GitLab implements GitHost {
|
|||||||
|
|
||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
GitHostRepo repoFromJson(Map<String, dynamic> parsedJson) {
|
GitHostRepo repoFromJson(Map<String, dynamic> parsedJson) {
|
||||||
DateTime updatedAt;
|
DateTime? updatedAt;
|
||||||
try {
|
try {
|
||||||
updatedAt = DateTime.parse(parsedJson['last_activity_at'].toString());
|
updatedAt = DateTime.parse(parsedJson['last_activity_at'].toString());
|
||||||
} catch (e) {
|
} catch (e, st) {
|
||||||
Log.e(e);
|
Log.e("gitlab repoFromJson", ex: e, stacktrace: st);
|
||||||
}
|
}
|
||||||
var licenseMap = parsedJson['license'];
|
var licenseMap = parsedJson['license'];
|
||||||
|
|
||||||
@ -247,8 +245,8 @@ class GitLab implements GitHost {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<UserInfo> getUserInfo() async {
|
Future<UserInfo?> getUserInfo() async {
|
||||||
if (_accessCode.isEmpty) {
|
if (_accessCode!.isEmpty) {
|
||||||
throw GitHostException.MissingAccessCode;
|
throw GitHostException.MissingAccessCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,7 +262,7 @@ class GitLab implements GitHost {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> map = jsonDecode(response.body);
|
Map<String, dynamic>? map = jsonDecode(response.body);
|
||||||
if (map == null || map.isEmpty) {
|
if (map == null || map.isEmpty) {
|
||||||
Log.d("GitLab getUserInfo: jsonDecode Failed " +
|
Log.d("GitLab getUserInfo: jsonDecode Failed " +
|
||||||
response.statusCode.toString() +
|
response.statusCode.toString() +
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
@ -18,12 +16,10 @@ import 'utils/logger.dart';
|
|||||||
Future<String> getVersionString() async {
|
Future<String> getVersionString() async {
|
||||||
var info = await PackageInfo.fromPlatform();
|
var info = await PackageInfo.fromPlatform();
|
||||||
var versionText = "";
|
var versionText = "";
|
||||||
if (info != null) {
|
versionText = info.appName + " " + info.version + "+" + info.buildNumber;
|
||||||
versionText = info.appName + " " + info.version + "+" + info.buildNumber;
|
|
||||||
|
|
||||||
if (JournalApp.isInDebugMode) {
|
if (JournalApp.isInDebugMode) {
|
||||||
versionText += " (Debug)";
|
versionText += " (Debug)";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return versionText;
|
return versionText;
|
||||||
@ -96,7 +92,7 @@ Future<void> shareNote(Note note) async {
|
|||||||
return Share.share(note.serialize());
|
return Share.share(note.serialize());
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Note> getTodayJournalEntry(NotesFolderFS rootFolder) async {
|
Future<Note?> getTodayJournalEntry(NotesFolderFS rootFolder) async {
|
||||||
var today = DateTime.now();
|
var today = DateTime.now();
|
||||||
var matches = await rootFolder.matchNotes((n) async {
|
var matches = await rootFolder.matchNotes((n) async {
|
||||||
var dt = n.created;
|
var dt = n.created;
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
// @dart=2.9
|
|
||||||
|
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user