Copy/share/open file options in fileviewer (#1193)

Closes #1191

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1193
Reviewed-by: qwerty287 <qwerty287@noreply.codeberg.org>
This commit is contained in:
M M Arif 2022-08-24 09:21:25 +02:00
parent f310f9f8e6
commit 5c23e4ee52
5 changed files with 113 additions and 18 deletions

View File

@ -1,11 +1,11 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 32
compileSdkVersion 33
defaultConfig {
applicationId "org.mian.gitnex"
minSdkVersion 23
targetSdkVersion 32
targetSdkVersion 33
versionCode 445
versionName "4.5.0-dev"
multiDexEnabled true
@ -56,10 +56,10 @@ dependencies {
def acra = '5.8.4'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.compose.material3:material3:1.0.0-alpha15'
implementation 'androidx.compose.material3:material3-window-size-class:1.0.0-alpha15'
implementation 'androidx.compose.material3:material3:1.0.0-alpha16'
implementation 'androidx.compose.material3:material3-window-size-class:1.0.0-alpha16'
implementation 'androidx.viewpager2:viewpager2:1.1.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation "androidx.legacy:legacy-support-v4:1.0.0"

View File

@ -8,9 +8,14 @@ import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.*;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat;
import com.vdurmont.emoji.EmojiParser;
import org.apache.commons.io.FilenameUtils;
@ -19,7 +24,12 @@ import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.databinding.ActivityFileViewBinding;
import org.mian.gitnex.fragments.BottomSheetFileViewerFragment;
import org.mian.gitnex.helpers.*;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.Constants;
import org.mian.gitnex.helpers.Images;
import org.mian.gitnex.helpers.Markdown;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.helpers.contexts.RepositoryContext;
import org.mian.gitnex.notifications.Notifications;
import org.mian.gitnex.structs.BottomSheetListener;
@ -266,7 +276,7 @@ public class FileViewActivity extends BaseActivity implements BottomSheetListene
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.generic_nav_dotted_menu, menu);
@ -362,6 +372,18 @@ public class FileViewActivity extends BaseActivity implements BottomSheetListene
Toasty.error(ctx, getString(R.string.fileTypeCannotBeEdited));
}
}
if("copyUrl".equals(text)) {
AppUtil.copyToClipboard(this, file.getHtmlUrl(), ctx.getString(R.string.copyIssueUrlToastMsg));
}
if("share".equals(text)) {
AppUtil.sharingIntent(this, file.getHtmlUrl());
}
if("open".equals(text)) {
AppUtil.openUrlInBrowser(this, file.getHtmlUrl());
}
}
private void requestFileDownload() {

View File

@ -13,7 +13,6 @@ import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout;
import org.gitnex.tea4j.v2.models.OrganizationPermissions;
import org.jetbrains.annotations.NotNull;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.fragments.*;
@ -82,13 +81,13 @@ public class OrganizationDetailActivity extends BaseActivity implements BottomSh
RetrofitClient.getApiInterface(this).orgIsMember(orgName, getAccount().getAccount().getUserName()).enqueue(new Callback<>() {
@Override
public void onResponse(@NotNull Call<Void> call, @NotNull Response<Void> response) {
public void onResponse(@NonNull Call<Void> call, @NonNull Response<Void> response) {
isMember = response.code() != 404;
init();
}
@Override
public void onFailure(@NotNull Call<Void> call, @NotNull Throwable t) {
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
isMember = false;
init();
}
@ -139,7 +138,7 @@ public class OrganizationDetailActivity extends BaseActivity implements BottomSh
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.repo_dotted_menu, menu);

View File

@ -53,6 +53,24 @@ public class BottomSheetFileViewerFragment extends BottomSheetDialogFragment {
dismiss();
});
bottomSheetFileViewerBinding.copyUrl.setOnClickListener(v1 -> {
bmListener.onButtonClicked("copyUrl");
dismiss();
});
bottomSheetFileViewerBinding.share.setOnClickListener(v1 -> {
bmListener.onButtonClicked("share");
dismiss();
});
bottomSheetFileViewerBinding.open.setOnClickListener(v1 -> {
bmListener.onButtonClicked("open");
dismiss();
});
return bottomSheetFileViewerBinding.getRoot();
}

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -32,7 +31,7 @@
android:gravity="center"
android:text="@string/file"
android:textColor="?attr/primaryTextColor"
android:textSize="16sp"/>
android:textSize="16sp" />
</LinearLayout>
@ -57,7 +56,7 @@
android:textColor="?attr/primaryTextColor"
android:textSize="16sp"
app:drawableTopCompat="@drawable/ic_edit"
app:layout_alignSelf="flex_start"/>
app:layout_alignSelf="flex_start" />
<TextView
android:id="@+id/deleteFile"
@ -70,7 +69,7 @@
android:textColor="?attr/primaryTextColor"
android:textSize="16sp"
app:drawableTopCompat="@drawable/ic_delete"
app:layout_alignSelf="flex_start"/>
app:layout_alignSelf="flex_start" />
<TextView
android:id="@+id/downloadFile"
@ -83,7 +82,64 @@
android:textColor="?attr/primaryTextColor"
android:textSize="16sp"
app:drawableTopCompat="@drawable/ic_download"
app:layout_alignSelf="flex_start"/>
app:layout_alignSelf="flex_start" />
</com.google.android.flexbox.FlexboxLayout>
<View
android:id="@+id/file_viewer_divider"
android:layout_width="match_parent"
android:layout_height="4dp"
android:layout_marginBottom="16dp"
android:background="?attr/dividerColor" />
<com.google.android.flexbox.FlexboxLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp"
app:alignContent="center"
app:alignItems="flex_start"
app:flexWrap="wrap"
app:justifyContent="center">
<TextView
android:id="@+id/copy_url"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:gravity="center"
android:padding="8dp"
android:text="@string/genericCopyUrl"
android:textColor="?attr/primaryTextColor"
android:textSize="16sp"
app:drawableTopCompat="@drawable/ic_copy"
app:layout_alignSelf="flex_start" />
<TextView
android:id="@+id/share"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:gravity="center"
android:padding="8dp"
android:text="@string/share"
android:textColor="?attr/primaryTextColor"
android:textSize="16sp"
app:drawableTopCompat="@drawable/ic_share"
app:layout_alignSelf="flex_start" />
<TextView
android:id="@+id/open"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:gravity="center"
android:padding="8dp"
android:text="@string/openInBrowser"
android:textColor="?attr/primaryTextColor"
android:textSize="16sp"
app:drawableTopCompat="@drawable/ic_browser"
app:layout_alignSelf="flex_start" />
</com.google.android.flexbox.FlexboxLayout>