Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CardActivityFragment.java « activities « card « ui « deck « nextcloud « niedermann « it « java « main « src « app - github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 08d960257a5f551ba097e98699df6ef1a30b8adb (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
52
53
54
55
56
57
58
59
60
61
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 androidx.recyclerview.widget.RecyclerView;

import it.niedermann.nextcloud.deck.DeckLog;
import it.niedermann.nextcloud.deck.databinding.FragmentCardEditTabActivitiesBinding;
import it.niedermann.nextcloud.deck.persistence.sync.SyncManager;
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 EditCardViewModel 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();
        }

        if (!viewModel.isCreateMode()) {
            final SyncManager syncManager = new SyncManager(requireContext());

            syncManager.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);
                    RecyclerView.Adapter adapter = new CardActivityAdapter(activities, requireActivity().getMenuInflater());
                    binding.activitiesList.setAdapter(adapter);
                }
            }));
        } else {
            binding.emptyContentView.setVisibility(View.VISIBLE);
            binding.activitiesList.setVisibility(View.GONE);
        }
        return binding.getRoot();
    }
}