Commit 7917561a by Kazuyuki Hida

Merge branch 'features/1.4.500_53088_agreement_to_terms' into 'features/1.4.500'

規約同意画面を追加

See merge request !316
parents 17000bea f732d5a6
......@@ -15,6 +15,7 @@ import java.util.Observer;
import jp.agentec.abook.abv.bl.acms.client.json.AcmsBooleanResultJSON;
import jp.agentec.abook.abv.bl.acms.client.json.AcmsCommonJSON;
import jp.agentec.abook.abv.bl.acms.client.json.AcmsMessageJSON;
import jp.agentec.abook.abv.bl.acms.client.json.AgreementToTermsJSON;
import jp.agentec.abook.abv.bl.acms.client.json.ApertureMasterDataJSON;
import jp.agentec.abook.abv.bl.acms.client.json.AppLatestVersionJSON;
import jp.agentec.abook.abv.bl.acms.client.json.ArchiveDetailJSON;
......@@ -54,6 +55,7 @@ import jp.agentec.abook.abv.bl.acms.client.parameters.AbstractAcmsLoginParameter
import jp.agentec.abook.abv.bl.acms.client.parameters.AcmsContentParameters;
import jp.agentec.abook.abv.bl.acms.client.parameters.AcmsParameters;
import jp.agentec.abook.abv.bl.acms.client.parameters.AddMemberGroupParameters;
import jp.agentec.abook.abv.bl.acms.client.parameters.AgreementToTermsParameters;
import jp.agentec.abook.abv.bl.acms.client.parameters.AppStoreNewLoginParameters;
import jp.agentec.abook.abv.bl.acms.client.parameters.ArchiveDetailRequestParameters;
import jp.agentec.abook.abv.bl.acms.client.parameters.ArchiveRequestParameters;
......@@ -1112,6 +1114,36 @@ public class AcmsClient implements AcmsClientResponseListener {
return new TermsOfUseJson(response.httpResponseBody);
}
/**
* 規約情報の取得
*
* @param sid セッションID
* @return
* @throws AcmsException CMSがエラーを返した時の例外
* @throws NetworkDisconnectedException ネットワークエラー
*/
public AgreementToTermsJSON getTerms(String sid) throws AcmsException, NetworkDisconnectedException {
HttpResponse response = send(AcmsApis.ApiGetTerms, new AcmsParameters(sid));
AgreementToTermsJSON json = new AgreementToTermsJSON(response.httpResponseBody);
return json;
}
/**
* 規約に同意したことをCMSに通達
*
* @param params パラメータ
* @return 標準的なレスポンス
* @throws AcmsException CMSがエラーを返した時の例外
* @throws NetworkDisconnectedException ネットワークエラー
*/
public AcmsCommonJSON agreeTerms(AgreementToTermsParameters params) throws AcmsException, NetworkDisconnectedException {
HttpResponse response = send(AcmsApis.ApiAgreeTerms, params);
AcmsCommonJSON json = new AcmsCommonJSON(response.httpResponseBody);
return json;
}
/**********************************************************************************************/
/** 以下、共用メソッド---------------------------------------------------------------------- **/
/**********************************************************************************************/
......
package jp.agentec.abook.abv.bl.acms.client.json;
import org.json.adf.JSONException;
import org.json.adf.JSONObject;
import jp.agentec.abook.abv.bl.common.exception.AcmsException;
import jp.agentec.abook.abv.bl.common.exception.JSONValidationException;
/**
* 規約同意のAPIで使うレスポンス
*/
public class AgreementToTermsJSON extends AcmsCommonJSON {
private static final String TERMS_VERSION = "termsVersion";
private static final String TERMS = "terms";
private String termsVersion;
private String terms;
public AgreementToTermsJSON(String jsonString) throws AcmsException {
super(jsonString);
}
@Override
protected void parse(JSONObject json) throws JSONValidationException, JSONException {
super.parse(json);
termsVersion = json.has(TERMS_VERSION) ? json.getString(TERMS_VERSION) : "";
terms = json.has(TERMS) ? json.getString(TERMS) : "";
}
/**
* @return 規約のバージョン
*/
public String getTermsVersion() {
return termsVersion;
}
/**
* @return 規約の内容
*/
public String getTerms() {
return terms;
}
}
package jp.agentec.abook.abv.bl.acms.client.parameters;
import jp.agentec.adf.net.http.HttpParameterObject;
/**
* 規約同意時に使用するパラメータ
*/
public class AgreementToTermsParameters extends HttpParameterObject {
private final String sid;
private final String termsVersion;
/**
* @param sid セッションID
* @param termsVersion 同意した規約のバージョン
*/
public AgreementToTermsParameters(String sid, String termsVersion) {
super();
this.sid = sid;
this.termsVersion = termsVersion;
}
/**
* @return セッションID
*/
public String getSid() {
return sid;
}
/**
* @return 同意した規約のバージョン
*/
public String getTermsVersion() {
return termsVersion;
}
}
......@@ -177,6 +177,10 @@ public class AcmsApis {
public static final String ApigetArchive = "archive";
public static final String ApigetCollaboration = "collaboration";
// 規約同意
public static final String ApiGetTerms = "getTerms";
public static final String ApiAgreeTerms = "agreeTerms";
public static final class UserCmds {
public static final String inviteUsers = "3";
public static final String getMyInfo = "9";
......
......@@ -180,5 +180,10 @@ public interface ServiceOption {
* 利用しない:N(通常)、利用する:Y
*/
int AlcoholCheckerHw = 202;
/**
* 規約同意
*/
int agrementToTerms = 203;
}
}
\ No newline at end of file
......@@ -246,6 +246,9 @@ public class ABookKeys {
public static final String TASK_DEVICE_TYPE = "deviceType"; // CMSのインターフェースのパラメータ:devicetype
public static final String TASK_QUESTION_ID = "qid"; // CMSのインターフェースのパラメータ:qid
public static final String AGREEMENT_TO_TERMS_VERSION = "termsVersion";
public static final String AGREEMENT_TO_TERMS = "terms";
public static final String JSON_NAME = "jsonName";
public static final String JSON_DATA = "jsonData";
public static final String PUSH_MESSAGE_ID = "pushMessageId";
......
......@@ -352,6 +352,13 @@ public class ABVDataCache {
}
/**
* @return 規約同意オプションがYならtrue
*/
public boolean isUsableAgreementToTerms() {
return isServiceOptionEnable(ServiceOptionId.agrementToTerms);
}
/**
* @version 1.2.300
* サービスオプション(ユーザパスワードソルト付加)返す
* @return true:利用する, false:利用しない
......
package jp.agentec.abook.abv.bl.logic;
import jp.agentec.abook.abv.bl.acms.client.AcmsClient;
import jp.agentec.abook.abv.bl.acms.client.json.AcmsCommonJSON;
import jp.agentec.abook.abv.bl.acms.client.json.AgreementToTermsJSON;
import jp.agentec.abook.abv.bl.acms.client.parameters.AgreementToTermsParameters;
import jp.agentec.abook.abv.bl.common.exception.AcmsException;
import jp.agentec.abook.abv.bl.common.exception.NetworkDisconnectedException;
/**
* 規約同意の入出力
*/
public class AgreementToTermsLogic extends AbstractLogic {
private static final String TAG = "AgreementToTermsLogic";
/**
* 規約情報の取得
*
* @return 規約情報
* @throws AcmsException CMSがエラーを返したという例外
* @throws NetworkDisconnectedException ネットワークエラー
*/
public AgreementToTermsJSON getTerms() throws AcmsException, NetworkDisconnectedException {
String sid = cache.getMemberInfo().sid;
return AcmsClient.getInstance(cache.getUrlPath(), networkAdapter).getTerms(sid);
}
/**
* 同意したことをCMSに通達
*
* @param termsVersion バージョン
* @return 標準的なレスポンス情報
* @throws AcmsException CMSがエラーを返したという例外
* @throws NetworkDisconnectedException ネットワークエラー
*/
public AcmsCommonJSON agreeTerms(String termsVersion) throws AcmsException, NetworkDisconnectedException {
String sid = cache.getMemberInfo().sid;
return AcmsClient.getInstance(cache.getUrlPath(), networkAdapter).agreeTerms(new AgreementToTermsParameters(sid, termsVersion));
}
}
......@@ -1548,4 +1548,9 @@
<string name="msg_ble_connect_success">%1$sと接続になりました。%1$sを操作してください。</string>
<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>
</resources>
......@@ -1545,4 +1545,9 @@
<string name="pairing_search_scan">주사</string>
<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>
</resources>
\ No newline at end of file
......@@ -1548,4 +1548,9 @@
<string name="msg_ble_connect_success">It is now connected to the %1$s.Operate the %1$s.</string>
<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>
</resources>
<?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="0dp"
android:layout_weight="1"
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
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#ff999999"
android:padding="8dp"
>
<Button
android:id="@+id/agreeButton"
style="@style/ButtonABookDark"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/agree"/>
<Button
android:id="@+id/disagreeButton"
style="@style/ButtonABookDark"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/disagree" />
</LinearLayout>
</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,8 @@ 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.helper.LogoutHelper;
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,13 +58,12 @@ 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 {
private static final String TAG = "ABVNoAuthenticatedActivity";
private Context mContext = ABVNoAuthenticatedActivity.this;
private final Context mContext = ABVNoAuthenticatedActivity.this;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -94,8 +86,59 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity {
*
* @param loginId
*/
protected void showMainActivity(String loginId) {
AgreementToTermsHelper.AgreementListener listener = new AgreementToTermsHelper.AgreementListener() {
@Override
public void onDisabled() {
onAgreed();
}
@Override
public void onEmpty() {
onAgreed();
}
@Override
public void onAgreed() {
// 規約同意画面が開かれなかったら、次に進む
doShowMainActivity();
}
@Override
public void onConfirmed(boolean isAgreed) {
if (isAgreed) {
// 同意したら初期化
doShowMainActivity();
} else {
// 規約に同意しなかったので、ログアウト
LogoutHelper.logout(ABVNoAuthenticatedActivity.this);
}
}
@Override
public void onError(Exception e) {
logoutAlert(R.string.C_E_SYSTEM_0001);
}
@Override
public void onFailed(Exception e) {
// 読み込みに失敗したらログアウト
logoutAlert(R.string.failed_to_get_terms_of_service);
}
private void logoutAlert(int messageRes) {
AlertDialogUtil.showAlertDialog(ABVNoAuthenticatedActivity.this, R.string.app_name, messageRes, true, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
LogoutHelper.logout(ABVNoAuthenticatedActivity.this);
}
});
}
};
AgreementToTermsHelper.confirmAgreement(this, isNormalSize(), listener);
}
protected void doShowMainActivity() {
startActivity(new Intent().setClassName(getApplicationContext().getPackageName(), getMainActivityClassName()).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP), NaviConsts.Right);
finish();
Intent intent = new Intent();
......@@ -122,7 +165,7 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity {
};
FcmManager.getFcmToken(mContext, resultCallback);
}
});
});
}
protected void noAuthenticatedShowMain(boolean isGuestLogin, String deviceToken, String urlPath) {
......@@ -322,8 +365,6 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity {
}
}
/**
* 1日1回のバージョンチェックを行う
* @return true チェックを行う false 行わない
......@@ -380,50 +421,95 @@ public abstract class ABVNoAuthenticatedActivity extends ABVActivity {
}
protected void moveToHome() {
try {
Bundle extras = getIntent().getExtras();
Intent intent = new Intent();
if (extras != null && !StringUtil.isNullOrEmpty(extras.getString(AppDefType.PushMessageKey.data))) {
intent.putExtra(AppDefType.PushMessageKey.data, extras.getString(AppDefType.PushMessageKey.data));
// カスタムURI起動の場合は、規約同意は無視
final Uri data = getIntent().getData();
if (data != null && data.getScheme() != null && data.getScheme().equals(getString(R.string.scheme_url))) {
doMoveToHome();
return;
}
// 必要に応じて、規約同意画面を表示
AgreementToTermsHelper.AgreementListener listener = new AgreementToTermsHelper.AgreementListener() {
@Override
public void onDisabled() {
onAgreed();
}
// 定期点検用
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))) {
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;
}
@Override
public void onEmpty() {
onAgreed();
}
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
@Override
public void onAgreed() {
// 規約同意画面が開かれなかったら、次に進む
doMoveToHome();
}
@Override
public void onConfirmed(boolean isAgreed) {
if (isAgreed) {
// 同意したら初期化
doMoveToHome();
} else {
// 規約に同意しなかったので、ログアウト
LogoutHelper.logout(ABVNoAuthenticatedActivity.this);
}
}
startActivity(intent);
finish();
} catch (Exception e) {
Logger.e("ABVException Login", e);
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) {
// 失敗しても、次に進む
Logger.e(TAG, e);
doMoveToHome();
}
@Override
public void onFailed(Exception e) {
// 読み込みに失敗しても、次に進む
Logger.e(TAG, e);
doMoveToHome();
}
};
AgreementToTermsHelper.confirmAgreement(this, isNormalSize(), listener);
}
private void doMoveToHome() {
Bundle extras = getIntent().getExtras();
Intent intent = new Intent();
if (extras != null && !StringUtil.isNullOrEmpty(extras.getString(AppDefType.PushMessageKey.data))) {
intent.putExtra(AppDefType.PushMessageKey.data, extras.getString(AppDefType.PushMessageKey.data));
}
// 定期点検用
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))) {
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();
}
/**
......
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.NonNull;
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;
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.util.AlertDialogUtil;
/**
* 規約同意ダイアログを表示するヘルパー
*/
public class AgreementToTermsHelper {
private static final String TAG = "AgreementToTermsHelper";
/**
* 規約同意状態に応じて動作するリスナー
*/
public interface AgreementListener {
// 規約同意オプションがNoだった
void onDisabled();
// 規約内容やバージョンが空だった
void onEmpty();
// 規約情報の取得に失敗した
void onFailed(Exception e);
// すでに同意済みだった
void onAgreed();
// 同意するまたはしないをタップされた
void onConfirmed(boolean isAgreed);
// 規約情報の取得以外でエラーがあった
void onError(Exception e);
}
/**
* 同意規約情報を読み込んで、バージョンが異なっていたら、ダイアログを表示
* バージョンが同じだったら何もしない
*/
public static void confirmAgreement(final ABVActivity context, final boolean isNomalSize, @NonNull final AgreementListener listener) {
if (! ABVDataCache.getInstance().serviceOption.isUsableAgreementToTerms()) {
// 規約同意オプションが無効な場合、表示しない
listener.onDisabled();
return;
}
context.showProgressPopup();
CommonExecutor.execute(new Runnable() {
@Override
public void run() {
AgreementToTermsJSON termsJSON;
try {
AgreementToTermsLogic logic = AbstractLogic.getLogic(AgreementToTermsLogic.class);
termsJSON = logic.getTerms();
if (termsJSON == null || termsJSON.getTerms().isEmpty() || termsJSON.getTermsVersion().isEmpty()) {
// 規約内容やバージョンが空の場合は表示しない
listener.onEmpty();
return;
}
if (getLatestVersion(context).equals(termsJSON.getTermsVersion())) {
// 規約のバージョンが、すでに同意しているものと同じときは表示しない
listener.onAgreed();
return;
}
final AgreementToTermsJSON termsJSON1 = termsJSON;
context.runOnUiThread(new Runnable() {
@Override
public void run() {
// 同意画面表示
showAgreementDialog(context, termsJSON1, isNomalSize, listener);
}
});
} catch (Exception e) {
Logger.e(TAG, e);
// 取得に失敗した場合
listener.onFailed(e);
} finally {
context.runOnUiThread(new Runnable() {
@Override
public void run() {
context.closeProgressPopup();
}
});
}
}
});
}
/**
* 実際にダイアログを表示するメソッド
*
* @param activity 土台になるActivity
* @param termsJSON 規約情報
* @param isNomalSize 画面サイズがスマホならtrue
* @param listener 状態に応じてコールバックを受け取るリスナー
*/
private static void showAgreementDialog(final ABVActivity activity, final AgreementToTermsJSON termsJSON, final boolean isNomalSize, @NonNull final AgreementListener listener) {
try {
AlertDialog dialog = makeDialog(activity, termsJSON, isNomalSize, listener);
dialog.show();
WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
WindowManager wm = (WindowManager)activity.getSystemService(Context.WINDOW_SERVICE);
Display disp = wm.getDefaultDisplay();
if (isNomalSize) {
params.width = disp.getWidth() * 49 / 50;
} else {
params.width = disp.getWidth() * 4 / 5;
}
dialog.getWindow().setAttributes(params);
} catch (Exception e) {
listener.onError(e);
}
}
/**
* ダイアログを組み立てるメソッド
*
* @param activity 土台になるActivity
* @param termsJSON 規約情報
* @param isNomalSize 画面サイズがスマホならtrue
* @param listener 状態に応じてコールバックを受け取るリスナー
* @return 規約同意画面になるダイアログ
*/
private static AlertDialog makeDialog(final ABVActivity activity, final AgreementToTermsJSON termsJSON, final boolean isNomalSize, @NonNull final AgreementListener listener) {
// ダイアログ表示
AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.style.Theme_MyDialog);
builder.setTitle(R.string.terms_of_service);
LayoutInflater inflater = activity.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);
final AlertDialog dialog = builder.create();
layout.findViewById(R.id.agreeButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
agree(activity, dialog, termsJSON.getTermsVersion(), isNomalSize, listener);
}
});
layout.findViewById(R.id.disagreeButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
disagree(activity, dialog, isNomalSize, listener);
}
});
return dialog;
}
/**
* 同意するをタップしたときの処理
*
* @param activity 土台となるActivity
* @param dialog 規約同意画面のダイアログ
* @param currentVersion 同意する規約のバージョン
* @param isNomalSize 画面サイズがスマホならtrue
* @param listener 状態に応じてコールバックを受け取るリスナー
*/
private static void agree(final ABVActivity activity, final AlertDialog dialog, final String currentVersion, final boolean isNomalSize, final AgreementListener listener) {
activity.showProgressPopup();
CommonExecutor.execute(new Runnable() {
@Override
public void run() {
try {
// 同意したことをCMSに送信
AgreementToTermsLogic logic = AbstractLogic.getLogic(AgreementToTermsLogic.class);
logic.agreeTerms(currentVersion);
// 同意したバージョンを保存して閉じる
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
setLatestVersion(activity, currentVersion);
dialog.dismiss();
listener.onConfirmed(true);
}
});
} catch (final Exception e) {
Logger.e(TAG, e);
// 失敗したらアラート表示
activity.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(activity, R.string.app_name, messageId);
}
});
} finally {
activity.closeProgressPopup();
}
}
});
}
/**
* 同意しないをタップしたときの処理
*
* @param activity 土台となるActivity
* @param dialog 規約同意画面のダイアログ
* @param isNomalSize 画面サイズがスマホならtrue
* @param listener 状態に応じてコールバックを受け取るリスナー
*/
private static void disagree(final ABVActivity activity, final AlertDialog dialog, final boolean isNomalSize, final AgreementListener listener) {
AlertDialogUtil.showAlertDialog(activity, R.string.app_name, R.string.logout_by_disagree, false,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// ログアウトしてよし
listener.onConfirmed(false);
dialog.dismiss();
}
}
);
}
/**
* 最後に同意した規約のバージョンの取得
*
* @param context コンテクスト
* @return 最後に同意した規約のバージョン
*/
private static String getLatestVersion(Context context) {
return PreferenceUtil.getUserPref(context, ABookKeys.AGREEMENT_TO_TERMS_VERSION, "");
}
/**
* 最後に同意した規約のバージョンの保存
*
* @param context コンテクスト
* @param version 規約のバージョン
*/
private static void setLatestVersion(Context context, String version) {
PreferenceUtil.putUserPref(context, ABookKeys.AGREEMENT_TO_TERMS_VERSION, version);
}
}
package jp.agentec.abook.abv.ui.common.helper;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.widget.Toast;
import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.abook.abv.bl.logic.AbstractLogic;
import jp.agentec.abook.abv.bl.logic.UserAuthenticateLogic;
import jp.agentec.abook.abv.launcher.android.R;
import jp.agentec.abook.abv.ui.common.appinfo.AppDefType;
import jp.agentec.abook.abv.ui.common.util.ABVToastUtil;
import jp.agentec.abook.abv.ui.home.activity.ABookSettingActivity;
import jp.agentec.abook.abv.ui.home.activity.LoginActivity;
/**
* ログアウトする時に使用するヘルパークラス
* 複数個所で、ログアウトする契機があるので、まとめた。
*/
public class LogoutHelper {
/**
* ログアウトして、ログイン画面に遷移する
*
* @param activity 呼び出し元アクティビティ
*/
public static void logout(Activity activity) {
try {
// modify by Jang 2013.06.20
UserAuthenticateLogic user = AbstractLogic.getLogic(UserAuthenticateLogic.class);
// ログイン情報がある場合のみログアウト処理を行う
if (user.getMemberInfo() != null) {
user.signoutUser();
// Widgetへ通知
Intent intent = new Intent();
activity.sendBroadcast(intent);
}
} catch (Exception e) {
Logger.w("signoutUser failed at callLoginActivity", e);
ABVToastUtil.showMakeText(activity, R.string.ERROR, Toast.LENGTH_SHORT);
}
// 新着更新が実行されている場合停止
if (activity instanceof ABookSettingActivity) {
((ABookSettingActivity)activity).stopContentRefresher();
}
SharedPreferences sharedPreferences = activity.getSharedPreferences(AppDefType.PrefName.USER_PREFERENCE, Context.MODE_PRIVATE);
sharedPreferences.edit().remove(AppDefType.UserPrefKey.GUEST_LOGIN).apply();
Intent intent = new Intent(activity, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
activity.startActivity(intent);
activity.finish();
}
}
......@@ -96,6 +96,10 @@ public class AlertDialogUtil {
alertDialog.show();
}
public static void showAlertDialog(Context context, int title, int message) {
showAlertDialog(context, title, message, true, null);
}
public static ABookAlertDialog deleteContentAlertDialog(Context context, int deleteMessage) {
ABookAlertDialog alertDialog = createAlertDialog(context, R.string.delete);
alertDialog.setMessage(deleteMessage);
......
......@@ -56,6 +56,7 @@ import jp.agentec.abook.abv.launcher.android.R;
import jp.agentec.abook.abv.ui.common.appinfo.AppDefType;
import jp.agentec.abook.abv.ui.common.appinfo.AppDefType.UserPrefKey;
import jp.agentec.abook.abv.ui.common.dialog.ABookAlertDialog;
import jp.agentec.abook.abv.ui.common.helper.LogoutHelper;
import jp.agentec.abook.abv.ui.common.helper.ProgressDialogHelper;
import jp.agentec.abook.abv.ui.common.util.ABVToastUtil;
import jp.agentec.abook.abv.ui.common.util.AlertDialogUtil;
......@@ -176,43 +177,13 @@ public class ABookSettingFragment extends PreferenceFragment {
logoutAkert.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(R.string.confirm), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
logout();
LogoutHelper.logout(getActivity());
}
});
logoutAkert.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(R.string.cancel), (DialogInterface.OnClickListener) null);
showAlertDialog(logoutAkert);
}
private void logout() {
try {
// modify by Jang 2013.06.20
UserAuthenticateLogic user = AbstractLogic.getLogic(UserAuthenticateLogic.class);
// ログイン情報がある場合のみログアウト処理を行う
if (user.getMemberInfo() != null) {
user.signoutUser();
// Widgetへ通知
Intent intent = new Intent();
getActivity().sendBroadcast(intent);
}
} catch (Exception e) {
Logger.w("signoutUser failed at callLoginActivity", e);
ABVToastUtil.showMakeText(getActivity(), R.string.ERROR, Toast.LENGTH_SHORT);
}
// 新着更新が実行されている場合停止
((ABookSettingActivity)getActivity()).stopContentRefresher();
SharedPreferences sharedPreferences = getActivity().getSharedPreferences(AppDefType.PrefName.USER_PREFERENCE, Context.MODE_PRIVATE);
sharedPreferences.edit().remove(AppDefType.UserPrefKey.GUEST_LOGIN).commit();
Intent intent = new Intent(getActivity(), LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
getActivity().finish();
}
private void setLogInfoSetting() {
PreferenceGroup logInfo = (PreferenceGroup) findPreference(LOG_INFO);
// ログExport
......
......@@ -86,7 +86,7 @@ is_check_invalid_passward_limit=true
repeat_default=true
#Setting Info(設定画面のABookについての設定情報)
version_name=1.4.413
version_name=1.4.500
release_date=2023/04/25
copy_right=2016 AGENTEC Co.,Ltd. All rights reserved.
hope_page=http://www.agentec.jp
......
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