mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 06:43:56 +01:00 
			
		
		
		
	remove method
Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>
This commit is contained in:
		
							parent
							
								
									2c8c441f25
								
							
						
					
					
						commit
						677dbb506c
					
				
					 2 changed files with 3 additions and 75 deletions
				
			
		|  | @ -302,8 +302,9 @@ public class UploadMediaDetailAdapter extends | ||||||
| 
 | 
 | ||||||
|             removeButton.setOnClickListener(v -> removeDescription(uploadMediaDetail, position)); |             removeButton.setOnClickListener(v -> removeDescription(uploadMediaDetail, position)); | ||||||
|             captionListener = new AbstractTextWatcher( |             captionListener = new AbstractTextWatcher( | ||||||
|                 captionText -> uploadMediaDetail.setCaptionText(convertIdeographicSpaceToLatinSpace( |                 captionText -> uploadMediaDetail.setCaptionText( | ||||||
|                         removeLeadingAndTrailingWhitespace(captionText)))); |                     convertIdeographicSpaceToLatinSpace(captionText.strip())) | ||||||
|  |             ); | ||||||
|             descriptionListener = new AbstractTextWatcher( |             descriptionListener = new AbstractTextWatcher( | ||||||
|                 descriptionText -> uploadMediaDetail.setDescriptionText(descriptionText)); |                 descriptionText -> uploadMediaDetail.setDescriptionText(descriptionText)); | ||||||
|             captionItemEditText.addTextChangedListener(captionListener); |             captionItemEditText.addTextChangedListener(captionListener); | ||||||
|  | @ -547,39 +548,6 @@ public class UploadMediaDetailAdapter extends | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /** |  | ||||||
|          * Removes any leading and trailing whitespace from the source text. |  | ||||||
|          * |  | ||||||
|          * @param source input string |  | ||||||
|          * @return a string without leading and trailing whitespace |  | ||||||
|          */ |  | ||||||
|         public String removeLeadingAndTrailingWhitespace(String source) { |  | ||||||
|             // This method can be replaced with the inbuilt String::strip when updated to JDK 11. |  | ||||||
|             // Note that String::trim does not adequately remove all whitespace chars. |  | ||||||
|             int firstNonWhitespaceIndex = 0; |  | ||||||
|             while (firstNonWhitespaceIndex < source.length()) { |  | ||||||
|                 if (Character.isWhitespace(source.charAt(firstNonWhitespaceIndex))) { |  | ||||||
|                     firstNonWhitespaceIndex++; |  | ||||||
|                 } else { |  | ||||||
|                     break; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             if (firstNonWhitespaceIndex == source.length()) { |  | ||||||
|                 return ""; |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             int lastNonWhitespaceIndex = source.length() - 1; |  | ||||||
|             while (lastNonWhitespaceIndex > firstNonWhitespaceIndex) { |  | ||||||
|                 if (Character.isWhitespace(source.charAt(lastNonWhitespaceIndex))) { |  | ||||||
|                     lastNonWhitespaceIndex--; |  | ||||||
|                 } else { |  | ||||||
|                     break; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             return source.substring(firstNonWhitespaceIndex, lastNonWhitespaceIndex + 1); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         /** |         /** | ||||||
|          * Convert Ideographic space to Latin space |          * Convert Ideographic space to Latin space | ||||||
|          * |          * | ||||||
|  |  | ||||||
|  | @ -269,50 +269,10 @@ class UploadMediaDetailAdapterUnitTest { | ||||||
|         verify(adapterView, times(3)).adapter |         verify(adapterView, times(3)).adapter | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Test |  | ||||||
|     fun testRemoveLeadingAndTrailingWhitespace() { |  | ||||||
|         // empty space |  | ||||||
|         val test1 = "  test  " |  | ||||||
|         val expected1 = "test" |  | ||||||
|         Assert.assertEquals(expected1, viewHolder.removeLeadingAndTrailingWhitespace(test1)) |  | ||||||
| 
 |  | ||||||
|         val test2 = "  test test " |  | ||||||
|         val expected2 = "test test" |  | ||||||
|         Assert.assertEquals(expected2, viewHolder.removeLeadingAndTrailingWhitespace(test2)) |  | ||||||
| 
 |  | ||||||
|         // No whitespace |  | ||||||
|         val test3 = "No trailing space" |  | ||||||
|         val expected3 = "No trailing space" |  | ||||||
|         Assert.assertEquals(expected3, viewHolder.removeLeadingAndTrailingWhitespace(test3)) |  | ||||||
| 
 |  | ||||||
|         // blank string |  | ||||||
|         val test4 = " \r \t  " |  | ||||||
|         val expected4 = "" |  | ||||||
|         Assert.assertEquals(expected4, viewHolder.removeLeadingAndTrailingWhitespace(test4)) |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Test |  | ||||||
|     fun testRemoveLeadingAndTrailingInstanceTab() { |  | ||||||
|         val test = "\ttest\t" |  | ||||||
|         val expected = "test" |  | ||||||
|         Assert.assertEquals(expected, viewHolder.removeLeadingAndTrailingWhitespace(test)) |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Test |  | ||||||
|     fun testRemoveLeadingAndTrailingCarriageReturn() { |  | ||||||
|         val test = "\rtest\r" |  | ||||||
|         val expected = "test" |  | ||||||
|         Assert.assertEquals(expected, viewHolder.removeLeadingAndTrailingWhitespace(test)) |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     @Test |     @Test | ||||||
|     fun testCaptionJapaneseCharacters() { |     fun testCaptionJapaneseCharacters() { | ||||||
|         val test1 = "テスト テスト" |         val test1 = "テスト テスト" | ||||||
|         val expected1 = "テスト テスト" |         val expected1 = "テスト テスト" | ||||||
|         Assert.assertEquals(expected1, viewHolder.convertIdeographicSpaceToLatinSpace(test1)) |         Assert.assertEquals(expected1, viewHolder.convertIdeographicSpaceToLatinSpace(test1)) | ||||||
| 
 |  | ||||||
|         val test2 = " \r \t テスト \r \t " |  | ||||||
|         val expected2 = "テスト" |  | ||||||
|         Assert.assertEquals(expected2, viewHolder.removeLeadingAndTrailingWhitespace(test2)) |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 parneet-guraya
						parneet-guraya