mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-30 23:03:00 +00:00 
			
		
		
		
	UX improvements: keep user edits & do not reset cursor
This commit is contained in:
		| @@ -75,6 +75,7 @@ import java.io.IOException; | |||||||
| import java.util.List; | import java.util.List; | ||||||
| import java.util.Locale; | import java.util.Locale; | ||||||
| import java.util.Objects; | import java.util.Objects; | ||||||
|  | import java.util.Optional; | ||||||
|  |  | ||||||
| import icepick.Icepick; | import icepick.Icepick; | ||||||
| import icepick.State; | import icepick.State; | ||||||
| @@ -566,19 +567,34 @@ public class DownloadDialog extends DialogFragment | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     private void onItemSelectedSetFileName() { |     private void onItemSelectedSetFileName() { | ||||||
|         final String fileName = FilenameUtils.createFilename(getContext(), |         final String fileName = FilenameUtils.createFilename(getContext(), currentInfo.getName()); | ||||||
|                 currentInfo.getName()); |         final String prevFileName = Optional.ofNullable(dialogBinding.fileName.getText()) | ||||||
|         switch (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()) { |                 .map(Object::toString) | ||||||
|             case R.id.audio_button: |                 .orElse(""); | ||||||
|             case R.id.video_button: |  | ||||||
|                 dialogBinding.fileName.setText(fileName); |         if (prevFileName.isEmpty() | ||||||
|                 break; |                 || prevFileName.equals(fileName) | ||||||
|             case R.id.subtitle_button: |                 || prevFileName.startsWith(getString(R.string.caption_file_name, fileName, ""))) { | ||||||
|                 final String setSubtitleLanguageCode = subtitleStreamsAdapter |             // only update the file name field if it was not edited by the user | ||||||
|                         .getItem(selectedSubtitleIndex).getLanguageTag(); |  | ||||||
|                 dialogBinding.fileName.setText(getString( |             switch (dialogBinding.videoAudioGroup.getCheckedRadioButtonId()) { | ||||||
|                         R.string.caption_file_name, fileName, setSubtitleLanguageCode)); |                 case R.id.audio_button: | ||||||
|                 break; |                 case R.id.video_button: | ||||||
|  |                     if (!prevFileName.equals(fileName)) { | ||||||
|  |                         // since the user might have switched between audio and video, the correct | ||||||
|  |                         // text might already be in place, so avoid resetting the cursor position | ||||||
|  |                         dialogBinding.fileName.setText(fileName); | ||||||
|  |                     } | ||||||
|  |                     break; | ||||||
|  |  | ||||||
|  |                 case R.id.subtitle_button: | ||||||
|  |                     final String setSubtitleLanguageCode = subtitleStreamsAdapter | ||||||
|  |                             .getItem(selectedSubtitleIndex).getLanguageTag(); | ||||||
|  |                     // this will reset the cursor position, which is bad UX, but it can't be avoided | ||||||
|  |                     dialogBinding.fileName.setText(getString( | ||||||
|  |                             R.string.caption_file_name, fileName, setSubtitleLanguageCode)); | ||||||
|  |                     break; | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Stypox
					Stypox