Search in sources :

Example 1 with Code

use of com.shizhefei.task.Code in project MVCHelper by LuckyJayce.

the class ListTaskActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ultrarecyclerview);
    PtrClassicFrameLayout mPtrFrameLayout = (PtrClassicFrameLayout) findViewById(R.id.rotate_header_list_view_frame);
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    taskHelper = new TaskHelper<>(new MemoryCacheStore(200));
    // 注册全局的task执行回调
    taskHelper.registerCallBack(new ICallback<MovieAmount>() {

        @Override
        public void onPreExecute(Object task) {
            Log.d("pppp", "task:" + task);
        }

        @Override
        public void onProgress(Object task, int percent, long current, long total, Object extraData) {
        }

        @Override
        public void onPostExecute(Object task, Code code, Exception exception, MovieAmount movieAmount) {
            Log.d("pppp", "task:" + task + " code:" + code);
        }
    });
    mvcHelper = new MVCUltraHelper<>(mPtrFrameLayout);
    // 设置数据源
    mvcHelper.setDataSource(new MoviesDataSource());
    // 设置适配器
    mvcHelper.setAdapter(new MoviesAdapter(taskHelper));
    // 加载数据
    mvcHelper.refresh();
}
Also used : MemoryCacheStore(com.shizhefei.task.imp.MemoryCacheStore) MoviesAdapter(com.shizhefei.test.view.adapters.MoviesAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Code(com.shizhefei.task.Code) MoviesDataSource(com.shizhefei.test.models.datasource.MoviesDataSource) PtrClassicFrameLayout(in.srain.cube.views.ptr.PtrClassicFrameLayout) MovieAmount(com.shizhefei.test.models.enties.MovieAmount) RecyclerView(android.support.v7.widget.RecyclerView)

Example 2 with Code

use of com.shizhefei.task.Code in project MVCHelper by LuckyJayce.

the class TaskDemoActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_task_demo);
    asyncDataSourceButton = findViewById(R.id.taskdemo_iasyncdatasoruce_button);
    taskButton = findViewById(R.id.taskdemo_itask_button);
    asyncTaskButton = findViewById(R.id.taskdemo_iasynctask_button);
    dataSourceButton = findViewById(R.id.taskdemo_idatasoruce_button);
    longTimeTask = findViewById(R.id.taskdemo_longTimeTask_button);
    longTimeAsyncTask = findViewById(R.id.taskdemo_longTimeAsyncTask_button);
    resultTextView = (TextView) findViewById(R.id.taskdemo_result_textView);
    result2TextView = (TextView) findViewById(R.id.taskdemo_result2_textView);
    asyncDataSourceButton.setOnClickListener(onClickListener);
    taskButton.setOnClickListener(onClickListener);
    asyncTaskButton.setOnClickListener(onClickListener);
    dataSourceButton.setOnClickListener(onClickListener);
    longTimeTask.setOnClickListener(onClickListener);
    longTimeAsyncTask.setOnClickListener(onClickListener);
    taskHelper = new TaskHelper<>();
    taskHelper.registerCallBack(new SimpleCallback<Object>() {

        @Override
        public void onPreExecute(Object task) {
            super.onPreExecute(task);
            result2TextView.setText("开始执行:" + task.getClass().getSimpleName());
        }

        @Override
        public void onProgress(Object task, int percent, long current, long total, Object extraData) {
            super.onProgress(task, percent, current, total, extraData);
            result2TextView.append("\n progress percent:" + percent + " current:" + current + " total:" + total + " extraData:" + extraData);
            Log.d("zzzz", "registerCallBack progress:" + current);
        }

        @Override
        public void onPostExecute(Object task, Code code, Exception exception, Object data) {
            result2TextView.append("\n");
            result2TextView.append("code:" + code);
            result2TextView.append("\n");
            if (code == Code.SUCCESS) {
                result2TextView.append(new Gson().toJson(data));
            } else if (code == Code.EXCEPTION) {
                result2TextView.append(exception.getMessage());
            }
        }
    });
}
Also used : Gson(com.google.gson.Gson) Code(com.shizhefei.task.Code)

Aggregations

Code (com.shizhefei.task.Code)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Gson (com.google.gson.Gson)1 MemoryCacheStore (com.shizhefei.task.imp.MemoryCacheStore)1 MoviesDataSource (com.shizhefei.test.models.datasource.MoviesDataSource)1 MovieAmount (com.shizhefei.test.models.enties.MovieAmount)1 MoviesAdapter (com.shizhefei.test.view.adapters.MoviesAdapter)1 PtrClassicFrameLayout (in.srain.cube.views.ptr.PtrClassicFrameLayout)1