Commit 774a73c6 authored by Thomas's avatar Thomas
Browse files

Fix #566 #565 #564

parent e1e5284a
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -288,15 +288,15 @@
            android:name=".activities.InstanceActivity"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:label="@string/action_about_instance"
            android:theme="@style/AlertDialog" />
            android:theme="@style/AppThemeAlertDialog" />
        <activity
            android:name=".activities.InstanceProfileActivity"
            android:excludeFromRecents="true"
            android:theme="@style/AlertDialog" />
            android:theme="@style/AppThemeAlertDialog" />
        <activity
            android:name=".activities.ProxyActivity"
            android:excludeFromRecents="true"
            android:theme="@style/AlertDialog" />
            android:theme="@style/AppThemeAlertDialog" />
        <activity
            android:name=".activities.HashTagActivity"
            android:configChanges="keyboardHidden|orientation|screenSize" />
@@ -306,12 +306,12 @@
        <activity
            android:name=".activities.MediaActivity"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:theme="@style/TransparentDark" />
            android:theme="@style/Transparent" />

        <activity
            android:name=".activities.InstanceHealthActivity"
            android:excludeFromRecents="true"
            android:theme="@style/AlertDialog" />
            android:theme="@style/AppThemeAlertDialog" />

        <activity
            android:name=".activities.ReportActivity"
+15 −1
Original line number Diff line number Diff line
@@ -16,8 +16,10 @@ package app.fedilab.android.activities;


import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.Nullable;
@@ -102,8 +104,20 @@ public class BaseActivity extends AppCompatActivity {
            }
        }
        super.onCreate(savedInstanceState);
        if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) {
            ThemeHelper.adjustFontScale(this, getResources().getConfiguration());
        }
        Helper.setLocale(this);
    }

    @Override
    protected void attachBaseContext(Context newBase) {
        if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {
            final Configuration override = new Configuration(newBase.getResources().getConfiguration());
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(newBase);
            override.fontScale = prefs.getFloat(newBase.getString(R.string.SET_FONT_SCALE), 1.1f);
            applyOverrideConfiguration(override);
        }
        super.attachBaseContext(newBase);
    }
}
+123 −0
Original line number Diff line number Diff line
package app.fedilab.android.activities;
/* Copyright 2021 Thomas Schneider
 *
 * This file is a part of Fedilab
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation; either version 3 of the
 * License, or (at your option) any later version.
 *
 * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 * Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with Fedilab; if not,
 * see <http://www.gnu.org/licenses>. */


import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.preference.PreferenceManager;

import com.vanniktech.emoji.EmojiManager;
import com.vanniktech.emoji.one.EmojiOneProvider;

import app.fedilab.android.R;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;


@SuppressLint("Registered")
public class BaseAlertDialogActivity extends AppCompatActivity {

    static {
        Helper.installProvider();
        EmojiManager.install(new EmojiOneProvider());
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {

        final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this);
        String currentTheme = sharedpreferences.getString(getString(R.string.SET_THEME_BASE), getString(R.string.SET_DEFAULT_THEME));
        //Default automatic switch
        if (currentTheme.equals(getString(R.string.SET_DEFAULT_THEME))) {

            int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
            switch (currentNightMode) {
                case Configuration.UI_MODE_NIGHT_NO:
                    String defaultLight = sharedpreferences.getString(getString(R.string.SET_THEME_DEFAULT_LIGHT), "LIGHT");
                    switch (defaultLight) {
                        case "LIGHT":
                            setTheme(R.style.AppThemeAlertDialog);
                            break;
                        case "SOLARIZED_LIGHT":
                            setTheme(R.style.SolarizedAlertDialog);
                            break;
                    }
                    break;
                case Configuration.UI_MODE_NIGHT_YES:
                    String defaultDark = sharedpreferences.getString(getString(R.string.SET_THEME_DEFAULT_DARK), "DARK");
                    switch (defaultDark) {
                        case "DARK":
                            setTheme(R.style.AppThemeAlertDialog);
                            break;
                        case "SOLARIZED_DARK":
                            setTheme(R.style.SolarizedAlertDialog);
                            break;
                        case "BLACK":
                            setTheme(R.style.BlackAlertDialog);
                            break;
                    }
                    break;
            }
        } else {
            switch (currentTheme) {
                case "LIGHT":
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
                    setTheme(R.style.AppThemeAlertDialog);
                    break;
                case "DARK":
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
                    setTheme(R.style.AppThemeAlertDialog);
                    break;
                case "SOLARIZED_LIGHT":
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
                    setTheme(R.style.SolarizedAlertDialog);
                    break;
                case "SOLARIZED_DARK":
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
                    setTheme(R.style.SolarizedAlertDialog);
                    break;
                case "BLACK":
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
                    setTheme(R.style.BlackAlertDialog);
                    break;
            }
        }
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) {
            ThemeHelper.adjustFontScale(this, getResources().getConfiguration());
        }
        Helper.setLocale(this);
    }

    @Override
    protected void attachBaseContext(Context newBase) {
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {
            final Configuration override = new Configuration(newBase.getResources().getConfiguration());
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(newBase);
            override.fontScale = prefs.getFloat(newBase.getString(R.string.SET_FONT_SCALE), 1.1f);
            applyOverrideConfiguration(override);
        }
        super.attachBaseContext(newBase);
    }
}
+18 −1
Original line number Diff line number Diff line
@@ -16,8 +16,10 @@ package app.fedilab.android.activities;


