Skip to content

Commit

Permalink
refactor: upgrade all deps
Browse files Browse the repository at this point in the history
  • Loading branch information
denysvitali committed Mar 26, 2024
1 parent e0c9f1a commit facadb5
Show file tree
Hide file tree
Showing 20 changed files with 750 additions and 709 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"flutterMode": "debug",
"args": [
"--flavor",
"main"
"core"
],
}
]
Expand Down
6 changes: 3 additions & 3 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (keystorePropertiesFile.exists()) {
}

android {
compileSdkVersion 33
compileSdkVersion 34

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -41,8 +41,8 @@ android {

defaultConfig {
applicationId "io.vikunja.app"
minSdkVersion 21
targetSdkVersion 33
minSdkVersion 33
targetSdkVersion 34
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
android:icon="@mipmap/ic_launcher"
android:networkSecurityConfig="@xml/network_security_config"
>
<meta-data android:name="io.flutter.network-policy" android:resource="@xml/network_security_config"/>
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
Expand Down
3 changes: 2 additions & 1 deletion android/app/src/main/res/xml/network_security_config.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.7.20'
ext.kotlin_version = '1.9.23'
repositories {
google()
mavenCentral()
Expand Down
139 changes: 68 additions & 71 deletions lib/api/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:vikunja_app/global.dart';

import '../main.dart';


class Client {
GlobalKey<ScaffoldMessengerState>? global_scaffold_key;
final JsonDecoder _decoder = new JsonDecoder();
Expand All @@ -25,8 +24,6 @@ class Client {

String? post_body;



bool operator ==(dynamic otherClient) {
return otherClient._token == _token;
}
Expand All @@ -36,18 +33,17 @@ class Client {
configure(token: token, base: base, authenticated: authenticated);
}

void reload_ignore_certs(bool? val) {
void reloadIgnoreCerts(bool? val) {
ignoreCertificates = val ?? false;
HttpOverrides.global = new IgnoreCertHttpOverrides(ignoreCertificates);
if(global_scaffold_key == null || global_scaffold_key!.currentContext == null) return;
VikunjaGlobal
.of(global_scaffold_key!.currentContext!)
if (global_scaffold_key == null ||
global_scaffold_key!.currentContext == null) return;
VikunjaGlobal.of(global_scaffold_key!.currentContext!)
.settingsManager
.setIgnoreCertificates(ignoreCertificates);
}

get _headers =>
{
get _headers => {
'Authorization': _token != '' ? 'Bearer $_token' : '',
'Content-Type': 'application/json',
'User-Agent': 'Vikunja Mobile App'
Expand All @@ -59,20 +55,15 @@ class Client {
int get hashCode => _token.hashCode;

void configure({String? token, String? base, bool? authenticated}) {
if (token != null)
_token = token;
if (token != null) _token = token;
if (base != null) {
base = base.replaceAll(" ", "");
if(base.endsWith("/"))
base = base.substring(0,base.length-1);
if (base.endsWith("/")) base = base.substring(0, base.length - 1);
_base = base.endsWith('/api/v1') ? base : '$base/api/v1';
}
if (authenticated != null)
this.authenticated = authenticated;

if (authenticated != null) this.authenticated = authenticated;
}


void reset() {
_token = _base = '';
authenticated = false;
Expand All @@ -84,54 +75,61 @@ class Client {
// why are we doing it like this? because Uri doesnt have setters. wtf.

uri = Uri(
scheme: uri.scheme,
scheme: uri.scheme,
userInfo: uri.userInfo,
host: uri.host,
port: uri.port,
path: uri.path,
//queryParameters: {...uri.queryParameters, ...?queryParameters},
queryParameters: queryParameters,
fragment: uri.fragment
);
fragment: uri.fragment);

return http.get(uri, headers: _headers)
.then(_handleResponse).onError((error, stackTrace) =>
_handleError(error, stackTrace));
return http
.get(uri, headers: _headers)
.then(_handleResponse)
.onError((error, stackTrace) => _handleError(error, stackTrace));
}

Future<Response?> delete(String url) {
return http.delete(
'${this.base}$url'.toUri()!,
headers: _headers,
).then(_handleResponse).onError((error, stackTrace) =>
_handleError(error, stackTrace));
return http
.delete(
'${this.base}$url'.toUri()!,
headers: _headers,
)
.then(_handleResponse)
.onError((error, stackTrace) => _handleError(error, stackTrace));
}

Future<Response?> post(String url, {dynamic body}) {
return http.post(
'${this.base}$url'.toUri()!,
headers: _headers,
body: _encoder.convert(body),
)
.then(_handleResponse).onError((error, stackTrace) =>
_handleError(error, stackTrace));
return http
.post(
'${this.base}$url'.toUri()!,
headers: _headers,
body: _encoder.convert(body),
)
.then(_handleResponse)
.onError((error, stackTrace) => _handleError(error, stackTrace));
}

Future<Response?> put(String url, {dynamic body}) {
return http.put(
'${this.base}$url'.toUri()!,
headers: _headers,
body: _encoder.convert(body),
)
.then(_handleResponse).onError((error, stackTrace) =>
_handleError(error, stackTrace));
return http
.put(
'${this.base}$url'.toUri()!,
headers: _headers,
body: _encoder.convert(body),
)
.then(_handleResponse)
.onError((error, stackTrace) => _handleError(error, stackTrace));
}

Response? _handleError(Object? e, StackTrace? st) {
if(global_scaffold_key == null) return null;
if (global_scaffold_key == null) return null;
SnackBar snackBar = SnackBar(
content: Text("Error on request: " + e.toString()),
action: SnackBarAction(label: "Clear", onPressed: () => global_scaffold_key!.currentState?.clearSnackBars()),);
action: SnackBarAction(
label: "Clear",
onPressed: () => global_scaffold_key!.currentState?.clearSnackBars()),
);
global_scaffold_key!.currentState?.showSnackBar(snackBar);
return null;
}
Expand All @@ -144,39 +142,38 @@ class Client {
return map;
}


Error? _handleResponseErrors(http.Response response) {
if (response.statusCode < 200 ||
response.statusCode >= 400) {
if (response.statusCode < 200 || response.statusCode >= 400) {
Map<String, dynamic> error;
error = _decoder.convert(response.body);


final SnackBar snackBar = SnackBar(
content: Text(
"Error code " + response.statusCode.toString() + " received."),
action: globalNavigatorKey.currentContext == null ? null : SnackBarAction(
label: ("Details"),
onPressed: () {
showDialog(
context: globalNavigatorKey.currentContext!,
builder: (BuildContext context) =>
AlertDialog(
title: Text("Error ${response.statusCode}"),
content: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text("Message: ${error["message"]}", textAlign: TextAlign.start,),
Text("Url: ${response.request!.url.toString()}"),
],
)
)
);
},
),
content:
Text("Error code " + response.statusCode.toString() + " received."),
action: globalNavigatorKey.currentContext == null
? null
: SnackBarAction(
label: ("Details"),
onPressed: () {
showDialog(
context: globalNavigatorKey.currentContext!,
builder: (BuildContext context) => AlertDialog(
title: Text("Error ${response.statusCode}"),
content: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
"Message: ${error["message"]}",
textAlign: TextAlign.start,
),
Text("Url: ${response.request!.url.toString()}"),
],
)));
},
),
);
if(global_scaffold_key != null && showSnackBar)
if (global_scaffold_key != null && showSnackBar)
global_scaffold_key!.currentState?.showSnackBar(snackBar);
else
print("error on request: ${error["message"]}");
Expand Down
64 changes: 30 additions & 34 deletions lib/api/list_implementation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ import 'package:vikunja_app/service/services.dart';

class ListAPIService extends APIService implements ListService {
FlutterSecureStorage _storage;
ListAPIService(Client client, FlutterSecureStorage storage) : _storage = storage, super(client);
ListAPIService(Client client, FlutterSecureStorage storage)
: _storage = storage,
super(client);

@override
Future<TaskList?> create(namespaceId, TaskList tl) {
tl.namespaceId = namespaceId;
return client
.put('/namespaces/$namespaceId/lists', body: tl.toJSON())
.then((response) {
if (response == null) return null;
return TaskList.fromJson(response.body);
});
if (response == null) return null;
return TaskList.fromJson(response.body);
});
}

@override
Expand All @@ -32,60 +34,55 @@ class ListAPIService extends APIService implements ListService {
if (response == null) return null;
final map = response.body;
if (map.containsKey('id')) {
return client
.get("/lists/$listId/tasks")
.then((tasks) {
map['tasks'] = tasks?.body;
return TaskList.fromJson(map);
});
return client.get("/lists/$listId/tasks").then((tasks) {
map['tasks'] = tasks?.body;
return TaskList.fromJson(map);
});
}
return TaskList.fromJson(map);
});
}

@override
Future<List<TaskList>?> getAll() {
return client.get('/lists').then(
(list) {
if (list == null || list.statusCode != 200) return null;
if (list.body.toString().isEmpty)
return Future.value([]);
print(list.statusCode);
return convertList(list.body, (result) => TaskList.fromJson(result));});
return client.get('/lists').then((list) {
if (list == null || list.statusCode != 200) return null;
if (list.body.toString().isEmpty) return Future.value([]);
print(list.statusCode);
return convertList(list.body, (result) => TaskList.fromJson(result));
});
}

@override
Future<List<TaskList>?> getByNamespace(int namespaceId) {
// TODO there needs to be a better way for this. /namespaces/-2/lists should
// return favorite lists
if(namespaceId == -2) {
if (namespaceId == -2) {
// Favourites.
return getAll().then((value) {
if (value == null) return null;
value.removeWhere((element) => !element.isFavorite); return value;});
value.removeWhere((element) => !element.isFavorite);
return value;
});
}
return client.get('/namespaces/$namespaceId/lists').then(
(list) {
if (list == null || list.statusCode != 200) return null;
return convertList(list.body, (result) => TaskList.fromJson(result));
});
return client.get('/namespaces/$namespaceId/lists').then((list) {
if (list == null || list.statusCode != 200) return null;
return convertList(list.body, (result) => TaskList.fromJson(result));
});
}

@override
Future<TaskList?> update(TaskList tl) {
return client
.post('/lists/${tl.id}', body: tl.toJSON())
.then((response) {
if (response == null) return null;
return TaskList.fromJson(response.body);
});
return client.post('/lists/${tl.id}', body: tl.toJSON()).then((response) {
if (response == null) return null;
return TaskList.fromJson(response.body);
});
}

@override
Future<String> getDisplayDoneTasks(int listId) {
return _storage.read(key: "display_done_tasks_list_$listId").then((value)
{
if(value == null) {
return _storage.read(key: "display_done_tasks_list_$listId").then((value) {
if (value == null) {
// TODO: implement default value
setDisplayDoneTasks(listId, "1");
return Future.value("1");
Expand All @@ -104,7 +101,6 @@ class ListAPIService extends APIService implements ListService {
return _storage.read(key: "default_list_id");
}

@override
void setDefaultList(int? listId) {
_storage.write(key: "default_list_id", value: listId.toString());
}
Expand Down
Loading

0 comments on commit facadb5

Please sign in to comment.