Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasKaminsky committed Mar 12, 2020
2 parents 4923a8e + 48d0249 commit 909c960
Show file tree
Hide file tree
Showing 11 changed files with 284 additions and 85 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: "Validate Gradle Wrapper"
on: [push, pull_request]

jobs:
validation:
name: "Validation"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: gradle/wrapper-validation-action@v1
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ repositories {

// semantic versioning for version code
def versionMajor = 3
def versionMinor = 11
def versionMinor = 12
def versionPatch = 0
def versionBuild = 0 // 0-50=Alpha / 51-98=RC / 90-99=stable

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
*
* Nextcloud Android client application
*
* @author Tobias Kaminsky
* Copyright (C) 2020 Tobias Kaminsky
* Copyright (C) 2020 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.owncloud.android.ui.activity;

import android.Manifest;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.net.Uri;
import android.os.Bundle;

import com.nextcloud.client.account.UserAccountManager;
import com.nextcloud.client.account.UserAccountManagerImpl;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.lib.common.accounts.AccountUtils;

import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;

import androidx.test.espresso.contrib.DrawerActions;
import androidx.test.espresso.intent.rule.IntentsTestRule;
import androidx.test.rule.GrantPermissionRule;

import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.anyOf;
import static org.junit.Assert.assertEquals;

public class DrawerActivityIT extends AbstractIT {
@Rule public IntentsTestRule<FileDisplayActivity> activityRule = new IntentsTestRule<>(FileDisplayActivity.class,
true,
false);

@Rule
public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
Manifest.permission.WRITE_EXTERNAL_STORAGE);
private static Account account2;
private static String account2Name;
private static String account2DisplayName;

@BeforeClass
public static void beforeClass() {
Bundle arguments = androidx.test.platform.app.InstrumentationRegistry.getArguments();
Uri baseUrl = Uri.parse(arguments.getString("TEST_SERVER_URL"));
String loginName = "user1";
String password = "user1";

Account temp = new Account(loginName + "@" + baseUrl, MainApp.getAccountType(targetContext));
UserAccountManager accountManager = UserAccountManagerImpl.fromContext(targetContext);
if (!accountManager.exists(temp)) {
AccountManager platformAccountManager = AccountManager.get(targetContext);
platformAccountManager.addAccountExplicitly(temp, password, null);
platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_ACCOUNT_VERSION,
Integer.toString(UserAccountManager.ACCOUNT_VERSION));
platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_VERSION, "14.0.0.0");
platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_BASE_URL, baseUrl.toString());
platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_USER_ID, loginName); // same as userId
}

final UserAccountManager userAccountManager = UserAccountManagerImpl.fromContext(targetContext);
account2 = userAccountManager.getAccountByName(loginName + "@" + baseUrl);
account2Name = loginName + "@" + baseUrl;
account2DisplayName = "User One@" + baseUrl;
}

@Test
public void switchAccountViaAccountList() {
FileDisplayActivity sut = activityRule.launchActivity(null);

assertEquals(account, sut.getUser().get().toPlatformAccount());

onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
onView(withId(R.id.drawer_active_user)).perform(click());

onView(anyOf(withText(account2Name), withText(account2DisplayName))).perform(click());

waitForIdleSync();

assertEquals(account2, sut.getUser().get().toPlatformAccount());

onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
onView(withId(R.id.drawer_active_user)).perform(click());
onView(withText(account.name)).perform(click());
}

