Ejemplo n.º 1
0
 public MainController(onCopyFunc onCopy)
 {
     this.onCopy        = onCopy;
     LabelText          = getTokenFlg.Select(flg => flg ? "PINコード" : "検索ワード").ToReadOnlyReactiveProperty();
     ButtonText         = getTokenFlg.Select(flg => flg ? "入力" : "検索").ToReadOnlyReactiveProperty();
     showListViewFlg    = getTokenFlg.Select(flg => !flg).ToReadOnlyReactiveProperty();
     SearchStartCommand = SearchWord.Select(s => s.Length != 0).CombineLatest(progressFlg, (x, y) => x & !y).ToReactiveCommand();
     CopyLinkCommand    = SelectTweet.Select(t => t != null).ToReactiveCommand();
     OpenLinkCommand    = SelectTweet.Select(t => t != null).ToReactiveCommand();
     RtRtCommand        = SelectTweet.Select(t => t != null).ToReactiveCommand();
     SearchResult       = searchResult.ToReadOnlyReactiveCollection();
     //
     LoginCommand.Subscribe(_ => Login());
     SearchStartCommand.Subscribe(async _ => {
         if (getTokenFlg.Value)
         {
             // トークン入力処理
             token = session.GetTokens(SearchWord.Value);
             Application.Current.Properties["AccessToken"]       = token.AccessToken;
             Application.Current.Properties["AccessTokenSecret"] = token.AccessTokenSecret;
             getTokenFlg.Value = false;
             SearchWord.Value  = "";
         }
         else
         {
             // 検索処理
             await SearchTweet();
         }
     });
     CopyLinkCommand.Subscribe(_ => {
         string url = "https://twitter.com/" + SelectTweet.Value.User.ScreenName + "/status/" + SelectTweet.Value.Id;
         this.onCopy(url);
     });
     OpenLinkCommand.Subscribe(_ => {
         string url = "https://twitter.com/" + SelectTweet.Value.User.ScreenName + "/status/" + SelectTweet.Value.Id;
         Device.OpenUri(new Uri(url));
     });
     RtRtCommand.Subscribe(_ => {
     });
     //トークンが保存されているかを確かめ、されてない場合に限りログイン処理を行う
     if (Application.Current.Properties.ContainsKey("AccessToken") &&
         Application.Current.Properties.ContainsKey("AccessTokenSecret"))
     {
         token = Tokens.Create(Consumer.Key, Consumer.Secret,
                               Application.Current.Properties["AccessToken"] as string,
                               Application.Current.Properties["AccessTokenSecret"] as string);
     }
     else
     {
         Login();
     }
 }