Commit 8ebbd2f0 authored by mengcuiguang's avatar mengcuiguang

首次提交

parents
Pipeline #91 failed with stages
*.iml
.DS_Store
gradle.properties
local.properties
/.idea
/.gradle
/build
#lib project
app/build
shareSdkLib/build
picture_library/build
ucrop/build
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion rootProject.ext.androidCompileSdkVersion
buildToolsVersion rootProject.ext.androidBuildToolsVersion
defaultConfig {
applicationId "com.mints.goodmoney"
minSdkVersion rootProject.ext.androidMinSdkVersion
targetSdkVersion rootProject.ext.androidTargetSdkVersion
versionCode 1
versionName "1.0.0"
flavorDimensions "default"
// dex突破65535的限制
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
//语言资源,只支持中文
resConfigs "zh"
// ndk {
// //选择要添加的对应cpu类型的.so库。
// abiFilters 'armeabi', 'armeabi-v8a', 'x86'
// // 还可以添加 'x86', 'x86_64', 'mips', 'mips64', 'armeabi-v7a'
// }
//配置so文件
ndk {
abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
}
manifestPlaceholders = [CHANNEL_NAME_VALUE: "mints",
SHARE_KEY : RELEASE_SHARESDK_KEY,
SHARE_SECRET : RELEASE_SHARESDK_SECRET]
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
signingConfigs {
debug {
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD
}
release {
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASSWORD
keyAlias RELEASE_KEY_ALIAS
keyPassword RELEASE_KEY_PASSWORD
}
}
buildTypes {
debug {
// 不显示Log
buildConfigField "boolean", "LOG_DEBUG", "true"
buildConfigField "String", "AppKeyPre", "\"abcd\""
buildConfigField "String", "MainIp", DEBUG_URL
manifestPlaceholders = [TD_SCHEMA_KEY: DEBUG_TD_SCHEMA_KEY,
TD_KEY : DEBUG_TD_KEY]
//混淆
minifyEnabled false
zipAlignEnabled false
shrinkResources false//打开
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
release {
// 不显示Log
buildConfigField "boolean", "LOG_DEBUG", "false"
buildConfigField "String", "AppKeyPre", "\"abcd\""
buildConfigField "String", "MainIp", RELEASE_URL
manifestPlaceholders = [TD_SCHEMA_KEY: RELEASE_TD_SCHEMA_KEY,
TD_KEY : RELEASE_TD_KEY]
//混淆
minifyEnabled true
zipAlignEnabled true
shrinkResources true//打开
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
lintOptions {
//lint 遇到 error 时继续 构建
//abortOnError false
//build release 版本 时 开启lint 检测
checkReleaseBuilds false
// 防止在发布的时候出现因MissingTranslation导致Build Failed!
disable 'MissingTranslation'
}
productFlavors {
yingyongbao {}
position {}
}
productFlavors.all {
flavor -> flavor.manifestPlaceholders = [CHANNEL_NAME_VALUE: name]
}
// 自定义输出配置
applicationVariants.all { variant ->
variant.outputs.all { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
outputFileName = "${variant.productFlavors[0].name}_${defaultConfig.versionName}.apk"
}
}
}
repositories {
flatDir {
dirs 'libs'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
// 网络请求
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
// 异步
implementation "io.reactivex.rxjava2:rxjava:2.2.6"
implementation 'io.reactivex:rxandroid:1.2.1'
// 状态栏适配
implementation 'com.readystatesoftware.systembartint:systembartint:1.0.3'
implementation 'com.gyf.immersionbar:immersionbar:2.3.3-beta15'
// okhttp3日志
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0'
implementation 'com.squareup.okhttp3:okhttp:3.14.2'
implementation 'com.orhanobut:logger:2.1.1'
// 权限
implementation 'com.tbruyelle.rxpermissions:rxpermissions:0.9.3@aar'
// 图片加载
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
// 65536
implementation 'androidx.multidex:multidex:2.0.0'
//下拉刷新
implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-alpha-26'
implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0-alpha-26'
//类似sharedPreference
implementation 'net.grandcentrix.tray:tray:0.12.0'
// 工具类
// gson
implementation files('libs/gson-2.3.1.jar')
// BASE64Decoder
implementation files('libs/sun.misc.BASE64Decoder.jar')
// 三方接入
// shareSdk
implementation project(':shareSdkLib')
// umeng
implementation 'com.umeng.umsdk:analytics:8.0.0'
implementation 'com.umeng.umsdk:common:2.0.0'
// TalkingDada
// implementation files('libs/SaaS_AppAnalytics_Android_SDK_V4.0.36.jar')
// aliyun OSS
implementation 'com.aliyun.dpa:oss-android-sdk:+'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}
This diff is collapsed.
package com.baixing.assistance.myapplication;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.gs.pro.myapplication", appContext.getPackageName());
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.mints.goodmoney">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<application
android:name=".MintsApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/CustomAppTheme"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">
<meta-data
android:name="android.max_aspect"
android:value="2.4" /> <!-- 适配小米(xiaomi)刘海屏 -->
<meta-data
android:name="android.notch_support"
android:value="true" />
<meta-data
android:name="notch.config"
android:value="portrait|landscape" /> <!-- 渠道名称 -->
<meta-data
android:name="CHANNEL_NAME"
android:value="${CHANNEL_NAME_VALUE}" /> <!-- TalkingData -->
<meta-data
android:name="Mob-AppKey"
android:value="${SHARE_KEY}" />
<meta-data
android:name="Mob-AppSecret"
android:value="${SHARE_SECRET}" />
<activity android:name=".ui.activitys.SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.activitys.MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoneTranslucent" />
<activity android:name=".ui.activitys.WebActivity" />
<activity
android:name="com.mints.library.base.BaseWebActivity"
android:theme="@style/AppTheme.NoneTranslucent" />
<service
android:name=".service.UpdateService"
android:exported="true" /> <!-- ShareSDK start -->
<activity
android:name="com.mob.tools.MobUIShell"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:windowSoftInputMode="stateHidden|adjustResize" />
<activity
android:name="cn.sharesdk.tencent.qq.ReceiveActivity"
android:launchMode="singleTask"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="tencent1109991028" />
</intent-filter>
</activity>
<activity
android:name=".wxapi.WXEntryActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<activity
android:name=".apshare.ShareEntryActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.mints.goodmoney.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
</application>
</manifest>
\ No newline at end of file
{
"supplier":{
"vivo":{
"appid":"103255134"
},
"xiaomi":{
"appid":"2882303761518253698"
},
"huawei":{
"appid":"101365295"
},
"yingyongbao":{
"appid":"1109991028"
},
"baidu":{
"appid":"17859897"
},
"oppo":{
"appid":"30220048"
}
}
}
package com.mints.goodmoney;
import android.content.Context;
import android.content.Intent;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.multidex.MultiDex;
import androidx.multidex.MultiDexApplication;
import com.mints.library.utils.CommonUtils;
import com.mints.goodmoney.common.Constant;
import com.mints.goodmoney.net.LoanService;
import com.mints.goodmoney.utils.ForegroundOrBackground;
import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.FormatStrategy;
import com.orhanobut.logger.Logger;
import com.orhanobut.logger.PrettyFormatStrategy;
import com.umeng.commonsdk.UMConfigure;
import rx.Scheduler;
import rx.schedulers.Schedulers;
/**
* 描述:Application
* 作者:孟崔广
* 时间:2020/9/20 11:40
* 邮箱:mengcuiguang@cashbang.cn
*/
public class MintsApplication extends MultiDexApplication {
private static Context mContext;
private static LocalBroadcastManager mLocalBroadcatManager;
private Scheduler defaultSubscribeScheduler;
private LoanService loanService;
/**
* 获取全局context
*/
public static Context getContext() {
return mContext;
}
@Override
public void onCreate() {
super.onCreate();
mContext = this.getApplicationContext();
// 三方配置
thirdConfig();
}
@Override
public void onLowMemory() {
android.os.Process.killProcess(android.os.Process.myPid());
super.onLowMemory();
}
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(base);
}
/**
* 三方配置
*/
private void thirdConfig() {
// TalkingData数据埋点与错误日志
// TalkingDataConfig();
// 判断应用是否在前台
ForegroundOrBackground.init(this);
// 初始化ShareSDK
// MobSDK.init(this);
// 友盟初始化
// initUm(this);
//logger
BindLogger();
}
/**
* 友盟初始化
*/
public void initUm(Context context) {
// System.out.println("mcg __ init um");
/**
* 参数4:设备类型,必须参数,传参数为UMConfigure.DEVICE_TYPE_PHONE则表示手机;传参数为UMConfigure.DEVICE_TYPE_BOX则表示盒子;默认为手机。
* 参数5:Push推送业务的secret,需要集成Push功能时必须传入Push的secret,否则传空。
*/
UMConfigure.init(context, "5db5876b570df381430007da", CommonUtils.getAppMetaData(context, "CHANNEL_NAME"), UMConfigure.DEVICE_TYPE_PHONE, "");
}
/**
* 自定义logger
*/
private void BindLogger() {
//自定义logger
FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder()
.showThreadInfo(false) //是否选择显示线程信息,默认为true
.methodCount(0) //方法数显示多少行,默认2行
.methodOffset(7) //隐藏方法内部调用到偏移量,默认5
// .logStrategy(customLog) //打印日志的策略,默认LogCat
.tag("mints---network") //自定义TAG全部标签,默认PRETTY_LOGGER
.build();
Logger.addLogAdapter(new AndroidLogAdapter(formatStrategy));
}
/**
* 设置TalkingData
*/
// private void TalkingDataConfig() {
// //TalkingData配置
// if (BuildConfig.DEBUG) {
// TCAgent.LOG_ON = true;
// } else {
// TCAgent.LOG_ON = false;
// }
//// String td_channel_id = CommonUtils.getAppMetaData(mContext, "TD_CHANNEL_ID");
// String talkingData_id = CommonUtils.getAppMetaData(mContext, "TD_KEY");
// String td_channel_id = CommonUtils.getAppMetaData(mContext, "CHANNEL_NAME");
// TCAgent.init(this, talkingData_id, td_channel_id);
// TCAgent.setReportUncaughtExceptions(true);
// }
/**
* app退出
*/
public void exitApp() {
Intent intent = new Intent();
intent.setAction(Constant.ACTION_EXIT_APP);
intent.addCategory(Intent.CATEGORY_DEFAULT);
MintsApplication.getLocalBroadcastManager().sendBroadcast(intent);
System.gc();
}
/**
* 获得LocalBroadcastManager对象
*
* @return LocalBroadcastManager对象
*/
public static LocalBroadcastManager getLocalBroadcastManager() {
if (mLocalBroadcatManager == null) {
mLocalBroadcatManager = LocalBroadcastManager.getInstance(mContext);
}
return mLocalBroadcatManager;
}
public LoanService getLoanService() {
if (loanService == null) {
loanService = LoanService.Factory.create(this);
}
return loanService;
}
public void setLoanService(LoanService loanService) {
this.loanService = loanService;
}
public Scheduler defaultSubscribeScheduler() {
if (defaultSubscribeScheduler == null) {
defaultSubscribeScheduler = Schedulers.io();
}
return defaultSubscribeScheduler;
}
}
package com.mints.goodmoney.common;
/**
* 描述:配置app设置开关
* 作者:孟崔广
* 时间:2017/10/10 17:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public class AppConfig {
/**
* 是否正在执行更新
*/
public static boolean app_updateing = false;
/**
* 默认的屏蔽宽度
*/
public static float design_width = 750;
/**
* app应用首页 0-主页 1-position 2-我
*/
public static int fragmentClickFlag = 0;
}
package com.mints.goodmoney.common
import android.os.Environment
object Constant {
/**
* 首次弹出权限声明
*/
const val LOAN_PERMISSION_FLAG = "loan_permission_flag"
/**
* 获取TAGNAME
*/
const val TAG_NAME = "SUN"
/**
* 应用包名
*/
const val MINTS_PKG_NAME = "com.mints.boxing"
/**
* 退出广播tag
*/
const val ACTION_EXIT_APP = "package.exit"
/**
* 是否首次使用(安装后才是首次使用)
*/
const val FIRST_USE_KEY = "app_first_use"
/**
* 默认的加密向量
*/
const val DEFAULT_CHANNEL_SECRET = "mail.gs.com@2x222$#bbb#2"
/**
* 自定义版本控制,为升级后做预操作
*/
const val CUSTOM_VERSION = "custom_version"
/**
* 是否第一次打开app的标示的key,在SplashActivity界面使用
*/
const val ISFIRSTENTER = "isfirstenter"
/**
* 存储地址 /storage/emulated/0/test/
*/
var ICASH_PATH = Environment.getExternalStorageDirectory().path + "/box/" + "apk/"
/**
* app应用首页 0-主页 1-pan 2-friends 3-我
*/
const val FRAGMENT_CLICK_MAIN = 0
const val FRAGMENT_CLICK_PAN = 1
const val FRAGMENT_CLICK_FRIENDS = 2
const val FRAGMENT_CLICK_MY = 3
}
\ No newline at end of file
package com.mints.goodmoney.manager;
import com.mints.goodmoney.MintsApplication;
import com.mints.library.net.neterror.HttpResponseFunc;
import com.mints.goodmoney.mvp.model.BaseResponse;
import rx.Observable;
import rx.Scheduler;
import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
/**
* 描述:AppHttpManager
* 作者:孟崔广
* 时间:2018/01/15 10:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public class AppHttpManager {
private static AppHttpManager _inst;
private MintsApplication application;
private Observable.Transformer exceptTransformer = null;
public synchronized static AppHttpManager getInstance(MintsApplication application) {
if (_inst != null) {
return _inst;
} else {
_inst = new AppHttpManager(application);
return _inst;
}
}
private AppHttpManager(MintsApplication application) {
this.application = application;
return;
}
/**
* @param subscriber
*/
public Subscription call(Observable observable, Subscriber subscriber) {
return observable.compose(schedulersTransformer)
.compose(handleErrTransformer())
.subscribe(subscriber);
}
final Observable.Transformer schedulersTransformer = new Observable.Transformer() {
@Override
public Object call(Object observable) {
Scheduler scheduler = application.defaultSubscribeScheduler();
return ((Observable) observable).subscribeOn(scheduler)
.unsubscribeOn(scheduler)
.observeOn(AndroidSchedulers.mainThread());
}
};
/**
* @param <T>
* @return
*/
public <T> Observable.Transformer<BaseResponse<T>, T> handleErrTransformer() {
if (exceptTransformer != null) {
return exceptTransformer;
} else {
return exceptTransformer = new Observable.Transformer() {
@Override
public Object call(Object observable) {
return ((Observable) observable)/*.map(new HandleFuc<T>())*/.onErrorResumeNext(new HttpResponseFunc<T>());
}
};
}
}
}
package com.mints.goodmoney.manager;
import android.text.TextUtils;
import com.mints.goodmoney.MintsApplication;
import com.mints.goodmoney.mvp.presenters.TrackPresenter;
/**
* 描述:离线管理器
*/
public class TrackManager {
private static volatile TrackManager _inst;
private TrackPresenter trackPresenter = null;
public static TrackManager getInstance() {
if (_inst == null) {
synchronized (TrackManager.class) {
if (_inst == null) {
_inst = new TrackManager();
}
}
}
return _inst;
}
private TrackManager() {
init();
}
private void init() {
trackPresenter = new TrackPresenter();
trackPresenter.attachView((MintsApplication) MintsApplication.getContext());
}
/**
* 离线收益
*/
public void offline() {
if (trackPresenter != null &&
!TextUtils.isEmpty(UserManager.getInstance().getTokenID())) {
trackPresenter.offline();
}
}
}
package com.mints.goodmoney.manager;
import android.text.TextUtils;
import com.mints.goodmoney.MintsApplication;
import com.mints.goodmoney.mvp.model.UserBean;
import net.grandcentrix.tray.AppPreferences;
/**
* 描述:管理用户信息
* 作者:孟崔广
* 时间:2019/10/28 13:54
*/
public class UserManager {
private static UserManager _inst;
private AppPreferences ps;
/**
* 游客 or 登录用户
*/
private static final String IS_TEMP_USER = "is_temp_user";
/**
* 用户ID
*/
private static final String USER_ID = "userId";
/**
* 登陆状态ID
*/
private static final String TOKEN_ID = "tokenId";
/**
* 手机号
*/
private static final String MOBILE = "mobile";
/**
* 姓名
*/
private static final String REAL_NAME = "realName";
/**
* vip是否有效
*/
private static final String VIP_FLAG = "vipFlag";
/**
* vip是否永久
*/
private static final String VIP_FOREVER = "VIP_FOREVER";
private static final String CDK = "CDK";
private static final String CREATE_TIME = "CREATE_TIME";
public static UserManager getInstance() {
if (_inst != null) {
return _inst;
} else {
_inst = new UserManager();
return _inst;
}
}
private UserManager() {
init();
return;
}
private void init() {
ps = new AppPreferences(MintsApplication.getContext());
}
/**
* 保存用户信息
*
* @param userinfo
*/
public void saveUserInfo(UserBean userinfo) {
if (ps == null) {
return;
}
UserBean.ConsumerBean user = userinfo.getConsumer();
String token = userinfo.getToken();
if (token != null) {
ps.put(TOKEN_ID, token);
}
if (user != null) {
String uid = String.valueOf(user.getPk_id());
String mobile = user.getMobile();
if (TextUtils.isEmpty(mobile)) {
ps.remove(IS_TEMP_USER);
} else {
ps.put(IS_TEMP_USER, mobile);
}
if (user.getExpireTime() > 0) {
ps.put(VIP_FLAG, true);
} else {
ps.put(VIP_FLAG, false);
}
ps.put(VIP_FOREVER, user.isForever());
ps.put(USER_ID, uid);
ps.put(CDK, user.getCdk());
ps.put(MOBILE, user.getMobile());
ps.put(CREATE_TIME, user.getCreateTime());
}
}
/**
* 单独获取用户id
*/
public String getMobile() {
if (ps == null) {
return null;
}
return ps.getString(MOBILE, "");
}
public Long getCreateTime() {
if (ps == null) {
return null;
}
return ps.getLong(CREATE_TIME, 0);
}
/**
* 判断用户是否已登录
*
* @return true为已登录 false 为未登录
*/
public boolean userIsLogin() {
if (ps == null) {
return false;
}
// return !TextUtils.isEmpty(ps.getString(TOKEN_ID));
return !TextUtils.isEmpty(ps.getString(IS_TEMP_USER, ""));
}
/**
* 单独获取用户id
*/
public String getUserID() {
if (ps == null) {
return null;
}
return ps.getString(USER_ID, "");
}
public String getUserCDK() {
if (ps == null) {
return null;
}
return ps.getString(CDK, "");
}
public boolean getVipFlag() {
if (ps == null) {
return false;
}
return ps.getBoolean(VIP_FLAG, false);
}
/**
* 获取用户登陆状态
*/
public String getTokenID() {
if (ps == null) {
return null;
}
return ps.getString(TOKEN_ID, "");
}
public boolean getVipForever() {
if (ps == null) {
return false;
}
return ps.getBoolean(VIP_FOREVER, false);
}
public void setVipFlag(boolean vipFlag) {
if (ps == null) {
return;
}
ps.put(VIP_FLAG, vipFlag);
}
/**
* mobile
*
* @param mobile
*/
public void setMobile(String mobile) {
if (ps == null) {
return;
}
ps.put(MOBILE, mobile);
}
public void setVipForever(boolean isForever) {
if (ps == null) {
return;
}
ps.put(VIP_FOREVER, isForever);
}
public void setCreateTime(long createTime) {
if (ps == null) {
return;
}
ps.put(CREATE_TIME, createTime);
}
public void userLogout() {
if (ps != null) {
ps.remove(USER_ID);
ps.remove(MOBILE);
ps.remove(TOKEN_ID);
ps.remove(REAL_NAME);
ps.remove(IS_TEMP_USER);
ps.remove(VIP_FLAG);
ps.remove(VIP_FOREVER);
ps.remove(CDK);
ps.remove(CREATE_TIME);
}
_inst = null;
}
}
package com.mints.goodmoney.mvp.model;
import java.io.Serializable;
/**
* 最外层请求数据
*/
public class AppRequest implements Serializable {
/**
* {
* "data":"SEebPNaIQqWTBAap3xfl21GzkIIVn/7W9S0Fwws6Mhl4mPb8ZjN+xEvQr5cy90px+ lUMt",
* "key":"ckPc1k8d07O5UbV5csWOT1jUsO7rXHvEgAoAVKZYP/8Kabh7HIdHL1wdZ0JHDc OKeNzoDMNo5LunUIW0hc1rLPSWtJblZSuzzN2+/2VJnj1=="
* }
*/
private String channel;
private String sign;
private String check;//新增1.1.9
private String data;
public String getChannel() {
return channel;
}
public void setChannel(String channel) {
this.channel = channel;
}
public String getSign() {
return sign;
}
public void setSign(String sign) {
this.sign = sign;
}
public String getCheck() {
return check;
}
public void setCheck(String check) {
this.check = check;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
}
package com.mints.goodmoney.mvp.model;
import java.io.Serializable;
import java.util.List;
public class BannerBean implements Serializable {
private boolean show;
private List<BannerBean.ListBean> list;
public boolean isShow() {
return show;
}
public void setShow(boolean show) {
this.show = show;
}
public List<BannerBean.ListBean> getList() {
return list;
}
public void setList(List<BannerBean.ListBean> list) {
this.list = list;
}
public class ListBean implements Serializable {
private String url;
private String sid;
private String imgUrl;
private String title;
private String toUrl;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getId() {
return sid;
}
public void setId(String sid) {
this.sid = sid;
}
public String getImgUrl() {
return imgUrl;
}
public void setImgUrl(String imgUrl) {
this.imgUrl = imgUrl;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getToUrl() {
return toUrl;
}
public void setToUrl(String toUrl) {
this.toUrl = toUrl;
}
}
}
package com.mints.goodmoney.mvp.model;
import java.io.Serializable;
/**
* 描述:BaseResponse
* 作者:孟崔广
* 时间:2017/10/10 10:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public class BaseResponse<T> implements Serializable {
/**
* 状态码
*/
private int status;
/**
* 内容
*/
private String message;
/**
* 结果
*/
private T data;
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}
package com.mints.goodmoney.mvp.model;
import java.io.Serializable;
/**
* 描述:用户每次登录上传设备信息
* 作者:孟崔广
* 时间:2019/10/29 18:42
* 邮箱:mengcga@163.com
*/
public class Device implements Serializable {
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column e_device.deviceid
*
* @mbggenerated
*/
private String deviceid;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column e_device.uid
*
* @mbggenerated
*/
private String uid;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column e_device.jgID
*
* @mbggenerated
*/
private String jgid;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column e_device.deviceInfo
*
* @mbggenerated
*/
private String deviceinfo;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column e_device.deviceType
* 1.Android,2.IOS,3.其他
*
* @mbggenerated
*/
private int devicetype;
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column e_device.deviceid
*
* @return the value of e_device.deviceid
* @mbggenerated
*/
public String getDeviceid() {
return deviceid;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column e_device.deviceid
*
* @param deviceid the value for e_device.deviceid
* @mbggenerated
*/
public void setDeviceid(String deviceid) {
this.deviceid = deviceid == null ? null : deviceid.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column e_device.uid
*
* @return the value of e_device.uid
* @mbggenerated
*/
public String getUid() {
return uid;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column e_device.uid
*
* @param uid the value for e_device.uid
* @mbggenerated
*/
public void setUid(String uid) {
this.uid = uid == null ? null : uid.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column e_device.jgID
*
* @return the value of e_device.jgID
* @mbggenerated
*/
public String getJgid() {
return jgid;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column e_device.jgID
*
* @param jgid the value for e_device.jgID
* @mbggenerated
*/
public void setJgid(String jgid) {
this.jgid = jgid == null ? null : jgid.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column e_device.deviceInfo
*
* @return the value of e_device.deviceInfo
* @mbggenerated
*/
public String getDeviceinfo() {
return deviceinfo;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column e_device.deviceInfo
*
* @param deviceinfo the value for e_device.deviceInfo
* @mbggenerated
*/
public void setDeviceinfo(String deviceinfo) {
this.deviceinfo = deviceinfo == null ? null : deviceinfo.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column e_device.deviceType
*
* @return the value of e_device.deviceType
* @mbggenerated
*/
public int getDevicetype() {
return devicetype;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column e_device.deviceType
*
* @param devicetype the value for e_device.deviceType
* @mbggenerated
*/
public void setDevicetype(int devicetype) {
this.devicetype = devicetype;
}
}
\ No newline at end of file
package com.mints.goodmoney.mvp.model;
public class EventMessage<T> {
String message;
private T content;
public EventMessage(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getContent() {
return content;
}
public void setContent(T content) {
this.content = content;
}
}
package com.mints.goodmoney.mvp.model;
import java.io.Serializable;
/**
* 地理位置信息
*/
public class GpsInfo implements Serializable {
private String longitude;
private String latitude;
private String address;
private String province; // 省
private String city; // 市
private String district; // 区
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getDistrict() {
return district;
}
public void setDistrict(String district) {
this.district = district;
}
public String getLongitude() {
return longitude;
}
public void setLongitude(String longitude) {
this.longitude = longitude;
}
public String getLatitude() {
return latitude;
}
public void setLatitude(String latitude) {
this.latitude = latitude;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
package com.mints.goodmoney.mvp.model;
import java.io.Serializable;
/**
* Description: 地理位置数据bean
*/
public class LocationBean implements Serializable {
/*
latitude=39.958008longitude=116.467249
province=北京市#city=北京市#district=朝阳区#
cityCode=010#adCode=110105#address=
北京市朝阳区天泽路靠近中国银行(北京霄云路支行)#
country=中国#road=天泽路#poiName=中国银行(北京霄云路支行)
#street=女人街#streetNum=38号#aoiName=新恒基国际大厦#errorCode=0
#errorInfo=success#locationDetail=-1#locationType=5
*/
private Double latitude;
private Double longitude;
private String province;
private String city;
private String district;
private String address;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Double getLatitude() {
return latitude;
}
public void setLatitude(Double latitude) {
this.latitude = latitude;
}
public Double getLongitude() {
return longitude;
}
public void setLongitude(Double longitude) {
this.longitude = longitude;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getDistrict() {
return district;
}
public void setDistrict(String district) {
this.district = district;
}
}
package com.mints.goodmoney.mvp.model;
import java.io.Serializable;
public class PkgInfo implements Serializable {
private String name;
private String pkgName;
private long installTime;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPkgName() {
return pkgName;
}
public void setPkgName(String pkgName) {
this.pkgName = pkgName;
}
public long getInstallTime() {
return installTime;
}
public void setInstallTime(long installTime) {
this.installTime = installTime;
}
}
package com.mints.goodmoney.mvp.model;
import java.io.Serializable;
/**
* 描述:用户信息
* 作者:孟崔广
* 时间:2019/10/29 18:42
* 邮箱:mengcga@163.com
*/
public class UserBean implements Serializable {
private String token;
private ConsumerBean consumer;
public String getToken() {
return token;
}
public ConsumerBean getConsumer() {
return consumer;
}
public class ConsumerBean implements Serializable {
private String nickName;
private String mobile;
private String idcode;
private String cdk;
private boolean isForever;//true-永久会员
private long expireTime;// vip到期时间 0-非vip
private long pk_id;// 用户id
private long createTime;// 用户id
public String getNickName() {
return nickName;
}
public void setNickName(String nickName) {
this.nickName = nickName;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public long getExpireTime() {
return expireTime;
}
public void setExpireTime(long expireTime) {
this.expireTime = expireTime;
}
public long getPk_id() {
return pk_id;
}
public void setPk_id(long pk_id) {
this.pk_id = pk_id;
}
public boolean isForever() {
return isForever;
}
public void setForever(boolean forever) {
isForever = forever;
}
public String getIdcode() {
return idcode;
}
public void setIdcode(String idcode) {
this.idcode = idcode;
}
public String getCdk() {
return cdk;
}
public void setCdk(String cdk) {
this.cdk = cdk;
}
public long getCreateTime() {
return createTime;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
}
}
}
package com.mints.goodmoney.mvp.model;
import java.io.Serializable;
import java.util.LinkedList;
/**
* 描述:版本信息
* 作者:孟崔广
* 时间:2019/10/29 18:42
* 邮箱:mengcga@163.com
*/
public class Version implements Serializable {
private static final long serialVersionUID = -7241422035310338721L;
/**
* upgrades : [{"updateid":"583ab0df6b4744ae986afcff0d1e45a4","version":"1.0.1","updatemsg":"cj","script":null,"forceflag":1,"updatenum":1,"createtime":1483169915000,"updatetime":1483169918000}]
* forceUpgrade : true
*/
private boolean forceUpgrade;
private LinkedList<UpgradesBean> upgrades;
public boolean isForceUpgrade() {
return forceUpgrade;
}
public void setForceUpgrade(boolean forceUpgrade) {
this.forceUpgrade = forceUpgrade;
}
public LinkedList<UpgradesBean> getUpgrades() {
return upgrades;
}
public void setUpgrades(LinkedList<UpgradesBean> upgrades) {
this.upgrades = upgrades;
}
public class UpgradesBean implements Serializable {
/**
* updateid : 583ab0df6b4744ae986afcff0d1e45a4
* version : 1.0.1
* updatemsg : cj
* script : null
* forceflag : 1
* updatenum : 1
* createtime : 1483169915000
* updatetime : 1483169918000
*/
private String updateid;
private String version;
private String updatemsg;
private String url;
private int forceflag;
private int updatenum;
public String getUpdateid() {
return updateid;
}
public void setUpdateid(String updateid) {
this.updateid = updateid;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public String getUpdatemsg() {
return updatemsg;
}
public void setUpdatemsg(String updatemsg) {
this.updatemsg = updatemsg;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public int getForceflag() {
return forceflag;
}
public void setForceflag(int forceflag) {
this.forceflag = forceflag;
}
public int getUpdatenum() {
return updatenum;
}
public void setUpdatenum(int updatenum) {
this.updatenum = updatenum;
}
}
}
package com.mints.goodmoney.mvp.model;
import java.io.Serializable;
/**
* 第三方登录 微信
*/
public class WXInfo implements Serializable {
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column e_wxinfo.wid
*
* @mbggenerated
*/
private String wid;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column e_wxinfo.uid
*
* @mbggenerated
*/
private String uid;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column e_wxinfo.unionid
*
* @mbggenerated
*/
private String unionid;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column e_wxinfo.openid
*
* @mbggenerated
*/
private String openid;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column e_wxinfo.nickname
*
* @mbggenerated
*/
private String nickname;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column e_wxinfo.headimgurl
*
* @mbggenerated
*/
private String headimgurl;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column e_wxinfo.sex
*
* @mbggenerated
*/
private int sex;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column e_wxinfo.country
*
* @mbggenerated
*/
private String country;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column e_wxinfo.province
*
* @mbggenerated
*/
private String province;
/**
* This field was generated by MyBatis Generator.
* This field corresponds to the database column e_wxinfo.city
*
* @mbggenerated
*/
private String city;
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column e_wxinfo.wid
*
* @return the value of e_wxinfo.wid
* @mbggenerated
*/
public String getWid() {
return wid;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column e_wxinfo.wid
*
* @param wid the value for e_wxinfo.wid
* @mbggenerated
*/
public void setWid(String wid) {
this.wid = wid == null ? null : wid.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column e_wxinfo.uid
*
* @return the value of e_wxinfo.uid
* @mbggenerated
*/
public String getUid() {
return uid;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column e_wxinfo.uid
*
* @param uid the value for e_wxinfo.uid
* @mbggenerated
*/
public void setUid(String uid) {
this.uid = uid == null ? null : uid.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column e_wxinfo.unionid
*
* @return the value of e_wxinfo.unionid
* @mbggenerated
*/
public String getUnionid() {
return unionid;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column e_wxinfo.unionid
*
* @param unionid the value for e_wxinfo.unionid
* @mbggenerated
*/
public void setUnionid(String unionid) {
this.unionid = unionid == null ? null : unionid.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column e_wxinfo.openid
*
* @return the value of e_wxinfo.openid
* @mbggenerated
*/
public String getOpenid() {
return openid;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column e_wxinfo.openid
*
* @param openid the value for e_wxinfo.openid
* @mbggenerated
*/
public void setOpenid(String openid) {
this.openid = openid == null ? null : openid.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column e_wxinfo.nickname
*
* @return the value of e_wxinfo.nickname
* @mbggenerated
*/
public String getNickname() {
return nickname;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column e_wxinfo.nickname
*
* @param nickname the value for e_wxinfo.nickname
* @mbggenerated
*/
public void setNickname(String nickname) {
this.nickname = nickname == null ? null : nickname.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column e_wxinfo.headimgurl
*
* @return the value of e_wxinfo.headimgurl
* @mbggenerated
*/
public String getHeadimgurl() {
return headimgurl;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column e_wxinfo.headimgurl
*
* @param headimgurl the value for e_wxinfo.headimgurl
* @mbggenerated
*/
public void setHeadimgurl(String headimgurl) {
this.headimgurl = headimgurl == null ? null : headimgurl.trim();
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column e_wxinfo.country
*
* @return the value of e_wxinfo.country
* @mbggenerated
*/
public String getCountry() {
return country;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column e_wxinfo.country
*
* @param country the value for e_wxinfo.country
* @mbggenerated
*/
public void setCountry(String country) {
this.country = country == null ? null : country.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column e_wxinfo.province
*
* @return the value of e_wxinfo.province
* @mbggenerated
*/
public String getProvince() {
return province;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column e_wxinfo.province
*
* @param province the value for e_wxinfo.province
* @mbggenerated
*/
public void setProvince(String province) {
this.province = province == null ? null : province.trim();
}
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column e_wxinfo.city
*
* @return the value of e_wxinfo.city
* @mbggenerated
*/
public String getCity() {
return city;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column e_wxinfo.city
*
* @param city the value for e_wxinfo.city
* @mbggenerated
*/
public void setCity(String city) {
this.city = city == null ? null : city.trim();
}
}
\ No newline at end of file
package com.mints.goodmoney.mvp.presenters;
import com.mints.goodmoney.MintsApplication;
import com.mints.goodmoney.mvp.views.BaseView;
import com.mints.goodmoney.net.LoanService;
import rx.Subscription;
/**
* 描述:BasePresenter
* 作者:孟崔广
* 时间:2018/1/10 17:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public class BasePresenter<V extends BaseView> implements Presenter<V> {
protected MintsApplication loanApplication;
protected LoanService loanService;
protected V view;
protected Subscription subscription;
@Override
public void attachView(V v) {
view = v;
loanApplication = view.getBaseApplication();
loanService = loanApplication.getLoanService();
}
@Override
public void detachView() {
view = null;
if (subscription != null && !subscription.isUnsubscribed()) {
subscription.unsubscribe();
}
}
/**
* 判断view是否与activity关联
*
* @return true是未关联 false是关联
*/
public boolean isLinkView() {
return view == null;
}
}
package com.mints.goodmoney.mvp.presenters;
import com.mints.goodmoney.MintsApplication;
import com.mints.goodmoney.net.LoanService;
import rx.Subscription;
/**
* 描述:BasePresenter
* 作者:孟崔广
* 时间:2018/1/10 17:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public class BaseTrackPresenter implements Presenter<MintsApplication> {
protected MintsApplication loanApplication;
protected LoanService loanService;
protected Subscription subscription;
@Override
public void attachView(MintsApplication loanApplication) {
this.loanApplication = loanApplication;
loanService = loanApplication.getLoanService();
}
@Override
public void detachView() {
if (subscription != null && !subscription.isUnsubscribed()) {
subscription.unsubscribe();
}
}
}
package com.mints.goodmoney.mvp.presenters
import android.content.Context
import android.text.TextUtils
import com.mints.goodmoney.common.DeviceInfo
import com.mints.goodmoney.manager.AppHttpManager
import com.mints.goodmoney.manager.UserManager
import com.mints.goodmoney.mvp.model.BaseResponse
import com.mints.goodmoney.mvp.model.UserBean
import com.mints.goodmoney.mvp.views.HomeView
import com.mints.goodmoney.utils.DeviceUuidFactory
import com.mints.library.net.neterror.BaseSubscriber
import com.mints.library.net.neterror.Throwable
import java.util.*
class HomePresenter : BasePresenter<HomeView>() {
/**
* 游客登录
*/
fun userLogin(context: Context) {
val vo = HashMap<String, Any>()
vo["device"] = DeviceUuidFactory(context).deviceUuid.toString()
AppHttpManager.getInstance(loanApplication)
.call(loanService.visitorlogin(vo),
object : BaseSubscriber<BaseResponse<UserBean>>() {
override fun onCompleted() {
}
override fun onError(e: Throwable) {
}
override fun onNext(baseResponse: BaseResponse<UserBean>) {
val code = baseResponse.getStatus()
val message = baseResponse.getMessage()
val data: UserBean? = baseResponse.getData()
when (code) {
200 -> if (data != null) {
UserManager.getInstance().saveUserInfo(data)
val consumer = data.getConsumer()
if (consumer != null) {
saveTerminalInfo(context, consumer)
}
}
else -> view.showToast(message)
}
}
})
}
/**
* 提交设备信息
*
* @param context
*/
fun saveTerminalInfo(context: Context, consumer: UserBean.ConsumerBean) {
val vo = HashMap<String, Any>()
val deviceInfo: DeviceInfo = DeviceInfo.instance
try {
val macAddress: String = deviceInfo.getMacAddress(context)
if (!TextUtils.isEmpty(macAddress)) {
val mac = macAddress.replace(":", "")
vo["mac"] = mac
vo["mac1"] = macAddress
}
} catch (e: Exception) {
e.printStackTrace()
vo["mac"] = "02:00:00:00:00:00"
vo["mac1"] = "02:00:00:00:00:00".replace(":", "")
}
val androidId: String = deviceInfo.getAndroidId(context)
if (!TextUtils.isEmpty(androidId)) {
vo["androidid"] = androidId
}
AppHttpManager.getInstance(loanApplication)
.call(loanService.saveTerminalInfo(vo),
object : BaseSubscriber<BaseResponse<Any>>() {
override fun onCompleted() {
if (isLinkView) return
}
override fun onError(e: Throwable) {
if (isLinkView) return
}
override fun onNext(baseResponse: BaseResponse<Any>) {
if (isLinkView) return
val code = baseResponse.status
when (code) {
200 -> if (consumer != null) {
}
}
}
})
}
}
\ No newline at end of file
package com.mints.goodmoney.mvp.presenters
import android.content.Context
import android.text.TextUtils
import com.mints.goodmoney.common.DeviceInfo
import com.mints.goodmoney.manager.AppHttpManager
import com.mints.goodmoney.manager.UserManager
import com.mints.goodmoney.mvp.model.BaseResponse
import com.mints.goodmoney.mvp.model.UserBean
import com.mints.goodmoney.mvp.views.MyView
import com.mints.goodmoney.utils.DeviceUuidFactory
import com.mints.library.net.neterror.BaseSubscriber
import com.mints.library.net.neterror.Throwable
import java.util.*
class MyPresenter : BasePresenter<MyView>() {
/**
* 游客登录
*/
fun userLogin(context: Context) {
val vo = HashMap<String, Any>()
vo["device"] = DeviceUuidFactory(context).deviceUuid.toString()
AppHttpManager.getInstance(loanApplication)
.call(loanService.visitorlogin(vo),
object : BaseSubscriber<BaseResponse<UserBean>>() {
override fun onCompleted() {
}
override fun onError(e: Throwable) {
}
override fun onNext(baseResponse: BaseResponse<UserBean>) {
val code = baseResponse.getStatus()
val message = baseResponse.getMessage()
val data: UserBean? = baseResponse.getData()
when (code) {
200 -> if (data != null) {
UserManager.getInstance().saveUserInfo(data)
val consumer = data.getConsumer()
if (consumer != null) {
saveTerminalInfo(context, consumer)
}
}
else -> view.showToast(message)
}
}
})
}
/**
* 提交设备信息
*
* @param context
*/
fun saveTerminalInfo(context: Context, consumer: UserBean.ConsumerBean) {
val vo = HashMap<String, Any>()
val deviceInfo: DeviceInfo = DeviceInfo.instance
try {
val macAddress: String = deviceInfo.getMacAddress(context)
if (!TextUtils.isEmpty(macAddress)) {
val mac = macAddress.replace(":", "")
vo["mac"] = mac
vo["mac1"] = macAddress
}
} catch (e: Exception) {
e.printStackTrace()
vo["mac"] = "02:00:00:00:00:00"
vo["mac1"] = "02:00:00:00:00:00".replace(":", "")
}
val androidId: String = deviceInfo.getAndroidId(context)
if (!TextUtils.isEmpty(androidId)) {
vo["androidid"] = androidId
}
AppHttpManager.getInstance(loanApplication)
.call(loanService.saveTerminalInfo(vo),
object : BaseSubscriber<BaseResponse<Any>>() {
override fun onCompleted() {
if (isLinkView) return
}
override fun onError(e: Throwable) {
if (isLinkView) return
}
override fun onNext(baseResponse: BaseResponse<Any>) {
if (isLinkView) return
val code = baseResponse.status
when (code) {
200 -> if (consumer != null) {
}
}
}
})
}
}
\ No newline at end of file
package com.mints.goodmoney.mvp.presenters
import android.content.Context
import android.text.TextUtils
import com.mints.goodmoney.common.DeviceInfo
import com.mints.library.net.neterror.BaseSubscriber
import com.mints.library.net.neterror.Throwable
import com.mints.goodmoney.manager.AppHttpManager
import com.mints.goodmoney.manager.UserManager
import com.mints.goodmoney.mvp.model.BaseResponse
import com.mints.goodmoney.mvp.model.UserBean
import com.mints.goodmoney.mvp.views.PanView
import com.mints.goodmoney.utils.DeviceUuidFactory
import java.util.*
class PanPresenter : BasePresenter<PanView>() {
/**
* 游客登录
*/
fun userLogin(context: Context) {
val vo = HashMap<String, Any>()
vo["device"] = DeviceUuidFactory(context).deviceUuid.toString()
AppHttpManager.getInstance(loanApplication)
.call(loanService.visitorlogin(vo),
object : BaseSubscriber<BaseResponse<UserBean>>() {
override fun onCompleted() {
}
override fun onError(e: Throwable) {
}
override fun onNext(baseResponse: BaseResponse<UserBean>) {
val code = baseResponse.getStatus()
val message = baseResponse.getMessage()
val data: UserBean? = baseResponse.getData()
when (code) {
200 -> if (data != null) {
UserManager.getInstance().saveUserInfo(data)
val consumer = data.getConsumer()
if (consumer != null) {
saveTerminalInfo(context, consumer)
}
}
else -> view.showToast(message)
}
}
})
}
/**
* 提交设备信息
*
* @param context
*/
fun saveTerminalInfo(context: Context, consumer: UserBean.ConsumerBean) {
val vo = HashMap<String, Any>()
val deviceInfo: DeviceInfo = DeviceInfo.instance
try {
val macAddress: String = deviceInfo.getMacAddress(context)
if (!TextUtils.isEmpty(macAddress)) {
val mac = macAddress.replace(":", "")
vo["mac"] = mac
vo["mac1"] = macAddress
}
} catch (e: Exception) {
e.printStackTrace()
vo["mac"] = "02:00:00:00:00:00"
vo["mac1"] = "02:00:00:00:00:00".replace(":", "")
}
val androidId: String = deviceInfo.getAndroidId(context)
if (!TextUtils.isEmpty(androidId)) {
vo["androidid"] = androidId
}
AppHttpManager.getInstance(loanApplication)
.call(loanService.saveTerminalInfo(vo),
object : BaseSubscriber<BaseResponse<Any>>() {
override fun onCompleted() {
if (isLinkView) return
}
override fun onError(e: Throwable) {
if (isLinkView) return
}
override fun onNext(baseResponse: BaseResponse<Any>) {
if (isLinkView) return
val code = baseResponse.status
when (code) {
200 -> if (consumer != null) {
}
}
}
})
}
}
\ No newline at end of file
package com.mints.goodmoney.mvp.presenters;
/**
* 描述:Presenter
* 作者:孟崔广
* 时间:2017/10/10 10:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public interface Presenter<V> {
void attachView(V v);
void detachView();
}
package com.mints.goodmoney.mvp.presenters;
public class TrackPresenter extends BaseTrackPresenter {
/**
* 离线收益
*/
public void offline() {
// AppHttpManager.getInstance(loanApplication)
// .call(loanService.offline(),
// new BaseSubscriber<BaseResponse<Object>>() {
// @Override
// public void onCompleted() {
// }
//
// @Override
// public void onError(Throwable e) {
//
// }
//
// @Override
// public void onNext(BaseResponse<Object> baseResponse) {
// }
// });
}
}
package com.mints.goodmoney.mvp.views;
import com.mints.goodmoney.MintsApplication;
/**
* 描述:BaseView
* 作者:孟崔广
* 时间:2017/10/10 17:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public interface BaseView {
/**
* get view context
*
* @return
*/
MintsApplication getBaseApplication();
/**
* show loading message
*
* @param msg
*/
void showLoading(String msg);
/**
* hide loading
*/
void hideLoading();
/**
* show error exception net message
*/
void showToast(String msg);
}
package com.mints.goodmoney.mvp.views
interface HomeView : BaseView {
}
package com.mints.goodmoney.mvp.views;
public interface LoginView extends BaseView {
/**
* 获取图形验证码成功
*
* @param base64Img
* @param codeId
*/
void sumPhotoCodeSuc(String base64Img,String codeId);
/**
* 发送验证码成功
*/
void sendCodeSuc();
/**
* 登录成功
*/
void loginSuc();
}
package com.mints.goodmoney.mvp.views;
public interface MainView extends BaseView {
}
package com.mints.goodmoney.mvp.views
import com.mints.goodmoney.mvp.model.UserBean
interface MyView : BaseView {
fun getMyInfoSuc(data: UserBean)
}
package com.mints.goodmoney.mvp.views
interface PanView : BaseView {
}
\ No newline at end of file
package com.mints.goodmoney.mvp.views;
public interface WxLoginView extends BaseView {
/**
* 登录成功
*/
void loginSuc();
}
package com.mints.goodmoney.net;
import android.app.Activity;
import com.google.gson.Gson;
import com.mints.goodmoney.MintsApplication;
import com.mints.goodmoney.common.Constant;
import com.mints.goodmoney.mvp.model.BaseResponse;
import com.mints.goodmoney.utils.DeviceUuidFactory;
import com.mints.goodmoney.utils.ForegroundOrBackground;
import com.mints.library.utils.TLog;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.nio.charset.Charset;
import java.util.HashMap;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import okio.Buffer;
import retrofit2.Converter;
import retrofit2.Retrofit;
/**
* Description:gson 2.2 gson全局解析问题
*/
public class GsonConverterFactory extends Converter.Factory {
private final Gson gson;
public static GsonConverterFactory create() {
return create(new Gson());
}
public static GsonConverterFactory create(Gson gson) {
return new GsonConverterFactory(gson);
}
private GsonConverterFactory(Gson gson) {
if (gson == null) throw new NullPointerException("gson == null");
this.gson = gson;
}
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations,
Retrofit retrofit) {
return new GsonResponseBodyConverter<>(gson, type);
}
@Override
public Converter<?, RequestBody> requestBodyConverter(Type type,
Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
return new GsonRequestBodyConverter<>(gson, type);
}
// 这里创建从ResponseBody其它类型的Converter
// 主要用于对响应体的处理
final class GsonResponseBodyConverter<T> implements Converter<ResponseBody, T> {
private final Gson gson;
private final Type type;
GsonResponseBodyConverter(Gson gson, Type type) {
this.gson = gson;
this.type = type;
}
@Override
public T convert(ResponseBody value) throws IOException {
Reader reader = value.charStream();
try {
T t = gson.fromJson(reader, type);
loginInvalid(t);
return t;
} finally {
try {
if (reader != null)
reader.close();
} catch (IOException ignored) {
ignored.printStackTrace();
}
}
}
/**
* 用户登陆失效
*
* @param t
*/
private void loginInvalid(T t) {
if (t instanceof BaseResponse) {
BaseResponse br = (BaseResponse) t;
int code = br.getStatus();
if (code == 401) {
Activity forwardActivity = ForegroundOrBackground.getApp_activity();
try {
if (forwardActivity != null) {
// boolean isMainActivity = forwardActivity instanceof MainActivity;
//
// if (isMainActivity) {
//// ((MainActivity) forwardActivity).MainHandler.sendEmptyMessage(MainActivity.FLAGLOAN);
// UserManager.getInstance().userLogout();
// }
//
// if (!forwardActivity.isFinishing() && !isMainActivity) {
// forwardActivity.startActivity(new Intent(forwardActivity, LoginActivity.class));
// UserManager.getInstance().userLogout();
// }
userLogin(forwardActivity);
}
} catch (Exception e) {
TLog.d(Constant.TAG_NAME, "获取最上层activity出错");
}
}
}
}
}
// 在这里创建 从自定类型到ResponseBody 的Converter
// 主要用于对Part、PartMap、Body注解的处理
final class GsonRequestBodyConverter<T> implements Converter<T, RequestBody> {
private final MediaType MEDIA_TYPE = MediaType.parse("application/json; charset=UTF-8");
private final Charset UTF_8 = Charset.forName("UTF-8");
private final Gson gson;
private final Type type;
GsonRequestBodyConverter(Gson gson, Type type) {
this.gson = gson;
this.type = type;
}
@Override
public RequestBody convert(T value) throws IOException {
Buffer buffer = new Buffer();
Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
gson.toJson(value, type, writer);
writer.flush();
return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
}
/**
* 游客登录
*
* @param activity
*/
private void userLogin(Activity activity) {
if (activity == null)
return;
MintsApplication loanApplication = (MintsApplication) activity.getApplication();
HashMap<String, Object> vo = new HashMap<>();
String uuid = new DeviceUuidFactory(loanApplication).getDeviceUuid().toString();
vo.put("device", uuid);
// loanApplication.getLoanService().visitorlogin(vo)
// .observeOn(AndroidSchedulers.mainThread())
// .subscribeOn(loanApplication.defaultSubscribeScheduler())
// .subscribe(new BaseSubscriber<BaseResponse<UserBean>>() {
// @Override
// public void onCompleted() {
//
// }
//
// @Override
// public void onError(Throwable e) {
//
// }
//
// @Override
// public void onNext(BaseResponse<UserBean> baseResponse) {
// int code = baseResponse.getStatus();
// switch (code) {
// case 200://成功
// UserBean content = baseResponse.getData();
// if (content != null) {
// UserManager.getInstance().saveUserInfo(content);
// saveTerminalInfo(loanApplication, activity, uuid,content.getConsumer());
// }
// break;
// }
// }
// });
}
/**
* 提交设备信息
* @param loanApplication
* @param context
* @param uuid
* @param consumer
*/
// private void saveTerminalInfo(MintsApplication loanApplication, Activity context, String uuid, UserBean.ConsumerBean consumer) {
// if (loanApplication == null || context == null) return;
//
// DeviceInfo deviceInfo = DeviceInfo.getDeviceInfo(context);
// String macAddress = deviceInfo.getMacAddress(context);
//
// HashMap<String, Object> vo = new HashMap<>();
// if (!TextUtils.isEmpty(macAddress)) {
// String mac = macAddress.replace(":", "");
// vo.put("mac", mac);
// vo.put("mac1", macAddress);
//
// }
//
// try {
// String imei = deviceInfo.getIMEI();
// if (!TextUtils.isEmpty(imei)) {
// vo.put("imei", imei);
// }
// } catch (Exception e) {
// e.printStackTrace();
//
// vo.put("imei", "");
// }
//
// String androidId = deviceInfo.getAndroidId(context);
// if (!TextUtils.isEmpty(androidId)) {
// vo.put("androidid", androidId);
// }
//
// vo.put("os", "android");
// vo.put("model", deviceInfo.getMobileModel());
// vo.put("uuid", uuid);
// vo.put("osversion", deviceInfo.getOSVersion());
// vo.put("appversion", deviceInfo.getVersionName());
// vo.put("appPkgList", deviceInfo.getPkgInfo(context));
//
// loanApplication.getLoanService().saveTerminalInfo(vo)
// .observeOn(AndroidSchedulers.mainThread())
// .subscribeOn(loanApplication.defaultSubscribeScheduler())
// .subscribe(new BaseSubscriber<BaseResponse<Object>>() {
// @Override
// public void onCompleted() {
//
// }
//
// @Override
// public void onError(Throwable e) {
//
// }
//
// @Override
// public void onNext(BaseResponse<Object> baseResponse) {
// int code = baseResponse.getStatus();
// switch (code) {
// case 200://成功
// if (consumer != null) {
// //绑定用户jpush
// String userId = String.valueOf(consumer.getPk_id());
// JpushManager.getInstance().setJpushService(userId);
// }
// break;
// }
// }
// });
// }
}
package com.mints.goodmoney.net;
import android.content.Context;
import android.text.TextUtils;
import com.mints.goodmoney.BuildConfig;
import com.mints.goodmoney.mvp.model.BaseResponse;
import com.mints.goodmoney.mvp.model.UserBean;
import com.mints.goodmoney.mvp.model.Version;
import com.mints.goodmoney.utils.AESUtils;
import com.orhanobut.logger.Logger;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.http.Body;
import retrofit2.http.POST;
import rx.Observable;
/**
* 描述:服务器交互
* 作者:孟崔广
* 时间:2019/10/10 10:51
* 邮箱:mengcuiguang@cashbang.cn
*/
public interface LoanService {
/**
* 更新版本
*
* @return
*/
@POST("common/checkUpgrade.do")
Observable<BaseResponse<Version>> checkUpgrade(@Body Map<String, Object> vo);
/**
* 用户反馈
*
* @return
*/
@POST("api/feedback")
Observable<BaseResponse<Object>> feedback(@Body Map<String, Object> vo);
/**
* 游客登录
*
* @return
*/
@POST("api/consumer/visitorlogin")
Observable<BaseResponse<UserBean>> visitorlogin(@Body Map<String, Object> vo);
/**
* 提交设备信息
*
* @return
*/
@POST("api/saveTerminalInfo")
Observable<BaseResponse<Object>> saveTerminalInfo(@Body Map<String, Object> vo);
/**
* 默认http工厂
*/
class Factory {
public static LoanService create(Context context) {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.retryOnConnectionFailure(true);
builder.connectTimeout(20, TimeUnit.SECONDS);
builder.readTimeout(20, TimeUnit.SECONDS);
builder.writeTimeout(20, TimeUnit.SECONDS);
// if (BuildConfig.DEBUG) {
// HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
// logging.setLevel(HttpLoggingInterceptor.Level.BODY);
// builder.interceptors().add(logging);
// }
if (BuildConfig.DEBUG) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor(message -> {
if (TextUtils.isEmpty(message)) return;
String s = message.substring(0, 1);
String request = message.substring(0, 4);
if ("{".equals(s) || "[".equals(s)) {
Logger.json(message);
} else if (request.contains("-->") || request.contains("<--")) {
Logger.d("Method" + message);
} else {
Logger.d("params:" + message);
}
});
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
builder.interceptors().add(logging);
}
OkHttpInterceptor okHttpInterceptor = new OkHttpInterceptor(AESUtils.getDefaultKey());
builder.interceptors().add(okHttpInterceptor);
Retrofit retrofit;
// if (BuildConfig.DEBUG) {
// SPUtil spUtil = SPUtil.getInstance(context);
// if (TextUtils.isEmpty(spUtil.getString(Constant.LOCAL_IP))) {
// spUtil.putString(Constant.LOCAL_IP, "http://39.106.5.102:9081/");
// }
// retrofit = new Retrofit.Builder()
// .client(builder.build())
// .baseUrl(spUtil.getString(Constant.LOCAL_IP))
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// } else {
// retrofit = new Retrofit.Builder()
// .client(builder.build())
// .baseUrl(BuildConfig.MainIp)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
// .build();
// }
retrofit = new Retrofit.Builder()
.client(builder.build())
.baseUrl(BuildConfig.MainIp)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build();
return retrofit.create(LoanService.class);
}
}
}
package com.mints.goodmoney.net;
import android.text.TextUtils;
import com.google.gson.Gson;
import com.mints.goodmoney.BuildConfig;
import com.mints.goodmoney.MintsApplication;
import com.mints.goodmoney.manager.UserManager;
import com.mints.goodmoney.mvp.model.AppRequest;
import com.mints.goodmoney.utils.AESUtils;
import com.mints.goodmoney.utils.Base64;
import com.mints.goodmoney.utils.MD5;
import com.mints.library.utils.CommonUtils;
import java.io.IOException;
import java.nio.charset.Charset;
import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
/**
* 用拦截器对传输数据加密
* Response返回值拦截
*/
public class OkHttpInterceptor implements Interceptor {
private String aesKey = "";
/**
* 实例化拦截器对象
*/
public OkHttpInterceptor(String aesKey) {
this.aesKey = aesKey;
}
@Override
public Response intercept(Chain chain) throws IOException {
String tokenID = UserManager.getInstance().getTokenID();
long time = System.currentTimeMillis();
String channel = CommonUtils.getAppMetaData(MintsApplication.getContext(), "CHANNEL_NAME");
Request request = chain.request();
request = encrypt(request, tokenID, time, channel);//加密方法
Request builder = request.newBuilder().
addHeader("version", BuildConfig.VERSION_NAME).
addHeader("token", tokenID).
addHeader("channel", channel).
addHeader("new-session", MD5.GetMD5Code(String.valueOf(time))).
addHeader("last-session", Base64.encode(String.valueOf(time).getBytes("UTF-8"))).
build();
return chain.proceed(builder);
}
// json加密
private Request encrypt(Request request, String tokenID, long time, String channel) throws IOException {
//这个是请求的url,也就是咱们前面配置的baseUrl
String url = request.url().toString();
//是否加密标识
boolean isSign = true;
if (!TextUtils.isEmpty(url)) {
isSign = !url.contains("common/");
}
//获取请求body,只有@Body 参数的requestBody 才不会为 null
RequestBody requestBody = request.body();
if (requestBody != null) {
okio.Buffer buffer = new okio.Buffer();
requestBody.writeTo(buffer);
Charset charset = Charset.forName("UTF-8");
MediaType contentType = requestBody.contentType();
if (contentType != null) {
charset = contentType.charset(charset);
}
// 原始报文
String valueStr = buffer.readString(charset);
String checkStr = valueStr;
//加密
if (isSign && !TextUtils.isEmpty(valueStr)) {
valueStr = AESUtils.encrypt(valueStr, aesKey);
}
// 渠道
String channelName = "android_" + channel;
// sign
String requestSign = tokenID + ":" + channelName + ":" + time;
String sign = MD5.GetMD5Code(requestSign);
// 验证
String check = MD5.GetMD5Code(requestSign + ":" + checkStr);
AppRequest appRequest = new AppRequest();
appRequest.setChannel(channelName);
appRequest.setSign(sign);
appRequest.setCheck(check);
appRequest.setData(valueStr);
RequestBody body = MultipartBody.create(contentType, new Gson().toJson(appRequest));
request = request.newBuilder()
.post(body)
.build();
}
return request;
}
// json解密
// private Response decrypt(Response response) throws IOException {
// if (response.isSuccessful()) {
// //the response data
// ResponseBody body = response.body();
// BufferedSource source = body.source();
// source.request(Long.MAX_VALUE); // Buffer the entire body.
// Buffer buffer = source.buffer();
// Charset charset = Charset.defaultCharset();
// MediaType contentType = body.contentType();
// if (contentType != null) {
// charset = contentType.charset(charset);
// }
// String string = buffer.clone().readString(charset);
// //解密方法,需要自己去实现
// String bodyString = AESUtils.decrypt(string, aesKey);
// ResponseBody responseBody = ResponseBody.create(contentType, bodyString);
// response = response.newBuilder().body(responseBody).build();
// }
// return response;
// }
// 表单加密
// @Override
// public Response intercept(Chain chain) throws IOException {
// Request request = chain.request();
//
// Request.Builder requestBuilder = request.newBuilder();
// RequestBody requestBody = request.body();
// URL url = request.url().url();
// String urlString = url.toString();
//
// //是否加密标识
// boolean isSign = true;
// if (!TextUtils.isEmpty(urlString)) {
// isSign = !urlString.contains("common/");
// }
//
//// UserManage instance = UserManage.getInstance();
//// String mobile = instance.getMobile();
//// if (!TextUtils.isEmpty(mobile) && isSign) {
//// mobile =AESUtils;
//// }
//
// if (requestBody instanceof FormBody) {
// FormBody.Builder newFormBody = new FormBody.Builder();
// FormBody oldFormBody = (FormBody) requestBody;
//
// for (int i = 0; i < oldFormBody.size(); i++) {
// String name_e = oldFormBody.encodedName(i);
// String value = oldFormBody.value(i);
// String value_e = "";
// if (!TextUtils.isEmpty(value) && isSign) {
// value_e = AESUtils.encrypt(value, aesKey);
// } else {
// value_e = oldFormBody.value(i);
// }
// newFormBody.add(name_e, value_e);
// }
// requestBuilder.method(request.method(), newFormBody.build());
// }
//
// Request newRequest = requestBuilder
// .addHeader("mobile", "18311400069")
// .build();
// Response originalResponse = chain.proceed(newRequest);
//
// return originalResponse;
// }
}
package com.mints.goodmoney.ui.activitys
import android.os.Bundle
import android.view.KeyEvent
import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction
import com.mints.goodmoney.R
import com.mints.goodmoney.common.AppConfig
import com.mints.goodmoney.common.Constant
import com.mints.goodmoney.mvp.views.MainView
import com.mints.goodmoney.ui.activitys.base.BaseActivity
import com.mints.goodmoney.ui.fragment.FriendsFragment
import com.mints.goodmoney.ui.fragment.MainFragment
import com.mints.goodmoney.ui.fragment.MyFragment
import com.mints.goodmoney.ui.fragment.PanFragment
import kotlinx.android.synthetic.main.activity_main.*
/**
* 描述:main
* 作者:孟崔广
* 时间:2020/10/9 10:39
* 邮箱:mengcga@163.com
*/
class MainActivity : BaseActivity(), MainView, View.OnClickListener {
// 底部标签切换的Fragment
private var mainFragment: Fragment? = null
private var panFragment: Fragment? = null
private var friendsFragment: Fragment? = null
private var myFragment: Fragment? = null
private var currentFragment: Fragment? = null
override fun getContentViewLayoutID(): Int {
return R.layout.activity_main
}
override fun initViewsAndEvents() {
if (mainFragment == null) {
mainFragment = MainFragment()
}
if (!mainFragment!!.isAdded) {
// 提交事务
supportFragmentManager.beginTransaction()
.add(R.id.content_layout, mainFragment!!).commitAllowingStateLoss()
// 记录当前Fragment
currentFragment = mainFragment
}
tab_iv_main.setSelected(true)
tab_tv_main.setSelected(true)
tab_rl_main.setOnClickListener(this)
tab_rl_pan.setOnClickListener(this)
tab_rl_friends.setOnClickListener(this)
tab_rl_my.setOnClickListener(this)
}
override fun isApplyKitKatTranslucency(): Boolean {
return false
}
public override fun onDestroy() {
super.onDestroy()
}
public override fun onSaveInstanceState(outState: Bundle) {
//将这一行注释掉,阻止activity保存fragment的状态,防止UI重叠
//super.onSaveInstanceState(outState);
}
var oldTime: Long = 0
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
when (keyCode) {
KeyEvent.KEYCODE_BACK -> {
// 设置为后台
val currentTime = System.currentTimeMillis()
if (currentTime - oldTime < 2 * 1000) {
baseApplication.exitApp()
} else {
showToast("再次点击退出" + getString(R.string.app_name))
oldTime = currentTime
}
}
}
return true
}
override fun onClick(view: View) {
when (view.id) {
R.id.tab_rl_main -> clickTab1Layout()
R.id.tab_rl_pan -> clickTab2Layout()
R.id.tab_rl_friends -> clickTab3Layout()
R.id.tab_rl_my -> clickTab4Layout()
}
}
/**
* 点击第一个tab
*/
fun clickTab1Layout() {
AppConfig.fragmentClickFlag = Constant.FRAGMENT_CLICK_MAIN
if (mainFragment == null) {
mainFragment = MainFragment()
}
addOrShowFragment(supportFragmentManager.beginTransaction(), mainFragment!!)
tab_iv_main.setSelected(true)
tab_tv_main.setSelected(true)
tab_iv_pan.setSelected(false)
tab_tv_pan.setSelected(false)
tab_iv_friends.setSelected(false)
tab_tv_friends.setSelected(false)
tab_iv_my.setSelected(false)
tab_tv_my.setSelected(false)
}
/**
* 点击第二个tab
*/
fun clickTab2Layout() {
AppConfig.fragmentClickFlag = Constant.FRAGMENT_CLICK_PAN
if (panFragment == null) {
panFragment = PanFragment()
}
addOrShowFragment(supportFragmentManager.beginTransaction(), panFragment!!)
tab_iv_main.setSelected(false)
tab_tv_main.setSelected(false)
tab_iv_pan.setSelected(true)
tab_tv_pan.setSelected(true)
tab_iv_friends.setSelected(false)
tab_tv_friends.setSelected(false)
tab_iv_my.setSelected(false)
tab_tv_my.setSelected(false)
}
/**
* 点击第三个tab
*/
private fun clickTab3Layout() {
AppConfig.fragmentClickFlag = Constant.FRAGMENT_CLICK_FRIENDS
if (friendsFragment == null) {
friendsFragment = FriendsFragment()
}
addOrShowFragment(supportFragmentManager.beginTransaction(), friendsFragment!!)
tab_iv_main.setSelected(false)
tab_tv_main.setSelected(false)
tab_iv_pan.setSelected(false)
tab_tv_pan.setSelected(false)
tab_iv_friends.setSelected(true)
tab_tv_friends.setSelected(true)
tab_iv_my.setSelected(false)
tab_tv_my.setSelected(false)
}
/**
* 点击第四个tab
*/
private fun clickTab4Layout() {
AppConfig.fragmentClickFlag = Constant.FRAGMENT_CLICK_MY
if (myFragment == null) {
myFragment = MyFragment()
}
addOrShowFragment(supportFragmentManager.beginTransaction(), myFragment!!)
tab_iv_main.setSelected(false)
tab_tv_main.setSelected(false)
tab_iv_pan.setSelected(false)
tab_tv_pan.setSelected(false)
tab_iv_friends.setSelected(false)
tab_tv_friends.setSelected(false)
tab_iv_my.setSelected(true)
tab_tv_my.setSelected(true)
}
/**
* 添加或者显示碎片
*
* @param transaction
* @param fragment
*/
private fun addOrShowFragment(transaction: FragmentTransaction,
fragment: Fragment) {
if (currentFragment === fragment) return
if (!fragment.isAdded) { // 如果当前fragment未被添加,则添加到Fragment管理器中
transaction.hide(currentFragment!!)
.add(R.id.content_layout, fragment).commitAllowingStateLoss()
} else {
transaction.hide(currentFragment!!).show(fragment).commitAllowingStateLoss()
}
currentFragment = fragment
}
}
\ No newline at end of file
package com.mints.goodmoney.ui.activitys
import android.view.KeyEvent
import android.view.animation.AlphaAnimation
import android.view.animation.Animation
import android.view.animation.AnimationSet
import com.mints.goodmoney.R
import com.mints.goodmoney.common.DeviceInfo
import com.mints.goodmoney.ui.activitys.base.BaseActivity
import kotlinx.android.synthetic.main.activity_splash.*
/**
* 启动页
*/
class SplashActivity : BaseActivity() {
private val mAlph by lazy { AlphaAnimation(1f, 1f) }
private val animationSet by lazy { AnimationSet(true) }
override fun isApplyKitKatTranslucency()=false
override fun initViewsAndEvents() {
if (!isTaskRoot) {
//点击Home键后再点击App图标,会回到原来的界面。今天重新打包后,但是在Debug模式下,一切正常,
// 但是把打完包的apk(Release)安装在其他手机上时,回到桌面后点击图标会重新打开启动页
finish()
return
}
// 校验APP签名
checkAppSign()
}
override fun getContentViewLayoutID()= R.layout.activity_splash
override fun toggleIsBack2Left() = true
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
return if (keyCode == KeyEvent.KEYCODE_BACK) {
true
} else super.onKeyDown(keyCode, event)
}
override fun onDestroy() {
super.onDestroy()
if (mAlph != null) mAlph.cancel()
if (animationSet != null) {
animationSet.cancel()
animationSet.setAnimationListener(null)
}
}
/**
* 校验App签名
*/
private fun checkAppSign() {
val deviceInfo: DeviceInfo = DeviceInfo.instance!!
if (!deviceInfo.signInfo) {
finish()
} else {
setAnimation()
}
}
/**
* 动画实现
*/
private fun setAnimation() {
//渐变动画
mAlph.duration = 1000
mAlph.fillAfter = true
//动画集合
animationSet.addAnimation(mAlph)
splash_root.startAnimation(animationSet)
animationSet.setAnimationListener(mAnimationListener)
}
private val mAnimationListener: Animation.AnimationListener =
object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation) {}
override fun onAnimationRepeat(animation: Animation) {}
override fun onAnimationEnd(animation: Animation) {
readyGoThenKill(MainActivity::class.java)
}
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment