Skip to content

Commit

Permalink
feat: UI refactor (#204)
Browse files Browse the repository at this point in the history
* refactor: UI refactor

* refactor: UI refactor

* refactor: UI refactor

* refactor: UI refactor

* refactor: UI refactor

* refactor: UI refactor

* refactor: UI refactor

* refactor: UI refactor

* refactor: UI refactor

* refactor: fix & format

* refactor: UI refactor

* refactor: UI refactor

* refactor: UI refactor

* refactor: UI refactor

* refactor: UI refactor

* fix: removed invalid code

* refactor: format

* feat: updated metadata
  • Loading branch information
jhomlala authored Jun 26, 2024
1 parent a3ae2f0 commit 7590c71
Show file tree
Hide file tree
Showing 61 changed files with 1,938 additions and 1,463 deletions.
2 changes: 1 addition & 1 deletion docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

```yaml
dependencies:
alice: ^1.0.0-dev6
alice: ^1.0.0-dev7
```
2. Choose adapter based on your HTTP client. **pubspec.yaml** file:
Expand Down
2 changes: 1 addition & 1 deletion examples/alice_http/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class _MyAppState extends State<MyApp> {
const Text(
style: TextStyle(fontSize: 14),
'Welcome to example of Alice Http Inspector. '
'Click buttons below to generate sample data.',
'Click buttons below to generate sample data.',
),
ElevatedButton(
onPressed: _runHttpHttpRequests,
Expand Down
3 changes: 3 additions & 0 deletions packages/alice/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.0.0-dev-7
* Refactored UI code.

# 1.0.0-dev.6

* [BREAKING_CHANGE] Bumped minimal Flutter version to 3.10.0.
Expand Down
1 change: 1 addition & 0 deletions packages/alice/lib/alice.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class Alice {
return _aliceCore.isInspectorOpened();
}

/// Adds new adapter to Alice.
void addAdapter(AliceAdapter adapter) {
adapter.injectCore(_aliceCore);
}
Expand Down
1 change: 1 addition & 0 deletions packages/alice/lib/core/alice_adapter.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:alice/core/alice_core.dart';

/// Adapter mixin which is used in http client adapters.
mixin AliceAdapter {
late final AliceCore aliceCore;

Expand Down
12 changes: 4 additions & 8 deletions packages/alice/lib/core/alice_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:alice/model/alice_http_call.dart';
import 'package:alice/model/alice_http_error.dart';
import 'package:alice/model/alice_http_response.dart';
import 'package:alice/model/alice_log.dart';
import 'package:alice/ui/page/alice_calls_list_screen.dart';
import 'package:alice/ui/common/alice_navigation.dart';
import 'package:alice/utils/num_comparison.dart';
import 'package:alice/utils/shake_detector.dart';
import 'package:collection/collection.dart' show IterableExtension;
Expand All @@ -17,7 +17,7 @@ import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:rxdart/rxdart.dart';

class AliceCore {
/// Should user be notified with notification if there's new request catched
/// Should user be notified with notification if there's new request caught
/// by Alice
final bool showNotification;

Expand Down Expand Up @@ -136,12 +136,8 @@ class AliceCore {
}
if (!_isInspectorOpened) {
_isInspectorOpened = true;
Navigator.push<void>(
context,
MaterialPageRoute(
builder: (_) => AliceCallsListScreen(this, _aliceLogger),
),
).then((_) => _isInspectorOpened = false);
AliceNavigation.navigateToCallsList(core: this, logger: _aliceLogger)
.then((_) => _isInspectorOpened = false);
}
}

Expand Down
8 changes: 5 additions & 3 deletions packages/alice/lib/core/alice_logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:alice/model/alice_log.dart';
import 'package:alice/utils/num_comparison.dart';
import 'package:flutter/foundation.dart';

/// Logger used to handle logs from application.
class AliceLogger {
AliceLogger({int? maximumSize = 1000}) : _maximumSize = maximumSize;

Expand Down Expand Up @@ -63,8 +64,10 @@ class AliceLogger {
];
}

void clear() => _logs.value.clear();
/// Clears all logs.
void clearLogs() => _logs.value.clear();

/// Returns raw logs from Android via ADB.
Future<String> getAndroidRawLogs() async {
if (Platform.isAndroid) {
final ProcessResult process =
Expand All @@ -74,11 +77,10 @@ class AliceLogger {
return '';
}

/// Clears all raw logs.
Future<void> clearAndroidRawLogs() async {
if (Platform.isAndroid) {
await Process.run('logcat', ['-c']);
}
}

void clearLogs() => logs.clear();
}
2 changes: 2 additions & 0 deletions packages/alice/lib/helper/alice_conversion_helper.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// Helper used in unit conversion.
class AliceConversionHelper {
static const int _kilobyteAsByte = 1000;
static const int _megabyteAsByte = 1000000;
Expand All @@ -13,6 +14,7 @@ class AliceConversionHelper {
_ => '${_formatDouble(bytes / _megabyteAsByte)} MB',
};

/// Formats double with two numbers after dot.
static String _formatDouble(double value) => value.toStringAsFixed(2);

/// Format time in milliseconds
Expand Down
46 changes: 23 additions & 23 deletions packages/alice/lib/helper/alice_save_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import 'dart:convert' show JsonEncoder;
import 'dart:io' show Directory, File, FileMode, IOSink, Platform;

import 'package:alice/core/alice_utils.dart';
import 'package:alice/helper/alice_alert_helper.dart';
import 'package:alice/helper/alice_conversion_helper.dart';
import 'package:alice/helper/operating_system.dart';
import 'package:alice/model/alice_http_call.dart';
import 'package:alice/ui/common/alice_dialog.dart';
import 'package:alice/utils/alice_parser.dart';
import 'package:flutter/material.dart';
import 'package:open_filex/open_filex.dart';
Expand Down Expand Up @@ -58,10 +58,10 @@ class AliceSaveHelper {
if (status) {
await _saveToFile(context, calls);
} else {
AliceAlertHelper.showAlert(
context,
'Permission error',
"Permission not granted. Couldn't save logs.",
AliceGeneralDialog.show(
context: context,
title: 'Permission error',
description: "Permission not granted. Couldn't save logs.",
);
}
}
Expand All @@ -73,10 +73,10 @@ class AliceSaveHelper {
) async {
try {
if (calls.isEmpty) {
AliceAlertHelper.showAlert(
context,
'Error',
'There are no logs to save',
AliceGeneralDialog.show(
context: context,
title: 'Error',
description: 'There are no logs to save',
);
return '';
}
Expand All @@ -100,10 +100,10 @@ class AliceSaveHelper {
await sink.close();

if (context.mounted) {
AliceAlertHelper.showAlert(
context,
'Success',
'Successfully saved logs in ${file.path}',
AliceGeneralDialog.show(
context: context,
title: 'Success',
description: 'Successfully saved logs in ${file.path}',
secondButtonTitle: Platform.isAndroid ? 'View file' : null,
secondButtonAction: () =>
Platform.isAndroid ? OpenFilex.open(file.path) : null,
Expand All @@ -113,19 +113,19 @@ class AliceSaveHelper {
return file.path;
} else {
if (context.mounted) {
AliceAlertHelper.showAlert(
context,
'Error',
'Failed to save http calls to file',
AliceGeneralDialog.show(
context: context,
title: 'Error',
description: 'Failed to save http calls to file',
);
}
}
} catch (exception) {
if (context.mounted) {
AliceAlertHelper.showAlert(
context,
'Error',
'Failed to save http calls to file',
AliceGeneralDialog.show(
context: context,
title: 'Error',
description: 'Failed to save http calls to file',
);
AliceUtils.log(exception.toString());
}
Expand Down Expand Up @@ -179,15 +179,15 @@ class AliceSaveHelper {

stringBuffer.writeAll([
'Request size: ${AliceConversionHelper.formatBytes(call.request?.size ?? 0)}\n',
'Request body: ${AliceParser.formatBody(call.request?.body, call.request?.contentType)}\n',
'Request body: ${AliceBodyParser.formatBody(call.request?.body, call.request?.contentType)}\n',
'--------------------------------------------\n',
'Response\n',
'--------------------------------------------\n',
'Response time: ${call.response?.time}\n',
'Response status: ${call.response?.status}\n',
'Response size: ${AliceConversionHelper.formatBytes(call.response?.size ?? 0)}\n',
'Response headers: ${_encoder.convert(call.response?.headers)}\n',
'Response body: ${AliceParser.formatBody(call.response?.body, AliceParser.getContentType(call.response?.headers))}\n',
'Response body: ${AliceBodyParser.formatBody(call.response?.body, AliceBodyParser.getContentType(call.response?.headers))}\n',
]);

if (call.error != null) {
Expand Down
1 change: 1 addition & 0 deletions packages/alice/lib/helper/operating_system.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// Definition of OS.
abstract class OperatingSystem {
static const String android = 'android';
static const String fuchsia = 'fuchsia';
Expand Down
1 change: 1 addition & 0 deletions packages/alice/lib/model/alice_form_data_file.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// Definition of data holder of form data file.
class AliceFormDataFile {
const AliceFormDataFile(
this.fileName,
Expand Down
1 change: 1 addition & 0 deletions packages/alice/lib/model/alice_from_data_field.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// Definition of form data field.
class AliceFormDataField {
const AliceFormDataField(
this.name,
Expand Down
1 change: 1 addition & 0 deletions packages/alice/lib/model/alice_http_call.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:alice/model/alice_http_error.dart';
import 'package:alice/model/alice_http_request.dart';
import 'package:alice/model/alice_http_response.dart';

/// Definition of http calls data holder.
class AliceHttpCall {
AliceHttpCall(this.id) {
loading = true;
Expand Down
1 change: 1 addition & 0 deletions packages/alice/lib/model/alice_http_error.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// Definition of http error data holder.
class AliceHttpError {
dynamic error;
StackTrace? stackTrace;
Expand Down
1 change: 1 addition & 0 deletions packages/alice/lib/model/alice_http_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io' show Cookie;
import 'package:alice/model/alice_form_data_file.dart';
import 'package:alice/model/alice_from_data_field.dart';

/// Definition of http request data holder.
class AliceHttpRequest {
int size = 0;
DateTime time = DateTime.now();
Expand Down
1 change: 1 addition & 0 deletions packages/alice/lib/model/alice_http_response.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// Definition of http response data holder.
class AliceHttpResponse {
int? status = 0;
int size = 0;
Expand Down
1 change: 1 addition & 0 deletions packages/alice/lib/model/alice_log.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart';

/// Definition of log data holder.
@immutable
class AliceLog with EquatableMixin {
AliceLog({
Expand Down
11 changes: 0 additions & 11 deletions packages/alice/lib/model/alice_menu_item.dart

This file was deleted.

18 changes: 0 additions & 18 deletions packages/alice/lib/model/alice_sort_option.dart

This file was deleted.

11 changes: 0 additions & 11 deletions packages/alice/lib/model/alice_tab_item.dart

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// Definition of tabs used in call details page.
enum AliceCallDetailsTabItem {
overview,
request,
response,
error,
}
20 changes: 20 additions & 0 deletions packages/alice/lib/ui/call_details/model/alice_menu_item.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:flutter/material.dart';

/// Definition of menu item used in call details.
class AliceCallDetailsMenuItem {
const AliceCallDetailsMenuItem(
this.title,
this.iconData,
);

final String title;
final IconData iconData;
}

/// Definition of all call details menu item types.
enum AliceCallDetailsMenuItemType {
sort,
delete,
stats,
save,
}
Loading

0 comments on commit 7590c71

Please sign in to comment.