2 * Copyright © 2019 Damyan Ivanov.
3 * This file is part of MoLe.
4 * MoLe is free software: you can distribute it and/or modify it
5 * under the term of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your opinion), any later version.
9 * MoLe is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License terms for details.
14 * You should have received a copy of the GNU General Public License
15 * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
18 package net.ktnx.mobileledger.ui.activity;
20 import android.os.Bundle;
21 import android.view.Menu;
23 import androidx.appcompat.app.ActionBar;
24 import androidx.appcompat.widget.Toolbar;
26 import net.ktnx.mobileledger.R;
27 import net.ktnx.mobileledger.model.Data;
28 import net.ktnx.mobileledger.model.MobileLedgerProfile;
29 import net.ktnx.mobileledger.ui.profiles.ProfileDetailFragment;
30 import net.ktnx.mobileledger.utils.Colors;
32 import java.util.ArrayList;
33 import java.util.Locale;
35 import static net.ktnx.mobileledger.utils.Logger.debug;
38 * An activity representing a single Profile detail screen. This
39 * activity is only used on narrow width devices. On tablet-size devices,
40 * item details are presented side-by-side with a list of items
41 * in a ProfileListActivity (not really).
43 public class ProfileDetailActivity extends CrashReportingActivity {
44 private MobileLedgerProfile profile = null;
45 private ProfileDetailFragment mFragment;
47 protected void onCreate(Bundle savedInstanceState) {
48 final int index = getIntent().getIntExtra(ProfileDetailFragment.ARG_ITEM_ID, -1);
51 ArrayList<MobileLedgerProfile> profiles = Data.profiles.getValue();
52 if (profiles != null) {
53 profile = profiles.get(index);
55 throw new AssertionError(
56 String.format("Can't get profile " + "(index:%d) from the global list",
59 debug("profiles", String.format(Locale.ENGLISH, "Editing profile %s (%s); hue=%d",
60 profile.getName(), profile.getUuid(), profile.getThemeId()));
64 super.onCreate(savedInstanceState);
65 Colors.setupTheme(this, profile);
66 setContentView(R.layout.activity_profile_detail);
67 Toolbar toolbar = findViewById(R.id.detail_toolbar);
68 setSupportActionBar(toolbar);
70 // Show the Up button in the action bar.
71 ActionBar actionBar = getSupportActionBar();
72 if (actionBar != null) {
73 actionBar.setDisplayHomeAsUpEnabled(true);
76 // savedInstanceState is non-null when there is fragment state
77 // saved from previous configurations of this activity
78 // (e.g. when rotating the screen from portrait to landscape).
79 // In this case, the fragment will automatically be re-added
80 // to its container so we don't need to manually add it.
81 // For more information, see the Fragments API guide at:
83 // http://developer.android.com/guide/components/fragments.html
85 if (savedInstanceState == null) {
86 // Create the detail fragment and add it to the activity
87 // using a fragment transaction.
88 Bundle arguments = new Bundle();
89 arguments.putInt(ProfileDetailFragment.ARG_ITEM_ID, index);
90 mFragment = new ProfileDetailFragment();
91 mFragment.setArguments(arguments);
92 getSupportFragmentManager().beginTransaction()
93 .add(R.id.profile_detail_container, mFragment)
98 public boolean onCreateOptionsMenu(Menu menu) {
99 super.onCreateOptionsMenu(menu);
100 debug("profiles", "[activity] Creating profile details options menu");
101 if (mFragment != null)
102 mFragment.onCreateOptionsMenu(menu, getMenuInflater());