Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
e
os
eDrive
Commits
683ea5bd
Commit
683ea5bd
authored
Dec 14, 2019
by
vince-bourgmayer
Browse files
add IntentService to create initialFolder on cloud
parent
d578d162
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/src/main/AndroidManifest.xml
View file @
683ea5bd
...
...
@@ -58,7 +58,8 @@ http://www.gnu.org/licenses/gpl.html
<service
android:name=
".services.ObserverService"
android:enabled=
"true"
/>
<service
android:name=
".services.OperationManagerService"
/>
<service
android:name=
".backgroundServices.CreateInitialRemoteFoldersIntentService"
android:enabled=
"true"
/>
<!-- Receivers -->
<receiver
android:name=
".receivers.BootCompleteReceiver"
android:enabled=
"true"
>
...
...
app/src/main/java/foundation/e/drive/backgroundServices/CreateInitialRemoteFoldersIntentService.java
View file @
683ea5bd
package
foundation.e.drive.backgroundServices
;
import
android.accounts.Account
;
import
android.accounts.AccountManager
;
import
android.app.IntentService
;
import
android.content.Intent
;
import
android.os.Bundle
;
...
...
@@ -14,38 +16,46 @@ import java.io.File;
import
foundation.e.drive.database.DbHelper
;
import
foundation.e.drive.models.SyncedFolder
;
import
foundation.e.drive.utils.AppConstants
;
import
foundation.e.drive.utils.CommonUtils
;
import
static
foundation
.
e
.
drive
.
utils
.
AppConstants
.
ACCOUNT_KEY_CODE
;
import
static
foundation
.
e
.
drive
.
utils
.
AppConstants
.
resultCodeKey
;
import
static
foundation
.
e
.
drive
.
utils
.
AppConstants
.
resultIntentActionKey
;
//https://developer.android.com/training/run-background-service/report-status.html
//https://developer.android.com/guide/components/services.html#ExtendingIntentService
public
class
CreateInitialRemoteFoldersIntentService
extends
IntentService
{
private
static
final
String
TAG
=
CreateInitialRemoteFoldersIntentService
.
class
.
getSimpleName
();
public
static
final
String
createFullPathKey
=
"create_full_path"
;
public
static
final
String
syncedFolderKey
=
"synced_folder"
;
public
static
final
String
resultCodeKey
=
"result_code"
;
public
static
final
String
resultIntentActionKey
=
"result"
;
private
OwnCloudClient
client
;
/**
* Creates an IntentService.
*
*/
public
CreateInitialRemoteFoldersIntentService
(
OwnCloudClient
client
)
{
public
CreateInitialRemoteFoldersIntentService
()
{
super
(
TAG
);
client
=
client
;
}
@Override
protected
void
onHandleIntent
(
Intent
workIntent
)
{
if
(
workIntent
==
null
||
workIntent
.
getExtras
()
==
null
)
return
;
Bundle
extras
=
workIntent
.
getExtras
();
boolean
mCreateFullPath
=
extras
.
getBoolean
(
createFullPathKey
);
SyncedFolder
mSyncedFolder
=
(
SyncedFolder
)
extras
.
getParcelable
(
syncedFolderKey
);
Account
mAccount
=
extras
.
getParcelable
(
ACCOUNT_KEY_CODE
);
OwnCloudClient
client
=
CommonUtils
.
getOwnCloudClient
(
mAccount
,
this
);
if
(
mSyncedFolder
==
null
)
return
;
//@TODO: Move this check in performTask
performTask
(
mSyncedFolder
,
mCreateFullPath
);
performTask
(
mSyncedFolder
,
mCreateFullPath
,
client
);
}
private
void
performTask
(
SyncedFolder
mSyncedFolder
,
boolean
mCreateFullPath
){
private
void
performTask
(
SyncedFolder
mSyncedFolder
,
boolean
mCreateFullPath
,
OwnCloudClient
client
){
Intent
resultIntent
=
new
Intent
(
resultIntentActionKey
);
...
...
@@ -60,14 +70,16 @@ public class CreateInitialRemoteFoldersIntentService extends IntentService {
createOperationResult
=
createFolderOperation
.
execute
(
client
,
true
);
if
(
createOperationResult
.
isSuccess
()
||
createOperationResult
.
getCode
()
==
RemoteOperationResult
.
ResultCode
.
FOLDER_ALREADY_EXISTS
){
if
(
DbHelper
.
insertSyncedFolder
(
mSyncedFolder
,
this
)
>=
0
)
{
resultIntent
.
putExtra
(
resultCodeKey
,
RemoteOperationResult
.
ResultCode
.
OK
);
resultIntent
.
putExtra
(
AppConstants
.
resultIntentHttpCodeKey
,
createOperationResult
.
getHttpCode
());
}
else
{
Log
.
d
(
TAG
,
"insertion of folder in DB failed"
);
resultIntent
.
putExtra
(
resultCodeKey
,
RemoteOperationResult
.
ResultCode
.
FOLDER_ALREADY_EXISTS
);
resultIntent
.
putExtra
(
AppConstants
.
resultIntentHttpCodeKey
,
createOperationResult
.
getHttpCode
());
}
}
else
{
resultIntent
.
putExtra
(
resultCodeKey
,
createOperationResult
.
getCode
());
resultIntent
.
putExtra
(
AppConstants
.
resultIntentHttpCodeKey
,
createOperationResult
.
getHttpCode
());
}
Log
.
d
(
TAG
,
createOperationResult
.
getLogMessage
()+
" \n"
+
createOperationResult
.
getCode
()+
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment