diff --git a/src/com/annimon/client/fragments/MailFragment.java b/src/com/annimon/client/fragments/MailFragment.java index 3ef84fb..55d4352 100644 --- a/src/com/annimon/client/fragments/MailFragment.java +++ b/src/com/annimon/client/fragments/MailFragment.java @@ -2,7 +2,6 @@ package com.annimon.client.fragments; import android.app.ListFragment; import android.os.Bundle; -import android.widget.ArrayAdapter; import com.annimon.client.utils.MoreListHelper; diff --git a/src/com/annimon/client/utils/ExceptionHandler.java b/src/com/annimon/client/utils/ExceptionHandler.java new file mode 100644 index 0000000..f63273c --- /dev/null +++ b/src/com/annimon/client/utils/ExceptionHandler.java @@ -0,0 +1,54 @@ +package com.annimon.client.utils; + +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.util.Log; + +/** + * Handling exceptions. + * If error is critical or must be show to user, then + * call alert method. + * In other situations call log method. + * + * @author aNNiMON + */ +public class ExceptionHandler { + + private static final boolean DEBUG = false; + private static final String TAG = "anmclient::ExceptionHandler"; + + public static void alert(Context context, Exception ex) { + alert(context, getErrorMessage(ex)); + } + + public static void alert(Context context, int resourceId) { + alert(context, context.getString(resourceId)); + } + + public static void alert(Context context, String message) { + new AlertDialog.Builder(context) + .setIcon(android.R.drawable.ic_dialog_alert) + .setTitle(android.R.string.dialog_alert_title) + .setMessage(message) + .setPositiveButton(android.R.string.ok, + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + + }).show(); + } + + public static void log(Exception ex) { + if (DEBUG) { + Log.e(TAG, getErrorMessage(ex)); + } + } + + private static String getErrorMessage(Exception ex) { + return ex.getMessage(); + } +} diff --git a/src/com/annimon/client/utils/MoreListHelper.java b/src/com/annimon/client/utils/MoreListHelper.java index 570f8a5..106e7d3 100644 --- a/src/com/annimon/client/utils/MoreListHelper.java +++ b/src/com/annimon/client/utils/MoreListHelper.java @@ -10,7 +10,7 @@ import android.widget.TextView; import java.util.ArrayList; /** - * Вспомагательный класс для создания подгружаемых списков. + * . * * @author aNNiMON */ @@ -34,7 +34,7 @@ public abstract class MoreListHelper { this.activity = activity; if (footerView == null) { - // Создаём footer по умочанию. + // footer . footerView = new TextView(activity); ((TextView) footerView).setText("Loading..."); } @@ -47,8 +47,8 @@ public abstract class MoreListHelper { } /** - * Создаёт новый адаптер из ресурса разметки. - * @param layoutResource ресурс разметки + * . + * @param layoutResource */ public void createAdapter(int layoutResource) { adapter = new ArrayAdapter(activity, layoutResource, items); @@ -63,9 +63,9 @@ public abstract class MoreListHelper { } /** - * Задаёт количество элементов на страницу. - * Используется при загрузке новых элементов для ограничения загружаемых данных. - * @param value количество элементов + * . + * . + * @param value */ public void setItemsPerPage(int value) { itemsPerPage = value; @@ -91,10 +91,10 @@ public abstract class MoreListHelper { }; /** - * Метод загрузки новых элементов списка. - * Выполняется в отдельном треде. - * @param items список для заполнения - * @param itemsPerPage количество элементов на страницу (по умолчанию 10) + * . + * . + * @param items + * @param itemsPerPage ( 10) */ public abstract void onLoadItems(ArrayList items, int itemsPerPage); @@ -103,9 +103,9 @@ public abstract class MoreListHelper { public void run() { loadingMore = true; items = new ArrayList(); - // Загружаем данные. + // . onLoadItems(items, itemsPerPage); - // Обновляем список и адаптер. + // . activity.runOnUiThread(updateAdapterRunnable); } };