Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to change font feature #11645

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -103,6 +107,10 @@ android {
'META-INF/COPYRIGHT']
}
}

buildFeatures {
aidl true
}
}

ext {
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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"

Expand Down
Binary file added app/src/main/assets/fonts/Algerian.TTF
Binary file not shown.
Binary file added app/src/main/assets/fonts/BELL.TTF
Binary file not shown.
Binary file added app/src/main/assets/fonts/BROADW.TTF
Binary file not shown.
Binary file added app/src/main/assets/fonts/arial.ttf
Binary file not shown.
Binary file added app/src/main/assets/fonts/calibrii.ttf
Binary file not shown.
Binary file added app/src/main/assets/fonts/times.ttf
Binary file not shown.
1 change: 1 addition & 0 deletions app/src/main/java/org/schabi/newpipe/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public void onCreate() {
configureRxJavaErrorHandler();
}


@Override
public void onTerminate() {
super.onTerminate();
Expand Down
55 changes: 54 additions & 1 deletion app/src/main/java/org/schabi/newpipe/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 + "]");
Expand Down Expand Up @@ -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);

Expand All @@ -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();
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/org/schabi/newpipe/RouterActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/org/schabi/newpipe/about/AboutActivity.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down
20 changes: 16 additions & 4 deletions app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<AudioStream, Stream> audioStreamsAdapter;
private StreamItemAdapter<VideoStream, AudioStream> videoStreamsAdapter;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/org/schabi/newpipe/error/ErrorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
Loading
Loading