diff --git a/README.md b/README.md index 57199c1..8ad890e 100644 --- a/README.md +++ b/README.md @@ -131,501 +131,23 @@ The next steps are for working with multiple uri as well as for a single uri. ### 🎲 Kotlin -#### 💫 Initialization - -1.1 - In Kotlin for the implementation of the Listener you can implement it within the scope of the class, as shown below, or also as shown in item **1.2**: - -```kotlin - - class MainActivity : AppCompatActivity(), HandlePathOzListener.MultipleUri { - //... - } - -``` - -`Alt+Enter` to implement the methods, we will discuss the methods later in the topic **Controller**. -Implement handlePathOz in your `onCreate()` method, as shown below: - -```kotlin - - private lateinit var handlePathOz: HandlePathOz - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - //Initialize HandlePathOz - //context, listener - handlePathOz = HandlePathOz(this, this) - } - -``` - -1.2 - You can also implement the Listener when initializing the class, without having to implement it within the scope of the class: - -```kotlin - - private lateinit var handlePathOz: HandlePathOz - private val listener = object: HandlePathOzListener.MultipleUri{ - //implement methods - } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - //Initialize HandlePathOz - //context, listener - handlePathOz = HandlePathOz(this, listener) - } - -``` - -2 - After selecting the desired files (The sample application has the entire step) in ```onActivityResult``` leave as follows: - -```kotlin - - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - if ((requestCode == REQUEST_OPEN_GALLERY) and (resultCode == Activity.RESULT_OK)) { - //This extension retrieves the path of all selected files without treatment. - val listUri = data.getListUri() - - //with the list you can update some recyclerview and switch to the method that handles Uri's. - - //set list of the Uri to handle - //in concurrency use: - // 1 -> for tasks sequentially - //greater than 1 -> for the number of tasks you want to perform in parallel. - //Nothing -> for parallel tasks - by default the value is 10 - handlePathOz.getListRealPath(listUri) - // handlePathOz.getListRealPath(listUri, 1) - - //show Progress Loading - } - } - -``` - -#### 🎮 Controller - -We have two methods in the listeners, one of which is optional: - -```kotlin - - //On Completion (Sucess or Error) - //If there is a cancellation or error, the entire task that was handled will be returned in the list. - override fun onRequestHandlePathOz(listPathOz: List, tr: Throwable?) { - //Hide Progress - //Update the recyclerview with the list - yourAdapter.updateListChanged(listPathOz.map { uri -> Uri.parse(uri.path) }) - - //Handle any Exception (Optional) - tr?.let { - Toast.makeText(this, "${it.message}", Toast.LENGTH_SHORT).show() - } - } - - //This method is Optional - override fun onLoading(currentUri: Int) { - //Update UI with the current Uri - //progressLoading.setText = "${currentUri}/${listUri.size}" - } - -``` - - #### ☁️ Cloud files and Unknown Providers - -If the selected file was from Dropbox,Google Drive, OneDrive or an unknown file provider, it will then be copied/created in -InternalStorage/Android/data/your.package.name/files/Temp/sameFileNameAndExtension -When you want to delete the generated files call: - -```kotlin - - handlePathOz.deleteTemporaryFiles() - -``` - -#### 💣 Cancel the tasks - -There are two methods for canceling tasks, ```cancelTask()``` and ```onDestroy()```. - -**handlePathOz.cancelTask() ->** Can be called as a button action for canceling or by progressBar (As shown in the demo application). -In the cancellation of the task by this method, all Uri that was treated will be passed in the ```onRequestHandlePathOz()``` method. - -**handlePathOz.onDestroy() ->** It can be called with the Activity or fragment's ```onDestroy()``` method. -This method destroys the task and its cancellation does not update anything and cannot be restarted. -Example of use: - -```kotlin - - override fun onDestroy() { - handlePathOz.onDestroy() - //You can delete the temporary files here as well. - super.onDestroy() - } - -``` - ---- +You can check in the wikipage, [click here](https://github.com/onimur/handle-path-oz/wiki/Kotlin---Multiple-Uri). ### 🎲 Java - -#### 💫 Initialization - -The implementation of the Listener you can implement it within the scope of the class, as shown below: - -```java - - public class MainActivity extends AppCompatActivity implements HandlePathOzListener.MultipleUri { - // - } - -``` - -`Alt+Enter` to implement the methods, we will discuss the methods later in the topic **Controller**. -Implement handlePathOz in your `onCreate()` method, as shown below: - -```java - - private HandlePathOz handlePathOz; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - //Initialize HandlePathOz - //context, listener - handlePathOz = HandlePathOz(this, this) - } - -``` -After selecting the desired files (The sample application has the entire step) in ```onActivityResult``` leave as follows: - -```java - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (requestCode == REQUEST_OPEN_GALLERY && resultCode == RESULT_OK) { - //This extension retrieves the path of all selected files without treatment. - listUri = getListUri(data); - - //with the list you can update some recyclerview and switch to the method that handles Uri's. - - - //set list of the Uri to handle - //in concurrency use: - // 1 -> for tasks sequentially - //greater than 1 -> for the number of tasks you want to perform in parallel. - //Nothing -> for parallel tasks - by default the value is 10 - handlePathOz.getListRealPath(listUri); - // handlePathOz.getListRealPath(listUri, 1) - - //show Progress Loading - } - } - -``` - -#### 🎮 Controller - -We have two methods in the listeners, one of which is optional: - -```java - - //On Completion (Sucess or Error) - //If there is a cancellation or error, the entire task that was handled will be returned in the list. - @Override - public void onRequestHandlePathOz(@NonNull List listPathOz, Throwable tr) { - //Hide Progress - //Update the recyclerview with the list - //Update the adapter - List listUri = new ArrayList<>(); - for (int i = 0; i < listPathOz.size(); i++) { - Uri uri = Uri.parse(listPathOz.get(i).getPath()); - listUri.add(uri); - } - yourAdapter.updateListChanged(listUri); - - //Handle Exception (Optional) - if (throwable != null) { - Toast.makeText(this, throwable.getMessage(), Toast.LENGTH_SHORT).show(); - } - } - - //This method is Optional - @Override - public void onLoading(int currentUri) { - //Update UI with the current Uri - //progressLoading.setText(currentUri + "/" + listUri.size()); - } - -``` - -#### ☁️ Cloud files and Unknown Providers - -If the selected file was from Dropbox,Google Drive, OneDrive or an unknown file provider, it will then be copied/created in -InternalStorage/Android/data/your.package.name/files/Temp/sameFileNameAndExtension -When you want to delete the generated files call: - -```java - - handlePathOz.deleteTemporaryFiles() +You can check in the wikipage, [click here](https://github.com/onimur/handle-path-oz/wiki/Java---Multiple-Uri). -``` - -#### 💣 Cancel the tasks - -There are two methods for canceling tasks, ```cancelTask()``` and ```onDestroy()```. - -**handlePathOz.cancelTask() ->** Can be called as a button action for canceling or by progressBar (As shown in the demo application). -In the cancellation of the task by this method, all Uri that was treated will be passed in the ```onRequestHandlePathOz()``` method. - -**handlePathOz.onDestroy() ->** It can be called with the Activity or fragment's ```onDestroy()``` method. -This method destroys the task and its cancellation does not update anything and cannot be restarted. -Example of use: - -```java - - @Override - public void onDestroy() { - handlePathOz.onDestroy(); - //You can delete the temporary files here as well. - super.onDestroy(); - } - -``` ## Working with Single uri The next steps only serve to work with a single uri. ### 🎲 Kotlin -#### 💫 Initialization - -1.1 - In Kotlin for the implementation of the Listener you can implement it within the scope of the class, as shown below, or also as shown in item **1.2**: - -```kotlin - - class MainActivity : AppCompatActivity(), HandlePathOzListener.SingleUri { - //... - } - -``` - -`Alt+Enter` to implement the methods, we will discuss the methods later in the topic **Controller**. -Implement handlePathOz in your `onCreate()` method, as shown below: - -```kotlin - - private lateinit var handlePathOz: HandlePathOz - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - //Initialize HandlePathOz - //context, listener - handlePathOz = HandlePathOz(this, this) - } - -``` - -1.2 - You can also implement the Listener when initializing the class, without having to implement it within the scope of the class: - -```kotlin - - private lateinit var handlePathOz: HandlePathOz - private val listener = object: HandlePathOzListener.SingleUri{ - //implement methods - } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - //Initialize HandlePathOz - //context, listener - handlePathOz = HandlePathOz(this, listener) - } - -``` - -2 - After selecting the desired files (The sample application has the entire step) in ```onActivityResult``` leave as follows: - -```kotlin - - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - if ((requestCode == REQUEST_OPEN_GALLERY) and (resultCode == Activity.RESULT_OK)) { - data?.data?.also { it -> - //set uri to handle - handlePathOz.getRealPath(it) - //show Progress Loading - } - } - } - -``` - -#### 🎮 Controller - -Override Listeners - -```kotlin - - //On Completion (Sucess or Error) - //If there is a cancellation or error. - override fun onRequestHandlePathOz(pathOz: PathOz, tr: Throwable?) { - //Hide Progress - - //Now you can work with real path: - Toast.makeText(this, "The real path is: ${pathOz.path} \n The type is: ${path.type}", Toast.LENGTH_SHORT).show() - - //Handle any Exception (Optional) - tr?.let { - Toast.makeText(this, "${it.message}", Toast.LENGTH_SHORT).show() - } - } - -``` - - #### ☁️ Cloud files and Unknown Providers - -If the selected file was from Dropbox,Google Drive, OneDrive or an unknown file provider, it will then be copied/created in -InternalStorage/Android/data/your.package.name/files/Temp/sameFileNameAndExtension -When you want to delete the generated files call: - -```kotlin - - handlePathOz.deleteTemporaryFiles() - -``` - -#### 💣 Cancel the tasks - -There are two methods for canceling tasks, ```cancelTask()``` and ```onDestroy()```. - -**handlePathOz.cancelTask() ->** Can be called as a button action for canceling or by progressBar (As shown in the demo application). - -**handlePathOz.onDestroy() ->** It can be called with the Activity or fragment's ```onDestroy()``` method. -This method destroys the task and its cancellation does not update anything and cannot be restarted. -Example of use: - -```kotlin - - override fun onDestroy() { - handlePathOz.onDestroy() - //You can delete the temporary files here as well. - super.onDestroy() - } - -``` - ---- +You can check in the wikipage, [click here](https://github.com/onimur/handle-path-oz/wiki/Kotlin-Single-Uri). ### 🎲 Java -#### 💫 Initialization - -The implementation of the Listener you can implement it within the scope of the class, as shown below: - -```java - - public class MainActivity extends AppCompatActivity implements HandlePathOzListener.SingleUri { - // - } - -``` - -`Alt+Enter` to implement the methods, we will discuss the methods later in the topic **Controller**. -Implement handlePathOz in your `onCreate()` method, as shown below: - -```java - - private HandlePathOz handlePathOz; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - - //Initialize HandlePathOz - //context, listener - handlePathOz = HandlePathOz(this, this) - } - -``` - -After selecting the desired files (The sample application has the entire step) in ```onActivityResult``` leave as follows: - -```java - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (requestCode == REQUEST_OPEN_GALLERY && resultCode == RESULT_OK) { - Uri uri = data.getData(); - if (uri != null) { - //set Uri to handle - handlePathOz.getRealPath(uri); - //show Progress Loading - } - } - } - -``` - -#### 🎮 Controller - -We have two methods in the listeners, one of which is optional: - -```java - - //On Completion (Sucess or Error) - //If there is a cancellation or error. - @Override - public void onRequestHandlePathOz(@NonNull PathOz pathOz, Throwable tr) { - //Hide Progress - - //Now you can work with real path: - Toast.makeText(this, "The real path is: " + pathOz.getPath + "\n The type is: " + path.getType, Toast.LENGTH_SHORT).show(); - - //Handle Exception (Optional) - if (throwable != null) { - Toast.makeText(this, throwable.getMessage(), Toast.LENGTH_SHORT).show(); - } - } - -``` - -#### ☁️ Cloud files and Unknown Providers - -If the selected file was from Dropbox,Google Drive, OneDrive or an unknown file provider, it will then be copied/created in -InternalStorage/Android/data/your.package.name/files/Temp/sameFileNameAndExtension -When you want to delete the generated files call: - -```java - - handlePathOz.deleteTemporaryFiles() - -``` - -#### 💣 Cancel the tasks - -There are two methods for canceling tasks, ```cancelTask()``` and ```onDestroy()```. - -**handlePathOz.cancelTask() ->** Can be called as a button action for canceling or by progressBar (As shown in the demo application). - -**handlePathOz.onDestroy() ->** It can be called with the Activity or fragment's ```onDestroy()``` method. -This method destroys the task and its cancellation does not update anything and cannot be restarted. -Example of use: - -```java - - @Override - public void onDestroy() { - handlePathOz.onDestroy(); - //You can delete the temporary files here as well. - super.onDestroy(); - } - -``` +You can check in the wikipage, [click here](https://github.com/onimur/handle-path-oz/wiki/Java-Single-Uri). ## 🚀 Projects using this library