Skip to content

Commit

Permalink
Refresh list in uncompleted events list on edits
Browse files Browse the repository at this point in the history
  • Loading branch information
dgudim committed Jan 15, 2024
1 parent 0402c1b commit 5679b7b
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package prototype.xd.scheduler.entities;

import android.content.Context;
import android.util.ArraySet;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.collection.ArraySet;

import java.io.IOException;
import java.io.ObjectInputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void handleOnBackPressed() {
CalendarView calendarView = new CalendarView(contentBnd.content.calendar, todoEntryManager);
todoEntryManager.attachCalendarView(calendarView, wrapper.lifecycle);
// when all entries are loaded and ui is created, setup listeners, todoEntryManager also updates the data
todoEntryManager.onInitFinished(this, el -> {
todoEntryManager.onInitFinished(getViewLifecycleOwner(), el -> {
setupListeners(contentBnd, binding.navView, calendarView, wrapper.activity);
binding.contentWrapper.content.progressBar.setVisibility(View.GONE);
});
Expand All @@ -138,7 +138,7 @@ private void setupListeners(@NonNull ContentWrapperBinding contentBnd,
todoEntryManager.notifyEntryListChanged();
});

todoEntryManager.onListChanged(this, status -> {
todoEntryManager.onListChanged(getViewLifecycleOwner(), status -> {
todoListViewAdapter.notifyEntryListChanged();
// update the status text with entry count
int events = todoListViewAdapter.getItemCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ protected void buildDialogBody(@NonNull ListViewBinding binding) {

ArrayList<GenericCalendarSettingsEntryConfig> calendarEntryList = new ArrayList<>(calendarGroup.size() + 1);
SettingsListViewAdapter calendarEntryListAdapter = new SettingsListViewAdapter(wrapper, calendarEntryList, true);
// TODO: enable stable ids + fixedSize for recyclerview everywhere

calendarEntryList.add(new CalendarAccountSettingsEntryConfig(
calendarGroup.get(0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,30 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.collection.ArraySet;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import prototype.xd.scheduler.R;
import prototype.xd.scheduler.adapters.TodoListViewAdapter;
import prototype.xd.scheduler.databinding.ListViewBinding;
import prototype.xd.scheduler.entities.TodoEntry;
import prototype.xd.scheduler.utilities.TodoEntryManager;
import prototype.xd.scheduler.utilities.misc.ContextWrapper;

public class UncompletedEntryListDialogFragment extends AlertSettingsDialogFragment<ListViewBinding> {
public class UncompletedEntryListDialogFragment extends AlertSettingsDialogFragment<ListViewBinding> { // NOSONAR

public static void show(@NonNull ContextWrapper wrapper) {
new UncompletedEntryListDialogFragment().show(wrapper.childFragmentManager, "uncompleted_entry_list");
}

@NonNull
private final Set<TodoEntry> originalEntries = new ArraySet<>();

@Override
protected void setVariablesFromData() {
// No variables
Expand All @@ -40,28 +44,32 @@ protected ListViewBinding inflate(@NonNull LayoutInflater inflater, @Nullable Vi
return ListViewBinding.inflate(inflater, container, false);
}

/**
* @noinspection CollectionWithoutInitialCapacity
*/
@Override
protected void buildDialogBody(@NonNull ListViewBinding binding) {
int pad = dpToPx(9);
binding.recyclerView.setPadding(0, 0, 0, pad);
binding.recyclerView.addItemDecoration(getRecyclerviewGap(wrapper, LinearLayout.VERTICAL, R.dimen.list_item_vertical_padding));
var adapter = new TodoListViewAdapter(wrapper);
adapter.setListSupplier(todoEntryManager -> {
var entryAdapter = new TodoListViewAdapter(wrapper);
entryAdapter.setListSupplier(todoEntryManager -> {
Collection<TodoEntry> entryList = todoEntryManager.getRegularTodoEntries();
List<TodoEntry> filteredEntryList = new ArrayList<>();
Set<TodoEntry> filteredEntryList = new ArraySet<>();
for (var entry : entryList) {
if (!entry.isCompleted() && !entry.isGlobal()) {
if ((!entry.isCompleted() && !entry.isGlobal())
|| originalEntries.contains(entry)) {
filteredEntryList.add(entry);
}
}
if (originalEntries.isEmpty()) {
originalEntries.addAll(filteredEntryList);
}
return filteredEntryList;
});
binding.recyclerView.setAdapter(adapter);
binding.recyclerView.setHasFixedSize(true);
binding.recyclerView.setAdapter(entryAdapter);
binding.recyclerView.setItemAnimator(null);
binding.recyclerView.setLayoutManager(new LinearLayoutManager(wrapper.context));

// Update adapter after list update
TodoEntryManager.getInstance(wrapper.context).onListChanged(this, aBoolean -> entryAdapter.notifyEntryListChanged());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,8 @@ public enum GlobalLabelPos {FRONT, BACK, HIDDEN}

private static final DefaultedBoolean SERVICE_UPDATE_SIGNAL = new DefaultedBoolean("update_lockscreen", false);
public static final DefaultedBoolean DEBUG_LOGGING = new DefaultedBoolean("debug_logging", false);
public static final DefaultedBoolean DEBUG_UNCOMPLETED_UPDATE_IMMEDIATELY = new DefaultedBoolean("debug_uncompleted_display_immediately", false);

public static final String SERVICE_KEEP_ALIVE_SIGNAL = "keep_alive";
public static final DefaultedBoolean SERVICE_FAILED = new DefaultedBoolean("service_failed", false);
public static final DefaultedBoolean WALLPAPER_OBTAIN_FAILED = new DefaultedBoolean("wallpaper_obtain_failed", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import androidx.annotation.Nullable;
import androidx.collection.ArrayMap;
import androidx.collection.ArraySet;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
Expand Down Expand Up @@ -142,8 +141,8 @@ public boolean isInitialized() {
return initFinished.getValue();
}

public void onInitFinished(@NonNull Fragment frag, @NonNull Observer<Boolean> observer) {
initFinished.observe(frag.getViewLifecycleOwner(), el -> {
public void onInitFinished(@NonNull LifecycleOwner owner, @NonNull Observer<Boolean> observer) {
initFinished.observe(owner, el -> {
observer.onChanged(el);
// update adapter showing entries
notifyEntryListChanged();
Expand All @@ -152,8 +151,8 @@ public void onInitFinished(@NonNull Fragment frag, @NonNull Observer<Boolean> ob
});
}

public void onListChanged(@NonNull Fragment frag, @NonNull Observer<Boolean> observer) {
listChanged.observe(frag.getViewLifecycleOwner(), observer);
public void onListChanged(@NonNull LifecycleOwner owner, @NonNull Observer<Boolean> observer) {
listChanged.observe(owner, observer);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -249,5 +249,5 @@
<string name="uncompleted_events">Незавершенные события</string>
<string name="view_uncompleted_events">Просмотреть незавершенные события</string>
<string name="view_uncompleted_events_description">Получить список всех незавершенных событий</string>
<string name="view_uncompleted_events_description_dialog">События, отмеченные/измененные здесь, будут завершены/изменены после закрытия диалога</string>
<string name="view_uncompleted_events_description_dialog">Здесь вы можете управлять всеми своими, возможно, забытыми незавершенными событиями.</string>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -249,5 +249,5 @@
<string name="uncompleted_events">Незавершені події</string>
<string name="view_uncompleted_events">Переглянути незавершені події</string>
<string name="view_uncompleted_events_description">Отримати список усіх незавершених подій</string>
<string name="view_uncompleted_events_description_dialog">Події, зазначені/змінені тут, будуть завершені/змінені після закриття діалогу</string>
<string name="view_uncompleted_events_description_dialog">Тут ви можете керувати всіма своїми, можливо, забутими незавершеними подіями.</string>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,5 +248,5 @@
<string name="uncompleted_events">Uncompleted events</string>
<string name="view_uncompleted_events">View uncompleted events</string>
<string name="view_uncompleted_events_description">Get a list of all uncompleted events</string>
<string name="view_uncompleted_events_description_dialog">Events marked/changed here will be completed/changed after closing the dialog</string>
<string name="view_uncompleted_events_description_dialog">Here you can manage all your maybe-forgotten uncompleted events</string>
</resources>

0 comments on commit 5679b7b

Please sign in to comment.