/* * 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.content.SharedPreferences; import android.os.AsyncTask; import android.os.Bundle; import android.preference.PreferenceManager; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import ee.htk.dippler.app.ArrayAdapters.CommentArrayAdapter; import ee.htk.dippler.app.entities.Comment; import ee.htk.dippler.app.service.ListingManager; public class CommentActivity extends ListActivity { private ListingManager listingManager; private List comments = new ArrayList(); private CommentArrayAdapter mAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); setContentView(R.layout.course_listing); listingManager = new ListingManager(); mAdapter = new CommentArrayAdapter(getApplicationContext(), R.layout.list_news, comments); setListAdapter(mAdapter); getListView().setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View view, int position, long id) { Intent post_intent = new Intent(getApplicationContext(), CommentDetailsActivity.class); post_intent.putExtra("dippler-task", comments.get(position)); startActivity(post_intent); } }); new fetchComments().execute(prefs.getString("dippler-blog", "")); } private class fetchComments extends AsyncTask> { @Override protected List doInBackground(String... params) { return listingManager.getComments(params[0]); } @Override protected void onPostExecute(List comments_in) { super.onPostExecute(comments_in); comments.addAll(comments_in); mAdapter.notifyDataSetChanged(); findViewById(R.id.progress_wrapper).setVisibility(View.GONE); } } }