Commit 7371d7a2 by Kazuyuki Hida

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

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