/*
- * Copyright © 2019 Damyan Ivanov.
+ * Copyright © 2020 Damyan Ivanov.
* This file is part of MoLe.
* MoLe is free software: you can distribute it and/or modify it
* under the term of the GNU General Public License as published by
import android.annotation.SuppressLint;
import android.os.Bundle;
+import androidx.annotation.Nullable;
+
import net.ktnx.mobileledger.model.Data;
import net.ktnx.mobileledger.model.MobileLedgerProfile;
import net.ktnx.mobileledger.utils.Colors;
-import androidx.annotation.Nullable;
-
@SuppressLint("Registered")
public class ProfileThemedActivity extends CrashReportingActivity {
protected MobileLedgerProfile mProfile;
+ private boolean themeSetUp = false;
+ private boolean mIgnoreProfileChange;
protected void setupProfileColors() {
- Colors.setupTheme(this, mProfile);
+ final int themeHue = (mProfile == null) ? -1 : mProfile.getThemeHue();
+
+ Colors.setupTheme(this, themeHue);
+
+ if (themeSetUp)
+ this.recreate();
+ themeSetUp = true;
+
+ Colors.profileThemeId = Data.retrieveCurrentThemeIdFromDb();
}
@Override
protected void onStart() {
}
protected void onCreate(@Nullable Bundle savedInstanceState) {
initProfile();
- super.onCreate(savedInstanceState);
setupProfileColors();
+
+ mIgnoreProfileChange = true;
+ Data.observeProfile(this, profile -> {
+ if (!mIgnoreProfileChange) {
+ mProfile = profile;
+ setupProfileColors();
+ }
+
+ mIgnoreProfileChange = false;
+ });
+
+ super.onCreate(savedInstanceState);
}
protected void initProfile() {
- mProfile = Data.profile.getValue();
+ mProfile = Data.initProfile();
}
}