Skip to content

Commit

Permalink
Action bar ready when view ready.
Browse files Browse the repository at this point in the history
  • Loading branch information
pnemonic78 committed Jan 2, 2025
1 parent f78ec11 commit 82c6ade
Show file tree
Hide file tree
Showing 18 changed files with 128 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -284,7 +279,6 @@ public void onActivityCreated(Bundle savedInstanceState) {
} else {
initializeViews();
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -171,7 +183,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
LinearLayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
mBinding.list.setLayoutManager(mLayoutManager);
}
return mBinding.getRoot();
}

@Override
Expand All @@ -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);
}
Expand All @@ -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");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -134,8 +135,9 @@ public void onLoaderReset(@NonNull Loader<Cursor> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Commodity> commodities = CommoditiesDbAdapter.getInstance().getAllRecords();
for (Commodity commodity : commodities) {
String code = commodity.getCurrencyCode();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit 82c6ade

Please sign in to comment.