import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.Nullable;
@@ -102,8 +104,23 @@ public class BaseBarActivity extends AppCompatActivity {
            }
        }
        super.onCreate(savedInstanceState);
        if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) {
            ThemeHelper.adjustFontScale(this, getResources().getConfiguration());
        }
        Helper.setLocale(this);
    }

    @Override
    protected void attachBaseContext(Context newBase) {

        if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {
            final Configuration override = new Configuration(newBase.getResources().getConfiguration());
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(newBase);
            override.fontScale = prefs.getFloat(newBase.getString(R.string.SET_FONT_SCALE), 1.1f);
            applyOverrideConfiguration(override);
        }


        super.attachBaseContext(newBase);
    }
}
+126 −0
Original line number Diff line number Diff line
package app.fedilab.android.activities;
/* Copyright 2022 Thomas Schneider
 *
 * This file is a part of Fedilab
 *
 * This program is free software; you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation; either version 3 of the
 * License, or (at your option) any later version.
 *
 * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
 * Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with Fedilab; if not,
 * see <http://www.gnu.org/licenses>. */


import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.preference.PreferenceManager;

import com.vanniktech.emoji.EmojiManager;
import com.vanniktech.emoji.one.EmojiOneProvider;

import app.fedilab.android.R;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.helper.ThemeHelper;


@SuppressLint("Registered")
public class BaseTransparentActivity extends AppCompatActivity {

    static {
        Helper.installProvider();
        EmojiManager.install(new EmojiOneProvider());
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this);
        String currentTheme = sharedpreferences.getString(getString(R.string.SET_THEME_BASE), getString(R.string.SET_DEFAULT_THEME));
        //Default automatic switch
        if (currentTheme.equals(getString(R.string.SET_DEFAULT_THEME))) {

            int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
            switch (currentNightMode) {
                case Configuration.UI_MODE_NIGHT_NO:
                    String defaultLight = sharedpreferences.getString(getString(R.string.SET_THEME_DEFAULT_LIGHT), "LIGHT");
                    switch (defaultLight) {
                        case "LIGHT":
                            setTheme(R.style.Transparent);
                            break;
                        case "SOLARIZED_LIGHT":
                            setTheme(R.style.TransparentSolarized);
                            break;
                    }
                    break;
                case Configuration.UI_MODE_NIGHT_YES:
                    String defaultDark = sharedpreferences.getString(getString(R.string.SET_THEME_DEFAULT_DARK), "DARK");
                    switch (defaultDark) {
                        case "DARK":
                            setTheme(R.style.Transparent);
                            break;
                        case "SOLARIZED_DARK":
                            setTheme(R.style.TransparentSolarized);
                            break;
                        case "BLACK":
                            setTheme(R.style.TransparentBlack);
                            break;
                    }
                    break;
            }

        } else {
            switch (currentTheme) {
                case "LIGHT":
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
                    setTheme(R.style.Transparent);
                    break;
                case "DARK":
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
                    setTheme(R.style.Transparent);
                    break;
                case "SOLARIZED_LIGHT":
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
                    setTheme(R.style.TransparentSolarized);
                    break;
                case "SOLARIZED_DARK":
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
                    setTheme(R.style.TransparentSolarized);
                    break;
                case "BLACK":
                    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
                    setTheme(R.style.TransparentBlack);
                    break;
            }
        }
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) {
            ThemeHelper.adjustFontScale(this, getResources().getConfiguration());
        }
        Helper.setLocale(this);
    }

    @Override
    protected void attachBaseContext(Context newBase) {

        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {
            final Configuration override = new Configuration(newBase.getResources().getConfiguration());
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(newBase);
            override.fontScale = prefs.getFloat(newBase.getString(R.string.SET_FONT_SCALE), 1.1f);
            applyOverrideConfiguration(override);
        }


        super.attachBaseContext(newBase);
    }
}
Loading