-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avatars: update when changed in server, full load in background, sele…
…ctive server fetches, refactoring and clean-up
- Loading branch information
Showing
13 changed files
with
674 additions
and
237 deletions.
There are no files selected for viewing
Submodule owncloud-android-library
updated
5 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
227 changes: 161 additions & 66 deletions
227
src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package com.owncloud.android.datamodel; | ||
|
||
import android.support.annotation.Nullable; | ||
|
||
/** | ||
* ownCloud Android client application | ||
* | ||
* @author David A. Velasco | ||
* Copyright (C) 2016 ownCloud GmbH. | ||
* | ||
* 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/>. | ||
* | ||
*/ | ||
public class UserProfile { | ||
|
||
private long mId; | ||
private String mAccountName; | ||
|
||
private String mUserId; | ||
private String mDisplayName = ""; | ||
private String mEmail = ""; | ||
|
||
private UserAvatar mAvatar; | ||
|
||
public UserProfile(String accountName, String userId, String displayName, String email) { | ||
mAccountName = accountName; | ||
mUserId = userId; | ||
mDisplayName = displayName; | ||
mEmail = email; | ||
|
||
mAvatar = null; | ||
} | ||
|
||
public String getAccountName() { | ||
return mAccountName; | ||
} | ||
|
||
public String getUserId() { | ||
return mUserId; | ||
} | ||
|
||
public String getDisplayName() { | ||
return mDisplayName; | ||
} | ||
|
||
public String getEmail() { | ||
return mEmail; | ||
} | ||
|
||
@Nullable | ||
public UserAvatar getAvatar() { | ||
return mAvatar; | ||
} | ||
|
||
public void setAvatar(UserAvatar avatar) { | ||
mAvatar = avatar; | ||
} | ||
|
||
public static class UserAvatar { | ||
|
||
private String mCacheKey; | ||
private String mMimeType; | ||
private String mEtag; | ||
|
||
public UserAvatar(String cacheKey, String mimeType, String etag) { | ||
mCacheKey = cacheKey; | ||
mMimeType = mimeType; | ||
mEtag = etag; | ||
} | ||
|
||
public String getCacheKey() { | ||
return mCacheKey; | ||
} | ||
|
||
public String getMimeType() { | ||
return mMimeType; | ||
} | ||
|
||
public String getEtag() { | ||
return mEtag; | ||
} | ||
} | ||
} |
194 changes: 194 additions & 0 deletions
194
src/com/owncloud/android/datamodel/UserProfilesRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
package com.owncloud.android.datamodel; | ||
|
||
import android.content.ContentValues; | ||
import android.database.Cursor; | ||
import android.database.sqlite.SQLiteDatabase; | ||
|
||
import com.owncloud.android.MainApp; | ||
import com.owncloud.android.db.ProviderMeta; | ||
import com.owncloud.android.lib.common.utils.Log_OC; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* ownCloud Android client application | ||
* | ||
* Copyright (C) 2016 ownCloud GmbH. | ||
* | ||
* 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/>. | ||
* | ||
*/ | ||
|
||
/** | ||
* Minimum to get things working. | ||
* | ||
* Working around FileContentProvider, we have no interest in exporting user profiles to other apps. | ||
*/ | ||
public class UserProfilesRepository { | ||
|
||
private static final String TAG = UserProfilesRepository.class.getName(); | ||
|
||
private SQLiteDatabase mDb; | ||
|
||
public UserProfilesRepository() { | ||
File dbFile = MainApp.getAppContext().getDatabasePath(ProviderMeta.DB_NAME); | ||
mDb = SQLiteDatabase.openDatabase( | ||
dbFile.getAbsolutePath(), | ||
null, | ||
SQLiteDatabase.OPEN_READWRITE | ||
); | ||
} | ||
|
||
/** | ||
* Persist a user profile. | ||
* | ||
* Minimum to get things working: only storing info about avatar. | ||
* | ||
* Working around ContentProvider | ||
* | ||
* @param userProfile User profile. | ||
*/ | ||
public void update(UserProfile userProfile) { | ||
|
||
if (userProfile == null) { | ||
throw new IllegalArgumentException("Received userProfile with NULL value"); | ||
} | ||
|
||
if (userProfile.getAvatar() != null) { | ||
// map avatar properties to columns | ||
ContentValues avatarValues = new ContentValues(); | ||
avatarValues.put( | ||
ProviderMeta.ProviderTableMeta.USER_AVATARS__ACCOUNT_NAME, | ||
userProfile.getAccountName() | ||
); | ||
avatarValues.put( | ||
ProviderMeta.ProviderTableMeta.USER_AVATARS__CACHE_KEY, | ||
userProfile.getAvatar().getCacheKey() | ||
); | ||
avatarValues.put( | ||
ProviderMeta.ProviderTableMeta.USER_AVATARS__ETAG, | ||
userProfile.getAvatar().getEtag() | ||
); | ||
avatarValues.put( | ||
ProviderMeta.ProviderTableMeta.USER_AVATARS__MIME_TYPE, | ||
userProfile.getAvatar().getMimeType() | ||
); | ||
|
||
mDb.beginTransaction(); | ||
try { | ||
if (avatarExists(userProfile)) { | ||
// not new, UPDATE | ||
int count = mDb.update( | ||
ProviderMeta.ProviderTableMeta.USER_AVATARS__TABLE_NAME, | ||
avatarValues, | ||
ProviderMeta.ProviderTableMeta.USER_AVATARS__ACCOUNT_NAME + "=?", | ||
new String[]{String.valueOf(userProfile.getAccountName())} | ||
); | ||
Log_OC.d(TAG, "Avatar updated"); | ||
|
||
} else { | ||
// new, CREATE | ||
mDb.insert( | ||
ProviderMeta.ProviderTableMeta.USER_AVATARS__TABLE_NAME, | ||
null, | ||
avatarValues | ||
); | ||
Log_OC.d(TAG, "Avatar inserted"); | ||
} | ||
mDb.setTransactionSuccessful(); | ||
|
||
} finally { | ||
mDb.endTransaction(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Gets the information about a user avatar bound to an OC account. | ||
* | ||
* Shortcut method prevent retrieving a full {@link UserProfile}, | ||
* specially now that {@link UserProfile}s are not really stored. Naughty trick. | ||
* | ||
* @param accountName Name of an OC account. | ||
* @return Information about a user avatar bound to an OC account, or NULL if | ||
* there is no avatar for the given account. | ||
*/ | ||
public UserProfile.UserAvatar getAvatar(String accountName) { | ||
UserProfile.UserAvatar avatar = null; | ||
Cursor c = null; | ||
try { | ||
c = mDb.query( | ||
ProviderMeta.ProviderTableMeta.USER_AVATARS__TABLE_NAME, | ||
null, | ||
ProviderMeta.ProviderTableMeta.USER_AVATARS__ACCOUNT_NAME + "=?", | ||
new String[]{accountName}, | ||
null, null, null | ||
); | ||
if (c != null && c.moveToFirst()) { | ||
avatar = new UserProfile.UserAvatar( | ||
c.getString(c.getColumnIndex( | ||
ProviderMeta.ProviderTableMeta.USER_AVATARS__CACHE_KEY | ||
)), | ||
c.getString(c.getColumnIndex( | ||
ProviderMeta.ProviderTableMeta.USER_AVATARS__MIME_TYPE | ||
)), | ||
c.getString( | ||
c.getColumnIndex(ProviderMeta.ProviderTableMeta.USER_AVATARS__ETAG | ||
)) | ||
); | ||
} // else, no avatar to return | ||
} catch (Exception e) { | ||
Log_OC.e(TAG, "Exception while querying avatar", e); | ||
} finally { | ||
if (c != null) { | ||
c.close(); | ||
} | ||
} | ||
return avatar; | ||
} | ||
|
||
public void deleteAvatar(String accountName) { | ||
try { | ||
mDb.delete( | ||
ProviderMeta.ProviderTableMeta.USER_AVATARS__TABLE_NAME, | ||
ProviderMeta.ProviderTableMeta.USER_AVATARS__ACCOUNT_NAME + "=?", | ||
new String[]{String.valueOf(accountName)} | ||
); | ||
Log_OC.d(TAG, "Avatar deleted"); | ||
|
||
} catch (Exception e) { | ||
Log_OC.e(TAG, "Exception while deleting avatar", e); | ||
} | ||
} | ||
|
||
private boolean avatarExists(UserProfile userProfile) { | ||
boolean exists = false; | ||
Cursor c = null; | ||
try { | ||
c = mDb.query( | ||
ProviderMeta.ProviderTableMeta.USER_AVATARS__TABLE_NAME, | ||
null, | ||
ProviderMeta.ProviderTableMeta.USER_AVATARS__ACCOUNT_NAME + "=?", | ||
new String[]{userProfile.getAccountName()}, | ||
null, null, null | ||
); | ||
exists = (c != null && c.moveToFirst()); | ||
} finally { | ||
if (c != null) { | ||
c.close(); | ||
} | ||
} | ||
return exists; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.