use of com.owncloud.android.lib.resources.status.OCCapability in project android by owncloud.
the class GetCapabilitiesOperarion method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
GetRemoteCapabilitiesOperation getCapabilities = new GetRemoteCapabilitiesOperation();
RemoteOperationResult result = getCapabilities.execute(client);
if (result.isSuccess()) {
// Read data from the result
if (result.getData() != null && result.getData().size() > 0) {
OCCapability capability = (OCCapability) result.getData().get(0);
// Save the capabilities into database
getStorageManager().saveCapabilities(capability);
}
}
return result;
}
use of com.owncloud.android.lib.resources.status.OCCapability in project android by nextcloud.
the class DrawerActivity method updateHeaderBackground.
public void updateHeaderBackground() {
if (getAccount() != null && getStorageManager().getCapability(getAccount().name).getServerBackground() != null) {
final ViewGroup navigationHeader = (ViewGroup) findNavigationViewChildById(R.id.drawer_header_view);
if (navigationHeader != null) {
OCCapability capability = getStorageManager().getCapability(getAccount().name);
String background = capability.getServerBackground();
CapabilityBooleanType backgroundDefault = capability.getServerBackgroundDefault();
CapabilityBooleanType backgroundPlain = capability.getServerBackgroundPlain();
int primaryColor = ThemeUtils.primaryColor(getAccount());
if (backgroundDefault.isTrue() && backgroundPlain.isTrue()) {
// use only solid color
setNavigationHeaderBackground(new ColorDrawable(primaryColor), navigationHeader);
} else if (backgroundDefault.isTrue() && backgroundPlain.isFalse()) {
// use nc13 background image with themed color
Drawable[] drawables = { new ColorDrawable(primaryColor), getResources().getDrawable(R.drawable.background_nc13) };
LayerDrawable layerDrawable = new LayerDrawable(drawables);
setNavigationHeaderBackground(layerDrawable, navigationHeader);
} else {
// use url
if (URLUtil.isValidUrl(background) || background.isEmpty()) {
// background image
SimpleTarget target = new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(Drawable resource, GlideAnimation glideAnimation) {
Drawable[] drawables = { new ColorDrawable(primaryColor), resource };
LayerDrawable layerDrawable = new LayerDrawable(drawables);
setNavigationHeaderBackground(layerDrawable, navigationHeader);
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
Drawable[] drawables = { new ColorDrawable(primaryColor), errorDrawable };
LayerDrawable layerDrawable = new LayerDrawable(drawables);
setNavigationHeaderBackground(layerDrawable, navigationHeader);
}
};
int backgroundResource;
OwnCloudVersion ownCloudVersion = AccountUtils.getServerVersion(getAccount());
if (ownCloudVersion.compareTo(OwnCloudVersion.nextcloud_13) >= 0) {
backgroundResource = R.drawable.background_nc13;
} else {
backgroundResource = R.drawable.background;
}
Glide.with(this).load(background).centerCrop().placeholder(backgroundResource).error(backgroundResource).crossFade().into(target);
} else {
// plain color
setNavigationHeaderBackground(new ColorDrawable(primaryColor), navigationHeader);
}
}
}
}
}
use of com.owncloud.android.lib.resources.status.OCCapability in project android by nextcloud.
the class ThemeUtils method getCapability.
private static OCCapability getCapability(Account acc) {
Account account;
Context context = MainApp.getAppContext();
if (context == null) {
return new OCCapability();
}
if (acc != null) {
account = acc;
} else {
account = AccountUtils.getCurrentOwnCloudAccount(context);
}
if (account != null) {
FileDataStorageManager storageManager = new FileDataStorageManager(account, context.getContentResolver());
return storageManager.getCapability(account.name);
} else {
return new OCCapability();
}
}
use of com.owncloud.android.lib.resources.status.OCCapability in project android by nextcloud.
the class EndToEndRandomIT method before.
@Before
public void before() throws IOException {
OCCapability capability = getStorageManager().getCapability(account.name);
if (capability.getVersion().equals(new OwnCloudVersion("0.0.0"))) {
// fetch new one
assertTrue(new GetCapabilitiesOperation(getStorageManager()).execute(client).isSuccess());
}
// tests only for NC19+
assumeTrue(getStorageManager().getCapability(account.name).getVersion().isNewerOrEqual(nextcloud_19));
// make sure that every file is available, even after tests that remove source file
createDummyFiles();
}
use of com.owncloud.android.lib.resources.status.OCCapability in project android by nextcloud.
the class DialogFragmentIT method testAccountChooserDialog.
@Test
@ScreenshotTest
public void testAccountChooserDialog() throws AccountUtils.AccountNotFoundException {
FileDisplayActivity activity = getFileDisplayActivity();
UserAccountManager userAccountManager = activity.getUserAccountManager();
AccountManager accountManager = AccountManager.get(targetContext);
for (Account account : accountManager.getAccountsByType(MainApp.getAccountType(targetContext))) {
accountManager.removeAccountExplicitly(account);
}
Account newAccount = new Account("test@https://nextcloud.localhost", MainApp.getAccountType(targetContext));
accountManager.addAccountExplicitly(newAccount, "password", null);
accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_OC_BASE_URL, SERVER_URL);
accountManager.setUserData(newAccount, AccountUtils.Constants.KEY_USER_ID, "test");
accountManager.setAuthToken(newAccount, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password");
User newUser = userAccountManager.getUser(newAccount.name).orElseThrow(RuntimeException::new);
Account newAccount2 = new Account("user1@nextcloud.localhost", MainApp.getAccountType(targetContext));
accountManager.addAccountExplicitly(newAccount2, "password", null);
accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_OC_BASE_URL, SERVER_URL);
accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_USER_ID, "user1");
accountManager.setUserData(newAccount2, AccountUtils.Constants.KEY_OC_VERSION, "20.0.0");
accountManager.setAuthToken(newAccount2, AccountTypeUtils.getAuthTokenTypePass(newAccount.type), "password");
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(newUser, targetContext.getContentResolver());
OCCapability capability = new OCCapability();
capability.setUserStatus(CapabilityBooleanType.TRUE);
capability.setUserStatusSupportsEmoji(CapabilityBooleanType.TRUE);
fileDataStorageManager.saveCapabilities(capability);
ChooseAccountDialogFragment sut = ChooseAccountDialogFragment.newInstance(new RegisteredUser(newAccount, new OwnCloudAccount(newAccount, targetContext), new Server(URI.create(SERVER_URL), OwnCloudVersion.nextcloud_20)));
showDialog(activity, sut);
activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.DND, "Busy fixing 🐛…", "", -1), targetContext));
waitForIdleSync();
shortSleep();
screenshot(sut, "dnd");
activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.ONLINE, "", "", -1), targetContext));
waitForIdleSync();
shortSleep();
screenshot(sut, "online");
activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.ONLINE, "Let's have some fun", "🎉", -1), targetContext));
waitForIdleSync();
shortSleep();
screenshot(sut, "fun");
activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.OFFLINE, "", "", -1), targetContext));
waitForIdleSync();
shortSleep();
screenshot(sut, "offline");
activity.runOnUiThread(() -> sut.setStatus(new Status(StatusType.AWAY, "Vacation", "🌴", -1), targetContext));
waitForIdleSync();
shortSleep();
screenshot(sut, "away");
}
Aggregations