mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-06-07 23:27:50 +00:00
Switch to AboutLibraries for the third-party license list
The previous library we were using is unmaintained and can't be customized to match the Material 3 theme.
This commit is contained in:
parent
8001ecb482
commit
60c72d48ee
19 changed files with 4020 additions and 375 deletions
|
@ -0,0 +1,55 @@
|
|||
package com.beemdevelopment.aegis.helpers;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.beemdevelopment.aegis.Preferences;
|
||||
import com.beemdevelopment.aegis.R;
|
||||
import com.beemdevelopment.aegis.Theme;
|
||||
import com.google.android.material.color.DynamicColors;
|
||||
import com.google.android.material.color.DynamicColorsOptions;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ThemeHelper {
|
||||
private final AppCompatActivity _activity;
|
||||
private final Preferences _prefs;
|
||||
|
||||
public ThemeHelper(AppCompatActivity activity, Preferences prefs) {
|
||||
_activity = activity;
|
||||
_prefs = prefs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the theme of the activity. The actual style that is set is picked from the
|
||||
* given map, based on the theme configured by the user.
|
||||
*/
|
||||
public void setTheme(Map<Theme, Integer> themeMap) {
|
||||
int theme = themeMap.get(getConfiguredTheme());
|
||||
_activity.setTheme(theme);
|
||||
|
||||
if (_prefs.isDynamicColorsEnabled()) {
|
||||
DynamicColorsOptions.Builder optsBuilder = new DynamicColorsOptions.Builder();
|
||||
if (getConfiguredTheme().equals(Theme.AMOLED)) {
|
||||
optsBuilder.setThemeOverlay(R.style.ThemeOverlay_Aegis_Dynamic_Amoled);
|
||||
}
|
||||
DynamicColors.applyToActivityIfAvailable(_activity, optsBuilder.build());
|
||||
}
|
||||
}
|
||||
|
||||
public Theme getConfiguredTheme() {
|
||||
Theme theme = _prefs.getCurrentTheme();
|
||||
|
||||
if (theme == Theme.SYSTEM || theme == Theme.SYSTEM_AMOLED) {
|
||||
int currentNightMode = _activity.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
|
||||
if (currentNightMode == Configuration.UI_MODE_NIGHT_YES) {
|
||||
theme = theme == Theme.SYSTEM_AMOLED ? Theme.AMOLED : Theme.DARK;
|
||||
} else {
|
||||
theme = Theme.LIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
return theme;
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package com.beemdevelopment.aegis.licenses;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.beemdevelopment.aegis.R;
|
||||
|
||||
import de.psdev.licensesdialog.licenses.License;
|
||||
|
||||
public class GlideLicense extends License {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Glide License";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readSummaryTextFromResources(Context context) {
|
||||
return getContent(context, R.raw.glide_license);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readFullTextFromResources(Context context) {
|
||||
return getContent(context, R.raw.glide_license);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl() {
|
||||
return "https://github.com/bumptech/glide/blob/master/LICENSE";
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package com.beemdevelopment.aegis.licenses;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.beemdevelopment.aegis.R;
|
||||
|
||||
import de.psdev.licensesdialog.licenses.License;
|
||||
|
||||
public class ProtobufLicense extends License {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Protocol Buffers License";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readSummaryTextFromResources(Context context) {
|
||||
return getContent(context, R.raw.protobuf_license);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String readFullTextFromResources(Context context) {
|
||||
return getContent(context, R.raw.protobuf_license);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl() {
|
||||
return "https://raw.githubusercontent.com/protocolbuffers/protobuf/master/LICENSE";
|
||||
}
|
||||
}
|
|
@ -16,15 +16,10 @@ import androidx.annotation.StringRes;
|
|||
|
||||
import com.beemdevelopment.aegis.BuildConfig;
|
||||
import com.beemdevelopment.aegis.R;
|
||||
import com.beemdevelopment.aegis.licenses.GlideLicense;
|
||||
import com.beemdevelopment.aegis.licenses.ProtobufLicense;
|
||||
import com.beemdevelopment.aegis.ui.dialogs.ChangelogDialog;
|
||||
import com.beemdevelopment.aegis.ui.dialogs.LicenseDialog;
|
||||
import com.google.android.material.color.MaterialColors;
|
||||
|
||||
import de.psdev.licensesdialog.LicenseResolver;
|
||||
import de.psdev.licensesdialog.LicensesDialog;
|
||||
|
||||
public class AboutActivity extends AegisActivity {
|
||||
|
||||
private static String GITHUB = "https://github.com/beemdevelopment/Aegis";
|
||||
|
@ -53,12 +48,15 @@ public class AboutActivity extends AegisActivity {
|
|||
View btnLicense = findViewById(R.id.btn_license);
|
||||
btnLicense.setOnClickListener(v -> {
|
||||
LicenseDialog.create()
|
||||
.setTheme(getConfiguredTheme())
|
||||
.setTheme(_themeHelper.getConfiguredTheme())
|
||||
.show(getSupportFragmentManager(), null);
|
||||
});
|
||||
|
||||
View btnThirdPartyLicenses = findViewById(R.id.btn_third_party_licenses);
|
||||
btnThirdPartyLicenses.setOnClickListener(v -> showThirdPartyLicenseDialog());
|
||||
btnThirdPartyLicenses.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(this, LicensesActivity.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
TextView appVersion = findViewById(R.id.app_version);
|
||||
appVersion.setText(getCurrentAppVersion());
|
||||
|
@ -89,7 +87,7 @@ public class AboutActivity extends AegisActivity {
|
|||
View btnChangelog = findViewById(R.id.btn_changelog);
|
||||
btnChangelog.setOnClickListener(v -> {
|
||||
ChangelogDialog.create()
|
||||
.setTheme(getConfiguredTheme())
|
||||
.setTheme(_themeHelper.getConfiguredTheme())
|
||||
.show(getSupportFragmentManager(), null);
|
||||
});
|
||||
}
|
||||
|
@ -126,27 +124,6 @@ public class AboutActivity extends AegisActivity {
|
|||
startActivity(Intent.createChooser(mailIntent, getString(R.string.email)));
|
||||
}
|
||||
|
||||
private void showThirdPartyLicenseDialog() {
|
||||
String stylesheet = getString(R.string.custom_notices_format_style);
|
||||
String backgroundColor = getThemeColorAsHex(com.google.android.material.R.attr.colorSurfaceContainerLow);
|
||||
String textColor = getThemeColorAsHex(com.google.android.material.R.attr.colorOnSurface);
|
||||
String licenseColor = getThemeColorAsHex(com.google.android.material.R.attr.colorSurfaceContainerLow);
|
||||
String linkColor = getThemeColorAsHex(com.google.android.material.R.attr.colorAccent);
|
||||
|
||||
stylesheet = String.format(stylesheet, backgroundColor, textColor, licenseColor, linkColor);
|
||||
|
||||
LicenseResolver.registerLicense(new GlideLicense());
|
||||
LicenseResolver.registerLicense(new ProtobufLicense());
|
||||
|
||||
new LicensesDialog.Builder(this)
|
||||
.setNotices(R.raw.notices)
|
||||
.setTitle(R.string.third_party_licenses)
|
||||
.setNoticesCssStyle(stylesheet)
|
||||
.setIncludeOwnLicense(true)
|
||||
.build()
|
||||
.show();
|
||||
}
|
||||
|
||||
private String getThemeColorAsHex(@AttrRes int attributeId) {
|
||||
int color = MaterialColors.getColor(this, attributeId, getClass().getCanonicalName());
|
||||
return String.format("%06X", 0xFFFFFF & color);
|
||||
|
|
|
@ -20,20 +20,17 @@ import androidx.core.view.ViewPropertyAnimatorCompat;
|
|||
|
||||
import com.beemdevelopment.aegis.Preferences;
|
||||
import com.beemdevelopment.aegis.R;
|
||||
import com.beemdevelopment.aegis.Theme;
|
||||
import com.beemdevelopment.aegis.ThemeMap;
|
||||
import com.beemdevelopment.aegis.helpers.ThemeHelper;
|
||||
import com.beemdevelopment.aegis.icons.IconPackManager;
|
||||
import com.beemdevelopment.aegis.vault.VaultManager;
|
||||
import com.beemdevelopment.aegis.vault.VaultRepositoryException;
|
||||
import com.google.android.material.color.DynamicColors;
|
||||
import com.google.android.material.color.DynamicColorsOptions;
|
||||
import com.google.android.material.color.MaterialColors;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
@ -46,6 +43,7 @@ import dagger.hilt.components.SingletonComponent;
|
|||
@AndroidEntryPoint
|
||||
public abstract class AegisActivity extends AppCompatActivity implements VaultManager.LockListener {
|
||||
protected Preferences _prefs;
|
||||
protected ThemeHelper _themeHelper;
|
||||
|
||||
@Inject
|
||||
protected VaultManager _vaultManager;
|
||||
|
@ -59,6 +57,7 @@ public abstract class AegisActivity extends AppCompatActivity implements VaultMa
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
// set the theme and locale before creating the activity
|
||||
_prefs = EarlyEntryPoints.get(getApplicationContext(), PrefEntryPoint.class).getPreferences();
|
||||
_themeHelper = new ThemeHelper(this, _prefs);
|
||||
onSetTheme();
|
||||
setLocale(_prefs.getLocale());
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -111,39 +110,7 @@ public abstract class AegisActivity extends AppCompatActivity implements VaultMa
|
|||
* Called when the activity is expected to set its theme.
|
||||
*/
|
||||
protected void onSetTheme() {
|
||||
setTheme(ThemeMap.DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the theme of the activity. The actual style that is set is picked from the
|
||||
* given map, based on the theme configured by the user.
|
||||
*/
|
||||
protected void setTheme(Map<Theme, Integer> themeMap) {
|
||||
int theme = themeMap.get(getConfiguredTheme());
|
||||
setTheme(theme);
|
||||
|
||||
if (_prefs.isDynamicColorsEnabled()) {
|
||||
DynamicColorsOptions.Builder optsBuilder = new DynamicColorsOptions.Builder();
|
||||
if (getConfiguredTheme().equals(Theme.AMOLED)) {
|
||||
optsBuilder.setThemeOverlay(R.style.ThemeOverlay_Aegis_Dynamic_Amoled);
|
||||
}
|
||||
DynamicColors.applyToActivityIfAvailable(this, optsBuilder.build());
|
||||
}
|
||||
}
|
||||
|
||||
protected Theme getConfiguredTheme() {
|
||||
Theme theme = _prefs.getCurrentTheme();
|
||||
|
||||
if (theme == Theme.SYSTEM || theme == Theme.SYSTEM_AMOLED) {
|
||||
int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
|
||||
if (currentNightMode == Configuration.UI_MODE_NIGHT_YES) {
|
||||
theme = theme == Theme.SYSTEM_AMOLED ? Theme.AMOLED : Theme.DARK;
|
||||
} else {
|
||||
theme = Theme.LIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
return theme;
|
||||
_themeHelper.setTheme(ThemeMap.DEFAULT);
|
||||
}
|
||||
|
||||
protected void setLocale(Locale locale) {
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
package com.beemdevelopment.aegis.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.beemdevelopment.aegis.Preferences;
|
||||
import com.beemdevelopment.aegis.R;
|
||||
import com.beemdevelopment.aegis.ThemeMap;
|
||||
import com.beemdevelopment.aegis.helpers.ThemeHelper;
|
||||
import com.mikepenz.aboutlibraries.LibsBuilder;
|
||||
import com.mikepenz.aboutlibraries.ui.LibsActivity;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import dagger.hilt.InstallIn;
|
||||
import dagger.hilt.android.EarlyEntryPoint;
|
||||
import dagger.hilt.android.EarlyEntryPoints;
|
||||
import dagger.hilt.components.SingletonComponent;
|
||||
|
||||
public class LicensesActivity extends LibsActivity {
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
LibsBuilder builder = new LibsBuilder()
|
||||
.withSearchEnabled(true)
|
||||
.withAboutMinimalDesign(true)
|
||||
.withActivityTitle(getString(R.string.title_activity_licenses));
|
||||
setIntent(builder.intent(this));
|
||||
|
||||
Preferences _prefs = EarlyEntryPoints.get(getApplicationContext(), PrefEntryPoint.class).getPreferences();
|
||||
ThemeHelper themeHelper = new ThemeHelper(this, _prefs);
|
||||
themeHelper.setTheme(ThemeMap.DEFAULT);
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@EarlyEntryPoint
|
||||
@InstallIn(SingletonComponent.class)
|
||||
public interface PrefEntryPoint {
|
||||
Preferences getPreferences();
|
||||
}
|
||||
}
|
|
@ -89,7 +89,7 @@ public class ScannerActivity extends AegisActivity implements QrCodeAnalyzer.Lis
|
|||
|
||||
@Override
|
||||
protected void onSetTheme() {
|
||||
setTheme(ThemeMap.FULLSCREEN);
|
||||
_themeHelper.setTheme(ThemeMap.FULLSCREEN);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -152,7 +152,7 @@ public class TransferEntriesActivity extends AegisActivity {
|
|||
_entriesCount.setText(getResources().getQuantityString(R.plurals.qr_count, _authInfos.size(), _currentEntryCount, _authInfos.size()));
|
||||
|
||||
@ColorInt int backgroundColor = Color.WHITE;
|
||||
if (getConfiguredTheme() == Theme.LIGHT) {
|
||||
if (_themeHelper.getConfiguredTheme() == Theme.LIGHT) {
|
||||
TypedValue typedValue = new TypedValue();
|
||||
getTheme().resolveAttribute(androidx.appcompat.R.attr.background, typedValue, true);
|
||||
backgroundColor = typedValue.data;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue