X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FProfileDetailActivity.java;h=7daa3d315cbfbd479970efb26fcbc3121c285c61;hb=a2299fe8eddcbf5577a1576f899ddc28c8df00d5;hp=ad7401de661079b75510f59eab70b5e4c6d79318;hpb=bd5da50ef980c0c9657ec1e9c3e681ab5092f438;p=mobile-ledger.git 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 ad7401de..7daa3d31 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 @@ -19,6 +19,10 @@ package net.ktnx.mobileledger.ui.activity; import android.os.Bundle; import android.view.Menu; +import android.view.MenuItem; + +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.widget.Toolbar; import net.ktnx.mobileledger.R; import net.ktnx.mobileledger.model.Data; @@ -26,8 +30,8 @@ import net.ktnx.mobileledger.model.MobileLedgerProfile; import net.ktnx.mobileledger.ui.profiles.ProfileDetailFragment; import net.ktnx.mobileledger.utils.Colors; -import androidx.appcompat.app.ActionBar; -import androidx.appcompat.widget.Toolbar; +import java.util.ArrayList; +import java.util.Locale; import static net.ktnx.mobileledger.utils.Logger.debug; @@ -45,16 +49,27 @@ public class ProfileDetailActivity extends CrashReportingActivity { final int index = getIntent().getIntExtra(ProfileDetailFragment.ARG_ITEM_ID, -1); if (index != -1) { - profile = Data.profiles.get(index); - if (profile == null) throw new AssertionError( - String.format("Can't get profile " + "(index:%d) from the global list", index)); + ArrayList profiles = Data.profiles.getValue(); + if (profiles != null) { + profile = profiles.get(index); + if (profile == null) + throw new AssertionError( + String.format("Can't get profile " + "(index:%d) from the global list", + index)); - debug("profiles", String.format("Editing profile %s (%s); hue=%d", profile.getName(), - profile.getUuid(), profile.getThemeId())); + debug("profiles", String.format(Locale.ENGLISH, "Editing profile %s (%s); hue=%d", + profile.getName(), profile.getUuid(), profile.getThemeHue())); + } } super.onCreate(savedInstanceState); - Colors.setupTheme(this, profile); + int themeHue; + if (profile != null) + themeHue = profile.getThemeHue(); + else { + themeHue = Colors.getNewProfileThemeHue(Data.profiles.getValue()); + } + Colors.setupTheme(this, themeHue); setContentView(R.layout.activity_profile_detail); Toolbar toolbar = findViewById(R.id.detail_toolbar); setSupportActionBar(toolbar); @@ -79,19 +94,29 @@ public class ProfileDetailActivity extends CrashReportingActivity { // using a fragment transaction. Bundle arguments = new Bundle(); arguments.putInt(ProfileDetailFragment.ARG_ITEM_ID, index); + arguments.putInt(ProfileDetailFragment.ARG_HUE, themeHue); mFragment = new ProfileDetailFragment(); mFragment.setArguments(arguments); getSupportFragmentManager().beginTransaction() - .add(R.id.profile_detail_container, mFragment).commit(); + .add(R.id.profile_detail_container, mFragment) + .commit(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); debug("profiles", "[activity] Creating profile details options menu"); - if (mFragment != null) mFragment.onCreateOptionsMenu(menu, getMenuInflater()); + if (mFragment != null) + mFragment.onCreateOptionsMenu(menu, getMenuInflater()); return true; } - + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == android.R.id.home) { + finish(); + return true; + } + return super.onOptionsItemSelected(item); + } }