Skip to content

Commit

Permalink
Fixed: Overview and stock page not populated after theme change or ot…
Browse files Browse the repository at this point in the history
…her cases (closes #692 and #695)
  • Loading branch information
dominiczedler committed May 21, 2023
1 parent fb0d2ad commit 17cfcd2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
return false;
});

if (savedInstanceState == null) {
if (savedInstanceState == null || !viewModel.isAlreadyLoadedFromDatabase()) {
viewModel.loadFromDatabase(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public void instantiateUnderlayButton(

hideDisabledFeatures();

if (savedInstanceState == null) {
if (savedInstanceState == null || !viewModel.isAlreadyLoadedFromDatabase()) {
viewModel.loadFromDatabase(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public class OverviewStartViewModel extends BaseViewModel {
private final LiveData<String> masterDataDescriptionTextLive;
private final MutableLiveData<Integer> currentUserIdLive;
private List<ShoppingList> shoppingLists;
private boolean alreadyLoadedFromDatabase;
private final boolean debug;

public OverviewStartViewModel(@NonNull Application application) {
Expand Down Expand Up @@ -137,6 +138,7 @@ public OverviewStartViewModel(@NonNull Application application) {
choreEntriesLive = new MutableLiveData<>();
tasksLive = new MutableLiveData<>();
currentUserIdLive = new MutableLiveData<>(sharedPrefs.getInt(PREF.CURRENT_USER_ID, 1));
alreadyLoadedFromDatabase = false;

stockDescriptionTextLive = new MediatorLiveData<>();
stockDescriptionTextLive.addSource(
Expand Down Expand Up @@ -482,6 +484,7 @@ public void loadFromDatabase(boolean downloadAfterLoading) {
choresDueSoonCountLive.setValue(choresDueSoonCount);
choresDueTodayCountLive.setValue(choresDueTodayCount);

alreadyLoadedFromDatabase = true;
if (downloadAfterLoading) {
downloadData(false);
}
Expand Down Expand Up @@ -642,6 +645,10 @@ public MutableLiveData<Boolean> getStoredPurchasesOnDevice() {
return storedPurchasesOnDevice;
}

public boolean isAlreadyLoadedFromDatabase() {
return alreadyLoadedFromDatabase;
}

public boolean isFeatureEnabled(String pref) {
if (pref == null) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public class StockOverviewViewModel extends BaseViewModel {
private ArrayList<String> searchResultsFuzzy;
private final boolean debug;
private final int maxDecimalPlacesAmount;
private boolean alreadyLoadedFromDatabase;

public StockOverviewViewModel(@NonNull Application application, StockOverviewFragmentArgs args) {
super(application);
Expand All @@ -124,6 +125,7 @@ public StockOverviewViewModel(@NonNull Application application, StockOverviewFra
STOCK.DECIMAL_PLACES_AMOUNT,
SETTINGS_DEFAULT.STOCK.DECIMAL_PLACES_AMOUNT
);
alreadyLoadedFromDatabase = false;

isLoadingLive = new MutableLiveData<>(false);
dlHelper = new DownloadHelper(getApplication(), TAG, isLoadingLive::setValue);
Expand Down Expand Up @@ -259,6 +261,7 @@ public void loadFromDatabase(boolean downloadAfterLoading) {
.setOpenedCount(itemsOpenedCount)
.emitCounts();
updateFilteredStockItems();
alreadyLoadedFromDatabase = true;
if (downloadAfterLoading) {
downloadData(false);
}
Expand Down Expand Up @@ -724,6 +727,10 @@ public void toggleScannerVisibility() {
scannerVisibilityLive.setValue(!isScannerVisible());
}

public boolean isAlreadyLoadedFromDatabase() {
return alreadyLoadedFromDatabase;
}

@NonNull
public MutableLiveData<Boolean> getOfflineLive() {
return offlineLive;
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/raw/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Fixed: Random crash with no reason (#699)
- Fixed: Prevent another crash after reopening app from background (#697)
- Fixed: Product pictures not loading (with Home Assistant or not, we don't know) (#700)
- Fixed: Overview and stock page not populated after theme change or other cases (#692, #695)

## 3.2.0

Expand Down

0 comments on commit 17cfcd2

Please sign in to comment.