X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fprofiles%2FProfileDetailFragment.java;h=4f61ba2e1d305f714c56737357335628eab709c3;hp=8ec74734b4e6b71c7ea1d8abdd17929f749045b6;hb=bd5da50ef980c0c9657ec1e9c3e681ab5092f438;hpb=cc46904e9b0c4aa9752fefe2754302bd62c2c927 diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java index 8ec74734..4f61ba2e 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java @@ -23,7 +23,6 @@ import android.content.DialogInterface; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; -import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -38,6 +37,7 @@ import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.textfield.TextInputLayout; +import net.ktnx.mobileledger.BuildConfig; import net.ktnx.mobileledger.R; import net.ktnx.mobileledger.model.Data; import net.ktnx.mobileledger.model.MobileLedgerProfile; @@ -51,6 +51,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; +import static net.ktnx.mobileledger.utils.Logger.debug; + /** * A fragment representing a single Profile detail screen. * a {@link ProfileDetailActivity} @@ -90,7 +92,7 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - Log.d("profiles", "[fragment] Creating profile details options menu"); + debug("profiles", "[fragment] Creating profile details options menu"); super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.profile_details, menu); final MenuItem menuDeleteProfile = menu.findItem(R.id.menuDelete); @@ -101,12 +103,12 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue builder.setPositiveButton(R.string.Remove, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - Log.d("profiles", + debug("profiles", String.format("[fragment] removing profile %s", mProfile.getUuid())); mProfile.removeFromDB(); Data.profiles.remove(mProfile); if (Data.profile.get().equals(mProfile)) { - Log.d("profiles", "[fragment] setting current profile to 0"); + debug("profiles", "[fragment] setting current profile to 0"); Data.setCurrentProfile(Data.profiles.get(0)); } getActivity().finish(); @@ -116,6 +118,18 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue return false; }); menuDeleteProfile.setVisible((mProfile != null) && (Data.profiles.size() > 1)); + + if (BuildConfig.DEBUG) { + final MenuItem menuWipeProfileData = menu.findItem(R.id.menuWipeData); + menuWipeProfileData.setOnMenuItemClickListener(this::onWipeDataMenuClicked); + menuWipeProfileData.setVisible(mProfile != null); + } + } + private boolean onWipeDataMenuClicked(MenuItem item) { + // this is a development option, so no confirmation + mProfile.wipeAllData(); + Data.profile.forceNotifyObservers(); + return true; } @Override public void onCreate(Bundle savedInstanceState) { @@ -146,15 +160,15 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue if (mProfile != null) { updateProfileFromUI(); -// Log.d("profiles", String.format("Selected item is %d", mProfile.getThemeId())); +// debug("profiles", String.format("Selected item is %d", mProfile.getThemeId())); mProfile.storeInDB(); - Log.d("profiles", "profile stored in DB"); + debug("profiles", "profile stored in DB"); Data.profiles.triggerItemChangedNotification(mProfile); if (mProfile.getUuid().equals(Data.profile.get().getUuid())) { // dummy update to notify the observers of the possibly new name/URL - Data.profile.set(mProfile); + Data.profile.forceNotifyObservers(); } } else { @@ -206,12 +220,11 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue rootView.findViewById(R.id.preferred_accounts_accounts_filter_layout); useAuthentication.setOnCheckedChangeListener((buttonView, isChecked) -> { - Log.d("profiles", isChecked ? "auth enabled " : "auth disabled"); + debug("profiles", isChecked ? "auth enabled " : "auth disabled"); authParams.setVisibility(isChecked ? View.VISIBLE : View.GONE); if (isChecked) userName.requestFocus(); }); - preferredAccountsFilter.setText(mProfile.getPreferredAccountsFilter()); postingPermitted.setOnCheckedChangeListener(((buttonView, isChecked) -> { preferredAccountsFilterLayout.setVisibility(isChecked ? View.VISIBLE : View.GONE); })); @@ -230,6 +243,7 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue authParams.setVisibility(mProfile.isAuthEnabled() ? View.VISIBLE : View.GONE); userName.setText(mProfile.isAuthEnabled() ? mProfile.getAuthUserName() : ""); password.setText(mProfile.isAuthEnabled() ? mProfile.getAuthPassword() : ""); + preferredAccountsFilter.setText(mProfile.getPreferredAccountsFilter()); profileThemeId = mProfile.getThemeId(); } else { @@ -240,6 +254,7 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue authParams.setVisibility(View.GONE); userName.setText(""); password.setText(""); + preferredAccountsFilter.setText(null); profileThemeId = -1; } @@ -250,7 +265,8 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue huePickerView.setTag(profileThemeId); huePickerView.setOnClickListener(v -> { HueRingDialog d = new HueRingDialog( - Objects.requireNonNull(ProfileDetailFragment.this.getContext()), hue); + Objects.requireNonNull(ProfileDetailFragment.this.getContext()), + profileThemeId, (Integer) v.getTag()); d.show(); d.setColorSelectedListener(this); });