Skip to content

Commit

Permalink
海外大規模噴火の扱い修正 (#649)
Browse files Browse the repository at this point in the history
* fix: modalの角丸をMaterial3に適合

* fix: WebSocket接続中の判定ミス

* add: 地震履歴一覧・詳細の大規模噴火の扱い修正
  • Loading branch information
YumNumm authored Apr 17, 2024
1 parent 5c47805 commit c03a61a
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 108 deletions.
12 changes: 5 additions & 7 deletions app/lib/core/component/sheet/basic_modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ class BasicModalSheet extends HookWidget {
),
child: DecoratedBox(
decoration: BoxDecoration(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(16),
topRight: Radius.circular(16),
borderRadius:
const BorderRadius.vertical(top: Radius.circular(28)),
color: theme.colorScheme.background,
border: Border.all(
color: theme.colorScheme.onSurface.withOpacity(0.1),
),
color: theme.colorScheme.surface,
boxShadow: const <BoxShadow>[
BoxShadow(color: Colors.black12, blurRadius: 12),
],
),
child: SafeArea(
top: hasAppBar,
Expand Down
19 changes: 19 additions & 0 deletions app/lib/core/extension/earthquake_v1.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:eqapi_types/eqapi_types.dart';

extension EarthquakeV1Ex on EarthquakeV1 {
bool get isVolcano =>
(text?.contains('大規模な噴火が発生しました') ?? false) &&
(text?.contains('実際には、規模の大きな地震は発生していない点に留意') ?? false);

String? get volcanoName {
if (!isVolcano) {
return null;
}

final splitted = text?.split('分頃(日本時間)に') ?? [];
if (splitted.length != 2) {
return null;
}
return splitted[1].split('で大規模な噴火が発生しました')[0];
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:developer';

import 'package:collection/collection.dart';
import 'package:eqapi_types/eqapi_types.dart';
Expand Down Expand Up @@ -183,17 +184,21 @@ class EarthquakeHistoryNotifier extends _$EarthquakeHistoryNotifier {
Future<void> _refreshIfWebsocketNotConnected() async {
// AsyncData以外の場合は何もしない
if (state is! AsyncData<EarthquakeHistoryNotifierState>) {
log('state is not AsyncData<EarthquakeHistoryNotifierState>');
return;
}
// WebSocketが接続されている場合は何もしない
final webSocketState = ref.read(websocketStatusProvider);
if (webSocketState is Connected || webSocketState is Connecting) {
if (webSocketState is Connected || webSocketState is Reconnected) {
log('WebSocket is ${webSocketState.runtimeType}');
return;
}
// パラメータが指定されている場合は何もしない
if (parameter != const EarthquakeHistoryParameter()) {
log('parameter is not default');
return;
}
log('refreshIfWebsocketNotConnected');

// リフレッシュ処理を実行
final repository = ref.read(earthquakeHistoryRepositoryProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:collection/collection.dart';
import 'package:eqapi_types/eqapi_types.dart';
import 'package:eqmonitor/core/component/intenisty/intensity_icon_type.dart';
import 'package:eqmonitor/core/component/intenisty/jma_intensity_icon.dart';
import 'package:eqmonitor/core/extension/earthquake_v1.dart';
import 'package:eqmonitor/core/provider/config/theme/intensity_color/intensity_color_provider.dart';
import 'package:eqmonitor/core/provider/config/theme/intensity_color/model/intensity_color_model.dart';
import 'package:eqmonitor/core/provider/jma_code_table_provider.dart';
Expand Down Expand Up @@ -64,11 +65,26 @@ class EarthquakeHistoryListTile extends HookConsumerWidget {
final theme = Theme.of(context);

final codeTable = ref.watch(jmaCodeTableProvider);

/// 遠地地震かどうか
final isFarEarthquake = item.headline?.contains('海外で規模の大きな地震') ?? false;

/// 噴火かどうか
final isVolcano = item.isVolcano;

final hypoName = useMemoized(
() => codeTable.areaEpicenter.items.firstWhereOrNull(
(e) => int.tryParse(e.code) == item.epicenterCode,
),
[item.epicenterCode],
() {
final volcanoName = item.volcanoName;
if (volcanoName != null) {
return volcanoName;
}
return codeTable.areaEpicenter.items
.firstWhereOrNull(
(e) => int.tryParse(e.code) == item.epicenterCode,
)
?.name;
},
[item],
);
final hypoDetailName = useMemoized(
() => codeTable.areaEpicenterDetail.items.firstWhereOrNull(
Expand All @@ -77,13 +93,6 @@ class EarthquakeHistoryListTile extends HookConsumerWidget {
[item.epicenterDetailCode],
);

/// 遠地地震かどうか
final isFarEarthquake = item.headline?.contains('海外で規模の大きな地震') ?? false;

/// 噴火かどうか
final isVolcano = (item.text?.contains('大規模な噴火が発生しました') ?? false) &&
(item.text?.contains('実際には、規模の大きな地震は発生していない点に留意') ?? false);

final maxIntensityRegionNames = item.maxIntensityRegionNames;
final maxIntensity = item.maxIntensity;
final title = switch ((
Expand All @@ -93,19 +102,19 @@ class EarthquakeHistoryListTile extends HookConsumerWidget {
maxIntensityRegionNames
)) {
(
final AreaEpicenter_AreaEpicenterItem hypoName,
final String hypoName,
final AreaEpicenterDetail_AreaEpicenterDetailItem hypoDetailName,
_,
_
) =>
'${hypoName.name}(${hypoDetailName.name})',
'$hypoName(${hypoDetailName.name})',
(
final AreaEpicenter_AreaEpicenterItem hypoName,
final String hypoName,
_,
_,
_,
) =>
hypoName.name,
hypoName,
(_, _, final JmaIntensity intensity, final List<String> regionNames)
when regionNames.isNotEmpty && regionNames.length >= 2 =>
'最大震度$intensityを${regionNames.first}などで観測',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:collection/collection.dart';
import 'package:eqapi_types/eqapi_types.dart';
import 'package:eqmonitor/core/component/intenisty/intensity_icon_type.dart';
import 'package:eqmonitor/core/component/intenisty/jma_intensity_icon.dart';
import 'package:eqmonitor/core/extension/earthquake_v1.dart';
import 'package:eqmonitor/core/provider/config/theme/intensity_color/intensity_color_provider.dart';
import 'package:eqmonitor/core/provider/config/theme/intensity_color/model/intensity_color_model.dart';
import 'package:eqmonitor/core/provider/jma_code_table_provider.dart';
Expand All @@ -28,10 +29,12 @@ class EarthquakeHypoInfoWidget extends HookConsumerWidget {
final textTheme = theme.textTheme;
final intensityColorScheme = ref.watch(intensityColorProvider);

final isVolcano = item.isVolcano;
final maxIntensity = item.maxIntensity;
final colorScheme = switch (maxIntensity) {
final JmaIntensity intensity =>
intensityColorScheme.fromJmaIntensity(intensity),
_ when isVolcano => intensityColorScheme.sixUpper,
_ => null,
};
final codeTable = ref.watch(jmaCodeTableProvider);
Expand Down Expand Up @@ -63,6 +66,61 @@ class EarthquakeHypoInfoWidget extends HookConsumerWidget {
],
)
: null;
// 「分頃(日本時間)」の後から「火山で大規模な噴火が発生しました」 の間の文字列
final volcanoName = item.volcanoName;
final volcanoWidget = isVolcano
? Padding(
padding: const EdgeInsets.all(8),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: [
Flexible(
child: Text(
'火山の大規模な噴火',
style: textTheme.titleMedium!.copyWith(
color: textTheme.titleMedium!.color!.withOpacity(0.8),
),
),
),
const SizedBox(width: 4),
Flexible(
child: Text(
volcanoName ?? '不明',
style: textTheme.headlineMedium!.copyWith(
fontWeight: FontWeight.bold,
),
),
),
],
),
Flexible(
child: Text.rich(
TextSpan(
children: [
TextSpan(
text: hypoName?.name ?? '不明',
style: textTheme.titleMedium,
),
if (hypoDetailName != null) ...[
const TextSpan(text: ' '),
TextSpan(
text: '(${hypoDetailName.name})',
style: textTheme.titleSmall,
),
],
],
),
),
),
],
),
)
: null;
// 「MaxInt, 震源地, 規模」
final hypoWidget = Row(
textBaseline: TextBaseline.ideographic,
Expand Down Expand Up @@ -269,7 +327,9 @@ class EarthquakeHypoInfoWidget extends HookConsumerWidget {
alignment: WrapAlignment.center,
children: [
const Row(),
if (isEarthquakeNull)
if (volcanoWidget != null)
volcanoWidget
else if (isEarthquakeNull)
earthquakeNullWidget
else if (isMagnitudeAndDepthUnknown) ...[
magnitudeDepthUnknownWidget,
Expand All @@ -284,8 +344,13 @@ class EarthquakeHypoInfoWidget extends HookConsumerWidget {
);

final card = Card(
margin: const EdgeInsets.all(4),
margin: const EdgeInsets.symmetric(
horizontal: 8,
).add(
const EdgeInsets.only(bottom: 4),
),
elevation: 0,

shadowColor: Colors.transparent,
// 角丸にして Border
shape: RoundedRectangleBorder(
Expand All @@ -303,7 +368,6 @@ class EarthquakeHypoInfoWidget extends HookConsumerWidget {
),
child: Column(
children: [
const SizedBox(height: 2),
Row(
children: [
if (maxIntensityWidget != null) maxIntensityWidget,
Expand Down
Loading

0 comments on commit c03a61a

Please sign in to comment.