blob: d00ce05dd317a92e79032d8211f67e75e761e030 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
package it.niedermann.nextcloud.deck.ui.card.activities;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import it.niedermann.nextcloud.deck.DeckLog;
import it.niedermann.nextcloud.deck.databinding.FragmentCardEditTabActivitiesBinding;
import it.niedermann.nextcloud.deck.ui.card.EditCardViewModel;
public class CardActivityFragment extends Fragment {
private FragmentCardEditTabActivitiesBinding binding;
public static Fragment newInstance() {
return new CardActivityFragment();
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
binding = FragmentCardEditTabActivitiesBinding.inflate(inflater, container, false);
final var viewModel = new ViewModelProvider(requireActivity()).get(EditCardViewModel.class);
// This might be a zombie fragment with an empty EditCardViewModel after Android killed the activity (but not the fragment instance
// See https://github.com/stefan-niedermann/nextcloud-deck/issues/478
if (viewModel.getFullCard() == null) {
DeckLog.logError(new IllegalStateException("Cannot populate " + CardActivityFragment.class.getSimpleName() + " because viewModel.getFullCard() is null"));
return binding.getRoot();
}
viewModel.syncActivitiesForCard(viewModel.getFullCard().getCard()).observe(getViewLifecycleOwner(), (activities -> {
if (activities == null || activities.size() == 0) {
binding.emptyContentView.setVisibility(View.VISIBLE);
binding.activitiesList.setVisibility(View.GONE);
} else {
binding.emptyContentView.setVisibility(View.GONE);
binding.activitiesList.setVisibility(View.VISIBLE);
binding.activitiesList.setAdapter(new CardActivityAdapter(activities, requireActivity().getMenuInflater()));
}
}));
return binding.getRoot();
}
}
|