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"
......
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