Explorar o código

instead of returning null on getServerVersion(), it returns now a very latest NC10 version

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky %!s(int64=7) %!d(string=hai) anos
pai
achega
08ff99e07d

+ 7 - 5
src/main/java/com/owncloud/android/authentication/AccountUtils.java

@@ -25,6 +25,7 @@ import android.accounts.AccountManager;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.preference.PreferenceManager;
+import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 
 import com.owncloud.android.MainApp;
@@ -199,8 +200,9 @@ public class AccountUtils {
      * @return              Version of the OC server corresponding to account, according to the data saved
      *                      in the system AccountManager
      */
-    public static OwnCloudVersion getServerVersion(Account account) {
-        OwnCloudVersion serverVersion = null;
+    public static @NonNull
+    OwnCloudVersion getServerVersion(Account account) {
+        OwnCloudVersion serverVersion = OwnCloudVersion.nextcloud_10;
         if (account != null) {
             AccountManager accountMgr = AccountManager.get(MainApp.getAppContext());
             String serverVersionStr = accountMgr.getUserData(account, Constants.KEY_OC_VERSION);
@@ -211,13 +213,13 @@ public class AccountUtils {
         return serverVersion;
     }
 
-    public static boolean hasSearchUsersSupport(Account account){
+    public static boolean hasSearchUsersSupport(Account account) {
         OwnCloudVersion serverVersion = getServerVersion(account);
-        return (serverVersion != null && serverVersion.isSearchUsersSupported());
+        return serverVersion.isSearchUsersSupported();
     }
 
     public static boolean hasSearchSupport(Account account) {
         OwnCloudVersion serverVersion = getServerVersion(account);
-        return (serverVersion != null && serverVersion.isSearchSupported());
+        return serverVersion.isSearchSupported();
     }
 }

+ 5 - 3
src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java

@@ -286,7 +286,8 @@ public class ThumbnailsCacheManager {
                 } else {
                     // Download thumbnail from server
                     OwnCloudVersion serverOCVersion = AccountUtils.getServerVersion(account);
-                    if (mClient != null && serverOCVersion != null) {
+
+                    if (mClient != null) {
                         if (serverOCVersion.supportsRemoteThumbnails()) {
                             GetMethod getMethod = null;
                             try {
@@ -530,7 +531,8 @@ public class ThumbnailsCacheManager {
                 } else {
                     // Download thumbnail from server
                     OwnCloudVersion serverOCVersion = AccountUtils.getServerVersion(mAccount);
-                    if (mClient != null && serverOCVersion != null) {
+
+                    if (mClient != null) {
                         if (serverOCVersion.supportsRemoteThumbnails()) {
                             getMethod = null;
                             try {
@@ -838,7 +840,7 @@ public class ThumbnailsCacheManager {
 
             // Download avatar from server
             OwnCloudVersion serverOCVersion = AccountUtils.getServerVersion(mAccount);
-            if (mClient != null && serverOCVersion != null) {
+            if (mClient != null) {
                 if (serverOCVersion.supportsRemoteThumbnails()) {
                     GetMethod get = null;
                     try {

+ 1 - 2
src/main/java/com/owncloud/android/services/OperationsService.java

@@ -442,8 +442,7 @@ public class OperationsService extends Service {
                                     getClientFor(ocAccount, mService);
 
                             OwnCloudVersion version = com.owncloud.android.authentication.AccountUtils.getServerVersion(
-                                    mLastTarget.mAccount
-                            );
+                                    mLastTarget.mAccount);
                             mOwnCloudClient.setOwnCloudVersion(version);
 
                             mStorageManager = new FileDataStorageManager(

+ 3 - 3
src/main/java/com/owncloud/android/ui/activity/ShareActivity.java

@@ -149,9 +149,9 @@ public class ShareActivity extends FileActivity implements ShareFragmentListener
             return OCShare.READ_PERMISSION_FLAG;    // minimum permissions
 
         } else if (isFederated) {
-            OwnCloudVersion serverVersion = com.owncloud.android.authentication.AccountUtils.
-                    getServerVersion(getAccount());
-            if (serverVersion != null && serverVersion.isNotReshareableFederatedSupported()) {
+            OwnCloudVersion serverVersion = com.owncloud.android.authentication.AccountUtils
+                    .getServerVersion(getAccount());
+            if (serverVersion.isNotReshareableFederatedSupported()) {
                 return (getFile().isFolder() ? OCShare.FEDERATED_PERMISSIONS_FOR_FOLDER_AFTER_OC9 :
                         OCShare.FEDERATED_PERMISSIONS_FOR_FILE_AFTER_OC9);
             } else {

+ 15 - 16
src/main/java/com/owncloud/android/ui/fragment/EditShareFragment.java

@@ -179,12 +179,11 @@ public class EditShareFragment extends Fragment {
             int sharePermissions = mShare.getPermissions();
             boolean isFederated = ShareType.FEDERATED.equals(mShare.getShareType());
             OwnCloudVersion serverVersion = AccountUtils.getServerVersion(mAccount);
-            boolean isNotReshareableFederatedSupported = (serverVersion != null &&
-                    serverVersion.isNotReshareableFederatedSupported());
+            boolean isNotReshareableFederatedSupported = serverVersion.isNotReshareableFederatedSupported();
 
             int accentColor = ThemeUtils.primaryAccentColor();
 
-            SwitchCompat shareSwitch = (SwitchCompat) editShareView.findViewById(R.id.canShareSwitch);
+            SwitchCompat shareSwitch = editShareView.findViewById(R.id.canShareSwitch);
             ThemeUtils.tintSwitch(shareSwitch, accentColor, true);
 
             if (isFederated) {
@@ -195,7 +194,7 @@ public class EditShareFragment extends Fragment {
 
             shareSwitch.setChecked((sharePermissions & OCShare.SHARE_PERMISSION_FLAG) > 0);
 
-            SwitchCompat switchCompat = (SwitchCompat) editShareView.findViewById(R.id.canEditSwitch);
+            SwitchCompat switchCompat = editShareView.findViewById(R.id.canEditSwitch);
             ThemeUtils.tintSwitch(switchCompat, accentColor, true);
             int anyUpdatePermission = OCShare.CREATE_PERMISSION_FLAG | OCShare.UPDATE_PERMISSION_FLAG |
                     OCShare.DELETE_PERMISSION_FLAG;
@@ -207,17 +206,17 @@ public class EditShareFragment extends Fragment {
             if (mFile.isFolder() && areEditOptionsAvailable) {
                 /// TODO change areEditOptionsAvailable in order to delete !isFederated
                 // from checking when iOS is ready
-                AppCompatCheckBox checkBox = (AppCompatCheckBox) editShareView.findViewById(R.id.canEditCreateCheckBox);
+                AppCompatCheckBox checkBox = editShareView.findViewById(R.id.canEditCreateCheckBox);
                 checkBox.setChecked((sharePermissions & OCShare.CREATE_PERMISSION_FLAG) > 0);
                 checkBox.setVisibility((canEdit) ? View.VISIBLE : View.GONE);
                 ThemeUtils.tintCheckbox(checkBox, accentColor);
 
-                checkBox = (AppCompatCheckBox) editShareView.findViewById(R.id.canEditChangeCheckBox);
+                checkBox = editShareView.findViewById(R.id.canEditChangeCheckBox);
                 checkBox.setChecked((sharePermissions & OCShare.UPDATE_PERMISSION_FLAG) > 0);
                 checkBox.setVisibility((canEdit) ? View.VISIBLE : View.GONE);
                 ThemeUtils.tintCheckbox(checkBox, accentColor);
 
-                checkBox = (AppCompatCheckBox) editShareView.findViewById(R.id.canEditDeleteCheckBox);
+                checkBox = editShareView.findViewById(R.id.canEditDeleteCheckBox);
                 checkBox.setChecked((sharePermissions & OCShare.DELETE_PERMISSION_FLAG) > 0);
                 checkBox.setVisibility((canEdit) ? View.VISIBLE : View.GONE);
                 ThemeUtils.tintCheckbox(checkBox, accentColor);
@@ -243,20 +242,20 @@ public class EditShareFragment extends Fragment {
         CompoundButton.OnCheckedChangeListener changeListener = enable ? mOnPrivilegeChangeListener : null;
         CompoundButton compound;
 
-        compound = (CompoundButton) editShareView.findViewById(R.id.canShareSwitch);
+        compound = editShareView.findViewById(R.id.canShareSwitch);
         compound.setOnCheckedChangeListener(changeListener);
 
-        compound = (CompoundButton) editShareView.findViewById(R.id.canEditSwitch);
+        compound = editShareView.findViewById(R.id.canEditSwitch);
         compound.setOnCheckedChangeListener(changeListener);
 
         if (mFile.isFolder()) {
-            compound = (CompoundButton) editShareView.findViewById(R.id.canEditCreateCheckBox);
+            compound = editShareView.findViewById(R.id.canEditCreateCheckBox);
             compound.setOnCheckedChangeListener(changeListener);
 
-            compound = (CompoundButton) editShareView.findViewById(R.id.canEditChangeCheckBox);
+            compound = editShareView.findViewById(R.id.canEditChangeCheckBox);
             compound.setOnCheckedChangeListener(changeListener);
 
-            compound = (CompoundButton) editShareView.findViewById(R.id.canEditDeleteCheckBox);
+            compound = editShareView.findViewById(R.id.canEditDeleteCheckBox);
             compound.setOnCheckedChangeListener(changeListener);
         }
 
@@ -301,7 +300,7 @@ public class EditShareFragment extends Fragment {
                                 /// not federated shares -> enable all the subpermisions
                                 for (int i = 0; i < sSubordinateCheckBoxIds.length; i++) {
                                     //noinspection ConstantConditions, prevented in the method beginning
-                                    subordinate = (CompoundButton) getView().findViewById(sSubordinateCheckBoxIds[i]);
+                                    subordinate = getView().findViewById(sSubordinateCheckBoxIds[i]);
                                     subordinate.setVisibility(View.VISIBLE);
                                     if (!subordinate.isChecked() &&
                                             !mFile.isSharedWithMe()) {          // see (1)
@@ -311,7 +310,7 @@ public class EditShareFragment extends Fragment {
                             } else {
                                 /// federated share -> enable delete subpermission, as server side; TODO why?
                                 //noinspection ConstantConditions, prevented in the method beginning
-                                subordinate = (CompoundButton) getView().findViewById(R.id.canEditDeleteCheckBox);
+                                subordinate = getView().findViewById(R.id.canEditDeleteCheckBox);
                                 if (!subordinate.isChecked()) {
                                     toggleDisablingListener(subordinate);
                                 }
@@ -320,7 +319,7 @@ public class EditShareFragment extends Fragment {
                         } else {
                             for (int i = 0; i < sSubordinateCheckBoxIds.length; i++) {
                                 //noinspection ConstantConditions, prevented in the method beginning
-                                subordinate = (CompoundButton) getView().findViewById(sSubordinateCheckBoxIds[i]);
+                                subordinate = getView().findViewById(sSubordinateCheckBoxIds[i]);
                                 subordinate.setVisibility(View.GONE);
                                 if (subordinate.isChecked()) {
                                     toggleDisablingListener(subordinate);
@@ -374,7 +373,7 @@ public class EditShareFragment extends Fragment {
          * @param isChecked                 'true' iif subordinateCheckBoxView was checked.
          */
         private void syncCanEditSwitch(View subordinateCheckBoxView, boolean isChecked) {
-            CompoundButton canEditCompound = (CompoundButton) getView().findViewById(R.id.canEditSwitch);
+            CompoundButton canEditCompound = getView().findViewById(R.id.canEditSwitch);
             if (isChecked) {
                 if (!canEditCompound.isChecked()) {
                     toggleDisablingListener(canEditCompound);

+ 11 - 9
src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -1212,15 +1212,17 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
     }
 
     private void updateLayout() {
-        updateFooter();
-        // decide grid vs list view
-        OwnCloudVersion version = AccountUtils.getServerVersion(
-                ((FileActivity) mContainerActivity).getAccount());
-        if (version != null && version.supportsRemoteThumbnails() &&
-                isGridViewPreferred(mFile)) {
-            switchToGridView();
-        } else {
-            switchToListView();
+        
+            updateFooter();
+            // decide grid vs list view
+            OwnCloudVersion version = AccountUtils.getServerVersion(
+                    ((FileActivity) mContainerActivity).getAccount());
+            if ( version.supportsRemoteThumbnails() &&
+                    isGridViewPreferred(mFile)) {
+                switchToGridView();
+            } else {
+                switchToListView();
+            
         }
 
         invalidateActionMode();

+ 5 - 6
src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java

@@ -387,7 +387,7 @@ public class FileOperationsHelper {
     public boolean isSharedSupported() {
         if (mFileActivity.getAccount() != null) {
             OwnCloudVersion serverVersion = AccountUtils.getServerVersion(mFileActivity.getAccount());
-            return (serverVersion != null && serverVersion.isSharedSupported());
+            return serverVersion.isSharedSupported();
         }
         return false;
     }
@@ -554,7 +554,7 @@ public class FileOperationsHelper {
         } else {
             OwnCloudVersion serverVersion = AccountUtils.getServerVersion(mFileActivity.getAccount());
 
-            if (serverVersion != null && serverVersion.isNotReshareableFederatedSupported()) {
+            if (serverVersion.isNotReshareableFederatedSupported()) {
                 updateShareIntent.putExtra(OperationsService.EXTRA_SHARE_PERMISSIONS,
                         OCShare.FEDERATED_PERMISSIONS_FOR_FOLDER_AFTER_OC9);
             } else {
@@ -572,7 +572,7 @@ public class FileOperationsHelper {
     public boolean isSearchUserSupportedSupported() {
         if (mFileActivity.getAccount() != null) {
             OwnCloudVersion serverVersion = AccountUtils.getServerVersion(mFileActivity.getAccount());
-            return (serverVersion != null && serverVersion.isSearchUsersSupported());
+            return serverVersion.isSearchUsersSupported();
         }
         return false;
     }
@@ -854,9 +854,8 @@ public class FileOperationsHelper {
      */
     public boolean isVersionWithForbiddenCharacters() {
         if (mFileActivity.getAccount() != null) {
-            OwnCloudVersion serverVersion =
-                    AccountUtils.getServerVersion(mFileActivity.getAccount());
-            return (serverVersion != null && serverVersion.isVersionWithForbiddenCharacters());
+            OwnCloudVersion serverVersion = AccountUtils.getServerVersion(mFileActivity.getAccount());
+            return serverVersion.isVersionWithForbiddenCharacters();
         }
         return false;
     }

+ 2 - 3
src/main/java/com/owncloud/android/utils/glide/HttpStreamFetcher.java

@@ -55,13 +55,12 @@ public class HttpStreamFetcher implements DataFetcher<InputStream> {
     public InputStream loadData(Priority priority) throws Exception {
 
         Account mAccount = AccountUtils.getCurrentOwnCloudAccount(MainApp.getAppContext());
-        OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount,
-                MainApp.getAppContext());
+        OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, MainApp.getAppContext());
         OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
                 getClientFor(ocAccount, MainApp.getAppContext());
 
         OwnCloudVersion serverOCVersion = AccountUtils.getServerVersion(mAccount);
-        if (mClient != null && serverOCVersion != null) {
+        if (mClient != null) {
             if (serverOCVersion.supportsRemoteThumbnails()) {
                 GetMethod get = null;
                 try {