3434import android .view .MenuItem ;
3535import android .view .View ;
3636import android .view .ViewGroup ;
37+ import android .view .animation .Animation ;
38+ import android .view .animation .Transformation ;
3739import android .widget .AdapterView ;
3840import android .widget .ArrayAdapter ;
3941import android .widget .CheckBox ;
@@ -134,7 +136,6 @@ public class ExportFormFragment extends Fragment implements
134136 @ BindView (R .id .switch_export_all ) SwitchCompat mExportAllSwitch ;
135137
136138 @ BindView (R .id .export_date_layout ) LinearLayout mExportDateLayout ;
137- @ BindView (R .id .export_separator_layout ) LinearLayout mExportSeparatorLayout ;
138139
139140 @ BindView (R .id .radio_ofx_format ) RadioButton mOfxRadioButton ;
140141 @ BindView (R .id .radio_qif_format ) RadioButton mQifRadioButton ;
@@ -194,8 +195,9 @@ private void onRadioButtonClicked(View view){
194195 } else {
195196 mExportWarningTextView .setVisibility (View .GONE );
196197 }
197- mExportDateLayout .setVisibility (View .VISIBLE );
198- mExportSeparatorLayout .setVisibility (View .GONE );
198+
199+ OptionsViewAnimationUtils .expand (mExportDateLayout );
200+ OptionsViewAnimationUtils .collapse (mCsvOptionsLayout );
199201 break ;
200202
201203 case R .id .radio_qif_format :
@@ -207,22 +209,23 @@ private void onRadioButtonClicked(View view){
207209 } else {
208210 mExportWarningTextView .setVisibility (View .GONE );
209211 }
210- mExportDateLayout .setVisibility (View .VISIBLE );
211- mCsvOptionsLayout .setVisibility (View .GONE );
212+
213+ OptionsViewAnimationUtils .expand (mExportDateLayout );
214+ OptionsViewAnimationUtils .collapse (mCsvOptionsLayout );
212215 break ;
213216
214217 case R .id .radio_xml_format :
215218 mExportFormat = ExportFormat .XML ;
216219 mExportWarningTextView .setText (R .string .export_warning_xml );
217- mExportDateLayout . setVisibility ( View . GONE );
218- mCsvOptionsLayout . setVisibility ( View . GONE );
220+ OptionsViewAnimationUtils . collapse ( mExportDateLayout );
221+ OptionsViewAnimationUtils . collapse ( mCsvOptionsLayout );
219222 break ;
220223
221224 case R .id .radio_csv_transactions_format :
222225 mExportFormat = ExportFormat .CSVT ;
223- mExportWarningTextView .setText ("Exports registered transactions as CSV" );
224- mExportDateLayout . setVisibility ( View . GONE );
225- mCsvOptionsLayout . setVisibility ( View . VISIBLE );
226+ mExportWarningTextView .setText (R . string . export_notice_csv );
227+ OptionsViewAnimationUtils . expand ( mExportDateLayout );
228+ OptionsViewAnimationUtils . expand ( mCsvOptionsLayout );
226229 break ;
227230
228231 case R .id .radio_separator_comma_format :
@@ -246,9 +249,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
246249
247250 bindViewListeners ();
248251
249- String [] export_format_strings = getResources ().getStringArray (R .array .export_formats );
250- mCsvTransactionsRadioButton .setText (export_format_strings [3 ]);
251-
252252 return view ;
253253 }
254254 @ Override
@@ -359,12 +359,11 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
359359 if (view == null ) //the item selection is fired twice by the Android framework. Ignore the first one
360360 return ;
361361 switch (position ) {
362- case 0 :
362+ case 0 : //Save As..
363363 mExportTarget = ExportParams .ExportTarget .URI ;
364364 mRecurrenceOptionsView .setVisibility (View .VISIBLE );
365365 if (mExportUri != null )
366366 setExportUriText (mExportUri .toString ());
367- selectExportFile ();
368367 break ;
369368 case 1 : //DROPBOX
370369 setExportUriText (getString (R .string .label_dropbox_export_destination ));
@@ -377,7 +376,7 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
377376 Auth .startOAuth2Authentication (getActivity (), dropboxAppKey );
378377 }
379378 break ;
380- case 2 :
379+ case 2 : //OwnCloud
381380 setExportUriText (null );
382381 mRecurrenceOptionsView .setVisibility (View .VISIBLE );
383382 mExportTarget = ExportParams .ExportTarget .OWNCLOUD ;
@@ -387,7 +386,7 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
387386 ocDialog .show (getActivity ().getSupportFragmentManager (), "ownCloud dialog" );
388387 }
389388 break ;
390- case 3 :
389+ case 3 : //Share File
391390 setExportUriText (getString (R .string .label_select_destination_after_export ));
392391 mExportTarget = ExportParams .ExportTarget .SHARING ;
393392 mRecurrenceOptionsView .setVisibility (View .GONE );
@@ -401,7 +400,7 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
401400
402401 @ Override
403402 public void onNothingSelected (AdapterView <?> parent ) {
404-
403+ //nothing to see here, move along
405404 }
406405 });
407406
@@ -482,7 +481,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
482481 mRecurrenceTextView .setOnClickListener (new RecurrenceViewClickListener ((AppCompatActivity ) getActivity (), mRecurrenceRule , this ));
483482
484483 //this part (setting the export format) must come after the recurrence view bindings above
485- String defaultExportFormat = sharedPrefs .getString (getString (R .string .key_default_export_format ), ExportFormat .QIF .name ());
484+ String defaultExportFormat = sharedPrefs .getString (getString (R .string .key_default_export_format ), ExportFormat .CSVT .name ());
486485 mExportFormat = ExportFormat .valueOf (defaultExportFormat );
487486
488487 View .OnClickListener radioClickListener = new View .OnClickListener () {
@@ -543,11 +542,6 @@ private void selectExportFile() {
543542 String bookName = BooksDbAdapter .getInstance ().getActiveBookDisplayName ();
544543
545544 String filename = Exporter .buildExportFilename (mExportFormat , bookName );
546- if (mExportFormat == ExportFormat .QIF ) {
547- createIntent .setType ("application/zip" );
548- filename += ".zip" ;
549- }
550-
551545 createIntent .putExtra (Intent .EXTRA_TITLE , filename );
552546 startActivityForResult (createIntent , REQUEST_EXPORT_FILE );
553547 }
@@ -615,3 +609,57 @@ public void onTimeSet(RadialTimePickerDialogFragment dialog, int hourOfDay, int
615609 }
616610}
617611
612+ // Gotten from: https://stackoverflow.com/a/31720191
613+ class OptionsViewAnimationUtils {
614+
615+ public static void expand (final View v ) {
616+ v .measure (ViewGroup .LayoutParams .MATCH_PARENT , ViewGroup .LayoutParams .WRAP_CONTENT );
617+ final int targetHeight = v .getMeasuredHeight ();
618+
619+ v .getLayoutParams ().height = 0 ;
620+ v .setVisibility (View .VISIBLE );
621+ Animation a = new Animation ()
622+ {
623+ @ Override
624+ protected void applyTransformation (float interpolatedTime , Transformation t ) {
625+ v .getLayoutParams ().height = interpolatedTime == 1
626+ ? ViewGroup .LayoutParams .WRAP_CONTENT
627+ : (int )(targetHeight * interpolatedTime );
628+ v .requestLayout ();
629+ }
630+
631+ @ Override
632+ public boolean willChangeBounds () {
633+ return true ;
634+ }
635+ };
636+
637+ a .setDuration ((int )(3 * targetHeight / v .getContext ().getResources ().getDisplayMetrics ().density ));
638+ v .startAnimation (a );
639+ }
640+
641+ public static void collapse (final View v ) {
642+ final int initialHeight = v .getMeasuredHeight ();
643+
644+ Animation a = new Animation ()
645+ {
646+ @ Override
647+ protected void applyTransformation (float interpolatedTime , Transformation t ) {
648+ if (interpolatedTime == 1 ){
649+ v .setVisibility (View .GONE );
650+ }else {
651+ v .getLayoutParams ().height = initialHeight - (int )(initialHeight * interpolatedTime );
652+ v .requestLayout ();
653+ }
654+ }
655+
656+ @ Override
657+ public boolean willChangeBounds () {
658+ return true ;
659+ }
660+ };
661+
662+ a .setDuration ((int )(3 * initialHeight / v .getContext ().getResources ().getDisplayMetrics ().density ));
663+ v .startAnimation (a );
664+ }
665+ }
0 commit comments