- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 3.3k
Save backup import/export location for future import/exports #6319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
            XiangRongLin
  merged 6 commits into
  TeamNewPipe:dev
from
ATofighi:feat-6039-store-backup-location
  
      
      
   
  May 21, 2021 
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            6 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      82f43ac
              
                Save backup import/export location for feature import/exports
              
              
                ATofighi fa2b11b
              
                Move ContentSettingsFragment.isValidPath to helpers and add unit test…
              
              
                ATofighi 92ab9ca
              
                Invert if condition in ContentSettingsFragment.setImportExportDataPat…
              
              
                ATofighi 0675282
              
                Add more tests for FilePathUtils.isValidDirectoryPath for better cove…
              
              
                ATofighi e8ad947
              
                Split up FilePathHelperTest tests in simpler methods
              
              
                ATofighi 376e5c1
              
                Remove unnecessary conversion between file and path
              
              
                XiangRongLin File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            22 changes: 22 additions & 0 deletions
          
          22 
        
  app/src/main/java/org/schabi/newpipe/util/FilePathUtils.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package org.schabi.newpipe.util; | ||
|  | ||
| import java.io.File; | ||
|  | ||
| public final class FilePathUtils { | ||
| private FilePathUtils() { } | ||
|  | ||
|  | ||
| /** | ||
| * Check that the path is a valid directory path and it exists. | ||
| * | ||
| * @param path full path of directory, | ||
| * @return is path valid or not | ||
| */ | ||
| public static boolean isValidDirectoryPath(final String path) { | ||
| if (path == null || path.isEmpty()) { | ||
| return false; | ||
| } | ||
| final File file = new File(path); | ||
| return file.exists() && file.isDirectory(); | ||
| } | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            56 changes: 56 additions & 0 deletions
          
          56 
        
  app/src/test/java/org/schabi/newpipe/util/FilePathHelperTest.java
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package org.schabi.newpipe.util; | ||
|  | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|  | ||
| import java.io.File; | ||
| import java.io.IOException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
|  | ||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertTrue; | ||
|  | ||
| public class FilePathHelperTest { | ||
|  | ||
| private Path dir; | ||
|  | ||
| @Before | ||
| public void setUp() throws IOException { | ||
| dir = Files.createTempDirectory("dir1"); | ||
| } | ||
|  | ||
| @Test | ||
| public void testIsValidDirectoryPathWithEmptyString() { | ||
| assertFalse(FilePathUtils.isValidDirectoryPath("")); | ||
| } | ||
|  | ||
| @Test | ||
| public void testIsValidDirectoryPathWithNullString() { | ||
| assertFalse(FilePathUtils.isValidDirectoryPath(null)); | ||
| } | ||
|  | ||
| @Test | ||
| public void testIsValidDirectoryPathWithValidPath() { | ||
| assertTrue(FilePathUtils.isValidDirectoryPath(dir.toAbsolutePath().toString())); | ||
| } | ||
|  | ||
| @Test | ||
| public void testIsValidDirectoryPathWithDeepValidDirectory() throws IOException { | ||
| final File subDir = Files.createDirectory(dir.resolve("subdir")).toFile(); | ||
| assertTrue(FilePathUtils.isValidDirectoryPath(subDir.getAbsolutePath())); | ||
| } | ||
|  | ||
| @Test | ||
| public void testIsValidDirectoryPathWithNotExistDirectory() { | ||
| assertFalse(FilePathUtils.isValidDirectoryPath(dir.resolve("not-exists-subdir"). | ||
| toFile().getAbsolutePath())); | ||
| } | ||
|  | ||
| @Test | ||
| public void testIsValidDirectoryPathWithFile() throws IOException { | ||
| final File tempFile = Files.createFile(dir.resolve("simple_file")).toFile(); | ||
| assertFalse(FilePathUtils.isValidDirectoryPath(tempFile.getAbsolutePath())); | ||
| } | ||
|  | ||
| } | 
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.