0
0
mirror of https://github.com/TrianguloY/UrlChecker.git synced 2024-09-19 20:02:16 +02:00

Merge pull request #233 from bjbjorn/New_button_+_issue98

I have added issue #98, which was the request to add a 'copy URL' button in the modules screen.

I have also added a button to the home screen that checks the URL in the clipboard. This button used to be hidden behind the three dots, which seemed like a really weird location to me. Considering this is always the way I use the app.

closes #98
This commit is contained in:
TrianguloY 2023-05-27 12:08:27 +02:00 committed by GitHub
commit 46975389d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 127 additions and 36 deletions

View File

@ -5,11 +5,13 @@ import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import com.trianguloy.urlchecker.R;
import com.trianguloy.urlchecker.utilities.AndroidSettings;
import com.trianguloy.urlchecker.utilities.AndroidUtils;
import com.trianguloy.urlchecker.utilities.PackageUtils;
import java.util.Objects;
@ -39,7 +41,8 @@ public class MainActivity extends Activity {
public boolean onCreateOptionsMenu(Menu menu) {
// option for the open in clipboard shortcut
menu.add(R.string.shortcut_checkClipboard)
.setIcon(R.mipmap.clipboard_launcher)
.setIcon(AndroidUtils.getColoredDrawable(R.drawable.ic_clipboard, android.R.attr.textColorPrimary, this))
.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT)
.setOnMenuItemClickListener(o -> {
PackageUtils.startActivity(
new Intent(this, ShortcutsActivity.class),

View File

@ -19,7 +19,6 @@ import com.trianguloy.urlchecker.modules.companions.CTabs;
import com.trianguloy.urlchecker.modules.companions.Flags;
import com.trianguloy.urlchecker.modules.companions.Incognito;
import com.trianguloy.urlchecker.modules.companions.LastOpened;
import com.trianguloy.urlchecker.modules.companions.OnOffConfig;
import com.trianguloy.urlchecker.url.UrlData;
import com.trianguloy.urlchecker.utilities.AndroidUtils;
import com.trianguloy.urlchecker.utilities.GenericPref;
@ -41,10 +40,18 @@ public class OpenModule extends AModuleData {
return new GenericPref.Bool("open_closeshare", true, cntx);
}
public static GenericPref.Bool CLOSECOPY_PREF(Context cntx) {
return new GenericPref.Bool("open_closecopy", false, cntx);
}
public static GenericPref.Bool NOREFERRER_PREF(Context cntx) {
return new GenericPref.Bool("open_noReferrer", true, cntx);
}
public static GenericPref.Bool MERGECOPY_PREF(Context cntx) {
return new GenericPref.Bool("open_mergeCopy", false, cntx);
}
@Override
public String getId() {
return "open";
@ -72,7 +79,9 @@ class OpenDialog extends AModuleDialog {
private final GenericPref.Bool closeOpenPref;
private final GenericPref.Bool closeSharePref;
private final GenericPref.Bool closeCopyPref;
private final GenericPref.Bool noReferrerPref;
private final GenericPref.Bool mergeCopyPref;
private final CTabs cTabs;
private final Incognito incognito;
@ -89,7 +98,9 @@ class OpenDialog extends AModuleDialog {
incognito = new Incognito(dialog);
closeOpenPref = OpenModule.CLOSEOPEN_PREF(dialog);
closeSharePref = OpenModule.CLOSESHARE_PREF(dialog);
closeCopyPref = OpenModule.CLOSECOPY_PREF(dialog);
noReferrerPref = OpenModule.NOREFERRER_PREF(dialog);
mergeCopyPref = OpenModule.MERGECOPY_PREF(dialog);
}
@Override
@ -116,13 +127,23 @@ class OpenDialog extends AModuleDialog {
btn_openWith = views.findViewById(R.id.open_with);
btn_openWith.setOnClickListener(v -> showList());
// init share
View btn_share = views.findViewById(R.id.share);
// init copy & share
var btn_copy = views.findViewById(R.id.copyUrl);
var btn_share = views.findViewById(R.id.share);
btn_share.setOnClickListener(v -> shareUrl());
btn_share.setOnLongClickListener(v -> {
AndroidUtils.copyToClipboard(getActivity(), R.string.mOpen_clipboard, getUrl());
return true;
});
if (mergeCopyPref.get()) {
// merge mode (single button)
btn_copy.setVisibility(View.GONE);
btn_share.setOnLongClickListener(v -> {
copyUrl();
return true;
});
} else {
// split mode (two buttons)
btn_copy.setOnClickListener(v -> copyUrl());
AndroidUtils.longTapForDescription(btn_share);
AndroidUtils.longTapForDescription(btn_copy);
}
// init openWith popup
popup = new PopupMenu(getActivity(), btn_open);
@ -252,7 +273,17 @@ class OpenDialog extends AModuleDialog {
getActivity()
);
if (closeSharePref.get()) {
this.getActivity().finish();
getActivity().finish();
}
}
/**
* Copy the url
*/
private void copyUrl() {
AndroidUtils.copyToClipboard(getActivity(), R.string.mOpen_clipboard, getUrl());
if (closeCopyPref.get()) {
getActivity().finish();
}
}
@ -260,23 +291,8 @@ class OpenDialog extends AModuleDialog {
class OpenConfig extends AModuleConfig {
private final GenericPref.Bool closeOpenPref;
private final GenericPref.Bool closeSharePref;
private final GenericPref.Bool noReferrerPref;
private final GenericPref.Enumeration<OnOffConfig> ctabsPref;
private final GenericPref.Enumeration<OnOffConfig> incognitoPref;
private final GenericPref.Bool perDomainPref;
public OpenConfig(ModulesActivity activity) {
super(activity);
ctabsPref = CTabs.PREF(activity);
incognitoPref = Incognito.PREF(activity);
closeOpenPref = OpenModule.CLOSEOPEN_PREF(activity);
closeSharePref = OpenModule.CLOSESHARE_PREF(activity);
noReferrerPref = OpenModule.NOREFERRER_PREF(activity);
perDomainPref = LastOpened.PERDOMAIN_PREF(activity);
}
@Override
@ -287,15 +303,17 @@ class OpenConfig extends AModuleConfig {
@Override
public void onInitialize(View views) {
if (CTabs.isAvailable()) {
ctabsPref.attachToSpinner(views.findViewById(R.id.ctabs_pref), null);
CTabs.PREF(getActivity()).attachToSpinner(views.findViewById(R.id.ctabs_pref), null);
} else {
views.findViewById(R.id.ctabs_parent).setVisibility(View.GONE);
}
incognitoPref.attachToSpinner(views.findViewById(R.id.incognito_pref), null);
closeOpenPref.attachToSwitch(views.findViewById(R.id.closeopen_pref));
closeSharePref.attachToSwitch(views.findViewById(R.id.closeshare_pref));
noReferrerPref.attachToSwitch(views.findViewById(R.id.noReferrer));
perDomainPref.attachToSwitch(views.findViewById(R.id.perDomain));
Incognito.PREF(getActivity()).attachToSpinner(views.findViewById(R.id.incognito_pref), null);
OpenModule.CLOSEOPEN_PREF(getActivity()).attachToSwitch(views.findViewById(R.id.closeopen_pref));
OpenModule.CLOSESHARE_PREF(getActivity()).attachToSwitch(views.findViewById(R.id.closeshare_pref));
OpenModule.CLOSECOPY_PREF(getActivity()).attachToSwitch(views.findViewById(R.id.closecopy_pref));
OpenModule.NOREFERRER_PREF(getActivity()).attachToSwitch(views.findViewById(R.id.noReferrer));
LastOpened.PERDOMAIN_PREF(getActivity()).attachToSwitch(views.findViewById(R.id.perDomain));
OpenModule.MERGECOPY_PREF(getActivity()).attachToSwitch(views.findViewById(R.id.mergeCopy_pref));
}
}

View File

@ -7,11 +7,13 @@ import android.content.ClipboardManager;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.text.SpannableStringBuilder;
import android.text.style.ClickableSpan;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
@ -199,4 +201,20 @@ public interface AndroidUtils {
view.setText(text);
view.setVisibility(text == null || text.length() == 0 ? View.GONE : View.VISIBLE);
}
/**
* Returns a drawable with a different color
*/
static Drawable getColoredDrawable(int drawableId, int colorAttr, Context cntx) {
// get drawable
var drawable = cntx.getResources().getDrawable(drawableId).mutate();
// get color
var resolvedAttr = new TypedValue();
cntx.getTheme().resolveAttribute(colorAttr, resolvedAttr, true);
// tint
drawable.setColorFilter(cntx.getResources().getColor(resolvedAttr.resourceId), PorterDuff.Mode.SRC_IN);
return drawable;
}
}

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/app"
android:pathData="M16,1L4,1c-1.1,0 -2,0.9 -2,2v14h2L4,3h12L16,1zM19,5L8,5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h11c1.1,0 2,-0.9 2,-2L21,7c0,-1.1 -0.9,-2 -2,-2zM19,21L8,21L8,7h11v14z" />
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/app"
android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z" />
</vector>

View File

@ -64,6 +64,20 @@
android:layout_marginTop="@dimen/smallPadding"
android:text="@string/mOpen_closeShare" />
<Switch
android:id="@+id/closecopy_pref"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/smallPadding"
android:text="@string/mOpen_closeCopy" />
<Switch
android:id="@+id/mergeCopy_pref"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/smallPadding"
android:text="@string/mOpen_mergeCopy" />
<Switch
android:id="@+id/perDomain"
android:layout_width="match_parent"

View File

@ -11,7 +11,6 @@
android:layout_height="match_parent"
android:contentDescription="@string/mOpen_tabsDesc"
android:minWidth="0dp"
android:minHeight="0dp"
android:src="@drawable/ctabs_off" />
<ImageButton
@ -21,7 +20,6 @@
android:layout_height="match_parent"
android:contentDescription="@string/mOpen_incognitoDesc"
android:minWidth="0dp"
android:minHeight="0dp"
android:src="@drawable/no_incognito" />
<LinearLayout
@ -52,14 +50,30 @@
android:background="@drawable/open_right"
android:paddingRight="1dp"
android:src="@drawable/arrow_down"
android:tint="?attr/colorAccent" />
android:tint="?attr/colorAccent"
android:paddingEnd="1dp" />
</LinearLayout>
<Button
<ImageButton
android:id="@+id/copyUrl"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:contentDescription="@string/mOpen_copyUrl"
android:minWidth="0dp"
android:minHeight="0dp"
android:scaleType="center"
android:src="@drawable/copy" />
<ImageButton
android:id="@+id/share"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/mOpen_share" />
android:minWidth="0dp"
android:minHeight="0dp"
android:contentDescription="@string/mOpen_share"
android:src="@drawable/share" />
</LinearLayout>

View File

@ -140,16 +140,20 @@ Note: if you edit the patterns, new built-in patterns from app updates will not
- Custom Tabs button: toggle to enable/disable the custom tab feature. When enabled, the browser should be opened in a 'lite' mode.
- Incognito button: For Firefox only. Toggle to enable/disable the incognito mode. When enabled, the browser should be opened in incognito.
- Open button: Press the app name to open the link on that app. If a link can be opened with multiple apps, an arrow will be shown to let you choose.
- Share button: Press the button to share the link. Long press to quickly copy to clipboard."</string>
- Copy button: Press the button to copy the link into the clipboard.
- Share button: Press the button to share the link."</string>
<string name="mOpen_ctabs">Custom tabs:</string>
<string name="mOpen_incognito">Incognito mode:</string>
<string name="mOpen_closeOpen">Close dialog after opening</string>
<string name="mOpen_closeShare">Close dialog after sharing</string>
<string name="mOpen_closeCopy">Close dialog after copying</string>
<string name="mOpen_perDomain">Sort different domains independently</string>
<string name="mOpen_noReferrer">Hide the source app (referrer)</string>
<string name="mOpen_mergeCopy">Merge Copy and Share buttons (long press to copy)</string>
<string name="mOpen_with">Open with %s</string>
<string name="mOpen_open">Open</string>
<string name="mOpen_share">Share</string>
<string name="mOpen_copyUrl">Copy</string>
<string name="mOpen_clipboard">URL copied to clipboard</string>
<string name="mOpen_noapps">No apps</string>
<string name="mOpen_tabsDesc">Toggle Custom Tabs feature</string>