Merge branch 'master' into develop
Conflicts: owncloud-android-library
|
@ -18,8 +18,8 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<manifest package="com.owncloud.android"
|
||||
android:versionCode="10500800"
|
||||
android:versionName="1.5.8" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
android:versionCode="10600000"
|
||||
android:versionName="1.6.0" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
|
||||
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.owncloud.android.workaround.accounts"
|
||||
android:versionCode="0100017"
|
||||
android:versionName="1.0.17" >
|
||||
android:versionCode="0100018"
|
||||
android:versionName="1.0.18" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="16"
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit c29631b8bfea22e5f0b448aab8ffff959ae4de66
|
||||
Subproject commit 5bd0d7387712ce3f53869294761ac4d8537841cd
|
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 2.9 KiB |
Before Width: | Height: | Size: 609 B After Width: | Height: | Size: 476 B |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2 KiB |
Before Width: | Height: | Size: 413 B After Width: | Height: | Size: 307 B |
Before Width: | Height: | Size: 793 B After Width: | Height: | Size: 934 B |
|
@ -16,6 +16,7 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/fileDownloadLL"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
android:layout_centerInParent="true"
|
||||
/>
|
||||
|
||||
<com.ortiz.touch.TouchImageView
|
||||
<com.owncloud.android.utils.TouchImageViewCustom
|
||||
android:id="@+id/image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
|
|
@ -284,7 +284,7 @@
|
|||
|
||||
<string name="prefs_category_accounts">Accounts</string>
|
||||
<string name="prefs_add_account">Add account</string>
|
||||
<string name="auth_redirect_non_secure_connection_title">Secure connection is redirected through an unsecured route.</string>
|
||||
<string name="auth_redirect_non_secure_connection_title">Secure connection is redirected to an unsecured route.</string>
|
||||
|
||||
<string name="actionbar_logger">Logs</string>
|
||||
<string name="log_send_history_button">Send History</string>
|
||||
|
|
|
@ -19,6 +19,7 @@ package com.owncloud.android;
|
|||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
|
||||
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory.Policy;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
@ -55,6 +56,9 @@ public class MainApp extends Application {
|
|||
OwnCloudClientManagerFactory.setDefaultPolicy(Policy.ALWAYS_NEW_CLIENT);
|
||||
}
|
||||
|
||||
// initialise thumbnails cache on background thread
|
||||
new ThumbnailsCacheManager.InitDiskCacheTask().execute();
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
|
||||
String dataFolder = getDataFolder();
|
||||
|
|
|
@ -246,13 +246,17 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
if (mAccount != null) {
|
||||
boolean oAuthRequired =
|
||||
(mAccountMgr.getUserData(mAccount, Constants.KEY_SUPPORTS_OAUTH2) != null);
|
||||
boolean samlWebSsoRequired =
|
||||
(mAccountMgr.getUserData(mAccount, Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null);
|
||||
boolean samlWebSsoRequired = (
|
||||
mAccountMgr.getUserData(
|
||||
mAccount, Constants.KEY_SUPPORTS_SAML_WEB_SSO
|
||||
) != null
|
||||
);
|
||||
mAuthTokenType = chooseAuthTokenType(oAuthRequired, samlWebSsoRequired);
|
||||
|
||||
} else {
|
||||
boolean oAuthSupported = AUTH_ON.equals(getString(R.string.auth_method_oauth2));
|
||||
boolean samlWebSsoSupported = AUTH_ON.equals(getString(R.string.auth_method_saml_web_sso));
|
||||
boolean samlWebSsoSupported =
|
||||
AUTH_ON.equals(getString(R.string.auth_method_saml_web_sso));
|
||||
mAuthTokenType = chooseAuthTokenType(oAuthSupported, samlWebSsoSupported);
|
||||
}
|
||||
}
|
||||
|
@ -321,7 +325,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
if (savedInstanceState == null) {
|
||||
if (mAccount != null) {
|
||||
mServerInfo.mBaseUrl = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_BASE_URL);
|
||||
mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://"); // TODO do this in a setter for mBaseUrl
|
||||
// TODO do next in a setter for mBaseUrl
|
||||
mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://");
|
||||
String ocVersion = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_VERSION);
|
||||
if (ocVersion != null) {
|
||||
mServerInfo.mVersion = new OwnCloudVersion(ocVersion);
|
||||
|
@ -405,8 +410,12 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
@Override
|
||||
public boolean onTouch(View view, MotionEvent event) {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType) &&
|
||||
mHostUrlInput.hasFocus()) {
|
||||
if (
|
||||
AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(
|
||||
MainApp.getAccountType()
|
||||
).equals(mAuthTokenType) &&
|
||||
mHostUrlInput.hasFocus()
|
||||
) {
|
||||
checkOcServer();
|
||||
}
|
||||
}
|
||||
|
@ -534,8 +543,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
/**
|
||||
* Saves relevant state before {@link #onPause()}
|
||||
*
|
||||
* Do NOT save {@link #mNewCapturedUriFromOAuth2Redirection}; it keeps a temporal flag, intended to defer the
|
||||
* processing of the redirection caught in {@link #onNewIntent(Intent)} until {@link #onResume()}
|
||||
* Do NOT save {@link #mNewCapturedUriFromOAuth2Redirection}; it keeps a temporal flag,
|
||||
* intended to defer the processing of the redirection caught in
|
||||
* {@link #onNewIntent(Intent)} until {@link #onResume()}
|
||||
*
|
||||
* See {@link #loadSavedInstanceState(Bundle)}
|
||||
*/
|
||||
|
@ -574,11 +584,11 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
|
||||
|
||||
/**
|
||||
* The redirection triggered by the OAuth authentication server as response to the GET AUTHORIZATION request
|
||||
* is caught here.
|
||||
* The redirection triggered by the OAuth authentication server as response to the
|
||||
* GET AUTHORIZATION request is caught here.
|
||||
*
|
||||
* To make this possible, this activity needs to be qualified with android:launchMode = "singleTask" in the
|
||||
* AndroidManifest.xml file.
|
||||
* To make this possible, this activity needs to be qualified with android:launchMode =
|
||||
* "singleTask" in the AndroidManifest.xml file.
|
||||
*/
|
||||
@Override
|
||||
protected void onNewIntent (Intent intent) {
|
||||
|
@ -591,8 +601,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
|
||||
|
||||
/**
|
||||
* The redirection triggered by the OAuth authentication server as response to the GET AUTHORIZATION, and
|
||||
* deferred in {@link #onNewIntent(Intent)}, is processed here.
|
||||
* The redirection triggered by the OAuth authentication server as response to the
|
||||
* GET AUTHORIZATION, and deferred in {@link #onNewIntent(Intent)}, is processed here.
|
||||
*/
|
||||
@Override
|
||||
protected void onResume() {
|
||||
|
@ -733,7 +743,10 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
|
||||
Intent getServerInfoIntent = new Intent();
|
||||
getServerInfoIntent.setAction(OperationsService.ACTION_GET_SERVER_INFO);
|
||||
getServerInfoIntent.putExtra(OperationsService.EXTRA_SERVER_URL, uri);
|
||||
getServerInfoIntent.putExtra(
|
||||
OperationsService.EXTRA_SERVER_URL,
|
||||
normalizeUrlSuffix(uri)
|
||||
);
|
||||
if (mOperationsServiceBinder != null) {
|
||||
mWaitingForOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent);
|
||||
} else {
|
||||
|
@ -777,7 +790,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
}
|
||||
|
||||
private boolean isPasswordVisible() {
|
||||
return ((mPasswordInput.getInputType() & InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
|
||||
return ((mPasswordInput.getInputType() & InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) ==
|
||||
InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
|
||||
}
|
||||
|
||||
private void hidePasswordButton() {
|
||||
|
@ -785,12 +799,16 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
}
|
||||
|
||||
private void showPassword() {
|
||||
mPasswordInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
|
||||
mPasswordInput.setInputType(
|
||||
InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
|
||||
);
|
||||
showViewPasswordButton();
|
||||
}
|
||||
|
||||
private void hidePassword() {
|
||||
mPasswordInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
|
||||
mPasswordInput.setInputType(
|
||||
InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD
|
||||
);
|
||||
showViewPasswordButton();
|
||||
}
|
||||
|
||||
|
@ -822,9 +840,13 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
return;
|
||||
}
|
||||
|
||||
if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()).equals(mAuthTokenType)) {
|
||||
if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()).
|
||||
equals(mAuthTokenType)) {
|
||||
|
||||
startOauthorization();
|
||||
} else if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType)) {
|
||||
} else if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).
|
||||
equals(mAuthTokenType)) {
|
||||
|
||||
startSamlBasedFederatedSingleSignOnAuthorization();
|
||||
} else {
|
||||
checkBasicAuthorization();
|
||||
|
@ -879,10 +901,18 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
// GET AUTHORIZATION request
|
||||
Uri uri = Uri.parse(mOAuthAuthEndpointText.getText().toString().trim());
|
||||
Uri.Builder uriBuilder = uri.buildUpon();
|
||||
uriBuilder.appendQueryParameter(OAuth2Constants.KEY_RESPONSE_TYPE, getString(R.string.oauth2_response_type));
|
||||
uriBuilder.appendQueryParameter(OAuth2Constants.KEY_REDIRECT_URI, getString(R.string.oauth2_redirect_uri));
|
||||
uriBuilder.appendQueryParameter(OAuth2Constants.KEY_CLIENT_ID, getString(R.string.oauth2_client_id));
|
||||
uriBuilder.appendQueryParameter(OAuth2Constants.KEY_SCOPE, getString(R.string.oauth2_scope));
|
||||
uriBuilder.appendQueryParameter(
|
||||
OAuth2Constants.KEY_RESPONSE_TYPE, getString(R.string.oauth2_response_type)
|
||||
);
|
||||
uriBuilder.appendQueryParameter(
|
||||
OAuth2Constants.KEY_REDIRECT_URI, getString(R.string.oauth2_redirect_uri)
|
||||
);
|
||||
uriBuilder.appendQueryParameter(
|
||||
OAuth2Constants.KEY_CLIENT_ID, getString(R.string.oauth2_client_id)
|
||||
);
|
||||
uriBuilder.appendQueryParameter(
|
||||
OAuth2Constants.KEY_SCOPE, getString(R.string.oauth2_scope)
|
||||
);
|
||||
uri = uriBuilder.build();
|
||||
Log_OC.d(TAG, "Starting browser to view " + uri.toString());
|
||||
Intent i = new Intent(Intent.ACTION_VIEW, uri);
|
||||
|
@ -927,7 +957,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
|
||||
} else if (operation instanceof ExistenceCheckRemoteOperation) {
|
||||
//Log_OC.wtf(TAG, "received detection response through callback" );
|
||||
if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType)) {
|
||||
if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).
|
||||
equals(mAuthTokenType)) {
|
||||
onSamlBasedFederatedSingleSignOnAuthorizationStart(result);
|
||||
|
||||
} else {
|
||||
|
@ -1081,14 +1112,18 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
}
|
||||
}
|
||||
|
||||
url = trimUrlWebdav(url);
|
||||
url = normalizeUrlSuffix(url);
|
||||
}
|
||||
return (url != null ? url : "");
|
||||
}
|
||||
|
||||
|
||||
private String normalizeUrlSuffix(String url) {
|
||||
if (url.endsWith("/")) {
|
||||
url = url.substring(0, url.length() - 1);
|
||||
}
|
||||
|
||||
}
|
||||
return (url != null ? url : "");
|
||||
url = trimUrlWebdav(url);
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1299,7 +1334,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> tokens = (Map<String, String>)(result.getData().get(0));
|
||||
mAuthToken = tokens.get(OAuth2Constants.KEY_ACCESS_TOKEN);
|
||||
//mAuthToken = ((OAuth2GetAccessToken)operation).getResultTokenMap().get(OAuth2Constants.KEY_ACCESS_TOKEN);
|
||||
Log_OC.d(TAG, "Got ACCESS TOKEN: " + mAuthToken);
|
||||
|
||||
accessRootFolderRemoteOperation("", "");
|
||||
|
@ -1358,7 +1392,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
showRefreshButton(true);
|
||||
mOkButton.setEnabled(false);
|
||||
|
||||
// very special case (TODO: move to a common place for all the remote operations) (dangerous here?)
|
||||
// very special case (TODO: move to a common place for all the remote operations)
|
||||
if (result.getCode() == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) {
|
||||
showUntrustedCertDialog(result);
|
||||
}
|
||||
|
@ -1374,23 +1408,27 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
|
||||
|
||||
/**
|
||||
* Sets the proper response to get that the Account Authenticator that started this activity saves
|
||||
* a new authorization token for mAccount.
|
||||
* Sets the proper response to get that the Account Authenticator that started this activity
|
||||
* saves a new authorization token for mAccount.
|
||||
*/
|
||||
private void updateToken() {
|
||||
Bundle response = new Bundle();
|
||||
response.putString(AccountManager.KEY_ACCOUNT_NAME, mAccount.name);
|
||||
response.putString(AccountManager.KEY_ACCOUNT_TYPE, mAccount.type);
|
||||
|
||||
if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()).equals(mAuthTokenType)) {
|
||||
if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()).
|
||||
equals(mAuthTokenType)) {
|
||||
response.putString(AccountManager.KEY_AUTHTOKEN, mAuthToken);
|
||||
// the next line is necessary; by now, notifications are calling directly to the AuthenticatorActivity to update, without AccountManager intervention
|
||||
// the next line is necessary, notifications are calling directly to the
|
||||
// AuthenticatorActivity to update, without AccountManager intervention
|
||||
mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);
|
||||
|
||||
} else if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType)) {
|
||||
} else if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).
|
||||
equals(mAuthTokenType)) {
|
||||
|
||||
response.putString(AccountManager.KEY_AUTHTOKEN, mAuthToken);
|
||||
// the next line is necessary; by now, notifications are calling directly to the AuthenticatorActivity to update, without AccountManager intervention
|
||||
// the next line is necessary; by now, notifications are calling directly to the
|
||||
// AuthenticatorActivity to update, without AccountManager intervention
|
||||
mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);
|
||||
|
||||
} else {
|
||||
|
@ -1411,8 +1449,10 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
*/
|
||||
private boolean createAccount() {
|
||||
/// create and save new ownCloud account
|
||||
boolean isOAuth = AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()).equals(mAuthTokenType);
|
||||
boolean isSaml = AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType);
|
||||
boolean isOAuth = AccountTypeUtils.
|
||||
getAuthTokenTypeAccessToken(MainApp.getAccountType()).equals(mAuthTokenType);
|
||||
boolean isSaml = AccountTypeUtils.
|
||||
getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType);
|
||||
|
||||
Uri uri = Uri.parse(mServerInfo.mBaseUrl);
|
||||
String username = mUsernameInput.getText().toString().trim();
|
||||
|
@ -1434,9 +1474,12 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
mAccount = newAccount;
|
||||
|
||||
if (isOAuth || isSaml) {
|
||||
mAccountMgr.addAccountExplicitly(mAccount, "", null); // with external authorizations, the password is never input in the app
|
||||
// with external authorizations, the password is never input in the app
|
||||
mAccountMgr.addAccountExplicitly(mAccount, "", null);
|
||||
} else {
|
||||
mAccountMgr.addAccountExplicitly(mAccount, mPasswordInput.getText().toString(), null);
|
||||
mAccountMgr.addAccountExplicitly(
|
||||
mAccount, mPasswordInput.getText().toString(), null
|
||||
);
|
||||
}
|
||||
|
||||
/// add the new account as default in preferences, if there is none already
|
||||
|
@ -1449,7 +1492,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
}
|
||||
|
||||
/// prepare result to return to the Authenticator
|
||||
// TODO check again what the Authenticator makes with it; probably has the same effect as addAccountExplicitly, but it's not well done
|
||||
// TODO check again what the Authenticator makes with it; probably has the same
|
||||
// effect as addAccountExplicitly, but it's not well done
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, MainApp.getAccountType());
|
||||
intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mAccount.name);
|
||||
|
@ -1459,9 +1503,14 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
if (isOAuth || isSaml) {
|
||||
mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);
|
||||
}
|
||||
/// add user data to the new account; TODO probably can be done in the last parameter addAccountExplicitly, or in KEY_USERDATA
|
||||
mAccountMgr.setUserData(mAccount, Constants.KEY_OC_VERSION, mServerInfo.mVersion.getVersion());
|
||||
mAccountMgr.setUserData(mAccount, Constants.KEY_OC_BASE_URL, mServerInfo.mBaseUrl);
|
||||
/// add user data to the new account; TODO probably can be done in the last parameter
|
||||
// addAccountExplicitly, or in KEY_USERDATA
|
||||
mAccountMgr.setUserData(
|
||||
mAccount, Constants.KEY_OC_VERSION, mServerInfo.mVersion.getVersion()
|
||||
);
|
||||
mAccountMgr.setUserData(
|
||||
mAccount, Constants.KEY_OC_BASE_URL, mServerInfo.mBaseUrl
|
||||
);
|
||||
|
||||
if (isSaml) {
|
||||
mAccountMgr.setUserData(mAccount, Constants.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE");
|
||||
|
@ -1483,7 +1532,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
* @param view 'Account register' button
|
||||
*/
|
||||
public void onRegisterClick(View view) {
|
||||
Intent register = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.welcome_link_url)));
|
||||
Intent register = new Intent(
|
||||
Intent.ACTION_VIEW, Uri.parse(getString(R.string.welcome_link_url))
|
||||
);
|
||||
setResult(RESULT_CANCELED);
|
||||
startActivity(register);
|
||||
}
|
||||
|
@ -1583,18 +1634,21 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
/**
|
||||
* Called when the 'action' button in an IME is pressed ('enter' in software keyboard).
|
||||
*
|
||||
* Used to trigger the authentication check when the user presses 'enter' after writing the password,
|
||||
* or to throw the server test when the only field on screen is the URL input field.
|
||||
* Used to trigger the authentication check when the user presses 'enter' after writing the
|
||||
* password, or to throw the server test when the only field on screen is the URL input field.
|
||||
*/
|
||||
@Override
|
||||
public boolean onEditorAction(TextView inputField, int actionId, KeyEvent event) {
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE && inputField != null && inputField.equals(mPasswordInput)) {
|
||||
if (actionId == EditorInfo.IME_ACTION_DONE && inputField != null &&
|
||||
inputField.equals(mPasswordInput)) {
|
||||
if (mOkButton.isEnabled()) {
|
||||
mOkButton.performClick();
|
||||
}
|
||||
|
||||
} else if (actionId == EditorInfo.IME_ACTION_NEXT && inputField != null && inputField.equals(mHostUrlInput)) {
|
||||
if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType)) {
|
||||
} else if (actionId == EditorInfo.IME_ACTION_NEXT && inputField != null &&
|
||||
inputField.equals(mHostUrlInput)) {
|
||||
if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).
|
||||
equals(mAuthTokenType)) {
|
||||
checkOcServer();
|
||||
}
|
||||
}
|
||||
|
@ -1622,8 +1676,10 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
final int x = (int) event.getX();
|
||||
final int y = (int) event.getY();
|
||||
final Rect bounds = rightDrawable.getBounds();
|
||||
if (x >= (view.getRight() - bounds.width() - fuzz) && x <= (view.getRight() - view.getPaddingRight() + fuzz)
|
||||
&& y >= (view.getPaddingTop() - fuzz) && y <= (view.getHeight() - view.getPaddingBottom()) + fuzz) {
|
||||
if ( x >= (view.getRight() - bounds.width() - fuzz) &&
|
||||
x <= (view.getRight() - view.getPaddingRight() + fuzz) &&
|
||||
y >= (view.getPaddingTop() - fuzz) &&
|
||||
y <= (view.getHeight() - view.getPaddingBottom()) + fuzz) {
|
||||
|
||||
return onDrawableTouch(event);
|
||||
}
|
||||
|
@ -1672,7 +1728,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType) &&
|
||||
if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).
|
||||
equals(mAuthTokenType) &&
|
||||
mHostUrlInput.hasFocus() && event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
checkOcServer();
|
||||
}
|
||||
|
@ -1683,13 +1740,16 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
/**
|
||||
* Show untrusted cert dialog
|
||||
*/
|
||||
public void showUntrustedCertDialog(X509Certificate x509Certificate, SslError error, SslErrorHandler handler) {
|
||||
public void showUntrustedCertDialog(
|
||||
X509Certificate x509Certificate, SslError error, SslErrorHandler handler
|
||||
) {
|
||||
// Show a dialog with the certificate info
|
||||
SslUntrustedCertDialog dialog = null;
|
||||
if (x509Certificate == null) {
|
||||
dialog = SslUntrustedCertDialog.newInstanceForEmptySslError(error, handler);
|
||||
} else {
|
||||
dialog = SslUntrustedCertDialog.newInstanceForFullSslError(x509Certificate, error, handler);
|
||||
dialog = SslUntrustedCertDialog.
|
||||
newInstanceForFullSslError(x509Certificate, error, handler);
|
||||
}
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
FragmentTransaction ft = fm.beginTransaction();
|
||||
|
@ -1703,7 +1763,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
*/
|
||||
private void showUntrustedCertDialog(RemoteOperationResult result) {
|
||||
// Show a dialog with the certificate info
|
||||
SslUntrustedCertDialog dialog = SslUntrustedCertDialog.newInstanceForFullSslError((CertificateCombinedException)result.getException());
|
||||
SslUntrustedCertDialog dialog = SslUntrustedCertDialog.
|
||||
newInstanceForFullSslError((CertificateCombinedException)result.getException());
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
FragmentTransaction ft = fm.beginTransaction();
|
||||
ft.addToBackStack(null);
|
||||
|
@ -1717,7 +1778,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
public void onSavedCertificate() {
|
||||
Fragment fd = getSupportFragmentManager().findFragmentByTag(SAML_DIALOG_TAG);
|
||||
if (fd == null) {
|
||||
// if SAML dialog is not shown, the SslDialog was shown due to an SSL error in the server check
|
||||
// if SAML dialog is not shown,
|
||||
// the SslDialog was shown due to an SSL error in the server check
|
||||
checkOcServer();
|
||||
}
|
||||
}
|
||||
|
@ -1767,7 +1829,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName component, IBinder service) {
|
||||
if (component.equals(new ComponentName(AuthenticatorActivity.this, OperationsService.class))) {
|
||||
if (component.equals(
|
||||
new ComponentName(AuthenticatorActivity.this, OperationsService.class)
|
||||
)) {
|
||||
//Log_OC.wtf(TAG, "Operations service connected");
|
||||
mOperationsServiceBinder = (OperationsServiceBinder) service;
|
||||
|
||||
|
@ -1781,7 +1845,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName component) {
|
||||
if (component.equals(new ComponentName(AuthenticatorActivity.this, OperationsService.class))) {
|
||||
if (component.equals(
|
||||
new ComponentName(AuthenticatorActivity.this, OperationsService.class)
|
||||
)) {
|
||||
Log_OC.e(TAG, "Operations service crashed");
|
||||
mOperationsServiceBinder = null;
|
||||
}
|
||||
|
@ -1797,7 +1863,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
public void createAuthenticationDialog(WebView webView, HttpAuthHandler handler) {
|
||||
|
||||
// Show a dialog with the certificate info
|
||||
CredentialsDialogFragment dialog = CredentialsDialogFragment.newInstanceForCredentials(webView, handler);
|
||||
CredentialsDialogFragment dialog =
|
||||
CredentialsDialogFragment.newInstanceForCredentials(webView, handler);
|
||||
FragmentManager fm = getSupportFragmentManager();
|
||||
FragmentTransaction ft = fm.beginTransaction();
|
||||
ft.addToBackStack(null);
|
||||
|
@ -1805,7 +1872,11 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
|
|||
dialog.show(ft, CREDENTIALS_DIALOG_TAG);
|
||||
|
||||
if (!mIsFirstAuthAttempt) {
|
||||
Toast.makeText(getApplicationContext(), getText(R.string.saml_authentication_wrong_pass), Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(
|
||||
getApplicationContext(),
|
||||
getText(R.string.saml_authentication_wrong_pass),
|
||||
Toast.LENGTH_LONG
|
||||
).show();
|
||||
} else {
|
||||
mIsFirstAuthAttempt = false;
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ public class FileDataStorageManager {
|
|||
public Vector<OCFile> getFolderImages(OCFile folder) {
|
||||
Vector<OCFile> ret = new Vector<OCFile>();
|
||||
if (folder != null) {
|
||||
// TODO better implementation, filtering in the access to database (if possible) instead of here
|
||||
// TODO better implementation, filtering in the access to database instead of here
|
||||
Vector<OCFile> tmp = getFolderContent(folder);
|
||||
OCFile current = null;
|
||||
for (int i=0; i<tmp.size(); i++) {
|
||||
|
@ -169,7 +169,10 @@ public class FileDataStorageManager {
|
|||
boolean overriden = false;
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp());
|
||||
cv.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA, file.getModificationTimestampAtLastSyncForData());
|
||||
cv.put(
|
||||
ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA,
|
||||
file.getModificationTimestampAtLastSyncForData()
|
||||
);
|
||||
cv.put(ProviderTableMeta.FILE_CREATION, file.getCreationTimestamp());
|
||||
cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
|
||||
cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimetype());
|
||||
|
@ -192,7 +195,7 @@ public class FileDataStorageManager {
|
|||
|
||||
boolean sameRemotePath = fileExists(file.getRemotePath());
|
||||
if (sameRemotePath ||
|
||||
fileExists(file.getFileId()) ) { // for renamed files; no more delete and create
|
||||
fileExists(file.getFileId()) ) { // for renamed files
|
||||
|
||||
OCFile oldFile = null;
|
||||
if (sameRemotePath) {
|
||||
|
@ -260,17 +263,24 @@ public class FileDataStorageManager {
|
|||
* @param files
|
||||
* @param removeNotUpdated
|
||||
*/
|
||||
public void saveFolder(OCFile folder, Collection<OCFile> updatedFiles, Collection<OCFile> filesToRemove) {
|
||||
public void saveFolder(
|
||||
OCFile folder, Collection<OCFile> updatedFiles, Collection<OCFile> filesToRemove
|
||||
) {
|
||||
|
||||
Log_OC.d(TAG, "Saving folder " + folder.getRemotePath() + " with " + updatedFiles.size() + " children and " + filesToRemove.size() + " files to remove");
|
||||
Log_OC.d(TAG, "Saving folder " + folder.getRemotePath() + " with " + updatedFiles.size()
|
||||
+ " children and " + filesToRemove.size() + " files to remove");
|
||||
|
||||
ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(updatedFiles.size());
|
||||
ArrayList<ContentProviderOperation> operations =
|
||||
new ArrayList<ContentProviderOperation>(updatedFiles.size());
|
||||
|
||||
// prepare operations to insert or update files to save in the given folder
|
||||
for (OCFile file : updatedFiles) {
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp());
|
||||
cv.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA, file.getModificationTimestampAtLastSyncForData());
|
||||
cv.put(
|
||||
ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA,
|
||||
file.getModificationTimestampAtLastSyncForData()
|
||||
);
|
||||
cv.put(ProviderTableMeta.FILE_CREATION, file.getCreationTimestamp());
|
||||
cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
|
||||
cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimetype());
|
||||
|
@ -302,29 +312,40 @@ public class FileDataStorageManager {
|
|||
|
||||
} else {
|
||||
// adding a new file
|
||||
operations.add(ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI).withValues(cv).build());
|
||||
operations.add(ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI).
|
||||
withValues(cv).build());
|
||||
}
|
||||
}
|
||||
|
||||
// prepare operations to remove files in the given folder
|
||||
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?" + " AND " + ProviderTableMeta.FILE_PATH + "=?";
|
||||
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?" + " AND " +
|
||||
ProviderTableMeta.FILE_PATH + "=?";
|
||||
String [] whereArgs = null;
|
||||
for (OCFile file : filesToRemove) {
|
||||
if (file.getParentId() == folder.getFileId()) {
|
||||
whereArgs = new String[]{mAccount.name, file.getRemotePath()};
|
||||
//Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, "" + file.getFileId());
|
||||
if (file.isFolder()) {
|
||||
operations.add(ContentProviderOperation
|
||||
.newDelete(ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_DIR, file.getFileId())).withSelection(where, whereArgs)
|
||||
.build());
|
||||
// TODO remove local folder
|
||||
operations.add(ContentProviderOperation.newDelete(
|
||||
ContentUris.withAppendedId(
|
||||
ProviderTableMeta.CONTENT_URI_DIR, file.getFileId()
|
||||
)
|
||||
).withSelection(where, whereArgs).build());
|
||||
|
||||
File localFolder =
|
||||
new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file));
|
||||
if (localFolder.exists()) {
|
||||
removeLocalFolder(localFolder);
|
||||
}
|
||||
} else {
|
||||
operations.add(ContentProviderOperation
|
||||
.newDelete(ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, file.getFileId())).withSelection(where, whereArgs)
|
||||
.build());
|
||||
operations.add(ContentProviderOperation.newDelete(
|
||||
ContentUris.withAppendedId(
|
||||
ProviderTableMeta.CONTENT_URI_FILE, file.getFileId()
|
||||
)
|
||||
).withSelection(where, whereArgs).build());
|
||||
|
||||
if (file.isDown()) {
|
||||
new File(file.getStoragePath()).delete();
|
||||
// TODO move the deletion of local contents after success of deletions
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -333,9 +354,12 @@ public class FileDataStorageManager {
|
|||
// update metadata of folder
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(ProviderTableMeta.FILE_MODIFIED, folder.getModificationTimestamp());
|
||||
cv.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA, folder.getModificationTimestampAtLastSyncForData());
|
||||
cv.put(
|
||||
ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA,
|
||||
folder.getModificationTimestampAtLastSyncForData()
|
||||
);
|
||||
cv.put(ProviderTableMeta.FILE_CREATION, folder.getCreationTimestamp());
|
||||
cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, 0); // FileContentProvider calculates the right size
|
||||
cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, 0);
|
||||
cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, folder.getMimetype());
|
||||
cv.put(ProviderTableMeta.FILE_NAME, folder.getFileName());
|
||||
cv.put(ProviderTableMeta.FILE_PARENT, folder.getParentId());
|
||||
|
@ -409,18 +433,21 @@ public class FileDataStorageManager {
|
|||
// Log_OC.d(TAG, "Updating size of " + id);
|
||||
// if (getContentResolver() != null) {
|
||||
// getContentResolver().update(ProviderTableMeta.CONTENT_URI_DIR,
|
||||
// new ContentValues(), // won't be used, but cannot be null; crashes in KLP
|
||||
// new ContentValues(),
|
||||
// won't be used, but cannot be null; crashes in KLP
|
||||
// ProviderTableMeta._ID + "=?",
|
||||
// new String[] { String.valueOf(id) });
|
||||
// } else {
|
||||
// try {
|
||||
// getContentProviderClient().update(ProviderTableMeta.CONTENT_URI_DIR,
|
||||
// new ContentValues(), // won't be used, but cannot be null; crashes in KLP
|
||||
// new ContentValues(),
|
||||
// won't be used, but cannot be null; crashes in KLP
|
||||
// ProviderTableMeta._ID + "=?",
|
||||
// new String[] { String.valueOf(id) });
|
||||
//
|
||||
// } catch (RemoteException e) {
|
||||
// Log_OC.e(TAG, "Exception in update of folder size through compatibility patch " + e.getMessage());
|
||||
// Log_OC.e(
|
||||
// TAG, "Exception in update of folder size through compatibility patch " + e.getMessage());
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
|
@ -437,9 +464,12 @@ public class FileDataStorageManager {
|
|||
|
||||
} else {
|
||||
if (removeDBData) {
|
||||
//Uri file_uri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, ""+file.getFileId());
|
||||
Uri file_uri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, file.getFileId());
|
||||
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?" + " AND " + ProviderTableMeta.FILE_PATH + "=?";
|
||||
Uri file_uri = ContentUris.withAppendedId(
|
||||
ProviderTableMeta.CONTENT_URI_FILE,
|
||||
file.getFileId()
|
||||
);
|
||||
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?" + " AND " +
|
||||
ProviderTableMeta.FILE_PATH + "=?";
|
||||
String [] whereArgs = new String[]{mAccount.name, file.getRemotePath()};
|
||||
int deleted = 0;
|
||||
if (getContentProviderClient() != null) {
|
||||
|
@ -481,8 +511,10 @@ public class FileDataStorageManager {
|
|||
}
|
||||
|
||||
private boolean removeFolderInDb(OCFile folder) {
|
||||
Uri folder_uri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, ""+ folder.getFileId()); // URI for recursive deletion
|
||||
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?" + " AND " + ProviderTableMeta.FILE_PATH + "=?";
|
||||
Uri folder_uri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, "" +
|
||||
folder.getFileId()); // URI for recursive deletion
|
||||
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?" + " AND " +
|
||||
ProviderTableMeta.FILE_PATH + "=?";
|
||||
String [] whereArgs = new String[]{mAccount.name, folder.getRemotePath()};
|
||||
int deleted = 0;
|
||||
if (getContentProviderClient() != null) {
|
||||
|
@ -552,43 +584,67 @@ public class FileDataStorageManager {
|
|||
public void moveFolder(OCFile folder, String newPath) {
|
||||
// TODO check newPath
|
||||
|
||||
if (folder != null && folder.isFolder() && folder.fileExists() && !OCFile.ROOT_PATH.equals(folder.getFileName())) {
|
||||
if ( folder != null && folder.isFolder() &&
|
||||
folder.fileExists() && !OCFile.ROOT_PATH.equals(folder.getFileName())
|
||||
) {
|
||||
/// 1. get all the descendants of 'dir' in a single QUERY (including 'dir')
|
||||
Cursor c = null;
|
||||
if (getContentProviderClient() != null) {
|
||||
try {
|
||||
c = getContentProviderClient().query(ProviderTableMeta.CONTENT_URI,
|
||||
c = getContentProviderClient().query (
|
||||
ProviderTableMeta.CONTENT_URI,
|
||||
null,
|
||||
ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + ProviderTableMeta.FILE_PATH + " LIKE ? ",
|
||||
new String[] { mAccount.name, folder.getRemotePath() + "%" }, ProviderTableMeta.FILE_PATH + " ASC ");
|
||||
ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " +
|
||||
ProviderTableMeta.FILE_PATH + " LIKE ? ",
|
||||
new String[] { mAccount.name, folder.getRemotePath() + "%" },
|
||||
ProviderTableMeta.FILE_PATH + " ASC "
|
||||
);
|
||||
} catch (RemoteException e) {
|
||||
Log_OC.e(TAG, e.getMessage());
|
||||
}
|
||||
} else {
|
||||
c = getContentResolver().query(ProviderTableMeta.CONTENT_URI,
|
||||
c = getContentResolver().query (
|
||||
ProviderTableMeta.CONTENT_URI,
|
||||
null,
|
||||
ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + ProviderTableMeta.FILE_PATH + " LIKE ? ",
|
||||
new String[] { mAccount.name, folder.getRemotePath() + "%" }, ProviderTableMeta.FILE_PATH + " ASC ");
|
||||
ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " +
|
||||
ProviderTableMeta.FILE_PATH + " LIKE ? ",
|
||||
new String[] { mAccount.name, folder.getRemotePath() + "%" },
|
||||
ProviderTableMeta.FILE_PATH + " ASC "
|
||||
);
|
||||
}
|
||||
|
||||
/// 2. prepare a batch of update operations to change all the descendants
|
||||
ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(c.getCount());
|
||||
ArrayList<ContentProviderOperation> operations =
|
||||
new ArrayList<ContentProviderOperation>(c.getCount());
|
||||
int lengthOfOldPath = folder.getRemotePath().length();
|
||||
String defaultSavePath = FileStorageUtils.getSavePath(mAccount.name);
|
||||
int lengthOfOldStoragePath = defaultSavePath.length() + lengthOfOldPath;
|
||||
if (c.moveToFirst()) {
|
||||
do {
|
||||
ContentValues cv = new ContentValues(); // don't take the constructor out of the loop and clear the object
|
||||
ContentValues cv = new ContentValues(); // keep the constructor in the loop
|
||||
OCFile child = createFileInstance(c);
|
||||
cv.put(ProviderTableMeta.FILE_PATH, newPath + child.getRemotePath().substring(lengthOfOldPath));
|
||||
if (child.getStoragePath() != null && child.getStoragePath().startsWith(defaultSavePath)) {
|
||||
cv.put(ProviderTableMeta.FILE_STORAGE_PATH, defaultSavePath + newPath + child.getStoragePath().substring(lengthOfOldStoragePath));
|
||||
cv.put(
|
||||
ProviderTableMeta.FILE_PATH,
|
||||
newPath + child.getRemotePath().substring(lengthOfOldPath)
|
||||
);
|
||||
if ( child.getStoragePath() != null &&
|
||||
child.getStoragePath().startsWith(defaultSavePath) ) {
|
||||
cv.put(
|
||||
ProviderTableMeta.FILE_STORAGE_PATH,
|
||||
defaultSavePath + newPath +
|
||||
child.getStoragePath().substring(lengthOfOldStoragePath)
|
||||
);
|
||||
}
|
||||
operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
|
||||
operations.add(
|
||||
ContentProviderOperation.
|
||||
newUpdate(ProviderTableMeta.CONTENT_URI).
|
||||
withValues(cv).
|
||||
withSelection( ProviderTableMeta._ID + "=?",
|
||||
new String[] { String.valueOf(child.getFileId()) })
|
||||
.build());
|
||||
withSelection(
|
||||
ProviderTableMeta._ID + "=?",
|
||||
new String[] { String.valueOf(child.getFileId()) }
|
||||
).
|
||||
build()
|
||||
);
|
||||
} while (c.moveToNext());
|
||||
}
|
||||
c.close();
|
||||
|
@ -603,10 +659,12 @@ public class FileDataStorageManager {
|
|||
}
|
||||
|
||||
} catch (OperationApplicationException e) {
|
||||
Log_OC.e(TAG, "Fail to update descendants of " + folder.getFileId() + " in database", e);
|
||||
Log_OC.e(TAG, "Fail to update descendants of " +
|
||||
folder.getFileId() + " in database", e);
|
||||
|
||||
} catch (RemoteException e) {
|
||||
Log_OC.e(TAG, "Fail to update desendants of " + folder.getFileId() + " in database", e);
|
||||
Log_OC.e(TAG, "Fail to update desendants of " +
|
||||
folder.getFileId() + " in database", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -851,7 +909,9 @@ public class FileDataStorageManager {
|
|||
file.setStoragePath(c.getString(c
|
||||
.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH)));
|
||||
if (file.getStoragePath() == null) {
|
||||
// try to find existing file and bind it with current account; - with the current update of SynchronizeFolderOperation, this won't be necessary anymore after a full synchronization of the account
|
||||
// try to find existing file and bind it with current account;
|
||||
// with the current update of SynchronizeFolderOperation, this won't be
|
||||
// necessary anymore after a full synchronization of the account
|
||||
File f = new File(FileStorageUtils.getDefaultSavePathFor(mAccount.name, file));
|
||||
if (f.exists()) {
|
||||
file.setStoragePath(f.getAbsolutePath());
|
||||
|
@ -930,13 +990,16 @@ public class FileDataStorageManager {
|
|||
cv.put(ProviderTableMeta.OCSHARES_SHARED_DATE, share.getSharedDate());
|
||||
cv.put(ProviderTableMeta.OCSHARES_EXPIRATION_DATE, share.getExpirationDate());
|
||||
cv.put(ProviderTableMeta.OCSHARES_TOKEN, share.getToken());
|
||||
cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME, share.getSharedWithDisplayName());
|
||||
cv.put(
|
||||
ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME,
|
||||
share.getSharedWithDisplayName()
|
||||
);
|
||||
cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0);
|
||||
cv.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId());
|
||||
cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getIdRemoteShared());
|
||||
cv.put(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER, mAccount.name);
|
||||
|
||||
if (shareExists(share.getIdRemoteShared())) { // for renamed files; no more delete and create
|
||||
if (shareExists(share.getIdRemoteShared())) { // for renamed files
|
||||
|
||||
overriden = true;
|
||||
if (getContentResolver() != null) {
|
||||
|
@ -1038,7 +1101,9 @@ public class FileDataStorageManager {
|
|||
share.setIsFolder(c.getInt(
|
||||
c.getColumnIndex(ProviderTableMeta.OCSHARES_IS_DIRECTORY)) == 1 ? true : false);
|
||||
share.setUserId(c.getLong(c.getColumnIndex(ProviderTableMeta.OCSHARES_USER_ID)));
|
||||
share.setIdRemoteShared(c.getLong(c.getColumnIndex(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED)));
|
||||
share.setIdRemoteShared(
|
||||
c.getLong(c.getColumnIndex(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED))
|
||||
);
|
||||
|
||||
}
|
||||
return share;
|
||||
|
@ -1090,7 +1155,9 @@ public class FileDataStorageManager {
|
|||
|
||||
} else {
|
||||
try {
|
||||
getContentProviderClient().update(ProviderTableMeta.CONTENT_URI, cv, where, whereArgs);
|
||||
getContentProviderClient().update(
|
||||
ProviderTableMeta.CONTENT_URI, cv, where, whereArgs
|
||||
);
|
||||
|
||||
} catch (RemoteException e) {
|
||||
Log_OC.e(TAG, "Exception in cleanSharedFiles" + e.getMessage());
|
||||
|
@ -1102,7 +1169,8 @@ public class FileDataStorageManager {
|
|||
ContentValues cv = new ContentValues();
|
||||
cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, false);
|
||||
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, "");
|
||||
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " + ProviderTableMeta.FILE_PARENT + "=?";
|
||||
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " +
|
||||
ProviderTableMeta.FILE_PARENT + "=?";
|
||||
String [] whereArgs = new String[] { mAccount.name , String.valueOf(folder.getFileId()) };
|
||||
|
||||
if (getContentResolver() != null) {
|
||||
|
@ -1110,7 +1178,9 @@ public class FileDataStorageManager {
|
|||
|
||||
} else {
|
||||
try {
|
||||
getContentProviderClient().update(ProviderTableMeta.CONTENT_URI, cv, where, whereArgs);
|
||||
getContentProviderClient().update(
|
||||
ProviderTableMeta.CONTENT_URI, cv, where, whereArgs
|
||||
);
|
||||
|
||||
} catch (RemoteException e) {
|
||||
Log_OC.e(TAG, "Exception in cleanSharedFilesInFolder " + e.getMessage());
|
||||
|
@ -1127,7 +1197,9 @@ public class FileDataStorageManager {
|
|||
|
||||
} else {
|
||||
try {
|
||||
getContentProviderClient().delete(ProviderTableMeta.CONTENT_URI_SHARE, where, whereArgs);
|
||||
getContentProviderClient().delete(
|
||||
ProviderTableMeta.CONTENT_URI_SHARE, where, whereArgs
|
||||
);
|
||||
|
||||
} catch (RemoteException e) {
|
||||
Log_OC.e(TAG, "Exception in cleanShares" + e.getMessage());
|
||||
|
@ -1138,7 +1210,8 @@ public class FileDataStorageManager {
|
|||
public void saveShares(Collection<OCShare> shares) {
|
||||
cleanShares();
|
||||
if (shares != null) {
|
||||
ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(shares.size());
|
||||
ArrayList<ContentProviderOperation> operations =
|
||||
new ArrayList<ContentProviderOperation>(shares.size());
|
||||
|
||||
// prepare operations to insert or update files to save in the given folder
|
||||
for (OCShare share : shares) {
|
||||
|
@ -1152,7 +1225,10 @@ public class FileDataStorageManager {
|
|||
cv.put(ProviderTableMeta.OCSHARES_SHARED_DATE, share.getSharedDate());
|
||||
cv.put(ProviderTableMeta.OCSHARES_EXPIRATION_DATE, share.getExpirationDate());
|
||||
cv.put(ProviderTableMeta.OCSHARES_TOKEN, share.getToken());
|
||||
cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME, share.getSharedWithDisplayName());
|
||||
cv.put(
|
||||
ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME,
|
||||
share.getSharedWithDisplayName()
|
||||
);
|
||||
cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0);
|
||||
cv.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId());
|
||||
cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getIdRemoteShared());
|
||||
|
@ -1160,15 +1236,23 @@ public class FileDataStorageManager {
|
|||
|
||||
if (shareExists(share.getIdRemoteShared())) {
|
||||
// updating an existing file
|
||||
operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI_SHARE).
|
||||
operations.add(
|
||||
ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI_SHARE).
|
||||
withValues(cv).
|
||||
withSelection( ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + "=?",
|
||||
new String[] { String.valueOf(share.getIdRemoteShared()) })
|
||||
.build());
|
||||
withSelection(
|
||||
ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + "=?",
|
||||
new String[] { String.valueOf(share.getIdRemoteShared()) }
|
||||
).
|
||||
build()
|
||||
);
|
||||
|
||||
} else {
|
||||
// adding a new file
|
||||
operations.add(ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI_SHARE).withValues(cv).build());
|
||||
operations.add(
|
||||
ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI_SHARE).
|
||||
withValues(cv).
|
||||
build()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1176,10 +1260,13 @@ public class FileDataStorageManager {
|
|||
if (operations.size() > 0) {
|
||||
@SuppressWarnings("unused")
|
||||
ContentProviderResult[] results = null;
|
||||
Log_OC.d(TAG, "Sending " + operations.size() + " operations to FileContentProvider");
|
||||
Log_OC.d(TAG, "Sending " + operations.size() +
|
||||
" operations to FileContentProvider");
|
||||
try {
|
||||
if (getContentResolver() != null) {
|
||||
results = getContentResolver().applyBatch(MainApp.getAuthority(), operations);
|
||||
results = getContentResolver().applyBatch(
|
||||
MainApp.getAuthority(), operations
|
||||
);
|
||||
|
||||
} else {
|
||||
results = getContentProviderClient().applyBatch(operations);
|
||||
|
@ -1200,13 +1287,17 @@ public class FileDataStorageManager {
|
|||
cleanSharedFiles();
|
||||
|
||||
if (sharedFiles != null) {
|
||||
ArrayList<ContentProviderOperation> operations = new ArrayList<ContentProviderOperation>(sharedFiles.size());
|
||||
ArrayList<ContentProviderOperation> operations =
|
||||
new ArrayList<ContentProviderOperation>(sharedFiles.size());
|
||||
|
||||
// prepare operations to insert or update files to save in the given folder
|
||||
for (OCFile file : sharedFiles) {
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(ProviderTableMeta.FILE_MODIFIED, file.getModificationTimestamp());
|
||||
cv.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA, file.getModificationTimestampAtLastSyncForData());
|
||||
cv.put(
|
||||
ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA,
|
||||
file.getModificationTimestampAtLastSyncForData()
|
||||
);
|
||||
cv.put(ProviderTableMeta.FILE_CREATION, file.getCreationTimestamp());
|
||||
cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, file.getFileLength());
|
||||
cv.put(ProviderTableMeta.FILE_CONTENT_TYPE, file.getMimetype());
|
||||
|
@ -1218,27 +1309,40 @@ public class FileDataStorageManager {
|
|||
}
|
||||
cv.put(ProviderTableMeta.FILE_ACCOUNT_OWNER, mAccount.name);
|
||||
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE, file.getLastSyncDateForProperties());
|
||||
cv.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA, file.getLastSyncDateForData());
|
||||
cv.put(
|
||||
ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA,
|
||||
file.getLastSyncDateForData()
|
||||
);
|
||||
cv.put(ProviderTableMeta.FILE_KEEP_IN_SYNC, file.keepInSync() ? 1 : 0);
|
||||
cv.put(ProviderTableMeta.FILE_ETAG, file.getEtag());
|
||||
cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, file.isShareByLink() ? 1 : 0);
|
||||
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink());
|
||||
cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
|
||||
cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
|
||||
cv.put(ProviderTableMeta.FILE_UPDATE_THUMBNAIL, file.needsUpdateThumbnail() ? 1 : 0);
|
||||
cv.put(
|
||||
ProviderTableMeta.FILE_UPDATE_THUMBNAIL,
|
||||
file.needsUpdateThumbnail() ? 1 : 0
|
||||
);
|
||||
|
||||
boolean existsByPath = fileExists(file.getRemotePath());
|
||||
if (existsByPath || fileExists(file.getFileId())) {
|
||||
// updating an existing file
|
||||
operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
|
||||
operations.add(
|
||||
ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
|
||||
withValues(cv).
|
||||
withSelection( ProviderTableMeta._ID + "=?",
|
||||
new String[] { String.valueOf(file.getFileId()) })
|
||||
.build());
|
||||
withSelection(
|
||||
ProviderTableMeta._ID + "=?",
|
||||
new String[] { String.valueOf(file.getFileId()) }
|
||||
).build()
|
||||
);
|
||||
|
||||
} else {
|
||||
// adding a new file
|
||||
operations.add(ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI).withValues(cv).build());
|
||||
operations.add(
|
||||
ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI).
|
||||
withValues(cv).
|
||||
build()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1246,10 +1350,13 @@ public class FileDataStorageManager {
|
|||
if (operations.size() > 0) {
|
||||
@SuppressWarnings("unused")
|
||||
ContentProviderResult[] results = null;
|
||||
Log_OC.d(TAG, "Sending " + operations.size() + " operations to FileContentProvider");
|
||||
Log_OC.d(TAG, "Sending " + operations.size() +
|
||||
" operations to FileContentProvider");
|
||||
try {
|
||||
if (getContentResolver() != null) {
|
||||
results = getContentResolver().applyBatch(MainApp.getAuthority(), operations);
|
||||
results = getContentResolver().applyBatch(
|
||||
MainApp.getAuthority(), operations
|
||||
);
|
||||
|
||||
} else {
|
||||
results = getContentProviderClient().applyBatch(operations);
|
||||
|
@ -1268,7 +1375,8 @@ public class FileDataStorageManager {
|
|||
|
||||
public void removeShare(OCShare share){
|
||||
Uri share_uri = ProviderTableMeta.CONTENT_URI_SHARE;
|
||||
String where = ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?" + " AND " + ProviderTableMeta.FILE_PATH + "=?";
|
||||
String where = ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?" + " AND " +
|
||||
ProviderTableMeta.FILE_PATH + "=?";
|
||||
String [] whereArgs = new String[]{mAccount.name, share.getPath()};
|
||||
if (getContentProviderClient() != null) {
|
||||
try {
|
||||
|
@ -1325,7 +1433,10 @@ public class FileDataStorageManager {
|
|||
cv.put(ProviderTableMeta.OCSHARES_SHARED_DATE, share.getSharedDate());
|
||||
cv.put(ProviderTableMeta.OCSHARES_EXPIRATION_DATE, share.getExpirationDate());
|
||||
cv.put(ProviderTableMeta.OCSHARES_TOKEN, share.getToken());
|
||||
cv.put(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME, share.getSharedWithDisplayName());
|
||||
cv.put(
|
||||
ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME,
|
||||
share.getSharedWithDisplayName()
|
||||
);
|
||||
cv.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY, share.isFolder() ? 1 : 0);
|
||||
cv.put(ProviderTableMeta.OCSHARES_USER_ID, share.getUserId());
|
||||
cv.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED, share.getIdRemoteShared());
|
||||
|
@ -1334,7 +1445,8 @@ public class FileDataStorageManager {
|
|||
/*
|
||||
if (shareExists(share.getIdRemoteShared())) {
|
||||
// updating an existing share resource
|
||||
operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI_SHARE).
|
||||
operations.add(
|
||||
ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI_SHARE).
|
||||
withValues(cv).
|
||||
withSelection( ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + "=?",
|
||||
new String[] { String.valueOf(share.getIdRemoteShared()) })
|
||||
|
@ -1343,7 +1455,11 @@ public class FileDataStorageManager {
|
|||
} else {
|
||||
*/
|
||||
// adding a new share resource
|
||||
operations.add(ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI_SHARE).withValues(cv).build());
|
||||
operations.add(
|
||||
ContentProviderOperation.newInsert(ProviderTableMeta.CONTENT_URI_SHARE).
|
||||
withValues(cv).
|
||||
build()
|
||||
);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
@ -1372,18 +1488,23 @@ public class FileDataStorageManager {
|
|||
|
||||
}
|
||||
|
||||
private ArrayList<ContentProviderOperation> prepareRemoveSharesInFolder(OCFile folder, ArrayList<ContentProviderOperation> preparedOperations) {
|
||||
private ArrayList<ContentProviderOperation> prepareRemoveSharesInFolder(
|
||||
OCFile folder, ArrayList<ContentProviderOperation> preparedOperations
|
||||
) {
|
||||
if (folder != null) {
|
||||
String where = ProviderTableMeta.OCSHARES_PATH + "=?" + " AND " + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?";
|
||||
String where = ProviderTableMeta.OCSHARES_PATH + "=?" + " AND "
|
||||
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?";
|
||||
String [] whereArgs = new String[]{ "", mAccount.name };
|
||||
|
||||
Vector<OCFile> files = getFolderContent(folder);
|
||||
|
||||
for (OCFile file : files) {
|
||||
whereArgs[0] = file.getRemotePath();
|
||||
preparedOperations.add(ContentProviderOperation.newDelete(ProviderTableMeta.CONTENT_URI_SHARE)
|
||||
.withSelection(where, whereArgs)
|
||||
.build());
|
||||
preparedOperations.add(
|
||||
ContentProviderOperation.newDelete(ProviderTableMeta.CONTENT_URI_SHARE).
|
||||
withSelection(where, whereArgs).
|
||||
build()
|
||||
);
|
||||
}
|
||||
}
|
||||
return preparedOperations;
|
||||
|
|
265
src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java
Normal file
|
@ -0,0 +1,265 @@
|
|||
/* ownCloud Android client application
|
||||
* Copyright (C) 2012-2014 ownCloud Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.owncloud.android.datamodel;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Bitmap.CompressFormat;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.ThumbnailUtils;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.TypedValue;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.ui.adapter.DiskLruImageCache;
|
||||
import com.owncloud.android.utils.BitmapUtils;
|
||||
import com.owncloud.android.utils.DisplayUtils;
|
||||
|
||||
/**
|
||||
* Manager for concurrent access to thumbnails cache.
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* @author David A. Velasco
|
||||
*/
|
||||
public class ThumbnailsCacheManager {
|
||||
|
||||
private static final String TAG = ThumbnailsCacheManager.class.getSimpleName();
|
||||
|
||||
private static final String CACHE_FOLDER = "thumbnailCache";
|
||||
|
||||
private static final Object mThumbnailsDiskCacheLock = new Object();
|
||||
private static DiskLruImageCache mThumbnailCache = null;
|
||||
private static boolean mThumbnailCacheStarting = true;
|
||||
|
||||
private static final int DISK_CACHE_SIZE = 1024 * 1024 * 10; // 10MB
|
||||
private static final CompressFormat mCompressFormat = CompressFormat.JPEG;
|
||||
private static final int mCompressQuality = 70;
|
||||
|
||||
public static Bitmap mDefaultImg =
|
||||
BitmapFactory.decodeResource(
|
||||
MainApp.getAppContext().getResources(),
|
||||
DisplayUtils.getResourceId("image/png", "default.png")
|
||||
);
|
||||
|
||||
|
||||
public static class InitDiskCacheTask extends AsyncTask<File, Void, Void> {
|
||||
@Override
|
||||
protected Void doInBackground(File... params) {
|
||||
synchronized (mThumbnailsDiskCacheLock) {
|
||||
mThumbnailCacheStarting = true;
|
||||
if (mThumbnailCache == null) {
|
||||
try {
|
||||
// Check if media is mounted or storage is built-in, if so,
|
||||
// try and use external cache dir; otherwise use internal cache dir
|
||||
final String cachePath =
|
||||
MainApp.getAppContext().getExternalCacheDir().getPath() +
|
||||
File.separator + CACHE_FOLDER;
|
||||
Log_OC.d(TAG, "create dir: " + cachePath);
|
||||
final File diskCacheDir = new File(cachePath);
|
||||
mThumbnailCache = new DiskLruImageCache(
|
||||
diskCacheDir,
|
||||
DISK_CACHE_SIZE,
|
||||
mCompressFormat,
|
||||
mCompressQuality
|
||||
);
|
||||
} catch (Exception e) {
|
||||
Log_OC.d(TAG, "Thumbnail cache could not be opened ", e);
|
||||
mThumbnailCache = null;
|
||||
}
|
||||
}
|
||||
mThumbnailCacheStarting = false; // Finished initialization
|
||||
mThumbnailsDiskCacheLock.notifyAll(); // Wake any waiting threads
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void addBitmapToCache(String key, Bitmap bitmap) {
|
||||
synchronized (mThumbnailsDiskCacheLock) {
|
||||
if (mThumbnailCache != null) {
|
||||
mThumbnailCache.put(key, bitmap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Bitmap getBitmapFromDiskCache(String key) {
|
||||
synchronized (mThumbnailsDiskCacheLock) {
|
||||
// Wait while disk cache is started from background thread
|
||||
while (mThumbnailCacheStarting) {
|
||||
try {
|
||||
mThumbnailsDiskCacheLock.wait();
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
if (mThumbnailCache != null) {
|
||||
return (Bitmap) mThumbnailCache.getBitmap(key);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static boolean cancelPotentialWork(OCFile file, ImageView imageView) {
|
||||
final ThumbnailGenerationTask bitmapWorkerTask = getBitmapWorkerTask(imageView);
|
||||
|
||||
if (bitmapWorkerTask != null) {
|
||||
final OCFile bitmapData = bitmapWorkerTask.mFile;
|
||||
// If bitmapData is not yet set or it differs from the new data
|
||||
if (bitmapData == null || bitmapData != file) {
|
||||
// Cancel previous task
|
||||
bitmapWorkerTask.cancel(true);
|
||||
} else {
|
||||
// The same work is already in progress
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// No task associated with the ImageView, or an existing task was cancelled
|
||||
return true;
|
||||
}
|
||||
|
||||
public static ThumbnailGenerationTask getBitmapWorkerTask(ImageView imageView) {
|
||||
if (imageView != null) {
|
||||
final Drawable drawable = imageView.getDrawable();
|
||||
if (drawable instanceof AsyncDrawable) {
|
||||
final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable;
|
||||
return asyncDrawable.getBitmapWorkerTask();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class ThumbnailGenerationTask extends AsyncTask<OCFile, Void, Bitmap> {
|
||||
private final WeakReference<ImageView> mImageViewReference;
|
||||
private OCFile mFile;
|
||||
private FileDataStorageManager mStorageManager;
|
||||
|
||||
public ThumbnailGenerationTask(ImageView imageView, FileDataStorageManager storageManager) {
|
||||
// Use a WeakReference to ensure the ImageView can be garbage collected
|
||||
mImageViewReference = new WeakReference<ImageView>(imageView);
|
||||
if (storageManager == null)
|
||||
throw new IllegalArgumentException("storageManager must not be NULL");
|
||||
mStorageManager = storageManager;
|
||||
}
|
||||
|
||||
// Decode image in background.
|
||||
@Override
|
||||
protected Bitmap doInBackground(OCFile... params) {
|
||||
Bitmap thumbnail = null;
|
||||
|
||||
try {
|
||||
mFile = params[0];
|
||||
final String imageKey = String.valueOf(mFile.getRemoteId());
|
||||
|
||||
// Check disk cache in background thread
|
||||
thumbnail = getBitmapFromDiskCache(imageKey);
|
||||
|
||||
// Not found in disk cache
|
||||
if (thumbnail == null || mFile.needsUpdateThumbnail()) {
|
||||
// Converts dp to pixel
|
||||
Resources r = MainApp.getAppContext().getResources();
|
||||
int px = (int) Math.round(TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP, 150, r.getDisplayMetrics()
|
||||
));
|
||||
|
||||
if (mFile.isDown()){
|
||||
Bitmap bitmap = BitmapUtils.decodeSampledBitmapFromFile(
|
||||
mFile.getStoragePath(), px, px);
|
||||
|
||||
if (bitmap != null) {
|
||||
thumbnail = ThumbnailUtils.extractThumbnail(bitmap, px, px);
|
||||
|
||||
// Add thumbnail to cache
|
||||
addBitmapToCache(imageKey, thumbnail);
|
||||
|
||||
mFile.setNeedsUpdateThumbnail(false);
|
||||
mStorageManager.saveFile(mFile);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Throwable t) {
|
||||
// the app should never break due to a problem with thumbnails
|
||||
Log_OC.e(TAG, "Generation of thumbnail for " + mFile + " failed", t);
|
||||
if (t instanceof OutOfMemoryError) {
|
||||
System.gc();
|
||||
}
|
||||
}
|
||||
|
||||
return thumbnail;
|
||||
}
|
||||
|
||||
protected void onPostExecute(Bitmap bitmap){
|
||||
if (isCancelled()) {
|
||||
bitmap = null;
|
||||
}
|
||||
|
||||
if (mImageViewReference != null && bitmap != null) {
|
||||
final ImageView imageView = mImageViewReference.get();
|
||||
final ThumbnailGenerationTask bitmapWorkerTask =
|
||||
getBitmapWorkerTask(imageView);
|
||||
if (this == bitmapWorkerTask && imageView != null) {
|
||||
if (imageView.getTag().equals(mFile.getFileId())) {
|
||||
imageView.setImageBitmap(bitmap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class AsyncDrawable extends BitmapDrawable {
|
||||
private final WeakReference<ThumbnailGenerationTask> bitmapWorkerTaskReference;
|
||||
|
||||
public AsyncDrawable(
|
||||
Resources res, Bitmap bitmap, ThumbnailGenerationTask bitmapWorkerTask
|
||||
) {
|
||||
|
||||
super(res, bitmap);
|
||||
bitmapWorkerTaskReference =
|
||||
new WeakReference<ThumbnailGenerationTask>(bitmapWorkerTask);
|
||||
}
|
||||
|
||||
public ThumbnailGenerationTask getBitmapWorkerTask() {
|
||||
return bitmapWorkerTaskReference.get();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove from cache the remoteId passed
|
||||
* @param fileRemoteId: remote id of mFile passed
|
||||
*/
|
||||
public static void removeFileFromCache(String fileRemoteId){
|
||||
synchronized (mThumbnailsDiskCacheLock) {
|
||||
if (mThumbnailCache != null) {
|
||||
mThumbnailCache.removeKey(fileRemoteId);
|
||||
}
|
||||
mThumbnailsDiskCacheLock.notifyAll(); // Wake any waiting threads
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -398,6 +398,7 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
|
|||
file.setMimetype(mCurrentDownload.getMimeType());
|
||||
file.setStoragePath(mCurrentDownload.getSavePath());
|
||||
file.setFileLength((new File(mCurrentDownload.getSavePath()).length()));
|
||||
file.setRemoteId(mCurrentDownload.getFile().getRemoteId());
|
||||
mStorageManager.saveFile(file);
|
||||
}
|
||||
|
||||
|
|
|
@ -630,7 +630,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
|
|||
// coincidence; nothing else is needed, the storagePath is right
|
||||
// in the instance returned by mCurrentUpload.getFile()
|
||||
}
|
||||
|
||||
file.setNeedsUpdateThumbnail(true);
|
||||
mStorageManager.saveFile(file);
|
||||
}
|
||||
|
||||
|
@ -641,6 +641,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe
|
|||
file.setModificationTimestamp(remoteFile.getModifiedTimestamp());
|
||||
file.setModificationTimestampAtLastSyncForData(remoteFile.getModifiedTimestamp());
|
||||
// file.setEtag(remoteFile.getEtag()); // TODO Etag, where available
|
||||
file.setRemoteId(remoteFile.getRemoteId());
|
||||
}
|
||||
|
||||
private OCFile obtainNewOCFileToUpload(String remotePath, String localPath, String mimeType,
|
||||
|
|
|
@ -170,6 +170,8 @@ public class SynchronizeFileOperation extends SyncOperation {
|
|||
result = new RemoteOperationResult(ResultCode.OK);
|
||||
|
||||
} else if (serverChanged) {
|
||||
mLocalFile.setRemoteId(mServerFile.getRemoteId());
|
||||
|
||||
if (mSyncFileContents) {
|
||||
requestForDownload(mLocalFile); // local, not server; we won't to keep the value of keepInSync!
|
||||
// the update of local data will be done later by the FileUploader service when the upload finishes
|
||||
|
|
|
@ -70,8 +70,10 @@ public class SynchronizeFolderOperation extends RemoteOperation {
|
|||
|
||||
private static final String TAG = SynchronizeFolderOperation.class.getSimpleName();
|
||||
|
||||
public static final String EVENT_SINGLE_FOLDER_CONTENTS_SYNCED = SynchronizeFolderOperation.class.getName() + ".EVENT_SINGLE_FOLDER_CONTENTS_SYNCED";
|
||||
public static final String EVENT_SINGLE_FOLDER_SHARES_SYNCED = SynchronizeFolderOperation.class.getName() + ".EVENT_SINGLE_FOLDER_SHARES_SYNCED";
|
||||
public static final String EVENT_SINGLE_FOLDER_CONTENTS_SYNCED =
|
||||
SynchronizeFolderOperation.class.getName() + ".EVENT_SINGLE_FOLDER_CONTENTS_SYNCED";
|
||||
public static final String EVENT_SINGLE_FOLDER_SHARES_SYNCED =
|
||||
SynchronizeFolderOperation.class.getName() + ".EVENT_SINGLE_FOLDER_SHARES_SYNCED";
|
||||
|
||||
/** Time stamp for the synchronization process in progress */
|
||||
private long mCurrentSyncTime;
|
||||
|
@ -97,16 +99,19 @@ public class SynchronizeFolderOperation extends RemoteOperation {
|
|||
/** Counter of failed operations in synchronization of kept-in-sync files */
|
||||
private int mFailsInFavouritesFound;
|
||||
|
||||
/** Map of remote and local paths to files that where locally stored in a location out of the ownCloud folder and couldn't be copied automatically into it */
|
||||
/**
|
||||
* Map of remote and local paths to files that where locally stored in a location
|
||||
* out of the ownCloud folder and couldn't be copied automatically into it
|
||||
**/
|
||||
private Map<String, String> mForgottenLocalFiles;
|
||||
|
||||
/** 'True' means that this operation is part of a full account synchronization */
|
||||
private boolean mSyncFullAccount;
|
||||
|
||||
/** 'True' means that Share resources bound to the files into the folder should be refreshed also */
|
||||
/** 'True' means that Share resources bound to the files into should be refreshed also */
|
||||
private boolean mIsShareSupported;
|
||||
|
||||
/** 'True' means that the remote folder changed from last synchronization and should be fetched */
|
||||
/** 'True' means that the remote folder changed and should be fetched */
|
||||
private boolean mRemoteFolderChanged;
|
||||
|
||||
/** 'True' means that Etag will be ignored */
|
||||
|
@ -118,9 +123,12 @@ public class SynchronizeFolderOperation extends RemoteOperation {
|
|||
*
|
||||
* @param remoteFolderPath Remote folder to synchronize.
|
||||
* @param currentSyncTime Time stamp for the synchronization process in progress.
|
||||
* @param localFolderId Identifier in the local database of the folder to synchronize.
|
||||
* @param updateFolderProperties 'True' means that the properties of the folder should be updated also, not just its content.
|
||||
* @param syncFullAccount 'True' means that this operation is part of a full account synchronization.
|
||||
* @param localFolderId Identifier in the local database of the folder
|
||||
* to synchronize.
|
||||
* @param updateFolderProperties 'True' means that the properties of the folder should
|
||||
* be updated also, not just its content.
|
||||
* @param syncFullAccount 'True' means that this operation is part of a full account
|
||||
* synchronization.
|
||||
* @param dataStorageManager Interface with the local database.
|
||||
* @param account ownCloud account where the folder is located.
|
||||
* @param context Application context.
|
||||
|
@ -159,7 +167,8 @@ public class SynchronizeFolderOperation extends RemoteOperation {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the list of files and folders contained in the synchronized folder, if called after synchronization is complete.
|
||||
* Returns the list of files and folders contained in the synchronized folder,
|
||||
* if called after synchronization is complete.
|
||||
*
|
||||
* @return List of files and folders contained in the synchronized folder.
|
||||
*/
|
||||
|
@ -194,7 +203,9 @@ public class SynchronizeFolderOperation extends RemoteOperation {
|
|||
}
|
||||
|
||||
if (!mSyncFullAccount) {
|
||||
sendLocalBroadcast(EVENT_SINGLE_FOLDER_CONTENTS_SYNCED, mLocalFolder.getRemotePath(), result);
|
||||
sendLocalBroadcast(
|
||||
EVENT_SINGLE_FOLDER_CONTENTS_SYNCED, mLocalFolder.getRemotePath(), result
|
||||
);
|
||||
}
|
||||
|
||||
if (result.isSuccess() && mIsShareSupported && !mSyncFullAccount) {
|
||||
|
@ -202,7 +213,9 @@ public class SynchronizeFolderOperation extends RemoteOperation {
|
|||
}
|
||||
|
||||
if (!mSyncFullAccount) {
|
||||
sendLocalBroadcast(EVENT_SINGLE_FOLDER_SHARES_SYNCED, mLocalFolder.getRemotePath(), result);
|
||||
sendLocalBroadcast(
|
||||
EVENT_SINGLE_FOLDER_SHARES_SYNCED, mLocalFolder.getRemotePath(), result
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -235,12 +248,14 @@ public class SynchronizeFolderOperation extends RemoteOperation {
|
|||
|
||||
if (!mIgnoreETag) {
|
||||
// check if remote and local folder are different
|
||||
mRemoteFolderChanged = !(remoteFolder.getEtag().equalsIgnoreCase(mLocalFolder.getEtag()));
|
||||
mRemoteFolderChanged =
|
||||
!(remoteFolder.getEtag().equalsIgnoreCase(mLocalFolder.getEtag()));
|
||||
}
|
||||
|
||||
result = new RemoteOperationResult(ResultCode.OK);
|
||||
|
||||
Log_OC.i(TAG, "Checked " + mAccount.name + remotePath + " : " + (mRemoteFolderChanged ? "changed" : "not changed"));
|
||||
Log_OC.i(TAG, "Checked " + mAccount.name + remotePath + " : " +
|
||||
(mRemoteFolderChanged ? "changed" : "not changed"));
|
||||
|
||||
} else {
|
||||
// check failed
|
||||
|
@ -248,9 +263,11 @@ public class SynchronizeFolderOperation extends RemoteOperation {
|
|||
removeLocalFolder();
|
||||
}
|
||||
if (result.isException()) {
|
||||
Log_OC.e(TAG, "Checked " + mAccount.name + remotePath + " : " + result.getLogMessage(), result.getException());
|
||||
Log_OC.e(TAG, "Checked " + mAccount.name + remotePath + " : " +
|
||||
result.getLogMessage(), result.getException());
|
||||
} else {
|
||||
Log_OC.e(TAG, "Checked " + mAccount.name + remotePath + " : " + result.getLogMessage());
|
||||
Log_OC.e(TAG, "Checked " + mAccount.name + remotePath + " : " +
|
||||
result.getLogMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -267,7 +284,8 @@ public class SynchronizeFolderOperation extends RemoteOperation {
|
|||
if (result.isSuccess()) {
|
||||
synchronizeData(result.getData(), client);
|
||||
if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) {
|
||||
result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT); // should be different result, but will do the job
|
||||
result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT);
|
||||
// should be a different result code, but will do the job
|
||||
}
|
||||
} else {
|
||||
if (result.getCode() == ResultCode.FILE_NOT_FOUND)
|
||||
|
@ -281,7 +299,13 @@ public class SynchronizeFolderOperation extends RemoteOperation {
|
|||
private void removeLocalFolder() {
|
||||
if (mStorageManager.fileExists(mLocalFolder.getFileId())) {
|
||||
String currentSavePath = FileStorageUtils.getSavePath(mAccount.name);
|
||||
mStorageManager.removeFolder(mLocalFolder, true, (mLocalFolder.isDown() && mLocalFolder.getStoragePath().startsWith(currentSavePath)));
|
||||
mStorageManager.removeFolder(
|
||||
mLocalFolder,
|
||||
true,
|
||||
( mLocalFolder.isDown() &&
|
||||
mLocalFolder.getStoragePath().startsWith(currentSavePath)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -296,7 +320,7 @@ public class SynchronizeFolderOperation extends RemoteOperation {
|
|||
*
|
||||
* @param client Client instance to the remote server where the data were
|
||||
* retrieved.
|
||||
* @return 'True' when any change was made in the local data, 'false' otherwise.
|
||||
* @return 'True' when any change was made in the local data, 'false' otherwise
|
||||
*/
|
||||
private void synchronizeData(ArrayList<Object> folderAndFiles, OwnCloudClient client) {
|
||||
// get 'fresh data' from the database
|
||||
|
@ -307,7 +331,8 @@ public class SynchronizeFolderOperation extends RemoteOperation {
|
|||
remoteFolder.setParentId(mLocalFolder.getParentId());
|
||||
remoteFolder.setFileId(mLocalFolder.getFileId());
|
||||
|
||||
Log_OC.d(TAG, "Remote folder " + mLocalFolder.getRemotePath() + " changed - starting update of local data ");
|
||||
Log_OC.d(TAG, "Remote folder " + mLocalFolder.getRemotePath()
|
||||
+ " changed - starting update of local data ");
|
||||
|
||||
List<OCFile> updatedFiles = new Vector<OCFile>(folderAndFiles.size() - 1);
|
||||
List<SynchronizeFileOperation> filesToSyncContents = new Vector<SynchronizeFileOperation>();
|
||||
|
@ -330,27 +355,35 @@ public class SynchronizeFolderOperation extends RemoteOperation {
|
|||
// localFile = mStorageManager.getFileByPath(remoteFile.getRemotePath());
|
||||
localFile = localFilesMap.remove(remoteFile.getRemotePath());
|
||||
|
||||
/// add to the remoteFile (the new one) data about LOCAL STATE (not existing in the server side)
|
||||
/// add to the remoteFile (the new one) data about LOCAL STATE (not existing in server)
|
||||
remoteFile.setLastSyncDateForProperties(mCurrentSyncTime);
|
||||
if (localFile != null) {
|
||||
// some properties of local state are kept unmodified
|
||||
remoteFile.setFileId(localFile.getFileId());
|
||||
remoteFile.setKeepInSync(localFile.keepInSync());
|
||||
remoteFile.setLastSyncDateForData(localFile.getLastSyncDateForData());
|
||||
remoteFile.setModificationTimestampAtLastSyncForData(localFile.getModificationTimestampAtLastSyncForData());
|
||||
remoteFile.setModificationTimestampAtLastSyncForData(
|
||||
localFile.getModificationTimestampAtLastSyncForData()
|
||||
);
|
||||
remoteFile.setStoragePath(localFile.getStoragePath());
|
||||
remoteFile.setEtag(localFile.getEtag()); // eTag will not be updated unless contents are synchronized (Synchronize[File|Folder]Operation with remoteFile as parameter)
|
||||
// eTag will not be updated unless contents are synchronized
|
||||
// (Synchronize[File|Folder]Operation with remoteFile as parameter)
|
||||
remoteFile.setEtag(localFile.getEtag());
|
||||
if (remoteFile.isFolder()) {
|
||||
remoteFile.setFileLength(localFile.getFileLength()); // TODO move operations about size of folders to FileContentProvider
|
||||
remoteFile.setFileLength(localFile.getFileLength());
|
||||
// TODO move operations about size of folders to FileContentProvider
|
||||
}
|
||||
remoteFile.setPublicLink(localFile.getPublicLink());
|
||||
remoteFile.setShareByLink(localFile.isShareByLink());
|
||||
} else {
|
||||
remoteFile.setEtag(""); // remote eTag will not be updated unless contents are synchronized (Synchronize[File|Folder]Operation with remoteFile as parameter)
|
||||
// remote eTag will not be updated unless contents are synchronized
|
||||
// (Synchronize[File|Folder]Operation with remoteFile as parameter)
|
||||
remoteFile.setEtag("");
|
||||
}
|
||||
|
||||
/// check and fix, if needed, local storage path
|
||||
checkAndFixForeignStoragePath(remoteFile); // fixing old policy - now local files must be copied into the ownCloud local folder
|
||||
checkAndFixForeignStoragePath(remoteFile); // policy - local files are COPIED
|
||||
// into the ownCloud local folder;
|
||||
searchForLocalFileInDefaultPath(remoteFile); // legacy
|
||||
|
||||
/// prepare content synchronization for kept-in-sync files
|
||||
|
@ -368,7 +401,7 @@ public class SynchronizeFolderOperation extends RemoteOperation {
|
|||
updatedFiles.add(remoteFile);
|
||||
}
|
||||
|
||||
// save updated contents in local database; all at once, trying to get a best performance in database update (not a big deal, indeed)
|
||||
// save updated contents in local database
|
||||
mStorageManager.saveFolder(remoteFolder, updatedFiles, localFilesMap.values());
|
||||
|
||||
// request for the synchronization of file contents AFTER saving current remote properties
|
||||
|
@ -378,27 +411,32 @@ public class SynchronizeFolderOperation extends RemoteOperation {
|
|||
}
|
||||
|
||||
/**
|
||||
* Performs a list of synchronization operations, determining if a download or upload is needed or
|
||||
* if exists conflict due to changes both in local and remote contents of the each file.
|
||||
* Performs a list of synchronization operations, determining if a download or upload is needed
|
||||
* or if exists conflict due to changes both in local and remote contents of the each file.
|
||||
*
|
||||
* If download or upload is needed, request the operation to the corresponding service and goes on.
|
||||
* If download or upload is needed, request the operation to the corresponding service and goes
|
||||
* on.
|
||||
*
|
||||
* @param filesToSyncContents Synchronization operations to execute.
|
||||
* @param client Interface to the remote ownCloud server.
|
||||
*/
|
||||
private void startContentSynchronizations(List<SynchronizeFileOperation> filesToSyncContents, OwnCloudClient client) {
|
||||
private void startContentSynchronizations(
|
||||
List<SynchronizeFileOperation> filesToSyncContents, OwnCloudClient client
|
||||
) {
|
||||
RemoteOperationResult contentsResult = null;
|
||||
for (SynchronizeFileOperation op: filesToSyncContents) {
|
||||
contentsResult = op.execute(mStorageManager, mContext); // returns without waiting for upload or download finishes
|
||||
contentsResult = op.execute(mStorageManager, mContext); // async
|
||||
if (!contentsResult.isSuccess()) {
|
||||
if (contentsResult.getCode() == ResultCode.SYNC_CONFLICT) {
|
||||
mConflictsFound++;
|
||||
} else {
|
||||
mFailsInFavouritesFound++;
|
||||
if (contentsResult.getException() != null) {
|
||||
Log_OC.e(TAG, "Error while synchronizing favourites : " + contentsResult.getLogMessage(), contentsResult.getException());
|
||||
Log_OC.e(TAG, "Error while synchronizing favourites : "
|
||||
+ contentsResult.getLogMessage(), contentsResult.getException());
|
||||
} else {
|
||||
Log_OC.e(TAG, "Error while synchronizing favourites : " + contentsResult.getLogMessage());
|
||||
Log_OC.e(TAG, "Error while synchronizing favourites : "
|
||||
+ contentsResult.getLogMessage());
|
||||
}
|
||||
}
|
||||
} // won't let these fails break the synchronization process
|
||||
|
@ -430,11 +468,11 @@ public class SynchronizeFolderOperation extends RemoteOperation {
|
|||
|
||||
|
||||
/**
|
||||
* Checks the storage path of the OCFile received as parameter. If it's out of the local ownCloud folder,
|
||||
* tries to copy the file inside it.
|
||||
* Checks the storage path of the OCFile received as parameter.
|
||||
* If it's out of the local ownCloud folder, tries to copy the file inside it.
|
||||
*
|
||||
* If the copy fails, the link to the local file is nullified. The account of forgotten files is kept in
|
||||
* {@link #mForgottenLocalFiles}
|
||||
* If the copy fails, the link to the local file is nullified. The account of forgotten
|
||||
* files is kept in {@link #mForgottenLocalFiles}
|
||||
*)
|
||||
* @param file File to check and fix.
|
||||
*/
|
||||
|
@ -456,7 +494,9 @@ public class SynchronizeFolderOperation extends RemoteOperation {
|
|||
File expectedParent = expectedFile.getParentFile();
|
||||
expectedParent.mkdirs();
|
||||
if (!expectedParent.isDirectory()) {
|
||||
throw new IOException("Unexpected error: parent directory could not be created");
|
||||
throw new IOException(
|
||||
"Unexpected error: parent directory could not be created"
|
||||
);
|
||||
}
|
||||
expectedFile.createNewFile();
|
||||
if (!expectedFile.isFile()) {
|
||||
|
@ -480,12 +520,14 @@ public class SynchronizeFolderOperation extends RemoteOperation {
|
|||
try {
|
||||
if (in != null) in.close();
|
||||
} catch (Exception e) {
|
||||
Log_OC.d(TAG, "Weird exception while closing input stream for " + storagePath + " (ignoring)", e);
|
||||
Log_OC.d(TAG, "Weird exception while closing input stream for "
|
||||
+ storagePath + " (ignoring)", e);
|
||||
}
|
||||
try {
|
||||
if (out != null) out.close();
|
||||
} catch (Exception e) {
|
||||
Log_OC.d(TAG, "Weird exception while closing output stream for " + expectedPath + " (ignoring)", e);
|
||||
Log_OC.d(TAG, "Weird exception while closing output stream for "
|
||||
+ expectedPath + " (ignoring)", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -497,7 +539,8 @@ public class SynchronizeFolderOperation extends RemoteOperation {
|
|||
RemoteOperationResult result = null;
|
||||
|
||||
// remote request
|
||||
GetRemoteSharesForFileOperation operation = new GetRemoteSharesForFileOperation(mLocalFolder.getRemotePath(), false, true);
|
||||
GetRemoteSharesForFileOperation operation =
|
||||
new GetRemoteSharesForFileOperation(mLocalFolder.getRemotePath(), false, true);
|
||||
result = operation.execute(client);
|
||||
|
||||
if (result.isSuccess()) {
|
||||
|
@ -532,13 +575,17 @@ public class SynchronizeFolderOperation extends RemoteOperation {
|
|||
|
||||
|
||||
/**
|
||||
* Sends a message to any application component interested in the progress of the synchronization.
|
||||
* Sends a message to any application component interested in the progress
|
||||
* of the synchronization.
|
||||
*
|
||||
* @param event
|
||||
* @param dirRemotePath Remote path of a folder that was just synchronized (with or without success)
|
||||
* @param dirRemotePath Remote path of a folder that was just synchronized
|
||||
* (with or without success)
|
||||
* @param result
|
||||
*/
|
||||
private void sendLocalBroadcast(String event, String dirRemotePath, RemoteOperationResult result) {
|
||||
private void sendLocalBroadcast(
|
||||
String event, String dirRemotePath, RemoteOperationResult result
|
||||
) {
|
||||
Log_OC.d(TAG, "Send broadcast " + event);
|
||||
Intent intent = new Intent(event);
|
||||
intent.putExtra(FileSyncAdapter.EXTRA_ACCOUNT_NAME, mAccount.name);
|
||||
|
|
|
@ -22,13 +22,12 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
|
||||
import com.owncloud.android.db.ProviderMeta;
|
||||
import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.shares.ShareType;
|
||||
|
||||
|
||||
|
||||
import android.content.ContentProvider;
|
||||
import android.content.ContentProviderOperation;
|
||||
import android.content.ContentProviderResult;
|
||||
|
@ -165,13 +164,14 @@ public class FileContentProvider extends ContentProvider {
|
|||
int count = 0;
|
||||
switch (mUriMatcher.match(uri)) {
|
||||
case SINGLE_FILE:
|
||||
/*Cursor c = query(db, uri, null, where, whereArgs, null);
|
||||
String remotePath = "(unexisting)";
|
||||
Cursor c = query(db, uri, null, where, whereArgs, null);
|
||||
String remoteId = "";
|
||||
if (c != null && c.moveToFirst()) {
|
||||
remotePath = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PATH));
|
||||
remoteId = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID));
|
||||
//ThumbnailsCacheManager.removeFileFromCache(remoteId);
|
||||
}
|
||||
Log_OC.d(TAG, "Removing FILE " + remotePath);
|
||||
*/
|
||||
Log_OC.d(TAG, "Removing FILE " + remoteId);
|
||||
|
||||
count = db.delete(ProviderTableMeta.FILE_TABLE_NAME,
|
||||
ProviderTableMeta._ID
|
||||
+ "="
|
||||
|
@ -201,12 +201,24 @@ public class FileContentProvider extends ContentProvider {
|
|||
//String remotePath;
|
||||
while (!children.isAfterLast()) {
|
||||
childId = children.getLong(children.getColumnIndex(ProviderTableMeta._ID));
|
||||
isDir = "DIR".equals(children.getString(children.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)));
|
||||
isDir = "DIR".equals(children.getString(
|
||||
children.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE)
|
||||
));
|
||||
//remotePath = children.getString(children.getColumnIndex(ProviderTableMeta.FILE_PATH));
|
||||
if (isDir) {
|
||||
count += delete(db, ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_DIR, childId), null, null);
|
||||
count += delete(
|
||||
db,
|
||||
ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_DIR, childId),
|
||||
null,
|
||||
null
|
||||
);
|
||||
} else {
|
||||
count += delete(db, ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, childId), null, null);
|
||||
count += delete(
|
||||
db,
|
||||
ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, childId),
|
||||
null,
|
||||
null
|
||||
);
|
||||
}
|
||||
children.moveToNext();
|
||||
}
|
||||
|
@ -241,7 +253,6 @@ public class FileContentProvider extends ContentProvider {
|
|||
return count;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getType(Uri uri) {
|
||||
switch (mUriMatcher.match(uri)) {
|
||||
|
@ -257,7 +268,6 @@ public class FileContentProvider extends ContentProvider {
|
|||
|
||||
@Override
|
||||
public Uri insert(Uri uri, ContentValues values) {
|
||||
//Log_OC.d(TAG, "Inserting " + values.getAsString(ProviderTableMeta.FILE_PATH) + " at provider " + this);
|
||||
Uri newUri = null;
|
||||
SQLiteDatabase db = mDbHelper.getWritableDatabase();
|
||||
db.beginTransaction();
|
||||
|
@ -277,23 +287,31 @@ public class FileContentProvider extends ContentProvider {
|
|||
case SINGLE_FILE:
|
||||
String remotePath = values.getAsString(ProviderTableMeta.FILE_PATH);
|
||||
String accountName = values.getAsString(ProviderTableMeta.FILE_ACCOUNT_OWNER);
|
||||
String[] projection = new String[] {ProviderTableMeta._ID, ProviderTableMeta.FILE_PATH, ProviderTableMeta.FILE_ACCOUNT_OWNER };
|
||||
String where = ProviderTableMeta.FILE_PATH + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
|
||||
String[] projection = new String[] {
|
||||
ProviderTableMeta._ID, ProviderTableMeta.FILE_PATH,
|
||||
ProviderTableMeta.FILE_ACCOUNT_OWNER
|
||||
};
|
||||
String where = ProviderTableMeta.FILE_PATH + "=? AND " +
|
||||
ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
|
||||
String[] whereArgs = new String[] {remotePath, accountName};
|
||||
Cursor doubleCheck = query(db, uri, projection, where, whereArgs, null);
|
||||
if (doubleCheck == null || !doubleCheck.moveToFirst()) { // ugly patch; serious refactorization is needed to reduce work in FileDataStorageManager and bring it to FileContentProvider
|
||||
// ugly patch; serious refactorization is needed to reduce work in
|
||||
// FileDataStorageManager and bring it to FileContentProvider
|
||||
if (doubleCheck == null || !doubleCheck.moveToFirst()) {
|
||||
long rowId = db.insert(ProviderTableMeta.FILE_TABLE_NAME, null, values);
|
||||
if (rowId > 0) {
|
||||
Uri insertedFileUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, rowId);
|
||||
//Log_OC.d(TAG, "Inserted " + values.getAsString(ProviderTableMeta.FILE_PATH) + " at provider " + this);
|
||||
Uri insertedFileUri =
|
||||
ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, rowId);
|
||||
return insertedFileUri;
|
||||
} else {
|
||||
//Log_OC.d(TAG, "Error while inserting " + values.getAsString(ProviderTableMeta.FILE_PATH) + " at provider " + this);
|
||||
throw new SQLException("ERROR " + uri);
|
||||
}
|
||||
} else {
|
||||
// file is already inserted; race condition, let's avoid a duplicated entry
|
||||
Uri insertedFileUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, doubleCheck.getLong(doubleCheck.getColumnIndex(ProviderTableMeta._ID)));
|
||||
Uri insertedFileUri = ContentUris.withAppendedId(
|
||||
ProviderTableMeta.CONTENT_URI_FILE,
|
||||
doubleCheck.getLong(doubleCheck.getColumnIndex(ProviderTableMeta._ID))
|
||||
);
|
||||
doubleCheck.close();
|
||||
|
||||
return insertedFileUri;
|
||||
|
@ -302,22 +320,35 @@ public class FileContentProvider extends ContentProvider {
|
|||
case SHARES:
|
||||
String path = values.getAsString(ProviderTableMeta.OCSHARES_PATH);
|
||||
String accountNameShare= values.getAsString(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER);
|
||||
String[] projectionShare = new String[] {ProviderTableMeta._ID, ProviderTableMeta.OCSHARES_PATH, ProviderTableMeta.OCSHARES_ACCOUNT_OWNER };
|
||||
String whereShare = ProviderTableMeta.OCSHARES_PATH + "=? AND " + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?";
|
||||
String[] projectionShare = new String[] {
|
||||
ProviderTableMeta._ID, ProviderTableMeta.OCSHARES_PATH,
|
||||
ProviderTableMeta.OCSHARES_ACCOUNT_OWNER
|
||||
};
|
||||
String whereShare = ProviderTableMeta.OCSHARES_PATH + "=? AND " +
|
||||
ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?";
|
||||
String[] whereArgsShare = new String[] {path, accountNameShare};
|
||||
Uri insertedShareUri = null;
|
||||
Cursor doubleCheckShare = query(db, uri, projectionShare, whereShare, whereArgsShare, null);
|
||||
if (doubleCheckShare == null || !doubleCheckShare.moveToFirst()) { // ugly patch; serious refactorization is needed to reduce work in FileDataStorageManager and bring it to FileContentProvider
|
||||
Cursor doubleCheckShare =
|
||||
query(db, uri, projectionShare, whereShare, whereArgsShare, null);
|
||||
// ugly patch; serious refactorization is needed to reduce work in
|
||||
// FileDataStorageManager and bring it to FileContentProvider
|
||||
if (doubleCheckShare == null || !doubleCheckShare.moveToFirst()) {
|
||||
long rowId = db.insert(ProviderTableMeta.OCSHARES_TABLE_NAME, null, values);
|
||||
if (rowId >0) {
|
||||
insertedShareUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_SHARE, rowId);
|
||||
insertedShareUri =
|
||||
ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_SHARE, rowId);
|
||||
} else {
|
||||
throw new SQLException("ERROR " + uri);
|
||||
|
||||
}
|
||||
} else {
|
||||
// file is already inserted; race condition, let's avoid a duplicated entry
|
||||
insertedShareUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_SHARE, doubleCheckShare.getLong(doubleCheckShare.getColumnIndex(ProviderTableMeta._ID)));
|
||||
insertedShareUri = ContentUris.withAppendedId(
|
||||
ProviderTableMeta.CONTENT_URI_SHARE,
|
||||
doubleCheckShare.getLong(
|
||||
doubleCheckShare.getColumnIndex(ProviderTableMeta._ID)
|
||||
)
|
||||
);
|
||||
doubleCheckShare.close();
|
||||
}
|
||||
updateFilesTableAccordingToShareInsertion(db, uri, values);
|
||||
|
@ -330,11 +361,17 @@ public class FileContentProvider extends ContentProvider {
|
|||
|
||||
}
|
||||
|
||||
private void updateFilesTableAccordingToShareInsertion(SQLiteDatabase db, Uri uri, ContentValues shareValues) {
|
||||
private void updateFilesTableAccordingToShareInsertion(
|
||||
SQLiteDatabase db, Uri uri, ContentValues shareValues
|
||||
) {
|
||||
ContentValues fileValues = new ContentValues();
|
||||
fileValues.put(ProviderTableMeta.FILE_SHARE_BY_LINK,
|
||||
ShareType.PUBLIC_LINK.getValue() == shareValues.getAsInteger(ProviderTableMeta.OCSHARES_SHARE_TYPE)? 1 : 0);
|
||||
String whereShare = ProviderTableMeta.FILE_PATH + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
|
||||
fileValues.put(
|
||||
ProviderTableMeta.FILE_SHARE_BY_LINK,
|
||||
ShareType.PUBLIC_LINK.getValue() ==
|
||||
shareValues.getAsInteger(ProviderTableMeta.OCSHARES_SHARE_TYPE)? 1 : 0
|
||||
);
|
||||
String whereShare = ProviderTableMeta.FILE_PATH + "=? AND " +
|
||||
ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
|
||||
String[] whereArgsShare = new String[] {
|
||||
shareValues.getAsString(ProviderTableMeta.OCSHARES_PATH),
|
||||
shareValues.getAsString(ProviderTableMeta.OCSHARES_ACCOUNT_OWNER)
|
||||
|
@ -362,7 +399,14 @@ public class FileContentProvider extends ContentProvider {
|
|||
|
||||
|
||||
@Override
|
||||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
|
||||
public Cursor query(
|
||||
Uri uri,
|
||||
String[] projection,
|
||||
String selection,
|
||||
String[] selectionArgs,
|
||||
String sortOrder
|
||||
) {
|
||||
|
||||
Cursor result = null;
|
||||
SQLiteDatabase db = mDbHelper.getReadableDatabase();
|
||||
db.beginTransaction();
|
||||
|
@ -375,7 +419,15 @@ public class FileContentProvider extends ContentProvider {
|
|||
return result;
|
||||
}
|
||||
|
||||
private Cursor query(SQLiteDatabase db, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
|
||||
private Cursor query(
|
||||
SQLiteDatabase db,
|
||||
Uri uri,
|
||||
String[] projection,
|
||||
String selection,
|
||||
String[] selectionArgs,
|
||||
String sortOrder
|
||||
) {
|
||||
|
||||
SQLiteQueryBuilder sqlQuery = new SQLiteQueryBuilder();
|
||||
|
||||
sqlQuery.setTables(ProviderTableMeta.FILE_TABLE_NAME);
|
||||
|
@ -429,7 +481,6 @@ public class FileContentProvider extends ContentProvider {
|
|||
@Override
|
||||
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
|
||||
|
||||
//Log_OC.d(TAG, "Updating " + values.getAsString(ProviderTableMeta.FILE_PATH) + " at provider " + this);
|
||||
int count = 0;
|
||||
SQLiteDatabase db = mDbHelper.getWritableDatabase();
|
||||
db.beginTransaction();
|
||||
|
@ -445,14 +496,24 @@ public class FileContentProvider extends ContentProvider {
|
|||
|
||||
|
||||
|
||||
private int update(SQLiteDatabase db, Uri uri, ContentValues values, String selection, String[] selectionArgs) {
|
||||
private int update(
|
||||
SQLiteDatabase db,
|
||||
Uri uri,
|
||||
ContentValues values,
|
||||
String selection,
|
||||
String[] selectionArgs
|
||||
) {
|
||||
switch (mUriMatcher.match(uri)) {
|
||||
case DIRECTORY:
|
||||
return 0; //updateFolderSize(db, selectionArgs[0]);
|
||||
case SHARES:
|
||||
return db.update(ProviderTableMeta.OCSHARES_TABLE_NAME, values, selection, selectionArgs);
|
||||
return db.update(
|
||||
ProviderTableMeta.OCSHARES_TABLE_NAME, values, selection, selectionArgs
|
||||
);
|
||||
default:
|
||||
return db.update(ProviderTableMeta.FILE_TABLE_NAME, values, selection, selectionArgs);
|
||||
return db.update(
|
||||
ProviderTableMeta.FILE_TABLE_NAME, values, selection, selectionArgs
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -510,8 +571,10 @@ public class FileContentProvider extends ContentProvider {
|
|||
*/
|
||||
|
||||
@Override
|
||||
public ContentProviderResult[] applyBatch (ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
|
||||
Log_OC.d("FileContentProvider", "applying batch in provider " + this + " (temporary: " + isTemporary() + ")" );
|
||||
public ContentProviderResult[] applyBatch (ArrayList<ContentProviderOperation> operations)
|
||||
throws OperationApplicationException {
|
||||
Log_OC.d("FileContentProvider", "applying batch in provider " + this +
|
||||
" (temporary: " + isTemporary() + ")" );
|
||||
ContentProviderResult[] results = new ContentProviderResult[operations.size()];
|
||||
int i=0;
|
||||
|
||||
|
@ -600,12 +663,13 @@ public class FileContentProvider extends ContentProvider {
|
|||
db.beginTransaction();
|
||||
try {
|
||||
db.execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
|
||||
" ADD COLUMN " + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " INTEGER " +
|
||||
" DEFAULT 0");
|
||||
" ADD COLUMN " + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA +
|
||||
" INTEGER " + " DEFAULT 0");
|
||||
|
||||
// assume there are not local changes pending to upload
|
||||
db.execSQL("UPDATE " + ProviderTableMeta.FILE_TABLE_NAME +
|
||||
" SET " + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " = " + System.currentTimeMillis() +
|
||||
" SET " + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " = "
|
||||
+ System.currentTimeMillis() +
|
||||
" WHERE " + ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL");
|
||||
|
||||
upgraded = true;
|
||||
|
@ -619,11 +683,12 @@ public class FileContentProvider extends ContentProvider {
|
|||
db.beginTransaction();
|
||||
try {
|
||||
db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
|
||||
" ADD COLUMN " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " INTEGER " +
|
||||
" DEFAULT 0");
|
||||
" ADD COLUMN " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA +
|
||||
" INTEGER " + " DEFAULT 0");
|
||||
|
||||
db.execSQL("UPDATE " + ProviderTableMeta.FILE_TABLE_NAME +
|
||||
" SET " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " = " + ProviderTableMeta.FILE_MODIFIED +
|
||||
" SET " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " = " +
|
||||
ProviderTableMeta.FILE_MODIFIED +
|
||||
" WHERE " + ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL");
|
||||
|
||||
upgraded = true;
|
||||
|
@ -633,7 +698,8 @@ public class FileContentProvider extends ContentProvider {
|
|||
}
|
||||
}
|
||||
if (!upgraded)
|
||||
Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion);
|
||||
Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
|
||||
", newVersion == " + newVersion);
|
||||
|
||||
if (oldVersion < 5 && newVersion >= 5) {
|
||||
Log_OC.i("SQL", "Entering in the #4 ADD in onUpgrade");
|
||||
|
@ -650,7 +716,8 @@ public class FileContentProvider extends ContentProvider {
|
|||
}
|
||||
}
|
||||
if (!upgraded)
|
||||
Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion);
|
||||
Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
|
||||
", newVersion == " + newVersion);
|
||||
|
||||
if (oldVersion < 6 && newVersion >= 6) {
|
||||
Log_OC.i("SQL", "Entering in the #5 ADD in onUpgrade");
|
||||
|
@ -689,7 +756,8 @@ public class FileContentProvider extends ContentProvider {
|
|||
}
|
||||
}
|
||||
if (!upgraded)
|
||||
Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion);
|
||||
Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
|
||||
", newVersion == " + newVersion);
|
||||
|
||||
if (oldVersion < 7 && newVersion >= 7) {
|
||||
Log_OC.i("SQL", "Entering in the #7 ADD in onUpgrade");
|
||||
|
@ -710,7 +778,8 @@ public class FileContentProvider extends ContentProvider {
|
|||
}
|
||||
}
|
||||
if (!upgraded)
|
||||
Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion);
|
||||
Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
|
||||
", newVersion == " + newVersion);
|
||||
|
||||
if (oldVersion < 8 && newVersion >= 8) {
|
||||
Log_OC.i("SQL", "Entering in the #8 ADD in onUpgrade");
|
||||
|
@ -727,7 +796,8 @@ public class FileContentProvider extends ContentProvider {
|
|||
}
|
||||
}
|
||||
if (!upgraded)
|
||||
Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion);
|
||||
Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
|
||||
", newVersion == " + newVersion);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ import android.content.res.Resources.NotFoundException;
|
|||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
|
@ -64,7 +63,7 @@ import com.owncloud.android.utils.ErrorMessageAdapter;
|
|||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
public class MoveActivity extends HookActivity implements FileFragment.ContainerActivity,
|
||||
OnClickListener, SwipeRefreshLayout.OnRefreshListener {
|
||||
OnClickListener, OnEnforceableRefreshListener {
|
||||
|
||||
public static final String EXTRA_CURRENT_FOLDER = UploadFilesActivity.class.getCanonicalName() + ".EXTRA_CURRENT_FOLDER";
|
||||
public static final String EXTRA_TARGET_FILE = UploadFilesActivity.class.getCanonicalName() + "EXTRA_TARGET_FILE";
|
||||
|
@ -554,16 +553,23 @@ public class MoveActivity extends HookActivity implements FileFragment.Container
|
|||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
refreshList(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh(boolean enforced) {
|
||||
refreshList(enforced);
|
||||
}
|
||||
|
||||
private void refreshList(boolean ignoreETag) {
|
||||
OCFileListFragment listOfFiles = getListOfFilesFragment();
|
||||
if (listOfFiles != null) {
|
||||
OCFile folder = listOfFiles.getCurrentFile();
|
||||
if (folder != null) {
|
||||
startSyncFolderOperation(folder, true);
|
||||
startSyncFolderOperation(folder, ignoreETag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,3 +1,20 @@
|
|||
/* ownCloud Android client application
|
||||
* Copyright (C) 2012-2014 ownCloud Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.adapter;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
|
@ -7,14 +24,10 @@ import java.io.FileNotFoundException;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Bitmap.CompressFormat;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.util.Log;
|
||||
|
||||
import com.jakewharton.disklrucache.DiskLruCache;
|
||||
import com.owncloud.android.BuildConfig;
|
||||
|
@ -28,16 +41,14 @@ public class DiskLruImageCache {
|
|||
private static final int CACHE_VERSION = 1;
|
||||
private static final int VALUE_COUNT = 1;
|
||||
private static final int IO_BUFFER_SIZE = 8 * 1024;
|
||||
private static final Pattern CAPITAL_LETTERS = Pattern.compile("[A-Z]");
|
||||
|
||||
private StringBuffer mValidKeyBuffer = new StringBuffer(64);
|
||||
private StringBuffer mConversionBuffer = new StringBuffer(2).append('_');
|
||||
private static final String TAG = DiskLruImageCache.class.getSimpleName();
|
||||
|
||||
private static final String TAG = "DiskLruImageCache";
|
||||
//public DiskLruImageCache( Context context,String uniqueName, int diskCacheSize,
|
||||
public DiskLruImageCache(
|
||||
File diskCacheDir, int diskCacheSize, CompressFormat compressFormat, int quality
|
||||
) throws IOException {
|
||||
|
||||
public DiskLruImageCache( Context context,String uniqueName, int diskCacheSize,
|
||||
CompressFormat compressFormat, int quality ) throws IOException {
|
||||
final File diskCacheDir = getDiskCacheDir(context, uniqueName );
|
||||
mDiskCache = DiskLruCache.open(
|
||||
diskCacheDir, CACHE_VERSION, VALUE_COUNT, diskCacheSize
|
||||
);
|
||||
|
@ -58,17 +69,6 @@ public class DiskLruImageCache {
|
|||
}
|
||||
}
|
||||
|
||||
private File getDiskCacheDir(Context context, String uniqueName) {
|
||||
|
||||
// Check if media is mounted or storage is built-in, if so, try and use external cache dir
|
||||
// otherwise use internal cache dir
|
||||
final String cachePath = context.getExternalCacheDir().getPath();
|
||||
|
||||
Log_OC.d(TAG, "create dir: " + cachePath + File.separator + uniqueName);
|
||||
|
||||
return new File(cachePath + File.separator + uniqueName);
|
||||
}
|
||||
|
||||
public void put( String key, Bitmap data ) {
|
||||
|
||||
DiskLruCache.Editor editor = null;
|
||||
|
@ -83,17 +83,17 @@ public class DiskLruImageCache {
|
|||
mDiskCache.flush();
|
||||
editor.commit();
|
||||
if ( BuildConfig.DEBUG ) {
|
||||
Log.d( "cache_test_DISK_", "image put on disk cache " + validKey );
|
||||
Log_OC.d( "cache_test_DISK_", "image put on disk cache " + validKey );
|
||||
}
|
||||
} else {
|
||||
editor.abort();
|
||||
if ( BuildConfig.DEBUG ) {
|
||||
Log.d( "cache_test_DISK_", "ERROR on: image put on disk cache " + validKey );
|
||||
Log_OC.d( "cache_test_DISK_", "ERROR on: image put on disk cache " + validKey );
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if ( BuildConfig.DEBUG ) {
|
||||
Log.d( "cache_test_DISK_", "ERROR on: image put on disk cache " + validKey );
|
||||
Log_OC.d( "cache_test_DISK_", "ERROR on: image put on disk cache " + validKey );
|
||||
}
|
||||
try {
|
||||
if ( editor != null ) {
|
||||
|
@ -131,7 +131,8 @@ public class DiskLruImageCache {
|
|||
}
|
||||
|
||||
if ( BuildConfig.DEBUG ) {
|
||||
Log.d("cache_test_DISK_", bitmap == null ? "not found" : "image read from disk " + validKey);
|
||||
Log_OC.d("cache_test_DISK_", bitmap == null ?
|
||||
"not found" : "image read from disk " + validKey);
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
|
@ -160,7 +161,7 @@ public class DiskLruImageCache {
|
|||
|
||||
public void clearCache() {
|
||||
if ( BuildConfig.DEBUG ) {
|
||||
Log.d( "cache_test_DISK_", "disk cache CLEARED");
|
||||
Log_OC.d( "cache_test_DISK_", "disk cache CLEARED");
|
||||
}
|
||||
try {
|
||||
mDiskCache.delete();
|
||||
|
@ -174,16 +175,20 @@ public class DiskLruImageCache {
|
|||
}
|
||||
|
||||
private String convertToValidKey(String key) {
|
||||
Matcher capitalLettersMatcher = CAPITAL_LETTERS.matcher(key);
|
||||
mValidKeyBuffer.delete(0, mValidKeyBuffer.length());
|
||||
mConversionBuffer.delete(1, mConversionBuffer.length());
|
||||
|
||||
while (capitalLettersMatcher.find()) {
|
||||
mConversionBuffer.replace(1, 2, capitalLettersMatcher.group(0).toLowerCase());
|
||||
capitalLettersMatcher.appendReplacement(mValidKeyBuffer, mConversionBuffer.toString());
|
||||
}
|
||||
capitalLettersMatcher.appendTail(mValidKeyBuffer);
|
||||
return mValidKeyBuffer.toString();
|
||||
return Integer.toString(key.hashCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove passed key from cache
|
||||
* @param key
|
||||
*/
|
||||
public void removeKey( String key ) {
|
||||
String validKey = convertToValidKey(key);
|
||||
try {
|
||||
mDiskCache.remove(validKey);
|
||||
Log_OC.d(TAG, "removeKey from cache: " + validKey);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,21 +17,11 @@
|
|||
*/
|
||||
package com.owncloud.android.ui.adapter;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Vector;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Bitmap.CompressFormat;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.ThumbnailUtils;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -45,11 +35,11 @@ import com.owncloud.android.R;
|
|||
import com.owncloud.android.authentication.AccountUtils;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
|
||||
import com.owncloud.android.datamodel.ThumbnailsCacheManager.AsyncDrawable;
|
||||
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
|
||||
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.ui.activity.ComponentsGetter;
|
||||
import com.owncloud.android.utils.BitmapUtils;
|
||||
import com.owncloud.android.utils.DisplayUtils;
|
||||
|
||||
|
||||
|
@ -64,8 +54,6 @@ import com.owncloud.android.utils.DisplayUtils;
|
|||
public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
||||
private final static String PERMISSION_SHARED_WITH_ME = "S";
|
||||
|
||||
private static final String TAG = FileListListAdapter.class.getSimpleName();
|
||||
|
||||
private Context mContext;
|
||||
private OCFile mFile = null;
|
||||
private Vector<OCFile> mFiles = null;
|
||||
|
@ -75,14 +63,6 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|||
private Account mAccount;
|
||||
private ComponentsGetter mTransferServiceGetter;
|
||||
|
||||
private final Object thumbnailDiskCacheLock = new Object();
|
||||
private DiskLruImageCache mThumbnailCache;
|
||||
private boolean mThumbnailCacheStarting = true;
|
||||
private static final int DISK_CACHE_SIZE = 1024 * 1024 * 10; // 10MB
|
||||
private static final CompressFormat mCompressFormat = CompressFormat.JPEG;
|
||||
private static final int mCompressQuality = 70;
|
||||
private Bitmap defaultImg;
|
||||
|
||||
public FileListListAdapter(
|
||||
boolean justFolders,
|
||||
Context context,
|
||||
|
@ -93,141 +73,9 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|||
mContext = context;
|
||||
mAccount = AccountUtils.getCurrentOwnCloudAccount(mContext);
|
||||
mTransferServiceGetter = transferServiceGetter;
|
||||
defaultImg = BitmapFactory.decodeResource(mContext.getResources(),
|
||||
DisplayUtils.getResourceId("image/png", "default.png"));
|
||||
|
||||
// Initialise disk cache on background thread
|
||||
new InitDiskCacheTask().execute();
|
||||
}
|
||||
|
||||
class InitDiskCacheTask extends AsyncTask<File, Void, Void> {
|
||||
@Override
|
||||
protected Void doInBackground(File... params) {
|
||||
synchronized (thumbnailDiskCacheLock) {
|
||||
try {
|
||||
mThumbnailCache = new DiskLruImageCache(mContext, "thumbnailCache",
|
||||
DISK_CACHE_SIZE, mCompressFormat, mCompressQuality);
|
||||
} catch (Exception e) {
|
||||
Log_OC.d(TAG, "Thumbnail cache could not be opened ", e);
|
||||
mThumbnailCache = null;
|
||||
}
|
||||
mThumbnailCacheStarting = false; // Finished initialization
|
||||
thumbnailDiskCacheLock.notifyAll(); // Wake any waiting threads
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static class AsyncDrawable extends BitmapDrawable {
|
||||
private final WeakReference<ThumbnailGenerationTask> bitmapWorkerTaskReference;
|
||||
|
||||
public AsyncDrawable(Resources res, Bitmap bitmap,
|
||||
ThumbnailGenerationTask bitmapWorkerTask) {
|
||||
super(res, bitmap);
|
||||
bitmapWorkerTaskReference =
|
||||
new WeakReference<ThumbnailGenerationTask>(bitmapWorkerTask);
|
||||
}
|
||||
|
||||
public ThumbnailGenerationTask getBitmapWorkerTask() {
|
||||
return bitmapWorkerTaskReference.get();
|
||||
}
|
||||
}
|
||||
|
||||
class ThumbnailGenerationTask extends AsyncTask<OCFile, Void, Bitmap> {
|
||||
private final WeakReference<ImageView> imageViewReference;
|
||||
private OCFile file;
|
||||
|
||||
|
||||
public ThumbnailGenerationTask(ImageView imageView) {
|
||||
// Use a WeakReference to ensure the ImageView can be garbage collected
|
||||
imageViewReference = new WeakReference<ImageView>(imageView);
|
||||
}
|
||||
|
||||
// Decode image in background.
|
||||
@Override
|
||||
protected Bitmap doInBackground(OCFile... params) {
|
||||
Bitmap thumbnail = null;
|
||||
|
||||
try {
|
||||
file = params[0];
|
||||
final String imageKey = String.valueOf(file.getRemoteId());
|
||||
|
||||
// Check disk cache in background thread
|
||||
thumbnail = getBitmapFromDiskCache(imageKey);
|
||||
|
||||
// Not found in disk cache
|
||||
if (thumbnail == null || file.needsUpdateThumbnail()) {
|
||||
// Converts dp to pixel
|
||||
Resources r = mContext.getResources();
|
||||
int px = (int) Math.round(TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP, 150, r.getDisplayMetrics()
|
||||
));
|
||||
|
||||
if (file.isDown()){
|
||||
Bitmap bitmap = BitmapUtils.decodeSampledBitmapFromFile(
|
||||
file.getStoragePath(), px, px);
|
||||
|
||||
if (bitmap != null) {
|
||||
thumbnail = ThumbnailUtils.extractThumbnail(bitmap, px, px);
|
||||
|
||||
// Add thumbnail to cache
|
||||
addBitmapToCache(imageKey, thumbnail);
|
||||
|
||||
file.setNeedsUpdateThumbnail(false);
|
||||
mStorageManager.saveFile(file);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Throwable t) {
|
||||
// the app should never break due to a problem with thumbnails
|
||||
Log_OC.e(TAG, "Generation of thumbnail for " + file + " failed", t);
|
||||
if (t instanceof OutOfMemoryError) {
|
||||
System.gc();
|
||||
}
|
||||
}
|
||||
|
||||
return thumbnail;
|
||||
}
|
||||
|
||||
protected void onPostExecute(Bitmap bitmap){
|
||||
if (isCancelled()) {
|
||||
bitmap = null;
|
||||
}
|
||||
|
||||
if (imageViewReference != null && bitmap != null) {
|
||||
final ImageView imageView = imageViewReference.get();
|
||||
final ThumbnailGenerationTask bitmapWorkerTask =
|
||||
getBitmapWorkerTask(imageView);
|
||||
if (this == bitmapWorkerTask && imageView != null) {
|
||||
imageView.setImageBitmap(bitmap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addBitmapToCache(String key, Bitmap bitmap) {
|
||||
synchronized (thumbnailDiskCacheLock) {
|
||||
if (mThumbnailCache != null) {
|
||||
mThumbnailCache.put(key, bitmap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Bitmap getBitmapFromDiskCache(String key) {
|
||||
synchronized (thumbnailDiskCacheLock) {
|
||||
// Wait while disk cache is started from background thread
|
||||
while (mThumbnailCacheStarting) {
|
||||
try {
|
||||
thumbnailDiskCacheLock.wait();
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
if (mThumbnailCache != null) {
|
||||
return (Bitmap) mThumbnailCache.getBitmap(key);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
// initialise thumbnails cache on background thread
|
||||
new ThumbnailsCacheManager.InitDiskCacheTask().execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -280,6 +128,7 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|||
|
||||
fileName.setText(name);
|
||||
ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1);
|
||||
fileIcon.setTag(file.getFileId());
|
||||
ImageView sharedIconV = (ImageView) view.findViewById(R.id.sharedIcon);
|
||||
ImageView sharedWithMeIconV = (ImageView) view.findViewById(R.id.sharedWithMeIcon);
|
||||
sharedWithMeIconV.setVisibility(View.GONE);
|
||||
|
@ -334,18 +183,28 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|||
}
|
||||
|
||||
// get Thumbnail if file is image
|
||||
if (file.isImage()){
|
||||
if (file.isImage() && file.getRemoteId() != null){
|
||||
// Thumbnail in Cache?
|
||||
Bitmap thumbnail = getBitmapFromDiskCache(String.valueOf(file.getRemoteId()));
|
||||
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
|
||||
String.valueOf(file.getRemoteId())
|
||||
);
|
||||
if (thumbnail != null && !file.needsUpdateThumbnail()){
|
||||
fileIcon.setImageBitmap(thumbnail);
|
||||
} else {
|
||||
// generate new Thumbnail
|
||||
if (cancelPotentialWork(file, fileIcon)) {
|
||||
final ThumbnailGenerationTask task =
|
||||
new ThumbnailGenerationTask(fileIcon);
|
||||
final AsyncDrawable asyncDrawable =
|
||||
new AsyncDrawable(mContext.getResources(), defaultImg, task);
|
||||
if (ThumbnailsCacheManager.cancelPotentialWork(file, fileIcon)) {
|
||||
final ThumbnailsCacheManager.ThumbnailGenerationTask task =
|
||||
new ThumbnailsCacheManager.ThumbnailGenerationTask(
|
||||
fileIcon, mStorageManager
|
||||
);
|
||||
if (thumbnail == null) {
|
||||
thumbnail = ThumbnailsCacheManager.mDefaultImg;
|
||||
}
|
||||
final AsyncDrawable asyncDrawable = new AsyncDrawable(
|
||||
mContext.getResources(),
|
||||
thumbnail,
|
||||
task
|
||||
);
|
||||
fileIcon.setImageDrawable(asyncDrawable);
|
||||
task.execute(file);
|
||||
}
|
||||
|
@ -396,35 +255,6 @@ public class FileListListAdapter extends BaseAdapter implements ListAdapter {
|
|||
return view;
|
||||
}
|
||||
|
||||
public static boolean cancelPotentialWork(OCFile file, ImageView imageView) {
|
||||
final ThumbnailGenerationTask bitmapWorkerTask = getBitmapWorkerTask(imageView);
|
||||
|
||||
if (bitmapWorkerTask != null) {
|
||||
final OCFile bitmapData = bitmapWorkerTask.file;
|
||||
// If bitmapData is not yet set or it differs from the new data
|
||||
if (bitmapData == null || bitmapData != file) {
|
||||
// Cancel previous task
|
||||
bitmapWorkerTask.cancel(true);
|
||||
} else {
|
||||
// The same work is already in progress
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// No task associated with the ImageView, or an existing task was cancelled
|
||||
return true;
|
||||
}
|
||||
|
||||
private static ThumbnailGenerationTask getBitmapWorkerTask(ImageView imageView) {
|
||||
if (imageView != null) {
|
||||
final Drawable drawable = imageView.getDrawable();
|
||||
if (drawable instanceof AsyncDrawable) {
|
||||
final AsyncDrawable asyncDrawable = (AsyncDrawable) drawable;
|
||||
return asyncDrawable.getBitmapWorkerTask();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewTypeCount() {
|
||||
return 1;
|
||||
|
|
|
@ -32,6 +32,7 @@ import android.view.View;
|
|||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
@ -126,6 +127,13 @@ public class FileDownloadFragment extends FileFragment implements OnClickListene
|
|||
|
||||
((ImageButton)mView.findViewById(R.id.cancelBtn)).setOnClickListener(this);
|
||||
|
||||
((LinearLayout)mView.findViewById(R.id.fileDownloadLL)).setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
((PreviewImageActivity) getActivity()).toggleFullScreen();
|
||||
}
|
||||
});
|
||||
|
||||
if (mError) {
|
||||
setButtonsForRemote();
|
||||
} else {
|
||||
|
|
70
src/com/owncloud/android/ui/preview/ImageViewCustom.java
Normal file
|
@ -0,0 +1,70 @@
|
|||
package com.owncloud.android.ui.preview;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
||||
public class ImageViewCustom extends ImageView {
|
||||
|
||||
private static final boolean IS_ICS_OR_HIGHER = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
|
||||
|
||||
private Bitmap mBitmap;
|
||||
|
||||
|
||||
public ImageViewCustom(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ImageViewCustom(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public ImageViewCustom(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
|
||||
if(IS_ICS_OR_HIGHER && checkIfMaximumBitmapExceed(canvas)) {
|
||||
// Set layer type to software one for avoiding exceed
|
||||
// and problems in visualization
|
||||
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||
}
|
||||
|
||||
super.onDraw(canvas);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if current bitmaps exceed the maximum OpenGL texture size limit
|
||||
* @param bitmap
|
||||
* @return boolean
|
||||
*/
|
||||
@SuppressLint("NewApi")
|
||||
private boolean checkIfMaximumBitmapExceed(Canvas canvas) {
|
||||
Log_OC.d("OC", "Canvas maximum: " + canvas.getMaximumBitmapWidth() + " - " + canvas.getMaximumBitmapHeight());
|
||||
if (mBitmap!= null && (mBitmap.getWidth() > canvas.getMaximumBitmapWidth()
|
||||
|| mBitmap.getHeight() > canvas.getMaximumBitmapHeight())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set current bitmap
|
||||
* @param bitmap
|
||||
*/
|
||||
public void setBitmap (Bitmap bitmap) {
|
||||
mBitmap = bitmap;
|
||||
}
|
||||
|
||||
}
|
|
@ -16,6 +16,12 @@
|
|||
*/
|
||||
package com.owncloud.android.ui.preview;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
import android.accounts.Account;
|
||||
|
@ -40,7 +46,6 @@ import android.widget.TextView;
|
|||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuInflater;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
import com.ortiz.touch.TouchImageView;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.files.FileMenuFilter;
|
||||
|
@ -48,6 +53,8 @@ import com.owncloud.android.lib.common.utils.Log_OC;
|
|||
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
|
||||
import com.owncloud.android.ui.dialog.RemoveFileDialogFragment;
|
||||
import com.owncloud.android.ui.fragment.FileFragment;
|
||||
import com.owncloud.android.utils.TouchImageViewCustom;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -60,12 +67,13 @@ import com.owncloud.android.ui.fragment.FileFragment;
|
|||
* @author David A. Velasco
|
||||
*/
|
||||
public class PreviewImageFragment extends FileFragment {
|
||||
|
||||
public static final String EXTRA_FILE = "FILE";
|
||||
public static final String EXTRA_ACCOUNT = "ACCOUNT";
|
||||
|
||||
private View mView;
|
||||
private Account mAccount;
|
||||
private TouchImageView mImageView;
|
||||
private TouchImageViewCustom mImageView;
|
||||
private TextView mMessageView;
|
||||
private ProgressBar mProgressWheel;
|
||||
|
||||
|
@ -124,7 +132,7 @@ public class PreviewImageFragment extends FileFragment {
|
|||
Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
mView = inflater.inflate(R.layout.preview_image_fragment, container, false);
|
||||
mImageView = (TouchImageView) mView.findViewById(R.id.image);
|
||||
mImageView = (TouchImageViewCustom) mView.findViewById(R.id.image);
|
||||
mImageView.setVisibility(View.GONE);
|
||||
mImageView.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
|
@ -306,6 +314,7 @@ public class PreviewImageFragment extends FileFragment {
|
|||
public void onDestroy() {
|
||||
if (mBitmap != null) {
|
||||
mBitmap.recycle();
|
||||
System.gc();
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
@ -327,7 +336,7 @@ public class PreviewImageFragment extends FileFragment {
|
|||
*
|
||||
* Using a weak reference will avoid memory leaks if the target ImageView is retired from memory before the load finishes.
|
||||
*/
|
||||
private final WeakReference<ImageView> mImageViewRef;
|
||||
private final WeakReference<ImageViewCustom> mImageViewRef;
|
||||
|
||||
/**
|
||||
* Weak reference to the target {@link TextView} where error messages will be written.
|
||||
|
@ -356,75 +365,44 @@ public class PreviewImageFragment extends FileFragment {
|
|||
*
|
||||
* @param imageView Target {@link ImageView} where the bitmap will be loaded into.
|
||||
*/
|
||||
public BitmapLoader(ImageView imageView, TextView messageView, ProgressBar progressWheel) {
|
||||
mImageViewRef = new WeakReference<ImageView>(imageView);
|
||||
public BitmapLoader(ImageViewCustom imageView, TextView messageView, ProgressBar progressWheel) {
|
||||
mImageViewRef = new WeakReference<ImageViewCustom>(imageView);
|
||||
mMessageViewRef = new WeakReference<TextView>(messageView);
|
||||
mProgressWheelRef = new WeakReference<ProgressBar>(progressWheel);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@SuppressLint({ "NewApi", "NewApi", "NewApi" }) // to avoid Lint errors since Android SDK r20
|
||||
@Override
|
||||
protected Bitmap doInBackground(String... params) {
|
||||
Bitmap result = null;
|
||||
if (params.length != 1) return result;
|
||||
String storagePath = params[0];
|
||||
try {
|
||||
// set desired options that will affect the size of the bitmap
|
||||
BitmapFactory.Options options = new Options();
|
||||
options.inScaled = true;
|
||||
options.inPurgeable = true;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
options.inPreferQualityOverSpeed = false;
|
||||
}
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
|
||||
options.inMutable = false;
|
||||
}
|
||||
// make a false load of the bitmap - just to be able to read outWidth, outHeight and outMimeType
|
||||
options.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeFile(storagePath, options);
|
||||
|
||||
int width = options.outWidth;
|
||||
int height = options.outHeight;
|
||||
int scale = 1;
|
||||
File picture = new File(storagePath);
|
||||
|
||||
Display display = getActivity().getWindowManager().getDefaultDisplay();
|
||||
Point size = new Point();
|
||||
int screenWidth;
|
||||
int screenHeight;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR2) {
|
||||
display.getSize(size);
|
||||
screenWidth = size.x;
|
||||
screenHeight = size.y;
|
||||
} else {
|
||||
screenWidth = display.getWidth();
|
||||
screenHeight = display.getHeight();
|
||||
if (picture != null) {
|
||||
//Decode file into a bitmap in real size for being able to make zoom on the image
|
||||
result = BitmapFactory.decodeStream(new FlushedInputStream
|
||||
(new BufferedInputStream(new FileInputStream(picture))));
|
||||
}
|
||||
|
||||
if (width > screenWidth) {
|
||||
// second try to scale down the image , this time depending upon the screen size
|
||||
scale = (int) Math.floor((float)width / screenWidth);
|
||||
}
|
||||
if (height > screenHeight) {
|
||||
scale = Math.max(scale, (int) Math.floor((float)height / screenHeight));
|
||||
}
|
||||
options.inSampleSize = scale;
|
||||
|
||||
// really load the bitmap
|
||||
options.inJustDecodeBounds = false; // the next decodeFile call will be real
|
||||
result = BitmapFactory.decodeFile(storagePath, options);
|
||||
//Log_OC.d(TAG, "Image loaded - width: " + options.outWidth + ", loaded height: " + options.outHeight);
|
||||
|
||||
if (result == null) {
|
||||
mErrorMessageId = R.string.preview_image_error_unknown_format;
|
||||
Log_OC.e(TAG, "File could not be loaded as a bitmap: " + storagePath);
|
||||
}
|
||||
|
||||
} catch (OutOfMemoryError e) {
|
||||
mErrorMessageId = R.string.preview_image_error_unknown_format;
|
||||
Log_OC.e(TAG, "Out of memory occured for file " + storagePath, e);
|
||||
|
||||
// If out of memory error when loading image, try to load it scaled
|
||||
result = loadScaledImage(storagePath);
|
||||
|
||||
if (result == null) {
|
||||
mErrorMessageId = R.string.preview_image_error_unknown_format;
|
||||
Log_OC.e(TAG, "File could not be loaded as a bitmap: " + storagePath);
|
||||
}
|
||||
|
||||
} catch (NoSuchFieldError e) {
|
||||
mErrorMessageId = R.string.common_error_unknown;
|
||||
Log_OC.e(TAG, "Error from access to unexisting field despite protection; file " + storagePath, e);
|
||||
|
@ -447,10 +425,12 @@ public class PreviewImageFragment extends FileFragment {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
private void showLoadedImage(Bitmap result) {
|
||||
if (mImageViewRef != null) {
|
||||
final ImageView imageView = mImageViewRef.get();
|
||||
final ImageViewCustom imageView = mImageViewRef.get();
|
||||
if (imageView != null) {
|
||||
imageView.setBitmap(result);
|
||||
imageView.setImageBitmap(result);
|
||||
imageView.setVisibility(View.VISIBLE);
|
||||
mBitmap = result;
|
||||
|
@ -511,8 +491,87 @@ public class PreviewImageFragment extends FileFragment {
|
|||
container.finish();
|
||||
}
|
||||
|
||||
public TouchImageView getImageView() {
|
||||
public TouchImageViewCustom getImageView() {
|
||||
return mImageView;
|
||||
}
|
||||
|
||||
static class FlushedInputStream extends FilterInputStream {
|
||||
public FlushedInputStream(InputStream inputStream) {
|
||||
super(inputStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long skip(long n) throws IOException {
|
||||
long totalBytesSkipped = 0L;
|
||||
while (totalBytesSkipped < n) {
|
||||
long bytesSkipped = in.skip(n - totalBytesSkipped);
|
||||
if (bytesSkipped == 0L) {
|
||||
int byteValue = read();
|
||||
if (byteValue < 0) {
|
||||
break; // we reached EOF
|
||||
} else {
|
||||
bytesSkipped = 1; // we read one byte
|
||||
}
|
||||
}
|
||||
totalBytesSkipped += bytesSkipped;
|
||||
}
|
||||
return totalBytesSkipped;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load image scaled
|
||||
* @param storagePath: path of the image
|
||||
* @return Bitmap
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private Bitmap loadScaledImage(String storagePath) {
|
||||
|
||||
Log_OC.d(TAG, "Loading image scaled");
|
||||
|
||||
// set desired options that will affect the size of the bitmap
|
||||
BitmapFactory.Options options = new Options();
|
||||
options.inScaled = true;
|
||||
options.inPurgeable = true;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
options.inPreferQualityOverSpeed = false;
|
||||
}
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
|
||||
options.inMutable = false;
|
||||
}
|
||||
// make a false load of the bitmap - just to be able to read outWidth, outHeight and outMimeType
|
||||
options.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeFile(storagePath, options);
|
||||
|
||||
int width = options.outWidth;
|
||||
int height = options.outHeight;
|
||||
int scale = 1;
|
||||
|
||||
Display display = getActivity().getWindowManager().getDefaultDisplay();
|
||||
Point size = new Point();
|
||||
int screenWidth;
|
||||
int screenHeight;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB_MR2) {
|
||||
display.getSize(size);
|
||||
screenWidth = size.x;
|
||||
screenHeight = size.y;
|
||||
} else {
|
||||
screenWidth = display.getWidth();
|
||||
screenHeight = display.getHeight();
|
||||
}
|
||||
|
||||
if (width > screenWidth) {
|
||||
// second try to scale down the image , this time depending upon the screen size
|
||||
scale = (int) Math.floor((float)width / screenWidth);
|
||||
}
|
||||
if (height > screenHeight) {
|
||||
scale = Math.max(scale, (int) Math.floor((float)height / screenHeight));
|
||||
}
|
||||
options.inSampleSize = scale;
|
||||
|
||||
// really load the bitmap
|
||||
options.inJustDecodeBounds = false; // the next decodeFile call will be real
|
||||
return BitmapFactory.decodeFile(storagePath, options);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import android.media.MediaPlayer;
|
|||
import android.media.MediaPlayer.OnCompletionListener;
|
||||
import android.media.MediaPlayer.OnErrorListener;
|
||||
import android.media.MediaPlayer.OnPreparedListener;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
|
@ -372,13 +373,15 @@ public class PreviewMediaFragment extends FileFragment implements
|
|||
mVideoPreview.setOnErrorListener(mVideoHelper);
|
||||
}
|
||||
|
||||
@SuppressWarnings("static-access")
|
||||
private void playVideo() {
|
||||
// create and prepare control panel for the user
|
||||
mMediaController.setMediaPlayer(mVideoPreview);
|
||||
|
||||
// load the video file in the video player ;
|
||||
// when done, VideoHelper#onPrepared() will be called
|
||||
mVideoPreview.setVideoPath(getFile().getStoragePath());
|
||||
Uri uri = Uri.parse(getFile().getStoragePath());
|
||||
mVideoPreview.setVideoPath(uri.encode(getFile().getStoragePath()));
|
||||
}
|
||||
|
||||
|
||||
|
|