mirror of
https://github.com/MaintainTeam/LastPipeBender.git
synced 2025-02-28 21:38:20 +03:00
chore: Font Manager
This commit is contained in:
parent
77028cc378
commit
e2f7aba57f
3 changed files with 69 additions and 51 deletions
|
@ -20,6 +20,7 @@ import org.schabi.newpipe.extractor.downloader.Downloader;
|
|||
import org.schabi.newpipe.ktx.ExceptionUtils;
|
||||
import org.schabi.newpipe.settings.NewPipeSettings;
|
||||
import org.schabi.newpipe.util.BridgeStateSaverInitializer;
|
||||
import org.schabi.newpipe.util.FontManager;
|
||||
import org.schabi.newpipe.util.Localization;
|
||||
import org.schabi.newpipe.util.ServiceHelper;
|
||||
import org.schabi.newpipe.util.StateSaver;
|
||||
|
@ -102,6 +103,7 @@ public class App extends Application {
|
|||
Localization.getPreferredContentCountry(this));
|
||||
Localization.initPrettyTime(Localization.resolvePrettyTime(getApplicationContext()));
|
||||
|
||||
FontManager.init(this);
|
||||
BridgeStateSaverInitializer.init(this);
|
||||
StateSaver.init(this);
|
||||
initNotificationChannels();
|
||||
|
|
|
@ -176,13 +176,9 @@ public class MainActivity extends AppCompatActivity {
|
|||
UpdateSettingsFragment.askForConsentToUpdateChecks(this);
|
||||
}
|
||||
|
||||
// Apply the preferred font globally
|
||||
final String preferredFont = getPreferredFont(this);
|
||||
setUpFont(preferredFont);
|
||||
|
||||
if (!preferredFont.equals(getString(R.string.default_font_key))) {
|
||||
// if (!preferredFont.equals(getString(R.string.default_font_key))) {
|
||||
Fonty.setFonts(this);
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -199,51 +195,6 @@ public class MainActivity extends AppCompatActivity {
|
|||
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();
|
||||
|
|
65
app/src/main/java/org/schabi/newpipe/util/FontManager.java
Normal file
65
app/src/main/java/org/schabi/newpipe/util/FontManager.java
Normal file
|
@ -0,0 +1,65 @@
|
|||
package org.schabi.newpipe.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import com.marcinorlowski.fonty.Fonty;
|
||||
import org.schabi.newpipe.R;
|
||||
|
||||
|
||||
public final class FontManager {
|
||||
private FontManager() { }
|
||||
|
||||
public static void init(final Context context) {
|
||||
// Apply the preferred font globally
|
||||
final String preferredFont = getPreferredFont(context);
|
||||
|
||||
setUpFont(preferredFont, context);
|
||||
}
|
||||
|
||||
public static 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 static void setUpFont(final String preferredFont, final Context context) {
|
||||
switch (preferredFont) {
|
||||
case "Arial":
|
||||
Fonty.context(context)
|
||||
.normalTypeface("arial.ttf")
|
||||
.build();
|
||||
break;
|
||||
case "Broadway":
|
||||
Fonty.context(context)
|
||||
.normalTypeface("BROADW.TTF")
|
||||
.build();
|
||||
break;
|
||||
case "Algerian":
|
||||
Fonty.context(context)
|
||||
.normalTypeface("Algerian.TTF")
|
||||
.build();
|
||||
break;
|
||||
case "Bell MT":
|
||||
Fonty.context(context)
|
||||
.normalTypeface("BELL.TTF")
|
||||
.build();
|
||||
break;
|
||||
case "Calibri":
|
||||
Fonty.context(context)
|
||||
.normalTypeface("calibrii.ttf")
|
||||
.build();
|
||||
break;
|
||||
case "Time New Roman":
|
||||
Fonty.context(context)
|
||||
.normalTypeface("times.ttf")
|
||||
.build();
|
||||
break;
|
||||
default:
|
||||
// do nothing
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue