/* * Copyright 2012 Tallinn University Centre for Educational Technology * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package ee.htk.dippler.app; import java.util.ArrayList; import java.util.List; import android.app.ListActivity; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import ee.htk.dippler.app.ArrayAdapters.AssignmentArrayAdapter; import ee.htk.dippler.app.entities.Assignment; import ee.htk.dippler.app.entities.Course; import ee.htk.dippler.app.service.ListingManager; import ee.htk.dippler.app.service.SessionObject; public class TasksActivity extends ListActivity { private ListingManager listingManager; private List tasks = new ArrayList(); private AssignmentArrayAdapter mAdapter; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); Intent a = getIntent(); Bundle extras = a.getExtras(); Course course = extras.getParcelable("dippler-course"); SessionObject session = extras.getParcelable("dippler-session"); listingManager = new ListingManager(this, session.getId()); setContentView(R.layout.course_listing); mAdapter = new AssignmentArrayAdapter(getApplicationContext(), R.layout.list_news, tasks); setListAdapter(mAdapter); getListView().setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View view, int position, long id) { Intent post_intent = new Intent(getApplicationContext(), TaskDetailsActivity.class); post_intent.putExtra("dippler-task", tasks.get(position)); startActivity(post_intent); } }); new fetchAssignments().execute(course.getId()); } private class fetchAssignments extends AsyncTask> { @Override protected List doInBackground(Integer... params) { return listingManager.getAssignments(params[0]); } @Override protected void onPostExecute(List tasks_in) { super.onPostExecute(tasks_in); tasks.addAll(tasks_in); mAdapter.notifyDataSetChanged(); findViewById(R.id.progress_wrapper).setVisibility(View.GONE); } } }