发布公众号

This commit is contained in:
itgaojian 2023-07-28 14:24:25 +08:00
parent 362c4a89f9
commit 1a7efbd45a
20 changed files with 459 additions and 352 deletions

View File

@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 13,
"versionName": "1.1.3",
"versionCode": 14,
"versionName": "1.1.4",
"outputFile": "app-city-release.apk"
}
],

View File

@ -9,6 +9,7 @@ import com.alibaba.android.arouter.launcher.ARouter;
import com.baidu.location.BDLocation;
import com.baidu.mapapi.CoordType;
import com.baidu.mapapi.SDKInitializer;
import com.hjq.toast.Toaster;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.sucstepsoft.cm_utils.core.widget.refresh.CustomRefreshHeader;
@ -46,8 +47,8 @@ public class BaseMyApplication extends Application {
initShare();
initBaiduMap();
ToastUtils.init(this);
ToastUtils.setGravity(Gravity.TOP, 0, 80);
Toaster.init(this);
Toaster.setGravity(Gravity.TOP, 0, 100);
getConfigCityCode();
}
@ -55,7 +56,7 @@ public class BaseMyApplication extends Application {
UserLgUtils.setCurrentCityCode(this.getResources().getString(R.string.CITY_CODE));
UserLgUtils.setCurrentCity(this.getResources().getString(R.string.CITY_NAME));
UserLgUtils.setCurrentCityId(this.getResources().getString(R.string.CITY_ID));
UserLgUtils.setAppPathCode(this.getResources().getString(R.string.APP_PATH_CODE));
UserLgUtils.setAppPathCode(this.getResources().getString(R.string.VERSION_PATH_CODE));
}
private void initShare() {

View File

@ -56,8 +56,8 @@ ext {
gCompileSdkVersion = 31
gMinSdkVersion = 16
gTargetSdkVersion = 29
gVersionCode = 13
gVersionName = '1.1.3'
gVersionCode = 14
gVersionName = '1.1.4'
gBuildToolsVersion = "30.0.2"
// gVersionCode=26
// gVersionName='1.3.0'

View File

@ -76,5 +76,7 @@ dependencies {
implementation 'com.gyf.immersionbar:immersionbar-components:3.0.0'
//
api 'com.github.mmin18:realtimeblurview:1.2.1'
//toast
api 'com.github.getActivity:Toaster:12.3'
}

View File

@ -32,7 +32,6 @@ public class PathConfig {
public static final String WECHAT_APPID = "wxa5c5246b283713de";
public static final String WECHAT_SECERT = "e5b761f20841f81dd73a6d4aad2f8060";
public static final String SECRET = "CMXX_TOKEN_INFOS";//秘钥
public static final String PROJECT_NAME = "locationReal";//TODO ===项目名称==
public static final String ACTION_SYSTEM_MESSAGE = "com.sucstepsoft.hs.message";
public static final String ACTION_LOCATION_MESSAGE = "com.sucstepsoft.realtimelocation.MESSAGE_RECEIVED_ACTION";
public static final String ACTION_PUNCH_TIME_MESSAGE = "com.sucstepsoft.realtimelocation.MESSAGE_PUNCH_ACTION";
@ -65,7 +64,9 @@ public class PathConfig {
public static final String CITY_DEFAULT_NAME = "日喀则市";
public static final String CITY_DEFAULT_ID = "640675";
public static final int CITY_DEFAULT_LEVEL = 3;
public static final int NOTIFY_ID = 9999;//通知栏ID
public static final String PROJECT_NAME = "city-governance";/* ===项目名称==*/
public static final String PROJECT_NAME_CH = "数字文化云";
public static final String DID_CITY_CODE = "640675";//日喀则市编码
//新闻类型
public static final int NEWS_TYPE_MULTI_PIC = 2332;//key_1 三图; key_2 一图左;key_3 一图右;key_4 一图下;key_5 纯文字;key_6 视频;

View File

@ -207,7 +207,7 @@ public class CommonWebActivity extends BaseActivity {
private RequestBody buildRequestBody() {
PostWeChatTicketBean bean = new PostWeChatTicketBean();
PostWeChatTicketBean.JumpWxaBean subBean = new PostWeChatTicketBean.JumpWxaBean();
subBean.setEnv_version("trial");//默认 release 正式版 trial 体验版 develop 开发版
subBean.setEnv_version("release");//默认 release 正式版 trial 体验版 develop 开发版
subBean.setPath("/pages/commonQrCode/commonQrCode");
String query = "";

View File

@ -53,6 +53,45 @@ public class NotificationUtils extends ContextWrapper {
}
return mManager;
}
private static NotificationManager mNotificationManager;
private final static String PRIMARY_CHANNEL = "citygovernance";
public static Notification buildNotification(Context context, String title, String hintMsg) {
Notification notification = null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(PRIMARY_CHANNEL,
context.getString(R.string.app_name), NotificationManager.IMPORTANCE_HIGH);
channel.setLightColor(Color.GREEN);
channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
getNotificationManager(context).createNotificationChannel(channel);
Notification.Builder builder = new Notification.Builder(context,
PRIMARY_CHANNEL)
.setContentTitle(title)
.setContentText(hintMsg)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setSmallIcon(R.drawable.app_logo_smal)
.setAutoCancel(true);
notification = builder.build();
} else {
Notification.Builder builder = new Notification.Builder(context);
builder.setSmallIcon(R.drawable.app_logo_smal);
builder.setContentTitle(title);
builder.setContentText(hintMsg)
.setPriority(Notification.PRIORITY_MAX)
.setWhen(System.currentTimeMillis());
notification = builder.build();
}
return notification;
}
private static NotificationManager getNotificationManager(Context context) {
if (mNotificationManager == null) {
mNotificationManager = (NotificationManager) context.getSystemService(
Context.NOTIFICATION_SERVICE);
}
return mNotificationManager;
}
/**
* 发送通知

View File

@ -21,27 +21,31 @@ public class ExceptionHandler {
public static void handleException(Throwable throwable) {
if (throwable instanceof HttpException) {
LogUtils.e("HttpException");
HttpException ex = (HttpException) throwable;
try {
String errBody = ex.response().errorBody().string();
LogUtils.e("错误体:"+errBody);
if (!TextUtils.isEmpty(errBody)) {
ErrorBean errorBean = new Gson().fromJson(errBody, ErrorBean.class);
if (!TextUtils.isEmpty(errorBean.getMsg())) {
ToastUtils.showShort(errorBean.getMsg());
ToastUtils.show(errorBean.getMsg());
} else {
ToastUtils.showShort(errorBean.getMessage());
ToastUtils.show("网络错误(500)");
}
}else{
ToastUtils.show("网络错误(500)");
}
} catch (Exception e1) {
ToastUtils.showShort("网络错误,请稍后重试");
ToastUtils.show("网络错误,请稍后重试");
e1.printStackTrace();
}
} else if (throwable instanceof JsonParseException) {
ToastUtils.showShort("解析错误");
ToastUtils.show("解析错误");
} else if (throwable instanceof SocketTimeoutException) {
ToastUtils.showShort("网络连接超时");
ToastUtils.show("网络连接超时");
} else {
ToastUtils.showShort("网络错误,请稍后重试");
ToastUtils.show("网络错误,请稍后重试");
}
}

View File

@ -2,16 +2,15 @@ package com.sucstepsoft.cm_utils.utils.toast;
import android.util.Log;
import com.sucstepsoft.cm_utils.utils.toast.config.IToastInterceptor;
import java.lang.reflect.Modifier;
/**
* author : Android 轮子哥
* github : https://github.com/getActivity/ToastUtils
* time : 2020/11/04
* desc : 自定义 Toast 拦截器用于追踪 Toast 调用的位置
* author : Android 轮子哥
* github : https://github.com/getActivity/ToastUtils
* time : 2020/11/04
* desc : 自定义 Toast 拦截器用于追踪 Toast 调用的位置
*/
public class ToastLogInterceptor implements IToastInterceptor {
@ -50,7 +49,7 @@ public class ToastLogInterceptor implements IToastInterceptor {
}
protected boolean isLogEnable() {
return ToastUtils.isDebugMode();
return false;
}
protected void printLog(String msg) {

View File

@ -1,17 +1,6 @@
package com.sucstepsoft.cm_utils.utils.toast;
import android.app.Application;
import android.content.pm.ApplicationInfo;
import android.content.res.Resources;
import android.widget.Toast;
import com.sucstepsoft.cm_utils.utils.toast.config.IToastInterceptor;
import com.sucstepsoft.cm_utils.utils.toast.config.IToastStrategy;
import com.sucstepsoft.cm_utils.utils.toast.config.IToastStyle;
import com.sucstepsoft.cm_utils.utils.toast.style.BlackToastStyle;
import com.sucstepsoft.cm_utils.utils.toast.style.CustomViewToastStyle;
import com.sucstepsoft.cm_utils.utils.toast.style.LocationToastStyle;
import com.sucstepsoft.cm_utils.utils.toast.style.WhiteToastStyle;
import com.hjq.toast.Toaster;
/**
@ -22,313 +11,24 @@ import com.sucstepsoft.cm_utils.utils.toast.style.WhiteToastStyle;
*/
@SuppressWarnings("unused")
public final class ToastUtils {
/**
* Application 对象
*/
private static Application sApplication;
/**
* Toast 处理策略
*/
private static IToastStrategy sToastStrategy;
/**
* Toast 样式
*/
private static IToastStyle<?> sToastStyle;
/**
* Toast 拦截器可空
*/
private static IToastInterceptor sToastInterceptor;
/**
* 调试模式
*/
private static Boolean sDebugMode;
/**
* 不允许被外部实例化
*/
private ToastUtils() {
public static void show(String content) {
Toaster.show(content);
}
/**
* 初始化 Toast需要在 Application.create 中初始化
*
* @param application 应用的上下文
*/
public static void init(Application application) {
init(application, sToastStyle);
public static void show(int content) {
Toaster.show(content);
}
public static void init(Application application, IToastStrategy strategy) {
init(application, strategy, null);
public static void showLong(String content) {
Toaster.showLong(content);
}
public static void init(Application application, IToastStyle<?> style) {
init(application, null, style);
}
/**
* 初始化 Toast
*
* @param application 应用的上下文
* @param strategy Toast 策略
* @param style Toast 样式
*/
public static void init(Application application, IToastStrategy strategy, IToastStyle<?> style) {
sApplication = application;
// 初始化 Toast 策略
if (strategy == null) {
strategy = new ToastStrategy();
}
setStrategy(strategy);
// 设置 Toast 样式
if (style == null) {
style = new BlackToastStyle();
}
setStyle(style);
}
/**
* 判断当前框架是否已经初始化
*/
public static boolean isInit() {
return sApplication != null && sToastStrategy != null && sToastStyle != null;
}
/**
* 延迟显示 Toast
*/
public static void delayedShow(int id, long delayMillis) {
delayedShow(stringIdToCharSequence(id), delayMillis);
}
public static void delayedShow(Object object, long delayMillis) {
delayedShow(objectToCharSequence(object), delayMillis);
}
public static void delayedShow(CharSequence text, long delayMillis) {
ToastParams params = new ToastParams();
params.text = text;
params.delayMillis = delayMillis;
show(params);
}
/**
* debug 模式下显示 Toast
*/
public static void debugShow(int id) {
debugShow(stringIdToCharSequence(id));
}
public static void debugShow(Object object) {
debugShow(objectToCharSequence(object));
}
public static void debugShow(CharSequence text) {
if (!isDebugMode()) {
return;
}
ToastParams params = new ToastParams();
params.text = text;
show(params);
}
/**
* 显示一个短 Toast
*/
public static void showShort(int id) {
showShort(stringIdToCharSequence(id));
Toaster.showShort(id);
}
public static void showShort(Object object) {
showShort(objectToCharSequence(object));
}
public static void showShort(CharSequence text) {
ToastParams params = new ToastParams();
params.text = text;
params.duration = Toast.LENGTH_SHORT;
show(params);
}
/**
* 显示一个长 Toast
*/
public static void showLong(int id) {
showLong(stringIdToCharSequence(id));
}
public static void showLong(Object object) {
showLong(objectToCharSequence(object));
}
public static void showLong(CharSequence text) {
ToastParams params = new ToastParams();
params.text = text;
params.duration = Toast.LENGTH_LONG;
show(params);
}
/**
* 显示 Toast
*/
public static void show(int id) {
show(stringIdToCharSequence(id));
}
public static void show(Object object) {
show(objectToCharSequence(object));
}
public static void show(CharSequence text) {
ToastParams params = new ToastParams();
params.text = text;
show(params);
}
public static void show(ToastParams params) {
// 如果是空对象或者空文本就不显示
if (params.text == null || params.text.length() == 0) {
return;
}
if (params.strategy == null) {
params.strategy = sToastStrategy;
}
if (params.interceptor == null) {
if (sToastInterceptor == null) {
sToastInterceptor = new ToastLogInterceptor();
}
params.interceptor = sToastInterceptor;
}
if (params.style == null) {
params.style = sToastStyle;
}
if (params.interceptor.intercept(params)) {
return;
}
if (params.duration == -1) {
params.duration = params.text.length() > 20 ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT;
}
params.strategy.showToast(params);
}
/**
* 取消吐司的显示
*/
public static void cancel() {
sToastStrategy.cancelToast();
}
/**
* 设置吐司的位置
*
* @param gravity 重心
*/
public static void setGravity(int gravity) {
setGravity(gravity, 0, 0);
}
public static void setGravity(int gravity, int xOffset, int yOffset) {
setGravity(gravity, xOffset, yOffset, 0, 0);
}
public static void setGravity(int gravity, int xOffset, int yOffset, float horizontalMargin, float verticalMargin) {
sToastStyle = new LocationToastStyle(sToastStyle, gravity, xOffset, yOffset, horizontalMargin, verticalMargin);
}
/**
* 给当前 Toast 设置新的布局
*/
public static void setView(int id) {
if (id <= 0) {
return;
}
setStyle(new CustomViewToastStyle(id, sToastStyle.getGravity(),
sToastStyle.getXOffset(), sToastStyle.getYOffset(),
sToastStyle.getHorizontalMargin(), sToastStyle.getVerticalMargin()));
}
/**
* 初始化全局的 Toast 样式
*
* @param style 样式实现类框架已经实现两种不同的样式
* 黑色样式{@link BlackToastStyle}
* 白色样式{@link WhiteToastStyle}
*/
public static void setStyle(IToastStyle<?> style) {
sToastStyle = style;
}
public static IToastStyle<?> getStyle() {
return sToastStyle;
}
/**
* 设置 Toast 显示策略
*/
public static void setStrategy(IToastStrategy strategy) {
sToastStrategy = strategy;
sToastStrategy.registerStrategy(sApplication);
}
public static IToastStrategy getStrategy() {
return sToastStrategy;
}
/**
* 设置 Toast 拦截器可以根据显示的内容决定是否拦截这个Toast
* 场景打印 Toast 内容日志根据 Toast 内容是否包含敏感字来动态切换其他方式显示这里可以使用我的另外一套框架 XToast
*/
public static void setInterceptor(IToastInterceptor interceptor) {
sToastInterceptor = interceptor;
}
public static IToastInterceptor getInterceptor() {
return sToastInterceptor;
}
/**
* 是否为调试模式
*/
public static void setDebugMode(boolean debug) {
sDebugMode = debug;
}
static boolean isDebugMode() {
if (sDebugMode == null) {
sDebugMode = (sApplication.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
}
return sDebugMode;
}
private static CharSequence stringIdToCharSequence(int id) {
try {
// 如果这是一个资源 id
return sApplication.getResources().getText(id);
} catch (Resources.NotFoundException ignored) {
// 如果这是一个 int 整数
return String.valueOf(id);
}
}
private static CharSequence objectToCharSequence(Object object) {
return object != null ? object.toString() : "null";
public static void showShort(String sequence) {
Toaster.showShort(sequence);
}
}

View File

@ -11,7 +11,7 @@ project.ext {
resValue("string", "CITY_CODE", "540200000000")
resValue("string", "CITY_ID", "640675")
resValue("string", "CITY_NAME", "日喀则市")
resValue("string","APP_PATH_CODE","f5935aa1-4405-4cbe-85bc-d7c1a8ddc9c4")
resValue("string","VERSION_PATH_CODE","f5935aa1-4405-4cbe-85bc-d7c1a8ddc9c4")
manifestPlaceholders = [CHANNEL_VALUE: "cultural",
APP_LOGO : "@drawable/app_logo",
CITY_ID : "640675",

View File

@ -18,6 +18,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- Required -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission
android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
tools:ignore="ProtectedPermissions" />
@ -154,6 +155,9 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service
android:name=".cultural.socket.SocketService"
android:exported="true" />
</application>
</manifest>

View File

@ -344,7 +344,9 @@ public class LoginActivity extends BaseActivity {
public void onError(Throwable e) {
dialog.dismiss();
ExceptionHandler.handleException(e);
ToastUtils.show("登录失败,请稍后重试");
// ToastUtils.show("登录失败,请稍后重试");
setResult(333);
finish();
}
@Override

View File

@ -35,6 +35,7 @@ import com.sucstepsoft.cm_utils.core.retrofit_net.bean.VersionBean;
import com.sucstepsoft.cm_utils.core.widget.base.BaseActivity;
import com.sucstepsoft.cm_utils.core.widget.base.FragmentUtils;
import com.sucstepsoft.cm_utils.core.widget.views.CenterDialogUpdateView;
import com.sucstepsoft.cm_utils.utils.ExceptionHandler;
import com.sucstepsoft.cm_utils.utils.FileUtils;
import com.sucstepsoft.cm_utils.utils.LogUtils;
import com.sucstepsoft.cm_utils.utils.PermissionUtils;
@ -302,6 +303,9 @@ public class MainActivity extends BaseActivity {
@Override
public void onError(Throwable e) {
e.printStackTrace();
ExceptionHandler.handleException(e);
UserLgUtils.putIsPublicCode(false);
}
@Override

View File

@ -48,6 +48,7 @@ import com.sucstepsoft.cm_utils.core.beans.AddPhotoBean;
import com.sucstepsoft.cm_utils.core.beans.BaseImageBean;
import com.sucstepsoft.cm_utils.core.retrofit_net.BaseUrlApi;
import com.sucstepsoft.cm_utils.core.retrofit_net.RetrofitManager;
import com.sucstepsoft.cm_utils.core.retrofit_net.api.BaseApiService;
import com.sucstepsoft.cm_utils.core.widget.base.BannerImageTextAllAdapter;
import com.sucstepsoft.cm_utils.core.widget.base.BaseActivity;
import com.sucstepsoft.cm_utils.core.widget.base.CommonWebActivity;
@ -57,6 +58,7 @@ import com.sucstepsoft.cm_utils.core.widget.views.ButtomDialogView;
import com.sucstepsoft.cm_utils.core.widget.views.ItemSplitDivider;
import com.sucstepsoft.cm_utils.core.widget.views.NestedScrollWebView;
import com.sucstepsoft.cm_utils.core.widget.views.TypeFaceTextView;
import com.sucstepsoft.cm_utils.utils.AppUtils;
import com.sucstepsoft.cm_utils.utils.ConvertUtils;
import com.sucstepsoft.cm_utils.utils.ExceptionHandler;
import com.sucstepsoft.cm_utils.utils.FileUtils;
@ -81,6 +83,7 @@ import com.tengshisoft.mudulemain.R;
import com.tengshisoft.mudulemain.R2;
import com.tengshisoft.mudulemain.cultural.adapter.CommentAdapter;
import com.tengshisoft.mudulemain.cultural.adapter.NewsCategoryAdapter;
import com.tengshisoft.mudulemain.cultural.beans.AttentionCodeBean;
import com.tengshisoft.mudulemain.cultural.beans.BaseUserBean;
import com.tengshisoft.mudulemain.cultural.beans.CollectBean;
import com.tengshisoft.mudulemain.cultural.beans.CommentListBean;
@ -88,7 +91,7 @@ import com.tengshisoft.mudulemain.cultural.beans.CommentPublishBean;
import com.tengshisoft.mudulemain.cultural.beans.LikeBean;
import com.tengshisoft.mudulemain.cultural.beans.NewsDetailBean;
import com.tengshisoft.mudulemain.cultural.net.HomeApi;
import com.tengshisoft.mudulemain.cultural.socket.WsManager;
import com.tengshisoft.mudulemain.cultural.socket.SocketService;
import com.tengshisoft.mudulemain.cultural.widget.ButtomCommentListDialogView;
import com.youth.banner.Banner;
import com.youth.banner.transformer.ScaleInTransformer;
@ -180,6 +183,7 @@ public class NewsLocalDetailActivity extends BaseActivity {
Button mBtnPublic;
@BindView(R2.id.rl_public_code)
RelativeLayout mRlPublicCode;
private AddPhotoBean mCurrentBean;
private String mPicPath;
private Unbinder mBind;
@ -204,6 +208,8 @@ public class NewsLocalDetailActivity extends BaseActivity {
private NewsCategoryAdapter mCategoryAdapter;
private ActivityResultLauncher<Intent> mResultLauncher;
private SocketMsg mSocketMsg;
private boolean mIsAttention = false;//是否需要关注公众号
private boolean mIsFirst = true;
@Override
protected int setLayoutId() {
@ -345,8 +351,10 @@ public class NewsLocalDetailActivity extends BaseActivity {
IntentFilter filter = new IntentFilter();
filter.addAction(PathConfig.ACTION_FROM_SOCKET_PUSH_MSG);
registerReceiver(mSocketMsg, filter);
getNewsDetail();
String read = String.format(getResources().getString(R.string.big_data_str), "", mNId, "新闻");
LogUtils.e(read);
bigDataRead(read);
}
@ -369,21 +377,24 @@ public class NewsLocalDetailActivity extends BaseActivity {
@Override
public void onNext(NewsDetailBean newsDetailBean) {
if (!"".equals(newsDetailBean.getNewsContentId())) {
setDataToView(newsDetailBean);
if (TextUtils.isEmpty(newsDetailBean.getNewsViewAuth())) {
setDataToView(newsDetailBean);
mIsAttention = false;
} else {
//是否登录
if (TextUtils.isEmpty(UserLgUtils.getToken())) {
ARouter.getInstance()
.build(PathConfig.PATH_MODULE_MAIN_LOGIN)
.navigation();
finish();
} else {
//是否需要关注公众号
if (newsDetailBean.getNewsViewAuth().contains("2")) {
startSocket();
showPublicCodeDialog(newsDetailBean);
mIsAttention = true;
} else {
mIsAttention = false;
setDataToView(newsDetailBean);
}
}
@ -391,6 +402,7 @@ public class NewsLocalDetailActivity extends BaseActivity {
} else {
refreshView(STATE_LOAD_ERROR);
}
}
@Override
@ -406,16 +418,17 @@ public class NewsLocalDetailActivity extends BaseActivity {
});
}
/**
* 开启Socket
*/
private void startSocket() {
WsManager wsManager = new WsManager
.Builder(getApplication())
.wsUrl(BaseUrlApi.SOCKET_IP + UserLgUtils.getUserId())
.needReconnect(true)
.build();
wsManager.startConnect();
Intent intent = new Intent(mActivity, SocketService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mActivity.startForegroundService(intent);
} else {
mActivity.startService(intent);
}
}
/**
@ -427,6 +440,7 @@ public class NewsLocalDetailActivity extends BaseActivity {
if (!UserLgUtils.getIsPublicCode()) {
mRlPublicCode.setVisibility(View.VISIBLE);
mBtnPublic.setOnClickListener(v -> {
startSocket();
Intent intent = new Intent(mActivity, CommonWebActivity.class);
mResultLauncher.launch(intent);
});
@ -1176,6 +1190,22 @@ public class NewsLocalDetailActivity extends BaseActivity {
@Override
protected void onStart() {
super.onStart();
//在socket断链的情况先手动获取一次是否关注
LogUtils.e("是否关注" + UserLgUtils.getIsPublicCode() + mIsFirst);
if (!mIsFirst) {
if (!UserLgUtils.getIsPublicCode() && mIsAttention) {
if (mContentSkeleton != null) {
mContentSkeleton.show();
} else {
mContentSkeleton = Skeleton.bind(mLlNewsContent)
.load(R.layout.item_skeleton_news_content_local)
.show();
}
mRlPublicCode.setVisibility(View.GONE);
getUserIsPublicCode();
}
}
mIsFirst = false;
mCommentPage = 1;
if (!TextUtils.isEmpty(UserLgUtils.getToken())) {
getCommentListByLogin(mCommentPage);
@ -1184,6 +1214,40 @@ public class NewsLocalDetailActivity extends BaseActivity {
}
}
private void getUserIsPublicCode() {
if (!TextUtils.isEmpty(UserLgUtils.getUserId())) {
RetrofitManager.getInstance()
.create(BaseApiService.class)
.getIsPublicCode(UserLgUtils.getUserId())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Boolean>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(Boolean baseSuccessBean) {
UserLgUtils.putIsPublicCode(baseSuccessBean);
getNewsDetail();
}
@Override
public void onError(Throwable e) {
getNewsDetail();
}
@Override
public void onComplete() {
}
});
} else {
getNewsDetail();
}
}
/**
* 显示评论dialog
*/
@ -1531,6 +1595,18 @@ public class NewsLocalDetailActivity extends BaseActivity {
}
}
private void refreshPage() {
if (mContentSkeleton != null) {
mContentSkeleton.show();
} else {
mContentSkeleton = Skeleton.bind(mLlNewsContent)
.load(R.layout.item_skeleton_news_content_local)
.show();
}
mRlPublicCode.setVisibility(View.GONE);
getNewsDetail();
}
public class SocketMsg extends BroadcastReceiver {
@Override
@ -1538,8 +1614,19 @@ public class NewsLocalDetailActivity extends BaseActivity {
String action = intent.getAction();
if (PathConfig.ACTION_FROM_SOCKET_PUSH_MSG.equals(action)) {
//关注公众号
String strData = intent.getStringExtra(PathConfig.PUSH_DATA_KEY);
LogUtils.e("二维码返回:" + strData);
//关闭socket
stopService(new Intent(mActivity, SocketService.class));
try {
String strData = intent.getStringExtra(PathConfig.PUSH_DATA_KEY);
AttentionCodeBean errorBean = new Gson().fromJson(strData, AttentionCodeBean.class);
UserLgUtils.putIsPublicCode(errorBean.isAttention());
//刷新页面
if (errorBean.isAttention()) {
refreshPage();
}
} catch (Exception e) {
}
}
}
}
@ -1551,6 +1638,10 @@ public class NewsLocalDetailActivity extends BaseActivity {
mAudio.pause();
mAudio.release();
}
boolean processIsRuning = AppUtils.getProcessIsRuning(mActivity, "com.tengshisoft.mudulemain.cultural.socket.SocketService");
if (processIsRuning) {
stopService(new Intent(mActivity, SocketService.class));
}
if (mSocketMsg != null) {
unregisterReceiver(mSocketMsg);
}

View File

@ -0,0 +1,32 @@
package com.tengshisoft.mudulemain.cultural.beans;
public class AttentionCodeBean {
private String appId;
private String userId;
private boolean attention;
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public boolean isAttention() {
return attention;
}
public void setAttention(boolean attention) {
this.attention = attention;
}
}

View File

@ -0,0 +1,217 @@
package com.tengshisoft.mudulemain.cultural.socket;
import android.app.ActivityManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import androidx.annotation.Nullable;
import com.sucstepsoft.cm_utils.constant.PathConfig;
import com.sucstepsoft.cm_utils.core.retrofit_net.BaseUrlApi;
import com.sucstepsoft.cm_utils.core.widget.base.NotificationUtils;
import com.sucstepsoft.cm_utils.utils.LogUtils;
import com.sucstepsoft.cm_utils.utils.UserLgUtils;
import com.tengshisoft.mudulemain.R;
import org.json.JSONObject;
import java.util.List;
import io.reactivex.disposables.Disposable;
public class SocketService extends Service {
private MediaPlayer mMediaPlayer;
private WsManager mWsManager;
private Disposable mSocketHeart;
@Override
public void onCreate() {
super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
startPlayVoice();
startForegroundNotify();
startSocket();
return START_STICKY;
}
private void startSocket() {
mWsManager = new WsManager
.Builder(getApplication())
.wsUrl(BaseUrlApi.SOCKET_IP + UserLgUtils.getUserId())
.needReconnect(true)
.build();
mWsManager.startConnect();
}
/**
* 进程保活-开启前台通知,提升服务进程
*/
private void startForegroundNotify() {
startForeground(PathConfig.NOTIFY_ID, NotificationUtils.buildNotification(getApplicationContext(), PathConfig.PROJECT_NAME_CH, PathConfig.PROJECT_NAME_CH + "平台正在运行中..."));
}
/**
* 进程保活-后台播放音乐
*/
private void startPlayVoice() {
if (mMediaPlayer == null) {
mMediaPlayer = MediaPlayer.create(this, R.raw.no_kill);
mMediaPlayer.setVolume(0f, 0f);
mMediaPlayer.setOnCompletionListener(mp -> playVoice());
playVoice();
}
}
/**
* 开始播放音乐
*/
private void playVoice() {
if (mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
mMediaPlayer.start();
}
}
private void pauseVoice() {
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
mMediaPlayer.pause();
}
}
/**
* 判断activity是否在运行
*
* @return
*/
private boolean isActivityAlive() {
ActivityManager am = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> runningTasks = am.getRunningTasks(100);
for (ActivityManager.RunningTaskInfo info : runningTasks) {
LogUtils.e("前台运行===" + info.topActivity.getClassName());
if (this.getPackageName().equals(info.topActivity.getPackageName())) {
return true;
}
}
return false;
}
/**
* 判断App是否在前台
*
* @return
*/
private boolean appOnForeground() {
ActivityManager am = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> appProcesses = am.getRunningAppProcesses();
if (appProcesses == null) {
return false;
}
for (ActivityManager.RunningAppProcessInfo info : appProcesses) {
if (info.processName.equals(this.getPackageName()) && info.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
return true;
}
}
return false;
}
/**
* 发送系统通知
*/
private void sendSystemNotify(String from, JSONObject obj) {
}
/**
* 发送socket已办
*/
private void sendSocketNoticeMsg(String msg) {
if (mWsManager != null) {
mWsManager.sendMessage(msg);
}
}
/**
* socket
*/
private void startSocketService() {
if (mWsManager == null) {
mWsManager = new WsManager
.Builder(getApplication())
.wsUrl(BaseUrlApi.SOCKET_IP)
.needReconnect(true)
.build();
}
if (!mWsManager.isWsConnected()) {
mWsManager.startConnect();
//心跳
}
}
/**
* 停止连接socket
*/
private void stopSocketService() {
if (mWsManager != null && mWsManager.isWsConnected()) {
mWsManager.stopConnect();
mWsManager = null;
if (mSocketHeart != null && !mSocketHeart.isDisposed()) {
mSocketHeart.dispose();
mSocketHeart = null;
}
}
}
/**
* 发送一个通知
*/
private void sendNotify(String from, String msg, String page, int type) {
// NotificationUtils utils = new NotificationUtils(SocketService.this);
// if (TextUtils.isEmpty(page)) {
// utils.sendNotification(1000865, from, msg);
// } else {
// // 判断是普通通知还是通话通知
// Intent intent = new Intent();
// intent.setAction(LionActions.ACTION_PUSH_MSG_ACTIVITY);
// intent.putExtra("page", page);
// intent.putExtra("type", type);
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// PendingIntent pIntent = PendingIntent.getActivity(this, 12, intent, PendingIntent.FLAG_CANCEL_CURRENT);
// utils.sendNotificationPendingIntent(from, msg, pIntent);
//
// }
}
@Override
public void onDestroy() {
super.onDestroy();
stopSocketService();
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
mMediaPlayer.stop();
mMediaPlayer = null;
}
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
}

View File

@ -290,8 +290,11 @@
<RelativeLayout
android:id="@+id/rl_public_code"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:visibility="gone"
android:layout_height="match_parent">
tools:visibility="visible">
<com.github.mmin18.widget.RealtimeBlurView
android:layout_width="match_parent"
@ -300,24 +303,31 @@
app:realtimeOverlayColor="#8000" />
<TextView
android:layout_width="match_parent"
android:id="@+id/tv_public_code_hint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="关注公众号继续阅读"
android:textColor="@color/white"
android:textSize="@dimen/text_20"
android:textStyle="bold" />
android:textStyle="bold"
tools:textColor="@color/black" />
<Button
android:id="@+id/btn_public"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
android:layout_below="@id/tv_public_code_hint"
android:layout_alignLeft="@id/tv_public_code_hint"
android:layout_alignRight="@id/tv_public_code_hint"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:layout_marginRight="10dp"
android:background="@drawable/sel_btn_submit_no_size"
android:minHeight="0dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="去关注"
android:textColor="@color/white" />
</RelativeLayout>

Binary file not shown.

View File

@ -175,6 +175,7 @@ public class SettingActivity extends BaseActivity {
private void loginOut() {
UserLgUtils.setToken("");
UserLgUtils.setId("");
UserLgUtils.putIsPublicCode(false);
isLogin = false;
mTvLoginOut.setText("登录");
ToastUtils.showShort("退出成功");