Commit 98e7bd4c by Kazuyuki Hida

規約同意画面をAlertDialogで実装したが、複雑になりすぎたので、Activityベースに変更してみるため、いったんコミット

parent 4aed3d16
......@@ -1549,6 +1549,7 @@
<string name="select_spp_device_title">シリアル通信機器選択</string>
<string name="msg_get_device_token_fail">プッシュ通知サービスに必要なデバイストークンの取得に失敗しました。\nGooglePlayServiceアプリがインストールされているか確認してください。</string>
<string name="terms_of_service">利用規約</string>
<string name="failed_to_get_terms_of_service">利用規約の取得に失敗しました。</string>
<string name="logout_by_disagree">ログアウトされ、ログイン画面に遷移します。よろしいでしょうか?</string>
<string name="failed_to_send_agreement">利用規約同意情報をサーバへ送信失敗しました。\nもう一度、同意ボタンをタップしてください。</string>
......
......@@ -1546,6 +1546,7 @@
<string name="pairing_search_stop">멈추다</string>
<string name="msg_get_device_token_fail">알림 서비스에 필요한 단말기 토큰을 취득하지 못했습니다. \nGooglePlayService가 인스톨 되어있는지 확인해 주세요.</string>
<string name="terms_of_service">이용규약</string>
<string name="failed_to_get_terms_of_service">이용규약 정보 취득에 실패하였습니다.</string>
<string name="logout_by_disagree">로그 아웃되어 로그인 화면으로 이동합니다. 실행 하시겠습니까?</string>
<string name="failed_to_send_agreement">이용 규약 동의 정보를 서버에 전송 실패하였습니다. 다시 한번 동의 버튼을 눌러주세요.</string>
......
......@@ -1549,6 +1549,7 @@
<string name="select_spp_device_title">Serial communication device selection</string>
<string name="msg_get_device_token_fail">Failed to acquire the device token required for the push notification service. \nCheck if the GooglePlayService app is installed.</string>
<string name="terms_of_service">Terms of Service</string>
<string name="failed_to_get_terms_of_service">Failed to get the terms of service information.</string>
<string name="logout_by_disagree">Log out and transition to the login screen. Are you okay?</string>
<string name="failed_to_send_agreement">Failed to send information about agreeing to the Terms of Service to the server. Please tap \"Agree\" again.</string>
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/basic_white1"
>
<!-- 規約 -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="UselessParent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
>
<TextView
android:id="@+id/textVersion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:textColor="@color/dialog_text_color"
android:textSize="16sp"
android:lineSpacingMultiplier="1.2"
/>
<TextView
android:id="@+id/textTerms"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/dialog_text_color"
android:textSize="18sp"
android:lineSpacingMultiplier="1.2"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
\ No newline at end of file
package jp.agentec.abook.abv.ui.common.activity;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.DownloadManager;
import android.app.DownloadManager.Request;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
......@@ -23,18 +20,12 @@ import android.widget.ImageView;
import android.widget.Toast;
import java.io.File;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.UUID;
import jp.agentec.abook.abv.bl.acms.client.AcmsClient;
import jp.agentec.abook.abv.bl.acms.client.json.AcmsMessageJSON;
import jp.agentec.abook.abv.bl.acms.client.parameters.AppLastVersionParameters;
import jp.agentec.abook.abv.bl.acms.type.AcmsApis;
import jp.agentec.abook.abv.bl.acms.type.AuthLevel;
import jp.agentec.abook.abv.bl.acms.type.LoginMode;
import jp.agentec.abook.abv.bl.acms.type.ServiceOption.ServiceOptionId;
import jp.agentec.abook.abv.bl.common.ABVEnvironment;
import jp.agentec.abook.abv.bl.common.Callback;
import jp.agentec.abook.abv.bl.common.CommonExecutor;
......@@ -58,6 +49,7 @@ import jp.agentec.abook.abv.ui.common.constant.ErrorMessage;
import jp.agentec.abook.abv.ui.common.constant.NaviConsts;
import jp.agentec.abook.abv.ui.common.dialog.ABookAlertDialog;
import jp.agentec.abook.abv.ui.common.helper.ABVViewUnbindHelper;
import jp.agentec.abook.abv.ui.common.helper.AgreementToTermsHelper;
import jp.agentec.abook.abv.ui.common.util.ABVToastUtil;
import jp.agentec.abook.abv.ui.common.util.AlertDialogUtil;
import jp.agentec.abook.abv.ui.home.activity.LoginActivity;
......@@ -65,7 +57,6 @@ import jp.agentec.abook.abv.ui.home.activity.OperationListActivity;
import jp.agentec.abook.abv.ui.home.helper.ABookPermissionHelper;
import jp.agentec.adf.util.DateTimeFormat;
import jp.agentec.adf.util.DateTimeUtil;
import jp.agentec.adf.util.FileUtil;
import jp.agentec.adf.util.StringUtil;
public abstract class ABVNoAuthenticatedActivity extends ABVActivity {
......@@ -122,7 +113,7 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity {
};
FcmManager.getFcmToken(mContext, resultCallback);
}
});
});
}
protected void noAuthenticatedShowMain(boolean isGuestLogin, String deviceToken, String urlPath) {
......@@ -380,7 +371,28 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity {
}
protected void moveToHome() {
try {
AgreementToTermsHelper.clearVersion(this);
AgreementToTermsHelper.confirmAgreement(this, isNormalSize(), agreementListener);
}
private final AgreementToTermsHelper.AgreementListener agreementListener = new AgreementToTermsHelper.AgreementListener() {
@Override
public void onDisabled() {
onAgreed();
}
@Override
public void onEmpty() {
onAgreed();
}
@Override
public void onFailed() {
onAgreed();
}
@Override
public void onAgreed() {
Bundle extras = getIntent().getExtras();
Intent intent = new Intent();
if (extras != null && !StringUtil.isNullOrEmpty(extras.getString(AppDefType.PushMessageKey.data))) {
......@@ -388,9 +400,9 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity {
}
// 定期点検用
if (extras != null && !StringUtil.isNullOrEmpty(extras.getString(AppDefType.PushMessageKey.operationId))) {
intent.putExtra(AppDefType.PushMessageKey.operationId, extras.getString(AppDefType.PushMessageKey.operationId));
intent.putExtra(AppDefType.PushMessageKey.message, extras.getString(AppDefType.PushMessageKey.message));
if (extras != null && !StringUtil.isNullOrEmpty(extras.getString(AppDefType.PushMessageKey.operationId))) {
intent.putExtra(AppDefType.PushMessageKey.operationId, extras.getString(AppDefType.PushMessageKey.operationId));
intent.putExtra(AppDefType.PushMessageKey.message, extras.getString(AppDefType.PushMessageKey.message));
} else {
// チャットのプッシュメッセージがある場合
if (extras != null && !StringUtil.isNullOrEmpty(extras.getString(AppDefType.ChatPushMessageKey.roomName))) {
......@@ -417,14 +429,24 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity {
}
startActivity(intent);
finish();
} catch (Exception e) {
Logger.e("ABVException Login", e);
}
@Override
public void onDisagreed() {
Intent intent = new Intent();
intent.setClassName(getApplicationContext().getPackageName(), LoginActivity.class.getName()).setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
finish();
}
}
@Override
public void onError(Exception e) {
Intent intent = new Intent();
intent.setClassName(getApplicationContext().getPackageName(), LoginActivity.class.getName()).setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
finish();
}
};
/**
* カスタムURL対応
......
package jp.agentec.abook.abv.ui.common.helper;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import androidx.annotation.Nullable;
import jp.agentec.abook.abv.bl.acms.client.json.AgreementToTermsJSON;
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;
import jp.agentec.abook.abv.bl.data.ABVDataCache;
import jp.agentec.abook.abv.bl.logic.AbstractLogic;
import jp.agentec.abook.abv.bl.logic.AgreementToTermsLogic;
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.dialog.ABookAlertDialog;
import jp.agentec.abook.abv.ui.common.util.AlertDialogUtil;
public class AgreementToTermsHelper {
private static final String TAG = "AgreementToTermsHelper";
public interface AgreementListener {
void onDisabled();
void onEmpty();
void onFailed();
void onAgreed();
void onDisagreed();
void onError(Exception e);
}
/**
* 同意規約情報を読み込んで、バージョンが異なっていたら、ダイアログを表示
* バージョンが同じだったら何もしない
*/
public static void confirmAgreement(final ABVActivity context, final boolean isNomalSize, @Nullable final AgreementListener listener) {
if (! ABVDataCache.getInstance().serviceOption.isUsableAgreementToTerms()) {
// 規約同意オプションが無効な場合、表示しない
if (listener != null) {
listener.onDisabled();
}
return;
}
final AgreementToTermsJSON termsJSON;
try {
context.showProgressPopup();
AgreementToTermsLogic logic = AbstractLogic.getLogic(AgreementToTermsLogic.class);
termsJSON = logic.getTerms();
if (termsJSON.getTerms().isEmpty() || termsJSON.getTermsVersion().isEmpty()) {
// 規約内容やバージョンが空の場合は表示しない
if (listener != null) {
listener.onEmpty();
}
return;
}
if (getLatestVersion(context).equals(termsJSON.getTermsVersion())) {
// 規約のバージョンが、すでに同意しているものと同じときは表示しない
if (listener != null) {
listener.onAgreed();
}
return;
}
} catch (Exception e) {
Logger.e(TAG, e);
if (listener != null) {
// 取得に失敗した場合
listener.onFailed();
}
return;
} finally {
context.closeProgressPopup();
}
try {
// ダイアログ表示
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.Theme_MyDialog);
builder.setTitle(R.string.terms_of_service);
LayoutInflater inflater = context.getLayoutInflater();
View layout = inflater.inflate(R.layout.dlg_agreement_to_terms, null, false);
TextView versionText = layout.findViewById(R.id.textVersion);
TextView termsText = layout.findViewById(R.id.textTerms);
versionText.setText(termsJSON.getTermsVersion());
termsText.setText(termsJSON.getTerms());
builder.setView(layout);
builder.setCancelable(false);
builder.setPositiveButton(R.string.agree, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
setLatestVersion(context, termsJSON.getTermsVersion());
agree(context, termsJSON.getTermsVersion(), isNomalSize, listener);
}
});
builder.setNegativeButton(R.string.disagree, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
disagree(context, isNomalSize, listener);
}
});
AlertDialog dialog = builder.create();
dialog.show();
if (! isNomalSize) {
WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
Display disp = wm.getDefaultDisplay();
params.width = disp.getWidth() * 4 / 5;
dialog.getWindow().setAttributes(params);
}
} catch (Exception e) {
if (listener != null) {
// ダイアログ表示でエラーが出た場合
listener.onError(e);
}
}
}
// 同意する
private static void agree(final ABVActivity context, String currentVersion, final boolean isNomalSize, final AgreementListener listener) {
try {
// 同意したことをCMSに送信
AgreementToTermsLogic logic = AbstractLogic.getLogic(AgreementToTermsLogic.class);
logic.agreeTerms(currentVersion);
// 同意したバージョンを保存して閉じる
setLatestVersion(context, currentVersion);
if (listener != null) {
listener.onAgreed();
}
} catch (final Exception e) {
Logger.e(TAG, e);
// 失敗したらアラート表示
ABookAlertDialog dialog = AlertDialogUtil.createAlertDialog(context, R.string.app_name);
if (e instanceof NetworkDisconnectedException) {
dialog.setMessage(R.string.msg_network_offline);
} else {
dialog.setMessage(R.string.failed_to_send_agreement);
}
dialog.setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (e instanceof NetworkDisconnectedException) {
confirmAgreement(context, isNomalSize, listener);
}
}
});
dialog.show();
}
}
// 同意しない
private static void disagree(final ABVActivity context, final boolean isNomalSize, final AgreementListener listener) {
// 確認ダイアログ
ABookAlertDialog dialog = AlertDialogUtil.createAlertDialog(context, R.string.app_name);
dialog.setMessage(R.string.logout_by_disagree);
dialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (listener != null) {
listener.onDisagreed();
}
}
});
dialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
confirmAgreement(context, isNomalSize, listener);
}
});
dialog.show();
}
private static String getLatestVersion(Context context) {
return PreferenceUtil.getUserPref(context, ABookKeys.AGREEMENT_TO_TERMS_VERSION, "");
}
private static void setLatestVersion(Context context, String version) {
PreferenceUtil.putUserPref(context, ABookKeys.AGREEMENT_TO_TERMS_VERSION, version);
}
public static void clearVersion(Context context) {
PreferenceUtil.removeUserPref(context, ABookKeys.AGREEMENT_TO_TERMS_VERSION);
}
}
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