Search in sources :

Example 1 with MovieAmount

use of com.shizhefei.test.models.enties.MovieAmount 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 MovieAmount

use of com.shizhefei.test.models.enties.MovieAmount in project MVCHelper by LuckyJayce.

the class MovieAmountTask2 method execute.

@Override
public RequestHandle execute(final ResponseSender<MovieAmount> sender) throws Exception {
    final AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackground(Void... params) {
            try {
                Thread.sleep(2000);
                Random random = new Random();
                int commentCount = random.nextInt(100);
                int playCount = random.nextInt(1000) + 10;
                long updateTime = System.currentTimeMillis();
                sender.sendData(new MovieAmount(name, commentCount, playCount, name + " " + DateFormat.format("dd kk:mm:ss", updateTime)));
            } catch (Exception e) {
                e.printStackTrace();
                sender.sendError(e);
            }
            return null;
        }
    };
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else {
        asyncTask.execute();
    }
    return new RequestHandle() {

        @Override
        public void cancle() {
            asyncTask.cancel(true);
        }

        @Override
        public boolean isRunning() {
            return false;
        }
    };
}
Also used : Random(java.util.Random) MovieAmount(com.shizhefei.test.models.enties.MovieAmount) RequestHandle(com.shizhefei.mvc.RequestHandle) AsyncTask(android.os.AsyncTask) IAsyncTask(com.shizhefei.task.IAsyncTask)

Example 3 with MovieAmount

use of com.shizhefei.test.models.enties.MovieAmount in project MVCHelper by LuckyJayce.

the class MovieAmountTask method execute.

@Override
public MovieAmount execute(ProgressSender progressSender) throws Exception {
    Thread.sleep(2000);
    Random random = new Random();
    int commentCount = random.nextInt(100);
    int playCount = random.nextInt(1000) + 10;
    long updateTime = System.currentTimeMillis();
    return new MovieAmount(name, commentCount, playCount, name + " " + DateFormat.format("dd kk:mm:ss", updateTime));
}
Also used : Random(java.util.Random) MovieAmount(com.shizhefei.test.models.enties.MovieAmount)

Aggregations

MovieAmount (com.shizhefei.test.models.enties.MovieAmount)3 Random (java.util.Random)2 AsyncTask (android.os.AsyncTask)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 RequestHandle (com.shizhefei.mvc.RequestHandle)1 Code (com.shizhefei.task.Code)1 IAsyncTask (com.shizhefei.task.IAsyncTask)1 MemoryCacheStore (com.shizhefei.task.imp.MemoryCacheStore)1 MoviesDataSource (com.shizhefei.test.models.datasource.MoviesDataSource)1 MoviesAdapter (com.shizhefei.test.view.adapters.MoviesAdapter)1 PtrClassicFrameLayout (in.srain.cube.views.ptr.PtrClassicFrameLayout)1