22using System . Collections ;
33using System . Collections . Generic ;
44using System . ComponentModel ;
5+ using System . Threading . Tasks ;
56using System . Windows ;
67using System . Windows . Controls ;
78using System . Windows . Data ;
89using System . Windows . Media ;
910using System . Windows . Media . Animation ;
11+ using RestSharp ;
1012using TumblrThemeSelect . Api ;
1113using TumblrThemeSelect . Val ;
1214
@@ -77,16 +79,28 @@ private async void ButtonSave_Click(object sender, RoutedEventArgs e)
7779 GridLoading . Visibility = Visibility . Visible ;
7880 t . Cav . CustomParams . Clear ( ) ;
7981 foreach ( dynamic param in StackPanelDefaultParam . Children ) { t . Cav . CustomParams [ param . ID ] = param . Value ; }
80- await ( ( Val . Theme ) ListBoxTheme . SelectedItem ) ? . ApplyTheme ( CurrentTheme ) ;
82+ var item = ( ( Val . Theme ) ListBoxTheme . SelectedItem ) ;
83+ await Task . Factory . StartNew ( ( ) =>
84+ {
85+ if ( ! CurrentTheme )
86+ {
87+ t . Cav . CustomTheme = Newtonsoft . Json . JsonConvert . DeserializeObject < Val . Theme > ( t . restClient . Post ( new RestRequest ( $ "customize_api/theme/{ t . Cav . Name } /{ item . Id } ") . AddHeader ( "referer" , "https://www.tumblr.com/customize/" ) ) . Content ) . ThemeCode ;
88+ t . Cav . ThemeId = "0" ;
89+ }
90+ t . restClient . Post ( new RestRequest ( $ "customize_api/blog/{ t . Cav . Name } ") . AddHeader ( "referer" , $ "https://www.tumblr.com/customize/{ t . Cav . Name } ") . AddParameter ( "application/json" , Newtonsoft . Json . JsonConvert . SerializeObject ( t . Cav ) , ParameterType . RequestBody ) ) ;
91+ } ) ;
92+
8193 BeginAnimation ( WidthProperty , new DoubleAnimation ( Width , 306 , TimeSpan . FromSeconds ( 1 ) ) ) ;
8294 GridLoading . Visibility = Visibility . Collapsed ;
8395 }
8496 private void ButtonSelect_Click ( object sender , RoutedEventArgs e )
8597 {
98+ CurrentTheme = false ;
8699 LoadEditing ( ( ( Val . Theme ) ListBoxTheme . SelectedItem ) ? . DefaultParams ) ;
87100 }
88101 private void ButtonCurrentThemeSettings_Click ( object sender , RoutedEventArgs e )
89102 {
103+ CurrentTheme = true ;
90104 LoadEditing ( t . Cav . CustomParams ) ;
91105 }
92106 private void LoadEditing ( IDictionary < string , object > data )
@@ -99,7 +113,6 @@ private void LoadEditing(IDictionary<string, object> data)
99113 else if ( param . Key . StartsWith ( "select:" ) ) { }
100114 else { StackPanelDefaultParam . Children . Add ( new ParametrePanel ( param . Key , param . Value , t , GridLoading ) ) ; }
101115 }
102- CurrentTheme = true ;
103116 GridThemes . Visibility = Visibility . Collapsed ;
104117 GridCustomize . Visibility = Visibility . Visible ;
105118 GridLoading . Visibility = Visibility . Collapsed ;
0 commit comments