Skip to content

Commit

Permalink
增加MainActivity mvp示例“
Browse files Browse the repository at this point in the history
  • Loading branch information
zjlong committed Apr 19, 2016
1 parent 5fda1ba commit cc5ab89
Show file tree
Hide file tree
Showing 19 changed files with 275 additions and 70 deletions.
9 changes: 5 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
android:name=".App"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:name=".App"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".view.activity.SplashActivity"
android:name=".ui.activity.SplashActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
Expand All @@ -22,8 +22,9 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".view.activity.LoginActivity"/>
<activity android:name="com.common.view.ui.WebViewActivity"/>
<activity android:name=".ui.activity.LoginActivity" />
<activity android:name=".ui.activity.MainActivity" />
<activity android:name="com.common.view.ui.WebViewActivity" />
</application>

</manifest>
5 changes: 4 additions & 1 deletion app/src/main/java/com/matto/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.common.EasyApplication;
import com.common.model.control.LogicProxy;
import com.matto.model.LoginLogic;
import com.matto.model.MainLogic;

/**
* author miekoz on 2016/3/17.
Expand All @@ -13,6 +14,8 @@ public class App extends EasyApplication {
@Override
public void onCreate() {
super.onCreate();
LogicProxy.getInstance().init(LoginLogic.class);
LogicProxy.getInstance().init(
LoginLogic.class, MainLogic.class
);
}
}
11 changes: 3 additions & 8 deletions app/src/main/java/com/matto/model/LoginLogic.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.matto.model;

import com.common.model.control.LogicControl;
import com.common.model.control.MvpLogic;
import com.common.model.annotation.Implement;
import com.matto.ui.view.LoginView;


/**
Expand All @@ -10,13 +11,7 @@
*/

