Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

強震モニタのスケール実装 #645

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions app/lib/core/component/widget/blend_mask.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';

// https://stackoverflow.com/a/77039320
class BlendMask extends SingleChildRenderObjectWidget {
const BlendMask({
required this.blendMode,
this.opacity = 1.0,
super.key,
super.child,
});
final BlendMode blendMode;
final double opacity;

@override
RenderObject createRenderObject(BuildContext context) {
return RenderBlendMask(blendMode, opacity);
}

@override
void updateRenderObject(BuildContext context, RenderBlendMask renderObject) {
renderObject
..blendMode = blendMode
..opacity = opacity;
}
}

class RenderBlendMask extends RenderProxyBox {
RenderBlendMask(this.blendMode, this.opacity);
BlendMode blendMode;
double opacity;

@override
void paint(PaintingContext context, Offset offset) {
context.canvas.saveLayer(
offset & size,
Paint()
..blendMode = blendMode
..color = Color.fromARGB((opacity * 255).round(), 255, 255, 255),
);

super.paint(context, offset);

context.canvas.restore();
}
}
16 changes: 16 additions & 0 deletions app/lib/core/extension/double_to_jma_forecast_intensity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,19 @@ extension JmaForecastIntensityDouble on double {
_ => JmaForecastIntensity.seven,
};
}

extension JmaForecastIntensityEx on JmaForecastIntensity {
(double min, double max) get toRealtimeValue => switch (this) {
JmaForecastIntensity.zero => (double.negativeInfinity, 0.5),
JmaForecastIntensity.one => (0.5, 1.5),
JmaForecastIntensity.two => (1.5, 2.5),
JmaForecastIntensity.three => (2.5, 3.5),
JmaForecastIntensity.four => (3.5, 4.5),
JmaForecastIntensity.fiveLower => (4.5, 5.0),
JmaForecastIntensity.fiveUpper => (5.0, 5.5),
JmaForecastIntensity.sixLower => (5.5, 6.0),
JmaForecastIntensity.sixUpper => (6.0, 6.5),
JmaForecastIntensity.seven => (6.5, double.infinity),
_ => throw UnimplementedError(),
};
}
6 changes: 6 additions & 0 deletions app/lib/core/extension/kyoshin_color_map_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'package:eqmonitor/core/provider/kmoni/model/kyoshin_color_map_model.dart';
import 'package:flutter/material.dart';

extension KyoshinColorMapModelEx on KyoshinColorMapModel {
Color get color => Color.fromARGB(255, r, g, b);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,13 @@ import 'dart:convert';
import 'package:eqmonitor/core/provider/kmoni/model/kyoshin_color_map_model.dart';
import 'package:eqmonitor/gen/assets.gen.dart';
import 'package:flutter/services.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'kyoshin_color_map_data_source.g.dart';

@Riverpod(keepAlive: true)
KyoshinColorMapDataSource kyoshinColorMapDataSource(
KyoshinColorMapDataSourceRef ref,
) =>
KyoshinColorMapDataSource();

class KyoshinColorMapDataSource {
Future<List<KyoshinColorMapModel>> getKyoshinColorMap() async {
final str = await rootBundle.loadString(Assets.kyoshinShindoColorMap);
final json = jsonDecode(str) as List<dynamic>;
return json
.map(
(e) => KyoshinColorMapModel.fromJson(e as Map<String, dynamic>),
)
.toList();
}
Future<List<KyoshinColorMapModel>> getKyoshinColorMap() async {
final str = await rootBundle.loadString(Assets.kyoshinShindoColorMap);
final json = jsonDecode(str) as List<dynamic>;
return json
.map(
(e) => KyoshinColorMapModel.fromJson(e as Map<String, dynamic>),
)
.toList();
}

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/lib/core/provider/kmoni/page/kmoni_settings_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:eqmonitor/core/component/widget/kmoni_caution.dart';
import 'package:eqmonitor/core/provider/kmoni/viewmodel/kmoni_view_settings.dart';
import 'package:eqmonitor/core/provider/kmoni/viewmodel/kmoni_settings.dart';
import 'package:eqmonitor/feature/home/component/sheet/sheet_header.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import 'package:collection/collection.dart';
import 'package:eqmonitor/core/provider/kmoni/data/kyoshin_color_map_data_source.dart';
import 'package:eqmonitor/core/provider/kmoni/model/kyoshin_color_map_model.dart';
import 'package:flutter/material.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'kmoni_color_provider.g.dart';

@Riverpod(keepAlive: true)
Future<List<KyoshinColorMapModel>> kyoshinColorMap(
List<KyoshinColorMapModel> kyoshinColorMap(
KyoshinColorMapRef ref,
) =>
ref.watch(kyoshinColorMapDataSourceProvider).getKyoshinColorMap();
throw UnimplementedError();

extension IntensityToKyoshinColor on List<KyoshinColorMapModel> {
Color intensityToColor(double intensity) {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@ import 'package:eqmonitor/core/provider/shared_preferences.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'kmoni_view_settings.freezed.dart';
part 'kmoni_view_settings.g.dart';
part 'kmoni_settings.freezed.dart';
part 'kmoni_settings.g.dart';

@freezed
class KmoniSettingsState with _$KmoniSettingsState {
const factory KmoniSettingsState({
// 設定
/// 震度0以上のみ表示するかどうか
/// 震度0-1: グレーで表示
/// 震度1-: isShowIntensityIcon が true の場合はアイコンを表示
/// 震度1-: isShowIntensityIcon が false の場合は色で表示
@Default(false) bool isUpper0Only,
/// 強震モニタの表示最低リアルタイム震度
@Default(null) double? minRealtimeShindo,

/// 震度アイコンを表示するかどうか
@Default(false) bool isShowIntensityIcon,
/// スケールを表示するかどうか
@Default(true) bool showRealtimeShindoScale,

/// 強震モニタを使用するかどうか
@Default(false) bool useKmoni,
Expand Down Expand Up @@ -63,27 +59,27 @@ class KmoniSettings extends _$KmoniSettings {
jsonEncode(state.toJson()),
);

void toggleIsUpper0Only() {
void toggleUseKmoni() {
state = state.copyWith(
isUpper0Only: !state.isUpper0Only,
useKmoni: !state.useKmoni,
);
}

void toggleIsShowIntensityIcon() {
void setUseKmoni({required bool value}) {
state = state.copyWith(
isShowIntensityIcon: !state.isShowIntensityIcon,
useKmoni: value,
);
}

void toggleUseKmoni() {
void setMinRealtimeShindo({required double? value}) {
state = state.copyWith(
useKmoni: !state.useKmoni,
minRealtimeShindo: value,
);
}

void setUseKmoni({required bool value}) {
void setShowRealtimeShindoScale({required bool value}) {
state = state.copyWith(
useKmoni: value,
showRealtimeShindoScale: value,
);
}
}
Loading
Loading