Android: provide an ID to document providers
This ID will be useful to get an instance of a document provider back from a different activity. Change-Id: I9419ea23d51f8e9ffd70252bd8e367cf51bde1ad
This commit is contained in:
@@ -57,9 +57,9 @@ public final class DocumentProviderFactory {
|
||||
|
||||
// initialize document providers list
|
||||
instance.providers = new IDocumentProvider[3];
|
||||
instance.providers[0] = new LocalDocumentsDirectoryProvider();
|
||||
instance.providers[1] = new LocalDocumentsProvider();
|
||||
instance.providers[2] = new OwnCloudProvider(context);
|
||||
instance.providers[0] = new LocalDocumentsDirectoryProvider(0);
|
||||
instance.providers[1] = new LocalDocumentsProvider(1);
|
||||
instance.providers[2] = new OwnCloudProvider(2, context);
|
||||
|
||||
// initialize document provider names list
|
||||
instance.providerNames = new String[instance.providers.length];
|
||||
@@ -80,13 +80,14 @@ public final class DocumentProviderFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the provider associated to a certain position.
|
||||
* Retrieve the provider associated to a certain id.
|
||||
*
|
||||
* @param position
|
||||
* @return document provider in that position.
|
||||
* @param id
|
||||
* @return document provider with that id.
|
||||
*/
|
||||
public IDocumentProvider getProvider(int position) {
|
||||
return providers[position];
|
||||
public IDocumentProvider getProvider(int id) {
|
||||
// as for now, id == position in providers array
|
||||
return providers[id];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -43,4 +43,15 @@ public interface IDocumentProvider {
|
||||
* @return string resource pointing to the provider name.
|
||||
*/
|
||||
int getNameResource();
|
||||
|
||||
/**
|
||||
* Provides the unique ID for a document provider instance in a program.
|
||||
*
|
||||
* This ID should be set when the instance is built. It could be used to
|
||||
* tell two instances of the same document provider apart, e. g. two
|
||||
* instances of OwnCloudProvider pointing to different servers.
|
||||
*
|
||||
* @return Unique ID for a document provider instance.
|
||||
*/
|
||||
int getId();
|
||||
}
|
||||
|
@@ -25,6 +25,10 @@ import android.os.Environment;
|
||||
*/
|
||||
public class LocalDocumentsDirectoryProvider extends LocalDocumentsProvider {
|
||||
|
||||
public LocalDocumentsDirectoryProvider(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFile getRootDirectory() {
|
||||
File documentsDirectory = new File(
|
||||
|
@@ -23,6 +23,12 @@ import android.os.Environment;
|
||||
*/
|
||||
public class LocalDocumentsProvider implements IDocumentProvider {
|
||||
|
||||
private int id;
|
||||
|
||||
public LocalDocumentsProvider(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFile getRootDirectory() {
|
||||
return new LocalFile(Environment.getExternalStorageDirectory());
|
||||
@@ -37,4 +43,9 @@ public class LocalDocumentsProvider implements IDocumentProvider {
|
||||
public int getNameResource() {
|
||||
return R.string.local_file_system;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
@@ -29,6 +29,8 @@ import com.owncloud.android.lib.resources.files.RemoteFile;
|
||||
public class OwnCloudProvider implements IDocumentProvider,
|
||||
OnSharedPreferenceChangeListener {
|
||||
|
||||
private int id;
|
||||
|
||||
private Context context;
|
||||
private OwnCloudClient client;
|
||||
private File cacheDir;
|
||||
@@ -37,7 +39,8 @@ public class OwnCloudProvider implements IDocumentProvider,
|
||||
private String userName;
|
||||
private String password;
|
||||
|
||||
public OwnCloudProvider(Context context) {
|
||||
public OwnCloudProvider(int id, Context context) {
|
||||
this.id = id;
|
||||
this.context = context;
|
||||
|
||||
// read preferences
|
||||
@@ -169,4 +172,9 @@ public class OwnCloudProvider implements IDocumentProvider,
|
||||
if (changed)
|
||||
setupClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user