Commit ef4a0be0 by 王宇航

將用戶模塊,訂單模塊移出。登陸頁面請求完成,還有錯誤。

parent 864fd762
......@@ -71,8 +71,6 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':mvp:arms')
// addComponent 'component_login'
// addComponent 'component_register'
......
......@@ -61,4 +61,5 @@ public interface IView {
* 杀死自己
*/
void killMyself();
}
......@@ -36,5 +36,5 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':mvp:arms')
implementation project(':arms')
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
minSdkVersion 18
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation files('libs/sun.misc.BASE64Decoder.jar')
}
package com.joe.utils;
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() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.joe.utils.test", appContext.getPackageName());
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.joe.utils" />
/*
* 文 件 名: Base64.java
* 版 权: Copyright www.face-garden.com Corporation 2014 版权所有
* 描 述: <描述>
* 修 改 人: shiwei
* 修改时间: 2014-12-25
* 跟踪单号: <跟踪单号>
* 修改单号: <修改单号>
* 修改内容: <修改内容>
*/
package com.joe.utils.encryption;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
/**
* <一句话功能简述> <功能详细描述>
*
* @author shiwei
* @version [版本号, 2014-12-25]
* @see [相关类/方法]
* @since [产品/模块版本]
*/
public class Base64 {
private static final char[] legalChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
.toCharArray();
/**
* data[]进行编码
*
* @param data
* @return
*/
public static String encode(byte[] data) {
int start = 0;
int len = data.length;
StringBuffer buf = new StringBuffer(data.length * 3 / 2);
int end = len - 3;
int i = start;
int n = 0;
while (i <= end) {
int d = (((data[i]) & 0x0ff) << 16)
| (((data[i + 1]) & 0x0ff) << 8)
| ((data[i + 2]) & 0x0ff);
buf.append(legalChars[(d >> 18) & 63]);
buf.append(legalChars[(d >> 12) & 63]);
buf.append(legalChars[(d >> 6) & 63]);
buf.append(legalChars[d & 63]);
i += 3;
if (n++ >= 14) {
n = 0;
buf.append(" ");
}
}
if (i == start + len - 2) {
int d = (((data[i]) & 0x0ff) << 16)
| (((data[i + 1]) & 255) << 8);
buf.append(legalChars[(d >> 18) & 63]);
buf.append(legalChars[(d >> 12) & 63]);
buf.append(legalChars[(d >> 6) & 63]);
buf.append("=");
} else if (i == start + len - 1) {
int d = ((data[i]) & 0x0ff) << 16;
buf.append(legalChars[(d >> 18) & 63]);
buf.append(legalChars[(d >> 12) & 63]);
buf.append("==");
}
return buf.toString();
}
private static int decode(char c) {
if (c >= 'A' && c <= 'Z')
return (c) - 65;
else if (c >= 'a' && c <= 'z')
return (c) - 97 + 26;
else if (c >= '0' && c <= '9')
return (c) - 48 + 26 + 26;
else
switch (c) {
case '+':
return 62;
case '/':
return 63;
case '=':
return 0;
default:
throw new RuntimeException("unexpected code: " + c);
}
}
/**
* Decodes the given Base64 encoded String to a new byte array. The byte
* array holding the decoded data is returned.
*/
public static byte[] decode(String s) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
decode(s, bos);
} catch (IOException e) {
throw new RuntimeException();
}
byte[] decodedBytes = bos.toByteArray();
try {
bos.close();
bos = null;
} catch (IOException ex) {
System.err.println("Error while decoding BASE64: " + ex.toString());
}
return decodedBytes;
}
private static void decode(String s, OutputStream os) throws IOException {
int i = 0;
int len = s.length();
while (true) {
while (i < len && s.charAt(i) <= ' ')
i++;
if (i == len)
break;
int tri = (decode(s.charAt(i)) << 18)
+ (decode(s.charAt(i + 1)) << 12)
+ (decode(s.charAt(i + 2)) << 6)
+ (decode(s.charAt(i + 3)));
os.write((tri >> 16) & 255);
if (s.charAt(i + 2) == '=')
break;
os.write((tri >> 8) & 255);
if (s.charAt(i + 3) == '=')
break;
os.write(tri & 255);
i += 4;
}
}
}
package com.joe.utils.encryption;
import java.io.IOException;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import Decoder.BASE64Decoder;
import Decoder.BASE64Encoder;
public class DESUtil {
private final static String DES = "DES";
private final static String KEY = "gingerso";
public static String encrypt(String args) {
// String data = "123456";
// System.err.println(encrypt(data, key));
// System.err.println(decrypt("c7Y73rm2l0w=", key));
// System.out.println("解密"+decrypt("qsiZS3lTTp9PDAcS3PeCZmthelKEXO4FbCSzajOULURsRY55VA1v9I+D4Kfy ELoL40zaBae/F1g=", "gingerso"));
String text = args;
// 安卓调用
String result1 = null;// 加密
try {
result1 = encryptDES(args, KEY);
} catch (Exception e) {
e.printStackTrace();
return "";
}
// String result2 = decryptDES(result1, key);// 解密
System.out.println(result1);
// System.out.println(result2);
return result1;
}
private static byte[] iv = {1, 2, 3, 4, 5, 6, 7, 8};
public static String encryptDES(String encryptString, String encryptKey)
throws Exception {
// IvParameterSpec zeroIv = new IvParameterSpec(new byte[8]);
IvParameterSpec zeroIv = new IvParameterSpec(iv);
SecretKeySpec key = new SecretKeySpec(encryptKey.getBytes(), "DES");
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");//DES是加密方式 CBC是工作模式 PKCS5Padding是填充模式
cipher.init(Cipher.ENCRYPT_MODE, key, zeroIv);
byte[] encryptedData = cipher.doFinal(encryptString.getBytes());
return Base64.encode(encryptedData);
}
@SuppressWarnings("static-access")
public static String decryptDES(String decryptString, String decryptKey) throws Exception {
byte[] byteMi = Base64.decode(decryptString);
IvParameterSpec zeroIv = new IvParameterSpec(iv);
// IvParameterSpec zeroIv = new IvParameterSpec(new byte[8]);
SecretKeySpec key = new SecretKeySpec(decryptKey.getBytes(), "DES");
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, key, zeroIv);
byte decryptedData[] = cipher.doFinal(byteMi);
return new String(decryptedData);
}
/**
* Description 根据键值进行加密
*
* @param data
* @param key 加密键byte数组
* @return
* @throws Exception
*/
public static String encrypt(String data, String key) throws Exception {
byte[] bt = encrypt(data.getBytes(), key.getBytes());
String strs = new BASE64Encoder().encode(bt);
return strs;
}
/**
* Description 根据键值进行解密
*
* @param data
* @param key 加密键byte数组
* @return
* @throws IOException
* @throws Exception
*/
public static String decrypt(String data, String key) {
if (data == null)
return null;
BASE64Decoder decoder = new BASE64Decoder();
byte[] buf = new byte[0];
try {
buf = decoder.decodeBuffer(data);
} catch (IOException e) {
e.printStackTrace();
}
byte[] bt = new byte[0];
try {
bt = decrypt(buf, key.getBytes());
} catch (Exception e) {
e.printStackTrace();
}
return new String(bt);
}
/**
* Description 根据键值进行加密
*
* @param data
* @param key 加密键byte数组
* @return
* @throws Exception
*/
private static byte[] encrypt(byte[] data, byte[] key) throws Exception {
// 生成一个可信任的随机数源
SecureRandom sr = new SecureRandom();
// 从原始密钥数据创建DESKeySpec对象
DESKeySpec dks = new DESKeySpec(key);
// 创建一个密钥工厂,然后用它把DESKeySpec转换成SecretKey对象
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
SecretKey securekey = keyFactory.generateSecret(dks);
// Cipher对象实际完成加密操作
Cipher cipher = Cipher.getInstance(DES);
// 用密钥初始化Cipher对象
cipher.init(Cipher.ENCRYPT_MODE, securekey, sr);
return cipher.doFinal(data);
}
/**
* Description 根据键值进行解密
*
* @param data
* @param key 加密键byte数组
* @return
* @throws Exception
*/
private static byte[] decrypt(byte[] data, byte[] key) throws Exception {
// 生成一个可信任的随机数源
SecureRandom sr = new SecureRandom();
// 从原始密钥数据创建DESKeySpec对象
DESKeySpec dks = new DESKeySpec(key);
// 创建一个密钥工厂,然后用它把DESKeySpec转换成SecretKey对象
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
SecretKey securekey = keyFactory.generateSecret(dks);
// Cipher对象实际完成解密操作
Cipher cipher = Cipher.getInstance(DES);
// 用密钥初始化Cipher对象
cipher.init(Cipher.DECRYPT_MODE, securekey, sr);
return cipher.doFinal(data);
}
public static void main(String[] args) {
try {
System.out.print(encrypt("{\"passWord\":\"123456\",\"userName\":\"18384840551\"}"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
<resources>
<string name="app_name">public-utils</string>
</resources>
package com.joe.utils;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
include ':app',
':mvp:arms',
include ':app', ':public-utils',
':cc-register', ':cc',
':android_internal',
':public2:component-database',
':order:component-order-list',
':order:component-order-detail',
':user:component-login',
':user:component-register',
':arms',
':order-detail',
':order-list',
'public-database',
'public-network',
'user-login',
'user-register'
rootProject.name='GSA-Cloud'
......@@ -36,6 +36,7 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':mvp:arms')
implementation project(':arms')
implementation project(path: ':public-utils')
}
......@@ -9,14 +9,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/user_login_AppTheme">
<activity android:name="com.gingersoft.gsa.cloud.user.login.LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".mvp.ui.activity.LoginActivity"></activity>
</application>
</manifest>
\ No newline at end of file
......@@ -4,6 +4,7 @@ import com.billy.cc.core.component.CC;
import com.billy.cc.core.component.CCResult;
import com.billy.cc.core.component.CCUtil;
import com.billy.cc.core.component.IComponent;
import com.gingersoft.gsa.cloud.user.login.mvp.ui.activity.LoginActivity;
public class ComponentLogin implements IComponent {
......
package com.gingersoft.gsa.cloud.user.login.di.component;
import dagger.BindsInstance;
import dagger.Component;
import com.jess.arms.di.component.AppComponent;
import com.gingersoft.gsa.cloud.user.login.di.module.LoginAModule;
import com.gingersoft.gsa.cloud.user.login.mvp.contract.LoginAContract;
import com.jess.arms.di.scope.ActivityScope;
import com.gingersoft.gsa.cloud.user.login.mvp.ui.activity.LoginActivity;
/**
* ================================================
* Description:
* <p>
* Created by MVPArmsTemplate on 12/20/2019 18:41
* <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
* <a href="https://github.com/JessYanCoding">Follow me</a>
* <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
* <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
* <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
* ================================================
*/
@ActivityScope
@Component(modules = LoginAModule.class, dependencies = AppComponent.class)
public interface LoginAComponent {
void inject(LoginActivity activity);
@Component.Builder
interface Builder {
@BindsInstance
LoginAComponent.Builder view(LoginAContract.View view);
LoginAComponent.Builder appComponent(AppComponent appComponent);
LoginAComponent build();
}
}
\ No newline at end of file
package com.gingersoft.gsa.cloud.user.login.di.module;
import com.jess.arms.di.scope.ActivityScope;
import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import com.gingersoft.gsa.cloud.user.login.mvp.contract.LoginAContract;
import com.gingersoft.gsa.cloud.user.login.mvp.model.LoginAModel;
/**
* ================================================
* Description:
* <p>
* Created by MVPArmsTemplate on 12/20/2019 18:41
* <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
* <a href="https://github.com/JessYanCoding">Follow me</a>
* <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
* <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
* <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
* ================================================
*/
@Module
public abstract class LoginAModule {
@Binds
abstract LoginAContract.Model bindLoginAModel(LoginAModel model);
}
\ No newline at end of file
package com.gingersoft.gsa.cloud.user.login.mvp.bean;
/**
* Created by Wyh on 2019/12/20.
*/
public class TestLoginBean {
/**
* success : true
* sysTime : 1.7506064484631255E7
* data : {"user":{"id":-2.59329254789086E7,"groupId":4.9519301404318124E7,"parentId":7.234733767439088E7,"merchantsId":-7.917127479317397E7,"userName":"Lorem ut in qui","mobile":"et non tempor ut","email":"est velit occaecat Excepteur ad","status":-2.4309450245410383E7,"createTime":"ea proident Excepteur","createBy":"Excepteur proident dolor anim","updateTime":"mag","updateBy":"nisi sed ut esse ex"},"token":"in"}
*/
private boolean success;
private double sysTime;
private DataBean data;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public double getSysTime() {
return sysTime;
}
public void setSysTime(double sysTime) {
this.sysTime = sysTime;
}
public DataBean getData() {
return data;
}
public void setData(DataBean data) {
this.data = data;
}
public static class DataBean {
/**
* user : {"id":-2.59329254789086E7,"groupId":4.9519301404318124E7,"parentId":7.234733767439088E7,"merchantsId":-7.917127479317397E7,"userName":"Lorem ut in qui","mobile":"et non tempor ut","email":"est velit occaecat Excepteur ad","status":-2.4309450245410383E7,"createTime":"ea proident Excepteur","createBy":"Excepteur proident dolor anim","updateTime":"mag","updateBy":"nisi sed ut esse ex"}
* token : in
*/
private UserBean user;
private String token;
public UserBean getUser() {
return user;
}
public void setUser(UserBean user) {
this.user = user;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public static class UserBean {
/**
* id : -2.59329254789086E7
* groupId : 4.9519301404318124E7
* parentId : 7.234733767439088E7
* merchantsId : -7.917127479317397E7
* userName : Lorem ut in qui
* mobile : et non tempor ut
* email : est velit occaecat Excepteur ad
* status : -2.4309450245410383E7
* createTime : ea proident Excepteur
* createBy : Excepteur proident dolor anim
* updateTime : mag
* updateBy : nisi sed ut esse ex
*/
private double id;
private double groupId;
private double parentId;
private double merchantsId;
private String userName;
private String mobile;
private String email;
private double status;
private String createTime;
private String createBy;
private String updateTime;
private String updateBy;
public double getId() {
return id;
}
public void setId(double id) {
this.id = id;
}
public double getGroupId() {
return groupId;
}
public void setGroupId(double groupId) {
this.groupId = groupId;
}
public double getParentId() {
return parentId;
}
public void setParentId(double parentId) {
this.parentId = parentId;
}
public double getMerchantsId() {
return merchantsId;
}
public void setMerchantsId(double merchantsId) {
this.merchantsId = merchantsId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public double getStatus() {
return status;
}
public void setStatus(double status) {
this.status = status;
}
public String getCreateTime() {
return createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
public String getCreateBy() {
return createBy;
}
public void setCreateBy(String createBy) {
this.createBy = createBy;
}
public String getUpdateTime() {
return updateTime;
}
public void setUpdateTime(String updateTime) {
this.updateTime = updateTime;
}
public String getUpdateBy() {
return updateBy;
}
public void setUpdateBy(String updateBy) {
this.updateBy = updateBy;
}
}
}
}
package com.gingersoft.gsa.cloud.user.login.mvp.contract;
import com.gingersoft.gsa.cloud.user.login.mvp.bean.TestLoginBean;
import com.jess.arms.mvp.IView;
import com.jess.arms.mvp.IModel;
import java.util.HashMap;
import io.reactivex.Observable;
/**
* ================================================
* Description:
* <p>
* Created by MVPArmsTemplate on 12/20/2019 18:41
* <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
* <a href="https://github.com/JessYanCoding">Follow me</a>
* <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
* <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
* <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
* ================================================
*/
public interface LoginAContract {
//对于经常使用的关于UI的方法可以定义到IView中,如显示隐藏进度条,和显示文字消息
interface View extends IView {
void loginSuccess(TestLoginBean info);
void loginOut();
}
//Model层定义接口,外部只需关心Model返回的数据,无需关心内部细节,即是否使用缓存
interface Model extends IModel{
Observable<TestLoginBean> login(HashMap<String, Object> params);
Observable<TestLoginBean> loginOut(HashMap<String, Object> params);
}
}
package com.gingersoft.gsa.cloud.user.login.mvp.model;
import android.app.Application;
import com.gingersoft.gsa.cloud.user.login.mvp.bean.TestLoginBean;
import com.gingersoft.gsa.cloud.user.login.mvp.server.LoginService;
import com.google.gson.Gson;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;
import com.jess.arms.di.scope.ActivityScope;
import javax.inject.Inject;
import com.gingersoft.gsa.cloud.user.login.mvp.contract.LoginAContract;
import com.joe.utils.encryption.DESUtil;
import java.util.HashMap;
import io.reactivex.Observable;
/**
* ================================================
* Description:
* <p>
* Created by MVPArmsTemplate on 12/20/2019 18:41
* <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
* <a href="https://github.com/JessYanCoding">Follow me</a>
* <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
* <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
* <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
* ================================================
*/
@ActivityScope
public class LoginAModel extends BaseModel implements LoginAContract.Model {
@Inject
Gson mGson;
@Inject
Application mApplication;
@Inject
public LoginAModel(IRepositoryManager repositoryManager) {
super(repositoryManager);
}
@Override
public void onDestroy() {
super.onDestroy();
this.mGson = null;
this.mApplication = null;
}
@Override
public Observable<TestLoginBean> login(HashMap<String, Object> params) {
long times = System.currentTimeMillis();
return mRepositoryManager.obtainRetrofitService(LoginService.class)
.login(DESUtil.encrypt(mGson.toJson(params)),
times + "",
RequestUtils.getSign(params, times));
}
@Override
public Observable<TestLoginBean> loginOut(HashMap<String, Object> params) {
long times = System.currentTimeMillis();
RetrofitUrlManager.getInstance().putDomain("common", "http://gingersoft.tpddns.cn:58201/");
return mRepositoryManager.obtainRetrofitService(LoginService.class)
.loginOut(DESUtil.encrypt(mGson.toJson(params)),
times + "",
RequestUtils.getSign(params, times));
}
}
\ No newline at end of file
package com.gingersoft.gsa.cloud.user.login.mvp.presenter;
import android.app.Application;
import android.util.Log;
import com.gingersoft.gsa.cloud.user.login.mvp.bean.TestLoginBean;
import com.jess.arms.integration.AppManager;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.mvp.BasePresenter;
import com.jess.arms.http.imageloader.ImageLoader;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.schedulers.Schedulers;
import me.jessyan.rxerrorhandler.core.RxErrorHandler;
import me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber;
import javax.inject.Inject;
import com.gingersoft.gsa.cloud.user.login.mvp.contract.LoginAContract;
import com.jess.arms.utils.RxLifecycleUtils;
import java.util.HashMap;
/**
* ================================================
* Description:
* <p>
* Created by MVPArmsTemplate on 12/20/2019 18:41
* <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
* <a href="https://github.com/JessYanCoding">Follow me</a>
* <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
* <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
* <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
* ================================================
*/
@ActivityScope
public class LoginAPresenter extends BasePresenter<LoginAContract.Model, LoginAContract.View> {
@Inject
RxErrorHandler mErrorHandler;
@Inject
Application mApplication;
@Inject
ImageLoader mImageLoader;
@Inject
AppManager mAppManager;
@Inject
public LoginAPresenter(LoginAContract.Model model, LoginAContract.View rootView) {
super(model, rootView);
}
@Override
public void onDestroy() {
super.onDestroy();
this.mErrorHandler = null;
this.mAppManager = null;
this.mImageLoader = null;
this.mApplication = null;
}
public void login(String account, String pwd) {
HashMap<String, Object> params = new HashMap<>();
params.put("userName", account.trim() + "");
params.put("passWord", pwd.trim() + "");
mModel.login(params)
.subscribeOn(Schedulers.io())
.doOnSubscribe(disposable -> mRootView.showLoading())
.subscribeOn(AndroidSchedulers.mainThread())
.observeOn(AndroidSchedulers.mainThread())
.doAfterTerminate(() -> mRootView.hideLoading())
.compose(RxLifecycleUtils.bindToLifecycle(mRootView))
.subscribe(new ErrorHandleSubscriber<TestLoginBean>(mErrorHandler) {
@Override
public void onNext(@NonNull TestLoginBean info) {
Log.e("login", "" + info);
if(info != null && info.isSuccess()){
mRootView.showMessage("登陸成功");
mRootView.loginSuccess(info);
}
}
});
}
public void loginOut() {
HashMap<String, Object> params = new HashMap<>();
mModel.loginOut(params)
.subscribeOn(Schedulers.io())
.doOnSubscribe(disposable -> mRootView.showLoading())
.subscribeOn(AndroidSchedulers.mainThread())
.observeOn(AndroidSchedulers.mainThread())
.doAfterTerminate(() -> mRootView.hideLoading())
.compose(RxLifecycleUtils.bindToLifecycle(mRootView))
.subscribe(new ErrorHandleSubscriber<TestLoginBean>(mErrorHandler) {
@Override
public void onNext(@NonNull TestLoginBean info) {
Log.e("login", "" + info);
mRootView.loginOut();
}
});
}
}
package com.gingersoft.gsa.cloud.user.login.mvp.server;
import android.database.Observable;
import com.gingersoft.gsa.cloud.user.login.mvp.bean.TestLoginBean;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
/**
* Created by Wyh on 2019/12/20.
*/
public interface LoginService {
@FormUrlEncoded
@POST("ricepon-cloud-gsa/api/gsa/login")
Observable<TestLoginBean> login(@Field("args") String args, @Field("time") String time, @Field("sign") String sign);
@FormUrlEncoded
@POST("ricepon-cloud-gsa/api/gsa/logout")
Observable<TestLoginBean> loginOut(@Field("args") String args, @Field("time") String time, @Field("sign") String sign);
}
package com.gingersoft.gsa.cloud.user.login.mvp.ui.activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
import com.gingersoft.gsa.cloud.user.login.R;
import com.gingersoft.gsa.cloud.user.login.mvp.bean.TestLoginBean;
import com.gingersoft.gsa.cloud.user.login.mvp.contract.LoginAContract;
import com.gingersoft.gsa.cloud.user.login.mvp.presenter.LoginAPresenter;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import butterknife.BindView;
import butterknife.ButterKnife;
import static com.jess.arms.utils.Preconditions.checkNotNull;
/**
* ================================================
* Description:
* <p>
* Created by MVPArmsTemplate on 12/20/2019 18:41
* <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
* <a href="https://github.com/JessYanCoding">Follow me</a>
* <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
* <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
* <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
* ================================================
*/
public class LoginActivity extends BaseActivity<LoginAPresenter> implements LoginAContract.View {
@BindView(R.id.ed_gsa_user_account)
EditText account;
@BindView(R.id.ed_gsa_user_login_pwd)
EditText pwd;
@BindView(R.id.tv_gsa_user_login)
TextView login;
@Override
public void setupActivityComponent(@NonNull AppComponent appComponent) {
DaggerLoginAComponent //如找不到该类,请编译一下项目
.builder()
.appComponent(appComponent)
.view(this)
.build()
.inject(this);
}
@Override
public int initView(@Nullable Bundle savedInstanceState) {
return R.layout.activity_login; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
}
@Override
public void initData(@Nullable Bundle savedInstanceState) {
ButterKnife.bind(this);
login.setOnClickListener(v -> {
if ((login.getText().equals("登陸"))) {
mPresenter.login(account.getText().toString(), pwd.getText().toString());
} else {
//退出登錄
mPresenter.loginOut();
}
});
}
@Override
public void initIntent() {
}
@Override
public void initTopBar() {
}
@Override
public void initLanguage() {
}
@Override
public void initLayoutParams() {
}
@Override
public void initLayoutVisible() {
}
@Override
public void showLoading(String message) {
}
@Override
public void hideLoading() {
}
@Override
public void showMessage(@NonNull String message) {
checkNotNull(message);
ArmsUtils.snackbarText(message);
}
@Override
public void launchActivity(@NonNull Intent intent) {
checkNotNull(intent);
ArmsUtils.startActivity(intent);
}
@Override
public void killMyself() {
finish();
}
@Override
public void loginSuccess(TestLoginBean info) {
}
@Override
public void loginOut() {
}
}
......@@ -36,5 +36,5 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':mvp:arms')
implementation project(':arms')
}
<resources>
<string name="demo_a_app_name">Demo_A</string>
</resources>
<resources>
<string name="user_register_app_name">Demo_A</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>
<resources>
<string name="user_register_name">component-user-register</string>
</resources>
package com.gsa.cloud.user.login;
import android.os.Bundle;
import com.gsa.cloud.login.R;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public class LoginActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gsa_user_loginactivity_login);
}
}
<resources>
<string name="demo_a_app_name">Demo_A</string>
</resources>
<resources>
<string name="user_register_app_name">Demo_A</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>
<resources>
<string name="user_register_name">component-user-register</string>
</resources>
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