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