Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

DebugPage の実装 #178

Merged
merged 26 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
92fb986
new for issue#160
i-maruyama May 14, 2021
c22df7f
issue#160 (simple debugpage)
i-maruyama May 14, 2021
47f32e3
Update Covid19Radar/Covid19Radar/ViewModels/HomePage/DebugPageViewMod…
i-maruyama May 14, 2021
baa112f
Update Covid19Radar/Covid19Radar/ViewModels/HomePage/DebugPageViewMod…
i-maruyama May 14, 2021
516d974
Update Covid19Radar/Covid19Radar/ViewModels/HomePage/DebugPageViewMod…
i-maruyama May 14, 2021
adc6bfe
Update Covid19Radar/Covid19Radar/ViewModels/HomePage/DebugPageViewMod…
i-maruyama May 14, 2021
77209c1
refactoring and delete unused services
i-maruyama May 14, 2021
e9bd943
change name of variables
i-maruyama May 14, 2021
239f33c
Update Covid19Radar/Covid19Radar/ViewModels/HomePage/DebugPageViewMod…
i-maruyama May 15, 2021
39e03a3
follow VisualStudio's advice. c.f.: https://github.com/cocoa-mhlw/coc…
i-maruyama May 15, 2021
3857b4a
`Release` ビルド時にデバッグページを除外して容量を削減する
Takym May 16, 2021
b8f90a3
XAMLファイルが正しく除外されていなかったので修正した
Takym May 16, 2021
9273bcb
git mv HomePage/... Settings/ c.f.: https://github.com/cocoa-mhlw/co…
i-maruyama May 16, 2021
80128f5
Info への変更
i-maruyama May 16, 2021
7d64bc3
Update Covid19Radar/Covid19Radar/ViewModels/Settings/DebugPageViewMod…
i-maruyama May 16, 2021
4f594a2
Update Covid19Radar/Covid19Radar/ViewModels/Settings/DebugPageViewMod…
i-maruyama May 16, 2021
8fbbc10
Update Covid19Radar/Covid19Radar/ViewModels/Settings/DebugPageViewMod…
i-maruyama May 16, 2021
2185ec7
Merge pull request #1 from Takym/refactoring/issue-160
i-maruyama May 25, 2021
857bc1c
directory name fix
i-maruyama May 25, 2021
da3f2c1
Revert "directory name fix"
i-maruyama May 26, 2021
051ab33
commit only Covid19Radar.csproj
i-maruyama May 26, 2021
243a3d3
Merge branch 'cocoa-mhlw:develop' into issue#160
i-maruyama Jun 7, 2021
de97c2e
use GetExposureCountToDisplay.
i-maruyama Jun 7, 2021
0bda3cf
Merge branch 'cocoa-mhlw:develop' into issue#160
i-maruyama Jun 9, 2021
489700c
Merge branch 'feature/debug_page' of github.com:cocoa-mhlw/cocoa into…
keiji Sep 2, 2021
24be80f
Merge pull request #2 from keiji/issue#160
i-maruyama Sep 2, 2021
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
3 changes: 3 additions & 0 deletions Covid19Radar/Covid19Radar/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ protected override void RegisterTypes(IContainerRegistry containerRegistry)
containerRegistry.RegisterForNavigation<NavigationPage>();
containerRegistry.RegisterForNavigation<MenuPage>();
containerRegistry.RegisterForNavigation<HomePage>();
#if DEBUG
containerRegistry.RegisterForNavigation<DebugPage>();
#endif

// Settings
containerRegistry.RegisterForNavigation<SettingsPage>();
Expand Down
165 changes: 165 additions & 0 deletions Covid19Radar/Covid19Radar/ViewModels/HomePage/DebugPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
keiji marked this conversation as resolved.
Show resolved Hide resolved

using System;
using System.Collections.Generic;
using System.Diagnostics;
using Acr.UserDialogs;
using Covid19Radar.Common;
using Covid19Radar.Model;
using Covid19Radar.Resources;
using Covid19Radar.Services;
using Covid19Radar.Services.Logs;
using Covid19Radar.Views;
using Prism.Navigation;
using Xamarin.Forms;

