Merge branch 'master' into 'master'
Make progressbar in notification determinate See merge request !175
This commit is contained in:
commit
72b3bda941
@ -179,10 +179,10 @@ public class RepoPersister {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
while (i < operations.size()) {
|
while (i < operations.size()) {
|
||||||
int count = Math.min(operations.size() - i, 100);
|
int count = Math.min(operations.size() - i, 100);
|
||||||
|
int progress = (int) ((double) (currentCount + i) / totalUpdateCount * 100);
|
||||||
ArrayList<ContentProviderOperation> o = new ArrayList<>(operations.subList(i, i + count));
|
ArrayList<ContentProviderOperation> o = new ArrayList<>(operations.subList(i, i + count));
|
||||||
UpdateService.sendStatus(context, UpdateService.STATUS_INFO, context.getString(
|
UpdateService.sendStatus(context, UpdateService.STATUS_INFO, context.getString(
|
||||||
R.string.status_inserting,
|
R.string.status_inserting, progress), progress);
|
||||||
(int) ((double) (currentCount + i) / totalUpdateCount * 100)));
|
|
||||||
context.getContentResolver().applyBatch(providerAuthority, o);
|
context.getContentResolver().applyBatch(providerAuthority, o);
|
||||||
i += 100;
|
i += 100;
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,7 @@ public class UpdateService extends IntentService implements ProgressListener {
|
|||||||
public static final String EXTRA_STATUS_CODE = "status";
|
public static final String EXTRA_STATUS_CODE = "status";
|
||||||
public static final String EXTRA_ADDRESS = "address";
|
public static final String EXTRA_ADDRESS = "address";
|
||||||
public static final String EXTRA_MANUAL_UPDATE = "manualUpdate";
|
public static final String EXTRA_MANUAL_UPDATE = "manualUpdate";
|
||||||
|
public static final String EXTRA_PROGRESS = "progress";
|
||||||
|
|
||||||
public static final int STATUS_COMPLETE_WITH_CHANGES = 0;
|
public static final int STATUS_COMPLETE_WITH_CHANGES = 0;
|
||||||
public static final int STATUS_COMPLETE_AND_SAME = 1;
|
public static final int STATUS_COMPLETE_AND_SAME = 1;
|
||||||
@ -157,14 +158,19 @@ public class UpdateService extends IntentService implements ProgressListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static void sendStatus(Context context, int statusCode) {
|
protected static void sendStatus(Context context, int statusCode) {
|
||||||
sendStatus(context, statusCode, null);
|
sendStatus(context, statusCode, null, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void sendStatus(Context context, int statusCode, String message) {
|
protected static void sendStatus(Context context, int statusCode, String message) {
|
||||||
|
sendStatus(context, statusCode, message, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static void sendStatus(Context context, int statusCode, String message, int progress) {
|
||||||
Intent intent = new Intent(LOCAL_ACTION_STATUS);
|
Intent intent = new Intent(LOCAL_ACTION_STATUS);
|
||||||
intent.putExtra(EXTRA_STATUS_CODE, statusCode);
|
intent.putExtra(EXTRA_STATUS_CODE, statusCode);
|
||||||
if (!TextUtils.isEmpty(message))
|
if (!TextUtils.isEmpty(message))
|
||||||
intent.putExtra(EXTRA_MESSAGE, message);
|
intent.putExtra(EXTRA_MESSAGE, message);
|
||||||
|
intent.putExtra(EXTRA_PROGRESS, progress);
|
||||||
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
|
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,11 +199,12 @@ public class UpdateService extends IntentService implements ProgressListener {
|
|||||||
String message;
|
String message;
|
||||||
if (totalSize == -1) {
|
if (totalSize == -1) {
|
||||||
message = getString(R.string.status_download_unknown_size, repoAddress, downloadedSizeFriendly);
|
message = getString(R.string.status_download_unknown_size, repoAddress, downloadedSizeFriendly);
|
||||||
|
percent = -1;
|
||||||
} else {
|
} else {
|
||||||
String totalSizeFriendly = Utils.getFriendlySize(totalSize);
|
String totalSizeFriendly = Utils.getFriendlySize(totalSize);
|
||||||
message = getString(R.string.status_download, repoAddress, downloadedSizeFriendly, totalSizeFriendly, percent);
|
message = getString(R.string.status_download, repoAddress, downloadedSizeFriendly, totalSizeFriendly, percent);
|
||||||
}
|
}
|
||||||
sendStatus(context, STATUS_INFO, message);
|
sendStatus(context, STATUS_INFO, message, percent);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -216,13 +223,16 @@ public class UpdateService extends IntentService implements ProgressListener {
|
|||||||
|
|
||||||
final String message = intent.getStringExtra(EXTRA_MESSAGE);
|
final String message = intent.getStringExtra(EXTRA_MESSAGE);
|
||||||
int resultCode = intent.getIntExtra(EXTRA_STATUS_CODE, -1);
|
int resultCode = intent.getIntExtra(EXTRA_STATUS_CODE, -1);
|
||||||
|
int progress = intent.getIntExtra(EXTRA_PROGRESS, -1);
|
||||||
|
|
||||||
String text;
|
String text;
|
||||||
switch (resultCode) {
|
switch (resultCode) {
|
||||||
case STATUS_INFO:
|
case STATUS_INFO:
|
||||||
notificationBuilder.setContentText(message)
|
notificationBuilder.setContentText(message)
|
||||||
.setProgress(0, 0, true)
|
|
||||||
.setCategory(NotificationCompat.CATEGORY_SERVICE);
|
.setCategory(NotificationCompat.CATEGORY_SERVICE);
|
||||||
|
if (progress != -1) {
|
||||||
|
notificationBuilder.setProgress(100, progress, false);
|
||||||
|
}
|
||||||
notificationManager.notify(NOTIFY_ID_UPDATING, notificationBuilder.build());
|
notificationManager.notify(NOTIFY_ID_UPDATING, notificationBuilder.build());
|
||||||
break;
|
break;
|
||||||
case STATUS_ERROR_GLOBAL:
|
case STATUS_ERROR_GLOBAL:
|
||||||
@ -510,6 +520,6 @@ public class UpdateService extends IntentService implements ProgressListener {
|
|||||||
message = getString(R.string.status_processing_xml_percent, repoAddress, downloadedSize, totalSize, percent);
|
message = getString(R.string.status_processing_xml_percent, repoAddress, downloadedSize, totalSize, percent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sendStatus(this, STATUS_INFO, message);
|
sendStatus(this, STATUS_INFO, message, percent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user