use of de.geeksfactory.opacclient.frontend.MultiStepResultHelper.StepTask in project opacclient by opacapp.
the class SearchResultDetailFragment method reservationPerform.
public void reservationPerform() {
MultiStepResultHelper<DetailedItem> msrhReservation = new MultiStepResultHelper<>(getActivity(), item, R.string.doing_res);
msrhReservation.setCallback(new Callback<DetailedItem>() {
@Override
public void onSuccess(MultiStepResult result) {
AccountDataSource adata = new AccountDataSource(getActivity());
adata.invalidateCachedAccountData(app.getAccount());
if (result.getMessage() != null) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(result.getMessage()).setCancelable(false).setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
}).setPositiveButton(R.string.account, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
Intent intent = new Intent(getActivity(), app.getMainActivity());
intent.putExtra(MainActivity.EXTRA_FRAGMENT, "account");
getActivity().startActivity(intent);
getActivity().finish();
}
});
AlertDialog alert = builder.create();
alert.show();
} else {
Intent intent = new Intent(getActivity(), app.getMainActivity());
intent.putExtra(MainActivity.EXTRA_FRAGMENT, "account");
getActivity().startActivity(intent);
getActivity().finish();
}
}
@Override
public void onError(MultiStepResult result) {
dialog_wrong_credentials(result.getMessage(), false);
}
@Override
public void onUnhandledResult(MultiStepResult result) {
}
@Override
public void onUserCancel() {
}
@Override
public StepTask<?> newTask(MultiStepResultHelper helper, int useraction, String selection, DetailedItem item) {
return new ResTask(helper, useraction, selection, item);
}
});
msrhReservation.start();
}
use of de.geeksfactory.opacclient.frontend.MultiStepResultHelper.StepTask in project opacclient by opacapp.
the class AccountFragment method download.
public void download(final String a) {
MultiStepResultHelper<String> msrhDownload = new MultiStepResultHelper<>(getActivity(), a, R.string.doing_download);
msrhDownload.setCallback(new Callback<String>() {
@Override
public void onSuccess(MultiStepResult res) {
final EbookServiceApi.DownloadResult result = (EbookServiceApi.DownloadResult) res;
if (result.getUrl() != null) {
if (result.getUrl().contains("acsm") || (a.contains("overdrive") && !result.getUrl().contains("epub-sample") && (result.getUrl().contains(".odm") || result.getUrl().contains(".epub")))) {
String[] download_clients = new String[] { "com.android.aldiko", "com.aldiko.android", "com.bluefirereader", "com.mantano.reader.android.lite", "com.overdrive.mobile.android.mediaconsole", "com.datalogics.dlreader", "com.mantano.reader.android.normal", "com.mantano.reader.android", "com.neosoar" };
if (a.contains("overdrive") && result.getUrl().contains(".odm")) {
download_clients = new String[] { "com.overdrive.mobile.android.mediaconsole" };
}
boolean found = false;
PackageManager pm = getActivity().getPackageManager();
for (String id : download_clients) {
try {
pm.getPackageInfo(id, 0);
found = true;
} catch (NameNotFoundException e) {
}
}
final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
if (!found && !sp.contains("reader_needed_ignore")) {
int msg = R.string.reader_needed;
if (a.contains("overdrive")) {
msg = R.string.reader_needed_overdrive;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(msg).setCancelable(true).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
}).setNeutralButton(R.string.reader_needed_ignore, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(result.getUrl()));
sp.edit().putBoolean("reader_needed_ignore", true).apply();
startActivity(i);
}
}).setPositiveButton(R.string.download, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
String reader = "com.bluefirereader";
if (a.toLowerCase().contains("overdrive")) {
reader = "com.overdrive.mobile.android.mediaconsole";
}
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + reader));
startActivity(i);
}
});
AlertDialog alert = builder.create();
alert.show();
return;
}
}
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(result.getUrl()));
startActivity(i);
}
}
@Override
public void onError(MultiStepResult result) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(result.getMessage()).setCancelable(true).setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int id) {
d.cancel();
}
}).setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface d) {
if (d != null) {
d.cancel();
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
@Override
public void onUnhandledResult(MultiStepResult result) {
}
@Override
public void onUserCancel() {
}
@Override
public StepTask<?> newTask(MultiStepResultHelper helper, int useraction, String selection, String argument) {
return dt = new DownloadTask(helper, useraction, selection, argument);
}
});
msrhDownload.start();
}
use of de.geeksfactory.opacclient.frontend.MultiStepResultHelper.StepTask in project opacclient by opacapp.
the class AccountFragment method bookingStart.
public void bookingStart(String booking_info) {
long age = System.currentTimeMillis() - refreshtime;
if (refreshing || fromcache || age > MAX_CACHE_AGE) {
Toast.makeText(getActivity(), R.string.account_no_concurrent, Toast.LENGTH_LONG).show();
if (!refreshing) {
refresh();
}
return;
}
DetailedItem item = new DetailedItem();
item.setBookable(true);
item.setBooking_info(booking_info);
MultiStepResultHelper<DetailedItem> msrhBooking = new MultiStepResultHelper<>(getActivity(), item, R.string.doing_booking);
msrhBooking.setCallback(new Callback<DetailedItem>() {
@Override
public void onSuccess(MultiStepResult result) {
invalidateData();
}
@Override
public void onError(MultiStepResult result) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(result.getMessage()).setCancelable(true).setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int id) {
d.cancel();
}
}).setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface d) {
if (d != null) {
d.cancel();
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
@Override
public void onUnhandledResult(MultiStepResult result) {
}
@Override
public void onUserCancel() {
}
@Override
public StepTask<?> newTask(MultiStepResultHelper helper, int useraction, String selection, DetailedItem argument) {
return new BookingTask(helper, useraction, selection, argument);
}
});
msrhBooking.start();
}
use of de.geeksfactory.opacclient.frontend.MultiStepResultHelper.StepTask in project opacclient by opacapp.
the class AccountFragment method cancel.
public void cancel(final String a) {
long age = System.currentTimeMillis() - refreshtime;
if (refreshing || fromcache || age > MAX_CACHE_AGE) {
Toast.makeText(getActivity(), R.string.account_no_concurrent, Toast.LENGTH_LONG).show();
if (!refreshing) {
refresh();
}
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.cancel_confirm).setCancelable(true).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int id) {
d.cancel();
}
}).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int id) {
d.dismiss();
MultiStepResultHelper<String> msrhCancel = new MultiStepResultHelper<>(getActivity(), a, R.string.doing_cancel);
msrhCancel.setCallback(new Callback<String>() {
@Override
public void onSuccess(MultiStepResult result) {
invalidateData();
}
@Override
public void onError(MultiStepResult result) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(result.getMessage()).setCancelable(true).setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int id) {
d.cancel();
}
}).setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface d) {
if (d != null) {
d.cancel();
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
@Override
public void onUnhandledResult(MultiStepResult result) {
}
@Override
public void onUserCancel() {
}
@Override
public StepTask<?> newTask(MultiStepResultHelper helper, int useraction, String selection, String argument) {
return ct = new CancelTask(helper, useraction, selection, argument);
}
});
msrhCancel.start();
}
}).setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface d) {
if (d != null) {
d.cancel();
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
use of de.geeksfactory.opacclient.frontend.MultiStepResultHelper.StepTask in project opacclient by opacapp.
the class SearchResultDetailFragment method bookingDo.
public void bookingDo() {
MultiStepResultHelper<DetailedItem> msrhBooking = new MultiStepResultHelper<>(getActivity(), item, R.string.doing_booking);
msrhBooking.setCallback(new Callback<DetailedItem>() {
@Override
public void onSuccess(MultiStepResult result) {
if (getActivity() == null) {
return;
}
AccountDataSource adata = new AccountDataSource(getActivity());
adata.invalidateCachedAccountData(app.getAccount());
Intent intent = new Intent(getActivity(), app.getMainActivity());
intent.putExtra(MainActivity.EXTRA_FRAGMENT, "account");
getActivity().startActivity(intent);
getActivity().finish();
}
@Override
public void onError(MultiStepResult result) {
if (getActivity() == null) {
return;
}
dialog_wrong_credentials(result.getMessage(), false);
}
@Override
public void onUnhandledResult(MultiStepResult result) {
}
@Override
public void onUserCancel() {
}
@Override
public StepTask<?> newTask(MultiStepResultHelper helper, int useraction, String selection, DetailedItem item) {
return new BookingTask(helper, useraction, selection, item);
}
});
msrhBooking.start();
}
Aggregations