android-ibc-forum

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 58cce1eae0484e46c80ae09aa62aac7b9bc8f91f
parent 3b00a1806ef8d0bb6f6bceb934188c925612134b
Author: Jan Dankert <devnull@localhost>
Date:   Fri, 27 Jan 2012 21:47:28 +0100

Anwendungsresourcen in eigener Application-Klasse speichern.

Diffstat:
src/de/mtbnews/android/EndlessListActivity.java | 201+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
src/de/mtbnews/android/ForumActivity.java | 99++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------
src/de/mtbnews/android/ForumOverviewActivity.java | 14+++++---------
src/de/mtbnews/android/IBCActivity.java | 7++-----
src/de/mtbnews/android/IBCApplication.java | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/de/mtbnews/android/MailActivity.java | 3+--
src/de/mtbnews/android/MailboxActivity.java | 10+---------
src/de/mtbnews/android/MessageActivity.java | 15+--------------
src/de/mtbnews/android/NewsActivity.java | 3+--
src/de/mtbnews/android/NewsDetailActivity.java | 34++++++++++++++++++++++------------
src/de/mtbnews/android/PostActivity.java | 1-
src/de/mtbnews/android/SearchActivity.java | 5++---
src/de/mtbnews/android/TopicActivity.java | 189++++++++++++++++++++++---------------------------------------------------------
src/de/mtbnews/android/adapter/ListEntryContentAdapter.java | 12+++++++++---
src/de/mtbnews/android/util/AppData.java | 30------------------------------
15 files changed, 402 insertions(+), 287 deletions(-)

