Commit 2291d680 by Kazuyuki Hida

規約同意画面をActivityベースに変更。ログインからの処理でも規約同意画面が表示されるようにした。

parent 98e7bd4c
...@@ -256,5 +256,8 @@ ...@@ -256,5 +256,8 @@
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
android:configChanges="keyboardHidden|orientation|screenSize" > android:configChanges="keyboardHidden|orientation|screenSize" >
</activity> </activity>
<activity android:name="jp.agentec.abook.abv.ui.home.activity.AgreementToTermsActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>
<activity android:name="jp.agentec.abook.abv.ui.home.activity.AgreementToTermsActivityDialog" android:theme="@style/Theme.MyTheme.ModalDialog" />
</application> </application>
</manifest> </manifest>
\ No newline at end of file
...@@ -8,11 +8,50 @@ ...@@ -8,11 +8,50 @@
android:background="@color/basic_white1" android:background="@color/basic_white1"
> >
<!-- ヘッダ -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/list_first_color"
>
<TextView
android:id="@+id/disagreeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:text="@string/disagree"
android:textColor="@color/dialog_text_color"
android:padding="16dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="@string/terms_of_service"
android:textColor="@color/dialog_text_color"
android:padding="16dp"/>
<TextView
android:id="@+id/agreeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:text="@string/agree"
android:textColor="@color/dialog_text_color"
android:padding="16dp"
tools:ignore="RelativeOverlap"
/>
</RelativeLayout>
<!-- 規約 --> <!-- 規約 -->
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="0dp"
tools:ignore="UselessParent"> android:layout_weight="1">
<LinearLayout <LinearLayout
android:orientation="vertical" android:orientation="vertical"
......
...@@ -49,9 +49,10 @@ import jp.agentec.abook.abv.ui.common.constant.ErrorMessage; ...@@ -49,9 +49,10 @@ 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.constant.NaviConsts;
import jp.agentec.abook.abv.ui.common.dialog.ABookAlertDialog; 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.ABVViewUnbindHelper;
import jp.agentec.abook.abv.ui.common.helper.AgreementToTermsHelper; import jp.agentec.abook.abv.ui.common.helper.LogoutHelper;
import jp.agentec.abook.abv.ui.common.util.ABVToastUtil; import jp.agentec.abook.abv.ui.common.util.ABVToastUtil;
import jp.agentec.abook.abv.ui.common.util.AlertDialogUtil; import jp.agentec.abook.abv.ui.common.util.AlertDialogUtil;
import jp.agentec.abook.abv.ui.home.activity.AgreementToTermsActivity;
import jp.agentec.abook.abv.ui.home.activity.LoginActivity; import jp.agentec.abook.abv.ui.home.activity.LoginActivity;
import jp.agentec.abook.abv.ui.home.activity.OperationListActivity; import jp.agentec.abook.abv.ui.home.activity.OperationListActivity;
import jp.agentec.abook.abv.ui.home.helper.ABookPermissionHelper; import jp.agentec.abook.abv.ui.home.helper.ABookPermissionHelper;
...@@ -62,7 +63,11 @@ import jp.agentec.adf.util.StringUtil; ...@@ -62,7 +63,11 @@ import jp.agentec.adf.util.StringUtil;
public abstract class ABVNoAuthenticatedActivity extends ABVActivity { public abstract class ABVNoAuthenticatedActivity extends ABVActivity {
private static final String TAG = "ABVNoAuthenticatedActivity"; private static final String TAG = "ABVNoAuthenticatedActivity";
private Context mContext = ABVNoAuthenticatedActivity.this; 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;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -85,10 +90,32 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity { ...@@ -85,10 +90,32 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity {
* *
* @param loginId * @param loginId
*/ */
protected void showMainActivity(String loginId) { protected void showMainActivity(String loginId) {
confirmResult = AgreementToTermsActivity.confirmAgreement(this, REQUEST_AGREEMENT_FROM_LOGIN, isNormalSize(), null);
switch (confirmResult) {
case DISABLE:
case EMPTY:
case AGREED:
// 規約同意画面が開かれなかったら、改めて初期化
doShowMainActivity();
break;
case FAILED:
confirmResult = AgreementToTermsActivity.Result.AGREED;
doShowMainActivity();
break;
case CONFIRM:
// onActivityResultを待つ
break;
}
}
protected void doShowMainActivity() {
startActivity(new Intent().setClassName(getApplicationContext().getPackageName(), getMainActivityClassName()).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP), NaviConsts.Right); startActivity(new Intent().setClassName(getApplicationContext().getPackageName(), getMainActivityClassName()).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP), NaviConsts.Right);
finish(); if (!(this instanceof LoginActivity)) {
finish();
}
LoginActivity.finishPendingActivity();
Intent intent = new Intent(); Intent intent = new Intent();
getApplicationContext().sendBroadcast(intent); getApplicationContext().sendBroadcast(intent);
} }
...@@ -371,82 +398,94 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity { ...@@ -371,82 +398,94 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity {
} }
protected void moveToHome() { protected void moveToHome() {
AgreementToTermsHelper.clearVersion(this); // 必要に応じて、規約同意画面を表示
AgreementToTermsHelper.confirmAgreement(this, isNormalSize(), agreementListener); AgreementToTermsActivity.clearVersion(this); // for debug!
confirmResult = AgreementToTermsActivity.confirmAgreement(this, REQUEST_AGREEMENT, isNormalSize(), null);
switch (confirmResult) {
case DISABLE:
case EMPTY:
case AGREED:
// 規約同意画面が開かれなかったら、改めて初期化
doMoveToHome();
break;
case FAILED:
confirmResult = AgreementToTermsActivity.Result.AGREED;
doMoveToHome();
break;
case CONFIRM:
// onActivityResultを待つ
break;
}
} }
private final AgreementToTermsHelper.AgreementListener agreementListener = new AgreementToTermsHelper.AgreementListener() { @Override
@Override protected void onActivityResult( int requestCode, int resultCode, Intent data ) {
public void onDisabled() { super.onActivityResult(requestCode, resultCode, data);
onAgreed();
if (requestCode == REQUEST_AGREEMENT) {
if (resultCode == RESULT_OK) {
// 同意したら初期化
confirmResult = AgreementToTermsActivity.Result.AGREED;
doMoveToHome();
} else {
// 規約に同意しなかったので、ログアウト
LogoutHelper.logout(this);
}
} }
@Override if (requestCode == REQUEST_AGREEMENT_FROM_LOGIN) {
public void onEmpty() { if (resultCode == RESULT_OK) {
onAgreed(); // 同意したら初期化
confirmResult = AgreementToTermsActivity.Result.AGREED;
doShowMainActivity();
} else {
// 規約に同意しなかったので、ログアウト
LogoutHelper.logout(this);
}
} }
}
@Override private void doMoveToHome() {
public void onFailed() { Bundle extras = getIntent().getExtras();
onAgreed(); Intent intent = new Intent();
if (extras != null && !StringUtil.isNullOrEmpty(extras.getString(AppDefType.PushMessageKey.data))) {
intent.putExtra(AppDefType.PushMessageKey.data, extras.getString(AppDefType.PushMessageKey.data));
} }
@Override // 定期点検用
public void onAgreed() { if (extras != null && !StringUtil.isNullOrEmpty(extras.getString(AppDefType.PushMessageKey.operationId))) {
Bundle extras = getIntent().getExtras(); intent.putExtra(AppDefType.PushMessageKey.operationId, extras.getString(AppDefType.PushMessageKey.operationId));
Intent intent = new Intent(); intent.putExtra(AppDefType.PushMessageKey.message, extras.getString(AppDefType.PushMessageKey.message));
if (extras != null && !StringUtil.isNullOrEmpty(extras.getString(AppDefType.PushMessageKey.data))) { } else {
intent.putExtra(AppDefType.PushMessageKey.data, extras.getString(AppDefType.PushMessageKey.data)); // チャットのプッシュメッセージがある場合
} if (extras != null && !StringUtil.isNullOrEmpty(extras.getString(AppDefType.ChatPushMessageKey.roomName))) {
intent.putExtra(AppDefType.ChatPushMessageKey.roomId, extras.getLong(AppDefType.ChatPushMessageKey.roomId)); // Room Id
// 定期点検用 intent.putExtra(AppDefType.ChatPushMessageKey.roomName, extras.getString(AppDefType.ChatPushMessageKey.roomName)); // Room Name
if (extras != null && !StringUtil.isNullOrEmpty(extras.getString(AppDefType.PushMessageKey.operationId))) { intent.putExtra(AppDefType.ChatPushMessageKey.pushSendLoginId, extras.getString(AppDefType.ChatPushMessageKey.pushSendLoginId)); // sendLoginId
intent.putExtra(AppDefType.PushMessageKey.operationId, extras.getString(AppDefType.PushMessageKey.operationId)); intent.putExtra(AppDefType.ChatPushMessageKey.pushSendDate, extras.getLong(AppDefType.ChatPushMessageKey.pushSendDate));
intent.putExtra(AppDefType.PushMessageKey.message, extras.getString(AppDefType.PushMessageKey.message)); intent.putExtra(AppDefType.ChatPushMessageKey.roomType, extras.getString(AppDefType.ChatPushMessageKey.roomType));
} else { intent.putExtra(AppDefType.ChatPushMessageKey.collaborationType, extras.getString(AppDefType.ChatPushMessageKey.collaborationType));
// チャットのプッシュメッセージがある場合 getABVUIDataCache().isChatPushMessageOpenOperationList = true;
if (extras != null && !StringUtil.isNullOrEmpty(extras.getString(AppDefType.ChatPushMessageKey.roomName))) {
intent.putExtra(AppDefType.ChatPushMessageKey.roomId, extras.getLong(AppDefType.ChatPushMessageKey.roomId)); // Room Id
intent.putExtra(AppDefType.ChatPushMessageKey.roomName, extras.getString(AppDefType.ChatPushMessageKey.roomName)); // Room Name
intent.putExtra(AppDefType.ChatPushMessageKey.pushSendLoginId, extras.getString(AppDefType.ChatPushMessageKey.pushSendLoginId)); // sendLoginId
intent.putExtra(AppDefType.ChatPushMessageKey.pushSendDate, extras.getLong(AppDefType.ChatPushMessageKey.pushSendDate));
intent.putExtra(AppDefType.ChatPushMessageKey.roomType, extras.getString(AppDefType.ChatPushMessageKey.roomType));
intent.putExtra(AppDefType.ChatPushMessageKey.collaborationType, extras.getString(AppDefType.ChatPushMessageKey.collaborationType));
getABVUIDataCache().isChatPushMessageOpenOperationList = true;
}
}
intent.setClassName(getApplicationContext().getPackageName(), getMainActivityClassName()).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
final Uri data = getIntent().getData();
Logger.i(TAG, "call from URI intent : %s", data);
if (data != null && data.getScheme() != null) {
if (data.getScheme().equals(getString(R.string.scheme_url))) { // カスタムURI
intent.putExtra(CID, getLongValFromURI(data, CID));
intent.putExtra(PAGE, (int)getLongValFromURI(data, PAGE));
intent.putExtra(URL, getValFromURI(data, URL)); // Reader
intent.putExtra(PASSWORD, getValFromURI(data, PASSWORD)); // Reader
intent.putExtra(MESSAGE, getValFromURI(data, MESSAGE)); // Reader
}
} }
startActivity(intent);
finish();
} }
intent.setClassName(getApplicationContext().getPackageName(), getMainActivityClassName()).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
@Override final Uri data = getIntent().getData();
public void onDisagreed() { Logger.i(TAG, "call from URI intent : %s", data);
Intent intent = new Intent(); if (data != null && data.getScheme() != null) {
intent.setClassName(getApplicationContext().getPackageName(), LoginActivity.class.getName()).setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); if (data.getScheme().equals(getString(R.string.scheme_url))) { // カスタムURI
startActivity(intent); intent.putExtra(CID, getLongValFromURI(data, CID));
finish(); intent.putExtra(PAGE, (int)getLongValFromURI(data, PAGE));
intent.putExtra(URL, getValFromURI(data, URL)); // Reader
intent.putExtra(PASSWORD, getValFromURI(data, PASSWORD)); // Reader
intent.putExtra(MESSAGE, getValFromURI(data, MESSAGE)); // Reader
}
} }
startActivity(intent);
@Override if (! (this instanceof LoginActivity)) {
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(); finish();
} }
}; LoginActivity.finishPendingActivity();
}
/** /**
* カスタムURL対応 * カスタム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);
}
}
...@@ -34,7 +34,9 @@ public class LogoutHelper { ...@@ -34,7 +34,9 @@ public class LogoutHelper {
} }
// 新着更新が実行されている場合停止 // 新着更新が実行されている場合停止
((ABookSettingActivity)activity).stopContentRefresher(); if (activity instanceof ABookSettingActivity) {
((ABookSettingActivity)activity).stopContentRefresher();
}
SharedPreferences sharedPreferences = activity.getSharedPreferences(AppDefType.PrefName.USER_PREFERENCE, Context.MODE_PRIVATE); SharedPreferences sharedPreferences = activity.getSharedPreferences(AppDefType.PrefName.USER_PREFERENCE, Context.MODE_PRIVATE);
sharedPreferences.edit().remove(AppDefType.UserPrefKey.GUEST_LOGIN).apply(); sharedPreferences.edit().remove(AppDefType.UserPrefKey.GUEST_LOGIN).apply();
......
package jp.agentec.abook.abv.ui.home.activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;
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.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.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 {
private static final String TAG = "AgreementToTermsActivity";
private String currentVersion = "";
public enum Result {
DISABLE, // 規約同意オプションが無効だった
EMPTY, // 規約情報が空だった
AGREED, // 同意済みだった
FAILED, // 規約情報の読み込みに失敗した
CONFIRM // 規約同意画面を表示した
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ac_agreement_to_terms);
TextView versionText = findViewById(R.id.textVersion);
TextView termsText = findViewById(R.id.textTerms);
Intent intent = getIntent();
if (intent != null) {
currentVersion = intent.getStringExtra(ABookKeys.AGREEMENT_TO_TERMS_VERSION);
versionText.setText(currentVersion);
termsText.setText(intent.getStringExtra(ABookKeys.AGREEMENT_TO_TERMS));
}
setResult(RESULT_CANCELED);
findViewById(R.id.disagreeButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
disagree();
}
});
findViewById(R.id.agreeButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
agree();
}
});
}
@Override
public void onBackPressed() {
disagree();
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
disagree();
return true;
} else {
return super.onKeyUp(keyCode, event);
}
}
// 同意する
private void agree() {
try {
// 同意したことをCMSに送信
AgreementToTermsLogic logic = AbstractLogic.getLogic(AgreementToTermsLogic.class);
logic.agreeTerms(currentVersion);
// 同意したバージョンを保存して閉じる
setLatestVersion(AgreementToTermsActivity.this, currentVersion);
setResult(RESULT_OK);
finish();
} catch (Exception e) {
Logger.e(TAG, e);
// 失敗したらアラート表示
ABookAlertDialog dialog = AlertDialogUtil.createAlertDialog(this, 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, null);
showAlertDialog(dialog);
}
}
// 同意しない
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() {
@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);
}
/**
* 同意規約情報を読み込んで、バージョンが異なっていたら、Activityを表示
* バージョンが同じだったら何もしない
* 呼び出し側は、onActivityResultで、resultCode が RESULT_OK なら同意した、
* RESULT_CANCELEDなら同意しなかったと判断する
*
* @param context 呼び出し元アクティビティ
* @param requestCode startActivityForResultで使用するリクエスト・コード
* @param isNormalSize 端末サイズ指定(スマホならtrue)
* @param onFailed 規約情報の取得に失敗したときの処理
*/
public static Result confirmAgreement(ABVActivity context, int requestCode, boolean isNormalSize, @Nullable final Runnable onFailed) {
if (! ABVDataCache.getInstance().serviceOption.isUsableAgreementToTerms()) {
// 規約同意オプションが無効な場合、何もしない
return Result.DISABLE;
}
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);
}
return Result.FAILED;
} finally {
context.closeProgressPopup();
}
}
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() {
@Override
public void onClick(DialogInterface dialog, int which) {
// ログイン直後の場合失敗したら、ログアウトする仕様なので、それをonFailedを通して実行
onFailed.run();
}
});
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);
}
public static boolean isFirstAgreement(Context context) {
return PreferenceUtil.getUserPref(context, ABookKeys.AGREEMENT_TO_TERMS_VERSION, "").isEmpty();
}
}
package jp.agentec.abook.abv.ui.home.activity;
public class AgreementToTermsActivityDialog extends AgreementToTermsActivity {
}
...@@ -21,6 +21,9 @@ import android.widget.ImageButton; ...@@ -21,6 +21,9 @@ import android.widget.ImageButton;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import jp.agentec.abook.abv.bl.acms.client.json.CmsUrlJSON; import jp.agentec.abook.abv.bl.acms.client.json.CmsUrlJSON;
import jp.agentec.abook.abv.bl.acms.type.DeleteDataType; import jp.agentec.abook.abv.bl.acms.type.DeleteDataType;
import jp.agentec.abook.abv.bl.acms.type.LoginMode; import jp.agentec.abook.abv.bl.acms.type.LoginMode;
...@@ -98,8 +101,7 @@ public class LoginActivity extends ABVLoginActivity { ...@@ -98,8 +101,7 @@ public class LoginActivity extends ABVLoginActivity {
private InputMethodManager imm; private InputMethodManager imm;
// private CheckBox chexBoxAgree; private static List<LoginActivity> pendingActivityList = new ArrayList<>();
// private static String termsOfUseUrl = ABVEnvironment.getInstance().agreeToTermsOfUseUrl;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
...@@ -288,7 +290,18 @@ public class LoginActivity extends ABVLoginActivity { ...@@ -288,7 +290,18 @@ public class LoginActivity extends ABVLoginActivity {
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
finish(); pendingActivityList.add(this);
}
public static void finishPendingActivity() {
while (pendingActivityList.size() > 0) {
LoginActivity activity = pendingActivityList.remove(pendingActivityList.size() - 1);
activity.finish();
}
}
public static void clearPendingActivity() {
pendingActivityList.clear();
} }
@Override @Override
......
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