浏览代码

use interface
fix #1918

Signed-off-by: tobiaskaminsky <tobias@kaminsky.me>

tobiaskaminsky 7 年之前
父节点
当前提交
d434674315

+ 7 - 1
src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -130,7 +130,8 @@ import static com.owncloud.android.db.PreferenceManager.getSortOrder;
 
 public class FileDisplayActivity extends HookActivity
         implements FileFragment.ContainerActivity,
-        OnEnforceableRefreshListener, SortingOrderDialogFragment.OnSortingOrderListener {
+        OnEnforceableRefreshListener, SortingOrderDialogFragment.OnSortingOrderListener,
+        SendShareDialog.SendShareDialogDownloader {
  
     private SyncBroadcastReceiver mSyncBroadcastReceiver;
     private UploadFinishReceiver mUploadFinishReceiver;
@@ -1178,6 +1179,11 @@ public class FileDisplayActivity extends HookActivity
         getListOfFilesFragment().sortFiles(selection);
     }
 
+    @Override
+    public void downloadFile(OCFile file, String packageName, String activityName) {
+        startDownloadForSending(file, OCFileListFragment.DOWNLOAD_SEND, packageName, activityName);
+    }
+
     private class SyncBroadcastReceiver extends BroadcastReceiver {
 
         /**

+ 4 - 5
src/main/java/com/owncloud/android/ui/dialog/SendShareDialog.java

@@ -24,7 +24,6 @@ import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.adapter.SendButtonAdapter;
 import com.owncloud.android.ui.components.SendButtonData;
-import com.owncloud.android.ui.fragment.OCFileListFragment;
 import com.owncloud.android.ui.helpers.FileOperationsHelper;
 import com.owncloud.android.utils.MimeTypeUtil;
 import com.owncloud.android.utils.ThemeUtils;
@@ -187,8 +186,8 @@ public class SendShareDialog extends BottomSheetDialogFragment {
 
                     } else {  // Download the file
                         Log_OC.d(TAG, file.getRemotePath() + ": File must be downloaded");
-                        fileDisplayActivity.startDownloadForSending(file, OCFileListFragment.DOWNLOAD_SEND,
-                                packageName, activityName);
+                        ((SendShareDialog.SendShareDialogDownloader) getActivity()).downloadFile(file, packageName,
+                                activityName);
                     }
                 }
 
@@ -229,7 +228,7 @@ public class SendShareDialog extends BottomSheetDialogFragment {
         this.fileOperationsHelper = fileOperationsHelper;
     }
 
-    public void setFileDisplayActivity(FileDisplayActivity fileDisplayActivity) {
-        this.fileDisplayActivity = fileDisplayActivity;
+    public interface SendShareDialogDownloader {
+        void downloadFile(OCFile file, String packageName, String activityName);
     }
 }

+ 17 - 18
src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java

@@ -154,10 +154,10 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
         
         if (mLayout == R.layout.file_details_fragment) {
             int accentColor = ThemeUtils.primaryAccentColor();
-            SwitchCompat favoriteToggle = (SwitchCompat) mView.findViewById(R.id.fdFavorite);
+            SwitchCompat favoriteToggle = mView.findViewById(R.id.fdFavorite);
             favoriteToggle.setOnCheckedChangeListener(this);
             ThemeUtils.tintSwitch(favoriteToggle, accentColor, false);
-            ProgressBar progressBar = (ProgressBar)mView.findViewById(R.id.fdProgressBar);
+            ProgressBar progressBar = mView.findViewById(R.id.fdProgressBar);
             ThemeUtils.colorHorizontalProgressBar(progressBar, ThemeUtils.primaryAccentColor());
             mProgressListener = new ProgressListener(progressBar);
             mView.findViewById(R.id.fdCancelBtn).setOnClickListener(this);
@@ -320,8 +320,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
                     )
                             .show();
                 } else {
-                    mContainerActivity.getFileOperationsHelper().sendShareFile(getFile(),
-                        (FileDisplayActivity) mContainerActivity);
+                    mContainerActivity.getFileOperationsHelper().sendShareFile(getFile());
                 }
                 return true;
             }
@@ -368,7 +367,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
 
     @Override
     public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
-        SwitchCompat favSwitch = (SwitchCompat) getView().findViewById(R.id.fdFavorite);
+        SwitchCompat favSwitch = getView().findViewById(R.id.fdFavorite);
         mContainerActivity.getFileOperationsHelper().toggleOfflineFile(getFile(), favSwitch.isChecked());
     }
 
@@ -417,8 +416,8 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
             setFilesize(file.getFileLength());
 
             setTimeModified(file.getModificationTimestamp());
-            
-            SwitchCompat favSwitch = (SwitchCompat) getView().findViewById(R.id.fdFavorite);
+
+            SwitchCompat favSwitch = getView().findViewById(R.id.fdFavorite);
             favSwitch.setChecked(file.isAvailableOffline());
 
             setShareByLinkInfo(file.isSharedViaLink());
@@ -463,7 +462,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
      * @param filename to set
      */
     private void setFilename(String filename) {
-        TextView tv = (TextView) getView().findViewById(R.id.fdFilename);
+        TextView tv = getView().findViewById(R.id.fdFilename);
         if (tv != null) {
             tv.setText(filename);
         }
@@ -474,7 +473,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
      * @param file : An {@link OCFile}
      */
     private void setFiletype(OCFile file) {
-        ImageView iv = (ImageView) getView().findViewById(R.id.fdIcon);
+        ImageView iv = getView().findViewById(R.id.fdIcon);
 
         if (iv != null) {
             iv.setTag(file.getFileId());
@@ -521,7 +520,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
      * @param fileSize in bytes to set
      */
     private void setFilesize(long fileSize) {
-        TextView tv = (TextView) getView().findViewById(R.id.fdSize);
+        TextView tv = getView().findViewById(R.id.fdSize);
         if (tv != null) {
             tv.setText(DisplayUtils.bytesToHumanReadable(fileSize));
         }
@@ -533,7 +532,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
      * @param milliseconds Unix time to set
      */
     private void setTimeModified(long milliseconds) {
-        TextView tv = (TextView) getView().findViewById(R.id.fdModified);
+        TextView tv = getView().findViewById(R.id.fdModified);
         if (tv != null) {
             tv.setText(DisplayUtils.unixTimeToHumanReadable(milliseconds));
         }
@@ -545,12 +544,12 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
      * @param isShareByLink flag is share by link is enable
      */
     private void setShareByLinkInfo(boolean isShareByLink) {
-        TextView tv = (TextView) getView().findViewById(R.id.fdSharebyLink);
+        TextView tv = getView().findViewById(R.id.fdSharebyLink);
         if (tv != null) {
             tv.setText(isShareByLink ? R.string.filedetails_share_link_enable :
                     R.string.filedetails_share_link_disable);
         }
-        ImageView linkIcon = (ImageView) getView().findViewById(R.id.fdShareLinkIcon);
+        ImageView linkIcon = getView().findViewById(R.id.fdShareLinkIcon);
         if (linkIcon != null) {
             linkIcon.setVisibility(isShareByLink ? View.VISIBLE : View.GONE);
         }
@@ -581,10 +580,10 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
         );
 
         // Show data
-        ListView usersList = (ListView) getView().findViewById(R.id.fdshareUsersList);
+        ListView usersList = getView().findViewById(R.id.fdshareUsersList);
 
         // No data
-        TextView noList = (TextView) getView().findViewById(R.id.fdShareNoUsers);
+        TextView noList = getView().findViewById(R.id.fdShareNoUsers);
 
         if (mShares.size() > 0) {
             usersList.setVisibility(View.VISIBLE);
@@ -633,7 +632,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
             
             // show the progress bar for the transfer
             getView().findViewById(R.id.fdProgressBlock).setVisibility(View.VISIBLE);
-            TextView progressText = (TextView) getView().findViewById(R.id.fdProgressText);
+            TextView progressText = getView().findViewById(R.id.fdProgressText);
             progressText.setVisibility(View.VISIBLE);
             FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();
             FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();
@@ -658,7 +657,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
             
             // hides the progress bar
             getView().findViewById(R.id.fdProgressBlock).setVisibility(View.GONE);
-            TextView progressText = (TextView) getView().findViewById(R.id.fdProgressText);
+            TextView progressText = getView().findViewById(R.id.fdProgressText);
             progressText.setVisibility(View.GONE);
         }
     }
@@ -672,7 +671,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
             
             // hides the progress bar
             getView().findViewById(R.id.fdProgressBlock).setVisibility(View.GONE);
-            TextView progressText = (TextView) getView().findViewById(R.id.fdProgressText);
+            TextView progressText = getView().findViewById(R.id.fdProgressText);
             progressText.setVisibility(View.GONE);
         }
     }

+ 2 - 3
src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -513,7 +513,7 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
 
     @Override
     public void onShareIconClick(OCFile file) {
-        mContainerActivity.getFileOperationsHelper().sendShareFile(file, (FileDisplayActivity) mContainerActivity);
+        mContainerActivity.getFileOperationsHelper().sendShareFile(file);
     }
 
     @Override
@@ -944,8 +944,7 @@ public class OCFileListFragment extends ExtendedListFragment implements OCFileLi
             OCFile singleFile = checkedFiles.get(0);
             switch (menuId) {
                 case R.id.action_send_share_file: {
-                        mContainerActivity.getFileOperationsHelper().sendShareFile(singleFile,
-                    (FileDisplayActivity) mContainerActivity);
+                    mContainerActivity.getFileOperationsHelper().sendShareFile(singleFile);
                     return true;
                 }
                 case R.id.action_open_file_with: {

+ 1 - 3
src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java

@@ -54,7 +54,6 @@ import com.owncloud.android.services.OperationsService;
 import com.owncloud.android.services.observer.FileObserverService;
 import com.owncloud.android.ui.activity.ConflictsResolveActivity;
 import com.owncloud.android.ui.activity.FileActivity;
-import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.activity.ShareActivity;
 import com.owncloud.android.ui.dialog.SendShareDialog;
 import com.owncloud.android.ui.events.FavoriteEvent;
@@ -543,7 +542,7 @@ public class FileOperationsHelper {
         return false;
     }
 
-    public void sendShareFile(OCFile file, FileDisplayActivity fileDisplayActivity) {
+    public void sendShareFile(OCFile file) {
         // Show dialog
         FragmentManager fm = mFileActivity.getSupportFragmentManager();
         FragmentTransaction ft = fm.beginTransaction();
@@ -551,7 +550,6 @@ public class FileOperationsHelper {
 
         SendShareDialog mSendShareDialog = SendShareDialog.newInstance(file);
         mSendShareDialog.setFileOperationsHelper(this);
-        mSendShareDialog.setFileDisplayActivity(fileDisplayActivity);
         mSendShareDialog.show(ft, "TAG_SEND_SHARE_DIALOG");
     }
 

+ 8 - 10
src/main/java/com/owncloud/android/ui/preview/PreviewImageFragment.java

@@ -60,7 +60,6 @@ import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.files.FileMenuFilter;
 import com.owncloud.android.lib.common.utils.Log_OC;
-import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
 import com.owncloud.android.ui.dialog.RemoveFilesDialogFragment;
 import com.owncloud.android.ui.fragment.FileFragment;
@@ -180,7 +179,7 @@ public class PreviewImageFragment extends FileFragment {
                              Bundle savedInstanceState) {
         super.onCreateView(inflater, container, savedInstanceState);
         View view = inflater.inflate(R.layout.preview_image_fragment, container, false);
-        mImageView = (TouchImageViewCustom) view.findViewById(R.id.image);
+        mImageView = view.findViewById(R.id.image);
         mImageView.setPreviewImageFragment(this);
         mImageView.setVisibility(View.GONE);
 
@@ -200,7 +199,7 @@ public class PreviewImageFragment extends FileFragment {
             }
         });
 
-        mMultiView = (RelativeLayout) view.findViewById(R.id.multi_view);
+        mMultiView = view.findViewById(R.id.multi_view);
 
         setupMultiView(view);
         setMultiListLoadingMessage();
@@ -217,11 +216,11 @@ public class PreviewImageFragment extends FileFragment {
     }
 
     protected void setupMultiView(View view) {
-        mMultiListContainer = (LinearLayout) view.findViewById(R.id.empty_list_view);
-        mMultiListMessage = (TextView) view.findViewById(R.id.empty_list_view_text);
-        mMultiListHeadline = (TextView) view.findViewById(R.id.empty_list_view_headline);
-        mMultiListIcon = (ImageView) view.findViewById(R.id.empty_list_icon);
-        mMultiListProgress = (ProgressBar) view.findViewById(R.id.empty_list_progress);
+        mMultiListContainer = view.findViewById(R.id.empty_list_view);
+        mMultiListMessage = view.findViewById(R.id.empty_list_view_text);
+        mMultiListHeadline = view.findViewById(R.id.empty_list_view_headline);
+        mMultiListIcon = view.findViewById(R.id.empty_list_icon);
+        mMultiListProgress = view.findViewById(R.id.empty_list_progress);
     }
 
     /**
@@ -429,8 +428,7 @@ public class PreviewImageFragment extends FileFragment {
                     )
                             .show();
                 } else {
-                    mContainerActivity.getFileOperationsHelper().sendShareFile(getFile(),
-                        (FileDisplayActivity) mContainerActivity);
+                    mContainerActivity.getFileOperationsHelper().sendShareFile(getFile());
                 }
                 return true;
 

+ 1 - 1
src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java

@@ -486,7 +486,7 @@ public class PreviewMediaFragment extends FileFragment implements
 
     private void sendShareFile() {
         stopPreview(false);
-        mContainerActivity.getFileOperationsHelper().sendShareFile(getFile(), (FileDisplayActivity) mContainerActivity);
+        mContainerActivity.getFileOperationsHelper().sendShareFile(getFile());
     }
 
     private void prepareVideo() {

+ 8 - 9
src/main/java/com/owncloud/android/ui/preview/PreviewTextFragment.java

@@ -104,9 +104,9 @@ public class PreviewTextFragment extends FileFragment {
 
         View ret = inflater.inflate(R.layout.text_file_preview, container, false);
 
-        mTextPreview = (TextView) ret.findViewById(R.id.text_preview);
+        mTextPreview = ret.findViewById(R.id.text_preview);
 
-        mMultiView = (RelativeLayout) ret.findViewById(R.id.multi_view);
+        mMultiView = ret.findViewById(R.id.multi_view);
 
         setupMultiView(ret);
         setMultiListLoadingMessage();
@@ -115,11 +115,11 @@ public class PreviewTextFragment extends FileFragment {
     }
 
     protected void setupMultiView(View view) {
-        mMultiListContainer = (LinearLayout) view.findViewById(R.id.empty_list_view);
-        mMultiListMessage = (TextView) view.findViewById(R.id.empty_list_view_text);
-        mMultiListHeadline = (TextView) view.findViewById(R.id.empty_list_view_headline);
-        mMultiListIcon = (ImageView) view.findViewById(R.id.empty_list_icon);
-        mMultiListProgress = (ProgressBar) view.findViewById(R.id.empty_list_progress);
+        mMultiListContainer = view.findViewById(R.id.empty_list_view);
+        mMultiListMessage = view.findViewById(R.id.empty_list_view_text);
+        mMultiListHeadline = view.findViewById(R.id.empty_list_view_headline);
+        mMultiListIcon = view.findViewById(R.id.empty_list_icon);
+        mMultiListProgress = view.findViewById(R.id.empty_list_progress);
     }
 
     private void setMultiListLoadingMessage() {
@@ -390,8 +390,7 @@ public class PreviewTextFragment extends FileFragment {
                     )
                             .show();
                 } else {
-                    mContainerActivity.getFileOperationsHelper().sendShareFile(getFile(),
-                        (FileDisplayActivity) mContainerActivity);
+                    mContainerActivity.getFileOperationsHelper().sendShareFile(getFile());
                 }
                 return true;
             }