@ -1,7 +1,7 @@
@@ -1,7 +1,7 @@
package com.kanglai.push.ui.activity ;
import android.Manifest ;
import android.content.Context ;
import android.app.AlertDialog ;
import android.content.Intent ;
import android.content.pm.PackageManager ;
import android.os.Bundle ;
@ -14,22 +14,16 @@ import android.widget.TextView;
@@ -14,22 +14,16 @@ import android.widget.TextView;
import androidx.core.app.NotificationManagerCompat ;
import com.blankj.utilcode.util.Object Utils ;
import com.blankj.utilcode.util.Permission Utils ;
import com.blankj.utilcode.util.StringUtils ;
import com.blankj.utilcode.util.Utils ;
import com.dolphin.core.base.AppManager ;
import com.dolphin.core.base.BaseActivity ;
import com.dolphin.core.constant.AppConstant ;
import com.dolphin.core.util.PermissionUtil ;
import com.dolphin.core.util.ToastUtil ;
import com.dolphin.umeng.UmengClient ;
import com.dolphin.umeng.enums.PlatformEnum ;
import com.google.gson.Gson ;
import com.kanglai.push.BR ;
import com.kanglai.push.R ;
import com.kanglai.push.databinding.ActivityLoginBinding ;
import com.kanglai.push.ui.vm.LoginViewModel ;
import com.kanglai.push.ui.vm.PushTypeViewModel ;
import com.kanglai.push.util.CountDownTimerUtils ;
import com.kanglai.push.util.ViewFilterUtil ;
import com.kongzue.dialogx.dialogs.MessageDialog ;
import com.kongzue.dialogx.interfaces.OnDialogButtonClickListener ;
@ -61,9 +55,7 @@ public class LoginActivity extends BaseActivity<ActivityLoginBinding, LoginViewM
@@ -61,9 +55,7 @@ public class LoginActivity extends BaseActivity<ActivityLoginBinding, LoginViewM
public Button loginBtn ; // 登录按钮
/** 软件申请动态权限,必须设置不设置不让进软件 */
private String [ ] needPermissions = {
Manifest . permission . ACCESS_COARSE_LOCATION ,
Manifest . permission . ACCESS_FINE_LOCATION ,
private final String [ ] needPermissions = {
Manifest . permission . WRITE_EXTERNAL_STORAGE ,
Manifest . permission . READ_EXTERNAL_STORAGE ,
Manifest . permission . READ_PHONE_STATE
@ -87,73 +79,20 @@ public class LoginActivity extends BaseActivity<ActivityLoginBinding, LoginViewM
@@ -87,73 +79,20 @@ public class LoginActivity extends BaseActivity<ActivityLoginBinding, LoginViewM
startActivity ( TabBarActivity . class ) ;
finish ( ) ;
}
EditText input01 = findViewById ( R . id . et_phone ) ;
EditText input02 = findViewById ( R . id . et_captcha ) ;
input01 . setFilters ( new InputFilter [ ] { ViewFilterUtil . getNoSpecialCharactersFilter ( ) } ) ; // 输入框去空格
input01 . setFilters ( new InputFilter [ ] { ViewFilterUtil . getNoSpecialCharactersFilter ( ) } ) ;
input02 . setFilters ( new InputFilter [ ] { ViewFilterUtil . getNoSpecialCharactersFilter ( ) } ) ;
input01 . setFilters ( new InputFilter [ ] { new InputFilter . LengthFilter ( 11 ) } ) ; // 限制输入最大长度
input01 . setFilters ( new InputFilter [ ] { new InputFilter . LengthFilter ( 11 ) } ) ;
input02 . setFilters ( new InputFilter [ ] { new InputFilter . LengthFilter ( 6 ) } ) ;
mTextView = findViewById ( R . id . tv_sendCMS ) ;
loginBtn = findViewById ( R . id . login_btn ) ;
}
/** 微信登录点击事件 -已废弃 */
public void wechatLoginClick ( View view ) {
if ( ! UmengClient . isAppInstalled ( this , PlatformEnum . WECHAT ) ) {
ToastUtil . show ( "当前没有安装微信!" ) ;
return ;
}
UmengClient . login ( this , PlatformEnum . WECHAT , ( platformEnum , data ) - > {
if ( ObjectUtils . isEmpty ( data ) ) return ;
ToastUtil . show ( new Gson ( ) . toJson ( data ) ) ;
} ) ;
}
/** QQ登录点击事件 - 已废弃 */
public void qqLoginClick ( View view ) {
if ( ! UmengClient . isAppInstalled ( this , PlatformEnum . QQ ) ) {
ToastUtil . show ( "当前没有安装QQ!" ) ;
return ;
}
UmengClient . login ( this , PlatformEnum . QQ , ( platformEnum , data ) - > {
if ( ObjectUtils . isEmpty ( data ) ) return ;
ToastUtil . show ( new Gson ( ) . toJson ( data ) ) ;
} ) ;
}
@Override
protected void onResume ( ) {
super . onResume ( ) ;
if ( requestPermissionNeedCheck ) checkPermissions ( needPermissions ) ;
if ( ! NotificationManagerCompat . from ( getApplicationContext ( ) ) . areNotificationsEnabled ( ) ) { // 通知栏权限检测
NoticeBoardDialog ( ) ;
}
}
/** 通知栏权限申请提醒 同意进 | 取消则退出程序 */
private void NoticeBoardDialog ( ) {
MessageDialog . show ( getString ( com . dolphin . core . R . string . app_name ) + " 想要获取此设备的通知栏权限?" , "" , "前往设置" , "取 消" )
. setOkButton ( new OnDialogButtonClickListener < MessageDialog > ( ) {
@Override
public boolean onClick ( MessageDialog dialog , View v ) {
dialog . dismiss ( ) ;
Intent intent = new Intent ( ) ;
intent . setAction ( "android.settings.APP_NOTIFICATION_SETTINGS" ) ;
intent . putExtra ( "android.provider.extra.APP_PACKAGE" , getPackageName ( ) ) ;
startActivity ( intent ) ;
return true ;
}
} )
. setCancelButton ( new OnDialogButtonClickListener < MessageDialog > ( ) {
@Override
public boolean onClick ( MessageDialog dialog , View v ) {
Process . killProcess ( Process . myPid ( ) ) ; // 不同意调用通知栏权限,退出app
return false ;
}
} )
. setCancelable ( false ) // 无法通过点击对话框之外的区域或按下返回按钮来快速关闭对话框
. show ( ) ;
}
/** 检查软件所需要的权限,没有则弹出软件权限申请框申请 */
@ -182,36 +121,23 @@ public class LoginActivity extends BaseActivity<ActivityLoginBinding, LoginViewM
@@ -182,36 +121,23 @@ public class LoginActivity extends BaseActivity<ActivityLoginBinding, LoginViewM
requestPermissionNeedCheck = false ;
PermissionUtil . openApplicationSettings ( this , "当前应用缺少必要权限。\n请点击设置-权限-打开所需权限!" ) ;
}
}
// 申请勿扰权限方式要由用户自主权限 - 对于友盟消息推送送达率并无明显提升
// NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// if (!notificationManager.isNotificationPolicyAccessGranted()) {
// DNDModePromiss();
// }
}
private void DNDModePromiss ( ) { // 勿扰模式弹窗提示
MessageDialog . show ( "允许”勿扰“权限" , "是否允许" + getString ( com . dolphin . core . R . string . app_name ) + getResources ( ) . getString ( R . string . privacy_DND ) , "前往设置" , "取 消" )
. setOkButton ( new OnDialogButtonClickListener < MessageDialog > ( ) {
@Override
public boolean onClick ( MessageDialog dialog , View v ) {
if ( ! NotificationManagerCompat . from ( getApplicationContext ( ) ) . areNotificationsEnabled ( ) ) {
new AlertDialog . Builder ( this )
. setTitle ( "授权设备权限" )
. setMessage ( getString ( com . dolphin . core . R . string . app_name ) + " 想要获取此设备的通知权限?" )
. setNegativeButton ( "取消" , ( dialog , which ) - > AppManager . getAppManager ( ) . finishAllActivity ( ) )
. setPositiveButton ( "前往设置" , ( dialog , which ) - > {
dialog . dismiss ( ) ;
Intent intent = new Intent ( android . provider . Settings . ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS ) ;
intent . setFlags ( Intent . FLAG_ACTIVITY_NEW_TASK ) ;
Utils . getApp ( ) . startActivity ( intent ) ;
return true ;
}
} )
. setCancelButton ( new OnDialogButtonClickListener < MessageDialog > ( ) {
@Override
public boolean onClick ( MessageDialog dialog , View v ) {
dialog . dismiss ( ) ;
return false ;
}
Intent intent = new Intent ( ) ;
intent . setAction ( "android.settings.APP_NOTIFICATION_SETTINGS" ) ;
intent . putExtra ( "android.provider.extra.APP_PACKAGE" , getPackageName ( ) ) ;
startActivity ( intent ) ;
} )
. setCancelable ( false ) // 无法通过点击对话框之外的区域或按下返回按钮来快速关闭对话框
. setCancelable ( false )
. show ( ) ;
}
}
}
@Override
protected void onActivityResult ( int requestCode , int resultCode , Intent data ) {