Commit e67f928b by onuma

文字列修正。URL修正。文言取得をContentsLogicクラスへ移動。

parent 85d821f7
package jp.agentec.abook.abv.bl.logic;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
......@@ -30,7 +35,11 @@ import jp.agentec.abook.abv.bl.dto.ContentDto;
import jp.agentec.abook.abv.bl.dto.ContentPageDto;
import jp.agentec.abook.abv.bl.dto.ContentTagDto;
import jp.agentec.abook.abv.bl.dto.comparator.ContentPageDtoComparator;
import jp.agentec.adf.net.http.HttpParameterObject;
import jp.agentec.adf.net.http.HttpRequestSender;
import jp.agentec.adf.net.http.HttpResponse;
import jp.agentec.adf.util.FileUtil;
import jp.agentec.adf.util.NumericUtil;
import jp.agentec.adf.util.StringUtil;
/**
......@@ -512,4 +521,45 @@ public class ContentLogic extends AbstractLogic {
}
return new ContentJSON(text);
}
/**
* 利用規約の詳細文を取得する
* @param url 取得しに行くURL
* @return 取得した文字列(失敗したらnullが返る)
*/
public String getTermsOfServiceText(String url, String laungage) {
HttpResponse response = new HttpResponse();
HttpURLConnection conn = null;
try {
URL requestUrl = new URL(url + "?language=" + laungage);
conn = HttpRequestSender.openConnection("GET", requestUrl, "UTF-8", null, null, 5000);
Logger.i(TAG,"responseCode : " + conn.getResponseCode());
response.httpResponseCode = conn.getResponseCode();
if (response.httpResponseCode != 200) {
return null;
}
response.httpResponseMessage = conn.getResponseMessage();
response.contentLength = NumericUtil.parseLong(conn.getHeaderField("Content-Length"), 0);
InputStream inputStream = conn.getInputStream();
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
String resultJson = new String();
String str;
while ( null != ( str = bufferReader.readLine() ) ) {
resultJson = resultJson + str;
}
bufferReader.close();
Logger.d(TAG,"response JSON : " + resultJson);
return resultJson;
} catch (IOException e) {
Logger.e(e.getMessage());
} catch (NumberFormatException e) {
Logger.e(e.getMessage());
} finally {
if (conn != null) {
conn.disconnect();
}
}
return null;
}
}
......@@ -1511,4 +1511,5 @@
<string name="btn_print">PDF</string>
<string name="msg_agree_to_terms_of_use">利用規約に同意する</string>
<string name="clickable_detail_button">(詳細)</string>
<string name="err_gert_term_of_use_text">利用規約の取得に失敗しました。ネットワークの接続状態を確認してください。</string>
</resources>
......@@ -1516,4 +1516,5 @@
<string name="btn_print">PDF</string>
<string name="msg_agree_to_terms_of_use">이용약관에 동의함</string>
<string name="clickable_detail_button">(상세)</string>
<string name="err_gert_term_of_use_text">이용약관을 얻지 못했습니다. 네트워크 연결 상태를 확인해주세요.</string>
</resources>
\ No newline at end of file
......@@ -1512,4 +1512,5 @@
<string name="btn_print">PDF</string>
<string name="msg_agree_to_terms_of_use">I agree to the terms of use</string>
<string name="clickable_detail_button">(detail)</string>
<string name="err_gert_term_of_use_text">Failed to get the terms of use. Check the network connection status.</string>
</resources>
......@@ -84,7 +84,7 @@
android:layout_gravity="center" />
<TextView
android:id="@+id/textView6"
android:id="@+id/terms_of_use_text"
android:layout_width="match_parent"
android:layout_height="46dp"
android:layout_gravity="left"
......
......@@ -57,6 +57,7 @@ import jp.agentec.abook.abv.bl.dto.MemberInfoDto;
import jp.agentec.abook.abv.bl.dto.PasswordLockInfoDto;
import jp.agentec.abook.abv.bl.logic.AbstractLogic;
import jp.agentec.abook.abv.bl.logic.CommunicationLogic;
import jp.agentec.abook.abv.bl.logic.ContentLogic;
import jp.agentec.abook.abv.bl.logic.ContractLogic;
import jp.agentec.abook.abv.bl.logic.OperationLogic;
import jp.agentec.abook.abv.bl.logic.UserAuthenticateLogic;
......@@ -112,9 +113,10 @@ public class LoginActivity extends ABVLoginActivity {
private Button btnLoginOff;
private Button btnLoginOn;
private Button btnDetail;
private CheckBox chexBoxAgree;
private String detail_text = "";
private static String agreementUrl = ABVEnvironment.getInstance().agree_to_terms_of_use_url;
private String termsOfUseText = "";
private static String termsOfUseUrl = ABVEnvironment.getInstance().agree_to_terms_of_use_url;
@Override
public void onCreate(Bundle savedInstanceState) {
......@@ -170,7 +172,7 @@ public class LoginActivity extends ABVLoginActivity {
}
});
// ログインボタン(最初はGONEにして見せない)
// 活性化したログインボタン。
btnLoginOn = findViewById(R.id.btn_login_on);
btnLoginOn.setOnClickListener(new View.OnClickListener() {
@Override
......@@ -178,6 +180,7 @@ public class LoginActivity extends ABVLoginActivity {
tryLogin();
}
});
// 非活性化したログインボタン
btnLoginOff = findViewById(R.id.btn_login_off);
btnLoginOff.setVisibility(View.VISIBLE);
......@@ -205,6 +208,16 @@ public class LoginActivity extends ABVLoginActivity {
}
});
// agreementUrl が 空の場合は、チェックボックスなどを消す
if (StringUtil.isNullOrEmpty(termsOfUseUrl)) {
chexBoxAgree.setVisibility(View.GONE);
findViewById(R.id.terms_of_use_text).setVisibility(View.GONE);
findViewById(R.id.detail).setVisibility(View.GONE);
// ログインボタン
btnLoginOff.setVisibility(View.GONE);
btnLoginOn.setVisibility(View.VISIBLE);
}
//androidバジョン6以上からMAC idではなくandroid固有numberを取得ため、ダイアログで表示
if (android.os.Build.VERSION.SDK_INT >= 23) {
mBtnDeviceInfo.setVisibility(View.VISIBLE);
......@@ -245,39 +258,51 @@ public class LoginActivity extends ABVLoginActivity {
}
// 詳細ボタン
Button btnDetail = findViewById(R.id.detail);
btnDetail = findViewById(R.id.detail);
btnDetail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
btnDetail.setEnabled(false); // 非活性化(連打防止)
// ネットワーク接続チェック
if (!ABVEnvironment.getInstance().networkAdapter.isNetworkConnected()) {
AlertDialogUtil.showAlertDialog(LoginActivity.this, getString(R.string.error), getString(R.string.err_gert_term_of_use_text), true, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
btnDetail.setEnabled(true); // 活性化
}
});
return;
}
CommonExecutor.execute(new Runnable() {
@Override
public void run() {
// CMSより文言を取得し、ダイアログで表示する。
detail_text = getAgreementText();
ContentLogic logic = AbstractLogic.getLogic(ContentLogic.class);
String language = Locale.getDefault().getLanguage();
termsOfUseText = logic.getTermsOfServiceText(termsOfUseUrl, language);
runOnUiThread(new Runnable() {
@Override
public void run() {
final ABookAlertDialog messageDialog = AlertDialogUtil.createAlertDialog(LoginActivity.this, R.string.error);
if (detail_text != null) {
JSONObject detail_json = new JSONObject(detail_text);
String messageText = getString(R.string.err_gert_term_of_use_text);
if (termsOfUseText != null) {
JSONObject detail_json = new JSONObject(termsOfUseText);
Locale locale = Locale.getDefault();
if (locale.getLanguage().equals("ja")) {
messageDialog.setMessage(detail_json.getString("ja"));
messageText = detail_json.getString("ja");
} else if (locale.getLanguage().equals("ko")) {
messageDialog.setMessage(detail_json.getString("ko"));
messageText = detail_json.getString("ko");
} else {
messageDialog.setMessage(detail_json.getString("en"));
messageText = detail_json.getString("en");
}
} else {
messageDialog.setMessage(R.string.NETWORK);
}
messageDialog.setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {
AlertDialogUtil.showAlertDialog(LoginActivity.this, getString(R.string.error), messageText, true, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
btnDetail.setEnabled(true); // 活性化
}
});
messageDialog.show();
}
});
}
......@@ -286,48 +311,6 @@ public class LoginActivity extends ABVLoginActivity {
});
}
/**
* 利用規約の詳細文を取得する
* @return 取得した文字列(失敗したらnullが返る)
*/
private String getAgreementText() {
HttpResponse response = new HttpResponse();
HttpURLConnection conn = null;
try {
java.net.URL url = new URL(agreementUrl);
Logger.d(TAG, "url=" + url);
conn = HttpRequestSender.openConnection("GET", url, "UTF-8", null, null, 5000);
Logger.i(TAG,"responseCode : " + conn.getResponseCode());
response.httpResponseCode = conn.getResponseCode();
if (response.httpResponseCode != 200) {
return null;
}
response.httpResponseMessage = conn.getResponseMessage();
response.contentLength = NumericUtil.parseLong(conn.getHeaderField("Content-Length"), 0);
InputStream inputStream = conn.getInputStream();
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
String resultJson = new String();
String str;
while ( null != ( str = bufferReader.readLine() ) ) {
resultJson = resultJson + str;
}
bufferReader.close();
Logger.i(TAG,"response JSON : " + resultJson);
return resultJson;
} catch (IOException e) {
Logger.e(e.getMessage());
} catch (NumberFormatException e) {
Logger.e(e.getMessage());
} finally {
if (conn != null) {
conn.disconnect();
}
}
return null;
}
@Override
public void onResume() {
Logger.i(TAG, "onResume");
......@@ -495,9 +478,12 @@ public class LoginActivity extends ABVLoginActivity {
return false;
}
}
if (!chexBoxAgree.isChecked()) {
handleErrorMessageToast(ErrorCode.E132);
return false;
if (!StringUtil.isNullOrEmpty(termsOfUseUrl)) {
if (!chexBoxAgree.isChecked()) {
handleErrorMessageToast(ErrorCode.E132);
return false;
}
}
return true;
}
......
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