1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 19:42:17 +02:00

Ongoing Notifications for catalogs loading and network search have been removed

git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@1388 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
Vasiliy Bout 2010-05-12 22:00:35 +00:00
parent 6a3ae4f261
commit 0dfa832205
6 changed files with 12 additions and 107 deletions

View file

@ -30,7 +30,7 @@ DONE Network library: Объединять книги по сериям
DONE для "поплнение счета" DONE для "поплнение счета"
DONE делать signIn при попытке открыть эти пункты DONE делать signIn при попытке открыть эти пункты
DONE сделать анимированный Title при загрузке DONE сделать анимированный Title при загрузке
* убрать Notification при загрузке каталогов / при поиске DONE убрать Notification при загрузке каталогов / при поиске
DONE вызывать invalidateChildren, если добавились новые элементы для AuthorTree и SeriesTree DONE вызывать invalidateChildren, если добавились новые элементы для AuthorTree и SeriesTree
** при загрузке каталогов проверка аутентификации осуществляется в UI-ном потоке ** при загрузке каталогов проверка аутентификации осуществляется в UI-ном потоке
** 3 иконки в верхнем-правом углу для книжек ** 3 иконки в верхнем-правом углу для книжек

View file

@ -28,11 +28,6 @@ import org.geometerplus.fbreader.network.NetworkLibraryItem;
abstract class ItemsLoadingRunnable implements Runnable { abstract class ItemsLoadingRunnable implements Runnable {
public static final int CATALOG_LOADING = 0;
public static final int NETWORK_SEARCH = 1;
public final int Type;
private final ItemsLoadingHandler myHandler; private final ItemsLoadingHandler myHandler;
private final long myUpdateInterval; // in milliseconds private final long myUpdateInterval; // in milliseconds
@ -42,7 +37,6 @@ abstract class ItemsLoadingRunnable implements Runnable {
private boolean myInterruptConfirmed; private boolean myInterruptConfirmed;
private Object myInterruptLock = new Object(); private Object myInterruptLock = new Object();
private boolean myFinished; private boolean myFinished;
private Handler myFinishedHandler; private Handler myFinishedHandler;
private Object myFinishedLock = new Object(); private Object myFinishedLock = new Object();
@ -79,21 +73,19 @@ abstract class ItemsLoadingRunnable implements Runnable {
} }
public ItemsLoadingRunnable(ItemsLoadingHandler handler, int type) { public ItemsLoadingRunnable(ItemsLoadingHandler handler) {
this(handler, type, 1000, 500); this(handler, 1000, 500);
} }
public ItemsLoadingRunnable(ItemsLoadingHandler handler, int type, long updateIntervalMillis, int itemsLimit) { public ItemsLoadingRunnable(ItemsLoadingHandler handler, long updateIntervalMillis, int itemsLimit) {
myHandler = handler; myHandler = handler;
myUpdateInterval = updateIntervalMillis; myUpdateInterval = updateIntervalMillis;
myItemsLimit = itemsLimit; myItemsLimit = itemsLimit;
Type = type;
} }
public abstract String doBefore(); public abstract String doBefore();
public abstract String doLoading(NetworkOperationData.OnNewItemListener doWithListener); public abstract String doLoading(NetworkOperationData.OnNewItemListener doWithListener);
public abstract int getNotificationId();
public abstract String getResourceKey(); public abstract String getResourceKey();

View file

@ -57,83 +57,6 @@ public class ItemsLoadingService extends Service {
} }
private HashMap<Integer, Integer> myRunnablesNumbers = new HashMap<Integer, Integer>(0, 0.9f);
private int getRunnablesNumber(int runnableType) {
Integer value = myRunnablesNumbers.get(runnableType);
if (value == null) {
return 0;
}
return value.intValue();
}
private int increaseRunnablesNumber(int runnableType) {
final Integer value = myRunnablesNumbers.get(runnableType);
final int val = (value == null) ? 1 : (value.intValue() + 1);
myRunnablesNumbers.put(runnableType, Integer.valueOf(val));
return val;
}
private int decreaseRunnablesNumber(int runnableType) {
final Integer value = myRunnablesNumbers.get(runnableType);
final int val = (value == null) ? 0 : (value.intValue() - 1);
if (val == 0) {
myRunnablesNumbers.remove(runnableType);
} else {
myRunnablesNumbers.put(runnableType, Integer.valueOf(val));
}
return val;
}
private void updateProgressNotification(ItemsLoadingRunnable runnable) {
final RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.download_notification);
String title = ZLResource.resource("networkView").getResource(runnable.getResourceKey()).getValue();
contentView.setTextViewText(R.id.download_notification_title, title);
contentView.setTextViewText(R.id.download_notification_progress_text, "");
contentView.setProgressBar(R.id.download_notification_progress_bar, 100, 0, true);
final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
final Notification notification = new Notification();
notification.icon = android.R.drawable.stat_notify_sync;
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.contentView = contentView;
notification.contentIntent = contentIntent;
notification.number = getRunnablesNumber(runnable.Type);
final NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(runnable.getNotificationId(), notification);
}
private void startProgressNotification(ItemsLoadingRunnable runnable) {
increaseRunnablesNumber(runnable.Type);
updateProgressNotification(runnable);
}
private void endProgressNotification(ItemsLoadingRunnable runnable) {
final int number = decreaseRunnablesNumber(runnable.Type);
if (number == 0) {
final NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(runnable.getNotificationId());
} else {
updateProgressNotification(runnable);
}
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onDestroy() {
final NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
final NetworkNotifications notifications = NetworkNotifications.Instance();
notificationManager.cancel(notifications.getCatalogLoadingId());
notificationManager.cancel(notifications.getNetworkSearchId());
super.onDestroy();
}
@Override @Override
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
return null; return null;
@ -164,7 +87,6 @@ public class ItemsLoadingService extends Service {
final Handler finishHandler = new Handler() { final Handler finishHandler = new Handler() {
public void handleMessage(Message message) { public void handleMessage(Message message) {
doStop(); doStop();
endProgressNotification(runnable);
if (NetworkView.Instance().isInitialized()) { if (NetworkView.Instance().isInitialized()) {
NetworkView.Instance().removeItemsLoadingRunnable(key); NetworkView.Instance().removeItemsLoadingRunnable(key);
NetworkView.Instance().fireModelChanged(); NetworkView.Instance().fireModelChanged();
@ -172,7 +94,6 @@ public class ItemsLoadingService extends Service {
} }
}; };
startProgressNotification(runnable);
NetworkView.Instance().fireModelChanged(); // this call is needed to show indeterminate progress bar in title right on downloading start NetworkView.Instance().fireModelChanged(); // this call is needed to show indeterminate progress bar in title right on downloading start
final Thread loader = new Thread(new Runnable() { final Thread loader = new Thread(new Runnable() {

View file

@ -328,15 +328,11 @@ class NetworkCatalogActions extends NetworkTreeActions {
private final boolean myCheckAuthentication; private final boolean myCheckAuthentication;
public ExpandCatalogRunnable(ItemsLoadingHandler handler, NetworkCatalogTree tree, boolean checkAuthentication) { public ExpandCatalogRunnable(ItemsLoadingHandler handler, NetworkCatalogTree tree, boolean checkAuthentication) {
super(handler, CATALOG_LOADING); super(handler);
myTree = tree; myTree = tree;
myCheckAuthentication = checkAuthentication; myCheckAuthentication = checkAuthentication;
} }
public int getNotificationId() {
return NetworkNotifications.Instance().getCatalogLoadingId();
}
public String getResourceKey() { public String getResourceKey() {
return "downloadingCatalogs"; return "downloadingCatalogs";
} }

View file

@ -29,8 +29,8 @@ class NetworkNotifications {
return ourInstance; return ourInstance;
} }
private static final int CATALOG_LOADING = 0; //private static final int CATALOG_LOADING = 0;
private static final int NETWORK_SEARCH = 1; //private static final int NETWORK_SEARCH = 1;
private static final int BOOK_DOWNLOADING_START = 0x10000000; private static final int BOOK_DOWNLOADING_START = 0x10000000;
private static final int BOOK_DOWNLOADING_END = 0x1fffffff; private static final int BOOK_DOWNLOADING_END = 0x1fffffff;
@ -40,13 +40,13 @@ class NetworkNotifications {
private NetworkNotifications() { private NetworkNotifications() {
} }
public int getCatalogLoadingId() { /*public int getCatalogLoadingId() {
return CATALOG_LOADING; return CATALOG_LOADING;
} }*/
public int getNetworkSearchId() { /*public int getNetworkSearchId() {
return NETWORK_SEARCH; return NETWORK_SEARCH;
} }*/
public synchronized int getBookDownloadingId() { public synchronized int getBookDownloadingId() {
final int id = myBookDownloadingId; final int id = myBookDownloadingId;

View file

@ -126,14 +126,10 @@ public class NetworkSearchActivity extends Activity {
private final String myPattern; private final String myPattern;
public SearchRunnable(ItemsLoadingHandler handler, String pattern) { public SearchRunnable(ItemsLoadingHandler handler, String pattern) {
super(handler, NETWORK_SEARCH); super(handler);
myPattern = pattern; myPattern = pattern;
} }
public int getNotificationId() {
return NetworkNotifications.Instance().getNetworkSearchId();
}
public String getResourceKey() { public String getResourceKey() {
return "searchingNetwork"; return "searchingNetwork";
} }