Skip to content

Commit

Permalink
Merge 'up-10/change-font-feature' into branch
Browse files Browse the repository at this point in the history
  • Loading branch information
asandikci committed Dec 5, 2024
2 parents 9232dcc + cfb58dc commit 7c550ed
Show file tree
Hide file tree
Showing 56 changed files with 842 additions and 78 deletions.
8 changes: 8 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ android {
// Disables dependency metadata when building Android App Bundles.
includeInBundle = false
}

buildFeatures {
aidl true // REVIEW up-10
}
}

ext {
Expand Down Expand Up @@ -255,6 +259,10 @@ dependencies {
implementation "com.evernote:android-state:$stateSaverVersion"
kapt "com.evernote:android-state-processor:$stateSaverVersion"

// 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 @@ -120,6 +120,7 @@ public void onCreate() {
configureRxJavaErrorHandler();
}


@Override
public void onTerminate() {
super.onTerminate();
Expand Down
54 changes: 53 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,50 @@ 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));
}

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
12 changes: 12 additions & 0 deletions app/src/main/java/org/schabi/newpipe/RouterActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import com.evernote.android.state.State;
import com.livefront.bridge.Bridge;
import com.marcinorlowski.fonty.Fonty; // REVIEW up-10

import org.schabi.newpipe.database.stream.model.StreamEntity;
import org.schabi.newpipe.databinding.ListRadioIconItemBinding;
Expand Down Expand Up @@ -129,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 @@ -184,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 @@ -41,6 +41,7 @@

import com.evernote.android.state.State;
import com.livefront.bridge.Bridge;
import com.marcinorlowski.fonty.Fonty; // REVIEW up-10
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
14 changes: 14 additions & 0 deletions app/src/main/java/org/schabi/newpipe/error/ReCaptchaActivity.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);

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

0 comments on commit 7c550ed

Please sign in to comment.