From 5c23e4ee5244b722261ae93d7c61bb670232d46f Mon Sep 17 00:00:00 2001 From: M M Arif Date: Wed, 24 Aug 2022 09:21:25 +0200 Subject: [PATCH] Copy/share/open file options in fileviewer (#1193) Closes #1191 Co-authored-by: M M Arif Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1193 Reviewed-by: qwerty287 --- app/build.gradle | 10 +-- .../gitnex/activities/FileViewActivity.java | 28 +++++++- .../OrganizationDetailActivity.java | 7 +- .../BottomSheetFileViewerFragment.java | 18 +++++ .../res/layout/bottom_sheet_file_viewer.xml | 68 +++++++++++++++++-- 5 files changed, 113 insertions(+), 18 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1e2668fa..dcd7ea4a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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" diff --git a/app/src/main/java/org/mian/gitnex/activities/FileViewActivity.java b/app/src/main/java/org/mian/gitnex/activities/FileViewActivity.java index a2a68015..20bbecef 100644 --- a/app/src/main/java/org/mian/gitnex/activities/FileViewActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/FileViewActivity.java @@ -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() { diff --git a/app/src/main/java/org/mian/gitnex/activities/OrganizationDetailActivity.java b/app/src/main/java/org/mian/gitnex/activities/OrganizationDetailActivity.java index 973aa7b5..66624e68 100644 --- a/app/src/main/java/org/mian/gitnex/activities/OrganizationDetailActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/OrganizationDetailActivity.java @@ -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 call, @NotNull Response response) { + public void onResponse(@NonNull Call call, @NonNull Response response) { isMember = response.code() != 404; init(); } @Override - public void onFailure(@NotNull Call call, @NotNull Throwable t) { + public void onFailure(@NonNull Call 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); diff --git a/app/src/main/java/org/mian/gitnex/fragments/BottomSheetFileViewerFragment.java b/app/src/main/java/org/mian/gitnex/fragments/BottomSheetFileViewerFragment.java index d3fd2922..6efe5488 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/BottomSheetFileViewerFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/BottomSheetFileViewerFragment.java @@ -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(); } diff --git a/app/src/main/res/layout/bottom_sheet_file_viewer.xml b/app/src/main/res/layout/bottom_sheet_file_viewer.xml index 993038cb..778a8eb8 100644 --- a/app/src/main/res/layout/bottom_sheet_file_viewer.xml +++ b/app/src/main/res/layout/bottom_sheet_file_viewer.xml @@ -1,6 +1,5 @@ - + android:textSize="16sp" /> @@ -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" /> + app:layout_alignSelf="flex_start" /> + app:layout_alignSelf="flex_start" /> + + + + + + + + + + + +