@Test
public void switchAccountViaAvatar() {
FileDisplayActivity sut = activityRule.launchActivity(null);

assertEquals(account, sut.getUser().get().toPlatformAccount());

onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
onView(withId(R.id.drawer_account_end)).perform(click());

waitForIdleSync();

assertEquals(account2, sut.getUser().get().toPlatformAccount());

onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
onView(withId(R.id.drawer_account_end)).perform(click());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
*
* Nextcloud Android client application
*
* @author Tobias Kaminsky
* Copyright (C) 2020 Tobias Kaminsky
* Copyright (C) 2020 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.owncloud.android.ui.helpers

import com.owncloud.android.MainApp
import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertTrue
import org.junit.Test

class FileOperationsHelperIT {

@Test
fun testNull() {
MainApp.setStoragePath(null)
assertEquals(-1L, FileOperationsHelper.getAvailableSpaceOnDevice())
}

@Test
fun testNonExistingPath() {
MainApp.setStoragePath("/123/123")
assertEquals(-1L, FileOperationsHelper.getAvailableSpaceOnDevice())
}

@Test
fun testExistingPath() {
MainApp.setStoragePath("/sdcard/")
assertTrue(FileOperationsHelper.getAvailableSpaceOnDevice() > 0L)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,10 @@ public boolean setCurrentOwnCloudAccount(String accountName) {
public boolean setCurrentOwnCloudAccount(int hashCode) {
boolean result = false;
if (hashCode != 0) {
for (final Account account : getAccounts()) {
if (hashCode == account.hashCode()) {
for (final User user : getAllUsers()) {
if (hashCode == user.hashCode()) {
SharedPreferences.Editor appPrefs = PreferenceManager.getDefaultSharedPreferences(context).edit();
appPrefs.putString(PREF_SELECT_OC_ACCOUNT, account.name);
appPrefs.putString(PREF_SELECT_OC_ACCOUNT, user.getAccountName());
appPrefs.apply();
result = true;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

package com.owncloud.android.ui.activity;

import android.accounts.Account;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -574,9 +573,8 @@ private void handleSearchEvents(SearchEvent searchEvent, int menuItemId) {
* @param hashCode HashCode of account to be set
*/
private void accountClicked(int hashCode) {
final Account currentAccount = accountManager.getCurrentAccount();
if (currentAccount != null && currentAccount.hashCode() != hashCode &&
accountManager.setCurrentOwnCloudAccount(hashCode)) {
final User currentUser = accountManager.getUser();
if (currentUser.hashCode() != hashCode && accountManager.setCurrentOwnCloudAccount(hashCode)) {
fetchExternalLinks(true);
restart();
}
Expand Down Expand Up @@ -606,7 +604,7 @@ private void externalLinkClicked(MenuItem menuItem){
* @param view the clicked ImageView
*/
public void onAccountDrawerClick(View view) {
accountClicked(Integer.parseInt(view.getContentDescription().toString()));
accountClicked((int) view.getTag());
}

/**
Expand Down Expand Up @@ -687,7 +685,7 @@ public void updateAccountList() {
// activate second/end account avatar
final User secondUser = mAvatars.size() > 1 ? mAvatars.get(1) : null;
if (secondUser != null) {
mAccountEndAccountAvatar.setTag(secondUser.getAccountName());
mAccountEndAccountAvatar.setTag(secondUser.hashCode());
DisplayUtils.setAvatar(secondUser,
this,
mOtherAccountAvatarRadiusDimension,
Expand All @@ -702,7 +700,7 @@ public void updateAccountList() {
// activate third/middle account avatar
final User thirdUser = mAvatars.size() > 2 ? mAvatars.get(2) : null;
if (thirdUser != null) {
mAccountMiddleAccountAvatar.setTag(thirdUser.getAccountName());
mAccountMiddleAccountAvatar.setTag(thirdUser.hashCode());
DisplayUtils.setAvatar(thirdUser,
this,
mOtherAccountAvatarRadiusDimension,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,9 @@ public void setFabVisible(final boolean visible) {
getActivity().runOnUiThread(() -> {
if (visible) {
mFabMain.show();
ThemeUtils.tintDrawable(mFabMain.getBackground(), ThemeUtils.primaryColor(getContext()));
int primaryColor = ThemeUtils.primaryColor(getContext());
mFabMain.setBackgroundTintList(ColorStateList.valueOf(primaryColor));
mFabMain.setRippleColor(primaryColor);
} else {
mFabMain.hide();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1710,11 +1710,14 @@ private boolean isSearchEventSet(SearchEvent event) {

private void syncAndCheckFiles(Collection<OCFile> files) {
for (OCFile file : files) {
// Get the remaining space on device (after file download)
// Get the remaining space on device
long availableSpaceOnDevice = FileOperationsHelper.getAvailableSpaceOnDevice();

// Determine if space is enough to download the file
boolean isSpaceEnough = availableSpaceOnDevice > file.getFileLength();
// Determine if space is enough to download the file, -1 available space if there in error while computing
boolean isSpaceEnough = true;
if (availableSpaceOnDevice >= 0) {
isSpaceEnough = availableSpaceOnDevice > file.getFileLength();
}

if (isSpaceEnough) {
mContainerActivity.getFileOperationsHelper().syncFile(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1038,10 +1038,18 @@ public static String getCapturedImageName() {
return new SimpleDateFormat("yyyy-MM-dd_HHmmss", Locale.US).format(new Date()) + ".jpg";
}

/**
* @return -1 if no space could computed, otherwise available space in bytes
*/
public static Long getAvailableSpaceOnDevice() {
StatFs stat = new StatFs(MainApp.getStoragePath());
long availableBytesOnDevice;
StatFs stat;
try {
stat = new StatFs(MainApp.getStoragePath());
} catch (NullPointerException | IllegalArgumentException e) {
return -1L;
}

long availableBytesOnDevice;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
availableBytesOnDevice = stat.getBlockSizeLong() * stat.getAvailableBlocksLong();
} else {
Expand All @@ -1051,5 +1059,4 @@ public static Long getAvailableSpaceOnDevice() {
return availableBytesOnDevice;
}


}
5 changes: 5 additions & 0 deletions src/main/res/values-el/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,12 @@
<string name="confirmation_remove_folder_alert">Θέλετε σίγουρα να διαγράψετε το %1$s και τα περιεχόμενά του;</string>
<string name="confirmation_remove_folders_alert">Θέλετε να διαγράψετε τα επιλεγμένα αντικείμενα και τα περιεχόμενά τους;</string>
<string name="confirmation_remove_local">Μόνο τοπικά</string>
<string name="conflict_already_existing_file">Το αρχείο υπάρχει ήδη</string>
<string name="conflict_keep_both">Διατήρηση και των δύο</string>
<string name="conflict_message">Ποια αρχεία θέλετε να διατηρήσετε; Αν επιλέξετε και τις δύο εκδόσεις, θα προστεθεί ένας αριθμός στο όνομα του τοπικού αρχείου.</string>
<string name="conflict_message_description">Εάν επιλέξετε και τις δύο εκδόσεις, στο όνομα του τοπικού αρχείου θα προστεθεί ένας αριθμός.</string>
<string name="conflict_message_headline">Ποια αρχεία θέλετε να κρατήσετε;</string>
<string name="conflict_new_file">Νέο αρχείο</string>
<string name="conflict_title">Διένεξη αρχείων</string>
<string name="conflict_use_local_version">τοπική έκδοση</string>
<string name="conflict_use_server_version">έκδοση διακομιστή</string>
Expand Down Expand Up @@ -696,6 +699,8 @@
<string name="tags">Ετικέτες</string>
<string name="test_server_button">Δοκιμή σύνδεσης με διακομιστή</string>
<string name="thumbnail">Μικρογραφία</string>
<string name="thumbnail_for_existing_file_description">Μικρογραφία υπάρχοντος αρχείου</string>
<string name="thumbnail_for_new_file_desc">Μικρογραφία νέου αρχείου</string>
<string name="timeout_richDocuments">Η φόρτωση διαρκεί πολύ…</string>
<string name="trashbin_activity_title">Διεγραμμένα αρχεία</string>
<string name="trashbin_empty_headline">Κανένα διαγεγραμμένο αρχείο</string>
Expand Down
Loading

0 comments on commit 909c960

Please sign in to comment.