Привет в приведенной ниже задаче содержит некоторый список элементов. Я звоню в Api и разыскиваю данные, а затем настраиваю адаптер и отображаю его в перечне утилит.
Но список подходит идеально. Для его отображения требуется слишком много времени. Все, что от Api - это строки и объекты. Нет файлов или изображений
Для отображения списка требуется время. Я хочу, чтобы отображение отображалось очень быстро
Может ли кто-нибудь помочь мне где я сделал ошибку или дал какое-то предложение
TaskFragment. java:
public class TaskFragement extends Fragment {
private TaskAdapter taskAdapter;
private RecyclerView recyclerViewTask;
Fragment fragment;
String sessionId;
SharedPreferences sharedPreferences;
SharedPreferences.Editor editor;
String mobie;
private ArrayList<TaskModel> listTask;
Gson gson;
private Object values;
public static final String ARG_PAGE = "ARG_PAGE";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
((AppCompatActivity) getActivity()).getSupportActionBar().setTitle("Task List");
View rootView = inflater.inflate(R.layout.account, container, false);
FloatingActionButton fb= rootView.findViewById(R.id.fab);
fb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((AppCompatActivity) getActivity()).getSupportActionBar().setTitle("Create New Task");
fragment = new TaskCreateFragement();
sessionId = getActivity().getIntent().getStringExtra("sessionId");
loadFragment(fragment);
}
});
recyclerViewTask = rootView.findViewById(R.id.recyclerOpportunity);
listTask = new ArrayList<>();
taskAdapter = new TaskAdapter(requireContext(),listTask);
recyclerViewTask.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
taskAdapter.notifyDataSetChanged();
fetchJSON();
return rootView;
}
private void loadFragment(Fragment fragment) {
// load fragment
FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.frame_container, fragment);
transaction.addToBackStack(null);
transaction.commit();
}
private void fetchJSON(){
sessionId = getActivity().getIntent().getStringExtra("sessionId");
String operation = "syncModuleRecords";
String module = "Calendar";
String syncToken="";
String mode="public";
final GetNoticeDataService service = RetrofitInstance.getRetrofitInstance().create(GetNoticeDataService.class);
/** Call the method with parameter in the interface to get the notice data*/
Call<SyncModule> call = service.GetSyncModuleList(operation, sessionId, module,syncToken,mode);
/**Log the URL called*/
Log.i("URL Called", call.request().url() + "");
call.enqueue(new Callback<SyncModule>() {
@Override
public void onResponse(Call<SyncModule> call, Response<SyncModule> response) {
Log.e("response", new Gson().toJson(response.body()));
if (response.isSuccessful()) {
Log.e("response", new Gson().toJson(response.body()));
SyncModule syncModule = response.body();
String success = syncModule.getSuccess();
if (success.equals("true")) {
SyncResults results = syncModule.getResult();
Sync sync = results.getSync();
ArrayList<SyncUpdated> syncUpdateds = sync.getUpdated();
for (SyncUpdated syncUpdated : syncUpdateds) {
ArrayList<SyncBlocks> syncBlocks = syncUpdated.getBlocks();
String value = "";
String subject = "";
String taskType = "";
String assigned = "";
String scheduleDate = "";
String location = "";
String opportunityNo = "";
String status = "";
String outcome = "";
for (SyncBlocks syncBlocks1 : syncBlocks) {
String label = syncBlocks1.getLabel();
if (label.equals("Task Details")) {
ArrayList<SynFields> synFields = syncBlocks1.getFields();
for (SynFields synFields1 : synFields) {
String name = synFields1.getName();
values = synFields1.getValue();
if (name.equals("subject")) {
subject = String.valueOf(values);
} else if (name.equals("cf_956")) {
taskType = String.valueOf(values);
} else if (name.equals("assigned_user_id")) {
try {
Gson gson = new Gson();
String strJson = gson.toJson(values);
JSONObject jsonObject = new JSONObject(strJson);
String v = jsonObject.getString("label");
//
assigned = v;
} catch (Exception ex) {
Log.e("SalesStageFragment", "Exception is : " + ex.toString());
}
} else if (name.equals("potential")) {
try {
Gson gson = new Gson();
String strJson = gson.toJson(values);
JSONObject jsonObject = new JSONObject(strJson);
String v = jsonObject.getString("label");
// assigned_tos.add(v);
opportunityNo = v;
} catch (Exception ex) {
Log.e("SalesStageFragment", "Exception is : " + ex.toString());
}
} else if (name.equals("date_start")) {
scheduleDate = String.valueOf(values);
} else if (name.equals("taskstatus")) {
status = String.valueOf(values);
} else if (name.equals("location")) {
location = String.valueOf(values);
}
else if (name.equals("cf_1015")) {
outcome = String.valueOf(values);
}
}
}
}
TaskModel taskModel = new TaskModel(subject,taskType,assigned,scheduleDate,location,opportunityNo,status,outcome);
listTask.add(taskModel);
recyclerViewTask.setAdapter(taskAdapter);
}
}
}
}
@Override
public void onFailure(Call<SyncModule> call, Throwable t) {
Log.d("error", t.getMessage());
}
});
}
}
TaskAdapter. java:
public class TaskAdapter extends RecyclerView.Adapter<TaskAdapter.MyViewHolder> {
private LayoutInflater inflater;
private Context mContext;
private ArrayList<TaskModel> tasklist;
public TaskAdapter(Context context, ArrayList<TaskModel> tasklist) {
mContext=context;
this.tasklist=tasklist;
}
@Override
public TaskAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Context context = parent.getContext();
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.fragment_task, parent, false);
TaskAdapter.MyViewHolder holder = new TaskAdapter.MyViewHolder(view);
return holder;
}
@Override
public void onBindViewHolder(TaskAdapter.MyViewHolder holder, final int position) {
holder.subject.setText(tasklist.get(position).getSubject());
holder.task_type.setText(tasklist.get(position).getTaskType());
holder.assigned_to.setText(tasklist.get(position).getAssigned());
// holder.related_to.setText(tasklist.get(position).);
holder.outcome.setText(tasklist.get(position).getOutcome());
holder.status.setText(tasklist.get(position).getStatus());
holder.location.setText(tasklist.get(position).getLocation());
holder.schedule_date.setText(tasklist.get(position).getScheduleDate());
holder.schedule_date.setBackgroundResource(R.color.password);
holder.opportunity.setText(tasklist.get(position).getOpportunityNo());
final String status = tasklist.get(position).getStatus();
if(status.equals("Scheduled")){
holder.status.setBackgroundResource(R.color.blue);
} else if(status.equals("Completed")){
holder.status.setBackgroundColor(ContextCompat.getColor(mContext, R.color.green));
} else if(status.equals("In Complete")){
holder.status.setBackgroundResource(R.color.red);
}
}
@Override
public int getItemCount() {
return tasklist.size();
}
class MyViewHolder extends RecyclerView.ViewHolder{
TextView subject, outcome, status,task_type,assigned_to,related_to,schedule_date,location,opportunity,bill_pin;
public MyViewHolder(View itemView) {
super(itemView);
subject= (TextView) itemView.findViewById(R.id.subject);
outcome = (TextView) itemView.findViewById(R.id.outcome);
status = (TextView) itemView.findViewById(R.id.status);
task_type = (TextView) itemView.findViewById(R.id.task_type);
assigned_to = (TextView) itemView.findViewById(R.id.assigned_to);
related_to = (TextView) itemView.findViewById(R.id.related_to);
schedule_date = (TextView) itemView.findViewById(R.id.schedule_date);
location = (TextView) itemView.findViewById(R.id.location);
opportunity = (TextView) itemView.findViewById(R.id.opp_no);
}
}
}
Modelclass:
public class TaskModel {
private String subject;
private String taskType;
private String assigned;
private String scheduleDate;
private String location;
private String opportunityNo;
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getTaskType() {
return taskType;
}
public void setTaskType(String taskType) {
this.taskType = taskType;
}
public String getAssigned() {
return assigned;
}
public void setAssigned(String assigned) {
this.assigned = assigned;
}
public String getScheduleDate() {
return scheduleDate;
}
public void setScheduleDate(String scheduleDate) {
this.scheduleDate = scheduleDate;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getOpportunityNo() {
return opportunityNo;
}
public void setOpportunityNo(String opportunityNo) {
this.opportunityNo = opportunityNo;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getOutcome() {
return outcome;
}
public void setOutcome(String outcome) {
this.outcome = outcome;
}
private String status;
public TaskModel(String subject, String taskType, String assigned, String scheduleDate, String location, String opportunityNo, String status, String outcome) {
this.subject = subject;
this.taskType = taskType;
this.assigned = assigned;
this.scheduleDate = scheduleDate;
this.location = location;
this.opportunityNo = opportunityNo;
this.status = status;
this.outcome = outcome;
}
private String outcome;
}