1. 程式人生 > >android 框架Dileber :專案實踐

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軟體