X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FProfileDetailActivity.java;h=40051dac68e4ef9155ea4036ba07fa0b7d56cd81;hp=fa55b8784281d189c73a13369f47b1677d7f5a22;hb=23b8360d4f884bbdb20cc2de1825486ef42f37d6;hpb=09e26d2279484b4dfe0de218b05f075362fff4b5 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 fa55b878..40051dac 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 @@ -17,46 +17,50 @@ package net.ktnx.mobileledger.ui.activity; -import android.content.Intent; import android.os.Bundle; -import com.google.android.material.floatingactionbutton.FloatingActionButton; -import com.google.android.material.snackbar.Snackbar; -import androidx.appcompat.app.ActionBar; -import androidx.appcompat.widget.Toolbar; -import android.util.Log; import android.view.Menu; -import android.view.MenuItem; -import android.view.View; 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.utils.Colors; + +import java.util.Locale; + +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.widget.Toolbar; + +import static net.ktnx.mobileledger.utils.Logger.debug; /** * An activity representing a single Profile detail screen. This * activity is only used on narrow width devices. On tablet-size devices, * item details are presented side-by-side with a list of items - * in a {@link ProfileListActivity}. + * in a ProfileListActivity (not really). */ public class ProfileDetailActivity extends CrashReportingActivity { - private MobileLedgerProfile profile; + private MobileLedgerProfile profile = null; + private ProfileDetailFragment mFragment; @Override protected void onCreate(Bundle savedInstanceState) { + 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)); + + debug("profiles", String.format(Locale.ENGLISH, "Editing profile %s (%s); hue=%d", + profile.getName(), profile.getUuid(), profile.getThemeId())); + } + super.onCreate(savedInstanceState); + Colors.setupTheme(this, profile); setContentView(R.layout.activity_profile_detail); Toolbar toolbar = findViewById(R.id.detail_toolbar); setSupportActionBar(toolbar); - FloatingActionButton fab = findViewById(R.id.fab); - fab.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Snackbar.make(view, "Replace with your own detail action", Snackbar.LENGTH_LONG) - .setAction("Action", null).show(); - } - }); - // Show the Up button in the action bar. ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { @@ -73,61 +77,23 @@ public class ProfileDetailActivity extends CrashReportingActivity { // http://developer.android.com/guide/components/fragments.html // if (savedInstanceState == null) { - 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)); - } - // Create the detail fragment and add it to the activity // using a fragment transaction. Bundle arguments = new Bundle(); arguments.putInt(ProfileDetailFragment.ARG_ITEM_ID, index); - ProfileDetailFragment fragment = new ProfileDetailFragment(); - fragment.setArguments(arguments); + mFragment = new ProfileDetailFragment(); + mFragment.setArguments(arguments); getSupportFragmentManager().beginTransaction() - .add(R.id.profile_detail_container, fragment).commit(); + .add(R.id.profile_detail_container, mFragment).commit(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); - Log.d("profiles", "[activity] Creating profile details options menu"); - getMenuInflater().inflate(R.menu.profile_details, menu); - MenuItem menuDeleteProfile = menu.findItem(R.id.menuDelete); - menuDeleteProfile.setOnMenuItemClickListener(item -> { - Log.d("profiles", String.format("[activity] deleting profile %s", profile.getUuid())); - profile.removeFromDB(); - Data.profiles.remove(profile); - if (Data.profile.get().equals(profile)) { - Log.d("profiles", "[activity] selecting profile 0"); - Data.setCurrentProfile(Data.profiles.get(0)); - } - finish(); - return true; - }); - - menuDeleteProfile.setVisible((profile != null) && (Data.profiles.size() > 1)); + debug("profiles", "[activity] Creating profile details options menu"); + if (mFragment != null) mFragment.onCreateOptionsMenu(menu, getMenuInflater()); return true; } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int id = item.getItemId(); - if (id == android.R.id.home) { - // This ID represents the Home or Up button. In the case of this - // activity, the Up button is shown. For - // more details, see the Navigation pattern on Android Design: - // - // http://developer.android.com/design/patterns/navigation.html#up-vs-back - // - navigateUpTo(new Intent(this, ProfileListActivity.class)); - return true; - } - return super.onOptionsItemSelected(item); - } }