From 0c8c9a89a371d6515c34d1c4f7417c26059ee969 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Fri, 29 Mar 2024 13:39:45 +0100 Subject: Move about screen to :ui:preferences (#7039) --- app/build.gradle | 12 ---- .../antennapod/activity/PreferenceActivity.java | 3 +- .../preferences/MainPreferencesFragment.java | 2 +- .../fragment/preferences/about/AboutFragment.java | 58 ------------------ app/src/main/res/layout/settings_activity.xml | 5 -- ui/preferences/build.gradle | 15 +++++ .../ui/preferences/screen/about/AboutFragment.java | 70 ++++++++++++++++++++++ .../src/main/res/layout/settings_activity.xml | 6 ++ 8 files changed, 94 insertions(+), 77 deletions(-) delete mode 100644 app/src/main/java/de/danoeh/antennapod/fragment/preferences/about/AboutFragment.java delete mode 100644 app/src/main/res/layout/settings_activity.xml create mode 100644 ui/preferences/src/main/java/de/danoeh/antennapod/ui/preferences/screen/about/AboutFragment.java create mode 100644 ui/preferences/src/main/res/layout/settings_activity.xml diff --git a/app/build.gradle b/app/build.gradle index 02031b9e1..1f813d092 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -15,18 +15,6 @@ android { versionCode 3030095 versionName "3.3.0" - 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) + '"') - javaCompileOptions { annotationProcessorOptions { arguments = [eventBusIndex: 'de.danoeh.antennapod.ApEventBusIndex'] diff --git a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java index 8d6ac965f..aa3b05715 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java @@ -21,7 +21,7 @@ import com.bytehamster.lib.preferencesearch.SearchPreferenceResultListener; import com.google.android.material.snackbar.Snackbar; import de.danoeh.antennapod.R; import de.danoeh.antennapod.ui.common.ThemeSwitcher; -import de.danoeh.antennapod.databinding.SettingsActivityBinding; + import de.danoeh.antennapod.event.MessageEvent; import de.danoeh.antennapod.fragment.preferences.ImportExportPreferencesFragment; import de.danoeh.antennapod.fragment.preferences.MainPreferencesFragment; @@ -32,6 +32,7 @@ import de.danoeh.antennapod.fragment.preferences.UserInterfacePreferencesFragmen import de.danoeh.antennapod.ui.preferences.screen.AutoDownloadPreferencesFragment; import de.danoeh.antennapod.ui.preferences.screen.NotificationPreferencesFragment; import de.danoeh.antennapod.ui.preferences.screen.synchronization.SynchronizationPreferencesFragment; +import de.danoeh.antennapod.ui.preferences.databinding.SettingsActivityBinding; import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/MainPreferencesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/MainPreferencesFragment.java index bf30700bf..50d201f39 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/MainPreferencesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/MainPreferencesFragment.java @@ -16,7 +16,7 @@ import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.BugReportActivity; import de.danoeh.antennapod.activity.PreferenceActivity; import de.danoeh.antennapod.core.util.IntentUtils; -import de.danoeh.antennapod.fragment.preferences.about.AboutFragment; +import de.danoeh.antennapod.ui.preferences.screen.about.AboutFragment; public class MainPreferencesFragment extends PreferenceFragmentCompat { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/about/AboutFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/about/AboutFragment.java deleted file mode 100644 index 0b17da3e6..000000000 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/about/AboutFragment.java +++ /dev/null @@ -1,58 +0,0 @@ -package de.danoeh.antennapod.fragment.preferences.about; - -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; -import android.os.Build; -import android.os.Bundle; -import androidx.preference.PreferenceFragmentCompat; -import com.google.android.material.snackbar.Snackbar; -import de.danoeh.antennapod.BuildConfig; -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.activity.PreferenceActivity; -import de.danoeh.antennapod.core.util.IntentUtils; -import de.danoeh.antennapod.ui.preferences.screen.about.ContributorsPagerFragment; -import de.danoeh.antennapod.ui.preferences.screen.about.LicensesFragment; - -public class AboutFragment extends PreferenceFragmentCompat { - - @Override - public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { - addPreferencesFromResource(R.xml.preferences_about); - - findPreference("about_version").setSummary(String.format( - "%s (%s)", BuildConfig.VERSION_NAME, 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(); - ((PreferenceActivity) getActivity()).getSupportActionBar().setTitle(R.string.about_pref); - } -} diff --git a/app/src/main/res/layout/settings_activity.xml b/app/src/main/res/layout/settings_activity.xml deleted file mode 100644 index 91fe40373..000000000 --- a/app/src/main/res/layout/settings_activity.xml +++ /dev/null @@ -1,5 +0,0 @@ - - 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 @@ + + -- cgit v1.2.3