Skip to content

Commit

Permalink
Merge pull request #11846 from nextcloud/refactor-links
Browse files Browse the repository at this point in the history
Refactor links
  • Loading branch information
AndyScherzinger authored Jul 28, 2023
2 parents d93962f + db3a38a commit 8ec2f34
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package com.nextcloud.client.errorhandling

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
Expand Down Expand Up @@ -65,17 +64,11 @@ class ShowErrorActivity : AppCompatActivity() {

private fun reportIssue() {
ClipboardUtil.copyToClipboard(this, binding.textViewError.text.toString(), false)
val issueLink = getString(R.string.report_issue_link)
if (issueLink.isNotEmpty()) {
val uriUrl = Uri.parse(
String.format(
issueLink,
URLEncoder.encode(binding.textViewError.text.toString())
)
)
val intent = Intent(Intent.ACTION_VIEW, uriUrl)
DisplayUtils.startIntentIfAppAvailable(intent, this, R.string.no_browser_available)
}
val issueLink = String.format(
getString(R.string.report_issue_link),
URLEncoder.encode(binding.textViewError.text.toString(), Charsets.UTF_8.name())
)
DisplayUtils.startLinkIntent(this, issueLink)
Toast.makeText(this, R.string.copied_to_clipboard, Toast.LENGTH_LONG).show()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import android.accounts.AccountManager;
import android.content.Intent;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -117,8 +116,8 @@ protected void onCreate(Bundle savedInstanceState) {
defaultViewThemeUtils.platform.colorTextView(binding.hostOwnServer, ColorRole.ON_PRIMARY);
binding.hostOwnServer.setVisibility(isProviderOrOwnInstallationVisible ? View.VISIBLE : View.GONE);

if (!isProviderOrOwnInstallationVisible) {
binding.hostOwnServer.setOnClickListener(v -> onHostYourOwnServerClick());
if (isProviderOrOwnInstallationVisible) {
binding.hostOwnServer.setOnClickListener(v -> DisplayUtils.startLinkIntent(this, R.string.url_server_install));
}


Expand Down Expand Up @@ -153,11 +152,7 @@ private void setSlideshowSize(boolean isLandscape) {
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
setSlideshowSize(true);
} else {
setSlideshowSize(false);
}
setSlideshowSize(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE);
}

@Override
Expand Down Expand Up @@ -201,11 +196,6 @@ public void onPageScrollStateChanged(int state) {
// unused but to be implemented due to abstract parent
}

public void onHostYourOwnServerClick() {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.url_server_install)));
DisplayUtils.startIntentIfAppAvailable(intent, this, R.string.no_browser_available);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
import androidx.annotation.VisibleForTesting;
import androidx.core.content.res.ResourcesCompat;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import kotlin.text.Charsets;

/**
* Manager for concurrent access to thumbnails cache.
Expand Down Expand Up @@ -1415,7 +1416,7 @@ private static Bitmap doResizedImageInBackground(OCFile file, FileDataStorageMan
GetMethod getMethod = null;
try {
String uri = mClient.getBaseUri() + "/index.php/core/preview.png?file="
+ URLEncoder.encode(file.getRemotePath())
+ URLEncoder.encode(file.getRemotePath(), Charsets.UTF_8.name())
+ "&x=" + (pxW / 2) + "&y=" + (pxH / 2) + "&a=1&mode=cover&forceIcon=0";
Log_OC.d(TAG, "generate resized image: " + file.getFileName() + " URI: " + uri);
getMethod = new GetMethod(uri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,7 @@ private void externalLinkClicked(MenuItem menuItem) {
for (ExternalLink link : externalLinksProvider.getExternalLink(ExternalLinkType.LINK)) {
if (menuItem.getTitle().toString().equalsIgnoreCase(link.getName())) {
if (link.getRedirect()) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link.getUrl()));
DisplayUtils.startIntentIfAppAvailable(intent, this, R.string.no_browser_available);
DisplayUtils.startLinkIntent(this, link.getUrl());
} else {
Intent externalWebViewIntent = new Intent(getApplicationContext(), ExternalSiteWebView.class);
externalWebViewIntent.putExtra(ExternalSiteWebView.EXTRA_TITLE, link.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,19 +680,14 @@ public static void showDevSnackbar(Activity activity,
DisplayUtils.showSnackMessage(activity, R.string.dev_version_no_information_available, Snackbar.LENGTH_LONG);
}
if (latestVersion > currentVersion) {
String devApkLink = activity.getString(R.string.dev_link) + latestVersion + ".apk";
if (openDirectly) {
String devApkLink = (String) activity.getText(R.string.dev_link) + latestVersion + ".apk";
Uri uriUrl = Uri.parse(devApkLink);
Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
DisplayUtils.startIntentIfAppAvailable(intent, activity, R.string.no_browser_available);
DisplayUtils.startLinkIntent(activity, devApkLink);
} else {
Snackbar.make(activity.findViewById(android.R.id.content), R.string.dev_version_new_version_available,
Snackbar.LENGTH_LONG)
.setAction(activity.getString(R.string.version_dev_download), v -> {
String devApkLink = (String) activity.getText(R.string.dev_link) + latestVersion + ".apk";
Uri uriUrl = Uri.parse(devApkLink);
Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
DisplayUtils.startIntentIfAppAvailable(intent, activity, R.string.no_browser_available);
DisplayUtils.startLinkIntent(activity, devApkLink);
}).show();
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,7 @@ private void setupImprintPreference(PreferenceCategory preferenceCategoryMore) {
String imprintWeb = getString(R.string.url_imprint);

if (!imprintWeb.isEmpty()) {
Uri uriUrl = Uri.parse(imprintWeb);
Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
DisplayUtils.startIntentIfAppAvailable(intent, this, R.string.no_browser_available);
DisplayUtils.startLinkIntent(this, imprintWeb);
}
//ImprintDialog.newInstance(true).show(preference.get, "IMPRINT_DIALOG");
return true;
Expand Down Expand Up @@ -539,12 +537,7 @@ private void setupHelpPreference(PreferenceCategory preferenceCategoryMore) {
if (pHelp != null) {
if (helpEnabled) {
pHelp.setOnPreferenceClickListener(preference -> {
String helpWeb = getString(R.string.url_help);
if (!helpWeb.isEmpty()) {
Uri uriUrl = Uri.parse(helpWeb);
Intent intent = new Intent(Intent.ACTION_VIEW, uriUrl);
DisplayUtils.startIntentIfAppAvailable(intent, this, R.string.no_browser_available);
}
DisplayUtils.startLinkIntent(this, R.string.url_help);
return true;
});
} else {
Expand Down Expand Up @@ -897,9 +890,7 @@ private void launchDavDroidLogin() {
startActivity(installIntent);
} else {
// no f-droid market app or Play store installed --> launch browser for f-droid url
Intent downloadIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://f-droid.org/repository/browse/?fdid=at.bitfire.davdroid"));
DisplayUtils.startIntentIfAppAvailable(downloadIntent, this, R.string.no_browser_available);
DisplayUtils.startLinkIntent(this, "https://f-droid.org/packages/at.bitfire.davdroid/");

DisplayUtils.showSnackMessage(this, R.string.prefs_calendar_contacts_no_store_error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public void onBindViewHolder(@NonNull NotificationViewHolder holder, int positio
subject = subject + " ↗";
holder.binding.subject.setTypeface(holder.binding.subject.getTypeface(),
Typeface.BOLD);
holder.binding.subject.setOnClickListener(v -> openLink(notification.getLink()));
holder.binding.subject.setOnClickListener(v -> DisplayUtils.startLinkIntent(notificationsActivity,
notification.getLink()));
holder.binding.subject.setText(subject);
} else {
if (!TextUtils.isEmpty(notification.subjectRich)) {
Expand Down Expand Up @@ -329,8 +330,7 @@ private SpannableStringBuilder makeSpecialPartsBold(Notification notification) {
closingBrace = openingBrace + name.length();

ssb.setSpan(styleSpanBold, openingBrace, closingBrace, 0);
ssb.setSpan(foregroundColorSpanBlack, openingBrace, closingBrace,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
ssb.setSpan(foregroundColorSpanBlack, openingBrace, closingBrace, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
openingBrace = text.indexOf('{', closingBrace);
}
Expand Down Expand Up @@ -382,12 +382,6 @@ private void downloadIcon(String icon, ImageView itemViewType, Context context)
.into(itemViewType);
}

private void openLink(String link) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));

DisplayUtils.startIntentIfAppAvailable(intent, notificationsActivity, R.string.no_browser_available);
}

@Override
public int getItemCount() {
return notificationsList.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
package com.owncloud.android.ui.preview;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.text.Html;
Expand Down Expand Up @@ -195,10 +193,7 @@ public void configureTheme(@NonNull MarkwonTheme.Builder builder) {

@Override
public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) {
builder.linkResolver((view, link) -> {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
DisplayUtils.startIntentIfAppAvailable(intent, activity, R.string.no_browser_available);
});
builder.linkResolver((view, link) -> DisplayUtils.startLinkIntent(activity, link));
}
})
.usePlugin(TablePlugin.create(activity))
Expand Down
12 changes: 7 additions & 5 deletions app/src/main/java/com/owncloud/android/utils/DisplayUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -775,13 +775,15 @@ static public void startLinkIntent(Activity activity, @StringRes int link) {
startLinkIntent(activity, activity.getString(link));
}

static public void startLinkIntent(Activity activity, Uri url) {
Intent intent = new Intent(Intent.ACTION_VIEW, url);
DisplayUtils.startIntentIfAppAvailable(intent, activity, R.string.no_browser_available);
static public void startLinkIntent(Activity activity, String url) {
if (!TextUtils.isEmpty(url)) {
startLinkIntent(activity, Uri.parse(url));
}
}

static public void startLinkIntent(Activity activity, String url) {
startLinkIntent(activity, Uri.parse(url));
static public void startLinkIntent(Activity activity, Uri uri) {
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
DisplayUtils.startIntentIfAppAvailable(intent, activity, R.string.no_browser_available);
}

static public void startIntentIfAppAvailable(Intent intent, Activity activity, @StringRes int error) {
Expand Down

0 comments on commit 8ec2f34

Please sign in to comment.