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
d578d162
Commit
d578d162
authored
Dec 14, 2019
by
vince-bourgmayer
Browse files
add IntentService to replace CreateInitialFolderOperation
parent
2216c64d
Pipeline
#34173
passed with stage
in 2 minutes and 11 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/foundation/e/drive/backgroundServices/CreateInitialRemoteFoldersIntentService.java
0 → 100644
View file @
d578d162
package
foundation.e.drive.backgroundServices
;
import
android.app.IntentService
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.support.v4.content.LocalBroadcastManager
;
import
android.util.Log
;
import
com.owncloud.android.lib.common.OwnCloudClient
;
import
com.owncloud.android.lib.common.operations.RemoteOperationResult
;
import
com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation
;
import
java.io.File
;
import
foundation.e.drive.database.DbHelper
;
import
foundation.e.drive.models.SyncedFolder
;
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
)
{
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
);
if
(
mSyncedFolder
==
null
)
return
;
//@TODO: Move this check in performTask
performTask
(
mSyncedFolder
,
mCreateFullPath
);
}
private
void
performTask
(
SyncedFolder
mSyncedFolder
,
boolean
mCreateFullPath
){
Intent
resultIntent
=
new
Intent
(
resultIntentActionKey
);
File
folder
=
new
File
(
mSyncedFolder
.
getLocalFolder
()
);
if
(
!
folder
.
exists
()
){
Log
.
e
(
TAG
,
"Local folder doesn't exist, so create it"
);
folder
.
mkdirs
();
}
CreateFolderRemoteOperation
createFolderOperation
=
new
CreateFolderRemoteOperation
(
mSyncedFolder
.
getRemoteFolder
(),
mCreateFullPath
);
RemoteOperationResult
createOperationResult
;
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
);
}
else
{
Log
.
d
(
TAG
,
"insertion of folder in DB failed"
);
resultIntent
.
putExtra
(
resultCodeKey
,
RemoteOperationResult
.
ResultCode
.
FOLDER_ALREADY_EXISTS
);
}
}
else
{
resultIntent
.
putExtra
(
resultCodeKey
,
createOperationResult
.
getCode
());
}
Log
.
d
(
TAG
,
createOperationResult
.
getLogMessage
()+
" \n"
+
createOperationResult
.
getCode
()+
" \n"
+
createOperationResult
.
getHttpCode
()+
" \n"
+
createOperationResult
.
getAuthenticateHeaders
().
toString
());
LocalBroadcastManager
.
getInstance
(
this
).
sendBroadcast
(
resultIntent
);
}
}
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