X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;ds=inline;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fprofiles%2FProfileDetailActivity.java;h=8afdefc10a40b2616d489a8715710cc72ab35f17;hb=7dcfecdf81f1ac19d30cfa3c5abb4ce15eb8c5c8;hp=1db1429acfd78b2c9c398008c4c0518b7f3d3af9;hpb=b06a7a291e35add2dfc89313d226c5efd1bae3b3;p=mobile-ledger-staging.git
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 1db1429a..8afdefc1 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,62 +1,88 @@
/*
- * Copyright © 2019 Damyan Ivanov.
- * This file is part of Mobile-Ledger.
- * Mobile-Ledger is free software: you can distribute it and/or modify it
+ * Copyright © 2021 Damyan Ivanov.
+ * 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;
-import android.content.Intent;
import android.os.Bundle;
-import android.support.design.widget.FloatingActionButton;
-import android.support.design.widget.Snackbar;
-import android.support.v7.app.ActionBar;
-import android.support.v7.app.AppCompatActivity;
-import android.support.v7.widget.Toolbar;
-import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
-import android.view.View;
+
+import androidx.appcompat.app.ActionBar;
+import androidx.appcompat.widget.Toolbar;
+import androidx.lifecycle.ViewModelProvider;
import net.ktnx.mobileledger.R;
import net.ktnx.mobileledger.model.Data;
import net.ktnx.mobileledger.model.MobileLedgerProfile;
-import net.ktnx.mobileledger.ui.activity.ProfileListActivity;
+import net.ktnx.mobileledger.ui.activity.CrashReportingActivity;
+import net.ktnx.mobileledger.utils.Colors;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.util.ArrayList;
+import java.util.Locale;
+
+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 AppCompatActivity {
- private MobileLedgerProfile profile;
+public class ProfileDetailActivity extends CrashReportingActivity {
+ private MobileLedgerProfile profile = null;
+ private ProfileDetailFragment mFragment;
+ @NotNull
+ private ProfileDetailModel getModel() {
+ return new ViewModelProvider(this).get(ProfileDetailModel.class);
+ }
@Override
protected void onCreate(Bundle savedInstanceState) {
+ final int index = getIntent().getIntExtra(ProfileDetailFragment.ARG_ITEM_ID, -1);
+
+ if (index != -1) {
+ 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(Locale.ENGLISH, "Editing profile %s (%s); hue=%d",
+ profile.getName(), profile.getUuid(), profile.getThemeHue()));
+ }
+ }
+
super.onCreate(savedInstanceState);
+ int themeHue;
+ if (profile != null)
+ themeHue = profile.getThemeHue();
+ else {
+ themeHue = Colors.getNewProfileThemeHue(Data.profiles.getValue());
+ }
+ Colors.setupTheme(this, themeHue);
+ final ProfileDetailModel model = getModel();
+ model.initialThemeHue = themeHue;
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();
@@ -74,59 +100,31 @@ public class ProfileDetailActivity extends AppCompatActivity {
// 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);
+ arguments.putInt(ProfileDetailFragment.ARG_HUE, themeHue);
+ 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));
+ if (item.getItemId() == android.R.id.home) {
+ finish();
return true;
}
return super.onOptionsItemSelected(item);