mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 15:15:51 +03:00
Minor refactoring
- use DisplayUtils.startLinkIntent instead of DisplayUtils.startIntentIfAppAvailable where applicable Signed-off-by: ZetaTom <70907959+ZetaTom@users.noreply.github.com>
This commit is contained in:
parent
c98df3285d
commit
2387e2ff75
9 changed files with 24 additions and 68 deletions
|
@ -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
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@ import android.accounts.Account;
|
|||
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;
|
||||
|
@ -118,7 +117,7 @@ public class FirstRunActivity extends BaseActivity implements ViewPager.OnPageCh
|
|||
binding.hostOwnServer.setVisibility(isProviderOrOwnInstallationVisible ? View.VISIBLE : View.GONE);
|
||||
|
||||
if (!isProviderOrOwnInstallationVisible) {
|
||||
binding.hostOwnServer.setOnClickListener(v -> onHostYourOwnServerClick());
|
||||
binding.hostOwnServer.setOnClickListener(v -> DisplayUtils.startLinkIntent(this, R.string.url_server_install));
|
||||
}
|
||||
|
||||
|
||||
|
@ -153,11 +152,7 @@ public class FirstRunActivity extends BaseActivity implements ViewPager.OnPageCh
|
|||
@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
|
||||
|
@ -201,11 +196,6 @@ public class FirstRunActivity extends BaseActivity implements ViewPager.OnPageCh
|
|||
// 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);
|
||||
|
|
|
@ -84,6 +84,7 @@ import androidx.annotation.Nullable;
|
|||
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.
|
||||
|
@ -1415,7 +1416,7 @@ public final class ThumbnailsCacheManager {
|
|||
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);
|
||||
|
|
|
@ -580,8 +580,7 @@ public abstract class DrawerActivity extends ToolbarActivity
|
|||
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());
|
||||
|
|
|
@ -680,19 +680,14 @@ public abstract class FileActivity extends DrawerActivity
|
|||
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 {
|
||||
|
|
|
@ -361,9 +361,7 @@ public class SettingsActivity extends PreferenceActivity
|
|||
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;
|
||||
|
@ -539,12 +537,7 @@ public class SettingsActivity extends PreferenceActivity
|
|||
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 {
|
||||
|
@ -897,9 +890,7 @@ public class SettingsActivity extends PreferenceActivity
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -123,7 +123,8 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
|
|||
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)) {
|
||||
|
@ -329,8 +330,7 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
|
|||
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);
|
||||
}
|
||||
|
@ -382,12 +382,6 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
|
|||
.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();
|
||||
|
|
|
@ -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;
|
||||
|
@ -195,10 +193,7 @@ public abstract class PreviewTextFragment extends FileFragment implements Search
|
|||
|
||||
@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))
|
||||
|
|
|
@ -775,13 +775,11 @@ public final class DisplayUtils {
|
|||
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) {
|
||||
startLinkIntent(activity, Uri.parse(url));
|
||||
if (!TextUtils.isEmpty(url)) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||
DisplayUtils.startIntentIfAppAvailable(intent, activity, R.string.no_browser_available);
|
||||
}
|
||||
}
|
||||
|
||||
static public void startIntentIfAppAvailable(Intent intent, Activity activity, @StringRes int error) {
|
||||
|
|
Loading…
Reference in a new issue