Skip to content

Commit

Permalink
retry on downloading error
Browse files Browse the repository at this point in the history
  • Loading branch information
miku-nyan committed May 22, 2016
1 parent 6912ecb commit 4e1ad3b
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 22 deletions.
19 changes: 16 additions & 3 deletions res/layout/downloading_error_report_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
android:id="@+id/downloading_error_report_view" />
</ScrollView>

<Button
android:id="@+id/downloading_error_report_ok_btn"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@android:string/ok" />
android:orientation="horizontal"
android:weightSum="2" >
<Button
android:id="@+id/downloading_error_report_retry_btn"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@string/downloading_error_report_retry" />
<Button
android:id="@+id/downloading_error_report_ok_btn"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="@android:string/ok" />
</LinearLayout>

</LinearLayout>
1 change: 1 addition & 0 deletions res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<string name="downloading_error_ticker">Einige Dateien werden nicht geladen</string>
<string name="downloading_error_title">Fehler beim Herunterladen</string>
<string name="downloading_error_report_title">Die folgenden Dateien wurden nicht heruntergeladen:</string>
<string name="downloading_error_report_retry">Wiederholen</string>
<string name="downloading_title">Herunterladen (%d verbleibend)</string>
<string name="downloading_title_simple">Herunterladen</string>
<string name="downloading_error_mkdir">Das Verzeichnis kann nicht erstellt werden</string>
Expand Down
1 change: 1 addition & 0 deletions res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<string name="downloading_error_ticker">Некоторые файлы не загружены</string>
<string name="downloading_error_title">Ошибка при загрузке</string>
<string name="downloading_error_report_title">Следующие файлы не были загружены:</string>
<string name="downloading_error_report_retry">Повторить</string>
<string name="downloading_title">Загрузка (%d осталось)</string>
<string name="downloading_title_simple">Загрузка</string>
<string name="downloading_error_mkdir">Невозможно создать директорию</string>
Expand Down
1 change: 1 addition & 0 deletions res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<string name="downloading_error_ticker">Не всі файли звантажені</string>
<string name="downloading_error_title">Помилка звантаження</string>
<string name="downloading_error_report_title">Не вдалося звантажити файли:</string>
<string name="downloading_error_report_retry">Повторити</string>
<string name="downloading_title">Звантаження (ще %d)</string>
<string name="downloading_title_simple">Звантаження</string>
<string name="downloading_error_mkdir">Помилка створення теки</string>
Expand Down
1 change: 1 addition & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<string name="downloading_error_ticker">Some files are not loaded</string>
<string name="downloading_error_title">Error while downloading</string>
<string name="downloading_error_report_title">The following files have not been downloaded.</string>
<string name="downloading_error_report_retry">Retry</string>
<string name="downloading_title">Downloading (%d remaining)</string>
<string name="downloading_title_simple">Downloading</string>
<string name="downloading_error_mkdir">Cannot create the directory</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,28 @@
package nya.miku.wishmaster.ui.downloading;

import nya.miku.wishmaster.R;
import nya.miku.wishmaster.common.Async;
import nya.miku.wishmaster.common.Logger;
import nya.miku.wishmaster.common.MainApplication;

import java.util.List;

import android.app.Activity;
import android.app.NotificationManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

public class DownloadingErrorReportActivity extends Activity implements View.OnClickListener {
private static final String TAG = "DownloadingErrorReportActivity";

private TextView textView;
private NotificationManager notificationManager;
private String errorItemsData;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -39,6 +50,7 @@ protected void onCreate(Bundle savedInstanceState) {
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
textView = (TextView) findViewById(R.id.downloading_error_report_view);
findViewById(R.id.downloading_error_report_ok_btn).setOnClickListener(this);
findViewById(R.id.downloading_error_report_retry_btn).setOnClickListener(this);
notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
updateErrorInfo();
}
Expand All @@ -50,14 +62,38 @@ protected void onNewIntent(Intent intent) {
}

private void updateErrorInfo() {
String report = getSharedPreferences(DownloadingService.SHARED_PREFERENCES_NAME, MODE_PRIVATE).
getString(DownloadingService.PREF_ERROR_REPORT, "");
SharedPreferences prefs = getSharedPreferences(DownloadingService.SHARED_PREFERENCES_NAME, MODE_PRIVATE);
String report = prefs.getString(DownloadingService.PREF_ERROR_REPORT, "");
textView.setText(report);
notificationManager.cancel(DownloadingService.ERROR_REPORT_NOTIFICATION_ID);
errorItemsData = prefs.getString(DownloadingService.PREF_ERROR_ITEMS, null);
}

@Override
public void onClick(View v) {
if (v.getId() == R.id.downloading_error_report_retry_btn) Async.runAsync(new Runnable() {
@Override
public void run() {
try {
List<DownloadingService.DownloadingQueueItem> items = DownloadingService.deserializeErrorItems(errorItemsData);
for (DownloadingService.DownloadingQueueItem item : items) {
if (!DownloadingService.isInQueue(item)) {
Intent downloadIntent = new Intent(DownloadingErrorReportActivity.this, DownloadingService.class);
downloadIntent.putExtra(DownloadingService.EXTRA_DOWNLOADING_ITEM, item);
startService(downloadIntent);
}
}
} catch (Exception e) {
Logger.e(TAG, e);
Async.runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainApplication.getInstance(), R.string.error_unknown, Toast.LENGTH_LONG).show();
}
});
}
}
});
finish();
}
}
Loading

0 comments on commit 4e1ad3b

Please sign in to comment.