Blame view

footsafety/app/src/main/java/etelligens/com/foodsafety/adapter/UserLoginOutlet.java 3.1 KB
f7a13682   “wangming”   项目初始化
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
  package etelligens.com.foodsafety.adapter;
  
  import android.content.Context;
  import android.content.SharedPreferences;
  
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.RelativeLayout;
  import android.widget.TextView;
  
  import androidx.annotation.NonNull;
  import androidx.recyclerview.widget.RecyclerView;
  
  import com.android.volley.toolbox.StringRequest;
  import com.google.gson.Gson;
  import com.google.gson.reflect.TypeToken;
  
  import java.lang.reflect.Type;
  import java.util.ArrayList;
  
  import etelligens.com.foodsafety.R;
  import etelligens.com.foodsafety.activities.lables.backEnd.ProductCatListBackend;
  import etelligens.com.foodsafety.model.UserLoginOutletModel;
  
  public class UserLoginOutlet extends RecyclerView.Adapter<UserLoginOutlet.ProgrammingViewHolder> {
      ArrayList<UserLoginOutletModel> models;
      Context context;
      PassData passData;
      String getOutletIdsFromSh, getOutletID = "empty";
  
      public UserLoginOutlet(Context context, ArrayList<UserLoginOutletModel> models, PassData passData) {
          this.models = models;
          this.context = context;
          this.passData = passData;
      }
  
      public interface PassData {
          void dataClickAble(UserLoginOutletModel model);
      }
  
      View view;
  
      @NonNull
      @Override
      public UserLoginOutlet.ProgrammingViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
          view = LayoutInflater.from(context).inflate(R.layout.userlogin_outlet, viewGroup, false);
          return new ProgrammingViewHolder(view);
      }
  
      @Override
      public void onBindViewHolder(@NonNull final UserLoginOutlet.ProgrammingViewHolder holder, final int position) {
  
          final UserLoginOutletModel model = models.get(position);
  
          String name = model.getName();
          final String id = String.valueOf(model.getId());
          if (name != null) {
  
              holder.textoutlet.setText(name);
          }
          SharedPreferences outletData = context.getSharedPreferences("OutletIDData", Context.MODE_PRIVATE);
          getOutletIdsFromSh = outletData.getString("OutletID", null);
          if (getOutletIdsFromSh != null)
              if (getOutletIdsFromSh.equals(id)) {
                  if (holder.rlcheckedlayout.getVisibility() != View.VISIBLE) {
                      holder.rlcheckedlayout.setVisibility(View.VISIBLE);
                  }
              }
          holder.rlitemlayout.setOnClickListener(v -> {
              holder.rlcheckedlayout.setVisibility(View.VISIBLE);
              passData.dataClickAble(model);
  //            models.clear();
          });
  
      }
  
      @Override
      public int getItemCount() {
          return models.size();
      }
  
      public class ProgrammingViewHolder extends RecyclerView.ViewHolder {
          RelativeLayout rlitemlayout, rlcheckedlayout;
          TextView textoutlet;
  
          public ProgrammingViewHolder(@NonNull View itemView) {
              super(itemView);
              rlitemlayout = itemView.findViewById(R.id.rl_item_layout);
              textoutlet = itemView.findViewById(R.id.list_outlet);
              rlcheckedlayout = itemView.findViewById(R.id.rl_checked_layout);
          }
      }
  }