From 82c6ade3a4ba136c8a55aab82802996d1aad7280 Mon Sep 17 00:00:00 2001 From: Moshe W Date: Tue, 31 Dec 2024 22:04:41 +0200 Subject: [PATCH] Action bar ready when view ready. --- .../ui/account/AccountFormFragment.java | 30 ++++++++----------- .../ui/account/AccountsListFragment.java | 27 ++++++++++------- .../ui/budget/BudgetAmountEditorFragment.java | 2 +- .../ui/budget/BudgetDetailFragment.java | 2 +- .../android/ui/budget/BudgetFormFragment.java | 2 +- .../android/ui/budget/BudgetListFragment.java | 6 ++-- .../android/ui/export/ExportFormFragment.java | 14 +++------ .../android/ui/report/BaseReportFragment.java | 14 +++++---- .../ui/settings/AboutPreferenceFragment.java | 12 ++++---- .../settings/AccountPreferencesFragment.java | 15 +++++++--- .../ui/settings/BackupPreferenceFragment.java | 10 +++++-- .../ui/settings/BookManagerFragment.java | 9 +++--- .../settings/GeneralPreferenceFragment.java | 9 +++--- .../ui/settings/PreferenceActivity.java | 5 +++- .../TransactionsPreferenceFragment.java | 9 +++++- .../ScheduledActionsListFragment.java | 16 ++++------ .../transaction/TransactionFormFragment.java | 25 +++++++++------- .../transaction/TransactionsListFragment.java | 25 ++++++++-------- 18 files changed, 128 insertions(+), 104 deletions(-) diff --git a/app/src/main/java/org/gnucash/android/ui/account/AccountFormFragment.java b/app/src/main/java/org/gnucash/android/ui/account/AccountFormFragment.java index 510c4755b..3a45c58a3 100644 --- a/app/src/main/java/org/gnucash/android/ui/account/AccountFormFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/account/AccountFormFragment.java @@ -46,6 +46,7 @@ import android.widget.Spinner; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; @@ -172,6 +173,7 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mAccountsDbAdapter = AccountsDbAdapter.getInstance(); mUseDoubleEntry = GnuCashApplication.isDoubleEntryEnabled(); + mAccountUID = getArguments().getString(UxArgument.SELECTED_ACCOUNT_UID); } /** @@ -181,6 +183,12 @@ public void onCreate(Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mBinding = FragmentAccountFormBinding.inflate(inflater, container, false); + return mBinding.getRoot(); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); mBinding.inputAccountName.addTextChangedListener(new TextWatcher() { @Override @@ -240,32 +248,19 @@ public void onClick(View view) { } }); - return mBinding.getRoot(); - } - - - /** - * Initializes the values of the views in the dialog - */ - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - CommoditiesCursorAdapter commoditiesAdapter = new CommoditiesCursorAdapter( getActivity(), android.R.layout.simple_spinner_item); commoditiesAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mBinding.inputCurrencySpinner.setAdapter(commoditiesAdapter); - - mAccountUID = getArguments().getString(UxArgument.SELECTED_ACCOUNT_UID); - - ActionBar supportActionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); + ActionBar actionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar(); + assert actionBar != null; if (mAccountUID != null) { mAccount = mAccountsDbAdapter.getSimpleRecord(mAccountUID); - supportActionBar.setTitle(R.string.title_edit_account); + actionBar.setTitle(R.string.title_edit_account); } else { - supportActionBar.setTitle(R.string.title_create_account); + actionBar.setTitle(R.string.title_create_account); } mRootAccountUID = mAccountsDbAdapter.getOrCreateGnuCashRootAccountUID(); @@ -284,7 +279,6 @@ public void onActivityCreated(Bundle savedInstanceState) { } else { initializeViews(); } - } /** diff --git a/app/src/main/java/org/gnucash/android/ui/account/AccountsListFragment.java b/app/src/main/java/org/gnucash/android/ui/account/AccountsListFragment.java index 2cdc4105a..06fcd8f64 100644 --- a/app/src/main/java/org/gnucash/android/ui/account/AccountsListFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/account/AccountsListFragment.java @@ -41,6 +41,7 @@ import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.PopupMenu; @@ -146,6 +147,17 @@ public static AccountsListFragment newInstance(DisplayMode displayMode) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mBinding = FragmentAccountsListBinding.inflate(inflater, container, false); + return mBinding.getRoot(); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + AppCompatActivity activity = (AppCompatActivity) requireActivity(); + ActionBar actionbar = activity.getSupportActionBar(); + assert actionbar != null; + actionbar.setTitle(R.string.title_accounts); + actionbar.setDisplayHomeAsUpEnabled(true); mBinding.list.setHasFixedSize(true); mBinding.list.setEmptyView(mBinding.emptyView); @@ -171,7 +183,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, LinearLayoutManager mLayoutManager = new LinearLayoutManager(getActivity()); mBinding.list.setLayoutManager(mLayoutManager); } - return mBinding.getRoot(); } @Override @@ -190,12 +201,6 @@ public void onCreate(Bundle savedInstanceState) { } } - AppCompatActivity activity = (AppCompatActivity) requireActivity(); - ActionBar actionbar = activity.getSupportActionBar(); - assert actionbar != null; - actionbar.setTitle(R.string.title_accounts); - actionbar.setDisplayHomeAsUpEnabled(true); - // specify an adapter (see also next example) mAccountRecyclerAdapter = new AccountRecyclerAdapter(null); } @@ -219,12 +224,12 @@ public void onResume() { } @Override - public void onAttach(Activity activity) { - super.onAttach(activity); + public void onAttach(@NonNull Context context) { + super.onAttach(context); try { - mAccountSelectedListener = (OnAccountClickedListener) activity; + mAccountSelectedListener = (OnAccountClickedListener) context; } catch (ClassCastException e) { - throw new ClassCastException(activity.toString() + " must implement OnAccountSelectedListener"); + throw new ClassCastException(context + " must implement OnAccountSelectedListener"); } } diff --git a/app/src/main/java/org/gnucash/android/ui/budget/BudgetAmountEditorFragment.java b/app/src/main/java/org/gnucash/android/ui/budget/BudgetAmountEditorFragment.java index d592dfe11..1ec4aab59 100644 --- a/app/src/main/java/org/gnucash/android/ui/budget/BudgetAmountEditorFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/budget/BudgetAmountEditorFragment.java @@ -95,7 +95,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) { public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); + ActionBar actionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar(); assert actionBar != null; actionBar.setTitle("Edit Budget Amounts"); diff --git a/app/src/main/java/org/gnucash/android/ui/budget/BudgetDetailFragment.java b/app/src/main/java/org/gnucash/android/ui/budget/BudgetDetailFragment.java index e65b860c7..11a82dbe7 100644 --- a/app/src/main/java/org/gnucash/android/ui/budget/BudgetDetailFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/budget/BudgetDetailFragment.java @@ -144,7 +144,7 @@ public void onResume() { public void refresh() { bindViews(); String budgetName = mBudgetsDbAdapter.getAttribute(mBudgetUID, DatabaseSchema.BudgetEntry.COLUMN_NAME); - ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); + ActionBar actionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar(); assert actionBar != null; actionBar.setTitle("Budget: " + budgetName); } diff --git a/app/src/main/java/org/gnucash/android/ui/budget/BudgetFormFragment.java b/app/src/main/java/org/gnucash/android/ui/budget/BudgetFormFragment.java index b23d85013..db2219ebc 100644 --- a/app/src/main/java/org/gnucash/android/ui/budget/BudgetFormFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/budget/BudgetFormFragment.java @@ -128,7 +128,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat if (budgetUID != null) { //if we are editing the budget initViews(mBudget = mBudgetsDbAdapter.getRecord(budgetUID)); } - ActionBar actionbar = ((AppCompatActivity) getActivity()).getSupportActionBar(); + ActionBar actionbar = ((AppCompatActivity) requireActivity()).getSupportActionBar(); assert actionbar != null; if (mBudget == null) actionbar.setTitle("Create Budget"); diff --git a/app/src/main/java/org/gnucash/android/ui/budget/BudgetListFragment.java b/app/src/main/java/org/gnucash/android/ui/budget/BudgetListFragment.java index 296df534f..a54697d68 100644 --- a/app/src/main/java/org/gnucash/android/ui/budget/BudgetListFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/budget/BudgetListFragment.java @@ -33,6 +33,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.PopupMenu; import androidx.fragment.app.Fragment; @@ -134,8 +135,9 @@ public void onLoaderReset(@NonNull Loader arg0) { public void onResume() { super.onResume(); refresh(); - getActivity().findViewById(R.id.fab_create_budget).setVisibility(View.VISIBLE); - ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle("Budgets"); + requireActivity().findViewById(R.id.fab_create_budget).setVisibility(View.VISIBLE); + ActionBar actionbar = ((AppCompatActivity) requireActivity()).getSupportActionBar(); + actionbar.setTitle("Budgets"); } @Override diff --git a/app/src/main/java/org/gnucash/android/ui/export/ExportFormFragment.java b/app/src/main/java/org/gnucash/android/ui/export/ExportFormFragment.java index 6ee8e880a..2ad4652f1 100644 --- a/app/src/main/java/org/gnucash/android/ui/export/ExportFormFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/export/ExportFormFragment.java @@ -202,6 +202,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); + AppCompatActivity activity = (AppCompatActivity) requireActivity(); + ActionBar actionBar = activity.getSupportActionBar(); + assert actionBar != null; + actionBar.setTitle(R.string.title_export_dialog); Bundle args = getArguments(); if ((args == null) || args.isEmpty()) { @@ -315,16 +319,6 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) { } } - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - AppCompatActivity activity = (AppCompatActivity) requireActivity(); - ActionBar actionBar = activity.getSupportActionBar(); - assert actionBar != null; - actionBar.setTitle(R.string.title_export_dialog); - } - @Override public void onResume() { super.onResume(); diff --git a/app/src/main/java/org/gnucash/android/ui/report/BaseReportFragment.java b/app/src/main/java/org/gnucash/android/ui/report/BaseReportFragment.java index 1300b9b58..a1c0f1d4f 100644 --- a/app/src/main/java/org/gnucash/android/ui/report/BaseReportFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/report/BaseReportFragment.java @@ -185,6 +185,14 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, return view; } + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + ActionBar actionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar(); + assert actionBar != null; + actionBar.setTitle(getTitle()); + } + @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -197,11 +205,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) { public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); - assert actionBar != null; - actionBar.setTitle(getTitle()); - - ReportsActivity reportsActivity = (ReportsActivity) getActivity(); + ReportsActivity reportsActivity = (ReportsActivity) requireActivity(); mReportPeriodStart = reportsActivity.getReportPeriodStart(); mReportPeriodEnd = reportsActivity.getReportPeriodEnd(); mAccountType = reportsActivity.getAccountType(); diff --git a/app/src/main/java/org/gnucash/android/ui/settings/AboutPreferenceFragment.java b/app/src/main/java/org/gnucash/android/ui/settings/AboutPreferenceFragment.java index 69369fcc9..ea0ba5e53 100644 --- a/app/src/main/java/org/gnucash/android/ui/settings/AboutPreferenceFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/settings/AboutPreferenceFragment.java @@ -17,7 +17,10 @@ package org.gnucash.android.ui.settings; import android.os.Bundle; +import android.view.View; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.preference.Preference; @@ -41,14 +44,13 @@ public void onCreatePreferences(Bundle bundle, String s) { } @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + ActionBar actionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar(); + assert actionBar != null; actionBar.setHomeButtonEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setTitle(R.string.title_about_gnucash); - } @Override diff --git a/app/src/main/java/org/gnucash/android/ui/settings/AccountPreferencesFragment.java b/app/src/main/java/org/gnucash/android/ui/settings/AccountPreferencesFragment.java index 9ccb5507f..da5c72b86 100644 --- a/app/src/main/java/org/gnucash/android/ui/settings/AccountPreferencesFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/settings/AccountPreferencesFragment.java @@ -21,8 +21,11 @@ import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; +import android.view.View; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.preference.ListPreference; @@ -71,10 +74,6 @@ public void onCreatePreferences(Bundle bundle, String s) { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); - assert actionBar != null; - actionBar.setTitle(R.string.title_account_preferences); - List commodities = CommoditiesDbAdapter.getInstance().getAllRecords(); for (Commodity commodity : commodities) { String code = commodity.getCurrencyCode(); @@ -84,6 +83,14 @@ public void onCreate(Bundle savedInstanceState) { } } + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + ActionBar actionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar(); + assert actionBar != null; + actionBar.setTitle(R.string.title_account_preferences); + } + @Override public void onResume() { super.onResume(); diff --git a/app/src/main/java/org/gnucash/android/ui/settings/BackupPreferenceFragment.java b/app/src/main/java/org/gnucash/android/ui/settings/BackupPreferenceFragment.java index 8dd26d87e..73fcd35ac 100644 --- a/app/src/main/java/org/gnucash/android/ui/settings/BackupPreferenceFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/settings/BackupPreferenceFragment.java @@ -33,6 +33,8 @@ import android.widget.ArrayAdapter; import android.widget.Toast; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; @@ -100,11 +102,15 @@ public void onCreatePreferences(Bundle bundle, String s) { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + mGoogleApiClient = getGoogleApiClient(requireContext()); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); ActionBar actionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar(); assert actionBar != null; actionBar.setTitle(R.string.title_backup_prefs); - - mGoogleApiClient = getGoogleApiClient(getActivity()); } @Override diff --git a/app/src/main/java/org/gnucash/android/ui/settings/BookManagerFragment.java b/app/src/main/java/org/gnucash/android/ui/settings/BookManagerFragment.java index c000f3b10..580ff0251 100644 --- a/app/src/main/java/org/gnucash/android/ui/settings/BookManagerFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/settings/BookManagerFragment.java @@ -87,6 +87,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setHasOptionsMenu(true); mCursorAdapter = new BooksCursorAdapter(requireContext(), R.layout.cardview_book, null, new String[]{BookEntry.COLUMN_DISPLAY_NAME, BookEntry.COLUMN_SOURCE_URI}, @@ -96,13 +97,11 @@ public void onCreate(@Nullable Bundle savedInstanceState) { } @Override - public void onActivityCreated(@Nullable Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + ActionBar actionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar(); assert actionBar != null; actionBar.setTitle(R.string.title_manage_books); - setHasOptionsMenu(true); getListView().setChoiceMode(ListView.CHOICE_MODE_NONE); } diff --git a/app/src/main/java/org/gnucash/android/ui/settings/GeneralPreferenceFragment.java b/app/src/main/java/org/gnucash/android/ui/settings/GeneralPreferenceFragment.java index 1d745b530..2fc69f6f5 100644 --- a/app/src/main/java/org/gnucash/android/ui/settings/GeneralPreferenceFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/settings/GeneralPreferenceFragment.java @@ -20,9 +20,11 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.view.View; import android.widget.Toast; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.preference.Preference; @@ -60,10 +62,9 @@ public void onCreatePreferences(Bundle bundle, String s) { } @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + ActionBar actionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar(); assert actionBar != null; actionBar.setTitle(R.string.title_general_prefs); } diff --git a/app/src/main/java/org/gnucash/android/ui/settings/PreferenceActivity.java b/app/src/main/java/org/gnucash/android/ui/settings/PreferenceActivity.java index 4f28563f6..6070f1c0b 100644 --- a/app/src/main/java/org/gnucash/android/ui/settings/PreferenceActivity.java +++ b/app/src/main/java/org/gnucash/android/ui/settings/PreferenceActivity.java @@ -39,7 +39,6 @@ import org.gnucash.android.R; import org.gnucash.android.app.GnuCashApplication; import org.gnucash.android.databinding.ActivitySettingsBinding; -import org.gnucash.android.db.adapter.BooksDbAdapter; import org.gnucash.android.ui.passcode.PasscodeLockActivity; import timber.log.Timber; @@ -135,6 +134,10 @@ private void handleBackPressed() { FragmentManager fm = getSupportFragmentManager(); if (fm.getBackStackEntryCount() > 0) { fm.popBackStack(); + + ActionBar actionBar = getSupportActionBar(); + assert actionBar != null; + actionBar.setTitle(R.string.title_settings); } else { finish(); } diff --git a/app/src/main/java/org/gnucash/android/ui/settings/TransactionsPreferenceFragment.java b/app/src/main/java/org/gnucash/android/ui/settings/TransactionsPreferenceFragment.java index 2676e4e8e..267d7adcc 100644 --- a/app/src/main/java/org/gnucash/android/ui/settings/TransactionsPreferenceFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/settings/TransactionsPreferenceFragment.java @@ -19,7 +19,10 @@ import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; +import android.view.View; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.preference.Preference; @@ -47,8 +50,12 @@ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getPreferenceManager().setSharedPreferencesName(GnuCashApplication.getActiveBookUID()); + } - ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + ActionBar actionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar(); assert actionBar != null; actionBar.setTitle(R.string.title_transaction_preferences); } diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/ScheduledActionsListFragment.java b/app/src/main/java/org/gnucash/android/ui/transaction/ScheduledActionsListFragment.java index 6fd92e091..8a02163f8 100644 --- a/app/src/main/java/org/gnucash/android/ui/transaction/ScheduledActionsListFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/transaction/ScheduledActionsListFragment.java @@ -77,6 +77,11 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); + ActionBar actionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar(); + assert actionBar != null; + actionBar.setDisplayShowTitleEnabled(true); + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setHomeButtonEnabled(true); binding.list.setEmptyView(binding.empty); binding.list.setLayoutManager(new LinearLayoutManager(view.getContext())); @@ -85,17 +90,6 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat getLoaderManager().initLoader(0, null, this); } - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - AppCompatActivity activity = (AppCompatActivity) requireActivity(); - ActionBar actionBar = activity.getSupportActionBar(); - actionBar.setDisplayShowTitleEnabled(true); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setHomeButtonEnabled(true); - } - @Override public void refresh() { getLoaderManager().restartLoader(0, null, this); diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java index c941fa29a..997d72333 100644 --- a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionFormFragment.java @@ -205,6 +205,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); + ActionBar actionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar(); + assert actionBar != null; + if (mEditMode) { + actionBar.setTitle(R.string.title_edit_transaction); + } else { + actionBar.setTitle(R.string.title_add_transaction); + } + setListeners(); //updateTransferAccountsList must only be called after initializing mAccountsDbAdapter updateTransferAccountsList(); @@ -301,16 +309,6 @@ public void onCreate(@Nullable Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - ActionBar actionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar(); - assert actionBar != null; -// actionBar.setSubtitle(mAccountsDbAdapter.getFullyQualifiedAccountName(mAccountUID)); - - if (mEditMode) { - actionBar.setTitle(R.string.title_edit_transaction); - } else { - actionBar.setTitle(R.string.title_add_transaction); - } - requireActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); } @@ -587,6 +585,13 @@ private void openSplitEditor() { * Sets click listeners for the dialog buttons */ private void setListeners() { + mBinding.btnSplitEditor.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + openSplitEditor(); + } + }); + mBinding.inputTransactionType.setAmountFormattingListener(mBinding.inputTransactionAmount, mBinding.currencySymbol); mBinding.inputDate.setOnClickListener(new View.OnClickListener() { diff --git a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionsListFragment.java b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionsListFragment.java index 575454173..91ef6bf2e 100644 --- a/app/src/main/java/org/gnucash/android/ui/transaction/TransactionsListFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/transaction/TransactionsListFragment.java @@ -120,6 +120,18 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, mBinding = FragmentTransactionsListBinding.inflate(inflater, container, false); View view = mBinding.getRoot(); + + return view; + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + ActionBar actionBar = ((AppCompatActivity) requireActivity()).getSupportActionBar(); + assert actionBar != null; + actionBar.setDisplayShowTitleEnabled(false); + actionBar.setDisplayHomeAsUpEnabled(true); + mBinding.list.setHasFixedSize(true); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 2); @@ -128,18 +140,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, LinearLayoutManager mLayoutManager = new LinearLayoutManager(getActivity()); mBinding.list.setLayoutManager(mLayoutManager); } - mBinding.list.setEmptyView(view.findViewById(R.id.empty_view)); - - return view; - } - - @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - ActionBar aBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); - aBar.setDisplayShowTitleEnabled(false); - aBar.setDisplayHomeAsUpEnabled(true); + mBinding.list.setEmptyView(mBinding.emptyView); mTransactionRecyclerAdapter = new TransactionRecyclerAdapter(null); mBinding.list.setAdapter(mTransactionRecyclerAdapter);