TopicActivity.java (5125B)
1 /** 2 * 3 */ 4 package de.mtbnews.android; 5 6 import java.util.List; 7 8 import android.app.AlertDialog; 9 import android.content.DialogInterface; 10 import android.content.Intent; 11 import android.os.Bundle; 12 import android.view.Menu; 13 import android.view.MenuInflater; 14 import android.view.MenuItem; 15 import android.widget.ListAdapter; 16 import android.widget.Toast; 17 import de.mtbnews.android.adapter.ListEntryContentAdapter; 18 import de.mtbnews.android.tapatalk.TapatalkClient; 19 import de.mtbnews.android.tapatalk.TapatalkException; 20 import de.mtbnews.android.tapatalk.wrapper.Post; 21 import de.mtbnews.android.tapatalk.wrapper.Topic; 22 import de.mtbnews.android.util.ServerAsyncTask; 23 24 /** 25 * Anzeige aller Beiträge eines Themas. 26 * 27 * @author dankert 28 * 29 */ 30 public class TopicActivity extends EndlessListActivity<Post> 31 { 32 public static final String TOPIC_ID = "topic_id"; 33 34 private String forumId; 35 private String topicId; 36 private String topicTitle; 37 38 private int totalSize; 39 private TapatalkClient client; 40 41 @Override 42 protected void onCreate(Bundle savedInstanceState) 43 { 44 super.onCreate(savedInstanceState); 45 46 setTheme(((IBCApplication) getApplication()).themeResId); 47 setContentView(R.layout.listing); 48 49 client = ((IBCApplication) getApplication()).getTapatalkClient(); 50 51 topicId = TopicActivity.this.getIntent().getStringExtra(TOPIC_ID); 52 // forumId = TopicActivity.this.getIntent().getStringExtra("forum_id"); 53 54 ListAdapter adapter = new ListEntryContentAdapter(TopicActivity.this, entries, true, false); 55 setListAdapter(adapter); 56 57 initialLoad(); 58 59 /* 60 * final ListView list = getListView(); list.setOnItemClickListener(new 61 * OnItemClickListener() { 62 * 63 * @Override public void onItemClick(AdapterView<?> parent, View view, 64 * int position, long id) { int aktPosition = displayFrom + position + 65 * 1; Toast.makeText(TopicActivity.this, "" + aktPosition, 66 * Toast.LENGTH_SHORT).show(); 67 * 68 * // final Intent intent = new Intent(TopicActivity.this, // 69 * PostActivity.class); // intent.putExtra("itemid", position); // 70 * startActivity(intent); } }); 71 */ 72 } 73 74 @Override 75 protected int getTotalSize() 76 { 77 return this.totalSize; 78 } 79 80 @Override 81 protected void loadEntries(final OnListLoadedListener<Post> onListLoadedListener, final int from, final int to, 82 boolean firstLoad) 83 { 84 new ServerAsyncTask(TopicActivity.this, firstLoad ? R.string.waitingfor_topic : R.string.waitingfor_loadmore) 85 { 86 private List<Post> posts; 87 private Topic topic; 88 89 @Override 90 protected void callServer() throws TapatalkException 91 { 92 93 topic = client.getTopic(topicId, from, to); 94 95 forumId = topic.forumId; 96 topicTitle = topic.getTitle(); 97 totalSize = topic.getPostCount(); 98 this.posts = topic.getPosts(); 99 } 100 101 protected void doOnSuccess() 102 { 103 TopicActivity.this.setTitle(topic.getTitle()); 104 onListLoadedListener.listLoaded(this.posts); 105 } 106 107 }.execute(); 108 } 109 110 @Override 111 public boolean onCreateOptionsMenu(Menu menu) 112 { 113 super.onCreateOptionsMenu(menu); 114 MenuInflater mi = new MenuInflater(getApplication()); 115 116 mi.inflate(R.menu.topic, menu); 117 118 return true; 119 } 120 121 public boolean onOptionsItemSelected(MenuItem item) 122 { 123 switch (item.getItemId()) 124 { 125 case R.id.menu_preferences: 126 startActivity(new Intent(this, Configuration.class)); 127 return true; 128 129 case R.id.menu_top: 130 131 getListView().setOnScrollListener(null); 132 getListView().setSelection(0); 133 getIntent().putExtra(FIRST_POST, true); 134 initialLoad(); 135 return true; 136 137 case R.id.menu_bottom: 138 139 getListView().setOnScrollListener(null); 140 getListView().setSelection(super.entries.size() - 1); 141 getIntent().putExtra(LAST_POST, true); 142 initialLoad(); 143 return true; 144 145 case R.id.menu_reply: 146 Intent intent = new Intent(this, ReplyPostActivity.class); 147 intent.putExtra("topic_id", topicId); 148 intent.putExtra("forum_id", forumId); 149 intent.putExtra("subject", topicTitle); 150 startActivity(intent); 151 return true; 152 153 case R.id.menu_subscribe: 154 155 AlertDialog.Builder builder = new AlertDialog.Builder(this); 156 builder.setTitle(R.string.subscribe_topic); 157 builder.setItems(R.array.subscription_modes, new DialogInterface.OnClickListener() 158 { 159 public void onClick(DialogInterface dialog, final int item) 160 { 161 new ServerAsyncTask(TopicActivity.this, R.string.subscribe_topic) 162 { 163 164 @Override 165 protected void callServer() throws TapatalkException 166 { 167 client.subscribeTopic(topicId, item - 1); 168 } 169 170 @Override 171 protected void doOnSuccess() 172 { 173 Toast 174 .makeText(getApplicationContext(), R.string.subscription_saved, 175 Toast.LENGTH_SHORT).show(); 176 } 177 }.execute(); 178 } 179 }); 180 builder.create().show(); 181 return true; 182 183 case R.id.menu_mark_read: 184 185 // TODO: In Tapatalk-API-Version 3 nicht verfügbar! 186 new ServerAsyncTask(TopicActivity.this, R.string.mark_topic_read) 187 { 188 189 @Override 190 protected void callServer() throws TapatalkException 191 { 192 client.markTopicAsRead(topicId); 193 } 194 }.execute(); 195 return true; 196 197 } 198 return false; 199 } 200 201 }