From c434526b687162a4ebf4c268e521404e2b58fcc7 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Fri, 15 May 2020 14:40:35 +0300 Subject: [PATCH] proile editor: fix passing of initial theme hue to the hue ring --- .../ui/activity/ProfileDetailActivity.java | 11 +++++++++++ .../ui/profiles/ProfileDetailFragment.java | 8 +++----- .../mobileledger/ui/profiles/ProfileDetailModel.java | 2 ++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileDetailActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileDetailActivity.java index 7daa3d31..1bc17ec4 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileDetailActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileDetailActivity.java @@ -23,13 +23,17 @@ import android.view.MenuItem; import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.Toolbar; +import androidx.lifecycle.ViewModelProvider; import net.ktnx.mobileledger.R; import net.ktnx.mobileledger.model.Data; import net.ktnx.mobileledger.model.MobileLedgerProfile; import net.ktnx.mobileledger.ui.profiles.ProfileDetailFragment; +import net.ktnx.mobileledger.ui.profiles.ProfileDetailModel; import net.ktnx.mobileledger.utils.Colors; +import org.jetbrains.annotations.NotNull; + import java.util.ArrayList; import java.util.Locale; @@ -44,6 +48,10 @@ import static net.ktnx.mobileledger.utils.Logger.debug; public class ProfileDetailActivity extends CrashReportingActivity { private MobileLedgerProfile profile = null; private ProfileDetailFragment mFragment; + @NotNull + private ProfileDetailModel getModel() { + return new ViewModelProvider(this).get(ProfileDetailModel.class); + } @Override protected void onCreate(Bundle savedInstanceState) { final int index = getIntent().getIntExtra(ProfileDetailFragment.ARG_ITEM_ID, -1); @@ -70,10 +78,13 @@ public class ProfileDetailActivity extends CrashReportingActivity { themeHue = Colors.getNewProfileThemeHue(Data.profiles.getValue()); } Colors.setupTheme(this, themeHue); + final ProfileDetailModel model = getModel(); + model.initialThemeHue = themeHue; setContentView(R.layout.activity_profile_detail); Toolbar toolbar = findViewById(R.id.detail_toolbar); setSupportActionBar(toolbar); + // Show the Up button in the action bar. ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java index f6323d51..68758402 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java @@ -63,9 +63,7 @@ import org.jetbrains.annotations.NotNull; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; -import java.util.Objects; -import static net.ktnx.mobileledger.utils.Colors.profileThemeId; import static net.ktnx.mobileledger.utils.Logger.debug; /** @@ -393,8 +391,8 @@ public class ProfileDetailFragment extends Fragment { }); huePickerView.setOnClickListener(v -> { - HueRingDialog d = new HueRingDialog( - Objects.requireNonNull(ProfileDetailFragment.this.getContext()), profileThemeId, + HueRingDialog d = new HueRingDialog(ProfileDetailFragment.this.requireContext(), + model.initialThemeHue, (Integer) v.getTag()); d.show(); d.setColorSelectedListener(model::setThemeId); @@ -426,7 +424,7 @@ public class ProfileDetailFragment extends Fragment { } @NotNull private ProfileDetailModel getModel() { - return new ViewModelProvider(this).get(ProfileDetailModel.class); + return new ViewModelProvider(requireActivity()).get(ProfileDetailModel.class); } private void onSaveFabClicked() { if (!checkValidity()) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailModel.java index 2a655dcc..57c99218 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailModel.java @@ -25,6 +25,7 @@ import androidx.lifecycle.ViewModel; import net.ktnx.mobileledger.async.SendTransactionTask; import net.ktnx.mobileledger.model.Currency; import net.ktnx.mobileledger.model.MobileLedgerProfile; +import net.ktnx.mobileledger.utils.Colors; import net.ktnx.mobileledger.utils.Misc; public class ProfileDetailModel extends ViewModel { @@ -44,6 +45,7 @@ public class ProfileDetailModel extends ViewModel { private final MutableLiveData authPassword = new MutableLiveData<>(null); private final MutableLiveData preferredAccountsFilter = new MutableLiveData<>(null); private final MutableLiveData themeId = new MutableLiveData<>(-1); + public int initialThemeHue = Colors.DEFAULT_HUE_DEG; public ProfileDetailModel() { } String getProfileName() { -- 2.39.5