Added I/O try-catch and toasts
This commit is contained in:
@@ -237,10 +237,15 @@ public class MainActivity extends AppCompatActivity {
|
||||
if (mOpen5eImportDisposable != null && mOpen5eImportDisposable.isDisposed()) {
|
||||
break;
|
||||
}
|
||||
try {
|
||||
((MonsterCardsApplication) getApplication()).getMonsterRepository()
|
||||
.saveMonster(monster)
|
||||
.blockingAwait();
|
||||
totalImported++;
|
||||
} catch (Exception e) {
|
||||
Logger.logError("Failed to save monster to database", e);
|
||||
runOnUiThread(() -> ToastHelper.showShort(MainActivity.this, "An error occurred while saving a monster."));
|
||||
}
|
||||
}
|
||||
nextUrl = page.nextUrl;
|
||||
} while (nextUrl != null && !nextUrl.isEmpty());
|
||||
@@ -422,6 +427,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Logger.logError("error reading file", e);
|
||||
ToastHelper.showLong(this, "An error occurred while reading the file.");
|
||||
return null;
|
||||
}
|
||||
return builder.toString();
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.majinnaibu.monstercards.importers.Open5eImporter;
|
||||
import com.majinnaibu.monstercards.models.Monster;
|
||||
import com.majinnaibu.monstercards.utils.Logger;
|
||||
import com.majinnaibu.monstercards.utils.SnackbarHelper;
|
||||
import com.majinnaibu.monstercards.utils.ToastHelper;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
@@ -212,6 +213,10 @@ public class MCFragment extends Fragment {
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.logError("Error reading URI contents for import", e);
|
||||
Context ctx = getContext();
|
||||
if (ctx != null) {
|
||||
ToastHelper.showLong(ctx, "An error occurred while reading the file.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return builder.toString();
|
||||
|
||||
Reference in New Issue
Block a user