3333import android .view .View ;
3434import android .view .View .OnClickListener ;
3535import android .view .ViewGroup ;
36+ import android .widget .Button ;
3637import android .widget .ImageView ;
3738import android .widget .LinearLayout ;
3839import android .widget .ProgressBar ;
@@ -153,6 +154,7 @@ public View onCreateView(@NotNull LayoutInflater inflater, ViewGroup container,
153154 }
154155
155156 updateFileDetails (false , false );
157+ setButtonsClickListener ();
156158 return mView ;
157159 }
158160
@@ -281,7 +283,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
281283 return true ;
282284 }
283285 case R .id .action_open_file_with : {
284- mContainerActivity . getFileOperationsHelper (). openFile ( getFile () );
286+ openWith ( );
285287 return true ;
286288 }
287289 case R .id .action_remove_file : {
@@ -300,17 +302,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
300302 }
301303 case R .id .action_download_file :
302304 case R .id .action_sync_file : {
303- mContainerActivity . getFileOperationsHelper (). syncFile ( getFile () );
305+ downloadFile ( );
304306 return true ;
305307 }
306308 case R .id .action_send_file : {
307- // Obtain the file
308- if (!getFile ().isDown ()) { // Download the file
309- Timber .d ("%s : File must be downloaded" , getFile ().getRemotePath ());
310- ((FileDisplayActivity ) mContainerActivity ).startDownloadForSending (getFile ());
311- } else {
312- mContainerActivity .getFileOperationsHelper ().sendDownloadedFile (getFile ());
313- }
309+ sendFile ();
314310 return true ;
315311 }
316312 case R .id .action_set_available_offline : {
@@ -326,6 +322,24 @@ public boolean onOptionsItemSelected(MenuItem item) {
326322 }
327323 }
328324
325+ private void openWith () {
326+ mContainerActivity .getFileOperationsHelper ().openFile (getFile ());
327+ }
328+
329+ private void downloadFile () {
330+ mContainerActivity .getFileOperationsHelper ().syncFile (getFile ());
331+ }
332+
333+ private void sendFile () {
334+ // Obtain the file
335+ if (!getFile ().isDown ()) { // Download the file
336+ Timber .d ("%s : File must be downloaded" , getFile ().getRemotePath ());
337+ ((FileDisplayActivity ) mContainerActivity ).startDownloadForSending (getFile ());
338+ } else {
339+ mContainerActivity .getFileOperationsHelper ().sendDownloadedFile (getFile ());
340+ }
341+ }
342+
329343 @ Override
330344 public void onClick (View v ) {
331345 switch (v .getId ()) {
@@ -335,6 +349,25 @@ public void onClick(View v) {
335349 }
336350 case R .id .fdIcon : {
337351 displayFile (getFile ());
352+
353+ break ;
354+ }
355+ case R .id .button_file_detail_download : {
356+ OCFile file = getFile ();
357+ if (file .isDown ()) {
358+
359+ } else {
360+ downloadFile ();
361+ }
362+ break ;
363+ }
364+ case R .id .button_file_detail_open_with : {
365+ openWith ();
366+ break ;
367+ }
368+ case R .id .button_file_detail_send : {
369+ sendFile ();
370+ break ;
338371 }
339372 default :
340373 Timber .e ("Incorrect view clicked!" );
@@ -426,6 +459,7 @@ private void updateFileDetails(boolean forcedTransferring, boolean refresh) {
426459 setButtonsForRemote ();
427460 }
428461 }
462+ setOpenOrDownloadButtonAction ();
429463 getView ().invalidate ();
430464 }
431465
@@ -575,4 +609,29 @@ private void setButtonsForRemote() {
575609 }
576610 }
577611
612+ private void setButtonsClickListener () {
613+ Button buttonDownload = getView ().findViewById (R .id .button_file_detail_download );
614+ Button buttonOpenWith = getView ().findViewById (R .id .button_file_detail_open_with );
615+ Button buttonSend = getView ().findViewById (R .id .button_file_detail_send );
616+
617+ buttonDownload .setOnClickListener (this );
618+ buttonOpenWith .setOnClickListener (this );
619+ buttonSend .setOnClickListener (this );
620+
621+ setOpenOrDownloadButtonAction ();
622+ }
623+
624+ private void setOpenOrDownloadButtonAction () {
625+ OCFile file = getFile ();
626+ Button button = getView ().findViewById (R .id .button_file_detail_download );
627+
628+ if (file .isDown ()) {
629+ button .setText (getString (R .string .filedetails_open ));
630+ button .setCompoundDrawablesWithIntrinsicBounds (R .drawable .ic_open_in_new , 0 , 0 , 0 );
631+ } else {
632+ button .setText (getString (R .string .filedetails_download ));
633+ button .setCompoundDrawablesWithIntrinsicBounds (R .drawable .ic_cloud_download , 0 , 0 , 0 );
634+ }
635+ }
636+
578637}
0 commit comments