]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/main/java/net/ktnx/mobileledger/ui/activity/ProfileDetailActivity.java
40051dac68e4ef9155ea4036ba07fa0b7d56cd81
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / ProfileDetailActivity.java
1 /*
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.ktnx.mobileledger.ui.activity;
19
20 import android.os.Bundle;
21 import android.view.Menu;
22
23 import net.ktnx.mobileledger.R;
24 import net.ktnx.mobileledger.model.Data;
25 import net.ktnx.mobileledger.model.MobileLedgerProfile;
26 import net.ktnx.mobileledger.ui.profiles.ProfileDetailFragment;
27 import net.ktnx.mobileledger.utils.Colors;
28
29 import java.util.Locale;
30
31 import androidx.appcompat.app.ActionBar;
32 import androidx.appcompat.widget.Toolbar;
33
34 import static net.ktnx.mobileledger.utils.Logger.debug;
35
36 /**
37  * An activity representing a single Profile detail screen. This
38  * activity is only used on narrow width devices. On tablet-size devices,
39  * item details are presented side-by-side with a list of items
40  * in a ProfileListActivity (not really).
41  */
42 public class ProfileDetailActivity extends CrashReportingActivity {
43     private MobileLedgerProfile profile = null;
44     private ProfileDetailFragment mFragment;
45     @Override
46     protected void onCreate(Bundle savedInstanceState) {
47         final int index = getIntent().getIntExtra(ProfileDetailFragment.ARG_ITEM_ID, -1);
48
49         if (index != -1) {
50             profile = Data.profiles.get(index);
51             if (profile == null) throw new AssertionError(
52                     String.format("Can't get profile " + "(index:%d) from the global list", index));
53
54                 debug("profiles", String.format(Locale.ENGLISH, "Editing profile %s (%s); hue=%d",
55                         profile.getName(), profile.getUuid(), profile.getThemeId()));
56         }
57
58         super.onCreate(savedInstanceState);
59         Colors.setupTheme(this, profile);
60         setContentView(R.layout.activity_profile_detail);
61         Toolbar toolbar = findViewById(R.id.detail_toolbar);
62         setSupportActionBar(toolbar);
63
64         // Show the Up button in the action bar.
65         ActionBar actionBar = getSupportActionBar();
66         if (actionBar != null) {
67             actionBar.setDisplayHomeAsUpEnabled(true);
68         }
69
70         // savedInstanceState is non-null when there is fragment state
71         // saved from previous configurations of this activity
72         // (e.g. when rotating the screen from portrait to landscape).
73         // In this case, the fragment will automatically be re-added
74         // to its container so we don't need to manually add it.
75         // For more information, see the Fragments API guide at:
76         //
77         // http://developer.android.com/guide/components/fragments.html
78         //
79         if (savedInstanceState == null) {
80             // Create the detail fragment and add it to the activity
81             // using a fragment transaction.
82             Bundle arguments = new Bundle();
83             arguments.putInt(ProfileDetailFragment.ARG_ITEM_ID, index);
84             mFragment = new ProfileDetailFragment();
85             mFragment.setArguments(arguments);
86             getSupportFragmentManager().beginTransaction()
87                     .add(R.id.profile_detail_container, mFragment).commit();
88         }
89     }
90     @Override
91     public boolean onCreateOptionsMenu(Menu menu) {
92         super.onCreateOptionsMenu(menu);
93         debug("profiles", "[activity] Creating profile details options menu");
94         if (mFragment != null) mFragment.onCreateOptionsMenu(menu, getMenuInflater());
95
96         return true;
97     }
98
99 }