diff --git a/app/build.gradle b/app/build.gradle index 081bc276605..5b04b15cb62 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,6 +11,10 @@ plugins { id "org.sonarqube" version "4.0.0.2929" } +repositories { + mavenCentral() + maven { url "https://jitpack.io" } +} android { compileSdk 34 namespace 'org.schabi.newpipe' @@ -103,6 +107,10 @@ android { 'META-INF/COPYRIGHT'] } } + + buildFeatures { + aidl true + } } ext { @@ -197,9 +205,9 @@ dependencies { // Or you can use a commit you pushed to GitHub by just replacing TeamNewPipe with your GitHub // name and the commit hash with the commit hash of the (pushed) commit you want to test // This works thanks to JitPack: https://jitpack.io/ - implementation 'com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751' - implementation 'com.github.TeamNewPipe:NewPipeExtractor:v0.24.2' - implementation 'com.github.TeamNewPipe:NoNonsense-FilePicker:5.0.0' + implementation 'com.github.teamnewpipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751' + implementation 'com.github.teamnewpipe:NewPipeExtractor:v0.24.2' + implementation 'com.github.teamnewpipe:NoNonsense-FilePicker:5.0.0' /** Checkstyle **/ checkstyle "com.puppycrawl.tools:checkstyle:${checkstyleVersion}" @@ -237,6 +245,10 @@ dependencies { implementation "frankiesardo:icepick:${icepickVersion}" kapt "frankiesardo:icepick-processor:${icepickVersion}" + // changing fonts + implementation 'com.github.MarcinOrlowski:fonty:3.1.5' + + // HTML parser implementation "org.jsoup:jsoup:1.17.2" diff --git a/app/src/main/assets/fonts/Algerian.TTF b/app/src/main/assets/fonts/Algerian.TTF new file mode 100644 index 00000000000..dcc72ae9d99 Binary files /dev/null and b/app/src/main/assets/fonts/Algerian.TTF differ diff --git a/app/src/main/assets/fonts/BELL.TTF b/app/src/main/assets/fonts/BELL.TTF new file mode 100644 index 00000000000..3f426758c48 Binary files /dev/null and b/app/src/main/assets/fonts/BELL.TTF differ diff --git a/app/src/main/assets/fonts/BROADW.TTF b/app/src/main/assets/fonts/BROADW.TTF new file mode 100644 index 00000000000..62aeb1e754b Binary files /dev/null and b/app/src/main/assets/fonts/BROADW.TTF differ diff --git a/app/src/main/assets/fonts/arial.ttf b/app/src/main/assets/fonts/arial.ttf new file mode 100644 index 00000000000..27372d9dbb7 Binary files /dev/null and b/app/src/main/assets/fonts/arial.ttf differ diff --git a/app/src/main/assets/fonts/calibrii.ttf b/app/src/main/assets/fonts/calibrii.ttf new file mode 100644 index 00000000000..f35fd1a814f Binary files /dev/null and b/app/src/main/assets/fonts/calibrii.ttf differ diff --git a/app/src/main/assets/fonts/times.ttf b/app/src/main/assets/fonts/times.ttf new file mode 100644 index 00000000000..3ea695f2e11 Binary files /dev/null and b/app/src/main/assets/fonts/times.ttf differ diff --git a/app/src/main/java/org/schabi/newpipe/App.java b/app/src/main/java/org/schabi/newpipe/App.java index d92425d200e..fe6e334f648 100644 --- a/app/src/main/java/org/schabi/newpipe/App.java +++ b/app/src/main/java/org/schabi/newpipe/App.java @@ -118,6 +118,7 @@ public void onCreate() { configureRxJavaErrorHandler(); } + @Override public void onTerminate() { super.onTerminate(); diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index 17569412572..90b69b86f18 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -57,6 +57,7 @@ import androidx.preference.PreferenceManager; import com.google.android.material.bottomsheet.BottomSheetBehavior; +import com.marcinorlowski.fonty.Fonty; import org.schabi.newpipe.databinding.ActivityMainBinding; import org.schabi.newpipe.databinding.DrawerHeaderBinding; @@ -130,6 +131,9 @@ public class MainActivity extends AppCompatActivity { @Override protected void onCreate(final Bundle savedInstanceState) { + // Apply the preferred font globally + final String preferredFont = getPreferredFont(this); + setUpFont(preferredFont); if (DEBUG) { Log.d(TAG, "onCreate() called with: " + "savedInstanceState = [" + savedInstanceState + "]"); @@ -174,9 +178,13 @@ protected void onCreate(final Bundle savedInstanceState) { && ReleaseVersionUtil.INSTANCE.isReleaseApk()) { UpdateSettingsFragment.askForConsentToUpdateChecks(this); } + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts(this); + } + } - @Override +@Override protected void onPostCreate(final Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); @@ -190,6 +198,51 @@ protected void onPostCreate(final Bundle savedInstanceState) { NewVersionWorker.enqueueNewVersionCheckingWork(app, false); } } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", getString(R.string.default_font_key)); + } + + // build the relevant font TypeFace + public void setUpFont(final String preferredFont) { + switch (preferredFont) { + case "Arial": + Fonty.context(this) + .normalTypeface("arial.ttf") + .build(); + break; + case "Broadway": + Fonty.context(this) + .normalTypeface("BROADW.TTF") + .build(); + break; + case "Algerian": + Fonty.context(this) + .normalTypeface("Algerian.TTF") + .build(); + break; + case "Bell MT": + Fonty.context(this) + .normalTypeface("BELL.TTF") + .build(); + break; + case "Calibri": + Fonty.context(this) + .normalTypeface("calibrii.ttf") + .build(); + break; + case "Time New Roman": + Fonty.context(this) + .normalTypeface("times.ttf") + .build(); + break; + default: + // do nothing + break; + } + + } private void setupDrawer() throws ExtractionException { addDrawerMenuForCurrentService(); diff --git a/app/src/main/java/org/schabi/newpipe/RouterActivity.java b/app/src/main/java/org/schabi/newpipe/RouterActivity.java index c59dc753235..17962ac4c43 100644 --- a/app/src/main/java/org/schabi/newpipe/RouterActivity.java +++ b/app/src/main/java/org/schabi/newpipe/RouterActivity.java @@ -41,6 +41,8 @@ import androidx.lifecycle.LifecycleOwner; import androidx.preference.PreferenceManager; +import com.marcinorlowski.fonty.Fonty; + import org.schabi.newpipe.database.stream.model.StreamEntity; import org.schabi.newpipe.databinding.ListRadioIconItemBinding; import org.schabi.newpipe.databinding.SingleChoiceDialogViewBinding; @@ -128,6 +130,7 @@ public class RouterActivity extends AppCompatActivity { @Override protected void onCreate(final Bundle savedInstanceState) { + final String preferredFont = getPreferredFont(this); ThemeHelper.setDayNightMode(this); setTheme(ThemeHelper.isLightThemeSelected(this) ? R.style.RouterActivityThemeLight : R.style.RouterActivityThemeDark); @@ -183,7 +186,17 @@ public void onFragmentDestroyed(@NonNull final FragmentManager fm, finish(); } } + + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts(this); + } } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", getString(R.string.default_font_key)); + } + @Override protected void onStop() { diff --git a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.kt b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.kt index 7f148e9b5c2..9795cc6b32c 100644 --- a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.kt +++ b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.kt @@ -1,5 +1,6 @@ package org.schabi.newpipe.about +import android.content.Context import android.os.Bundle import android.view.LayoutInflater import android.view.MenuItem @@ -10,8 +11,10 @@ import androidx.annotation.StringRes import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentActivity +import androidx.preference.PreferenceManager import androidx.viewpager2.adapter.FragmentStateAdapter import com.google.android.material.tabs.TabLayoutMediator +import com.marcinorlowski.fonty.Fonty import org.schabi.newpipe.BuildConfig import org.schabi.newpipe.R import org.schabi.newpipe.databinding.ActivityAboutBinding @@ -44,6 +47,15 @@ class AboutActivity : AppCompatActivity() { ) { tab, position -> tab.setText(mAboutStateAdapter.getPageTitle(position)) }.attach() + val preferredFont = getPreferredFont(this) + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts(this) + } + } + fun getPreferredFont(context: Context?): String? { + val preferences = PreferenceManager + .getDefaultSharedPreferences(context!!) + return preferences.getString("preferred_font", getString(R.string.default_font_key)) } override fun onOptionsItemSelected(item: MenuItem): Boolean { diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java b/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java index 37eefed96c6..8d73bdb23e2 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java @@ -1,6 +1,8 @@ package org.schabi.newpipe.download; +import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; @@ -10,6 +12,7 @@ import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.FragmentTransaction; +import androidx.preference.PreferenceManager; import org.schabi.newpipe.R; import org.schabi.newpipe.databinding.ActivityDownloaderBinding; @@ -22,6 +25,8 @@ import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; +import com.marcinorlowski.fonty.Fonty; + public class DownloadActivity extends AppCompatActivity { private static final String MISSIONS_FRAGMENT_TAG = "fragment_tag"; @@ -63,6 +68,10 @@ public void onGlobalLayout() { if (DeviceUtils.isTv(this)) { FocusOverlayView.setupFocusObserver(this); } + final String preferredFont = getPreferredFont(this); + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts(this); + } } private void updateFragments() { @@ -73,6 +82,12 @@ private void updateFragments() { .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) .commit(); } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", getString(R.string.default_font_key)); + } + @Override public boolean onCreateOptionsMenu(final Menu menu) { diff --git a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java index db2066b2782..0bf52f88417 100644 --- a/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java +++ b/app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java @@ -39,6 +39,7 @@ import androidx.fragment.app.DialogFragment; import androidx.preference.PreferenceManager; +import com.marcinorlowski.fonty.Fonty; import com.nononsenseapps.filepicker.Utils; import org.schabi.newpipe.MainActivity; @@ -117,7 +118,6 @@ public class DownloadDialog extends DialogFragment private ActionMenuItemView okButton = null; private Context context = null; private boolean askForSavePath; - private AudioTrackAdapter audioTrackAdapter; private StreamItemAdapter audioStreamsAdapter; private StreamItemAdapter videoStreamsAdapter; @@ -152,7 +152,6 @@ public DownloadDialog() { // otherwise InstantiationException will be thrown when fragment is recreated // TODO: Maybe use a custom FragmentFactory instead? } - /** * Create a new download dialog with the video, audio and subtitle streams from the provided * stream info. Video streams and video-only streams will be put into a single list menu, @@ -245,6 +244,7 @@ public void onServiceDisconnected(final ComponentName name) { }, Context.BIND_AUTO_CREATE); } + /** * Update the displayed video streams based on the selected audio track. */ @@ -287,10 +287,22 @@ public View onCreateView(@NonNull final LayoutInflater inflater, + "inflater = [" + inflater + "], container = [" + container + "], " + "savedInstanceState = [" + savedInstanceState + "]"); } - return inflater.inflate(R.layout.download_dialog, container); + final View view = inflater.inflate(R.layout.download_dialog, container); + final String preferredFont = getPreferredFont(view.getContext()); + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts((ViewGroup) view); + } + return view; } - @Override + public String getPreferredFont(final Context cont) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(cont); + return preferences.getString("preferred_font", getString(R.string.default_font_key)); + } + + +@Override public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); diff --git a/app/src/main/java/org/schabi/newpipe/error/ErrorActivity.java b/app/src/main/java/org/schabi/newpipe/error/ErrorActivity.java index 2f607b4876a..f179fabc115 100644 --- a/app/src/main/java/org/schabi/newpipe/error/ErrorActivity.java +++ b/app/src/main/java/org/schabi/newpipe/error/ErrorActivity.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -16,8 +17,10 @@ import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.IntentCompat; +import androidx.preference.PreferenceManager; import com.grack.nanojson.JsonWriter; +import com.marcinorlowski.fonty.Fonty; import org.schabi.newpipe.BuildConfig; import org.schabi.newpipe.R; @@ -83,6 +86,8 @@ public class ErrorActivity extends AppCompatActivity { @Override protected void onCreate(final Bundle savedInstanceState) { + final String preferredFont = getPreferredFont(this); + assureCorrectAppLanguage(this); super.onCreate(savedInstanceState); @@ -127,6 +132,9 @@ protected void onCreate(final Bundle savedInstanceState) { for (final String e : errorInfo.getStackTraces()) { Log.e(TAG, e); } + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts(this); + } } @Override @@ -150,6 +158,13 @@ public boolean onOptionsItemSelected(final MenuItem item) { return false; } } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", getString(R.string.default_font_key)); + } + + private void openPrivacyPolicyDialog(final Context context, final String action) { new AlertDialog.Builder(context) diff --git a/app/src/main/java/org/schabi/newpipe/error/ReCaptchaActivity.java b/app/src/main/java/org/schabi/newpipe/error/ReCaptchaActivity.java index 42ef261a15d..71a73327044 100644 --- a/app/src/main/java/org/schabi/newpipe/error/ReCaptchaActivity.java +++ b/app/src/main/java/org/schabi/newpipe/error/ReCaptchaActivity.java @@ -1,6 +1,7 @@ package org.schabi.newpipe.error; import android.annotation.SuppressLint; +import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; @@ -20,6 +21,8 @@ import androidx.core.app.NavUtils; import androidx.preference.PreferenceManager; +import com.marcinorlowski.fonty.Fonty; + import org.schabi.newpipe.DownloaderImpl; import org.schabi.newpipe.MainActivity; import org.schabi.newpipe.R; @@ -68,6 +71,7 @@ public static String sanitizeRecaptchaUrl(@Nullable final String url) { @SuppressLint("SetJavaScriptEnabled") @Override protected void onCreate(final Bundle savedInstanceState) { + final String preferredFont = getPreferredFont(this); ThemeHelper.setTheme(this); super.onCreate(savedInstanceState); @@ -109,6 +113,10 @@ public void onPageFinished(final WebView view, final String url) { CookieManager.getInstance().removeAllCookies(null); recaptchaBinding.reCaptchaWebView.loadUrl(url); + + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts(this); + } } @Override @@ -129,6 +137,12 @@ public boolean onCreateOptionsMenu(final Menu menu) { public void onBackPressed() { saveCookiesAndFinish(); } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", getString(R.string.default_font_key)); + } + @Override public boolean onOptionsItemSelected(final MenuItem item) { diff --git a/app/src/main/java/org/schabi/newpipe/fragments/BlankFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/BlankFragment.java index fe4eef37ac3..9de54ab49a2 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/BlankFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/BlankFragment.java @@ -1,11 +1,16 @@ package org.schabi.newpipe.fragments; +import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.annotation.Nullable; +import androidx.preference.PreferenceManager; + +import com.marcinorlowski.fonty.Fonty; import org.schabi.newpipe.BaseFragment; import org.schabi.newpipe.R; @@ -16,9 +21,20 @@ public class BlankFragment extends BaseFragment { public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container, final Bundle savedInstanceState) { setTitle("NewPipe"); - return inflater.inflate(R.layout.fragment_blank, container, false); + final View view = inflater.inflate(R.layout.fragment_blank, container, false); + final String preferredFont = getPreferredFont(view.getContext()); + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts((ViewGroup) view); + } + return view; + } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", getString(R.string.default_font_key)); } + @Override public void onResume() { super.onResume(); diff --git a/app/src/main/java/org/schabi/newpipe/fragments/EmptyFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/EmptyFragment.java index d4e73bcac78..7259611450d 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/EmptyFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/EmptyFragment.java @@ -1,11 +1,16 @@ package org.schabi.newpipe.fragments; +import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.annotation.Nullable; +import androidx.preference.PreferenceManager; + +import com.marcinorlowski.fonty.Fonty; import org.schabi.newpipe.BaseFragment; import org.schabi.newpipe.R; @@ -20,7 +25,11 @@ public static final EmptyFragment newInstance(final boolean showMessage) { emptyFragment.setArguments(bundle); return emptyFragment; } - + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", getString(R.string.default_font_key)); + } @Override public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container, final Bundle savedInstanceState) { @@ -28,6 +37,11 @@ public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGrou final View view = inflater.inflate(R.layout.fragment_empty, container, false); view.findViewById(R.id.empty_state_view).setVisibility( showMessage ? View.VISIBLE : View.GONE); + final String preferredFont = getPreferredFont(view.getContext()); + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts((ViewGroup) view); + } + return view; } } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java index 381de50032a..587b97186b3 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -32,6 +32,7 @@ import androidx.viewpager.widget.ViewPager; import com.google.android.material.tabs.TabLayout; +import com.marcinorlowski.fonty.Fonty; import org.schabi.newpipe.BaseFragment; import org.schabi.newpipe.R; @@ -91,14 +92,26 @@ public void onCreate(final Bundle savedInstanceState) { mainTabsPositionKey = getString(R.string.main_tabs_position_key); mainTabsPositionBottom = prefs.getBoolean(mainTabsPositionKey, false); } - + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", getString(R.string.default_font_key)); + } @Override + public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_main, container, false); + final View view = inflater.inflate(R.layout.fragment_main, container, false); + final String preferredFont = getPreferredFont(view.getContext()); + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts((ViewGroup) view); + } + return view; } + + @Override protected void initViews(final View rootView, final Bundle savedInstanceState) { super.initViews(rootView, savedInstanceState); diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/BaseDescriptionFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/BaseDescriptionFragment.java index 4789b02e65b..a36f7021a11 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/BaseDescriptionFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/BaseDescriptionFragment.java @@ -4,6 +4,8 @@ import static org.schabi.newpipe.extractor.utils.Utils.isBlank; import static org.schabi.newpipe.util.text.TextLinkifier.SET_LINK_MOVEMENT_METHOD; +import android.content.Context; +import android.content.SharedPreferences; import android.graphics.Typeface; import android.os.Bundle; import android.text.SpannableStringBuilder; @@ -21,8 +23,10 @@ import androidx.annotation.StringRes; import androidx.appcompat.widget.TooltipCompat; import androidx.core.text.HtmlCompat; +import androidx.preference.PreferenceManager; import com.google.android.material.chip.Chip; +import com.marcinorlowski.fonty.Fonty; import org.schabi.newpipe.BaseFragment; import org.schabi.newpipe.R; @@ -53,8 +57,17 @@ public View onCreateView(@NonNull final LayoutInflater inflater, setupDescription(); setupMetadata(inflater, binding.detailMetadataLayout); addTagsMetadataItem(inflater, binding.detailMetadataLayout); + final String preferredFont = getPreferredFont(binding.getRoot().getContext()); + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts((ViewGroup) binding.getRoot()); + } return binding.getRoot(); } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", getString(R.string.default_font_key)); + } @Override public void onDestroy() { diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 95b54f65a70..7d2ab288143 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -61,6 +61,7 @@ import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.bottomsheet.BottomSheetBehavior; import com.google.android.material.tabs.TabLayout; +import com.marcinorlowski.fonty.Fonty; import org.schabi.newpipe.App; import org.schabi.newpipe.R; @@ -333,8 +334,18 @@ public void onChange(final boolean selfChange) { public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { binding = FragmentVideoDetailBinding.inflate(inflater, container, false); + final String preferredFont = getPreferredFont(binding.getRoot().getContext()); + if (preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts((ViewGroup) binding.getRoot()); + } return binding.getRoot(); } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", getString(R.string.default_font_key)); + } + @Override public void onPause() { diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index fd382adbf46..248ad635d78 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -28,6 +28,7 @@ import com.google.android.material.snackbar.Snackbar; import com.google.android.material.tabs.TabLayout; import com.jakewharton.rxbinding4.view.RxView; +import com.marcinorlowski.fonty.Fonty; import org.schabi.newpipe.R; import org.schabi.newpipe.database.subscription.NotificationMode; @@ -192,8 +193,18 @@ public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { binding = FragmentChannelBinding.inflate(inflater, container, false); + final String preferredFont = getPreferredFont(binding.getRoot().getContext()); + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts((ViewGroup) binding.getRoot()); + } return binding.getRoot(); } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", getString(R.string.default_font_key)); + } + @Override // called from onViewCreated in BaseFragment.onViewCreated protected void initViews(final View rootView, final Bundle savedInstanceState) { diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelTabFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelTabFragment.java index 95ac42eed08..62f8ad093c3 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelTabFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelTabFragment.java @@ -1,5 +1,7 @@ package org.schabi.newpipe.fragments.list.channel; +import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; @@ -8,6 +10,9 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.preference.PreferenceManager; + +import com.marcinorlowski.fonty.Fonty; import org.schabi.newpipe.R; import org.schabi.newpipe.databinding.PlaylistControlBinding; @@ -75,8 +80,19 @@ public void onCreate(final Bundle savedInstanceState) { public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_channel_tab, container, false); + final View view = inflater.inflate(R.layout.fragment_channel_tab, container, false); + final String preferredFont = getPreferredFont(view.getContext()); + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts((ViewGroup) view); + } + return view; } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", getString(R.string.default_font_key)); + } + @Override public void onDestroyView() { diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentRepliesFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentRepliesFragment.java index 304eaf55a18..7539a3b5e66 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentRepliesFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentRepliesFragment.java @@ -2,6 +2,8 @@ import static org.schabi.newpipe.util.ServiceHelper.getServiceById; +import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -11,6 +13,9 @@ import androidx.annotation.Nullable; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.core.text.HtmlCompat; +import androidx.preference.PreferenceManager; + +import com.marcinorlowski.fonty.Fonty; import org.schabi.newpipe.R; import org.schabi.newpipe.databinding.CommentRepliesHeaderBinding; @@ -65,9 +70,20 @@ public CommentRepliesFragment(@NonNull final CommentsInfoItem commentsInfoItem) public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_comments, container, false); + final View view = inflater.inflate(R.layout.fragment_comments, container, false); + final String preferredFont = getPreferredFont(view.getContext()); + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts((ViewGroup) view); + } + return view; + } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", (getString(R.string.default_font_key))); } + @Override public void onDestroyView() { disposables.clear(); diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java index e25e02794f1..4d0412a3b99 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java @@ -1,5 +1,7 @@ package org.schabi.newpipe.fragments.list.comments; +import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; @@ -10,6 +12,9 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.preference.PreferenceManager; + +import com.marcinorlowski.fonty.Fonty; import org.schabi.newpipe.R; import org.schabi.newpipe.error.UserAction; @@ -55,7 +60,17 @@ protected void initViews(final View rootView, final Bundle savedInstanceState) { public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_comments, container, false); + final View view = inflater.inflate(R.layout.fragment_comments, container, false); + final String preferredFont = getPreferredFont(view.getContext()); + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts((ViewGroup) view); + } + return view; + } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", (getString(R.string.default_font_key))); } @Override diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java index b90dccb1732..27e9d841003 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/kiosk/KioskFragment.java @@ -1,5 +1,7 @@ package org.schabi.newpipe.fragments.list.kiosk; +import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; @@ -10,6 +12,9 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; +import androidx.preference.PreferenceManager; + +import com.marcinorlowski.fonty.Fonty; import org.schabi.newpipe.R; import org.schabi.newpipe.error.ErrorInfo; @@ -100,7 +105,11 @@ public void onCreate(final Bundle savedInstanceState) { name = kioskTranslatedName; contentCountry = Localization.getPreferredContentCountry(requireContext()); } - + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", (getString(R.string.default_font_key))); + } @Override public void onResume() { super.onResume(); @@ -120,7 +129,12 @@ public void onResume() { public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_kiosk, container, false); + final View view = inflater.inflate(R.layout.fragment_kiosk, container, false); + final String preferredFont = getPreferredFont(view.getContext()); + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts((ViewGroup) view); + } + return view; } /*////////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java index 6410fb9ee75..d7a51218b60 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java @@ -6,6 +6,7 @@ import static org.schabi.newpipe.util.ServiceHelper.getServiceById; import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; import android.text.TextUtils; import android.util.Log; @@ -19,9 +20,11 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.content.res.AppCompatResources; +import androidx.preference.PreferenceManager; import com.google.android.material.shape.CornerFamily; import com.google.android.material.shape.ShapeAppearanceModel; +import com.marcinorlowski.fonty.Fonty; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; @@ -98,7 +101,11 @@ public static PlaylistFragment getInstance(final int serviceId, final String url instance.setInitialData(serviceId, url, name); return instance; } - + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", (getString(R.string.default_font_key))); + } public PlaylistFragment() { super(UserAction.REQUESTED_PLAYLIST); } @@ -120,7 +127,12 @@ public void onCreate(final Bundle savedInstanceState) { public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_playlist, container, false); + final View view = inflater.inflate(R.layout.fragment_playlist, container, false); + final String preferredFont = getPreferredFont(view.getContext()); + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts((ViewGroup) view); + } + return view; } /*////////////////////////////////////////////////////////////////////////// @@ -135,7 +147,6 @@ protected Supplier getListHeaderSupplier() { return headerBinding::getRoot; } - @Override protected void initViews(final View rootView, final Bundle savedInstanceState) { super.initViews(rootView, savedInstanceState); @@ -148,7 +159,6 @@ protected void initViews(final View rootView, final Bundle savedInstanceState) { private PlayQueue getPlayQueueStartingAt(final StreamInfoItem infoItem) { return getPlayQueue(Math.max(infoListAdapter.getItemsList().indexOf(infoItem), 0)); } - @Override protected void showInfoItemDialog(final StreamInfoItem item) { final Context context = getContext(); @@ -186,7 +196,6 @@ public void onCreateOptionsMenu(@NonNull final Menu menu, public void onDestroyView() { headerBinding = null; playlistControlBinding = null; - super.onDestroyView(); if (isBookmarkButtonReady != null) { isBookmarkButtonReady.set(false); diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java index eef3455ae87..855096adaf0 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java @@ -40,6 +40,9 @@ import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.RecyclerView; + +import com.marcinorlowski.fonty.Fonty; + import org.schabi.newpipe.R; import org.schabi.newpipe.databinding.FragmentSearchBinding; import org.schabi.newpipe.error.ErrorInfo; @@ -209,9 +212,22 @@ public void onAttach(@NonNull final Context context) { } @Override - public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container, + public View onCreateView(@NonNull final LayoutInflater inflater, + @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_search, container, false); + final ViewGroup view = (ViewGroup) inflater + .inflate(R.layout.fragment_search, container, false); + final String preferredFont = getPreferredFont(view.getContext()); + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts(view); + } + return view; + } + + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", (getString(R.string.default_font_key))); } @Override diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SuggestionListAdapter.java b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SuggestionListAdapter.java index 856ba22f19c..eb856992398 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SuggestionListAdapter.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SuggestionListAdapter.java @@ -1,13 +1,18 @@ package org.schabi.newpipe.fragments.list.search; +import android.content.Context; +import android.content.SharedPreferences; import android.view.LayoutInflater; import android.view.ViewGroup; import androidx.annotation.NonNull; +import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.ListAdapter; import androidx.recyclerview.widget.RecyclerView; +import com.marcinorlowski.fonty.Fonty; + import org.schabi.newpipe.R; import org.schabi.newpipe.databinding.ItemSearchSuggestionBinding; @@ -27,8 +32,19 @@ public void setListener(final OnSuggestionItemSelected listener) { @Override public SuggestionItemHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) { - return new SuggestionItemHolder(ItemSearchSuggestionBinding + final SuggestionItemHolder item = new SuggestionItemHolder(ItemSearchSuggestionBinding .inflate(LayoutInflater.from(parent.getContext()), parent, false)); + final String preferredFont = getPreferredFont(item.itemView.getContext()); + if (!preferredFont.equals("system")) { + Fonty.setFonts((ViewGroup) item.itemView); + } + return item; + } + + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", "system"); } @Override diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedItemsFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedItemsFragment.java index e46937ede3d..0593e003262 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedItemsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/videos/RelatedItemsFragment.java @@ -1,5 +1,6 @@ package org.schabi.newpipe.fragments.list.videos; +import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.view.LayoutInflater; @@ -12,6 +13,8 @@ import androidx.annotation.Nullable; import androidx.preference.PreferenceManager; +import com.marcinorlowski.fonty.Fonty; + import org.schabi.newpipe.R; import org.schabi.newpipe.databinding.RelatedItemsHeaderBinding; import org.schabi.newpipe.error.UserAction; @@ -57,9 +60,20 @@ public RelatedItemsFragment() { public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_related_items, container, false); - } + final View view = inflater + .inflate(R.layout.fragment_related_items, container, false); + final String preferredFont = getPreferredFont(view.getContext()); + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts((ViewGroup) view); + } + return view; + } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", getString(R.string.default_font_key)); + } @Override public void onDestroyView() { headerBinding = null; diff --git a/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java index 575568c00f9..6e48029337e 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java @@ -1,6 +1,8 @@ package org.schabi.newpipe.info_list; import android.content.Context; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -11,6 +13,8 @@ import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.marcinorlowski.fonty.Fonty; + import org.schabi.newpipe.databinding.PignateFooterBinding; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.channel.ChannelInfoItem; @@ -274,11 +278,19 @@ public int getItemViewType(int position) { return -1; } } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", "system"); + } + @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int type) { + final RecyclerView.ViewHolder holder; + final String preferredFont; if (DEBUG) { Log.d(TAG, "onCreateViewHolder() called with: " + "parent = [" + parent + "], type = [" + type + "]"); @@ -288,40 +300,120 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull final ViewGroup paren // Always create a new instance otherwise the same instance // is sometimes reused which causes a crash case HEADER_TYPE: - return new HFHolder(headerSupplier.get()); + holder = new HFHolder(headerSupplier.get()); + preferredFont = getPreferredFont(holder.itemView.getContext()); + if (!preferredFont.equals("system")) { + Fonty.setFonts((ViewGroup) holder.itemView); + } + return holder; case FOOTER_TYPE: - return new HFHolder(PignateFooterBinding + holder = new HFHolder(PignateFooterBinding .inflate(layoutInflater, parent, false) .getRoot() ); + preferredFont = getPreferredFont(holder.itemView.getContext()); + if (!preferredFont.equals("system")) { + Fonty.setFonts((ViewGroup) holder.itemView); + } + return holder; case MINI_STREAM_HOLDER_TYPE: - return new StreamMiniInfoItemHolder(infoItemBuilder, parent); + holder = new StreamMiniInfoItemHolder(infoItemBuilder, parent); + preferredFont = getPreferredFont(holder.itemView.getContext()); + if (!preferredFont.equals("system")) { + Fonty.setFonts((ViewGroup) holder.itemView); + } + return holder; case STREAM_HOLDER_TYPE: - return new StreamInfoItemHolder(infoItemBuilder, parent); + holder = new StreamInfoItemHolder(infoItemBuilder, parent); + preferredFont = getPreferredFont(holder.itemView.getContext()); + if (!preferredFont.equals("system")) { + Fonty.setFonts((ViewGroup) holder.itemView); + } + return holder; case GRID_STREAM_HOLDER_TYPE: - return new StreamGridInfoItemHolder(infoItemBuilder, parent); + holder = new StreamGridInfoItemHolder(infoItemBuilder, parent); + preferredFont = getPreferredFont(holder.itemView.getContext()); + if (!preferredFont.equals("system")) { + Fonty.setFonts((ViewGroup) holder.itemView); + } + return holder; case CARD_STREAM_HOLDER_TYPE: - return new StreamCardInfoItemHolder(infoItemBuilder, parent); + holder = new StreamCardInfoItemHolder(infoItemBuilder, parent); + preferredFont = getPreferredFont(holder.itemView.getContext()); + if (!preferredFont.equals("system")) { + Fonty.setFonts((ViewGroup) holder.itemView); + } + return holder; case MINI_CHANNEL_HOLDER_TYPE: - return new ChannelMiniInfoItemHolder(infoItemBuilder, parent); + holder = new ChannelMiniInfoItemHolder(infoItemBuilder, parent); + preferredFont = getPreferredFont(holder.itemView.getContext()); + if (!preferredFont.equals("system")) { + Fonty.setFonts((ViewGroup) holder.itemView); + } + return holder; case CHANNEL_HOLDER_TYPE: - return new ChannelInfoItemHolder(infoItemBuilder, parent); + holder = new ChannelInfoItemHolder(infoItemBuilder, parent); + preferredFont = getPreferredFont(holder.itemView.getContext()); + if (!preferredFont.equals("system")) { + Fonty.setFonts((ViewGroup) holder.itemView); + } + return holder; case CARD_CHANNEL_HOLDER_TYPE: - return new ChannelCardInfoItemHolder(infoItemBuilder, parent); + holder = new ChannelCardInfoItemHolder(infoItemBuilder, parent); + preferredFont = getPreferredFont(holder.itemView.getContext()); + if (!preferredFont.equals("system")) { + Fonty.setFonts((ViewGroup) holder.itemView); + } + return holder; case GRID_CHANNEL_HOLDER_TYPE: - return new ChannelGridInfoItemHolder(infoItemBuilder, parent); + holder = new ChannelGridInfoItemHolder(infoItemBuilder, parent); + preferredFont = getPreferredFont(holder.itemView.getContext()); + if (!preferredFont.equals("system")) { + Fonty.setFonts((ViewGroup) holder.itemView); + } + return holder; case MINI_PLAYLIST_HOLDER_TYPE: - return new PlaylistMiniInfoItemHolder(infoItemBuilder, parent); + holder = new PlaylistMiniInfoItemHolder(infoItemBuilder, parent); + preferredFont = getPreferredFont(holder.itemView.getContext()); + if (!preferredFont.equals("system")) { + Fonty.setFonts((ViewGroup) holder.itemView); + } + return holder; case PLAYLIST_HOLDER_TYPE: - return new PlaylistInfoItemHolder(infoItemBuilder, parent); + holder = new PlaylistInfoItemHolder(infoItemBuilder, parent); + preferredFont = getPreferredFont(holder.itemView.getContext()); + if (!preferredFont.equals("system")) { + Fonty.setFonts((ViewGroup) holder.itemView); + } + return holder; case GRID_PLAYLIST_HOLDER_TYPE: - return new PlaylistGridInfoItemHolder(infoItemBuilder, parent); + holder = new PlaylistGridInfoItemHolder(infoItemBuilder, parent); + preferredFont = getPreferredFont(holder.itemView.getContext()); + if (!preferredFont.equals("system")) { + Fonty.setFonts((ViewGroup) holder.itemView); + } + return holder; case CARD_PLAYLIST_HOLDER_TYPE: - return new PlaylistCardInfoItemHolder(infoItemBuilder, parent); + holder = new PlaylistCardInfoItemHolder(infoItemBuilder, parent); + preferredFont = getPreferredFont(holder.itemView.getContext()); + if (!preferredFont.equals("system")) { + Fonty.setFonts((ViewGroup) holder.itemView); + } + return holder; case COMMENT_HOLDER_TYPE: - return new CommentInfoItemHolder(infoItemBuilder, parent); + holder = new CommentInfoItemHolder(infoItemBuilder, parent); + preferredFont = getPreferredFont(holder.itemView.getContext()); + if (!preferredFont.equals("system")) { + Fonty.setFonts((ViewGroup) holder.itemView); + } + return holder; default: - return new FallbackViewHolder(new View(parent.getContext())); + holder = new FallbackViewHolder(new View(parent.getContext())); + preferredFont = getPreferredFont(holder.itemView.getContext()); + if (!preferredFont.equals("system")) { + Fonty.setFonts((ViewGroup) holder.itemView); + } + return holder; } } diff --git a/app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java b/app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java index b33619dea7a..afea7811209 100644 --- a/app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java +++ b/app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java @@ -1,15 +1,19 @@ package org.schabi.newpipe.local; import android.content.Context; +import android.content.SharedPreferences; import android.util.Log; import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.marcinorlowski.fonty.Fonty; + import org.schabi.newpipe.database.LocalItem; import org.schabi.newpipe.database.stream.model.StreamStateEntity; import org.schabi.newpipe.info_list.ItemViewMode; @@ -27,7 +31,6 @@ import org.schabi.newpipe.local.holder.LocalStatisticStreamItemHolder; import org.schabi.newpipe.local.holder.RemoteBookmarkPlaylistItemHolder; import org.schabi.newpipe.local.holder.RemotePlaylistCardItemHolder; -import org.schabi.newpipe.local.holder.RemotePlaylistGridItemHolder; import org.schabi.newpipe.local.holder.RemotePlaylistItemHolder; import org.schabi.newpipe.util.FallbackViewHolder; import org.schabi.newpipe.util.Localization; @@ -312,48 +315,95 @@ public int getItemViewType(int position) { @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int type) { + final RecyclerView.ViewHolder holder; if (DEBUG) { Log.d(TAG, "onCreateViewHolder() called with: " + "parent = [" + parent + "], type = [" + type + "]"); } switch (type) { case HEADER_TYPE: + holder = new HeaderFooterHolder(header); + setUpFont(holder); return new HeaderFooterHolder(header); case FOOTER_TYPE: - return new HeaderFooterHolder(footer); + holder = new HeaderFooterHolder(footer); + setUpFont(holder); + return holder; case LOCAL_PLAYLIST_HOLDER_TYPE: - return new LocalPlaylistItemHolder(localItemBuilder, parent); + holder = new LocalPlaylistItemHolder(localItemBuilder, parent); + setUpFont(holder); + return holder; case LOCAL_PLAYLIST_GRID_HOLDER_TYPE: - return new LocalPlaylistGridItemHolder(localItemBuilder, parent); + holder = new LocalPlaylistGridItemHolder(localItemBuilder, parent); + setUpFont(holder); + return holder; case LOCAL_PLAYLIST_CARD_HOLDER_TYPE: - return new LocalPlaylistCardItemHolder(localItemBuilder, parent); + holder = new LocalPlaylistCardItemHolder(localItemBuilder, parent); + setUpFont(holder); + return holder; case LOCAL_BOOKMARK_PLAYLIST_HOLDER_TYPE: - return new LocalBookmarkPlaylistItemHolder(localItemBuilder, parent); + holder = new LocalBookmarkPlaylistItemHolder(localItemBuilder, parent); + setUpFont(holder); + return holder; case REMOTE_PLAYLIST_HOLDER_TYPE: - return new RemotePlaylistItemHolder(localItemBuilder, parent); + holder = new RemotePlaylistItemHolder(localItemBuilder, parent); + setUpFont(holder); + return holder; case REMOTE_PLAYLIST_GRID_HOLDER_TYPE: - return new RemotePlaylistGridItemHolder(localItemBuilder, parent); + holder = new RemotePlaylistCardItemHolder(localItemBuilder, parent); + setUpFont(holder); + return holder; case REMOTE_PLAYLIST_CARD_HOLDER_TYPE: - return new RemotePlaylistCardItemHolder(localItemBuilder, parent); + holder = new HeaderFooterHolder(footer); + setUpFont(holder); + return holder; case REMOTE_BOOKMARK_PLAYLIST_HOLDER_TYPE: - return new RemoteBookmarkPlaylistItemHolder(localItemBuilder, parent); + holder = new RemoteBookmarkPlaylistItemHolder(localItemBuilder, parent); + setUpFont(holder); + return holder; case STREAM_PLAYLIST_HOLDER_TYPE: - return new LocalPlaylistStreamItemHolder(localItemBuilder, parent); + holder = new LocalPlaylistStreamItemHolder(localItemBuilder, parent); + setUpFont(holder); + return holder; case STREAM_PLAYLIST_GRID_HOLDER_TYPE: - return new LocalPlaylistStreamGridItemHolder(localItemBuilder, parent); + holder = new LocalPlaylistStreamGridItemHolder(localItemBuilder, parent); + setUpFont(holder); + return holder; case STREAM_PLAYLIST_CARD_HOLDER_TYPE: - return new LocalPlaylistStreamCardItemHolder(localItemBuilder, parent); + holder = new LocalPlaylistStreamCardItemHolder(localItemBuilder, parent); + setUpFont(holder); + return holder; case STREAM_STATISTICS_HOLDER_TYPE: - return new LocalStatisticStreamItemHolder(localItemBuilder, parent); + holder = new LocalStatisticStreamItemHolder(localItemBuilder, parent); + setUpFont(holder); + return holder; case STREAM_STATISTICS_GRID_HOLDER_TYPE: - return new LocalStatisticStreamGridItemHolder(localItemBuilder, parent); + holder = new LocalStatisticStreamGridItemHolder(localItemBuilder, parent); + setUpFont(holder); + return holder; case STREAM_STATISTICS_CARD_HOLDER_TYPE: - return new LocalStatisticStreamCardItemHolder(localItemBuilder, parent); + holder = new LocalStatisticStreamCardItemHolder(localItemBuilder, parent); + setUpFont(holder); + return holder; default: + holder = new FallbackViewHolder(new View(parent.getContext())); + setUpFont(holder); Log.e(TAG, "No view type has been considered for holder: [" + type + "]"); - return new FallbackViewHolder(new View(parent.getContext())); + return holder; + } + } + public void setUpFont(final RecyclerView.ViewHolder holder) { + final View view = holder.itemView; + final String preferredFont = getPreferredFont(view.getContext()); + if (!preferredFont.equals("system")) { + Fonty.setFonts((ViewGroup) view); } } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", "system"); + } @SuppressWarnings("FinalParameters") @Override diff --git a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java index a366723e0f8..297efd24463 100644 --- a/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/bookmark/BookmarkFragment.java @@ -2,7 +2,9 @@ import static org.schabi.newpipe.local.bookmark.MergedPlaylistManager.getMergedOrderedPlaylists; +import android.content.Context; import android.content.DialogInterface; +import android.content.SharedPreferences; import android.os.Bundle; import android.os.Parcelable; import android.text.InputType; @@ -16,9 +18,12 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.FragmentManager; +import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.RecyclerView; +import com.marcinorlowski.fonty.Fonty; + import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; import org.schabi.newpipe.NewPipeDatabase; @@ -97,13 +102,21 @@ public void onCreate(final Bundle savedInstanceState) { @Override public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, - final Bundle savedInstanceState) { - - if (!useAsFrontPage) { - setTitle(activity.getString(R.string.tab_bookmarks)); + @Nullable final Bundle savedInstanceState) { + final View view = inflater.inflate(R.layout.fragment_bookmarks, container, false); + final String preferredFont = getPreferredFont(view.getContext()); + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts((ViewGroup) view); } - return inflater.inflate(R.layout.fragment_bookmarks, container, false); + return view; } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", (getString(R.string.default_font_key))); + } + + @Override public void onResume() { diff --git a/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistAppendDialog.java b/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistAppendDialog.java index e7f73079f43..4dada5e287e 100644 --- a/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistAppendDialog.java +++ b/app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistAppendDialog.java @@ -1,5 +1,7 @@ package org.schabi.newpipe.local.dialog; +import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -9,9 +11,12 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.marcinorlowski.fonty.Fonty; + import org.schabi.newpipe.NewPipeDatabase; import org.schabi.newpipe.R; import org.schabi.newpipe.database.playlist.model.PlaylistEntity; @@ -51,10 +56,22 @@ public static PlaylistAppendDialog newInstance(final List streamEn //////////////////////////////////////////////////////////////////////////*/ @Override - public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container, - final Bundle savedInstanceState) { - return inflater.inflate(R.layout.dialog_playlists, container); + public View onCreateView(@NonNull final LayoutInflater inflater, + @Nullable final ViewGroup container, + @Nullable final Bundle savedInstanceState) { + final View view = inflater.inflate(R.layout.dialog_playlists, container, false); + final String preferredFont = getPreferredFont(view.getContext()); + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts((ViewGroup) view); + } + return view; } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", (getString(R.string.default_font_key))); + } + @Override public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt index e8c5b1e3497..8d97b22872d 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt @@ -44,6 +44,7 @@ import androidx.lifecycle.ViewModelProvider import androidx.preference.PreferenceManager import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView +import com.marcinorlowski.fonty.Fonty import com.xwray.groupie.GroupieAdapter import com.xwray.groupie.Item import com.xwray.groupie.OnItemClickListener @@ -126,7 +127,14 @@ class FeedFragment : BaseStateFragment() { } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - return inflater.inflate(R.layout.fragment_feed, container, false) + val curView = inflater.inflate(R.layout.fragment_feed, container, false) as ViewGroup + + // Apply the preferred font globally + val preferredFont = getPreferredFont(curView.context) + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts(curView) + } + return curView } override fun onViewCreated(rootView: View, savedInstanceState: Bundle?) { @@ -179,6 +187,11 @@ class FeedFragment : BaseStateFragment() { } } } + fun getPreferredFont(context: Context?): String? { + val preferences = PreferenceManager + .getDefaultSharedPreferences(context!!) + return preferences.getString("preferred_font", (getString(R.string.default_font_key))) + } private fun setupListViewMode() { // does everything needed to setup the layouts for grid or list modes diff --git a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java index 1fea7e1559c..c04ebd5e936 100644 --- a/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/history/StatisticsPlaylistFragment.java @@ -1,6 +1,7 @@ package org.schabi.newpipe.local.history; import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; import android.os.Parcelable; import android.view.LayoutInflater; @@ -13,9 +14,11 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.preference.PreferenceManager; import androidx.viewbinding.ViewBinding; import com.google.android.material.snackbar.Snackbar; +import com.marcinorlowski.fonty.Fonty; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; @@ -95,9 +98,20 @@ public void onCreate(final Bundle savedInstanceState) { public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_playlist, container, false); + final View view = inflater.inflate(R.layout.fragment_playlist, container, false); + final String preferredFont = getPreferredFont(view.getContext()); + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts((ViewGroup) view); + } + return view; + } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", (getString(R.string.default_font_key))); } + @Override public void onResume() { super.onResume(); diff --git a/app/src/main/java/org/schabi/newpipe/local/holder/LocalBookmarkPlaylistItemHolder.java b/app/src/main/java/org/schabi/newpipe/local/holder/LocalBookmarkPlaylistItemHolder.java index 16130009b6e..6498dd987e6 100644 --- a/app/src/main/java/org/schabi/newpipe/local/holder/LocalBookmarkPlaylistItemHolder.java +++ b/app/src/main/java/org/schabi/newpipe/local/holder/LocalBookmarkPlaylistItemHolder.java @@ -1,9 +1,15 @@ package org.schabi.newpipe.local.holder; +import android.content.Context; +import android.content.SharedPreferences; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import androidx.preference.PreferenceManager; + +import com.marcinorlowski.fonty.Fonty; + import org.schabi.newpipe.R; import org.schabi.newpipe.database.LocalItem; import org.schabi.newpipe.database.playlist.PlaylistMetadataEntry; @@ -24,8 +30,19 @@ public LocalBookmarkPlaylistItemHolder(final LocalItemBuilder infoItemBuilder, final ViewGroup parent) { super(infoItemBuilder, layoutId, parent); itemHandleView = itemView.findViewById(R.id.itemHandle); + + final String preferredFont = getPreferredFont(itemHandleView.getContext()); + if (!preferredFont.equals("system")) { + Fonty.setFonts((ViewGroup) itemHandleView); + } + } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", "system"); } + @Override public void updateFromItem(final LocalItem localItem, final HistoryRecordManager historyRecordManager, diff --git a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java index d5ae431fadd..30b3accac1b 100644 --- a/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/playlist/LocalPlaylistFragment.java @@ -5,6 +5,7 @@ import static org.schabi.newpipe.util.ThemeHelper.shouldUseGridLayout; import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; import android.os.Parcelable; import android.text.InputType; @@ -22,10 +23,13 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; +import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.RecyclerView; import androidx.viewbinding.ViewBinding; +import com.marcinorlowski.fonty.Fonty; + import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; import org.schabi.newpipe.NewPipeDatabase; @@ -125,12 +129,21 @@ public void onCreate(final Bundle savedInstanceState) { isLoadingComplete = new AtomicBoolean(); debounceSaver = new DebounceSaver(this); } - + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", (getString(R.string.default_font_key))); + } @Override public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_playlist, container, false); + final View view = inflater.inflate(R.layout.fragment_playlist, container, false); + final String preferredFont = getPreferredFont(view.getContext()); + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts((ViewGroup) view); + } + return view; } /////////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt index fe232105913..92f398a0747 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionFragment.kt @@ -19,7 +19,9 @@ import androidx.activity.result.contract.ActivityResultContracts.StartActivityFo import androidx.annotation.StringRes import androidx.appcompat.app.AlertDialog import androidx.lifecycle.ViewModelProvider +import androidx.preference.PreferenceManager import androidx.recyclerview.widget.GridLayoutManager +import com.marcinorlowski.fonty.Fonty import com.xwray.groupie.Group import com.xwray.groupie.GroupAdapter import com.xwray.groupie.Section @@ -106,7 +108,18 @@ class SubscriptionFragment : BaseStateFragment() { } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - return inflater.inflate(R.layout.fragment_subscription, container, false) + val curView = inflater.inflate(R.layout.fragment_subscription, container, false) as ViewGroup + val preferredFont = getPreferredFont(curView.context) + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts(curView) + } + + return curView + } + fun getPreferredFont(context: Context?): String? { + val preferences = PreferenceManager + .getDefaultSharedPreferences(context!!) + return preferences.getString("preferred_font", (getString(R.string.default_font_key))) } override fun onPause() { diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionsImportFragment.java b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionsImportFragment.java index 56972b60d99..c5e1448859a 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionsImportFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/SubscriptionsImportFragment.java @@ -7,7 +7,9 @@ import static org.schabi.newpipe.local.subscription.services.SubscriptionsImportService.KEY_VALUE; import android.app.Activity; +import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import android.text.TextUtils; import android.text.util.Linkify; @@ -26,6 +28,9 @@ import androidx.annotation.StringRes; import androidx.appcompat.app.ActionBar; import androidx.core.text.util.LinkifyCompat; +import androidx.preference.PreferenceManager; + +import com.marcinorlowski.fonty.Fonty; import org.schabi.newpipe.BaseFragment; import org.schabi.newpipe.R; @@ -107,8 +112,19 @@ public void onResume() { public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final ViewGroup container, final Bundle savedInstanceState) { - return inflater.inflate(R.layout.fragment_import, container, false); + final View view = inflater.inflate(R.layout.fragment_import, container, false); + final String preferredFont = getPreferredFont(view.getContext()); + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts((ViewGroup) view); + } + return view; } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", getString(R.string.default_font_key)); + } + /*///////////////////////////////////////////////////////////////////////// // Fragment Views diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt index 41761fb0102..51058f43cf9 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupDialog.kt @@ -1,6 +1,7 @@ package org.schabi.newpipe.local.subscription.dialog import android.app.Dialog +import android.content.Context import android.os.Bundle import android.os.Parcelable import android.view.LayoutInflater @@ -16,8 +17,10 @@ import androidx.core.widget.doOnTextChanged import androidx.fragment.app.DialogFragment import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider +import androidx.preference.PreferenceManager import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView +import com.marcinorlowski.fonty.Fonty import com.xwray.groupie.GroupieAdapter import com.xwray.groupie.OnItemClickListener import com.xwray.groupie.Section @@ -89,7 +92,17 @@ class FeedGroupDialog : DialogFragment(), BackPressable { container: ViewGroup?, savedInstanceState: Bundle? ): View? { - return inflater.inflate(R.layout.dialog_feed_group_create, container) + val curView = inflater.inflate(R.layout.dialog_feed_group_create, container) as ViewGroup + val preferredFont = getPreferredFont(curView.context) + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts(curView) + } + return curView + } + fun getPreferredFont(context: Context?): String? { + val preferences = PreferenceManager + .getDefaultSharedPreferences(context!!) + return preferences.getString("preferred_font", getString(R.string.default_font_key)) } override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupReorderDialog.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupReorderDialog.kt index 1f3ab71eb62..6e03478b1f0 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupReorderDialog.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/dialog/FeedGroupReorderDialog.kt @@ -1,5 +1,6 @@ package org.schabi.newpipe.local.subscription.dialog +import android.content.Context import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -7,10 +8,12 @@ import android.view.ViewGroup import androidx.fragment.app.DialogFragment import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProvider +import androidx.preference.PreferenceManager import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper.SimpleCallback import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView +import com.marcinorlowski.fonty.Fonty import com.xwray.groupie.GroupieAdapter import com.xwray.groupie.TouchCallback import icepick.Icepick @@ -48,7 +51,18 @@ class FeedGroupReorderDialog : DialogFragment() { } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - return inflater.inflate(R.layout.dialog_feed_group_reorder, container) + val curView = (inflater.inflate(R.layout.dialog_feed_group_reorder, container)) as ViewGroup + val preferredFont = getPreferredFont(curView.context) + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts(curView) + } + + return curView + } + fun getPreferredFont(context: Context?): String? { + val preferences = PreferenceManager + .getDefaultSharedPreferences(context!!) + return preferences.getString("preferred_font", getString(R.string.default_font_key)) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { diff --git a/app/src/main/java/org/schabi/newpipe/player/PlayQueueActivity.java b/app/src/main/java/org/schabi/newpipe/player/PlayQueueActivity.java index 195baecbda8..473d1eaff6e 100644 --- a/app/src/main/java/org/schabi/newpipe/player/PlayQueueActivity.java +++ b/app/src/main/java/org/schabi/newpipe/player/PlayQueueActivity.java @@ -5,8 +5,10 @@ import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; import android.content.ComponentName; +import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; +import android.content.SharedPreferences; import android.os.Bundle; import android.os.IBinder; import android.provider.Settings; @@ -21,11 +23,13 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import com.google.android.exoplayer2.PlaybackParameters; +import com.marcinorlowski.fonty.Fonty; import org.schabi.newpipe.R; import org.schabi.newpipe.databinding.ActivityPlayerQueueControlBinding; @@ -84,6 +88,7 @@ public final class PlayQueueActivity extends AppCompatActivity @Override protected void onCreate(final Bundle savedInstanceState) { + final String preferredFont = getPreferredFont(this); assureCorrectAppLanguage(this); super.onCreate(savedInstanceState); ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this)); @@ -99,6 +104,9 @@ protected void onCreate(final Bundle savedInstanceState) { serviceConnection = getServiceConnection(); bind(); + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts(this); + } } @Override @@ -126,6 +134,12 @@ public boolean onPrepareOptionsMenu(final Menu m) { } return super.onPrepareOptionsMenu(m); } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", (getString(R.string.default_font_key))); + } + @Override public boolean onOptionsItemSelected(final MenuItem item) { diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java index ec2bed67a44..33a8dd88fdd 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java @@ -1,11 +1,13 @@ package org.schabi.newpipe.settings; import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; import android.util.Log; import android.widget.Toast; import androidx.preference.Preference; +import androidx.preference.PreferenceManager; import org.schabi.newpipe.DownloaderImpl; import org.schabi.newpipe.R; @@ -22,6 +24,7 @@ public class ContentSettingsFragment extends BasePreferenceFragment { private String youtubeRestrictedModeEnabledKey; private Localization initialSelectedLocalization; + private String initialSelectedFont; private ContentCountry initialSelectedContentCountry; private String initialLanguage; @@ -36,7 +39,9 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro initialSelectedContentCountry = org.schabi.newpipe.util.Localization .getPreferredContentCountry(requireContext()); initialLanguage = defaultPreferences.getString(getString(R.string.app_language_key), "en"); - + //saving the initial font as system default + initialSelectedFont = defaultPreferences + .getString(getString(R.string.app_font_key), getString(R.string.default_font_key)); final Preference imageQualityPreference = requirePreference(R.string.image_quality_key); imageQualityPreference.setOnPreferenceChangeListener( (preference, newValue) -> { @@ -78,7 +83,9 @@ public void onDestroy() { .getPreferredContentCountry(requireContext()); final String selectedLanguage = defaultPreferences.getString(getString(R.string.app_language_key), "en"); - + // getting the selectedFont from SharedPreference + final String selectedFont = + defaultPreferences.getString(getString(R.string.app_font_key), "Arial"); if (!selectedLocalization.equals(initialSelectedLocalization) || !selectedContentCountry.equals(initialSelectedContentCountry) || !selectedLanguage.equals(initialLanguage)) { @@ -86,6 +93,18 @@ public void onDestroy() { Toast.LENGTH_LONG).show(); NewPipe.setupLocalization(selectedLocalization, selectedContentCountry); + // checking if the font is changed from the initial + } else if ((!selectedFont.equals(initialSelectedFont))) { + // showing toast to prompt restarting app + Toast.makeText(requireContext(), R.string.font_changes_requires_app_restart, + Toast.LENGTH_LONG).show(); + + // saving the font selected into SharedPreference + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(requireContext()); + final SharedPreferences.Editor editor = preferences.edit(); + editor.putString("preferred_font", selectedFont); + editor.apply(); } } } diff --git a/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java index 9bc9058c803..c9b633453cb 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/HistorySettingsFragment.java @@ -1,12 +1,14 @@ package org.schabi.newpipe.settings; import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.preference.Preference; +import androidx.preference.PreferenceManager; import org.schabi.newpipe.DownloaderImpl; import org.schabi.newpipe.R; @@ -55,7 +57,11 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro clearCookiePref.setEnabled(false); } } - + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", (getString(R.string.default_font_key))); + } @Override public boolean onPreferenceTreeClick(final Preference preference) { if (preference.getKey().equals(cacheWipeKey)) { diff --git a/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java index 32e33d55bf6..8291670b6d7 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/MainSettingsFragment.java @@ -1,11 +1,14 @@ package org.schabi.newpipe.settings; +import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import androidx.annotation.NonNull; +import androidx.preference.PreferenceManager; import org.schabi.newpipe.MainActivity; import org.schabi.newpipe.R; @@ -58,7 +61,12 @@ public void onCreateOptionsMenu( return true; }); } - + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + // if no prefered font, return system default + return preferences.getString("preferred_font", getString(R.string.default_font_key)); + } @Override public void onDestroy() { // Unlink activity so that we don't get memory problems diff --git a/app/src/main/java/org/schabi/newpipe/settings/SelectPlaylistFragment.java b/app/src/main/java/org/schabi/newpipe/settings/SelectPlaylistFragment.java index 36abef9e5ca..a92ad4b71ea 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SelectPlaylistFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SelectPlaylistFragment.java @@ -2,6 +2,8 @@ import static org.schabi.newpipe.local.bookmark.MergedPlaylistManager.getMergedOrderedPlaylists; +import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -12,9 +14,12 @@ import androidx.annotation.NonNull; import androidx.fragment.app.DialogFragment; +import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.marcinorlowski.fonty.Fonty; + import org.schabi.newpipe.NewPipeDatabase; import org.schabi.newpipe.R; import org.schabi.newpipe.database.AppDatabase; @@ -146,8 +151,18 @@ public SelectPlaylistItemHolder onCreateViewHolder(final ViewGroup parent, final int viewType) { final View item = LayoutInflater.from(parent.getContext()) .inflate(R.layout.list_playlist_mini_item, parent, false); + final String preferredFont = getPreferredFont(item.getContext()); + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts((ViewGroup) item); + } return new SelectPlaylistItemHolder(item); } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", (getString(R.string.default_font_key))); + } + @Override public void onBindViewHolder(@NonNull final SelectPlaylistItemHolder holder, diff --git a/app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java b/app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java index 529e5344220..c8e3c166b39 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java @@ -3,6 +3,7 @@ import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage; import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; import android.text.TextUtils; import android.util.Log; @@ -20,8 +21,10 @@ import androidx.fragment.app.FragmentManager; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; +import androidx.preference.PreferenceManager; import com.jakewharton.rxbinding4.widget.RxTextView; +import com.marcinorlowski.fonty.Fonty; import org.schabi.newpipe.MainActivity; import org.schabi.newpipe.R; @@ -89,6 +92,7 @@ public class SettingsActivity extends AppCompatActivity implements @Override protected void onCreate(final Bundle savedInstanceBundle) { + setTheme(ThemeHelper.getSettingsThemeStyle(this)); assureCorrectAppLanguage(this); @@ -120,6 +124,10 @@ protected void onCreate(final Bundle savedInstanceBundle) { if (DeviceUtils.isTv(this)) { FocusOverlayView.setupFocusObserver(this); } + final String preferredFont = getPreferredFont(this); + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts(this); + } } @Override @@ -257,6 +265,12 @@ private void initSearch( } searchFragment.setSearcher(searcher); } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", (getString(R.string.default_font_key))); + } + /** * Ensures that the search shows the correct/available search results. diff --git a/app/src/main/java/org/schabi/newpipe/util/FilePickerActivityHelper.java b/app/src/main/java/org/schabi/newpipe/util/FilePickerActivityHelper.java index d7fb3965116..a8597d1022d 100644 --- a/app/src/main/java/org/schabi/newpipe/util/FilePickerActivityHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/FilePickerActivityHelper.java @@ -1,6 +1,7 @@ package org.schabi.newpipe.util; import android.content.Context; +import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; import android.os.Environment; @@ -14,9 +15,11 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.loader.content.Loader; +import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.SortedList; +import com.marcinorlowski.fonty.Fonty; import com.nononsenseapps.filepicker.AbstractFilePickerFragment; import com.nononsenseapps.filepicker.FilePickerFragment; @@ -36,12 +39,17 @@ public static boolean isOwnFileUri(@NonNull final Context context, @NonNull fina @Override public void onCreate(final Bundle savedInstanceState) { + final String preferredFont = getPreferredFont(this); if (ThemeHelper.isLightThemeSelected(this)) { this.setTheme(R.style.FilePickerThemeLight); } else { this.setTheme(R.style.FilePickerThemeDark); } super.onCreate(savedInstanceState); + + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts(this); + } } @Override @@ -54,6 +62,13 @@ public void onBackPressed() { currentFragment.goUp(); } } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", (getString(R.string.default_font_key))); + } + + @Override protected AbstractFilePickerFragment getFragment(@Nullable final String startPath, diff --git a/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java b/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java index 45211211f40..0e2c74dde2d 100755 --- a/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java +++ b/app/src/main/java/us/shandian/giga/service/DownloadManagerService.java @@ -129,6 +129,7 @@ private void notifyMediaScanner(Uri file) { @Override public void onCreate() { + super.onCreate(); if (DEBUG) { diff --git a/app/src/main/java/us/shandian/giga/ui/common/ToolbarActivity.java b/app/src/main/java/us/shandian/giga/ui/common/ToolbarActivity.java index 1542d3ff0be..bc8578377d6 100644 --- a/app/src/main/java/us/shandian/giga/ui/common/ToolbarActivity.java +++ b/app/src/main/java/us/shandian/giga/ui/common/ToolbarActivity.java @@ -1,9 +1,14 @@ package us.shandian.giga.ui.common; +import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; +import androidx.preference.PreferenceManager; + +import com.marcinorlowski.fonty.Fonty; import org.schabi.newpipe.R; @@ -12,13 +17,24 @@ public abstract class ToolbarActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { + final String preferredFont = getPreferredFont(this); super.onCreate(savedInstanceState); setContentView(getLayoutResource()); mToolbar = this.findViewById(R.id.toolbar); setSupportActionBar(mToolbar); + + if (!preferredFont.equals(getString(R.string.default_font_key))) { + Fonty.setFonts(this); + } } + public String getPreferredFont(final Context context) { + final SharedPreferences preferences = PreferenceManager + .getDefaultSharedPreferences(context); + return preferences.getString("preferred_font", (getString(R.string.default_font_key))); + } + protected abstract int getLayoutResource(); } diff --git a/app/src/main/res/layout-land/list_stream_card_item.xml b/app/src/main/res/layout-land/list_stream_card_item.xml deleted file mode 120000 index 70228ee1d20..00000000000 --- a/app/src/main/res/layout-land/list_stream_card_item.xml +++ /dev/null @@ -1 +0,0 @@ -../layout/list_stream_item.xml \ No newline at end of file diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index fb68a464d5a..65936c6dd78 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -354,6 +354,8 @@ app_language_key + app_font_key + feed_update_threshold_key 300 feed_show_played_items @@ -502,6 +504,10 @@ system + + system + preferred_font + @string/default_localization_key @@ -1343,6 +1349,29 @@ 正體中文 + + + + + @string/default_localization_key + Calibri + Algerian + Broadway + Arial + Bell MT + Time New Roman + + + @string/systems_font + Calibri + Algerian + Broadway + Arial + Bell MT + Time New Roman + + + limit_mobile_data_usage limit_data_usage_none diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 56140441cd0..decc894d247 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -411,6 +411,7 @@ Do you want to also import settings? Could not load comments The language will change once the app is restarted + The font will change once the app is restarted Trending Top 50 @@ -658,6 +659,9 @@ Choose an instance App language System default + System default + App font + Remove watched Remove watched videos? Remove duplicates diff --git a/app/src/main/res/xml/content_settings.xml b/app/src/main/res/xml/content_settings.xml index 2cdc6c545c9..9aefaf9bc9a 100644 --- a/app/src/main/res/xml/content_settings.xml +++ b/app/src/main/res/xml/content_settings.xml @@ -33,6 +33,16 @@ app:iconSpaceReserved="false" app:useSimpleSummaryProvider="true" /> + +