You need to sign in or sign up before continuing.
Commit 9db19690 by 倪力烽

first commit

parents
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
<entry name="!?*.aj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<component name="CopyrightManager">
<settings default="" />
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
<option value="$PROJECT_DIR$/myapplication" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectInspectionProfilesVisibleTreeState">
<entry key="Project Default">
<profile-state>
<expanded-state>
<State>
<id />
</State>
<State>
<id>Android</id>
</State>
<State>
<id>Android &gt; Lint &gt; Correctness</id>
</State>
<State>
<id>Android &gt; Lint &gt; Internationalization</id>
</State>
<State>
<id>Android &gt; Lint &gt; Security</id>
</State>
<State>
<id>Android &gt; Lint &gt; Usability &gt; Typography</id>
</State>
<State>
<id>Assignment issuesGroovy</id>
</State>
<State>
<id>Bitwise operation issuesJava</id>
</State>
<State>
<id>C/C++</id>
</State>
<State>
<id>Class structureJava</id>
</State>
<State>
<id>Code style issuesJava</id>
</State>
<State>
<id>Concurrency annotation issuesJava</id>
</State>
<State>
<id>Control flow issuesJava</id>
</State>
<State>
<id>CorrectnessLintAndroid</id>
</State>
<State>
<id>GeneralC/C++</id>
</State>
<State>
<id>Gradle</id>
</State>
<State>
<id>Groovy</id>
</State>
<State>
<id>Internationalization issuesJava</id>
</State>
<State>
<id>Java</id>
</State>
<State>
<id>Java language level migration aidsJava</id>
</State>
<State>
<id>LintAndroid</id>
</State>
<State>
<id>Performance issuesJava</id>
</State>
<State>
<id>Probable bugsGradle</id>
</State>
<State>
<id>Probable bugsGroovy</id>
</State>
<State>
<id>Probable bugsJava</id>
</State>
<State>
<id>Resource management issuesJava</id>
</State>
<State>
<id>Security issuesJava</id>
</State>
<State>
<id>Threading issuesGroovy</id>
</State>
<State>
<id>Threading issuesJava</id>
</State>
<State>
<id>Type checksC/C++</id>
</State>
</expanded-state>
</profile-state>
</entry>
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/EBike-Administrer-Tool.iml" filepath="$PROJECT_DIR$/EBike-Administrer-Tool.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
<module fileurl="file://$PROJECT_DIR$/myapplication/myapplication.iml" filepath="$PROJECT_DIR$/myapplication/myapplication.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>
\ No newline at end of file
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.senthink.ebike_administrer_tool"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.1'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
/*rotrofit*/
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.3.0'
/*rx-android-java*/
compile 'io.reactivex:rxjava:+'
compile 'com.squareup.retrofit:adapter-rxjava:+'
compile 'com.trello:rxlifecycle:+'
compile 'com.trello:rxlifecycle-components:+'
compile 'com.google.code.gson:gson:2.2.4'
//butterknife
compile 'com.jakewharton:butterknife:8.0.1'
apt 'com.jakewharton:butterknife-compiler:8.0.1'
compile 'com.jakewharton:butterknife:5.1.1'
compile 'com.jakewharton:butterknife:5.1.1'
compile 'com.android.support:design:25.3.1'
compile files('/Users/ni/Documents/lierda/lierda_project/EBike-Administrer-Tool/libs/android-async-http-1.4.6.jar')
compile files('/Users/ni/Documents/lierda/lierda_project/EBike-Administrer-Tool/libs/org.apache.http.legacy.jar')
}
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/ni/Library/Android/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
package com.senthink.ebike_administrer_tool;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumentation 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.senthink.ebike_administrer_tool", appContext.getPackageName());
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.senthink.ebike_administrer_tool" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".LoginActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".MainActivity"/>
</application>
</manifest>
\ No newline at end of file
package com.senthink.ebike_administrer_tool;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v7.app.AppCompatActivity;
import com.senthink.ebike_administrer_tool.utils.UIUtils;
/**
* @Description :
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/6
*/
public class BaseActivity extends AppCompatActivity {
protected final String TAG = getClass().getSimpleName();
public static BaseActivity activity;
@Override
public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
// TODO: 16/9/1 add the third service. eg.umeng ...
activity = this;
((MyApplication) UIUtils.getContext()).addActivity(this);
init();
}
@Override
protected void onResume() {
super.onResume();
activity = this;
}
@Override
protected void onPause() {
super.onPause();
activity = null;
}
private void init() {
initData();
initEvents();
}
/***
* 初始化事件(监听事件等事件绑定)
*/
protected void initEvents() {
}
/**
* 绑定数据
*/
protected void initData() {
}
/**
* activity退出时将activity移出栈
*/
@Override
protected void onDestroy() {
super.onDestroy();
((MyApplication) UIUtils.getContext()).removeActivity(this);
}
}
package com.senthink.ebike_administrer_tool;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
import com.senthink.ebike_administrer_tool.bean.LoginUser;
import com.senthink.ebike_administrer_tool.presenter.impl.LoginPresenterImpl;
import com.senthink.ebike_administrer_tool.view.LoginView;
import butterknife.BindView;
import butterknife.ButterKnife;
public class LoginActivity extends BaseActivity implements LoginView{
@BindView(R.id.et_username)
EditText userNameEt;
@BindView(R.id.et_password)
EditText pswEt;
@BindView(R.id.btn_login)
Button loginBtn;
@BindView(R.id.checkBox2)
CheckBox rememberCb;
private LoginPresenterImpl mLoginPresenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_login);
ButterKnife.bind(this);
mLoginPresenter = new LoginPresenterImpl(this);
initView();
}
public void initView() {
loginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mLoginPresenter.login();
}
});
}
@Override
public String getUserName() {
return userNameEt.getText().toString();
}
@Override
public String getPassWord() {
return pswEt.getText().toString();
}
@Override
public void showLoading() {
}
@Override
public void hideLoading() {
}
@Override
public void toLoginActivity(LoginUser loginUser) {
Toast.makeText(this, loginUser.getUserName() +
" login success , to MainActivity", Toast.LENGTH_SHORT).show();
saveInfo(loginUser);
Intent intent = new Intent();
intent.setClass(LoginActivity.this,MainActivity.class);
startActivity(intent);
}
@Override
public void showFailedError(String msg) {
Toast.makeText(this,
msg, Toast.LENGTH_SHORT).show();
}
/**
* @Description: 保存信息
* @param loginUser
* */
private void saveInfo(LoginUser loginUser) {
SharedPreferences preference = getSharedPreferences("loginUser", Context.MODE_PRIVATE);
SharedPreferences.Editor editor=preference.edit();
editor.putString("username", loginUser.getUserName());
editor.putString("password", loginUser.getPassWord());
editor.commit();
}
}
package com.senthink.ebike_administrer_tool;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.senthink.ebike_administrer_tool.fragment.DispatchFragment;
import com.senthink.ebike_administrer_tool.fragment.HandleIssueFragment;
import com.senthink.ebike_administrer_tool.fragment.MyInformationFragment;
import com.senthink.ebike_administrer_tool.fragment.ReplaceBatteryFragment;
import com.senthink.ebike_administrer_tool.fragment.SafeGuardFragment;
import butterknife.BindView;
/**
* @Description :
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/7
*/
public class MainActivity extends BaseActivity {
//Tab 文字
private final int[] TAB_TITLES = new int[]
{R.string.replace_battery,R.string.safeguard,
R.string.handl_issue,R.string.dispatch,R.string.me};
//Tab 图片
private final int[] TAB_IMGS = new int[]
{R.drawable.tab_replace_battery,R.drawable.tab_safegurad,
R.drawable.tab_handler_issue,R.drawable.tab_dispatch,R.drawable.tab_me};
private final Fragment[] TAB_FRAGMENT = new Fragment[]
{new ReplaceBatteryFragment(),new SafeGuardFragment(),new HandleIssueFragment()
,new DispatchFragment(),new MyInformationFragment()};
private static final int COUNT = 5;
@BindView(R.id.tablayout)
TabLayout mTabLayout;
@BindView(R.id.viewpager)
ViewPager mViewPager;
private MyViewPagerAdapter viewPagerAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_main);
initViews();
}
private void initViews() {
mTabLayout = (TabLayout)findViewById(R.id.tablayout);
setTabs(mTabLayout,this.getLayoutInflater(),TAB_TITLES,TAB_IMGS);
viewPagerAdapter = new MyViewPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.viewpager);
mViewPager.setAdapter(viewPagerAdapter);
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
mTabLayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
}
/**
* @description: 设置添加Tab
*/
private void setTabs(TabLayout tabLayout, LayoutInflater inflater, int[] tabTitlees, int[] tabImgs){
for (int i = 0; i < tabImgs.length; i++) {
TabLayout.Tab tab = tabLayout.newTab();
View view = inflater.inflate(R.layout.layout_tab_custom,null);
tab.setCustomView(view);
TextView tvTitle = (TextView)view.findViewById(R.id.tv_tab);
tvTitle.setText(tabTitlees[i]);
ImageView imgTab = (ImageView) view.findViewById(R.id.img_tab);
imgTab.setImageResource(tabImgs[i]);
tabLayout.addTab(tab);
}
}
/**
* @description: ViewPager 适配器
*/
private class MyViewPagerAdapter extends FragmentPagerAdapter {
public MyViewPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public android.support.v4.app.Fragment getItem(int position) {
return TAB_FRAGMENT[position];
}
@Override
public int getCount() {
return COUNT;
}
}
}
package com.senthink.ebike_administrer_tool;
import android.app.Application;
import android.content.Context;
import android.support.v7.app.AppCompatDelegate;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
/**
* @Description :
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/6
*/
public class MyApplication extends Application{
public final static String TAG = "BaseApplication";
public final static boolean DEBUG = true;
private static MyApplication myApplication;
private static int mainTid;
/**
* Activity集合,来管理所有的Activity
*/
private static List<BaseActivity> activities;
static {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
}
public static Application getContext() {
return myApplication;
}
@Override
public void onCreate() {
super.onCreate();
myApplication = this;
activities = new LinkedList<>();
mainTid = android.os.Process.myTid();
}
/**
* 获取application
*
* @return
*/
public static Context getApplication() {
return myApplication;
}
/**
* 获取主线程ID
*
* @return
*/
public static int getMainTid() {
return mainTid;
}
/**
* 添加一个Activity
*
* @param activity
*/
public void addActivity(BaseActivity activity) {
activities.add(activity);
}
/**
* 结束一个Activity
*
* @param activity
*/
public void removeActivity(BaseActivity activity) {
activities.remove(activity);
}
/**
* 结束当前所有Activity
*/
public static void clearActivities() {
ListIterator<BaseActivity> iterator = activities.listIterator();
BaseActivity activity;
while (iterator.hasNext()) {
activity = iterator.next();
if (activity != null) {
activity.finish();
}
}
}
/**
* 退出应运程序
*/
public static void quiteApplication() {
clearActivities();
System.exit(0);
}
}
package com.senthink.ebike_administrer_tool.api;
import com.senthink.ebike_administrer_tool.MyApplication;
import com.senthink.ebike_administrer_tool.utils.NetWorkUtil;
import java.io.File;
import java.io.IOException;
import okhttp3.Cache;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
/**
* @Description :
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/6
*/
public class ApiManager {
public static ApiManager apiManage = null;
private static final Interceptor REWRITE_CACHE_CONTROL_INTERCEPTOR = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Response originalResponse = chain.proceed(chain.request());
if (NetWorkUtil.isNetWorkAvailable(MyApplication.getApplication())) {
int maxAge = 60; // 在线缓存在1分钟内可读取
return originalResponse.newBuilder()
.removeHeader("Pragma") // 删除原有头部的字段
.removeHeader("Cache-Control") // 删除原有头部的字段
.header("Cache-Control", "public, max-age=" + maxAge) // 替换为这些字段,以达到重写头部,存入缓存的功能
.build();
} else {
int maxStale = 60 * 60 * 24 * 28; // 离线时缓存保存4周
return originalResponse.newBuilder()
.removeHeader("Pragma")
.removeHeader("Cache-Control")
.header("Cache-Control", "public, only-if-cached, max-stale=" + maxStale)
.build();
}
}
};
public LoginApi loginApi;
public UserApi userApi;
private Object monitor = new Object();
// private static File httpCacheDirectory = new File(MyApplication.getContext().getCacheDir(), "zhihuCache");
// private static int cacheSize = 10 * 1024 * 1024; // 10 MiB
// private static Cache cache = new Cache(httpCacheDirectory, cacheSize);
// 预请求的header信息
private static final class OptionsInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request.Builder builder = chain.request().newBuilder();
Request requst = builder.addHeader("Content-type", "application/json")
.addHeader("Accept", "application/json").build();
return chain.proceed(requst);
}
}
private static OkHttpClient client = new OkHttpClient.Builder() // client 中添加了以下属性
// .addNetworkInterceptor(REWRITE_CACHE_CONTROL_INTERCEPTOR)
// .addInterceptor(new LoginInterceptor())
.build();
public static ApiManager getInstance() {
if (apiManage == null) {
synchronized (ApiManager.class) {
if (apiManage == null) {
apiManage = new ApiManager();
}
}
}
return apiManage;
}
public LoginApi postUserInfo() {
if (loginApi == null) {
synchronized (monitor) {
if (loginApi == null) {
loginApi = new Retrofit.Builder()
.baseUrl("http://10.200.2.109:9051/")
// .baseUrl("http://10.200.0.51:9051/auth")
// .client(client)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build().create(LoginApi.class);
}
}
}
return loginApi;
}
/**
* @Description 获取Id
* */
public UserApi getUserId() {
if (userApi == null) {
synchronized (monitor) {
if (userApi == null) {
userApi = new Retrofit.Builder()
.baseUrl("http://10.200.2.109:9011/")
.client(client)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build().create(UserApi.class);
}
}
}
return userApi;
}
}
package com.senthink.ebike_administrer_tool.api;
import com.squareup.okhttp.RequestBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.OPTIONS;
import retrofit2.http.POST;
import rx.Observable;
/**
* @Description :
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/3
*/
public interface LoginApi {
@POST("auth")
Observable<RequestBody> userLogin(@Body RequestBody bean);// <LoginUser>为请求结果后的实体类,即账号密码;route为进行post请求的实体类
}
package com.senthink.ebike_administrer_tool.api;
import com.senthink.ebike_administrer_tool.bean.GetUserByName;
import com.senthink.ebike_administrer_tool.bean.GetUserInfoById;
import retrofit2.http.GET;
import retrofit2.http.Path;
import rx.Observable;
/**
* @Description : 获取个人信息的api
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/7
*/
public interface UserApi {
// 通过userName获得userId
@GET("challenger/user/me/{loginName}")
Observable<GetUserByName> getUserId(@Path("loginName") String userName);
@GET("app/user/me/{userId}")
Observable<GetUserInfoById> getUserInfo(@Path("userId") int userId);
}
package com.senthink.ebike_administrer_tool.asynchttp;
import android.content.Context;
import android.util.Log;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import org.apache.http.HttpEntity;
/**
* 异步Http通信客户端类
*
* @author wangxy 创建时间:2015-6-30
*
*/
public class AsyncClient {
private AsyncHttpClient MCLIENT = new AsyncHttpClient();
public AsyncClient(){
MCLIENT.setTimeout(20 * 1000);
MCLIENT.setConnectTimeout(20 * 1000);
MCLIENT.setResponseTimeout(20 * 1000);
}
public void get(String url, RequestParams params,
AsyncHttpResponseHandler responseHandler) {
// MCLIENT.removeAllHeaders();
MCLIENT.addHeader("Accept", "application/json");
//MCLIENT.addHeader("charset", "utf-8");
MCLIENT.get(url, params, responseHandler);
}
public void post(String url, RequestParams params,
AsyncHttpResponseHandler responseHandler) {
// MCLIENT.removeAllHeaders();
MCLIENT.addHeader("Accept", "application/json");
MCLIENT.post(url, params, responseHandler);
}
public void post(Context context, String url, HttpEntity entity,
String contentType, AsyncHttpResponseHandler responseHandler) {
SetHttpHeader();
MCLIENT.post(context, url, entity, contentType, responseHandler);
}
public void put(String url, RequestParams params,
AsyncHttpResponseHandler responseHandler) {
MCLIENT.removeAllHeaders();
MCLIENT.put(url, params, responseHandler);
}
public void put(Context context, String url, HttpEntity entity,
String contentType, AsyncHttpResponseHandler responseHandler) {
SetHttpHeader();
MCLIENT.put(context, url, entity, contentType, responseHandler);
}
public void SetHttpHeader() {
MCLIENT.addHeader("Content-Type", "application/json");
MCLIENT.addHeader("Accept", "application/json");
}
public void RemoveHttpHeader() {
MCLIENT.removeAllHeaders();
}
public void CancelAllRequest() {
MCLIENT.cancelAllRequests(true);
Log.i("appLog", "取消网络操作");
}
public void CancelRequest(Context context) {
MCLIENT.cancelRequests(context, true);
Log.i("appLog", "取消网络操作");
}
}
package com.senthink.ebike_administrer_tool.asynchttp;
import org.json.JSONObject;
/**
* 异步Http通信回调接口
* @author wangxy
* 创建时间:2015-6-30
*
*/
public interface HttpCallback {
public void HttpCallbackResult(int code, JSONObject response);
public void HttpCallbackResult(int code, String response);
}
package com.senthink.ebike_administrer_tool.bean;
import com.google.gson.annotations.SerializedName;
/**
* @Description :
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/7
*/
public class GetUserByName {
@SerializedName("data")
private UserByName userByName;
public void setUserByName(UserByName userByName) {
this.userByName = userByName;
}
public UserByName getUserByName() {
return userByName;
}
}
package com.senthink.ebike_administrer_tool.bean;
/**
* @Description : 个人信息bean
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/7
*/
public class GetUserInfoById {
/**
* id : 6
* loginName : xjl
* password : $2a$10$1y4WJRKepAStrwlZQxyxa.nrqL/KvFtYnHLk8i8N0qX8gIpThprLS
* realName : null
* telephone : null
* email : null
* address : null
* regTime : 1494481961000
* endTime : null
* orgCode : 10
* comName : kksks;
* productId : ADMIN
* userTypeId : 2
* userType : null
* chooseZoom : null
* state : 0
* stateName : null
* parentId : 0
* parentName : null
* direct : null
* businessType : null
* rejectReason : null
* rejectTime : null
* totalDealer : null
* userTypeName : null
* roles : null
* orgId : null
* companyName : null
* storeName : null
* accountDvc : null
* storeAddress : null
* storeUserName : null
* storeTel : null
* openid : null
* idCard : null
* depositState : null
* remark :
*/
private int id;
private String loginName;
private String password;
private String realName;
private String telephone;
private Object email;
private Object address;
private long regTime;
private Object endTime;
private String orgCode;
private String comName;
private String productId;
private int userTypeId;
private Object userType;
private Object chooseZoom;
private int state;
private Object stateName;
private int parentId;
private Object parentName;
private Object direct;
private Object businessType;
private Object rejectReason;
private Object rejectTime;
private Object totalDealer;
private Object userTypeName;
private Object roles;
private Object orgId;
private Object companyName;
private Object storeName;
private Object accountDvc;
private Object storeAddress;
private Object storeUserName;
private Object storeTel;
private Object openid;
private Object idCard;
private Object depositState;
private String remark;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getLoginName() {
return loginName;
}
public void setLoginName(String loginName) {
this.loginName = loginName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getRealName() {
return realName;
}
public void setRealName(String realName) {
this.realName = realName;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public Object getEmail() {
return email;
}
public void setEmail(Object email) {
this.email = email;
}
public Object getAddress() {
return address;
}
public void setAddress(Object address) {
this.address = address;
}
public long getRegTime() {
return regTime;
}
public void setRegTime(long regTime) {
this.regTime = regTime;
}
public Object getEndTime() {
return endTime;
}
public void setEndTime(Object endTime) {
this.endTime = endTime;
}
public String getOrgCode() {
return orgCode;
}
public void setOrgCode(String orgCode) {
this.orgCode = orgCode;
}
public String getComName() {
return comName;
}
public void setComName(String comName) {
this.comName = comName;
}
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public int getUserTypeId() {
return userTypeId;
}
public void setUserTypeId(int userTypeId) {
this.userTypeId = userTypeId;
}
public Object getUserType() {
return userType;
}
public void setUserType(Object userType) {
this.userType = userType;
}
public Object getChooseZoom() {
return chooseZoom;
}
public void setChooseZoom(Object chooseZoom) {
this.chooseZoom = chooseZoom;
}
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
}
public Object getStateName() {
return stateName;
}
public void setStateName(Object stateName) {
this.stateName = stateName;
}
public int getParentId() {
return parentId;
}
public void setParentId(int parentId) {
this.parentId = parentId;
}
public Object getParentName() {
return parentName;
}
public void setParentName(Object parentName) {
this.parentName = parentName;
}
public Object getDirect() {
return direct;
}
public void setDirect(Object direct) {
this.direct = direct;
}
public Object getBusinessType() {
return businessType;
}
public void setBusinessType(Object businessType) {
this.businessType = businessType;
}
public Object getRejectReason() {
return rejectReason;
}
public void setRejectReason(Object rejectReason) {
this.rejectReason = rejectReason;
}
public Object getRejectTime() {
return rejectTime;
}
public void setRejectTime(Object rejectTime) {
this.rejectTime = rejectTime;
}
public Object getTotalDealer() {
return totalDealer;
}
public void setTotalDealer(Object totalDealer) {
this.totalDealer = totalDealer;
}
public Object getUserTypeName() {
return userTypeName;
}
public void setUserTypeName(Object userTypeName) {
this.userTypeName = userTypeName;
}
public Object getRoles() {
return roles;
}
public void setRoles(Object roles) {
this.roles = roles;
}
public Object getOrgId() {
return orgId;
}
public void setOrgId(Object orgId) {
this.orgId = orgId;
}
public Object getCompanyName() {
return companyName;
}
public void setCompanyName(Object companyName) {
this.companyName = companyName;
}
public Object getStoreName() {
return storeName;
}
public void setStoreName(Object storeName) {
this.storeName = storeName;
}
public Object getAccountDvc() {
return accountDvc;
}
public void setAccountDvc(Object accountDvc) {
this.accountDvc = accountDvc;
}
public Object getStoreAddress() {
return storeAddress;
}
public void setStoreAddress(Object storeAddress) {
this.storeAddress = storeAddress;
}
public Object getStoreUserName() {
return storeUserName;
}
public void setStoreUserName(Object storeUserName) {
this.storeUserName = storeUserName;
}
public Object getStoreTel() {
return storeTel;
}
public void setStoreTel(Object storeTel) {
this.storeTel = storeTel;
}
public Object getOpenid() {
return openid;
}
public void setOpenid(Object openid) {
this.openid = openid;
}
public Object getIdCard() {
return idCard;
}
public void setIdCard(Object idCard) {
this.idCard = idCard;
}
public Object getDepositState() {
return depositState;
}
public void setDepositState(Object depositState) {
this.depositState = depositState;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}
package com.senthink.ebike_administrer_tool.bean;
/**
* @Description : 将账号密码转化为json格式
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/6
*/
public class LoginBean {
/**
* password : 123456
* username : xjl
*/
private String password;
private String username;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
package com.senthink.ebike_administrer_tool.bean;
/**
* @Description :
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/3
*/
public class LoginBody {
String userName;
String passWord;
public void setUserName(String userName) {
this.userName = userName;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
public String getUserName() {
return userName;
}
public String getPassWord() {
return passWord;
}
}
package com.senthink.ebike_administrer_tool.bean;
/**
* @Description : 存储账号和密码的bean
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/2
*/
public class LoginUser {
private String code;
private String userName;
private String passWord;
public String getPassWord() {
return passWord;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
package com.senthink.ebike_administrer_tool.bean;
import com.google.gson.annotations.SerializedName;
/**
* @Description :
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/7
*/
public class UserByName {
@SerializedName("productId")
private String productId;
@SerializedName("userId")
private int userId;
@SerializedName("orgCode")
private String orgCode;
@SerializedName("loginName")
private String loginName;
public void setUserId(int userId) {
this.userId = userId;
}
public void setLoginName(String loginName) {
this.loginName = loginName;
}
public void setOrgCode(String orgCode) {
this.orgCode = orgCode;
}
public void setProductId(String productId) {
this.productId = productId;
}
public String getLoginName() {
return loginName;
}
public String getOrgCode() {
return orgCode;
}
public String getProductId() {
return productId;
}
public int getUserId() {
return userId;
}
}
package com.senthink.ebike_administrer_tool.common;
/**
* @Description :
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/3
*/
public class Common {
private static final String BASE_URL = "http://10.200.2.109:9051";
}
package com.senthink.ebike_administrer_tool.fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.senthink.ebike_administrer_tool.R;
/**
* @Description : 调度界面
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/7
*/
public class DispatchFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_dispatch,container,false);
}
}
package com.senthink.ebike_administrer_tool.fragment;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.senthink.ebike_administrer_tool.R;
/**
* @Description : 异常处理界面
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/7
*/
public class HandleIssueFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_handle_issue,container,false);
}
}
package com.senthink.ebike_administrer_tool.fragment;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.senthink.ebike_administrer_tool.MyApplication;
import com.senthink.ebike_administrer_tool.R;
import com.senthink.ebike_administrer_tool.bean.GetUserInfoById;
import com.senthink.ebike_administrer_tool.bean.LoginUser;
import com.senthink.ebike_administrer_tool.presenter.MyInforPresenter;
import com.senthink.ebike_administrer_tool.presenter.impl.MyInforPresenterImpl;
import com.senthink.ebike_administrer_tool.view.IMyInformationFragment;
import butterknife.BindColor;
import butterknife.BindView;
import butterknife.ButterKnife;
/**
* @Description : 个人信息界面
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/7
*/
public class MyInformationFragment extends Fragment implements IMyInformationFragment,View.OnClickListener{
MyInforPresenterImpl myInforPresenter;
@BindView(R.id.tv_real_name)
TextView mRealNameTv;
@BindView(R.id.tv_password)
TextView mPasswordTv;
@BindView(R.id.tv_telphone)
TextView mTelphoneTv;
@BindView(R.id.tv_username)
TextView mUserNmaeTv;
@BindView(R.id.iv_modify_password)
ImageView mModifyPswIv;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_me,container,false);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ButterKnife.bind(this,view);
initData();
}
/**
* @Description 初始化数据
* */
private void initData() {
myInforPresenter = new MyInforPresenterImpl(this);
myInforPresenter.getUserInfo("xjl");
}
/**
* @Description 获取信息失败
* @param msg 错误信息
* */
@Override
public void getInformationFailed(String msg) {
}
/**
* @Description 提交信息失败
* @param msg 失败原因
* */
@Override
public void postInformationFailed(String msg) {
}
/**
* 扫描设备
* */
@Override
public void scan() {
}
/**
* @Description 获取信息之后,显示在界面上
* @param user 用户信息bean,主要包括
* */
@Override
public void updateInfor(GetUserInfoById user) {
SharedPreferences sharedPreferences = getContext()
.getSharedPreferences("loginUser", Context.MODE_PRIVATE);
String loginName = sharedPreferences.getString("username","");
String password = sharedPreferences.getString("password","");
user.setLoginName(loginName);
user.setPassword(password);
if (user.getRealName().equals("null")) {
mRealNameTv.setText("null");
}else {
mRealNameTv.setText(user.getRealName());
}
if (user.getTelephone().equals("null")) {
mTelphoneTv.setText("null");
}else {
mRealNameTv.setText(user.getTelephone());
}
mPasswordTv.setText(password); // 设置密码
mUserNmaeTv.setText(loginName);
}
@Override
public void onClick(View v) {
int id = v.getId();
switch (id) {
case R.id.iv_modify_password:
modifyPassword();
break;
}
}
/**
* @Description 修改密码
* */
private void modifyPassword() {
myInforPresenter.modifyPassword();
}
}
package com.senthink.ebike_administrer_tool.fragment;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.senthink.ebike_administrer_tool.R;
/**
* @Description : 更换电池界面
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/7
*/
public class ReplaceBatteryFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_replace_battery,container,false);
}
}
package com.senthink.ebike_administrer_tool.fragment;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.senthink.ebike_administrer_tool.R;
/**
* @Description : 维护界面
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/7
*/
public class SafeGuardFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_safeguard,container,false);
}
}
package com.senthink.ebike_administrer_tool.model;
/**
* @Description :
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/2
*/
public interface BasePresenter {
void unsubscribe();
}
package com.senthink.ebike_administrer_tool.model;
import com.senthink.ebike_administrer_tool.model.callback.LoginCallback;
/**
* @Description :
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/2
*/
public interface LoginModel{
void login(String userName, String passWord, LoginCallback mCallback);
}
package com.senthink.ebike_administrer_tool.model;
import com.senthink.ebike_administrer_tool.model.callback.UserInfoCallback;
/**
* @Description :
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/7
*/
public interface UserInfoModel extends BasePresenter{
void getUserIdByUserName(String userName,UserInfoCallback callback);
void getUserInfoById(int id, UserInfoCallback callback);
}
package com.senthink.ebike_administrer_tool.model.callback;
import com.senthink.ebike_administrer_tool.bean.LoginUser;
/**
* @Description :
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/3
*/
public interface LoginCallback {
void loginSuccess(LoginUser loginUser);
void loginFailed(String msg);
}
package com.senthink.ebike_administrer_tool.model.callback;
import com.senthink.ebike_administrer_tool.bean.GetUserInfoById;
/**
* @Description : 个人信息的回调
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/8
*/
public interface UserInfoCallback {
/** 获取信息成功 */
void getInfoSuccess(GetUserInfoById user);
/** 获取信息失败 */
void getInfoFailed(String msg);
/** 修改密码成功 */
void modifySuccess();
/** 修改密码失败 */
void modifyFailed(String msg);
}
package com.senthink.ebike_administrer_tool.model.impl;
import com.senthink.ebike_administrer_tool.model.BasePresenter;
import rx.Subscription;
import rx.subscriptions.CompositeSubscription;
/**
* @Description : 解除事件的订阅
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/3
*/
public class BasePresenterImpl implements BasePresenter {
private CompositeSubscription mCompositeSubscription;
protected void addSubscription(Subscription s) {
if (this.mCompositeSubscription == null) {
this.mCompositeSubscription = new CompositeSubscription();
}
this.mCompositeSubscription.add(s);
}
@Override
public void unsubscribe() {
// TODO: 16/8/17 find when unsubcrible
if (this.mCompositeSubscription != null) {
this.mCompositeSubscription.unsubscribe();
}
}
}
package com.senthink.ebike_administrer_tool.model.impl;
import com.senthink.ebike_administrer_tool.MyApplication;
import com.senthink.ebike_administrer_tool.api.LoginApi;
import com.senthink.ebike_administrer_tool.asynchttp.AsyncHttp;
import com.senthink.ebike_administrer_tool.asynchttp.HttpCallback;
import com.senthink.ebike_administrer_tool.bean.LoginBean;
import com.senthink.ebike_administrer_tool.bean.LoginUser;
import com.senthink.ebike_administrer_tool.model.callback.LoginCallback;
import com.senthink.ebike_administrer_tool.model.LoginModel;
import org.json.JSONException;
import org.json.JSONObject;
/**
* @Description : 实现对用户名、密码的检验
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/2
*/
public class LoginModelImpl implements LoginModel {
private LoginApi loginApi;
private static final String TAG = LoginModel.class.getSimpleName();
// private RequestBody bean;
private LoginBean bean = new LoginBean();
private LoginUser loginUser = new LoginUser();
@Override
public void login(final String userName, final String passWord, final LoginCallback mCallback) {
// TODO: 2017/6/3 用户名、密码的具体验证逻辑
AsyncHttp http = new AsyncHttp(MyApplication.getContext());
JSONObject obj = new JSONObject();
String url = "http://10.200.2.109:9051/auth";
try {
obj.put("password", passWord);
obj.put("username", userName);
} catch (JSONException e) {
e.printStackTrace();
}
http.PostHttpClient(url, obj, new HttpCallback( ){
@Override
public void HttpCallbackResult(int code, JSONObject response) {
// TODO Auto-generated method stub
if(code==200) {
// saveInfo(userName,passWord,response.getString("token"));
loginUser.setUserName(userName);
loginUser.setPassWord(passWord);
// loginUser.setToken(response.getString("token"));
// saveInfo(loginUser);
mCallback.loginSuccess(loginUser);
}else {
mCallback.loginFailed("Invalid username or password");
}
}
@Override
public void HttpCallbackResult(int code, String response) {
// TODO Auto-generated method stub
}
});
}
// /**
// * @Description: 保存信息
// * @param loginUser
// * */
// private void saveInfo(LoginUser loginUser) {
// SharedPreferences preference = MyApplication.getApplication()
// .getSharedPreferences("loginUser", Context.MODE_PRIVATE);
// SharedPreferences.Editor editor=preference.edit();
// editor.putString("username",loginUser.getUserName());
// editor.putString("password",loginUser.getPassWord());
// editor.commit();
// }
}
package com.senthink.ebike_administrer_tool.model.impl;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import com.senthink.ebike_administrer_tool.MyApplication;
import com.senthink.ebike_administrer_tool.api.ApiManager;
import com.senthink.ebike_administrer_tool.api.UserApi;
import com.senthink.ebike_administrer_tool.asynchttp.AsyncClient;
import com.senthink.ebike_administrer_tool.asynchttp.AsyncHttp;
import com.senthink.ebike_administrer_tool.asynchttp.HttpCallback;
import com.senthink.ebike_administrer_tool.bean.GetUserByName;
import com.senthink.ebike_administrer_tool.bean.GetUserInfoById;
import com.senthink.ebike_administrer_tool.model.LoginModel;
import com.senthink.ebike_administrer_tool.model.UserInfoModel;
import com.senthink.ebike_administrer_tool.model.callback.UserInfoCallback;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import rx.Observer;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
/**
* @Description :
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/7
*/
public class UserInfoModelImpl extends BasePresenterImpl implements UserInfoModel {
UserApi userApi;
private static final String TAG = UserInfoModelImpl.class.getSimpleName();
@Override
public void getUserIdByUserName(String userName, final UserInfoCallback callback) {
userApi = ApiManager.getInstance().getUserId();
StringBuilder url = new StringBuilder().append("http://10.200.2.109:9011/challenger/user/get/");
url.append(userName);
AsyncHttp http = new AsyncHttp(MyApplication.getContext());
http.GetHttpClient(url.toString(), new HttpCallback() {
@Override
public void HttpCallbackResult(int code, JSONObject response) {
if (code == 200) {
try {
JSONObject obj = response.getJSONObject("data");
int id = obj.getInt("userId");
Log.i(TAG, "HttpCallbackResult: " + id);
getUserInfoById(id,callback);
} catch (JSONException e) {
e.printStackTrace();
}
}else {
Log.i(TAG, "请求失败,code =" + code);
}
}
@Override
public void HttpCallbackResult(int code, String response) {
}
});
}
@Override
public void getUserInfoById(int id, final UserInfoCallback callback) {
StringBuilder url = new StringBuilder().append("http://10.200.2.109:9011/challenger/app/user/me/");
url.append(id);
AsyncHttp http = new AsyncHttp(MyApplication.getContext());
http.GetHttpClient(url.toString(), new HttpCallback() {
@Override
public void HttpCallbackResult(int code, JSONObject response) {
if (code == 200) {
try {
JSONObject obj = response.getJSONObject("data");
String name = obj.getString("realName"); // 真实姓名
String userName = obj.getString("loginName");
String tel = obj.getString("telephone");
String psw = obj.getString("password");
Log.i(TAG, "HttpCallbackResult: " + name);
Log.i(TAG, "HttpCallbackResult: " + tel);
GetUserInfoById user = new GetUserInfoById();
user.setRealName(name);
user.setTelephone(tel);
callback.getInfoSuccess(user);
} catch (JSONException e) {
e.printStackTrace();
}
}else {
callback.getInfoFailed("信息请求失败");
}
}
@Override
public void HttpCallbackResult(int code, String response) {
}
});
}
}
package com.senthink.ebike_administrer_tool.presenter;
import com.senthink.ebike_administrer_tool.model.BasePresenter;
/**
* @Description :
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/2
*/
public interface LoginPresenter{
void login();
}
package com.senthink.ebike_administrer_tool.presenter;
import com.senthink.ebike_administrer_tool.model.BasePresenter;
/**
* @Description :
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/7
*/
public interface MyInforPresenter {
/** 获取用户信息 */
void getUserInfo(String name);
/** 修改密码 */
void modifyPassword(String psw);
}
package com.senthink.ebike_administrer_tool.presenter.impl;
import android.util.Log;
import com.senthink.ebike_administrer_tool.bean.LoginUser;
import com.senthink.ebike_administrer_tool.model.callback.LoginCallback;
import com.senthink.ebike_administrer_tool.model.impl.LoginModelImpl;
import com.senthink.ebike_administrer_tool.presenter.LoginPresenter;
import com.senthink.ebike_administrer_tool.view.LoginView;
/**
* @Description : LoginPresenter的实例化
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/3
*/
public class LoginPresenterImpl implements LoginPresenter {
private LoginModelImpl loginImpl;
private LoginView loginView;
private String TAG = LoginPresenterImpl.class.getSimpleName();
public LoginPresenterImpl(LoginView loginView) {
this.loginView = loginView;
this.loginImpl = new LoginModelImpl();
}
@Override
public void login() {
loginView.showLoading();
loginImpl.login(loginView.getUserName(), loginView.getPassWord(), new LoginCallback() {
@Override
public void loginSuccess(LoginUser loginUser) {
loginView.toLoginActivity(loginUser);
loginView.hideLoading();
loginView.toLoginActivity(loginUser);// 去View层处理存储数据的操作
}
@Override
public void loginFailed(String msg) {
loginView.showFailedError(msg);
loginView.hideLoading();
Log.i(TAG, "loginFailed: ");
}
});
}
}
package com.senthink.ebike_administrer_tool.presenter.impl;
import com.senthink.ebike_administrer_tool.bean.GetUserInfoById;
import com.senthink.ebike_administrer_tool.model.callback.UserInfoCallback;
import com.senthink.ebike_administrer_tool.model.impl.BasePresenterImpl;
import com.senthink.ebike_administrer_tool.model.impl.UserInfoModelImpl;
import com.senthink.ebike_administrer_tool.presenter.MyInforPresenter;
import com.senthink.ebike_administrer_tool.view.IMyInformationFragment;
/**
* @Description : MyInforPresenter的实例化
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/7
*/
public class MyInforPresenterImpl implements MyInforPresenter {
private UserInfoModelImpl userInfoModel;
private IMyInformationFragment fragment;
public MyInforPresenterImpl(IMyInformationFragment myInformationFragment) {
this.fragment = myInformationFragment;
userInfoModel = new UserInfoModelImpl();
}
@Override
public void getUserInfo(String name) {
userInfoModel.getUserIdByUserName(name, new UserInfoCallback() {
@Override
public void getInfoSuccess(GetUserInfoById user) {
fragment.updateInfor(user);
}
@Override
public void getInfoFailed(String msg) {
}
@Override
public void modifySuccess() {
}
@Override
public void modifyFailed(String msg) {
}
});
}
/**
* @Description 修改密码
* @param psw 密码
* */
@Override
public void modifyPassword(String psw) {
}
}
package com.senthink.ebike_administrer_tool.utils;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
import java.lang.reflect.Type;
/**
* Description : Json转换工具类
* Author : lauren
* Email : lauren.liuling@gmail.com
* Blog : http://www.liuling123.com
* Date : 15/12/17
*/
public class JsonUtils {
private static Gson mGson = new Gson();
/**
* 将对象准换为json字符串
* @param object
* @param <T>
* @return
*/
public static <T> String serialize(T object) {
return mGson.toJson(object);
}
/**
* 将json字符串转换为对象
* @param json
* @param clz
* @param <T>
* @return
*/
public static <T> T deserialize(String json, Class<T> clz) throws JsonSyntaxException {
return mGson.fromJson(json, clz);
}
/**
* 将json对象转换为实体对象
* @param json
* @param clz
* @param <T>
* @return
* @throws JsonSyntaxException
*/
public static <T> T deserialize(JsonObject json, Class<T> clz) throws JsonSyntaxException {
return mGson.fromJson(json, clz);
}
/**
* 将json字符串转换为对象
* @param json
* @param type
* @param <T>
* @return
*/
public static <T> T deserialize(String json, Type type) throws JsonSyntaxException {
return mGson.fromJson(json, type);
}
}
package com.senthink.ebike_administrer_tool.utils;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
public class NetWorkUtil {
private NetWorkUtil() {}
/**
* 判断网络是否可用
*
* @param context
* @return
*/
public static boolean isNetWorkAvailable(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
return networkInfo != null && networkInfo.isConnected();
}
/**
* 检测wifi是否连接
*
* @return
*/
public static boolean isWifiConnected(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
return networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
}
/**
* 检测3G是否连接
*
* @return
*/
public static boolean is3gConnected(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
return networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_MOBILE;
}
}
package com.senthink.ebike_administrer_tool.utils;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import com.senthink.ebike_administrer_tool.BaseActivity;
import com.senthink.ebike_administrer_tool.MyApplication;
import com.senthink.ebike_administrer_tool.R;
/**
* Author :hymanme
* Email :hymanme@163.com
* Created at 2015/7/27
*/
public class UIUtils {
public static Context getContext() {
return MyApplication.getApplication();
}
/**
* 页面跳转
*
* @param intent
*/
public static void startActivity(Intent intent) {
// 如果不在activity里去打开activity 需要指定任务栈 需要设置标签
if (BaseActivity.activity == null) {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getContext().startActivity(intent);
} else {
BaseActivity.activity.startActivity(intent);
}
}
// /**
// * 分享
// *
// * @param context
// * @param content 分享内容
// * @param uri 分享图片uri
// */
// public static void share(Context context, String content, Uri uri) {
// Intent shareIntent = new Intent();
// shareIntent.setAction(Intent.ACTION_SEND);
// if (uri != null) {
// shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
// shareIntent.setType("image/*");
// //当用户选择短信时使用sms_body取得文字
// shareIntent.putExtra("sms_body", content);
// } else {
// shareIntent.setType("text/plain");
// }
// shareIntent.putExtra(Intent.EXTRA_TEXT, content);
// context.startActivity(Intent.createChooser(shareIntent, context.getString(R.string.share_dialog_title)));
// }
}
package com.senthink.ebike_administrer_tool.view;
/**
* @Description : fragment的一些公共接口
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/7
*/
public interface IBaseFragment {
// 获取信息失败
void getInformationFailed(String msg);
// post信息失败
void postInformationFailed(String msg);
// 扫一扫
void scan();
}
package com.senthink.ebike_administrer_tool.view;
import com.senthink.ebike_administrer_tool.bean.GetUserInfoById;
import com.senthink.ebike_administrer_tool.bean.LoginUser;
/**
* @Description : 更新信息
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/7
*/
public interface IMyInformationFragment extends IBaseFragment{
void updateInfor(GetUserInfoById user);
}
package com.senthink.ebike_administrer_tool.view;
import com.senthink.ebike_administrer_tool.bean.LoginUser;
/**
* @Description :
* @Author : ni
* @Email : lifengni2015@gmail.com
* @Date : 2017/6/2
*/
public interface LoginView {
String getUserName();
String getPassWord();
void showLoading();
void hideLoading();
void toLoginActivity(LoginUser loginUser);
void showFailedError(String msg);
}
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
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