diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2024-03-29 13:39:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-29 13:39:45 +0100 |
commit | 0c8c9a89a371d6515c34d1c4f7417c26059ee969 (patch) | |
tree | be7b961ba1cbf0e3e688a0e9f1e8f2ce7808bcd1 /ui/preferences | |
parent | f9dd837362921df3fbcea424f9e064ecc696f367 (diff) | |
download | AntennaPod-0c8c9a89a371d6515c34d1c4f7417c26059ee969.zip |
Move about screen to :ui:preferences (#7039)
Diffstat (limited to 'ui/preferences')
3 files changed, 91 insertions, 0 deletions
diff --git a/ui/preferences/build.gradle b/ui/preferences/build.gradle index b91158fb9..c1f56854f 100644 --- a/ui/preferences/build.gradle +++ b/ui/preferences/build.gradle @@ -6,6 +6,20 @@ apply from: "../../playFlavor.gradle" android { namespace "de.danoeh.antennapod.ui.preferences" + + defaultConfig { + def commit = "" + try { + def hashStdOut = new ByteArrayOutputStream() + exec { + commandLine "git", "rev-parse", "--short", "HEAD" + standardOutput = hashStdOut + } + commit = hashStdOut.toString().trim() + } catch (Exception ignore) { + } + buildConfigField "String", "COMMIT_HASH", ('"' + (commit.isEmpty() ? "Unknown commit" : commit) + '"') + } } dependencies { @@ -23,6 +37,7 @@ dependencies { annotationProcessor "androidx.annotation:annotation:$annotationVersion" implementation "androidx.appcompat:appcompat:$appcompatVersion" + implementation "androidx.fragment:fragment:$fragmentVersion" implementation "com.google.android.material:material:$googleMaterialVersion" implementation "androidx.preference:preference:$preferenceVersion" implementation "androidx.work:work-runtime:$workManagerVersion" diff --git a/ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/about/AboutFragment.java b/ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/about/AboutFragment.java new file mode 100644 index 000000000..ad956ed71 --- /dev/null +++ b/ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/about/AboutFragment.java @@ -0,0 +1,70 @@ +package de.danoeh.antennapod.ui.preferences.screen.about; + +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.os.Build; +import android.os.Bundle; +import androidx.appcompat.app.AppCompatActivity; +import androidx.preference.PreferenceFragmentCompat; +import com.google.android.material.snackbar.Snackbar; +import de.danoeh.antennapod.core.util.IntentUtils; +import de.danoeh.antennapod.ui.preferences.BuildConfig; +import de.danoeh.antennapod.ui.preferences.R; + +public class AboutFragment extends PreferenceFragmentCompat { + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + addPreferencesFromResource(R.xml.preferences_about); + + String versionName = "?"; + try { + PackageInfo packageInfo = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), 0); + versionName = packageInfo.versionName; + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + //noinspection ConstantValue + if ("free".equals(BuildConfig.FLAVOR)) { + versionName += "f"; + } + + findPreference("about_version").setSummary(String.format( + "%s (%s)", versionName, BuildConfig.COMMIT_HASH)); + findPreference("about_version").setOnPreferenceClickListener((preference) -> { + ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText(getString(R.string.bug_report_title), + findPreference("about_version").getSummary()); + clipboard.setPrimaryClip(clip); + if (Build.VERSION.SDK_INT <= 32) { + Snackbar.make(getView(), R.string.copied_to_clipboard, Snackbar.LENGTH_SHORT).show(); + } + return true; + }); + findPreference("about_contributors").setOnPreferenceClickListener((preference) -> { + getParentFragmentManager().beginTransaction() + .replace(R.id.settingsContainer, new ContributorsPagerFragment()) + .addToBackStack(getString(R.string.contributors)).commit(); + return true; + }); + findPreference("about_privacy_policy").setOnPreferenceClickListener((preference) -> { + IntentUtils.openInBrowser(getContext(), "https://antennapod.org/privacy/"); + return true; + }); + findPreference("about_licenses").setOnPreferenceClickListener((preference) -> { + getParentFragmentManager().beginTransaction() + .replace(R.id.settingsContainer, new LicensesFragment()) + .addToBackStack(getString(R.string.translators)).commit(); + return true; + }); + } + + @Override + public void onStart() { + super.onStart(); + ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(R.string.about_pref); + } +} diff --git a/ui/preferences/src/main/res/layout/settings_activity.xml b/ui/preferences/src/main/res/layout/settings_activity.xml new file mode 100644 index 000000000..58aeb7f60 --- /dev/null +++ b/ui/preferences/src/main/res/layout/settings_activity.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<androidx.fragment.app.FragmentContainerView + xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/settingsContainer" + android:layout_width="match_parent" + android:layout_height="match_parent" /> |