Skip to content

OneTimePassword を扱うための Model を追加 - #20

Merged
ykws merged 4 commits into
mainfrom
feature/model
Nov 22, 2021
Merged

OneTimePassword を扱うための Model を追加#20
ykws merged 4 commits into
mainfrom
feature/model

Conversation

@ykws

@ykws ykws commented Nov 14, 2021

Copy link
Copy Markdown
Owner
  • 対応する Issue が Linked Issues に設定されていることを確認してください

対応内容

  • OneTimePassword を扱うための Model を追加
  • 設定に関してもこの Model を通して行い、管理する
  • パスワードの生成も Model を通して行う

未対応事項

  • 設定画面の Picker の初期選択位置が正常に機能しないことがある
    • その時は didSelectRowAtIndexPath が呼ばれていない
    • settingsItem が選択したセルの位置と異なる

スクリーンショット

変更なし

@ykws ykws self-assigned this Nov 14, 2021
@ykws ykws linked an issue Nov 14, 2021 that may be closed by this pull request
@ykws
ykws requested a review from NMai-source November 14, 2021 19:17

@ykws ykws left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

変更内容についてコメントしました。


@implementation OneTimePasswordSettings

+ (instancetype)sharedInstance {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

memo-badge

シングルトンにするための処理です。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@ykws
今回はマルチスレッドな実装を行なっていないため、初期化処理に@synchronizedは必要ないのでしょうか?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@NMai-source とても良い指摘です。

結論としては必要ないです。

@synchronized の代わりに dispatch_once を利用しています。
iOS では、これによってシングルトンを実現できるようになっています。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@ykws
承知致しました。
教えて頂きありがとうございます!
URLも参考になりました。

return sharedInstance;
}

- (NSString *)generateOneTimePassword {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

memo-badge

ワンタイムパスワード生成はここに移動しました。

}

- (NSString *)digitsString {
return [NSString stringWithFormat:@"%d", (int)self.digits];

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

memo-badge

int のキャストは雑ですが、メニューでの設定値が限定されているので問題ないもの考えています。


#import "SettingController.h"
#import "SettingsTableViewCell.h"
#import "ViewController.h"

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

memo-badge

Model/OneTimePasswordSettings を経由してデータの共有をしているため、 ViewController への依存をなくしました。

AlgorithmItem,
DigitsItem,
PeriodItme,
PeriodItem,

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

memo-badge

Typo があったので修正しました。

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// FIXME: タップしても反応しないことがある

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

next-badge

設定画面の任意のセルをタップしても didSelectRowAtIndexPath が呼ばれなくて Picker の初期表示位置が意図した通りにできないことがあります。

#17 Model を追加とは別で、 TableView+Picker の課題なので、別途 Issue を作成して対応します。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

#22 で対応します

@interface ViewController : UIViewController
@property (nonatomic) NSString *algorithm;
@property (nonatomic) NSString *digits;
@property (nonatomic) NSString *period;

@ykws ykws Nov 14, 2021

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

memo-badge

Model/OneTimePasswordSettings を利用してデータを共有するようになったので、 property の公開は不要になりました。

フォーマットも修正 #18

@property (weak, nonatomic) IBOutlet UILabel *oneTimePasswordLabel;
@property (weak, nonatomic) IBOutlet UAProgressView *oneTimePasswordProgressView;
@property (nonatomic, assign) CGFloat localProgress;
@property (nonatomic) float scheduledTimerWithTimeInterval;

@ykws ykws Nov 14, 2021

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

memo-badge

Model/OneTimePasswordSettings を利用するようになったので、 import/property を整理しました。

フォーマットも修正 #18

if([_period isEqualToString:@"60"]) {
self.scheduledTimerWithTimeInterval = 0.06f;
}
}

@ykws ykws Nov 14, 2021

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

memo-badge

ワンタイムパスワード生成に関する処理は Model/OneTimePasswordSettings に移動しました。

#16 も合わせて解消

[self.oneTimePasswordLabel setText:password];

NSTimeInterval timeInterval = self.settings.period / 1000;
[NSTimer scheduledTimerWithTimeInterval:timeInterval target:self selector:@selector(updateOneTimePasswordView:) userInfo:nil repeats:YES];

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

memo-badge

ワンタイムパスワードに関する処理が View からなくなったので、 View で扱う初期化処理は initOneTimePasswordView に関することとして一つにまとめました。

@ykws

ykws commented Nov 14, 2021

Copy link
Copy Markdown
Owner Author

@NMai-source レビューをお願いできますでしょうか?
コードの書き方で疑問や質問などをコメントして欲しいです。
疑問や質問が解消できたら Approve してもらえればと思います。

@ykws ykws linked an issue Nov 14, 2021 that may be closed by this pull request
@ykws ykws mentioned this pull request Nov 14, 2021
@ykws ykws linked an issue Nov 14, 2021 that may be closed by this pull request
@ykws ykws linked an issue Nov 14, 2021 that may be closed by this pull request
2 tasks
@ykws ykws mentioned this pull request Nov 14, 2021
2 tasks
@ykws ykws linked an issue Nov 14, 2021 that may be closed by this pull request
@ykws ykws mentioned this pull request Nov 14, 2021
sharedInstance.issuer = issuer;
sharedInstance.algorithm = [OTPToken defaultAlgorithm];
sharedInstance.digits = [OTPToken defaultDigits];
sharedInstance.period = [OTPToken defaultPeriod];

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

memo-badge

デフォルト値で初期化するようにしました #19


_localProgress = newProgress;
[self.oneTimePasswordProgressView setProgress:_localProgress animated:NO];

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

memo-badge

フォーマット修正 #18

// 設定の文字列から保存できるようにする
- (void)saveAlgorithmString:(NSString *)algorithmString;
- (void)saveDigitsString:(NSString *)digitsString;
- (void)savePeriodString:(NSString *)periodString;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

suggestion-badge

save より store の方がしっくりくる

Suggested change
- (void)savePeriodString:(NSString *)periodString;
- (void)storePeriodString:(NSString *)periodString;

+ (instancetype)sharedInstance {
static OneTimePasswordSettings *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@NMai-source dispatch_once を利用しているのはこの部分です。

@NMai-source NMai-source left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@ykws
お疲れ様です。
遅くなりましたが、一通り修正内容の確認が完了しました。

return token.password;
}

- (NSString *)algorithmString {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

next-badge

以下のコンバートの責務は Converter に切り離して、ここではそれを呼ぶだけにしても良さそう

  • algorithmString: OTPAlgorithm -> NSString
  • digitsString: NSUInteger -> NSString
  • periodString: NSTimeInterval -> NSString
  • saveAlgorithmString: NSString -> OTPAlgorithm
  • saveDigitsString: NSString -> NSUInteger
  • savePeriodString: NSString -> NSTimeInterval

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

#21 にて対応予定

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

初期値を設定する フォーマット修正 Model を追加する property のアクセスに self を利用する 設定を保存する

2 participants