android-ibc-forum

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

commit ba9d19d5dff16345cf86368c847634cf551393ee
parent 58b794aa9a851fc04485f5d9647b0423b1671987
Author: Jan Dankert <devnull@localhost>
Date:   Thu,  9 Feb 2012 23:13:49 +0100

Fehlerhandling: TapatalkException erhält Fehlercode, der sich in String-Resourcen umwandeln lässt. Login bei jedem Timerevent im Abo-Service, bei Forenaktivitäten dasLogin nach 10 Minuten erneuern.

Diffstat:
res/values/strings.xml | 7+++++--
src/de/mtbnews/android/CreateTopicActivity.java | 15++++++++++++---
src/de/mtbnews/android/ForumOverviewActivity.java | 10++++++----
src/de/mtbnews/android/MailboxActivity.java | 4++--
src/de/mtbnews/android/ReplyPostActivity.java | 13++++++++++---
src/de/mtbnews/android/SubscriptionForenActivity.java | 8++++----
src/de/mtbnews/android/SubscriptionTopicsActivity.java | 8++++----
src/de/mtbnews/android/service/SubscriptionService.java | 32+++++++++-----------------------
src/de/mtbnews/android/tapatalk/TapatalkClient.java | 68+++++++++++++++++++++++++++++++-------------------------------------
src/de/mtbnews/android/tapatalk/TapatalkException.java | 23+++++++++++++++++++++--
src/de/mtbnews/android/util/IBC.java | 6+++++-
src/de/mtbnews/android/util/ServerAsyncTask.java | 9++++++---
src/de/mtbnews/android/util/Utils.java | 47+++++++++++++++++++++++++++++++++++++++++++++++
13 files changed, 162 insertions(+), 88 deletions(-)

