Skip to content

Commit 60c72d4

Browse files
committed
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.
1 parent 8001ecb commit 60c72d4

19 files changed

+4020
-375
lines changed

app/build.gradle

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
apply plugin: 'com.android.application'
22
apply plugin: 'com.google.protobuf'
33
apply plugin: 'dagger.hilt.android.plugin'
4+
apply plugin: 'com.mikepenz.aboutlibraries.plugin'
45

56
def getCmdOutput = { cmd ->
67
def stdout = new ByteArrayOutputStream()
@@ -120,6 +121,17 @@ protobuf {
120121
}
121122
}
122123

124+
aboutLibraries {
125+
// Tasks for aboutLibraries are not run automatically to keep the build reproducible
126+
// To update manually: ./gradlew app:exportLibraryDefinitions -PaboutLibraries.exportPath=src/main/res/raw
127+
prettyPrint = true
128+
configPath = "app/config"
129+
fetchRemoteFunding = false
130+
registerAndroidTasks = false
131+
exclusionPatterns = [~"javax.annotation.*"]
132+
duplicationMode = com.mikepenz.aboutlibraries.plugin.DuplicateMode.MERGE
133+
}
134+
123135
dependencies {
124136
def cameraxVersion = '1.3.1'
125137
def glideVersion = '4.16.0'
@@ -161,9 +173,12 @@ dependencies {
161173
implementation 'com.google.android.material:material:1.11.0'
162174
implementation 'com.google.protobuf:protobuf-javalite:3.25.1'
163175
implementation 'com.google.zxing:core:3.5.2'
176+
implementation("com.mikepenz:aboutlibraries:11.1.0") {
177+
exclude group: 'com.mikepenz', module: 'aboutlibraries-core'
178+
}
179+
implementation "com.mikepenz:aboutlibraries-core-android:11.1.0"
164180
implementation 'com.nulab-inc:zxcvbn:1.8.2'
165181
implementation 'de.hdodenhof:circleimageview:3.1.0'
166-
implementation 'de.psdev.licensesdialog:licensesdialog:2.2.0'
167182
implementation 'net.lingala.zip4j:zip4j:2.11.5'
168183
implementation 'info.guardianproject.trustedintents:trustedintents:0.2'
169184
implementation 'org.bouncycastle:bcprov-jdk18on:1.77'

app/config/libraries/krop.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"uniqueId": "com.github.avito-tech:krop",
3+
"licenses": [
4+
"MIT"
5+
]
6+
}

app/config/libraries/libsu.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"uniqueId": "com.github.topjohnwu.libsu:.*::regex",
3+
"licenses": [
4+
"Apache-2.0"
5+
]
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"uniqueId": "com.amulyakhare:com.amulyakhare.textdrawable",
3+
"licenses": [
4+
"MIT"
5+
]
6+
}

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@
8282
android:label="@string/title_activity_manage_groups" />
8383
<activity android:name=".ui.AssignIconsActivity"
8484
android:label="@string/title_activity_assign_icons"/>
85+
<activity android:name=".ui.LicensesActivity"
86+
android:label="@string/title_activity_licenses"/>
8587
<activity
8688
android:name=".ui.PanicResponderActivity"
8789
android:exported="true"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.beemdevelopment.aegis.helpers;
2+
3+
import android.content.res.Configuration;
4+
5+
import androidx.appcompat.app.AppCompatActivity;
6+
7+
import com.beemdevelopment.aegis.Preferences;
8+
import com.beemdevelopment.aegis.R;
9+
import com.beemdevelopment.aegis.Theme;
10+
import com.google.android.material.color.DynamicColors;
11+
import com.google.android.material.color.DynamicColorsOptions;
12+
13+
import java.util.Map;
14+
15+
public class ThemeHelper {
16+
private final AppCompatActivity _activity;
17+
private final Preferences _prefs;
18+
19+
public ThemeHelper(AppCompatActivity activity, Preferences prefs) {
20+
_activity = activity;
21+
_prefs = prefs;
22+
}
23+
24+
/**
25+
* Sets the theme of the activity. The actual style that is set is picked from the
26+
* given map, based on the theme configured by the user.
27+
*/
28+
public void setTheme(Map<Theme, Integer> themeMap) {
29+
int theme = themeMap.get(getConfiguredTheme());
30+
_activity.setTheme(theme);
31+
32+
if (_prefs.isDynamicColorsEnabled()) {
33+
DynamicColorsOptions.Builder optsBuilder = new DynamicColorsOptions.Builder();
34+
if (getConfiguredTheme().equals(Theme.AMOLED)) {
35+
optsBuilder.setThemeOverlay(R.style.ThemeOverlay_Aegis_Dynamic_Amoled);
36+
}
37+
DynamicColors.applyToActivityIfAvailable(_activity, optsBuilder.build());
38+
}
39+
}
40+
41+
public Theme getConfiguredTheme() {
42+
Theme theme = _prefs.getCurrentTheme();
43+
44+
if (theme == Theme.SYSTEM || theme == Theme.SYSTEM_AMOLED) {
45+
int currentNightMode = _activity.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
46+
if (currentNightMode == Configuration.UI_MODE_NIGHT_YES) {
47+
theme = theme == Theme.SYSTEM_AMOLED ? Theme.AMOLED : Theme.DARK;
48+
} else {
49+
theme = Theme.LIGHT;
50+
}
51+
}
52+
53+
return theme;
54+
}
55+
}