@Implement(LoginLogicImpl.class)
public interface LoginLogic extends LogicControl<LoginLogic.LoginView> {

interface LoginView {
void onLoginSuccess();

void onLoginFail();
}
public interface LoginLogic extends MvpLogic<LoginView> {

void login(String name, String passwrod);
}
15 changes: 15 additions & 0 deletions app/src/main/java/com/matto/model/MainLogic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.matto.model;

import com.common.model.annotation.Implement;
import com.common.model.control.MvpLogic;
import com.matto.ui.view.MainView;

/**
* author meikoz on 2016/4/19.
* email [email protected]
*/
@Implement(MainLogicImpl.class)
public interface MainLogic extends MvpLogic<MainView> {

void switchNavigation(int id);
}
35 changes: 35 additions & 0 deletions app/src/main/java/com/matto/model/MainLogicImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.matto.model;

import com.matto.R;

/**
* author meikoz on 2016/4/19.
* email [email protected]
*/
public class MainLogicImpl implements MainLogic {

MainView mMainView;

@Override
public void switchNavigation(int id) {

switch (id) {
case R.id.navigation_selection:
mMainView.switchHome();
break;
case R.id.navigation_discovery:
mMainView.switchDiscovery();
break;
case R.id.navigation_about:
mMainView.switchShomeMe();
break;
default:
break;
}
}

@Override
public void attachView(MainView mvpView) {
this.mMainView = mvpView;
}
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
package com.matto.view.activity;
package com.matto.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.common.model.basic.ToastTip;
import com.common.view.ui.BaseActivity;
import com.common.view.widget.OnClickEvent;
import com.matto.R;
import com.common.model.control.LogicProxy;
import com.matto.model.LoginLogic;
import com.matto.ui.view.LoginView;

import butterknife.Bind;
import butterknife.OnClick;

/**
* author meikoz on 2016/4/13.
* email [email protected]
*/
public class LoginActivity extends BaseActivity implements LoginLogic.LoginView {
public class LoginActivity extends BaseActivity implements LoginView {

public static void start(Activity activity) {
Intent intent = new Intent(activity, LoginActivity.class);
activity.startActivity(intent);
activity.finish();
}
@Bind(R.id.edit_username) EditText mEditName;
@Bind(R.id.edit_passwrod) EditText mEditPasswrod;
@Bind(R.id.btn_login) Button mLogin;

@Bind(R.id.edit_username)
EditText mEditName;
@Bind(R.id.edit_passwrod)
EditText mEditPasswrod;

LoginLogic mLoginLogic;
public int i= 1;

@Override
protected int getLayoutResource() {
Expand All @@ -40,27 +41,21 @@ protected int getLayoutResource() {
@Override
protected void onInitView() {
mLoginLogic = LogicProxy.getInstance().getBindViewProxy(LoginLogic.class, this);
mLogin.setOnClickListener(new OnClickEvent() {
@Override
public void singleClick(View v) {
Log.d("cs",i++ +"");
// mLoginLogic.login("zhangsan", "123");
}
});
}

// @OnClick(R.id.btn_login)
// void login() {
// mLoginLogic.login("zhangsan", "123");
// }
@OnClick(R.id.btn_login)
void login() {
mLoginLogic.login("zhangsan", "123");
}

@Override
public void onLoginSuccess() {
Log.d("cs", "登录成功");
ToastTip.show("登录成功");
MainActivity.start(LoginActivity.this);
}

@Override
public void onLoginFail() {
Log.d("cs", "登录失败");
ToastTip.show("登录失败");
}
}
66 changes: 66 additions & 0 deletions app/src/main/java/com/matto/ui/activity/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.matto.ui.activity;


import android.app.Activity;
import android.content.Intent;
import android.view.View;

import com.common.model.control.LogicProxy;
import com.common.view.ui.BaseActivity;
import com.matto.R;
import com.matto.model.MainLogic;
import com.matto.ui.fragment.DiscoveryFragment;
import com.matto.ui.fragment.HomeFragment;
import com.matto.ui.fragment.ShowMeFragment;
import com.matto.ui.view.MainView;

import butterknife.OnClick;


public class MainActivity extends BaseActivity implements MainView {


public static void start(Activity context) {
Intent intent = new Intent(context, MainActivity.class);
context.startActivity(intent);
context.finish();
}

MainLogic mainLogic;

@Override
protected int getLayoutResource() {
return R.layout.activity_main;
}

@Override
protected void onInitView() {
if (mainLogic == null)
mainLogic = LogicProxy.getInstance().getBindViewProxy(MainLogic.class, this);
switchHome();
}

@Override
public void switchHome() {
getSupportFragmentManager().beginTransaction()
.replace(R.id.frame_layout, new HomeFragment()).commit();
}

@Override
public void switchDiscovery() {
getSupportFragmentManager().beginTransaction()
.replace(R.id.frame_layout, new DiscoveryFragment()).commit();
}

@Override
public void switchShomeMe() {
getSupportFragmentManager().beginTransaction()
.replace(R.id.frame_layout, new ShowMeFragment()).commit();
}


@OnClick({R.id.navigation_selection, R.id.navigation_discovery, R.id.navigation_about})
void onClick(View view) {
mainLogic.switchNavigation(view.getId());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.matto.view.activity;
package com.matto.ui.activity;

import android.content.Intent;
import android.view.animation.Animation;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.matto.view.adapter;
package com.matto.ui.adapter;

import android.content.Context;

Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/com/matto/ui/fragment/DiscoveryFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.matto.ui.fragment;

import com.common.view.ui.BaseFragment;
import com.matto.R;

/**
* author meikoz on 2016/4/19.
* email [email protected]
*/
public class DiscoveryFragment extends BaseFragment {
@Override
protected int getLayoutResource() {
return R.layout.activity_login;
}

@Override
protected void onInitData() {

}
}
20 changes: 20 additions & 0 deletions app/src/main/java/com/matto/ui/fragment/HomeFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.matto.ui.fragment;

import com.common.view.ui.BaseFragment;
import com.matto.R;

/**
* author meikoz on 2016/4/19.
* email [email protected]
*/
public class HomeFragment extends BaseFragment {
@Override
protected int getLayoutResource() {
return R.layout.activity_spalsh;
}

@Override
protected void onInitData() {

}
}
20 changes: 20 additions & 0 deletions app/src/main/java/com/matto/ui/fragment/ShowMeFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.matto.ui.fragment;

import com.common.view.ui.BaseFragment;
import com.matto.R;

/**
* author meikoz on 2016/4/19.
* email [email protected]
*/
public class ShowMeFragment extends BaseFragment {
@Override
protected int getLayoutResource() {
return R.layout.activity_hosting;
}

@Override
protected void onInitData() {

}
}
11 changes: 11 additions & 0 deletions app/src/main/java/com/matto/ui/view/LoginView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.matto.ui.view;

/**
* author meikoz on 2016/4/19.
* email [email protected]
*/
public interface LoginView {
void onLoginSuccess();

void onLoginFail();
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/matto/ui/view/MainView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.matto.ui.view;

/**
* author meikoz on 2016/4/19.
* email [email protected]
*/
public interface MainView {
void switchHome();

void switchDiscovery();

void switchShomeMe();
}
Loading

0 comments on commit cc5ab89

Please sign in to comment.