diff --git a/res/values/strings.xml b/res/values/strings.xml @@ -1,6 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <resources> + <string name="canceled">Abgebrochen</string> <string name="more">Mehr</string> <string name="sub_only">Forum enthält keine Themen</string> <string name="app_name">IBC</string> @@ -60,7 +61,9 @@ <string name="description">Inhalt</string> <string name="editor">Inhalt</string> <string name="error_timeout">Zeitablauf</string> - <string name="error_io">Verbindungsabbruch</string> + <string name="error_io">Keine Verbindung</string> + <string name="xmlrpc_error">Keine Verbindung zum Server</string> + <string name="error_common_server">Keine Antwort vom Server</string> <string name="error">Fehler</string> <string name="error_tapatalk">Tut uns leid, aber diese Aktion war nicht erfolgreich</string> <string name="reason">Grund</string> @@ -94,7 +97,7 @@ <string name="auto_load_next_desc">Beim Scrollen die nächsten Einträge automatisch laden</string> <string name="login">Anmelden</string> - <string name="login_success">Benutzeranmeldung erfolgreich</string> + <string name="login_success">Anmeldung erfolgreich</string> <string name="login_failed">Benutzeranmeldung nicht erfolgreich</string> <string name="logout">Abmelden</string> <string-array name="num_load_list"> diff --git a/src/de/mtbnews/android/CreateTopicActivity.java b/src/de/mtbnews/android/CreateTopicActivity.java @@ -3,7 +3,9 @@ package de.mtbnews.android; import java.io.IOException; import android.app.Activity; +import android.content.SharedPreferences; import android.os.Bundle; +import android.preference.PreferenceManager; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; @@ -12,17 +14,19 @@ import android.widget.Toast; import de.mtbnews.android.tapatalk.TapatalkClient; import de.mtbnews.android.tapatalk.TapatalkException; import de.mtbnews.android.util.ServerAsyncTask; +import de.mtbnews.android.util.Utils; public class CreateTopicActivity extends Activity { private String forumId; + private SharedPreferences prefs; @Override protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.post); super.onCreate(savedInstanceState); - + prefs = PreferenceManager.getDefaultSharedPreferences(this); forumId = getIntent().getStringExtra("forum_id"); final TextView recipient = (TextView) findViewById(R.id.recipient); @@ -41,8 +45,7 @@ public class CreateTopicActivity extends Activity @Override public void onClick(View v) { - new ServerAsyncTask(CreateTopicActivity.this, - R.string.send) + new ServerAsyncTask(CreateTopicActivity.this, R.string.send) { @Override @@ -51,6 +54,12 @@ public class CreateTopicActivity extends Activity { TapatalkClient client = ((IBCApplication) getApplication()) .getTapatalkClient(); + + // Login. + if (Utils.loginExceeded(client)) + client.login(prefs.getString("username", ""), prefs + .getString("password", "")); + client.createTopic(forumId, subject.getText() .toString(), text.getText().toString()); } diff --git a/src/de/mtbnews/android/ForumOverviewActivity.java b/src/de/mtbnews/android/ForumOverviewActivity.java @@ -27,7 +27,9 @@ 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.IBC; import de.mtbnews.android.util.ServerAsyncTask; +import de.mtbnews.android.util.Utils; /** * @author dankert @@ -93,10 +95,10 @@ public class ForumOverviewActivity extends ExpandableListActivity protected void callServer() throws TapatalkException { // Login. - if (!((IBCApplication) getApplication()).getTapatalkClient().loggedIn - && prefs.getBoolean("auto_login", false)) - client.login(prefs.getString("username", ""), prefs - .getString("password", "")); + if (prefs.getBoolean("auto_login", false)) + if (Utils.loginExceeded(client)) + client.login(prefs.getString("username", ""), prefs + .getString("password", "")); forumList = client.getAllForum(); unterforenFlachkloppen(); diff --git a/src/de/mtbnews/android/MailboxActivity.java b/src/de/mtbnews/android/MailboxActivity.java @@ -21,6 +21,7 @@ import de.mtbnews.android.tapatalk.TapatalkClient; import de.mtbnews.android.tapatalk.TapatalkException; import de.mtbnews.android.tapatalk.wrapper.Mailbox; import de.mtbnews.android.util.ServerAsyncTask; +import de.mtbnews.android.util.Utils; public class MailboxActivity extends ListActivity { @@ -45,8 +46,7 @@ public class MailboxActivity extends ListActivity .getTapatalkClient(); // Login. - if (!((IBCApplication) getApplication()).getTapatalkClient().loggedIn - && prefs.getBoolean("auto_login", false)) + if (Utils.loginExceeded(client)) client.login(prefs.getString("username", ""), prefs .getString("password", "")); diff --git a/src/de/mtbnews/android/ReplyPostActivity.java b/src/de/mtbnews/android/ReplyPostActivity.java @@ -1,10 +1,9 @@ package de.mtbnews.android; -import java.io.IOException; - import android.app.Activity; -import android.app.AlertDialog; +import android.content.SharedPreferences; import android.os.Bundle; +import android.preference.PreferenceManager; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; @@ -13,6 +12,7 @@ import android.widget.Toast; import de.mtbnews.android.tapatalk.TapatalkClient; import de.mtbnews.android.tapatalk.TapatalkException; import de.mtbnews.android.util.ServerAsyncTask; +import de.mtbnews.android.util.Utils; public class ReplyPostActivity extends Activity { @@ -20,12 +20,14 @@ public class ReplyPostActivity extends Activity private String topicId; private String subject; private String quote; + private SharedPreferences prefs; @Override protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.post); super.onCreate(savedInstanceState); + prefs = PreferenceManager.getDefaultSharedPreferences(this); topicId = getIntent().getStringExtra("topic_id"); forumId = getIntent().getStringExtra("forum_id"); @@ -61,6 +63,11 @@ public class ReplyPostActivity extends Activity TapatalkClient client = ((IBCApplication) getApplication()) .getTapatalkClient(); + // Login. + if (Utils.loginExceeded(client)) + client.login(prefs.getString("username", ""), prefs + .getString("password", "")); + client.createReply(forumId, topicId, subject.getText() .toString(), text.getText().toString()); } diff --git a/src/de/mtbnews/android/SubscriptionForenActivity.java b/src/de/mtbnews/android/SubscriptionForenActivity.java @@ -29,6 +29,7 @@ import de.mtbnews.android.tapatalk.TapatalkClient; import de.mtbnews.android.tapatalk.TapatalkException; import de.mtbnews.android.tapatalk.wrapper.Forum; import de.mtbnews.android.util.ServerAsyncTask; +import de.mtbnews.android.util.Utils; /** * @author dankert @@ -95,13 +96,12 @@ public class SubscriptionForenActivity extends ListActivity protected void callServer() throws IOException, TapatalkException { TapatalkClient client = ((IBCApplication) getApplication()).client; - + // Login. - if (!((IBCApplication) getApplication()).getTapatalkClient().loggedIn - && prefs.getBoolean("auto_login", false)) + if (Utils.loginExceeded(client)) client.login(prefs.getString("username", ""), prefs .getString("password", "")); - + newForumList = client.getSubscribedForum(false); } diff --git a/src/de/mtbnews/android/SubscriptionTopicsActivity.java b/src/de/mtbnews/android/SubscriptionTopicsActivity.java @@ -26,6 +26,7 @@ import de.mtbnews.android.tapatalk.TapatalkException; import de.mtbnews.android.tapatalk.wrapper.ListHolder; import de.mtbnews.android.tapatalk.wrapper.Topic; import de.mtbnews.android.util.ServerAsyncTask; +import de.mtbnews.android.util.Utils; /** * Anzeige aller Beiträge eines Themas. @@ -43,7 +44,7 @@ public class SubscriptionTopicsActivity extends EndlessListActivity<Topic> { super.onCreate(savedInstanceState); prefs = PreferenceManager.getDefaultSharedPreferences(this); - + setContentView(R.layout.listing); ListAdapter adapter = new ListEntryContentAdapter( @@ -136,10 +137,9 @@ public class SubscriptionTopicsActivity extends EndlessListActivity<Topic> protected void callServer() throws IOException, TapatalkException { TapatalkClient client = ((IBCApplication) getApplication()).client; - + // Login. - if (!((IBCApplication) getApplication()).getTapatalkClient().loggedIn - && prefs.getBoolean("auto_login", false)) + if (Utils.loginExceeded(client)) client.login(prefs.getString("username", ""), prefs .getString("password", "")); diff --git a/src/de/mtbnews/android/service/SubscriptionService.java b/src/de/mtbnews/android/service/SubscriptionService.java @@ -32,6 +32,7 @@ import de.mtbnews.android.tapatalk.wrapper.ListHolder; import de.mtbnews.android.tapatalk.wrapper.Mailbox; import de.mtbnews.android.tapatalk.wrapper.Topic; import de.mtbnews.android.util.IBC; +import de.mtbnews.android.util.Utils; /** * @author dankert @@ -70,20 +71,6 @@ public class SubscriptionService extends Service client = ibcApp.getTapatalkClient(); - if (prefs.getBoolean("auto_login", false)) - { - Log.i(IBC.TAG, "Login for " + prefs.getString("username", "")); - try - { - client.login(prefs.getString("username", ""), prefs.getString( - "password", "")); - } - catch (TapatalkException e) - { - Log.w(IBC.TAG, e); - } - } - // Intervall in Minuten (Default = 3 Stunden) int intervalInMinutes = Integer.parseInt(prefs.getString( "subscription_service_interval", "180")); @@ -112,13 +99,8 @@ public class SubscriptionService extends Service try { - if (!client.loggedIn) - { - Log.d(IBC.TAG, "Login for: " - + prefs.getString("username", "")); - client.login(prefs.getString("username", ""), prefs - .getString("password", "")); - } + client.login(prefs.getString("username", ""), prefs.getString( + "password", "")); List<Forum> subscribedForum = client.getSubscribedForum(true); @@ -146,6 +128,7 @@ public class SubscriptionService extends Service .join(", ", forumNameList), contentIntent); nm.notify(NOTIFICATION_FORUM, notification); } + ListHolder<Topic> subscribedTopic = client.getSubscribedTopics( 0, 10, true); final List<String> topicNameList = new ArrayList<String>(); @@ -212,13 +195,16 @@ public class SubscriptionService extends Service } catch (TapatalkException e) { + // Kann vorkommen, wenn Login fehlschlägt oder Verbindung + // abbricht final Intent notificationIntent = new Intent( SubscriptionService.this, IBCActivity.class); final PendingIntent contentIntent = PendingIntent.getActivity( SubscriptionService.this, 0, notificationIntent, 0); final Notification notification = createNotification(e - .getMessage(), R.string.error, null, e.getMessage(), + .getMessage(), R.string.error, null, getResources() + .getString(Utils.getResId(e.getErrorCode())), contentIntent); notification.flags = Notification.FLAG_AUTO_CANCEL; @@ -234,7 +220,7 @@ public class SubscriptionService extends Service // Fehler nicht weiterwerfen, würde der Service eh nichts mehr // machen und niemandem wäre geholfen. Log.w(IBC.TAG, e); - throw new RuntimeException(e); + throw new RuntimeException("Unrecoverable error in service", e); } } diff --git a/src/de/mtbnews/android/tapatalk/TapatalkClient.java b/src/de/mtbnews/android/tapatalk/TapatalkClient.java @@ -9,6 +9,7 @@ import org.xmlrpc.android.XMLRPCClient; import org.xmlrpc.android.XMLRPCException; import android.text.TextUtils; +import de.mtbnews.android.tapatalk.TapatalkException.TapatalkErrorCode; import de.mtbnews.android.tapatalk.wrapper.Forum; import de.mtbnews.android.tapatalk.wrapper.ListHolder; import de.mtbnews.android.tapatalk.wrapper.Mailbox; @@ -28,7 +29,12 @@ public class TapatalkClient private XMLRPCClient client; public boolean loggedIn; + public long loginTime; + /** + * @param connectorUrl + * URL + */ public TapatalkClient(String connectorUrl) { this.client = new XMLRPCClient(connectorUrl); @@ -46,24 +52,10 @@ public class TapatalkClient throws TapatalkException { this.loggedIn = false; + this.loginTime = -1L; if (TextUtils.isEmpty(username)) - throw new TapatalkException("Username empty"); - - // try - // { - // - // final Map<String, Object> map = (Map<String, Object>) - // toMap(getXMLRPCClient() - // .call("get_config")); - // Log.i("IBC Server Config", map.toString()); - // for (String key : map.keySet()) - // Log.d("IBC Server Config", key + "=" + map.get(key)); - // } - // catch (XMLRPCException e) - // { - // throw new TapatalkException("Load Config failed", e); - // } + throw new TapatalkException("Username empty",TapatalkErrorCode.NO_USERNAME); final Object[] params = new Object[] { username.getBytes(), password.getBytes() }; @@ -73,11 +65,12 @@ public class TapatalkClient toMap(client.callEx("login", params)); this.loggedIn = true; + this.loginTime = System.currentTimeMillis(); } catch (XMLRPCException e) { throw new TapatalkException("Login failed" + ": " + e.getMessage(), - e); + e, TapatalkErrorCode.XMLRPC_ERROR); } } @@ -94,7 +87,7 @@ public class TapatalkClient catch (XMLRPCException e) { throw new TapatalkException( - "Logout failed" + ": " + e.getMessage(), e); + "Logout failed" + ": " + e.getMessage(), e, TapatalkErrorCode.XMLRPC_ERROR); } } @@ -131,7 +124,7 @@ public class TapatalkClient } catch (XMLRPCException e) { - throw new TapatalkException("Could not load Topic " + topicId, e); + throw new TapatalkException("Could not load Topic " + topicId, e, TapatalkErrorCode.XMLRPC_ERROR); } } @@ -149,7 +142,7 @@ public class TapatalkClient } catch (XMLRPCException e) { - throw new TapatalkException("Could not load Forum structure", e); + throw new TapatalkException("Could not load Forum structure", e, TapatalkErrorCode.XMLRPC_ERROR); } } @@ -215,7 +208,7 @@ public class TapatalkClient catch (XMLRPCException e) { throw new TapatalkException("Could not load Forum " + forumId - + ": " + e.getMessage(), e); + + ": " + e.getMessage(), e, TapatalkErrorCode.XMLRPC_ERROR); } } @@ -257,7 +250,7 @@ public class TapatalkClient catch (XMLRPCException e) { throw new TapatalkException("Could not load subscribe topics" - + ": " + e.getMessage(), e); + + ": " + e.getMessage(), e, TapatalkErrorCode.XMLRPC_ERROR); } } @@ -294,7 +287,7 @@ public class TapatalkClient catch (XMLRPCException e) { throw new TapatalkException("Could not load subscribe topics" - + ": " + e.getMessage(), e); + + ": " + e.getMessage(), e, TapatalkErrorCode.XMLRPC_ERROR); } } @@ -322,7 +315,7 @@ public class TapatalkClient } catch (XMLRPCException e) { - throw new TapatalkException("XMLRPC-Error: " + e.getMessage(), e); + throw new TapatalkException("XMLRPC-Error: " + e.getMessage(), e, TapatalkErrorCode.XMLRPC_ERROR); } } @@ -345,7 +338,7 @@ public class TapatalkClient catch (XMLRPCException e) { throw new TapatalkException("Marking topics read: " - + e.getMessage(), e); + + e.getMessage(), e, TapatalkErrorCode.XMLRPC_ERROR); } } @@ -384,7 +377,7 @@ public class TapatalkClient catch (XMLRPCException e) { throw new TapatalkException("Could not load subscribe topics" - + ": " + e.getMessage(), e); + + ": " + e.getMessage(), e, TapatalkErrorCode.XMLRPC_ERROR); } } @@ -417,7 +410,7 @@ public class TapatalkClient catch (XMLRPCException e) { throw new TapatalkException("Could not load subscribe topics" - + ": " + e.getMessage(), e); + + ": " + e.getMessage(), e, TapatalkErrorCode.XMLRPC_ERROR); } } @@ -497,7 +490,7 @@ public class TapatalkClient catch (XMLRPCException e) { throw new TapatalkException("Could not search" + ": " - + e.getMessage(), e); + + e.getMessage(), e, TapatalkErrorCode.XMLRPC_ERROR); } } @@ -534,7 +527,7 @@ public class TapatalkClient catch (XMLRPCException e) { throw new TapatalkException("Could not read mailbox" + ": " - + e.getMessage(), e); + + e.getMessage(), e, TapatalkErrorCode.XMLRPC_ERROR); } } @@ -587,7 +580,7 @@ public class TapatalkClient catch (XMLRPCException e) { throw new TapatalkException("Could not read mailbox " + boxId - + ": " + e.getMessage(), e); + + ": " + e.getMessage(), e, TapatalkErrorCode.XMLRPC_ERROR); } } @@ -627,7 +620,7 @@ public class TapatalkClient catch (XMLRPCException e) { throw new TapatalkException("Could not read message " + boxId + "," - + messageId + ": " + e.getMessage(), e); + + messageId + ": " + e.getMessage(), e, TapatalkErrorCode.XMLRPC_ERROR); } } @@ -656,7 +649,7 @@ public class TapatalkClient catch (XMLRPCException e) { throw new TapatalkException("Could not create the topic: " - + e.getMessage(), e); + + e.getMessage(), e, TapatalkErrorCode.XMLRPC_ERROR); } } @@ -684,7 +677,7 @@ public class TapatalkClient } catch (XMLRPCException e) { - throw new TapatalkException("Could not reply", e); + throw new TapatalkException("Could not reply", e, TapatalkErrorCode.XMLRPC_ERROR); } } @@ -709,12 +702,12 @@ public class TapatalkClient .callEx("create_message", params); if (!ok) { - throw new TapatalkException("sending message failed"); + throw new TapatalkException("sending message failed",TapatalkErrorCode.SEND_MESSAGE_FAILED); } } catch (XMLRPCException e) { - throw new TapatalkException("Could not create the message", e); + throw new TapatalkException("Could not create the message", e, TapatalkErrorCode.XMLRPC_ERROR); } } @@ -757,7 +750,7 @@ public class TapatalkClient if (!(o instanceof Map)) { throw new TapatalkException("no map: " + o.toString() + " (" - + o.getClass() + ")"); + + o.getClass() + ")",TapatalkErrorCode.UNKNOWN_SERVER_RESPONSE); } Map<String, Object> map = (Map<String, Object>) o; @@ -768,7 +761,7 @@ public class TapatalkClient boolean ok = (Boolean) object; if (!ok) throw new TapatalkException(byteArrayToString(map - .get("result_text"))); + .get("result_text")),TapatalkErrorCode.UNKNOWN_SERVER_RESPONSE); return map; } @@ -795,4 +788,5 @@ public class TapatalkClient } + } diff --git a/src/de/mtbnews/android/tapatalk/TapatalkException.java b/src/de/mtbnews/android/tapatalk/TapatalkException.java @@ -9,22 +9,41 @@ package de.mtbnews.android.tapatalk; */ public class TapatalkException extends Exception { + public static enum TapatalkErrorCode + { + NO_USERNAME, LOGIN_FAILED, XMLRPC_ERROR, UNKNOWN_SERVER_RESPONSE, SEND_MESSAGE_FAILED; + } + + private TapatalkErrorCode errorCode; /** * @param detailMessage * @param throwable + * @param errorCode + * TODO */ - public TapatalkException(String detailMessage, Throwable throwable) + public TapatalkException(String detailMessage, Throwable throwable, + TapatalkErrorCode errorCode) { + super(detailMessage, throwable); + this.errorCode = errorCode; } /** * @param detailMessage */ - public TapatalkException(String detailMessage) + public TapatalkException(String detailMessage, TapatalkErrorCode errorCode) { super(detailMessage); + this.errorCode = errorCode; } + /** + * @return + */ + public TapatalkErrorCode getErrorCode() + { + return errorCode; + } } diff --git a/src/de/mtbnews/android/util/IBC.java b/src/de/mtbnews/android/util/IBC.java @@ -23,7 +23,7 @@ public interface IBC * Fee-URL für Nachrichten. */ static final String IBC_NEWS_RSS_URL = "http://www.mtb-news.de/news/feed/"; - + /** * Feed-URL für Fotos. */ @@ -34,4 +34,8 @@ public interface IBC */ static final String TAG = "IBC"; + /** + * Sitzungs-Timeout. Ab wieviel Minuten sollte das Login erneuert werden? + */ + static final int LOGIN_TIMEOUT = 10; } diff --git a/src/de/mtbnews/android/util/ServerAsyncTask.java b/src/de/mtbnews/android/util/ServerAsyncTask.java @@ -13,6 +13,7 @@ import android.content.Context; import android.content.DialogInterface; import android.os.AsyncTask; import android.util.Log; +import android.widget.Toast; import de.mtbnews.android.R; import de.mtbnews.android.tapatalk.TapatalkClient; import de.mtbnews.android.tapatalk.TapatalkException; @@ -70,6 +71,7 @@ public abstract class ServerAsyncTask extends AsyncTask<Void, Void, Void> public void onCancel(DialogInterface dialog) { ServerAsyncTask.this.cancel(true); + Toast.makeText(context,R.string.canceled,Toast.LENGTH_SHORT).show(); } }); @@ -108,7 +110,7 @@ public abstract class ServerAsyncTask extends AsyncTask<Void, Void, Void> final Builder builder = new AlertDialog.Builder(this.context); alertDialog = builder.setCancelable(true).create(); - alertDialog.setIcon(android.R.drawable.ic_menu_close_clear_cancel); + alertDialog.setIcon(android.R.drawable.ic_menu_info_details); alertDialog.setMessage(context.getText(error.getErrorResId())); alertDialog.show(); @@ -142,7 +144,7 @@ public abstract class ServerAsyncTask extends AsyncTask<Void, Void, Void> Log.w(this.getClass().getName(), e.getMessage(), e); final int resId; - + if (e instanceof SocketTimeoutException) resId = R.string.error_timeout; else @@ -153,7 +155,8 @@ public abstract class ServerAsyncTask extends AsyncTask<Void, Void, Void> catch (TapatalkException e) { Log.w(this.getClass().getName(), e.getMessage(), e); - error = new IBCException(R.string.error_tapatalk, e.getMessage(), e); + error = new IBCException(Utils.getResId(e.getErrorCode()), e + .getMessage(), e); } catch (IBCException e) { diff --git a/src/de/mtbnews/android/util/Utils.java b/src/de/mtbnews/android/util/Utils.java @@ -0,0 +1,47 @@ +/** + * + */ +package de.mtbnews.android.util; + +import de.mtbnews.android.R; +import de.mtbnews.android.tapatalk.TapatalkClient; +import de.mtbnews.android.tapatalk.TapatalkException.TapatalkErrorCode; + +/** + * @author dankert + * + */ +public final class Utils +{ + + public static final int getResId(TapatalkErrorCode errorCode) + { + switch (errorCode) + { + case LOGIN_FAILED: + return R.string.login_failed; + case NO_USERNAME: + return R.string.nousername; + case SEND_MESSAGE_FAILED: + return R.string.sent_fail; + case XMLRPC_ERROR: + return R.string.xmlrpc_error; + case UNKNOWN_SERVER_RESPONSE: + default: + return R.string.error_common_server; + } + } + + /** + * Stellt fest, ob das Login abgelaufen ist. Dies ist der Fall, wenn + * Benutzer nicht angemeldet ist oder das letzte Login zu alt ist. + * + * @param client + * @return + */ + public static final boolean loginExceeded(TapatalkClient client) + { + return !client.loggedIn + || System.currentTimeMillis() - client.loginTime > IBC.LOGIN_TIMEOUT * 60 * 1000; + } +}