Commit 5c640418 by Kazuyuki Hida

非同期通信を実装

parent 7371d7a2
...@@ -90,26 +90,35 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity { ...@@ -90,26 +90,35 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity {
* @param loginId * @param loginId
*/ */
protected void showMainActivity(String 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 @Override
public void run() { public void onEmpty() {
LogoutHelper.logout(ABVNoAuthenticatedActivity.this); onAgreed();
} }
});
switch (confirmResult) { @Override
case DISABLE: public void onAgreed() {
case EMPTY: // 規約同意画面が開かれなかったら、次に進む
case AGREED:
// 規約同意画面が開かれなかったら、改めて初期化
doShowMainActivity(); doShowMainActivity();
break; }
case FAILED:
break; @Override
case CONFIRM: public void onFailed(Exception e) {
// onActivityResultを待つ // 読み込みに失敗したらログアウト
break; 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() { protected void doShowMainActivity() {
...@@ -408,22 +417,31 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity { ...@@ -408,22 +417,31 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity {
} }
// 必要に応じて、規約同意画面を表示 // 必要に応じて、規約同意画面を表示
AgreementToTermsActivity.clearVersion(this); // for debug! AgreementToTermsActivity.clearVersion(this); // for debug!
AgreementToTermsActivity.Result confirmResult = AgreementToTermsActivity.confirmAgreement(this, REQUEST_AGREEMENT, isNormalSize(), null); AgreementToTermsActivity.PreAgreementListener listener = new AgreementToTermsActivity.PreAgreementListener() {
switch (confirmResult) { @Override
case DISABLE: public void onDisabled() {
case EMPTY: onAgreed();
case AGREED: }
// 規約同意画面が開かれなかったら、改めて初期化
@Override
public void onEmpty() {
onAgreed();
}
@Override
public void onAgreed() {
// 規約同意画面が開かれなかったら、次に進む
doMoveToHome(); doMoveToHome();
break; }
case FAILED:
confirmResult = AgreementToTermsActivity.Result.AGREED; @Override
public void onFailed(Exception e) {
// 読み込みに失敗しても、次に進む
Logger.e(TAG, e);
doMoveToHome(); doMoveToHome();
break; }
case CONFIRM: };
// onActivityResultを待つ AgreementToTermsActivity.confirmAgreement(this, REQUEST_AGREEMENT, isNormalSize(), listener);
break;
}
} }
@Override @Override
......
...@@ -29,12 +29,11 @@ public class AgreementToTermsActivity extends ABVUIActivity { ...@@ -29,12 +29,11 @@ public class AgreementToTermsActivity extends ABVUIActivity {
private static final String TAG = "AgreementToTermsActivity"; private static final String TAG = "AgreementToTermsActivity";
private String currentVersion = ""; private String currentVersion = "";
public enum Result { public interface PreAgreementListener {
DISABLE, // 規約同意オプションが無効だった void onDisabled();
EMPTY, // 規約情報が空だった void onEmpty();
AGREED, // 同意済みだった void onAgreed();
FAILED, // 規約情報の読み込みに失敗した void onFailed(Exception e);
CONFIRM // 規約同意画面を表示した
} }
@Override @Override
...@@ -148,41 +147,45 @@ public class AgreementToTermsActivity extends ABVUIActivity { ...@@ -148,41 +147,45 @@ public class AgreementToTermsActivity extends ABVUIActivity {
* @param context 呼び出し元アクティビティ * @param context 呼び出し元アクティビティ
* @param requestCode startActivityForResultで使用するリクエスト・コード * @param requestCode startActivityForResultで使用するリクエスト・コード
* @param isNormalSize 端末サイズ指定(スマホならtrue) * @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()) { if (! ABVDataCache.getInstance().serviceOption.isUsableAgreementToTerms()) {
// 規約同意オプションが無効な場合、何もしない // 規約同意オプションが無効な場合、何もしない
return Result.DISABLE; listener.onDisabled();
return;
} }
try { context.showProgressPopup();
context.showProgressPopup(); CommonExecutor.execute(new Runnable() {
AgreementToTermsLogic logic = AbstractLogic.getLogic(AgreementToTermsLogic.class); @Override
AgreementToTermsJSON json = logic.getTerms(); public void run() {
try {
if (json.getTerms().isEmpty() || json.getTermsVersion().isEmpty()) { AgreementToTermsLogic logic = AbstractLogic.getLogic(AgreementToTermsLogic.class);
// 規約内容やバージョンが空の場合は何もしない AgreementToTermsJSON json = logic.getTerms();
return Result.EMPTY;
} if (json.getTerms().isEmpty() || json.getTermsVersion().isEmpty()) {
if (getLatestVersion(context).equals(json.getTermsVersion())) { // 規約内容やバージョンが空の場合は何もしない
// 規約のバージョンが、すでに同意しているものと同じときは何もしない listener.onEmpty();
return Result.AGREED; return;
} }
// ダイアログ表示 if (getLatestVersion(context).equals(json.getTermsVersion())) {
Intent intent = new Intent(context, isNormalSize ? AgreementToTermsActivity.class : AgreementToTermsActivityDialog.class); // 規約のバージョンが、すでに同意しているものと同じときは何もしない
intent.putExtra(ABookKeys.AGREEMENT_TO_TERMS_VERSION, json.getTermsVersion()); listener.onAgreed();
intent.putExtra(ABookKeys.AGREEMENT_TO_TERMS, json.getTerms()); return;
context.startActivityForResult(intent, requestCode); }
return Result.CONFIRM; // ダイアログ表示
} catch (Exception e) { Intent intent = new Intent(context, isNormalSize ? AgreementToTermsActivity.class : AgreementToTermsActivityDialog.class);
Logger.e(TAG, e); intent.putExtra(ABookKeys.AGREEMENT_TO_TERMS_VERSION, json.getTermsVersion());
if (onFailed != null) { intent.putExtra(ABookKeys.AGREEMENT_TO_TERMS, json.getTerms());
failed(context, onFailed); 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