Skip to content

Commit fe057d9

Browse files
committed
Button functionality added
1 parent 88b8bda commit fe057d9

3 files changed

Lines changed: 75 additions & 15 deletions

File tree

owncloudApp/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import android.view.View;
3434
import android.view.View.OnClickListener;
3535
import android.view.ViewGroup;
36+
import android.widget.Button;
3637
import android.widget.ImageView;
3738
import android.widget.LinearLayout;
3839
import 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
}

owncloudApp/src/main/res/layout/file_details_fragment.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@
170170
style="@style/Button.FileDetail"
171171
android:layout_width="0dp"
172172
android:layout_height="wrap_content"
173-
android:drawableStart="@drawable/ic_cloud_download"
174-
android:text="@string/filedetails_download"
175173
app:layout_constraintLeft_toLeftOf="parent"
176-
app:layout_constraintTop_toBottomOf="@id/view_file_detail_separator" />
174+
app:layout_constraintTop_toBottomOf="@id/view_file_detail_separator"
175+
tools:drawableStart="@drawable/ic_cloud_download"
176+
tools:text="@string/filedetails_download" />
177177

178178
<Button
179179
android:id="@+id/button_file_detail_open_with"
@@ -186,15 +186,15 @@
186186
app:layout_constraintTop_toBottomOf="@id/button_file_detail_download" />
187187

188188
<Button
189-
android:id="@+id/button_file_detail_open_send"
189+
android:id="@+id/button_file_detail_send"
190190
style="@style/Button.FileDetail"
191191
android:layout_width="0dp"
192192
android:layout_height="wrap_content"
193193
android:drawableStart="@drawable/ic_send"
194194
android:text="@string/filedetails_send"
195195
app:layout_constraintLeft_toLeftOf="parent"
196-
app:layout_constraintTop_toBottomOf="@id/button_file_detail_open_with"
197-
app:layout_constraintRight_toLeftOf="@id/barrier"/>
196+
app:layout_constraintRight_toLeftOf="@id/barrier"
197+
app:layout_constraintTop_toBottomOf="@id/button_file_detail_open_with" />
198198

199199
<androidx.constraintlayout.widget.Barrier
200200
android:id="@+id/barrier"

owncloudApp/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@
169169
<string name="filedetails_modified">Modified:</string>
170170
<string name="filedetails_download">Download</string>
171171
<string name="filedetails_open_with">Open with</string>
172+
<string name="filedetails_open">Open</string>
172173
<string name="filedetails_send">Send</string>
173174
<string name="filedetails_file_image_content_description">File Image</string>
174175
<string name="filedetails_cancel_btn_content_description">Cancel download button</string>

0 commit comments

Comments
 (0)