X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fprofiles%2FProfileDetailActivity.java;h=23d22f55007db84c65b75e30dac187032d058d75;hp=982fccfa4512f86a0e90fe7e18597f279dd94c48;hb=b4d5812942fdb2ca89c9f048e539c4c65a8994cf;hpb=5288da587233a9203d4abcaf7840dc62db2fb294 diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailActivity.java index 982fccfa..23d22f55 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailActivity.java @@ -1,18 +1,18 @@ /* * Copyright © 2019 Damyan Ivanov. - * This file is part of Mobile-Ledger. - * Mobile-Ledger is free software: you can distribute it and/or modify it + * 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 * the Free Software Foundation, either version 3 of the License, or * (at your opinion), any later version. * - * Mobile-Ledger is distributed in the hope that it will be useful, + * MoLe is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License terms for details. * * You should have received a copy of the GNU General Public License - * along with Mobile-Ledger. If not, see . + * along with MoLe. If not, see . */ package net.ktnx.mobileledger.ui.profiles; @@ -74,28 +74,19 @@ public class ProfileDetailActivity extends AppCompatActivity { // http://developer.android.com/guide/components/fragments.html // if (savedInstanceState == null) { - final String profileUUID = - getIntent().getStringExtra(ProfileDetailFragment.ARG_ITEM_ID); + final int index = getIntent().getIntExtra(ProfileDetailFragment.ARG_ITEM_ID, -1); - if (profileUUID != null) { - int i = 0; - for (MobileLedgerProfile p : Data.profiles.getList()) { - if (p.getUuid().equals(profileUUID)) { - Log.d("profiles", String.format("found profile %s at %d", profileUUID, i)); - profile = p; - break; - } - i++; - } + if (index != -1) { + profile = Data.profiles.get(index); if (profile == null) throw new AssertionError( - String.format("Can't get profile " + "(uuid:%s) from the " + "global list", - profileUUID)); + 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.putString(ProfileDetailFragment.ARG_ITEM_ID, profileUUID); + arguments.putInt(ProfileDetailFragment.ARG_ITEM_ID, index); ProfileDetailFragment fragment = new ProfileDetailFragment(); fragment.setArguments(arguments); getSupportFragmentManager().beginTransaction() @@ -109,10 +100,13 @@ public class ProfileDetailActivity extends AppCompatActivity { getMenuInflater().inflate(R.menu.profile_details, menu); MenuItem menuDeleteProfile = menu.findItem(R.id.menuDelete); menuDeleteProfile.setOnMenuItemClickListener(item -> { - Log.d("profiles", String.format("deleting profile %s", profile.getUuid())); + Log.d("profiles", String.format("[activity] deleting profile %s", profile.getUuid())); profile.removeFromDB(); Data.profiles.remove(profile); - Data.profile.set(Data.profiles.get(0)); + if (Data.profile.get().equals(profile)) { + Log.d("profiles", "[activity] selecting profile 0"); + Data.setCurrentProfile(Data.profiles.get(0)); + } finish(); return true; });