app/src/main/java/com/beemdevelopment/aegis/licenses/GlideLicense.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

app/src/main/java/com/beemdevelopment/aegis/licenses/ProtobufLicense.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

app/src/main/java/com/beemdevelopment/aegis/ui/AboutActivity.java

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,10 @@
1616

1717
import com.beemdevelopment.aegis.BuildConfig;
1818
import com.beemdevelopment.aegis.R;
19-
import com.beemdevelopment.aegis.licenses.GlideLicense;
20-
import com.beemdevelopment.aegis.licenses.ProtobufLicense;
2119
import com.beemdevelopment.aegis.ui.dialogs.ChangelogDialog;
2220
import com.beemdevelopment.aegis.ui.dialogs.LicenseDialog;
2321
import com.google.android.material.color.MaterialColors;
2422

25-
import de.psdev.licensesdialog.LicenseResolver;
26-
import de.psdev.licensesdialog.LicensesDialog;
27-
2823
public class AboutActivity extends AegisActivity {
2924

3025
private static String GITHUB = "https://github.com/beemdevelopment/Aegis";
@@ -53,12 +48,15 @@ protected void onCreate(Bundle savedInstanceState) {
5348
View btnLicense = findViewById(R.id.btn_license);
5449
btnLicense.setOnClickListener(v -> {
5550
LicenseDialog.create()
56-
.setTheme(getConfiguredTheme())
51+
.setTheme(_themeHelper.getConfiguredTheme())
5752
.show(getSupportFragmentManager(), null);
5853
});
5954

6055
View btnThirdPartyLicenses = findViewById(R.id.btn_third_party_licenses);
61-
btnThirdPartyLicenses.setOnClickListener(v -> showThirdPartyLicenseDialog());
56+
btnThirdPartyLicenses.setOnClickListener(v -> {
57+
Intent intent = new Intent(this, LicensesActivity.class);
58+
startActivity(intent);
59+
});
6260

6361
TextView appVersion = findViewById(R.id.app_version);
6462
appVersion.setText(getCurrentAppVersion());
@@ -89,7 +87,7 @@ protected void onCreate(Bundle savedInstanceState) {
8987
View btnChangelog = findViewById(R.id.btn_changelog);
9088
btnChangelog.setOnClickListener(v -> {
9189
ChangelogDialog.create()
92-
.setTheme(getConfiguredTheme())
90+
.setTheme(_themeHelper.getConfiguredTheme())
9391
.show(getSupportFragmentManager(), null);
9492
});
9593
}
@@ -126,27 +124,6 @@ private void openMail(String mailaddress) {
126124
startActivity(Intent.createChooser(mailIntent, getString(R.string.email)));
127125
}
128126

129-
private void showThirdPartyLicenseDialog() {
130-
String stylesheet = getString(R.string.custom_notices_format_style);
131-
String backgroundColor = getThemeColorAsHex(com.google.android.material.R.attr.colorSurfaceContainerLow);
132-
String textColor = getThemeColorAsHex(com.google.android.material.R.attr.colorOnSurface);
133-
String licenseColor = getThemeColorAsHex(com.google.android.material.R.attr.colorSurfaceContainerLow);
134-
String linkColor = getThemeColorAsHex(com.google.android.material.R.attr.colorAccent);
135-
136-
stylesheet = String.format(stylesheet, backgroundColor, textColor, licenseColor, linkColor);
137-
138-
LicenseResolver.registerLicense(new GlideLicense());
139-
LicenseResolver.registerLicense(new ProtobufLicense());
140-
141-
new LicensesDialog.Builder(this)
142-
.setNotices(R.raw.notices)
143-
.setTitle(R.string.third_party_licenses)
144-
.setNoticesCssStyle(stylesheet)
145-
.setIncludeOwnLicense(true)
146-
.build()
147-
.show();
148-
}
149-
150127
private String getThemeColorAsHex(@AttrRes int attributeId) {
151128
int color = MaterialColors.getColor(this, attributeId, getClass().getCanonicalName());
152129
return String.format("%06X", 0xFFFFFF & color);

app/src/main/java/com/beemdevelopment/aegis/ui/AegisActivity.java

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,17 @@
2020

2121
import com.beemdevelopment.aegis.Preferences;
2222
import com.beemdevelopment.aegis.R;
23-
import com.beemdevelopment.aegis.Theme;
2423
import com.beemdevelopment.aegis.ThemeMap;
24+
import com.beemdevelopment.aegis.helpers.ThemeHelper;
2525
import com.beemdevelopment.aegis.icons.IconPackManager;
2626
import com.beemdevelopment.aegis.vault.VaultManager;
2727
import com.beemdevelopment.aegis.vault.VaultRepositoryException;
28-
import com.google.android.material.color.DynamicColors;
29-
import com.google.android.material.color.DynamicColorsOptions;
3028
import com.google.android.material.color.MaterialColors;
3129

3230
import java.lang.reflect.Field;
3331
import java.lang.reflect.InvocationTargetException;
3432
import java.lang.reflect.Method;
3533
import java.util.Locale;
36-
import java.util.Map;
3734

3835
import javax.inject.Inject;
3936

@@ -46,6 +43,7 @@
4643
@AndroidEntryPoint
4744
public abstract class AegisActivity extends AppCompatActivity implements VaultManager.LockListener {
4845
protected Preferences _prefs;
46+
protected ThemeHelper _themeHelper;
4947

5048
@Inject
5149
protected VaultManager _vaultManager;
@@ -59,6 +57,7 @@ public abstract class AegisActivity extends AppCompatActivity implements VaultMa
5957
protected void onCreate(Bundle savedInstanceState) {
6058
// set the theme and locale before creating the activity
6159
_prefs = EarlyEntryPoints.get(getApplicationContext(), PrefEntryPoint.class).getPreferences();
60+
_themeHelper = new ThemeHelper(this, _prefs);
6261
onSetTheme();
6362
setLocale(_prefs.getLocale());
6463
super.onCreate(savedInstanceState);
@@ -111,39 +110,7 @@ public void onLocked(boolean userInitiated) {
111110
* Called when the activity is expected to set its theme.
112111
*/
113112
protected void onSetTheme() {
114-
setTheme(ThemeMap.DEFAULT);
115-
}
116-
117-
/**
118-
* Sets the theme of the activity. The actual style that is set is picked from the
119-
* given map, based on the theme configured by the user.
120-
*/
121-
protected void setTheme(Map<Theme, Integer> themeMap) {
122-
int theme = themeMap.get(getConfiguredTheme());
123-
setTheme(theme);
124-
125-
if (_prefs.isDynamicColorsEnabled()) {
126-
DynamicColorsOptions.Builder optsBuilder = new DynamicColorsOptions.Builder();
127-
if (getConfiguredTheme().equals(Theme.AMOLED)) {
128-
optsBuilder.setThemeOverlay(R.style.ThemeOverlay_Aegis_Dynamic_Amoled);
129-
}
130-
DynamicColors.applyToActivityIfAvailable(this, optsBuilder.build());
131-
}
132-
}
133-
134-
protected Theme getConfiguredTheme() {
135-
Theme theme = _prefs.getCurrentTheme();
136-
137-
if (theme == Theme.SYSTEM || theme == Theme.SYSTEM_AMOLED) {
138-
int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
139-
if (currentNightMode == Configuration.UI_MODE_NIGHT_YES) {
140-
theme = theme == Theme.SYSTEM_AMOLED ? Theme.AMOLED : Theme.DARK;
141-
} else {
142-
theme = Theme.LIGHT;
143-
}
144-
}
145-
146-
return theme;
113+
_themeHelper.setTheme(ThemeMap.DEFAULT);
147114
}
148115

149116
protected void setLocale(Locale locale) {

0 commit comments

Comments
 (0)