-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLAdapter.java
103 lines (89 loc) · 3.3 KB
/
LAdapter.java
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
95
96
97
98
99
100
101
102
103
package com.example.foredownload1.adpter;
import android.annotation.SuppressLint;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.foredownload1.R;
import com.example.foredownload1.models.ProgessModle;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class LAdapter extends RecyclerView.Adapter<LAdapter.ViewHolder> {
List<ProgessModle> applist = new ArrayList<>();
Map<Integer,ProgressBar> progresslist = new HashMap<>();
private int id = 0;
//Map<String,Integer> tag = new LinkedHashMap<>();
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ViewHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.item,parent,false));
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.textView.setText(applist.get(position).getAppname());
// holder.progress.setText("progress"+applist.get(position).getProgress());
// holder.itemView.setTag(position);
progresslist.put(position,holder.downlownBar);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
remove((Integer) v.getTag());
}
});
}
@Override
public int getItemCount() {
return applist.size();
}
public void setApplist(List<String> appnlist) {
this.applist = applist;
}
/*
public void setProgress(int progress, String appname){
Log.d("ww", "setProgress: "+ appname);
for(ProgessModle progessModle:applist){
Log.d("ww", "setProgress: "+progessModle.getAppname());
if(progessModle.getAppname().equals(appname)){
progessModle.setProgress(progress);
System.out.println(appname+progress);
notifyItemChanged(progessModle.getPosition());
break;
}
}
}
*/
public void setProgrss(int progrss,int id){
System.out.println("id" + id);
ProgressBar progressBar = progresslist.get(id-1);
progressBar.setProgress(progrss);
}
public void add(String appname) {
applist.add(new ProgessModle(0,appname,id));
id++;
System.out.println(applist.get(id-1).appname);
notifyDataSetChanged();
}
public void remove(Integer id){
applist.remove(id);
notifyDataSetChanged();
}
class ViewHolder extends RecyclerView.ViewHolder{
TextView textView;
TextView progress;
ProgressBar downlownBar;
public ViewHolder(@NonNull View itemView) {
super(itemView);
textView = itemView.findViewById(R.id.appname);
// progress = itemView.findViewById(R.id.appprogress);
downlownBar = itemView.findViewById(R.id.progressBar);
}
}
}