diff --git a/src/de/mtbnews/android/EndlessListActivity.java b/src/de/mtbnews/android/EndlessListActivity.java @@ -3,6 +3,7 @@ */ package de.mtbnews.android; +import java.util.ArrayList; import java.util.List; import android.app.ListActivity; @@ -23,13 +24,21 @@ import android.widget.AbsListView.OnScrollListener; */ public abstract class EndlessListActivity<T> extends ListActivity { - private boolean loadingMore = true; + private boolean loadingInProgress = true; - private int displayFrom; - private int displayTo; + protected int displayFrom; + protected int displayTo; + protected boolean autoScrollDown; - private SharedPreferences prefs = PreferenceManager - .getDefaultSharedPreferences(this); + /** + * Die Referenz auf diese Liste darf sich nicht ändern, da der ListAdapter + * mit dieser Instanz verbunden ist. Durch 'final' wird das sicher gestellt. + */ + final protected List<T> entries = new ArrayList<T>(); + + private SharedPreferences prefs; + + private boolean firstLoad = true; /** * Absolute Anzahl aller verfügbaren Elemente. @@ -40,32 +49,78 @@ public abstract class EndlessListActivity<T> extends ListActivity protected void initialLoad() { + prefs = PreferenceManager.getDefaultSharedPreferences(this); final int numLoad = Integer.parseInt(prefs.getString("num_load", "10")); - final boolean autoScrollDown = prefs.getBoolean("scroll_down", false); + + if (getIntent().getBooleanExtra("first_post", false)) + autoScrollDown = false; + else if (getIntent().getBooleanExtra("last_post", false)) + autoScrollDown = true; + else + autoScrollDown = prefs.getBoolean("scroll_down", false); if (autoScrollDown) { - loadEntries(0, 1, true); + loadEntries(new OnListLoadedListener<T>() + { + + @Override + public void listLoaded(List<T> list) + { + final int end = getTotalSize(); + final int start = Math.max(0, end - numLoad); + + loadEntries(new OnListLoadedListener<T>() + { + + @Override + public void listLoaded(List<T> list) + { + entries.clear(); + entries.addAll(list); + ((BaseAdapter) getListAdapter()) + .notifyDataSetChanged(); + + displayFrom = start; + displayTo = end; - int end = getTotalSize(); - int start = Math.max(0, end - numLoad); + getListView().setSelection(entries.size() - 1); - loadEntries(start, end, true); + setOnScrollListener(); + + loadingInProgress = false; + } + }, start, end); + + } + }, 0, 1); - displayFrom = start; - displayTo = end; } else { - int start = 0; - int end = numLoad - 1; + final int start = 0; + final int end = numLoad - 1; + + loadEntries(new OnListLoadedListener<T>() + { + + @Override + public void listLoaded(List<T> list) + { + entries.clear(); + entries.addAll(list); + ((BaseAdapter) getListAdapter()).notifyDataSetChanged(); + + displayFrom = start; + displayTo = start + entries.size() - 1; - List<T> entries = loadEntries(start, end, true); - displayFrom = start; - displayTo = start + entries.size() - 1; + setOnScrollListener(); + + loadingInProgress = false; + } + }, start, end); } - ((BaseAdapter) getListAdapter()).notifyDataSetChanged(); } /** @@ -74,9 +129,24 @@ public abstract class EndlessListActivity<T> extends ListActivity * @param firstLoad * @return gelandene Elemente */ - abstract protected List<T> loadEntries(int from, int to, boolean firstLoad); + abstract protected void loadEntries(OnListLoadedListener<T> onListLoaded, + int from, int to, boolean firstLoad); + + /** + * @param onListLoaded + * @param from + * @param to + * @param firstLoad + * @return gelandene Elemente + */ + private void loadEntries(OnListLoadedListener<T> onListLoaded, int from, + int to) + { + loadEntries(onListLoaded, from, to, firstLoad); + firstLoad = false; + } - protected void setOnScrollListener() + private void setOnScrollListener() { final ListView list = getListView(); @@ -109,34 +179,95 @@ public abstract class EndlessListActivity<T> extends ListActivity * int, int, int) */ @Override - public void onScroll(AbsListView view, int firstVisibleItem, - int visibleItemCount, int totalItemCount) + public void onScroll(AbsListView view, final int firstVisibleItem, + final int visibleItemCount, final int totalItemCount) { // Letztes Item, dass angezeigt wird. int lastInScreen = firstVisibleItem + visibleItemCount; - // is the bottom item visible & not loading more already ? Load - // more ! - if ((lastInScreen == totalItemCount) - && (totalItemCount < getTotalSize()) && !(loadingMore)) + if (autoScrollDown) { - loadingMore = true; + // Sind wir am oberen Rand der Liste und die Liste ist noch + // nicht vollständig geladen? + if (firstVisibleItem == 0 && displayFrom > 0 + && !loadingInProgress) + { + loadingInProgress = true; - int start = displayTo + 1; - int end = start - + Integer.parseInt(prefs - .getString("num_load", "10")) - 1; + int start = Math.max(0, displayFrom + - Integer.parseInt(prefs.getString("num_load", + "10"))); - displayTo = end; + int end = displayFrom - 1; - loadEntries(start, end, false); + loadEntries(new OnListLoadedListener<T>() + { - loadingMore = false; - ((BaseAdapter) getListAdapter()).notifyDataSetChanged(); + @Override + public void listLoaded(List<T> list) + { + int loadedSize = list.size(); + displayFrom -= loadedSize; + + list.addAll(entries); + entries.clear(); + entries.addAll(list); + + ((BaseAdapter) getListAdapter()) + .notifyDataSetChanged(); + + // Zur gleichen Position springen (die jetzt + // aber etwas weiter nach hinten verschoben + // ist). + getListView().setSelection( + firstVisibleItem + loadedSize); + loadingInProgress = false; + } + }, start, end); + + } + } + else + { + // Sind wir am unterenRand der Liste? + if ((lastInScreen == totalItemCount) + && (totalItemCount < getTotalSize()) + && !(loadingInProgress)) + { + loadingInProgress = true; + + int start = displayTo + 1; + int end = start + + Integer.parseInt(prefs.getString("num_load", + "10")) - 1; + + loadEntries(new OnListLoadedListener<T>() + { + @Override + public void listLoaded(List<T> list) + { + int loadedSize = list.size(); + entries.addAll(list); + + displayTo += loadedSize; + + ((BaseAdapter) getListAdapter()) + .notifyDataSetChanged(); + + loadingInProgress = false; + } + }, start, end); + + } } } }); } + + interface OnListLoadedListener<T> + { + abstract void listLoaded(List<T> list); + } } diff --git a/src/de/mtbnews/android/ForumActivity.java b/src/de/mtbnews/android/ForumActivity.java @@ -17,10 +17,13 @@ import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; import android.text.TextUtils; +import android.view.ContextMenu; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.view.ContextMenu.ContextMenuInfo; +import android.view.View.OnCreateContextMenuListener; import android.widget.AdapterView; import android.widget.ListAdapter; import android.widget.ListView; @@ -31,9 +34,6 @@ import de.mtbnews.android.adapter.MapContentAdapter; import de.mtbnews.android.tapatalk.TapatalkClient; import de.mtbnews.android.tapatalk.TapatalkException; import de.mtbnews.android.tapatalk.wrapper.Forum; -import de.mtbnews.android.tapatalk.wrapper.Topic; -import de.mtbnews.android.util.AppData; -import de.mtbnews.android.util.IBC; import de.mtbnews.android.util.ServerAsyncTask; /** @@ -50,15 +50,14 @@ public class ForumActivity extends ListActivity protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); setContentView(R.layout.listing); prefs = PreferenceManager.getDefaultSharedPreferences(this); - TapatalkClient client = AppData.getTapatalkClient(); - + TapatalkClient client = ((IBCApplication)getApplication()).getTapatalkClient(); + if (!client.loggedIn && prefs.getBoolean("auto_login", false)) { login(); @@ -84,38 +83,69 @@ public class ForumActivity extends ListActivity } } + @Override + public boolean onContextItemSelected(MenuItem item) + { + AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) item + .getMenuInfo(); + + switch (item.getItemId()) + { + case R.id.menu_goto_top: + + final Intent intent = new Intent(ForumActivity.this, + TopicActivity.class); + intent.putExtra("topic_id", forum.getTopics().get( + menuInfo.position).getId()); + intent.putExtra("first_post", true); + startActivity(intent); + return true; + + case R.id.menu_goto_bottom: + + final Intent intent2 = new Intent(ForumActivity.this, + TopicActivity.class); + intent2.putExtra("topic_id", forum.getTopics().get( + menuInfo.position).getId()); + intent2.putExtra("last_post", true); + startActivity(intent2); + return true; + } + + return super.onContextItemSelected(item); + } + private void login() { - final TapatalkClient client = AppData.client; + final TapatalkClient client = ((IBCApplication)getApplication()).client; new ServerAsyncTask(this, R.string.waitingfor_login) { - + @Override protected synchronized void callServer() throws IOException { - + try { Map<String, Object> map = client.login(prefs.getString( "username", ""), prefs.getString("password", "")); - + } catch (TapatalkException e) { e.printStackTrace(); throw new RuntimeException(e); } - + } - + }.executeSynchronized(); } - - + private void logout() { - final TapatalkClient client = AppData.client; - + final TapatalkClient client = ((IBCApplication)getApplication()).client; + new ServerAsyncTask(this, R.string.waitingfor_logout) { @@ -143,7 +173,7 @@ public class ForumActivity extends ListActivity { final SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(this); - final XMLRPCClient client = AppData.client.getXMLRPCClient(); + final XMLRPCClient client = ((IBCApplication)getApplication()).client.getXMLRPCClient(); new ServerAsyncTask(this, R.string.waitingforcontent) { @@ -219,7 +249,7 @@ public class ForumActivity extends ListActivity { final SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(this); - final XMLRPCClient client = AppData.client.getXMLRPCClient(); + final XMLRPCClient client = ((IBCApplication)getApplication()).client.getXMLRPCClient(); new ServerAsyncTask(this, R.string.waitingforcontent) { @@ -289,7 +319,7 @@ public class ForumActivity extends ListActivity { final SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(this); - final XMLRPCClient client = AppData.client.getXMLRPCClient(); + final XMLRPCClient client = ((IBCApplication)getApplication()).client.getXMLRPCClient(); new ServerAsyncTask(this, R.string.waitingfor_forum) { @@ -355,7 +385,7 @@ public class ForumActivity extends ListActivity private void loadForum(final String forumId) { - final TapatalkClient client = AppData.client; + final TapatalkClient client = ((IBCApplication)getApplication()).client; new ServerAsyncTask(this, R.string.waitingfor_forum) { @@ -404,6 +434,19 @@ public class ForumActivity extends ListActivity } }); + + list.setOnCreateContextMenuListener(new OnCreateContextMenuListener() + { + + @Override + public void onCreateContextMenu(ContextMenu menu, View v, + ContextMenuInfo menuInfo) + { + MenuInflater menuInflater = new MenuInflater(getApplication()); + menuInflater.inflate(R.menu.topic_context, menu); + + } + }); } @Override @@ -412,7 +455,7 @@ public class ForumActivity extends ListActivity super.onCreateOptionsMenu(menu); MenuInflater mi = new MenuInflater(getApplication()); - if (AppData.client.loggedIn) + if (((IBCApplication)getApplication()).client.loggedIn) mi.inflate(R.menu.forum, menu); else mi.inflate(R.menu.forum_guest, menu); @@ -453,8 +496,10 @@ public class ForumActivity extends ListActivity if (TextUtils.isEmpty(prefs.getString("username", ""))) { - Toast.makeText(this,R.string.nousername,Toast.LENGTH_LONG).show(); - + Toast + .makeText(this, R.string.nousername, + Toast.LENGTH_LONG).show(); + Intent intent4 = new Intent(this, Configuration.class); startActivity(intent4); } @@ -464,11 +509,13 @@ public class ForumActivity extends ListActivity { login(); } - else { - Toast.makeText(this,R.string.nousername,Toast.LENGTH_LONG).show(); + else + { + Toast + .makeText(this, R.string.nousername, + Toast.LENGTH_LONG).show(); } - return true; } return false; diff --git a/src/de/mtbnews/android/ForumOverviewActivity.java b/src/de/mtbnews/android/ForumOverviewActivity.java @@ -26,7 +26,6 @@ import de.mtbnews.android.adapter.ExpandableForumContentAdapter; import de.mtbnews.android.tapatalk.TapatalkClient; import de.mtbnews.android.tapatalk.TapatalkException; import de.mtbnews.android.tapatalk.wrapper.Forum; -import de.mtbnews.android.util.AppData; import de.mtbnews.android.util.IBC; import de.mtbnews.android.util.ServerAsyncTask; @@ -42,16 +41,13 @@ public class ForumOverviewActivity extends ExpandableListActivity @Override protected void onCreate(Bundle savedInstanceState) { - if (AppData.client == null) - AppData.client = new TapatalkClient(IBC.IBC_FORUM_CONNECTOR_URL); - super.onCreate(savedInstanceState); setContentView(R.layout.exp_listing); prefs = PreferenceManager.getDefaultSharedPreferences(this); - if (!AppData.getTapatalkClient().loggedIn + if (!((IBCApplication)getApplication()).getTapatalkClient().loggedIn && prefs.getBoolean("auto_login", false)) login(); @@ -60,7 +56,7 @@ public class ForumOverviewActivity extends ExpandableListActivity private void login() { - final TapatalkClient client = AppData.client; + final TapatalkClient client = ((IBCApplication)getApplication()).client; new ServerAsyncTask(this, R.string.waitingfor_login) { @@ -125,7 +121,7 @@ public class ForumOverviewActivity extends ExpandableListActivity private void loadForum() { - final TapatalkClient client = AppData.getTapatalkClient(); + final TapatalkClient client = ((IBCApplication)getApplication()).getTapatalkClient(); new ServerAsyncTask(this, R.string.waitingfor_forum) { @@ -214,7 +210,7 @@ public class ForumOverviewActivity extends ExpandableListActivity super.onCreateOptionsMenu(menu); MenuInflater mi = new MenuInflater(getApplication()); - TapatalkClient client = AppData.getTapatalkClient(); + TapatalkClient client = ((IBCApplication)getApplication()).getTapatalkClient(); if (client.loggedIn) mi.inflate(R.menu.forum, menu); @@ -295,7 +291,7 @@ public class ForumOverviewActivity extends ExpandableListActivity private void logout() { - final TapatalkClient client = AppData.client; + final TapatalkClient client = ((IBCApplication)getApplication()).client; new ServerAsyncTask(this, R.string.waitingfor_logout) { diff --git a/src/de/mtbnews/android/IBCActivity.java b/src/de/mtbnews/android/IBCActivity.java @@ -19,14 +19,12 @@ package de.mtbnews.android; import java.io.IOException; -import java.net.URI; import org.apache.http.client.ClientProtocolException; import org.mcsoxford.rss.RSSFeed; import org.mcsoxford.rss.RSSReader; import org.mcsoxford.rss.RSSReaderException; -import android.app.AlertDialog; import android.app.ListActivity; import android.content.Intent; import android.content.SharedPreferences; @@ -44,7 +42,6 @@ import android.widget.ListAdapter; import android.widget.ListView; import android.widget.AdapterView.OnItemClickListener; import de.mtbnews.android.adapter.RSSContentAdapter; -import de.mtbnews.android.util.AppData; import de.mtbnews.android.util.IBC; import de.mtbnews.android.util.ServerAsyncTask; @@ -104,7 +101,7 @@ public class IBCActivity extends ListActivity */ private void reloadFeed() { - if (AppData.newsFeed != null) + if (((IBCApplication)getApplication()).newsFeed != null) { // Nicht nochmal laden. // TODO: Reload-Funktion. @@ -123,7 +120,7 @@ public class IBCActivity extends ListActivity try { feed = reader.load(IBC.IBC_NEWS_RSS_URL); - AppData.newsFeed = feed; + ((IBCApplication)getApplication()).newsFeed = feed; } catch (RSSReaderException e) { diff --git a/src/de/mtbnews/android/IBCApplication.java b/src/de/mtbnews/android/IBCApplication.java @@ -0,0 +1,66 @@ +/** + * + */ +package de.mtbnews.android; + +import org.mcsoxford.rss.RSSFeed; + +import android.app.Application; +import de.mtbnews.android.tapatalk.TapatalkClient; +import de.mtbnews.android.util.IBC; + +/** + * IBC-Application. Diese Klasse dient als anwendungsweite (und damit + * Activity-übergreifende) Ablage für Informationen. + * + * @author dankert + * + */ +public class IBCApplication extends Application +{ + public RSSFeed newsFeed; + + public RSSFeed photoFeed; + + public TapatalkClient client; + + public TapatalkClient getTapatalkClient() + { + return client; + } + + /** + * {@inheritDoc} + * + * @see android.app.Application#onCreate() + */ + @Override + public void onCreate() + { + client = new TapatalkClient(IBC.IBC_FORUM_CONNECTOR_URL); + + super.onCreate(); + } + + /** + * {@inheritDoc} + * + * @see android.app.Application#onLowMemory() + */ + @Override + public void onLowMemory() + { + super.onLowMemory(); + } + + /** + * {@inheritDoc} + * + * @see android.app.Application#onTerminate() + */ + @Override + public void onTerminate() + { + super.onTerminate(); + } +} diff --git a/src/de/mtbnews/android/MailActivity.java b/src/de/mtbnews/android/MailActivity.java @@ -17,7 +17,6 @@ import android.widget.ListAdapter; import android.widget.ListView; import android.widget.AdapterView.OnItemClickListener; import de.mtbnews.android.adapter.MapContentAdapter; -import de.mtbnews.android.util.AppData; import de.mtbnews.android.util.ServerAsyncTask; public class MailActivity extends ListActivity @@ -44,7 +43,7 @@ public class MailActivity extends ListActivity try { - Object l = AppData.client.getXMLRPCClient().call("get_box"); + Object l = ((IBCApplication)getApplication()).client.getXMLRPCClient().call("get_box"); this.forumList = (Object[]) ((Map) l).get("list"); diff --git a/src/de/mtbnews/android/MailboxActivity.java b/src/de/mtbnews/android/MailboxActivity.java @@ -5,16 +5,11 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import org.apache.http.client.ClientProtocolException; -import org.mcsoxford.rss.RSSFeed; import org.mcsoxford.rss.RSSItem; -import org.mcsoxford.rss.RSSReader; -import org.mcsoxford.rss.RSSReaderException; import org.xmlrpc.android.XMLRPCException; import android.app.ListActivity; import android.content.Intent; -import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; @@ -22,9 +17,6 @@ import android.widget.ListAdapter; import android.widget.ListView; import android.widget.AdapterView.OnItemClickListener; import de.mtbnews.android.adapter.MapContentAdapter; -import de.mtbnews.android.adapter.RSSContentAdapter; -import de.mtbnews.android.util.AppData; -import de.mtbnews.android.util.IBC; import de.mtbnews.android.util.ServerAsyncTask; public class MailboxActivity extends ListActivity @@ -49,7 +41,7 @@ public class MailboxActivity extends ListActivity try { - Object l = AppData.client.getXMLRPCClient().call("get_box_info"); + Object l = ((IBCApplication)getApplication()).client.getXMLRPCClient().call("get_box_info"); this.forumList = (Object[]) ((Map) l).get("list"); diff --git a/src/de/mtbnews/android/MessageActivity.java b/src/de/mtbnews/android/MessageActivity.java @@ -1,28 +1,15 @@ package de.mtbnews.android; import java.io.IOException; -import java.util.Map; - -import org.apache.http.client.ClientProtocolException; -import org.mcsoxford.rss.RSSFeed; -import org.mcsoxford.rss.RSSReader; -import org.mcsoxford.rss.RSSReaderException; import android.app.Activity; import android.content.Intent; import android.os.Bundle; -import android.text.Html; -import android.text.format.DateFormat; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; -import android.widget.ListAdapter; import android.widget.TextView; -import de.mtbnews.android.NewsDetailActivity.ImageGetter; -import de.mtbnews.android.adapter.RSSContentAdapter; import de.mtbnews.android.tapatalk.TapatalkClient; -import de.mtbnews.android.util.AppData; -import de.mtbnews.android.util.IBC; import de.mtbnews.android.util.ServerAsyncTask; public class MessageActivity extends Activity @@ -41,7 +28,7 @@ public class MessageActivity extends Activity @Override protected void callServer() throws IOException { - client = AppData.getTapatalkClient(); + client = ((IBCApplication)getApplication()).getTapatalkClient(); } protected void doOnSuccess() diff --git a/src/de/mtbnews/android/NewsActivity.java b/src/de/mtbnews/android/NewsActivity.java @@ -16,7 +16,6 @@ import android.widget.ListAdapter; import android.widget.ListView; import android.widget.AdapterView.OnItemClickListener; import de.mtbnews.android.adapter.RSSContentAdapter; -import de.mtbnews.android.util.AppData; import de.mtbnews.android.util.IBC; import de.mtbnews.android.util.ServerAsyncTask; @@ -50,7 +49,7 @@ public class NewsActivity extends ListActivity try { feed = reader.load(IBC.IBC_NEWS_RSS_URL); - AppData.newsFeed = feed; + ((IBCApplication)getApplication()).newsFeed = feed; } catch (RSSReaderException e) { diff --git a/src/de/mtbnews/android/NewsDetailActivity.java b/src/de/mtbnews/android/NewsDetailActivity.java @@ -8,27 +8,31 @@ import org.mcsoxford.rss.RSSItem; import android.app.Activity; import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.Bundle; +import android.preference.PreferenceManager; import android.text.Html; import android.text.format.DateFormat; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; -import de.mtbnews.android.util.AppData; public class NewsDetailActivity extends Activity { + protected SharedPreferences prefs; + @Override protected void onCreate(Bundle savedInstanceState) { + prefs = PreferenceManager.getDefaultSharedPreferences(this); setContentView(R.layout.newsdetail); super.onCreate(savedInstanceState); - final RSSItem item = AppData.newsFeed.getItems().get( + final RSSItem item = ((IBCApplication)getApplication()).newsFeed.getItems().get( getIntent().getIntExtra("itemid", 0)); TextView datum = (TextView) findViewById(R.id.item_date); @@ -41,7 +45,13 @@ public class NewsDetailActivity extends Activity // if (e.getContent() != null) final String html = item.getContent(); - desc.setText(Html.fromHtml(html, new ImageGetter(), null)); + + ImageGetter imageGetter = null; + if (prefs.getBoolean("load_images", false)) + imageGetter = new ImageGetter(); + + desc.setText(Html.fromHtml(html, imageGetter, null)); + setTitle(item.getTitle()); Button button = (Button) findViewById(R.id.item_button); @@ -67,14 +77,14 @@ public class NewsDetailActivity extends Activity { Drawable d = null; String imageSource; -// if (!source.startsWith("http://www")) -// { -// imageSource = "http://www.minhembio.com" + source; -// } -// else -// { - imageSource = source; - // } + // if (!source.startsWith("http://www")) + // { + // imageSource = "http://www.minhembio.com" + source; + // } + // else + // { + imageSource = source; + // } try { @@ -94,7 +104,7 @@ public class NewsDetailActivity extends Activity catch (Exception e) { throw new RuntimeException(e); - //d = null; + // d = null; } return d; diff --git a/src/de/mtbnews/android/PostActivity.java b/src/de/mtbnews/android/PostActivity.java @@ -4,7 +4,6 @@ package de.mtbnews.android; import java.io.IOException; -import java.lang.reflect.ReflectPermission; import java.util.Map; import org.xmlrpc.android.XMLRPCClient; diff --git a/src/de/mtbnews/android/SearchActivity.java b/src/de/mtbnews/android/SearchActivity.java @@ -27,7 +27,6 @@ import de.mtbnews.android.tapatalk.TapatalkClient; import de.mtbnews.android.tapatalk.TapatalkException; import de.mtbnews.android.tapatalk.wrapper.Search; import de.mtbnews.android.tapatalk.wrapper.Topic; -import de.mtbnews.android.util.AppData; import de.mtbnews.android.util.ServerAsyncTask; /** @@ -75,7 +74,7 @@ public class SearchActivity extends ListActivity @Override protected void callServer() throws IOException { - TapatalkClient client = AppData.getTapatalkClient(); + TapatalkClient client = ((IBCApplication)getApplication()).getTapatalkClient(); try { @@ -156,7 +155,7 @@ public class SearchActivity extends ListActivity @Override protected void callServer() throws IOException { - TapatalkClient client = AppData.client; + TapatalkClient client = ((IBCApplication)getApplication()).client; try { diff --git a/src/de/mtbnews/android/TopicActivity.java b/src/de/mtbnews/android/TopicActivity.java @@ -4,92 +4,98 @@ package de.mtbnews.android; import java.io.IOException; -import java.util.ArrayList; import java.util.List; -import java.util.Map; -import org.xmlrpc.android.XMLRPCClient; -import org.xmlrpc.android.XMLRPCException; - -import android.app.ListActivity; -import android.content.Intent; -import android.content.SharedPreferences; import android.os.Bundle; -import android.preference.PreferenceManager; import android.view.View; -import android.widget.AbsListView; import android.widget.AdapterView; -import android.widget.BaseAdapter; import android.widget.ListAdapter; import android.widget.ListView; -import android.widget.AbsListView.OnScrollListener; +import android.widget.Toast; import android.widget.AdapterView.OnItemClickListener; import de.mtbnews.android.adapter.ListEntryContentAdapter; -import de.mtbnews.android.adapter.MapContentAdapter; import de.mtbnews.android.tapatalk.TapatalkClient; import de.mtbnews.android.tapatalk.TapatalkException; -import de.mtbnews.android.tapatalk.wrapper.ListEntry; import de.mtbnews.android.tapatalk.wrapper.Post; import de.mtbnews.android.tapatalk.wrapper.Topic; -import de.mtbnews.android.util.AppData; import de.mtbnews.android.util.ServerAsyncTask; /** + * Anzeige eines Themas. + * * @author dankert * */ -public class TopicActivity extends ListActivity +public class TopicActivity extends EndlessListActivity<Post> { - public static final String ID = "id"; - public static final String CLIENT = "client"; - - private boolean loadingMore = true; - - private int displayFrom; - private int displayTo; - private int postCount; - - private List<Post> posts; - private Topic topic; - - Map<String, String> data; + private int totalSize; @Override protected void onCreate(Bundle savedInstanceState) { - final SharedPreferences prefs = PreferenceManager - .getDefaultSharedPreferences(this); - super.onCreate(savedInstanceState); setContentView(R.layout.listing); - new ServerAsyncTask(this, R.string.waitingfor_topic) + ListAdapter adapter = new ListEntryContentAdapter(TopicActivity.this, + entries); + setListAdapter(adapter); + + initialLoad(); + + final ListView list = getListView(); + + list.setOnItemClickListener(new OnItemClickListener() + { + @Override + public void onItemClick(AdapterView<?> parent, View view, + int position, long id) + { + Toast.makeText(TopicActivity.this, + displayFrom + " - " + displayTo, Toast.LENGTH_SHORT) + .show(); + + // final Intent intent = new Intent(TopicActivity.this, + // PostActivity.class); + // intent.putExtra("itemid", position); + // startActivity(intent); + } + }); + } + + + @Override + protected int getTotalSize() + { + return this.totalSize; + } + + @Override + protected void loadEntries( + final OnListLoadedListener<Post> onListLoadedListener, + final int from, final int to, boolean firstLoad) + { + new ServerAsyncTask(TopicActivity.this, + firstLoad ? R.string.waitingfor_topic + : R.string.waitingfor_loadmore) { + private List<Post> posts; + private Topic topic; @Override protected void callServer() throws IOException { - TapatalkClient client = AppData.client; + TapatalkClient client = ((IBCApplication)getApplication()).client; try { - int start = 0; - int end = Integer.parseInt(prefs - .getString("num_load", "10")) - 1; - - displayFrom = start; - displayTo = end; - String topicId = TopicActivity.this.getIntent() .getStringExtra("topic_id"); - topic = client.getTopic(topicId, start, end); + topic = client.getTopic(topicId, from, to); - postCount = topic.getPostCount(); - posts = topic.getPosts(); - - loadingMore = false; + totalSize = topic.getPostCount(); + this.posts = topic.getPosts(); } catch (TapatalkException e) { @@ -100,98 +106,9 @@ public class TopicActivity extends ListActivity protected void doOnSuccess() { TopicActivity.this.setTitle(topic.getTitle()); - List p = posts; - ListAdapter adapter = new ListEntryContentAdapter( - TopicActivity.this, p); - setListAdapter(adapter); - + onListLoadedListener.listLoaded(this.posts); } }.execute(); - final ListView list = getListView(); - - list.setOnItemClickListener(new OnItemClickListener() - { - @Override - public void onItemClick(AdapterView<?> parent, View view, - int position, long id) - { - final Intent intent = new Intent(TopicActivity.this, - PostActivity.class); - intent.putExtra("itemid", position); - startActivity(intent); - } - }); - - /** - * Weitere List-Einträge automatisch nachladen. - */ - list.setOnScrollListener(new OnScrollListener() - { - - @Override - public void onScrollStateChanged(AbsListView view, int scrollState) - { - } - - @Override - public void onScroll(AbsListView view, int firstVisibleItem, - int visibleItemCount, int totalItemCount) - { - - // what is the bottom iten that is visible - int lastInScreen = firstVisibleItem + visibleItemCount; - - // is the bottom item visible & not loading more already ? Load - // more ! - if ((lastInScreen == totalItemCount) && !(loadingMore)) - { - loadingMore = true; - new ServerAsyncTask(TopicActivity.this, - R.string.waitingfor_loadmore) - { - @Override - protected void callServer() throws IOException - { - TapatalkClient client = AppData.client; - - try - { - int start = displayTo + 1; - int end = start - + Integer.parseInt(prefs.getString( - "num_load", "10")) - 1; - - displayTo = end; - - String topicId = TopicActivity.this.getIntent() - .getStringExtra("topic_id"); - - Topic topic = client.getTopic(topicId, start, - end); - - postCount = topic.getPostCount(); - posts.addAll(topic.getPosts()); - - loadingMore = false; - } - catch (TapatalkException e) - { - throw new RuntimeException(e); - } - } - - protected void doOnSuccess() - { - ((BaseAdapter) getListAdapter()) - .notifyDataSetChanged(); - } - - }.execute(); - - } - } - }); - } } diff --git a/src/de/mtbnews/android/adapter/ListEntryContentAdapter.java b/src/de/mtbnews/android/adapter/ListEntryContentAdapter.java @@ -4,18 +4,18 @@ package de.mtbnews.android.adapter; import java.util.List; -import java.util.Map; +import ru.perm.kefir.bbcode.BBProcessorFactory; +import ru.perm.kefir.bbcode.TextProcessor; import android.content.Context; +import android.text.Html; import android.text.format.DateFormat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; -import android.widget.LinearLayout; import android.widget.TextView; import de.mtbnews.android.R; -import de.mtbnews.android.adapter.MapContentAdapter.ViewHolder; import de.mtbnews.android.tapatalk.wrapper.ListEntry; /** @@ -115,7 +115,13 @@ public class ListEntryContentAdapter extends BaseAdapter viewHolder.name.setEnabled(false); if (e.getContent() != null) + { + //if ( prefs parse_bbcode ) {} + // TextProcessor create = BBProcessorFactory.getInstance().create(); + // CharSequence html = create.process("[b]..."); + // Html.fromHtml(html); viewHolder.desc.setText(e.getContent()); + } else viewHolder.desc.setText(""); diff --git a/src/de/mtbnews/android/util/AppData.java b/src/de/mtbnews/android/util/AppData.java @@ -1,30 +0,0 @@ -package de.mtbnews.android.util; - -import org.mcsoxford.rss.RSSFeed; -import org.xmlrpc.android.XMLRPCClient; - -import de.mtbnews.android.tapatalk.TapatalkClient; - -/** - * Speichert Anwendungsdaten. - * - * @author dankert - * - */ -public class AppData -{ - public static RSSFeed newsFeed; - - public static RSSFeed photoFeed; - - public static TapatalkClient client; - - public static TapatalkClient getTapatalkClient() - { - - if (client == null) - AppData.client = new TapatalkClient(IBC.IBC_FORUM_CONNECTOR_URL); - - return client; - } -}