namespace Covid19Radar.ViewModels
{
public class DebugPageViewModel : ViewModelBase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[提案] Debug Page 関連は他の画面と少し毛色が違うのでディレクトリ切ってそこに入れませんか?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このページだけのディレクトリを作るのは避けたいのですが、既存のもの(HelpPage, Settings..)だとどれが良いでしょうか?現状のページ配置も、それほど意味を見出せないのですが・・

・・・と、私は悩んで、どれでもいいかとなってしまっています。

Copy link
Contributor

@fumiya-kume fumiya-kume May 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DebugはDebugというだけでドメインが違うので単体でフォルダを切る価値があると思いました。
下手にフォルダの中に入れるのではなく、Viewの直下においても良いかもですね。

現状のページ配置も、それほど意味を見出せないのですが・・.

それな...

Copy link
Contributor Author

@i-maruyama i-maruyama May 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

もし開発チームに意向があればこちらに届けば反映する、という方針にして、ここは見えるようにおいておきます。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これは要検討ですね。
itemGroupのような仕掛けでReleaseビルドに含めないようにするのなら、1つのディレクトリ(たとえばDebugPageなど)に集約されていることに意味はあると思います。

一方で、今の名前空間がViewViewModelといった分け方なので、そこにいきなり機能単位のDebugPageが来るのは違和感が拭えません。

となると、View/DebugPageViewModel/DebugPageのようにするのが納得感がある反面、ディレクトリが深くなっただけで1つのファイルしか保存していないなら今のままでいいじゃないかという…

まずはここは課題として残しておき、機能面やその他の場所を見ていきましょう。どこに配置するかは頃合いを見て決めると言うことで。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

参考までに、元々あったデバッグページは設定ページと同じディレクトリに置いてありました。
https://github.com/cocoa-mhlw/cocoa/tree/4c4aca39b02dcb1bd89569674b65b0ef6a357bae/Covid19Radar/Covid19Radar/Views/Settings

同じ場所に置くと GitHub の History ボタンから履歴が見やすくなると思います。

Copy link
Contributor Author

@i-maruyama i-maruyama May 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同じ場所に置くと GitHub の History ボタンから履歴が見やすくなると思います。

少なくとも HomePage/ よりは、まともな根拠と思いますので、Settings/ に変えたいですね。ました。
80128f5

{
private readonly ILoggerService loggerService;
private readonly IUserDataService userDataService;
private readonly ITermsUpdateService termsUpdateService;
private readonly IExposureNotificationService exposureNotificationService;
private readonly IHttpDataService httpDataService;

private string _debugInfo;
public string DebugInfo
{
get { return _debugInfo; }
set { SetProperty(ref _debugInfo, value); }
}
public async void info(string ex = "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1関数が大きすぎませんか?

Copy link
Contributor

@Takym Takym May 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

他にも、COCOAでは公開関数の名前は大文字から始める様になっています(僕はそう認識しています)ので、そちらに合わせるべきでしょう。(Visual Studio からは Ctrl+R, Ctrl+R で名前を変更できます)

{
string os;
switch (Device.RuntimePlatform)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

元々Stringで Android, iOS と取得できるものを再度変換かけてString 取得している理由は何ですか?
現状、iOS, Android しかサポートしてないのでそこまで考える必要はなさそう

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この switch 文が別ファイルにあったので、安全のためそれに倣いました。将来を考えて、 default を付けています。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちらの8個目にあるように必要以上に安全な振りすぎてると思いますが、どうでしょう?

https://medium.com/edge-coders/the-mistakes-i-made-as-a-beginner-programmer-ac8b3e54c312

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここはもう、次のようにまとめてしまうのでどうでしょう。iOSとAndroid以外への対応は、要件が出てきたときに考えましょう。

            string os = Device.RuntimePlatform;

#if USE_MOCK
            os += ",USE_MOCK";
#endif

ちなみに、このページはDEBUGが有効の時にしか見えないものなので、if DEBUGはなくてもいいかなと思いました。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多数決で、

     string os = Device.RuntimePlatform;

にします。
あと、 if DEBUG はつけておきたいのですが良いでしょうか?手元では、 Release ビルドも実施しているので。

{
case Device.Android:
os = "Android";
break;
case Device.iOS:
os = "iOS";
break;
default:
os = "unknown";
break;
}
#if DEBUG
os += ",DEBUG";
#endif
#if USE_MOCK
os += ",USE_MOCK";
#endif

// debug info for ./SplashPageViewModel.cs
string agree;
if (termsUpdateService.IsAllAgreed())
{
agree = "exists";// (mainly) navigate from SplashPage to HomePage
var termsUpdateInfo = await termsUpdateService.GetTermsUpdateInfo();
if (termsUpdateService.IsReAgree(TermsType.TermsOfService, termsUpdateInfo))
{
agree += "-TermsOfService";
}
else if (termsUpdateService.IsReAgree(TermsType.PrivacyPolicy, termsUpdateInfo))
{
agree += "-PrivacyPolicy";
}
}
else
{
agree = "not exists"; // navigate from SplashPage to TutorialPage1
}

long ticks = exposureNotificationService.GetLastProcessTekTimestamp(AppSettings.Instance.SupportedRegions[0]);
DateTimeOffset dt = DateTimeOffset.FromUnixTimeMilliseconds(ticks).ToOffset(new TimeSpan(9, 0, 0));
//please check : offset is correct or not
//cf: ../../../Covid19Radar.Android/Services/Logs/LogPeriodicDeleteServiceAndroid.cs
string LastProcessTekTimestamp = dt.ToLocalTime().ToString("F");
i-maruyama marked this conversation as resolved.
Show resolved Hide resolved

var en = await Xamarin.ExposureNotifications.ExposureNotification.IsEnabledAsync();
i-maruyama marked this conversation as resolved.
Show resolved Hide resolved
var status = await exposureNotificationService.UpdateStatusMessageAsync();
i-maruyama marked this conversation as resolved.
Show resolved Hide resolved
// ../../settings.json
var str = new string[] { "Build: " + os, "Ver: " + AppSettings.Instance.AppVersion, "Region: " + string.Join(",", AppSettings.Instance.SupportedRegions), "CdnUrl: " + AppSettings.Instance.CdnUrlBase, "ApiUrl: " + AppSettings.Instance.ApiUrlBase, "Agree: " + agree, "StartDate: " + userDataService.GetStartDate().ToLocalTime().ToString("F"), "DaysOfUse: " + userDataService.GetDaysOfUse().ToString(), "ExposureCount: " + exposureNotificationService.GetExposureCount().ToString(), "LastProcessTek: " + LastProcessTekTimestamp, " (long): " + ticks.ToString(), "EN: " + en, "ENS: " + status, "Now: " + DateTime.Now.ToLocalTime().ToString("F"), ex};
i-maruyama marked this conversation as resolved.
Show resolved Hide resolved
DebugInfo = string.Join(Environment.NewLine, str);
}
public DebugPageViewModel(IHttpDataService httpDataService, INavigationService navigationService, ILoggerService loggerService, IUserDataService userDataService, ITermsUpdateService termsUpdateService, IExposureNotificationService exposureNotificationService) : base(navigationService)
i-maruyama marked this conversation as resolved.
Show resolved Hide resolved
i-maruyama marked this conversation as resolved.
Show resolved Hide resolved
{
Title = "Title:DebugPage";
this.loggerService = loggerService;
this.userDataService = userDataService;
this.termsUpdateService = termsUpdateService;
this.exposureNotificationService = exposureNotificationService;
}
public override async void Initialize(INavigationParameters parameters)
i-maruyama marked this conversation as resolved.
Show resolved Hide resolved
{
base.Initialize(parameters);
info("Initialize");
}
public Command OnClickReload => new Command(async () =>
{
info("Reload");
});

public Command OnClickStartExposureNotification => new Command(async () =>
{
UserDialogs.Instance.ShowLoading("Starting ExposureNotification...");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

あまり詳しくないのですが、UserDalogs へ直接参照を持つのではなく、代わりに IUserDialogs を参照するようにするのはどうですか?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UserDialogsのInstanceを使っているのはAcr.UserDialogs(外部イブラリでCOCOAの範疇外という認識)の通常の使い方のようです。

指摘の意図としては、UserDialogsのInstanceを一旦、IUserDialogsのプロパティやメンバ変数としてクラスに持った方がいいということでしょうか。InstanceがSingletonであればこのままでもいいような気がします。

var result = await exposureNotificationService.StartExposureNotification();
string str = "StartExposureNotification: " + result.ToString();
i-maruyama marked this conversation as resolved.
Show resolved Hide resolved
UserDialogs.Instance.HideLoading();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これも同じくInterfaceへ依存するようにすると良さそう。

await UserDialogs.Instance.AlertAsync(str, str, Resources.AppResources.ButtonOk);
info("StartExposureNotification");
});
public Command OnClickFetchExposureKeyAsync => new Command(async () =>
{
string exLog = "FetchExposureKeyAsync";
i-maruyama marked this conversation as resolved.
Show resolved Hide resolved
try { await exposureNotificationService.FetchExposureKeyAsync(); }
catch (Exception ex) { exLog += ":Exception: " + ex.ToString(); }
i-maruyama marked this conversation as resolved.
Show resolved Hide resolved
info(exLog);
});

// see ../Settings/SettingsPageViewModel.cs
public Command OnClickStopExposureNotification => new Command(async () =>
{
UserDialogs.Instance.ShowLoading("Stopping ExposureNotification...");
i-maruyama marked this conversation as resolved.
Show resolved Hide resolved
var result = await exposureNotificationService.StopExposureNotification();
string str = "StopExposureNotification: " + result.ToString();
UserDialogs.Instance.HideLoading();
await UserDialogs.Instance.AlertAsync(str, str, Resources.AppResources.ButtonOk);
i-maruyama marked this conversation as resolved.
Show resolved Hide resolved
info("StopExposureNotification");
});

public Command OnClickRemoveStartDate => new Command(async () =>
{
userDataService.RemoveStartDate();
info("RemoveStartDate");
});
public Command OnClickRemoveExposureInformation => new Command(async () =>
{
exposureNotificationService.RemoveExposureInformation();
info("RemoveExposureInformation");
});
public Command OnClickRemoveConfiguration => new Command(async () =>
{
exposureNotificationService.RemoveConfiguration();
info("RemoveConfiguration");
});
public Command OnClickRemoveLastProcessTekTimestamp => new Command(async () =>
{
exposureNotificationService.RemoveLastProcessTekTimestamp();
info("RemoveLastProcessTekTimestamp");
});
public Command OnClickRemoveAllUpdateDate => new Command(async () =>
{
termsUpdateService.RemoveAllUpdateDate();
info("RemoveAllUpdateDate");
});
public Command OnClickQuit => new Command(async () =>
{
Application.Current.Quit();
DependencyService.Get<ICloseApplication>().closeApplication();
});
}
}
10 changes: 10 additions & 0 deletions Covid19Radar/Covid19Radar/ViewModels/MenuPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ public MainMenuModel SelectedMenuItem
public MenuPageViewModel(INavigationService navigationService) : base(navigationService)
{
MenuItems = new ObservableCollection<MainMenuModel>();
#if DEBUG
MenuItems.Add(new MainMenuModel()
{
Icon = "\uf013",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本質的ではないのですが、虫Icon があるようですね。そちらにしたくなってきました。

PageName = nameof(DebugPage),
Title = "debug",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Title = "debug",
Title = "Debug",

IconColor = "#019AE8",
TextColor = "#000"
});
#endif
Comment on lines +32 to +41
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

デバッグ画面のカラムは一番下に置きましょう(あまり主張したくないので)。

MenuItems.Add(new MainMenuModel()
{
Icon = "\uf965",
Expand Down
Loading