手记

android 框架Dileber :项目实践

dileber android 框架:乁( ˙Ω˙ )厂 跳转链接 dileber android框架
怎么说呢?既然看到了就在github上star一下呗 (´ཀ`」 ∠)

最近我将一个用dileber 项目开发的示例软件提交到github上:
myshop软件
采用mvp模式开发项目
该项目使用了框架中的

  • 网络请求
  • cookies 使用
  • 自动判断cookies失效
  • 日志打印系统
  • 字体图标系统

SHOPApplication
开启日志打印系统,开启默认字体图标

public class SHOPApplication extends SApplication{

    @Override
    public void start() {
        loadDeaultFont = true;
        crash = true;
    }

    @Override
    protected void init() {

    }

    @Override
    public void appForbidden(final Call call, Response response, final RetCallback retCallback) {
        TCookie.clearCookie();
        UDialog.dialogOk("登录过时,重新登录?", new DialogLinstener() {
            @Override
            public void confirm(Dialog dialog) {
                String login_name = (SHOPPrefer.get(SHOPPrefer.USERNAME,"",String.class));
                String login_pass = (SHOPPrefer.get(SHOPPrefer.USERPASS,"",String.class));
                UserRepository.getInstance().login(login_name, MD5.getStringMD5(login_pass), new BaseDataSource.BaseCallback<UserWrapper>() {
                    @Override
                    public void onSuccess(UserWrapper userWrapper) {
                        if(userWrapper.getState()== 0){
                            call.clone().enqueue(retCallback);
                        }else if(userWrapper.getState()==-1){
                            UUi.toast(ActivityManager.getCurrentActivity(),userWrapper.getMsg(), Toast.LENGTH_SHORT);
                            LoginActivity.start(ActivityManager.getCurrentActivity());
                            ActivityManager.getInstance(BaseShopActivity.activityStack).finishAllActivity();
                        }
                    }

                    @Override
                    public void onFailure(DataSourceException e) {
                        UUi.toast(ActivityManager.getCurrentActivity(),e.getMessage(), Toast.LENGTH_SHORT);
                        LoginActivity.start(ActivityManager.getCurrentActivity());
                        ActivityManager.getInstance(BaseShopActivity.activityStack).finishAllActivity();
                    }
                });
                dialog.dismiss();
            }

            @Override
            public void cancel(Dialog dialog) {
                LoginActivity.start(ActivityManager.getCurrentActivity());
                ActivityManager.getInstance(BaseShopActivity.activityStack).finishAllActivity();
                dialog.dismiss();
            }
        }).show();

    }
}

SHOPConfig
配置debug开启,配置url

public class SHOPConfig extends BaseConfiger{

    static {
        BUG_NAME = "SHOPApplication";
        BUG_STATIC = true;
    }

    public final static String URL = "http://shop.dreamsoso.com/";

}

SHOPPrefer
配置存储,shareprefer

public class SHOPPrefer {

    public final static String SAREPREFER_SHOP = "sareprefer_shop";

    public final static String USERNAME = "username";
    public final static String USERPASS = "userpass";

    public static void push(String key,Object value){
        HPref.getInstance().put(SAREPREFER_SHOP,key,value);
    }

    public static <T>T get(String key, T defaultValue,Class<T> returnType){
        return HPref.getInstance().get(SAREPREFER_SHOP,key,defaultValue,returnType);
    }
}

如何控制某几个activity一起finish
在BaseShopActivity 中将特定的acitivity加入到某个栈中

public abstract class BaseShopActivity extends UBaseActivity {

    public final static String activityStack = "shop";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(!(this instanceof LoginActivity)){
            ActivityManager.getInstance(activityStack).pushActivity(this);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(!(this instanceof LoginActivity)){
            ActivityManager.getInstance(activityStack).popActivity(this);
        }
    }
}

详细的代码就在
github上:
myshop软件

1人推荐
随时随地看视频
慕课网APP