我创建了一个回收站视图,列出了电话的通话记录历史记录,并在点击时拨打所选的号码。 当用户选择一个号码并拨打它时,它不会通过呼叫日志顶部的新呼叫事务刷新回收者数据。
我的CallLogRecyclerAdapter:
public class CallLogAdapter extends RecyclerView.Adapter<CallLogAdapter.ViewHolder> {
private List<CallLogItemVO> mListItem;
Context context;
public CallLogAdapter(List<CallLogItemVO> mListItem,Context context) {
this.mListItem = mListItem;
this.context=context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.log_recycler_row,parent,false);
ViewHolder viewHolder=new ViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
CallLogItemVO callLogItem =mListItem.get(position);
holder.phoneNumberOrName.setText(callLogItem.getContactName());
holder.callDuration.setText(callLogItem.getCallDuration()+" ");
holder.callDate.setText(callLogItem.getCallDate()+", "+callLogItem.getCallTime());
String callTypeValue=callLogItem.getCallType();
if (callTypeValue=="Missed"){
holder.phoneNumberOrName.setTextColor(Color.parseColor("#FFF20B0B"));
holder.callType.setImageResource(R.drawable.ic_call_missed);
}else if (callTypeValue=="Outgoing") {
holder.phoneNumberOrName.setTextColor(Color.BLACK);
holder.callType.setImageResource(R.drawable.ic_sent_call);
}else if (callTypeValue=="Incoming") {
holder.phoneNumberOrName.setTextColor(Color.BLACK);
holder.callType.setImageResource(R.drawable.ic_call_received);
}else {
holder.phoneNumberOrName.setTextColor(Color.BLACK);
holder.callType.setImageResource(R.drawable.ic_call_rejected);
}
}
@Override
public int getItemCount() {
return mListItem.size();
}
class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
public Button callInfoButton;
public View view;
public TextView phoneNumberOrName,callDuration,callDate,phoneNumber;
ImageView callType;
public ViewHolder(View itemView)
{
super(itemView);
phoneNumberOrName = (TextView)itemView.findViewById(R.id.phoneNumberOrName);
callDuration = (TextView)itemView.findViewById(R.id.callDuration);
callDate = (TextView)itemView.findViewById(R.id.callDate);
callType = (ImageView)itemView.findViewById(R.id.callType);
callInfoButton=(Button) itemView.findViewById(R.id.ptnLogInfo);
itemView.setOnClickListener(this);
itemView.setOnLongClickListener(this);
}
@Override
public void onClick(View v) {
int position = getAdapterPosition();
CallLogItemVO callLogItem=mListItem.get(position);
Methods.callNumber(callLogItem.getPhoneNumber().toString(),context);
}
@Override
public boolean onLongClick(View v) {
return false;
}
}}
我的CallLogVO:
public class CallLogItemVO {
private String phoneNumber;
private String contactName;
private String callType;
private String callDate;
private String callDuration;
private String callTime;
public String getCallTime() {
return callTime;
}
public void setCallTime(String callTime) {
this.callTime = callTime;
}
public String getContactName() {
return contactName;
}
public void setContactName(String conatctName) {
this.contactName = conatctName;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getCallType() {
return callType;
}
public void setCallType(String callType) {
this.callType = callType;
}
public String getCallDate() {
return callDate;
}
public void setCallDate(String callDate) {
this.callDate = callDate;
}
public String getCallDuration() {
return callDuration;
}
public void setCallDuration(String callDuration) {
this.callDuration = callDuration;
}
我的CallLogFragment:
public class CallLogFragment extends Fragment {
String simOrange,simVodafone,simEtisalat,simOther;
ArrayList<CallLogItemVO> callLogItemsList = new ArrayList<>();
RecyclerView recyclerViewLog;
RecyclerView.LayoutManager layoutManagerLog;
RecyclerView.Adapter adapterLog;
public CallLogFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_call_log, container, false);
recyclerViewLog = (RecyclerView) view.findViewById(R.id.recyclerViewCallLog);
recyclerViewLog.setHasFixedSize(true);
layoutManagerLog = new LinearLayoutManager(getContext());
recyclerViewLog.setLayoutManager(layoutManagerLog);
getCallLogDetails();
return view;
}
private void getCallLogDetails() {
//adapterLog=null;
String strOrder = CallLog.Calls.DATE + " DESC";
Cursor managedCursor = getActivity().getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, strOrder);
int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER);
int name = managedCursor.getColumnIndex(CallLog.Calls.CACHED_NAME);
int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE);
int date = managedCursor.getColumnIndex(CallLog.Calls.DATE);
int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION);
while (managedCursor.moveToNext()) {
String phNum = managedCursor.getString(number);
String contactName = managedCursor.getString(name);
String callTypeCode = managedCursor.getString(type);
String strcallDate = managedCursor.getString(date);
Date callDate = new Date(Long.valueOf(strcallDate));
Time callTime = new Time(Long.valueOf(strcallDate));
String callDuration = managedCursor.getString(duration);
//تحديد نوع الاتصال
String callType = null;
int callcode = Integer.parseInt(callTypeCode);
switch (callcode) {
case CallLog.Calls.OUTGOING_TYPE:
callType = "Outgoing";
break;
case CallLog.Calls.INCOMING_TYPE:
callType = "Incoming";
break;
case CallLog.Calls.MISSED_TYPE:
callType = "Missed";
break;
}
try {
if(callType==null){
callType="Rejected";
}
} catch (Exception e) {
Toast.makeText(getContext(), ""+e, Toast.LENGTH_SHORT).show();
}
//تحديد رقم المتصل او اسمه
String phoneNumberOrName ;
if (contactName == null || contactName.isEmpty()){
phoneNumberOrName = phNum;
}else {
phoneNumberOrName=contactName;
}
CallLogItemVO callLogItem = new CallLogItemVO();
callLogItem.setPhoneNumber(phNum);
callLogItem.setContactName(phoneNumberOrName);
callLogItem.setCallDate(String.valueOf(callDate));
callLogItem.setCallTime(String.valueOf(callTime));
callLogItem.setCallType(callType);
callLogItem.setCallDuration(Methods.convertToTime(callDuration));
callLogItemsList.add(callLogItem);
adapterLog = new CallLogAdapter(callLogItemsList, getContext());
recyclerViewLog.setAdapter(adapterLog);
}
// Toast.makeText(this, "FillLog", Toast.LENGTH_SHORT).show();
managedCursor.close();
}}