添加通话记录数据更新功能。在长期打开主窗口后,通话记录可以实时更新。
This commit is contained in:
parent
bec4041b87
commit
f053218932
@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Mon Mar 31 04:07:30 GMT 2025
|
||||
#Mon Mar 31 04:57:39 GMT 2025
|
||||
stageCount=1
|
||||
libraryProject=
|
||||
baseVersion=15.2
|
||||
publishVersion=15.2.0
|
||||
buildCount=4
|
||||
buildCount=20
|
||||
baseBetaVersion=15.2.1
|
||||
|
@ -66,6 +66,8 @@ final public class MainActivity extends AppCompatActivity implements IWinBollAct
|
||||
|
||||
private TelephonyManager telephonyManager;
|
||||
private MyPhoneStateListener phoneStateListener;
|
||||
List<Fragment> fragmentList;
|
||||
List<String> tabTitleList;
|
||||
|
||||
private static final int DIALER_REQUEST_CODE = 1;
|
||||
|
||||
@ -110,13 +112,13 @@ final public class MainActivity extends AppCompatActivity implements IWinBollAct
|
||||
// getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
// }
|
||||
getSupportActionBar().setSubtitle(getTag());
|
||||
|
||||
|
||||
tabLayout = findViewById(R.id.tabLayout);
|
||||
viewPager = findViewById(R.id.viewPager);
|
||||
|
||||
// 创建Fragment列表和标题列表
|
||||
List<Fragment> fragmentList = new ArrayList<>();
|
||||
List<String> tabTitleList = new ArrayList<>();
|
||||
fragmentList = new ArrayList<>();
|
||||
tabTitleList = new ArrayList<>();
|
||||
fragmentList.add(CallLogFragment.newInstance(0));
|
||||
fragmentList.add(ContactsFragment.newInstance(1));
|
||||
fragmentList.add(LogFragment.newInstance(2));
|
||||
@ -130,7 +132,7 @@ final public class MainActivity extends AppCompatActivity implements IWinBollAct
|
||||
|
||||
// 关联TabLayout和ViewPager
|
||||
tabLayout.setupWithViewPager(viewPager);
|
||||
|
||||
|
||||
|
||||
|
||||
// initData();
|
||||
@ -175,7 +177,7 @@ final public class MainActivity extends AppCompatActivity implements IWinBollAct
|
||||
phoneStateListener = new MyPhoneStateListener();
|
||||
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ViewPager的适配器
|
||||
private class MyPagerAdapter extends FragmentPagerAdapter {
|
||||
|
@ -9,6 +9,9 @@ import android.Manifest;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.provider.CallLog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -22,6 +25,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import cc.winboll.studio.contacts.R;
|
||||
import cc.winboll.studio.contacts.adapters.CallLogAdapter;
|
||||
import cc.winboll.studio.contacts.beans.CallLogModel;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@ -30,22 +34,41 @@ public class CallLogFragment extends Fragment {
|
||||
|
||||
public static final String TAG = "CallFragment";
|
||||
|
||||
static volatile CallLogFragment _CallLogFragment;
|
||||
|
||||
public static final int MSG_UPDATE = 1; // 添加消息常量
|
||||
|
||||
private static final String ARG_PAGE = "ARG_PAGE";
|
||||
private int mPage;
|
||||
|
||||
|
||||
private static final int REQUEST_READ_CALL_LOG = 1;
|
||||
private RecyclerView recyclerView;
|
||||
private CallLogAdapter callLogAdapter;
|
||||
private List<CallLogModel> callLogList = new ArrayList<>();
|
||||
|
||||
// 添加Handler
|
||||
private final Handler mHandler = new Handler(Looper.getMainLooper()) {
|
||||
@Override
|
||||
public void handleMessage(@NonNull Message msg) {
|
||||
if (msg.what == MSG_UPDATE) {
|
||||
readCallLog(); // 接收到消息时更新通话记录
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
CallLogFragment() {
|
||||
super();
|
||||
}
|
||||
|
||||
public static CallLogFragment newInstance(int page) {
|
||||
Bundle args = new Bundle();
|
||||
args.putInt(ARG_PAGE, page);
|
||||
CallLogFragment fragment = new CallLogFragment();
|
||||
fragment.setArguments(args);
|
||||
_CallLogFragment = fragment;
|
||||
return fragment;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
@ -55,7 +78,7 @@ public class CallLogFragment extends Fragment {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments()!= null) {
|
||||
if (getArguments() != null) {
|
||||
mPage = getArguments().getInt(ARG_PAGE);
|
||||
}
|
||||
}
|
||||
@ -68,10 +91,10 @@ public class CallLogFragment extends Fragment {
|
||||
callLogAdapter = new CallLogAdapter(getContext(), callLogList);
|
||||
recyclerView.setAdapter(callLogAdapter);
|
||||
|
||||
if (ActivityCompat.checkSelfPermission(requireContext(), Manifest.permission.READ_CALL_LOG)!= PackageManager.PERMISSION_GRANTED) {
|
||||
if (ActivityCompat.checkSelfPermission(requireContext(), Manifest.permission.READ_CALL_LOG) != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(requireActivity(), new String[]{Manifest.permission.READ_CALL_LOG}, REQUEST_READ_CALL_LOG);
|
||||
} else {
|
||||
readCallLog();
|
||||
mHandler.sendEmptyMessage(MSG_UPDATE); // 通过Handler触发更新
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,12 +103,13 @@ public class CallLogFragment extends Fragment {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
if (requestCode == REQUEST_READ_CALL_LOG) {
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
readCallLog();
|
||||
mHandler.sendEmptyMessage(MSG_UPDATE); // 通过Handler触发更新
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void readCallLog() {
|
||||
callLogList.clear(); // 清空原有数据
|
||||
Cursor cursor = requireContext().getContentResolver().query(
|
||||
CallLog.Calls.CONTENT_URI,
|
||||
null,
|
||||
@ -93,7 +117,7 @@ public class CallLogFragment extends Fragment {
|
||||
null,
|
||||
CallLog.Calls.DATE + " DESC");
|
||||
|
||||
if (cursor!= null) {
|
||||
if (cursor != null) {
|
||||
while (cursor.moveToNext()) {
|
||||
String phoneNumber = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER));
|
||||
int callType = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.TYPE));
|
||||
@ -121,5 +145,20 @@ public class CallLogFragment extends Fragment {
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
mHandler.removeCallbacksAndMessages(null); // 清理Handler防止内存泄漏
|
||||
}
|
||||
|
||||
public void triggerUpdate() {
|
||||
mHandler.sendEmptyMessage(MSG_UPDATE);
|
||||
}
|
||||
|
||||
public static void updateCallLogFragment() {
|
||||
if (_CallLogFragment != null) {
|
||||
_CallLogFragment.triggerUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package cc.winboll.studio.contacts.phonecallui;
|
||||
|
||||
import static cc.winboll.studio.contacts.listenphonecall.CallListenerService.formatPhoneNumber;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@ -10,16 +8,16 @@ import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import cc.winboll.studio.contacts.ActivityStack;
|
||||
import cc.winboll.studio.contacts.MainActivity;
|
||||
import cc.winboll.studio.contacts.R;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import static cc.winboll.studio.contacts.listenphonecall.CallListenerService.formatPhoneNumber;
|
||||
|
||||
|
||||
/**
|
||||
* 提供接打电话的界面,仅支持 Android M (6.0, API 23) 及以上的系统
|
||||
@ -157,6 +155,7 @@ public class PhoneCallActivity extends AppCompatActivity implements View.OnClick
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
//MainActivity.updateCallLogFragment();
|
||||
phoneCallManager.destroy();
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import android.os.Build;
|
||||
import android.telecom.Call;
|
||||
import android.telecom.VideoProfile;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import cc.winboll.studio.contacts.dun.Rules;
|
||||
import cc.winboll.studio.contacts.MainActivity;
|
||||
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
|
@ -21,6 +21,7 @@ import androidx.annotation.RequiresApi;
|
||||
import cc.winboll.studio.contacts.ActivityStack;
|
||||
import cc.winboll.studio.contacts.beans.RingTongBean;
|
||||
import cc.winboll.studio.contacts.dun.Rules;
|
||||
import cc.winboll.studio.contacts.fragments.CallLogFragment;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -149,6 +150,12 @@ public class PhoneCallService extends InCallService {
|
||||
PhoneCallManager.call = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
CallLogFragment.updateCallLogFragment();
|
||||
}
|
||||
|
||||
public enum CallType {
|
||||
CALL_IN,
|
||||
CALL_OUT,
|
||||
|
Loading…
x
Reference in New Issue
Block a user