Commit 5c640418 by Kazuyuki Hida

非同期通信を実装

parent 7371d7a2
......@@ -90,26 +90,35 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity {
* @param loginId
*/
protected void showMainActivity(String loginId) {
AgreementToTermsActivity.PreAgreementListener listener = new AgreementToTermsActivity.PreAgreementListener() {
@Override
public void onDisabled() {
onAgreed();
}
AgreementToTermsActivity.Result confirmResult = AgreementToTermsActivity.confirmAgreement(this, REQUEST_AGREEMENT_FROM_LOGIN, isNormalSize(), new Runnable() {
@Override
public void run() {
LogoutHelper.logout(ABVNoAuthenticatedActivity.this);
public void onEmpty() {
onAgreed();
}
});
switch (confirmResult) {
case DISABLE:
case EMPTY:
case AGREED:
// 規約同意画面が開かれなかったら、改めて初期化
@Override
public void onAgreed() {
// 規約同意画面が開かれなかったら、次に進む
doShowMainActivity();
break;
case FAILED:
break;
case CONFIRM:
// onActivityResultを待つ
break;
}
}
@Override
public void onFailed(Exception e) {
// 読み込みに失敗したらログアウト
AlertDialogUtil.showAlertDialog(ABVNoAuthenticatedActivity.this, R.string.app_name, R.string.failed_to_get_terms_of_service, true, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
LogoutHelper.logout(ABVNoAuthenticatedActivity.this);
}
});
}
};
AgreementToTermsActivity.confirmAgreement(this, REQUEST_AGREEMENT_FROM_LOGIN, isNormalSize(), listener);
}
protected void doShowMainActivity() {
......@@ -408,22 +417,31 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity {
}
// 必要に応じて、規約同意画面を表示
AgreementToTermsActivity.clearVersion(this); // for debug!
AgreementToTermsActivity.Result confirmResult = AgreementToTermsActivity.confirmAgreement(this, REQUEST_AGREEMENT, isNormalSize(), null);
switch (confirmResult) {
case DISABLE:
case EMPTY:
case AGREED:
// 規約同意画面が開かれなかったら、改めて初期化
AgreementToTermsActivity.PreAgreementListener listener = new AgreementToTermsActivity.PreAgreementListener() {
@Override
public void onDisabled() {
onAgreed();
}
@Override
public void onEmpty() {
onAgreed();
}
@Override
public void onAgreed() {
// 規約同意画面が開かれなかったら、次に進む
doMoveToHome();
break;
case FAILED:
confirmResult = AgreementToTermsActivity.Result.AGREED;
}
@Override
public void onFailed(Exception e) {
// 読み込みに失敗しても、次に進む
Logger.e(TAG, e);
doMoveToHome();
break;
case CONFIRM:
// onActivityResultを待つ
break;
}
}
};
AgreementToTermsActivity.confirmAgreement(this, REQUEST_AGREEMENT, isNormalSize(), listener);
}
@Override
......
......@@ -29,12 +29,11 @@ public class AgreementToTermsActivity extends ABVUIActivity {
private static final String TAG = "AgreementToTermsActivity";
private String currentVersion = "";
public enum Result {
DISABLE, // 規約同意オプションが無効だった
EMPTY, // 規約情報が空だった
AGREED, // 同意済みだった
FAILED, // 規約情報の読み込みに失敗した
CONFIRM // 規約同意画面を表示した
public interface PreAgreementListener {
void onDisabled();
void onEmpty();
void onAgreed();
void onFailed(Exception e);
}
@Override
......@@ -148,41 +147,45 @@ public class AgreementToTermsActivity extends ABVUIActivity {
* @param context 呼び出し元アクティビティ
* @param requestCode startActivityForResultで使用するリクエスト・コード
* @param isNormalSize 端末サイズ指定(スマホならtrue)
* @param onFailed 規約情報の取得に失敗したときの処理
* @param listener 規約同意画面を表示する前に結果が出た時の動作を指定するリスナー
*/
public static Result confirmAgreement(final ABVActivity context, int requestCode, boolean isNormalSize, @Nullable final Runnable onFailed) {
public static void confirmAgreement(final ABVActivity context, final int requestCode, final boolean isNormalSize, final PreAgreementListener listener) {
if (! ABVDataCache.getInstance().serviceOption.isUsableAgreementToTerms()) {
// 規約同意オプションが無効な場合、何もしない
return Result.DISABLE;
listener.onDisabled();
return;
}
try {
context.showProgressPopup();
AgreementToTermsLogic logic = AbstractLogic.getLogic(AgreementToTermsLogic.class);
AgreementToTermsJSON json = logic.getTerms();
if (json.getTerms().isEmpty() || json.getTermsVersion().isEmpty()) {
// 規約内容やバージョンが空の場合は何もしない
return Result.EMPTY;
}
if (getLatestVersion(context).equals(json.getTermsVersion())) {
// 規約のバージョンが、すでに同意しているものと同じときは何もしない
return Result.AGREED;
}
// ダイアログ表示
Intent intent = new Intent(context, isNormalSize ? AgreementToTermsActivity.class : AgreementToTermsActivityDialog.class);
intent.putExtra(ABookKeys.AGREEMENT_TO_TERMS_VERSION, json.getTermsVersion());
intent.putExtra(ABookKeys.AGREEMENT_TO_TERMS, json.getTerms());
context.startActivityForResult(intent, requestCode);
return Result.CONFIRM;
} catch (Exception e) {
Logger.e(TAG, e);
if (onFailed != null) {
failed(context, onFailed);
context.showProgressPopup();
CommonExecutor.execute(new Runnable() {
@Override
public void run() {
try {
AgreementToTermsLogic logic = AbstractLogic.getLogic(AgreementToTermsLogic.class);
AgreementToTermsJSON json = logic.getTerms();
if (json.getTerms().isEmpty() || json.getTermsVersion().isEmpty()) {
// 規約内容やバージョンが空の場合は何もしない
listener.onEmpty();
return;
}
if (getLatestVersion(context).equals(json.getTermsVersion())) {
// 規約のバージョンが、すでに同意しているものと同じときは何もしない
listener.onAgreed();
return;
}
// ダイアログ表示
Intent intent = new Intent(context, isNormalSize ? AgreementToTermsActivity.class : AgreementToTermsActivityDialog.class);
intent.putExtra(ABookKeys.AGREEMENT_TO_TERMS_VERSION, json.getTermsVersion());
intent.putExtra(ABookKeys.AGREEMENT_TO_TERMS, json.getTerms());
context.startActivityForResult(intent, requestCode);
} catch (Exception e) {
Logger.e(TAG, e);
listener.onFailed(e);
} finally {
context.closeProgressPopup();
}
}
return Result.FAILED;
} finally {
context.closeProgressPopup();
}
});
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment