Commit 7371d7a2 by Kazuyuki Hida

レビューの指摘事項(非同期通信除く)を修正

parent f6cc3315
...@@ -65,9 +65,8 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity { ...@@ -65,9 +65,8 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity {
private static final int REQUEST_AGREEMENT = 120391; // ユニークで適当な値 private static final int REQUEST_AGREEMENT = 120391; // ユニークで適当な値
private static final int REQUEST_AGREEMENT_FROM_LOGIN = 120392; // ユニークで適当な値 private static final int REQUEST_AGREEMENT_FROM_LOGIN = 120392; // ユニークで適当な値
private AgreementToTermsActivity.Result confirmResult;
private Context mContext = ABVNoAuthenticatedActivity.this; private final Context mContext = ABVNoAuthenticatedActivity.this;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -92,7 +91,7 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity { ...@@ -92,7 +91,7 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity {
*/ */
protected void showMainActivity(String loginId) { protected void showMainActivity(String loginId) {
confirmResult = AgreementToTermsActivity.confirmAgreement(this, REQUEST_AGREEMENT_FROM_LOGIN, isNormalSize(), new Runnable() { AgreementToTermsActivity.Result confirmResult = AgreementToTermsActivity.confirmAgreement(this, REQUEST_AGREEMENT_FROM_LOGIN, isNormalSize(), new Runnable() {
@Override @Override
public void run() { public void run() {
LogoutHelper.logout(ABVNoAuthenticatedActivity.this); LogoutHelper.logout(ABVNoAuthenticatedActivity.this);
...@@ -408,7 +407,8 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity { ...@@ -408,7 +407,8 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity {
return; return;
} }
// 必要に応じて、規約同意画面を表示 // 必要に応じて、規約同意画面を表示
confirmResult = AgreementToTermsActivity.confirmAgreement(this, REQUEST_AGREEMENT, isNormalSize(), null); AgreementToTermsActivity.clearVersion(this); // for debug!
AgreementToTermsActivity.Result confirmResult = AgreementToTermsActivity.confirmAgreement(this, REQUEST_AGREEMENT, isNormalSize(), null);
switch (confirmResult) { switch (confirmResult) {
case DISABLE: case DISABLE:
case EMPTY: case EMPTY:
...@@ -433,7 +433,6 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity { ...@@ -433,7 +433,6 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity {
if (requestCode == REQUEST_AGREEMENT) { if (requestCode == REQUEST_AGREEMENT) {
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
// 同意したら初期化 // 同意したら初期化
confirmResult = AgreementToTermsActivity.Result.AGREED;
doMoveToHome(); doMoveToHome();
} else { } else {
// 規約に同意しなかったので、ログアウト // 規約に同意しなかったので、ログアウト
...@@ -444,7 +443,6 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity { ...@@ -444,7 +443,6 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity {
if (requestCode == REQUEST_AGREEMENT_FROM_LOGIN) { if (requestCode == REQUEST_AGREEMENT_FROM_LOGIN) {
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
// 同意したら初期化 // 同意したら初期化
confirmResult = AgreementToTermsActivity.Result.AGREED;
doShowMainActivity(); doShowMainActivity();
} else { } else {
// 規約に同意しなかったので、ログアウト // 規約に同意しなかったので、ログアウト
......
...@@ -12,6 +12,7 @@ import androidx.annotation.NonNull; ...@@ -12,6 +12,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import jp.agentec.abook.abv.bl.acms.client.json.AgreementToTermsJSON; import jp.agentec.abook.abv.bl.acms.client.json.AgreementToTermsJSON;
import jp.agentec.abook.abv.bl.common.CommonExecutor;
import jp.agentec.abook.abv.bl.common.constant.ABookKeys; import jp.agentec.abook.abv.bl.common.constant.ABookKeys;
import jp.agentec.abook.abv.bl.common.exception.NetworkDisconnectedException; import jp.agentec.abook.abv.bl.common.exception.NetworkDisconnectedException;
import jp.agentec.abook.abv.bl.common.log.Logger; import jp.agentec.abook.abv.bl.common.log.Logger;
...@@ -22,7 +23,6 @@ import jp.agentec.abook.abv.cl.util.PreferenceUtil; ...@@ -22,7 +23,6 @@ import jp.agentec.abook.abv.cl.util.PreferenceUtil;
import jp.agentec.abook.abv.launcher.android.R; import jp.agentec.abook.abv.launcher.android.R;
import jp.agentec.abook.abv.ui.common.activity.ABVActivity; import jp.agentec.abook.abv.ui.common.activity.ABVActivity;
import jp.agentec.abook.abv.ui.common.activity.ABVUIActivity; import jp.agentec.abook.abv.ui.common.activity.ABVUIActivity;
import jp.agentec.abook.abv.ui.common.dialog.ABookAlertDialog;
import jp.agentec.abook.abv.ui.common.util.AlertDialogUtil; import jp.agentec.abook.abv.ui.common.util.AlertDialogUtil;
public class AgreementToTermsActivity extends ABVUIActivity { public class AgreementToTermsActivity extends ABVUIActivity {
...@@ -85,48 +85,58 @@ public class AgreementToTermsActivity extends ABVUIActivity { ...@@ -85,48 +85,58 @@ public class AgreementToTermsActivity extends ABVUIActivity {
// 同意する // 同意する
private void agree() { private void agree() {
try { showProgressPopup();
// 同意したことをCMSに送信 CommonExecutor.execute(new Runnable() {
AgreementToTermsLogic logic = AbstractLogic.getLogic(AgreementToTermsLogic.class); @Override
logic.agreeTerms(currentVersion); public void run() {
// 同意したバージョンを保存して閉じる try {
setLatestVersion(AgreementToTermsActivity.this, currentVersion); // 同意したことをCMSに送信
setResult(RESULT_OK); AgreementToTermsLogic logic = AbstractLogic.getLogic(AgreementToTermsLogic.class);
finish(); logic.agreeTerms(currentVersion);
} catch (Exception e) { // 同意したバージョンを保存して閉じる
Logger.e(TAG, e); runOnUiThread(new Runnable() {
// 失敗したらアラート表示 @Override
ABookAlertDialog dialog = AlertDialogUtil.createAlertDialog(this, R.string.app_name); public void run() {
if (e instanceof NetworkDisconnectedException) { setLatestVersion(AgreementToTermsActivity.this, currentVersion);
dialog.setMessage(R.string.msg_network_offline); setResult(RESULT_OK);
} else { finish();
dialog.setMessage(R.string.failed_to_send_agreement); }
});
} catch (final Exception e) {
Logger.e(TAG, e);
// 失敗したらアラート表示
runOnUiThread(new Runnable() {
@Override
public void run() {
int messageId;
if (e instanceof NetworkDisconnectedException) {
messageId = R.string.msg_network_offline;
} else {
messageId = R.string.failed_to_send_agreement;
}
AlertDialogUtil.showAlertDialog(AgreementToTermsActivity.this, R.string.app_name, messageId, true, null);
}
});
} finally {
closeProgressPopup();
}
} }
dialog.setPositiveButton(R.string.close, null); });
showAlertDialog(dialog);
}
} }
// 同意しない // 同意しない
private void disagree() { private void disagree() {
// 確認ダイアログ // 確認ダイアログ
ABookAlertDialog dialog = AlertDialogUtil.createAlertDialog(this, R.string.app_name); AlertDialogUtil.showAlertDialog(this, R.string.app_name, R.string.logout_by_disagree, false,
dialog.setMessage(R.string.logout_by_disagree); new DialogInterface.OnClickListener() {
dialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override
@Override public void onClick(DialogInterface dialog, int which) {
public void onClick(DialogInterface dialog, int which) { // ログアウトしてよし
// ログアウトしてよし setResult(RESULT_CANCELED);
setResult(RESULT_CANCELED); finish();
finish(); }
} }
}); );
dialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// アラートを閉じるだけ
}
});
showAlertDialog(dialog);
} }
/** /**
...@@ -140,7 +150,7 @@ public class AgreementToTermsActivity extends ABVUIActivity { ...@@ -140,7 +150,7 @@ public class AgreementToTermsActivity extends ABVUIActivity {
* @param isNormalSize 端末サイズ指定(スマホならtrue) * @param isNormalSize 端末サイズ指定(スマホならtrue)
* @param onFailed 規約情報の取得に失敗したときの処理 * @param onFailed 規約情報の取得に失敗したときの処理
*/ */
public static Result confirmAgreement(ABVActivity context, int requestCode, boolean isNormalSize, @Nullable final Runnable onFailed) { public static Result confirmAgreement(final ABVActivity context, int requestCode, boolean isNormalSize, @Nullable final Runnable onFailed) {
if (! ABVDataCache.getInstance().serviceOption.isUsableAgreementToTerms()) { if (! ABVDataCache.getInstance().serviceOption.isUsableAgreementToTerms()) {
// 規約同意オプションが無効な場合、何もしない // 規約同意オプションが無効な場合、何もしない
return Result.DISABLE; return Result.DISABLE;
...@@ -148,7 +158,6 @@ public class AgreementToTermsActivity extends ABVUIActivity { ...@@ -148,7 +158,6 @@ public class AgreementToTermsActivity extends ABVUIActivity {
try { try {
context.showProgressPopup(); context.showProgressPopup();
AgreementToTermsLogic logic = AbstractLogic.getLogic(AgreementToTermsLogic.class); AgreementToTermsLogic logic = AbstractLogic.getLogic(AgreementToTermsLogic.class);
AgreementToTermsJSON json = logic.getTerms(); AgreementToTermsJSON json = logic.getTerms();
if (json.getTerms().isEmpty() || json.getTermsVersion().isEmpty()) { if (json.getTerms().isEmpty() || json.getTermsVersion().isEmpty()) {
...@@ -176,23 +185,38 @@ public class AgreementToTermsActivity extends ABVUIActivity { ...@@ -176,23 +185,38 @@ public class AgreementToTermsActivity extends ABVUIActivity {
} }
} }
/**
* 規約内容の読み込みに失敗したときは、それを伝えるアラートを出してから、失敗時の処理を行う
*
* @param context アラートを生成するためのコンテキスト
* @param onFailed 失敗時の処理
*/
private static void failed(Context context, @NonNull final Runnable onFailed) { private static void failed(Context context, @NonNull final Runnable onFailed) {
ABookAlertDialog dialog = AlertDialogUtil.createAlertDialog(context, R.string.app_name); AlertDialogUtil.showAlertDialog(context, R.string.app_name, R.string.failed_to_get_terms_of_service, true, new DialogInterface.OnClickListener() {
dialog.setMessage(R.string.failed_to_get_terms_of_service);
dialog.setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
// ログイン直後の場合失敗したら、ログアウトする仕様なので、それをonFailedを通して実行 // ログイン直後の場合失敗したら、ログアウトする仕様なので、それをonFailedを通して実行
onFailed.run(); onFailed.run();
} }
}); });
dialog.show();
} }
/**
* 直近の同意した規約のバージョンを返すメソッド
*
* @param context SharedPreferenceにアクセスするためのコンテキスト
* @return バージョン文字列
*/
private static String getLatestVersion(Context context) { private static String getLatestVersion(Context context) {
return PreferenceUtil.getUserPref(context, ABookKeys.AGREEMENT_TO_TERMS_VERSION, ""); return PreferenceUtil.getUserPref(context, ABookKeys.AGREEMENT_TO_TERMS_VERSION, "");
} }
/**
* 直近の同意した規約のバージョンを保存するメソッド
*
* @param context SharedPreferenceにアクセスするためのコンテキスト
* @param version バージョン文字列
*/
private static void setLatestVersion(Context context, String version) { private static void setLatestVersion(Context context, String version) {
PreferenceUtil.putUserPref(context, ABookKeys.AGREEMENT_TO_TERMS_VERSION, version); PreferenceUtil.putUserPref(context, ABookKeys.AGREEMENT_TO_TERMS_VERSION, version);
} }
...@@ -200,8 +224,4 @@ public class AgreementToTermsActivity extends ABVUIActivity { ...@@ -200,8 +224,4 @@ public class AgreementToTermsActivity extends ABVUIActivity {
public static void clearVersion(Context context) { public static void clearVersion(Context context) {
PreferenceUtil.removeUserPref(context, ABookKeys.AGREEMENT_TO_TERMS_VERSION); PreferenceUtil.removeUserPref(context, ABookKeys.AGREEMENT_TO_TERMS_VERSION);
} }
public static boolean isFirstAgreement(Context context) {
return PreferenceUtil.getUserPref(context, ABookKeys.AGREEMENT_TO_TERMS_VERSION, "").isEmpty();
}
} }
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