Administrator
2021-10-25 7475bfeadee82878faf2188665ae5ae83875835c
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 com.duqing.missions.ui.home;
 
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
 
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
 
import com.duqing.missions.R;
import com.duqing.missions.databinding.FragmentHomeBinding;
import com.scwang.smart.refresh.header.ClassicsHeader;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
 
public class HomeFragment extends Fragment {
 
    private HomeViewModel homeViewModel;
    private FragmentHomeBinding binding;
 
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        homeViewModel = new ViewModelProvider(this).get(HomeViewModel.class);
 
        binding = FragmentHomeBinding.inflate(inflater, container, false);
        View root = binding.getRoot();
        final SmartRefreshLayout smartRefresh = binding.smartRefresh;
        smartRefresh.setRefreshHeader(new ClassicsHeader(getContext()));
        final  TextView textView = binding.textRecommend;
        final ImageView imgSearch = binding.imgSearch;
        RecyclerView recyclerClassify = binding.recyclerClassify;
        RecyclerView recyclerTop = binding.recyclerTop;
        final RecyclerView recyclerRecommend = binding.recyclerRecommend;
        recyclerRecommend.setLayoutManager(new LinearLayoutManager(getContext()));
        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerClassify.setLayoutManager(layoutManager);
        recyclerTop.setLayoutManager(new GridLayoutManager(getContext(),3));
 
        homeViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
            @Override
            public void onChanged(@Nullable String s) {
                textView.setText(s);
            }
        });
        return root;
    }
 
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }
}