This Library is Discontinued as by 2.4.2015
This thread is a open betatest of a new Version of the Dropbox-Sync-Library.
This new Version will allow you to use Dropbox´s Datastores too.
You can find the Dropbox Api documentation here.
You can download the Library-files from my Dropbox-Account here. Examples will follow today too.
Actual Version shared: 3.29 (Library_3.29.rar)
This uses the most up to date Dropbox-SDK 3.1.2
Example 1: (Attached to this post)
This Example Loads a shareable Datastore and when you click on the MenuItem "Copy customers from DB to DS" Parts of the Northwind-Database (SQLite-DB, included in Assets) will be copied into the Datastore. Including BLOBs.
After the Data is inserted you can click on a table to show its content.
When viewing Employees and Categories the content is shown in a ListView (TwoLinesandBitmap)
To use the DropboxSync-Library (and the Datastores) you need to follow Erels Tutorial about the library first. When you setup everything correctly than you can have a look at the new Methods of the DbxAccountManager and the other new objects like DbxDatastore, DbxTable, DbxRecord... You will find more Informations about each object in the next posts.
But let´s start with the additions to the already know DbxAccountManager.
Results true or false. It the app is not linked to an Dropboxaccount then it will be false
If the app is linked (passed the authorization) then this will show true
example:
Gets a list of all linked Accounts (it can be more than one)
example:
Returns some Infos about the linked Account (Username, Organisationname and Displayname
example:
Returns a list of all accessible Datastores
Example:
Deletes the Datastore with the given ID
Example:
Get the Datastore with the given ID
A Datastore (in b4a) is an Instance of an Object of Type DbxDatastore
example:
Creates a PRIVATE Datastore with the given ID.
Private Datastores are not shareable. The are for your own app only.
example
Creates a shareable Datastore. The ID is autocalculated in this case.
THIS is probably the type of Datastore you want to have/use!
If shareds is set to true then the Datastore will become a Principal = PUBLIC and a Role = EDITOR
If shareds is set to false then the defaults from Dropbox will apply.
example:
In relation to SqLite for example we can say:
- A Datastore is likely a Database. It can hold any number of Tables. Each table can hold any number of Records (Object DbxRecord). Each record can hold any number of fields as the Datastores does not have a scheme like oridinary Databasesystems.
- A Record is like in normal Databases a "record" of one Table.
Edit
Autogenerated docs made with xml2bb script from @warwound
DropboxSync
Version: 3.29
This thread is a open betatest of a new Version of the Dropbox-Sync-Library.
This new Version will allow you to use Dropbox´s Datastores too.
You can find the Dropbox Api documentation here.
Actual Version shared: 3.29 (Library_3.29.rar)
This uses the most up to date Dropbox-SDK 3.1.2
Example 1: (Attached to this post)
This Example Loads a shareable Datastore and when you click on the MenuItem "Copy customers from DB to DS" Parts of the Northwind-Database (SQLite-DB, included in Assets) will be copied into the Datastore. Including BLOBs.
After the Data is inserted you can click on a table to show its content.
When viewing Employees and Categories the content is shown in a ListView (TwoLinesandBitmap)
To use the DropboxSync-Library (and the Datastores) you need to follow Erels Tutorial about the library first. When you setup everything correctly than you can have a look at the new Methods of the DbxAccountManager and the other new objects like DbxDatastore, DbxTable, DbxRecord... You will find more Informations about each object in the next posts.
But let´s start with the additions to the already know DbxAccountManager.
B4X:
manager.hasLinkedAccount
If the app is linked (passed the authorization) then this will show true
example:
B4X:
Log("HasLinkedAccount="&manager.hasLinkedAccount)
B4X:
manager.GetLinkedAccounts
example:
B4X:
Dim acclist As List=manager.GetLinkedAccounts
B4X:
manager.GetAccount
example:
B4X:
Dim dbxacc As Map = manager.GetAccount
B4X:
manager.ListDatastores
Example:
B4X:
Dim dslist As List = manager.ListDatastores
Log("dslistsize="&dslist.Size)
For i = 0 To dslist.Size -1
Log(dslist.Get(i))
Next
B4X:
manager.deleteDatastore(<dsid>)
Example:
B4X:
manager.deleteDatastore(".Q6k45pfVTNzrHnP4982XlPAm9v15Fzc0p225LS6mkhQ")
B4X:
manager.getDatastore(<dsid>)
A Datastore (in b4a) is an Instance of an Object of Type DbxDatastore
example:
B4X:
DIM ds as DbxDatastore = manager.getDatastore(".KhR8uRUPUH963GBbcPvn5_RFH3Vp1XKq2pAqZtwynq4")
B4X:
manager.openOrCreateDatastore(<dsid>)
Creates a PRIVATE Datastore with the given ID.
Private Datastores are not shareable. The are for your own app only.
example
B4X:
Dim ds As DbxDatastore = manager.openOrCreateDatastore(".KhR8uRUPUH963GBbcPvn5_RFH3Vp1XKq2pAqZtwynq4")
B4X:
manager.createDatastore(shareds As boolean)
THIS is probably the type of Datastore you want to have/use!
If shareds is set to true then the Datastore will become a Principal = PUBLIC and a Role = EDITOR
If shareds is set to false then the defaults from Dropbox will apply.
example:
B4X:
Dim ds As DbxDatastore = manager.createDatastore(true)
In relation to SqLite for example we can say:
- A Datastore is likely a Database. It can hold any number of Tables. Each table can hold any number of Records (Object DbxRecord). Each record can hold any number of fields as the Datastores does not have a scheme like oridinary Databasesystems.
- A Record is like in normal Databases a "record" of one Table.
Edit
Autogenerated docs made with xml2bb script from @warwound
DropboxSync
Version: 3.29
- DbxAccountManager
Events:- AccountReady (Success As Boolean)
- DatastoreDeleted (Success As Boolean)
- DownloadCompleted (Success As Boolean, LocalDir As String, LocalFileName As String)
- SyncCompleted (Success As Boolean)
- onAccountChange (acc As Object)
- onLinkedAccountChange (mgr as Object As , acc As Object)
- AutoSync As Boolean
If True then the cache will be synchronized automatically when a file is downloaded to assure that the latest file is downloaded.
- DownloadFile (RemoteDir As String, RemoteFile As String, LocalDir As String, LocalFile As String)
Downloads a file. If the file is not already in the cache then it will be automatically downloaded.
The DownloadComplete event will be raised when the local file is ready.
RemoteDir / RemoteFile - Remote path. The root folder (which is the app folder) is "/".
LocalDir / LocalFile - The local file. - GetAccount As Map
- GetLinkedAccount As DbxAccount
- GetLinkedAccounts As List
- Initialize (AppKey As String, AppSecret As String, EventName As String, setdebug As Boolean)
Initializes the object.
AppKey - The app key from Dropbox developer console.
AppSecret - The app secret from Dropbox developer console.
EventName - Sets the subs that will handle the events. - InitializeDatastoreManager
- LinkAccount
Links the application with the user's Dropbox account.
If the account was not linked before then the user will be shown an authentication form.
The AccountReady event will be raised when the account is ready. - ListDatastores As List
- ListFiles (Dir As String) As List
Returns a List with the infos of the files and folders under the given path.
Each item in the list is a DbxFileInfo object. - Sync
Forces a check for new file info from the server. The SyncCompleted event will be raised when the sync is completed. - UnlinkAccount
Unlinks the application from the user's Dropbox account. - UploadFile (LocalDir As String, LocalFile As String, RemoteDir As String, RemoteFile As String)
Writes a file to the local Dropbox cache. The file will be automatically uploaded to the Dropbox account.
LocalDir / LocalFile - Path to the local file.
RemoteDir / RemoteFile - Remote path. The root folder (which is the app folder) is "/".
No event is raised after this action. - addListener (EventName As String)
- createDatastore (shareDS As Boolean) As DbxDatastore
- delete (Dir As String, FileName As String)
- deleteDatastore (dsid As String)
- getDatastore (dsid As String) As DbxDatastore
Return type: @return:the Datastore with the ID dsid - hasLinkedAccount As Boolean
- openDatastore (id As String) As DbxDatastore
- openOrCreateDatastore (id As String) As DbxDatastore
Opens the datastore with the given ID, creating it if it does not already exist.
Datastores can be created offline with this method, and their contents will be
merged with any datastore of the same name when the app is online again.
The same datastore can't be opened more than once. You should generally keep
a datastore open only when your the relevant part of app is on the screen, to
maximize battery life.
You must call DbxDatastore.close() when you are finished with a Datastore.
See DbxDatastore.isValidId() for a description of valid strings for a datastore ID.
Throws
DbxException
if there is a failure opening the datastore. - setDebug (debug As Boolean) As Boolean
debug: the debug to set - stopListening
- android.permission.ACCESS_NETWORK_STATE
- android.permission.INTERNET
- Debug As Boolean [read only]
- FileSystem As DbxFileSystem [read only]
- DbxDatastore
Events:- onstatuschange (ds As DbxDatastore)
- BASE_CHANGE_SIZE As Long
- BASE_DATASTORE_SIZE As Long
- BASE_UNSYNCED_CHANGES_SIZE As Long
- Close
- DATASTORE_SIZE_LIMIT As Long
- GetEffectiveRole As Role
- IsInitialized As Boolean
- ListTables As List
Return type: @return: - RECORD_COUNT_LIMIT As Long
- Sync As Map
- UNSYNCED_CHANGES_SIZE_LIMIT As Long
- getTable (id As String) As DbxTable
Return type: @return: - isOpen As Boolean
Returns whether this DbxDatastore is currently open (i.e. it has not been closed). - isShareable As Boolean
Returns whether this DbxDatastore can be shared with other users. (This is currently equivalent to whether the ID starts with ".".)
Return type: @return: - isWriteable As Boolean
Returns whether this DbxDatastore is writable by the current user. (This is currently equivalent to whether the role is EDITOR or OWNER.) - setrole (principal As String, dsrole As String)
- startListening (EventName As String)
- stopListening
- ID As String [read only]
gets the id of this Datastore - Mtime As Date [read only]
- RecordCount As Long [read only]
getRecordCount - Size As Long [read only]
gets the size - SyncStatus As DbxDatastoreStatus [read only]
- Title As String
Returns the title of this datastore.
- DbxDatastoreStatus
Methods:- IsInitialized As Boolean
- hasIncoming As Boolean
Set when there are remote changes that will be incorporated by the next call to DbxDatastore.sync(). - hasOutgoing As Boolean
Set when there are local changes that haven't yet been committed by a call to DbxDatastore.sync(). - isConnected As Boolean
Set when the API is in active communication with the server, so that remote changes are likely to be visible quickly, and local changes can be uploaded soon. The API will attempt to connect when datastores are open, but may fail if offline. - isDownloading As Boolean
Set when there are remote changes that need to be downloaded from the server. Always set when a DbxDatastore is opened until the first successful check for updates. Always set for a local datastore. - isUploading As Boolean
Set when there are local changes that need to be uploaded to the server. Always set for a local datastore that has any changes at all. - needsReset As Boolean
Set when the datastore needs to be reset with a call to DbxDatastore.close() followed by DbxDatastoreManager.uncacheDatastore().
- DbxFields
Methods:- Fieldnames As List
- Initialize As DbxFields
getRecord delete field name - IsInitialized As Boolean
- deleteField (name As String) As DbxRecord
- getBoolean (name As String) As Boolean
Returns the Boolean "name". - getBytes (name As String) As Byte[]
Returns the Bytes "name". - getDate (name As String) As Long
Returns the Date "name". - getDouble (name As String) As Double
Returns the Double "name". - getFieldType (name As String) As ValueType
Returns the Double "name". - getId (o As Object) As Boolean
- getList (name As String) As DbxList
Returns the List "name". - getLong (name As String) As Long
Returns the Long "name". - getOrCreateList (name As String) As DbxList
Returns the Long "name". - getString (name As String) As String
Returns the String "name". - getTitle (name As String) As String
- hasField (name As String) As Boolean
Returns - hashCode As Int
Returns - isValidFieldName (name As String) As Boolean
- setBoolean (name As String, value As Boolean) As DbxFields
Returns - setByte (name As String, value() As Byte) As DbxFields
Returns - setDate (name As String, value As Long) As DbxFields
Returns - setDouble (name As String, value As Double) As DbxFields
Returns - setFields (fields As DbxFields) As DbxFields
Returns - setList (name As String, value As DbxList) As DbxFields
Returns - setLong (name As String, value As Long) As DbxFields
Returns - setString (name As String, value As String) As DbxFields
Returns
- DbxFileInfo
Methods:- IsInitialized As Boolean
- IsFolder As Boolean [read only]
Tests whether this is a folder. - ModifiedTime As Long [read only]
Returns the last modified time based on the local device system clock. - Name As String [read only]
Returns the file or folder name. - Path As DbxPath [read only]
- Size As Long [read only]
Returns the file size in bytes.
- DbxFileSystem
Events:- onPathChange (Path As DbxPath, m As Mode)
- GetModes As List
- IsInitialized As Boolean
- addPathListener (EventName As String, path As String, m As String)
- stopPathListening (path As DbxPath, mode As Mode)
- DbxList
Methods:- IsInitialized As Boolean
- addBoolean (elem As Boolean) As DbxList
Adds the given boolean value, appending it to the end of the list. Returns a
reference to this object, to allow for call chaining.
elem:
Return type: @return: - addBooleanAt (index As Int, elem As Boolean) As DbxList
Adds the given boolean value, inserting it at the given
index in the list. Returns a reference to this object,
to allow for call chaining.
index:
elem:
Return type: @return: - addByte (elem() As Byte) As DbxList
Adds the given byte value, appending it to the end of the list.
The value must not be null. Returns a reference to this object,
to allow for call chaining.
elem:
Return type: @return: - addByteAt (index As Int, elem() As Byte) As DbxList
Adds the given byte value, inserting it at the given
index in the list. The value must not be null. Returns
a reference to this object, to allow for call chaining.
index:
elem:
Return type: @return: - addDate (elem As Long) As DbxList
Adds the given Date value, appending it to the end of the
list. The value must not be null. Returns a reference to
this object, to allow for call chaining.
elem:
Return type: @return: - addDateAt (index As Int, elem As Long) As DbxList
Adds the given Date value, inserting it at the given
index in the list. The value must not be null. Returns
a reference to this object, to allow for call chaining.
index:
elem:
Return type: @return: - addDouble (elem As Double) As DbxList
Adds the given double value, appending it to the end of the list. Returns a
reference to this object, to allow for call chaining.
elem:
Return type: @return: - addDoubleAt (index As Int, elem As Double) As DbxList
Adds the given double value, inserting it at the given
index in the list. Returns a reference to this object,
to allow for call chaining.
index:
elem:
Return type: @return: - addLong (elem As Long) As DbxList
Adds the given long value, appending it to the end of the list. Returns a
reference to this object, to allow for call chaining.
elem:
Return type: @return: - addLongAt (index As Int, elem As Long) As DbxList
Adds the given long value, inserting it at the given
index in the list. Returns a reference to this object,
to allow for call chaining.
index:
elem:
Return type: @return: - addString (elem As String) As DbxList
Adds the given String value, appending it to the end of the list. The value
must not be null. Returns a reference to this object, to allow for call chaining.
elem:
Return type: @return: - addStringAt (index As Int, elem As String) As DbxList
Adds the given String value, inserting it at the given
index in the list. The value must not be null.Returns
a reference to this object, to allow for call chaining.
index:
elem:
Return type: @return: - clear As DbxList
Deletes all elements from this list.
This operation will override any parallel
changes rather than merging with them. - equals (elem As DbxList) As Boolean
- getBoolean (index As Int) As Boolean
Returns the value of a boolean element at the given index, which must exist and be of the correct type.
index: - getBytes (index As Int) As Byte[]
Returns the value of a byte element at the given index, which must exist and be of the correct type.
index: - getDate (index As Int) As Long
Returns the value of a Date element at the given index, which must exist and be of the correct type.
index: - getDouble (index As Int) As Double
Returns the value of a double element at the given index, which must exist and be of a numerical type.
If the field value is a long, this method will silently convert it to a double. No conversion is
performed on other field types.
index: - getLong (index As Int) As Long
Returns the value of a long element at the given index, which must exist and be of the correct type.
This method won't convert a double or boolean field to a long.
index: - getString (index As Int) As String
Returns the value of a String element at the given index, which must exist and be of the correct type.
index: - getType (index As Integer) As AtomType
Returns the type of the element at the given index.
index:
Return type: @return: - hashCode As Int
- isEmpty As Boolean
Returns whether this list is empty.
Return type: @return: - move (oldindex As Int, newindex As Int) As DbxList
Moves the element at oldIndex (which must exist)
to a position such that its index in the modified
list will be newIndex. Returns a reference to
this object, to allow for call chaining.
oldindex:
newindex:
Return type: @return: - remove (index As Int) As DbxList
Removes the element at the given index,
which must exist. Returns a reference to
this object, to allow for call chaining.
index:
Return type: @return: - setBooleanAt (index As Int, elem As String) As DbxList
Replaces the element at the given index
with a new boolean value. Returns a
reference to this object, to allow for
call chaining.
index:
elem:
Return type: @return: - setByteAt (index As Int, elem() As Byte) As DbxList
Replaces the element at the given index with a
new String value. The value must not be null.
Returns a reference to this object, to allow
for call chaining.
index:
elem:
Return type: @return: - setDateAt (index As Int, elem As Long) As DbxList
Replaces the element at the given index with a
new Date value. The value must not be null.
Returns a reference to this object, to allow
for call chaining.
index:
elem:
Return type: @return: - setDoubleAt (index As Int, elem As Double) As DbxList
Replaces the element at the given index with a
new double value. Returns a reference to this
object, to allow for call chaining.
index:
elem:
Return type: @return: - setLongAt (index As Int, elem As Long) As DbxList
Replaces the element at the given index with
a new long value. Returns a reference to this
object, to allow for call chaining.
index:
elem:
Return type: @return: - setStringAt (index As Int, elem As String) As DbxList
Replaces the element at the given index with a
new String value. The value must not be null.
Returns a reference to this object, to allow
for call chaining.
index:
elem:
Return type: @return: - size As Int
Returns the number of elements in this list.
Return type: @return:integer
- DbxPath
Methods:- IsInitialized As Boolean
- DbxRecord
Methods:- IsInitialized As Boolean
- asMap As Map
- deleteRecord
- fieldNames As List
- getBoolean (name As String) As Boolean
Returns the Boolean "name". - getBytes (name As String) As Byte[]
Returns the Bytes "name". - getDate (name As String) As Date
Returns the Date "name". - getDouble (name As String) As Double
Returns the Double "name". - getFieldType (name As String) As ValueType
Returns the Double "name". - getList (name As String) As DbxList
Returns the List "name". - getLong (name As String) As Long
Returns the Long "name". - getString (name As String) As String
Returns the String "name". - hasField (name As String) As Boolean
Returns - hashCode As Int
Returns - isDeleted As Boolean
Returns - setBoolean (name As String, value As Boolean) As DbxRecord
Returns - setByte (name As String, value() As Byte) As DbxRecord
- setDate (name As String, value As Long) As DbxRecord
- setDouble (name As String, value As Double) As DbxRecord
- setFields (fields As DbxFields) As DbxRecord
- setList (name As String, value As DbxList) As DbxRecord
- setLong (name As String, value As Long) As DbxRecord
- setString (name As String, value As String) As DbxRecord
- Id As String [read only]
gets the ID - Size As Long [read only]
Returns the Long "name".
- DbxTable
Methods:- Insert As DbxRecord
getRecord with ID id - IsInitialized As Boolean
- getOrInsert (id As String) As DbxRecord
- query As QueryResult
- Id As String [read only]
gets the ID
- Insert As DbxRecord
- QueryResult
Methods:- GetAll As List
- IsInitialized As Boolean
- RecordCount As Integer
- hasResults As Boolean
Attachments
Last edited: