Commit 00767a1e by Lee Munkyeong

ローディング表示修正

parent 484b514b
package jp.agentec.abook.abv.bl.download;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import jdk.nashorn.internal.codegen.CompilerConstants;
import jp.agentec.abook.abv.bl.acms.client.AcmsClient;
import jp.agentec.abook.abv.bl.acms.client.json.ContentVersionsJSON;
import jp.agentec.abook.abv.bl.acms.client.parameters.ContentDownloadLogParameters;
import jp.agentec.abook.abv.bl.acms.client.parameters.FetchDateParameters;
import jp.agentec.abook.abv.bl.common.ABVEnvironment;
import jp.agentec.abook.abv.bl.common.Callback;
import jp.agentec.abook.abv.bl.common.exception.ABVException;
import jp.agentec.abook.abv.bl.common.exception.ABVExceptionCode;
import jp.agentec.abook.abv.bl.common.exception.NetworkDisconnectedException;
......@@ -123,6 +124,34 @@ public class ContentRefresher {
refreshWorker.start();
}
public void refreshContentList(ContentDownloadListener listener, Callback progressCallback) throws Exception {
if (contentDownloader.getActiveCount() > 0) { // コンテンツのダウンロード中は、自動更新を行わない。
contentDownloader.kickTask(); // waitingで止まらないように実行を促す
throw new ABVException(ABVExceptionCode.C_I_CONTENT_0002);
}
networkAdapter = ABVEnvironment.getInstance().networkAdapter;
if (networkAdapter != null && !networkAdapter.isNetworkConnected()) { // NWのチェック
throw new NetworkDisconnectedException();
}
if (!AcmsClient.getInstance(cache.getUrlPath(), networkAdapter).checkSid(cache.getMemberInfo().sid)) { // SIDのチェックをここで行う
throw new ABVException(ABVExceptionCode.S_E_ACMS_1403);
}
if (isRefreshing()) { // すでに実行中か
throw new ABVException(ABVExceptionCode.C_I_CONTENT_0001);
}
if (listener != null) {
contentDownloadListener = listener;
}
initializingRefreshing = true;
contentDownloader.pauseAll();
refreshWorker = new RefreshContentWorker(progressCallback);
refreshWorker.setPriority(Thread.MIN_PRIORITY);
refreshWorker.start();
}
public void addRefreshingContentId(long contentId) {
refreshingContentMap.put(contentId, false);
}
......@@ -146,48 +175,70 @@ public class ContentRefresher {
private class RefreshContentWorker extends Thread {
private boolean interrupt = false;
private Callback mProgressCallback;
public RefreshContentWorker(Callback progressCallback) {
mProgressCallback = progressCallback;
}
public RefreshContentWorker() {
}
public void stopWorker() {
interrupt = true;
}
@Override
public void run() {
Logger.i(TAG, "refresh main thread start.-----------------------------------------------");
interrupt = false;
try {
boolean isFinishedContentCheck = false;
boolean isFinishedContentCheck = false;
List<ContentDto> localContents = contentDao.getAllContents();
if (networkAdapter.isNetworkConnected()) { // オンライン時の処理
resendLog(); // ログ送信
contractLogic.initializeContractServiceOption(); // サービスオプション関連処理
if (mProgressCallback != null) {
mProgressCallback.callback(3);
}
groupLogic.initializeGroups(); // グループ設定(グループ変更の場合、FetchDateをクリアする)
if (mProgressCallback != null) {
mProgressCallback.callback(7);
}
categoryLogic.initializeCategories(); // カテゴリ設定
// 絞り検索マスタデータの最新更新された時のFetchDateを一時に保存する。
if (mProgressCallback != null) {
mProgressCallback.callback(5);
}
// CMSでメンテナンスされる絞り検索マスタデータをアプリから取得できるようにJSONファイルを生成する。
apertureMasterDataLogic.initializeApertureMasterData();
if (mProgressCallback != null) {
mProgressCallback.callback(5);
}
// 作業種別情報を取得
operationGroupMasterLogic.setOperationGroupMaster();
if (mProgressCallback != null) {
mProgressCallback.callback(5);
}
if (interrupt) { // この時点で停止要求が来た場合先には進まない。(ServiceOption/Group/Categoryの更新は1セットで行う(トランザクションはそれぞれ別))
Logger.d(TAG, "stop refresh worker before content update.");
setFail();
updateRefreshContentListState(-1L, null);
return;
}
isFinishedContentCheck = retrieveServerContent(localContents); // ContentVersionAPIを呼出し新規と更新の場合ContentInfoをDLする
isFinishedContentCheck = retrieveServerContent(localContents, mProgressCallback); // ContentVersionAPIを呼出し新規と更新の場合ContentInfoをDLする
}
deleteLocalContent(localContents, isFinishedContentCheck); // コンテンツ削除処理
initializingRefreshing = false;
if (!isRefreshing()) {
updateRefreshContentListState(-1L, null);
updateRefreshContentListState(-1L, null, mProgressCallback);
}
} catch (Exception e) {
Logger.e("refreshContent failed.", e);
updateRefreshContentListState(-1L, e);
......@@ -267,7 +318,7 @@ public class ContentRefresher {
* @return 変更あり:true、変更なし:false
* @throws Exception
*/
private boolean retrieveServerContent(List<ContentDto> localContents) throws Exception {
private boolean retrieveServerContent(List<ContentDto> localContents, Callback mProgressCallback) throws Exception {
// コンテンツバージョン用lastFetchDateの取得
AcmsDao dao = AbstractDao.getDao(AcmsDao.class);
String lastFetchDate = dao.selectContentVersionLastFetchDate();
......@@ -329,10 +380,37 @@ public class ContentRefresher {
}
}
}
if (mProgressCallback != null) {
mProgressCallback.callback(5);
}
return true;
}
}
public void updateRefreshContentListState(long contentId, Exception e, Callback mCallBack) {
Logger.d(TAG, "[updateRefreshContentListState]: contentId=%s", contentId);
//noinspection VariableNotUsedInsideIf
if (e != null) {
setFail();
}
if (contentDownloadListener != null) {
if (!isRefreshing() && e == null) {
// 新着処理が終わったら以下の処理が実行
try {
// サーバー通信でプロジェクト取得
mCallBack.callback(3);
operationLogic.initializeOperations(mCallBack);
} catch (Exception e1) {
Logger.e(TAG, e1);
e = e1;
}
}
contentDownloadListener.onRefreshedContent(e == null, contentId, e);
}
}
public void updateRefreshContentListState(long contentId, Exception e) {
Logger.d(TAG, "[updateRefreshContentListState]: contentId=%s", contentId);
//noinspection VariableNotUsedInsideIf
......@@ -354,7 +432,7 @@ public class ContentRefresher {
contentDownloadListener.onRefreshedContent(e == null, contentId, e);
}
}
public void stopRefresh() {
if (isRefreshing() && refreshWorker != null) {
refreshWorker.stopWorker();
......
......@@ -110,6 +110,14 @@ public class OperationLogic extends AbstractLogic {
retrieveServerOperation();
}
public void initializeOperations(Callback mCallBack) throws AcmsException, NetworkDisconnectedException {
// 作業グループリスト取得
setWorkingGroupList();
mCallBack.callback(20);
// 作業一覧取得し、登録・更新・削除する
retrieveServerOperation(mCallBack);
}
/**
* 作業一覧取得し、登録・更新・削除する
*
......@@ -281,6 +289,162 @@ public class OperationLogic extends AbstractLogic {
}
}
private void retrieveServerOperation(Callback mCallBack) throws AcmsException, NetworkDisconnectedException {
List<OperationDto> localOperations = mOperationDao.getAllOperation();
AcmsParameters param = new AcmsParameters(cache.getMemberInfo().sid);
OperationListJSON json = AcmsClient.getInstance(cache.getUrlPath(), networkAdapter).getOperationList(param);
List<OperationDto> serverOperations = json.operationList;
for (OperationDto serverOperationDto : serverOperations) {
// 登録フラグ
boolean insertFlg = true;
for (OperationDto localOperationDto : localOperations) {
if (serverOperationDto.operationId.equals(localOperationDto.operationId)) {
//update
serverOperationDto.needSyncFlg = serverOperationDto.equalsLastEdit(localOperationDto) ? localOperationDto.needSyncFlg : true;
List<Long> localOperationContentIds = mOperationContentDao.getContentIds(serverOperationDto.operationId);
for (OperationContentDto operationContentDto : serverOperationDto.operationContentDtoList) {
if (localOperationContentIds == null || localOperationContentIds.size() == 0) {
// insert
mOperationContentDao.insertOperationContent(operationContentDto);
} else {
int localOperationContentIndex = localOperationContentIds.indexOf(operationContentDto.contentId);
if (localOperationContentIndex >= 0) {
// 存在する
localOperationContentIds.remove(localOperationContentIndex);
} else {
// insert
mOperationContentDao.insertOperationContent(operationContentDto);
}
}
}
if (localOperationContentIds != null) {
// 関連資料の削除処理
for (Long deleteContentId : localOperationContentIds) {
mOperationContentDao.deleteOperationContent(localOperationDto.operationId, deleteContentId);
}
}
if (mOperationContentDao.isExistMainOperationContent(serverOperationDto.operationId)) {
serverOperationDto.contentCreatingFlg = false;
}
// ローカルにある作業情報に紐づく全作業IDを取得
List<Integer> localOperationGroupMasterIds = mOperationGroupMasterOperationDao.getOperationGroupMasterIds(serverOperationDto.operationId);
for (OperationGroupMasterRelationDto operationGroupMasterRelationDto : serverOperationDto.operationGroupMasterRelationDtoList) {
if (localOperationGroupMasterIds == null || localOperationGroupMasterIds.size() == 0) {
// 作業IDが存在しなければ、登録する
mOperationGroupMasterOperationDao.insertOperationGroupMasterOperation(operationGroupMasterRelationDto);
} else {
// ローカル(DB)に作業IDが存在するかチェックして更新・登録を判定
int localOperationContentIndex = localOperationGroupMasterIds.indexOf(operationGroupMasterRelationDto.operationGroupMasterId);
if (localOperationContentIndex >= 0) {
// 作業IDが存在するので更新
localOperationGroupMasterIds.remove(localOperationContentIndex);
} else {
// 作業IDが存在しないので登録
mOperationGroupMasterOperationDao.insertOperationGroupMasterOperation(operationGroupMasterRelationDto);
}
}
}
if (localOperationGroupMasterIds != null) {
// ローカルとサーバーの差分は削除と見做し、削除処理を行う。
for (Integer deleteOperationGroupMasterId : localOperationGroupMasterIds) {
mOperationGroupMasterOperationDao.deleteOperationGroupMasterOperation(deleteOperationGroupMasterId, serverOperationDto.operationId);
}
}
mOperationDao.update(serverOperationDto);
// 更新することで登録フラグをfalseにセット
insertFlg = false;
break;
}
mCallBack.callback(1);
}
// 更新されたら以下の処理は行わない
if (insertFlg) {
boolean isNotExistContent = false;
for (OperationContentDto operationContentDto : serverOperationDto.operationContentDtoList) {
if (operationContentDto.operationContentFlg) {
if(mContentDao.getContent(operationContentDto.contentId) == null) {
isNotExistContent = true;
}
}
}
// コンテンツテーブルに存在しない場合、プロジェクトを登録しない
if (isNotExistContent) { continue; }
serverOperationDto.needSyncFlg = true;
serverOperationDto.contentCreatingFlg = false;
mOperationDao.insert(serverOperationDto);
// 関連資料の登録
for (OperationContentDto operationContentDto : serverOperationDto.operationContentDtoList) {
mOperationContentDao.insertOperationContent(operationContentDto);
}
// 作業種別・作業のリレーションテーブルにデータ登録
for (OperationGroupMasterRelationDto operationGroupMasterRelationDto : serverOperationDto.operationGroupMasterRelationDtoList) {
mOperationGroupMasterOperationDao.insertOperationGroupMasterOperation(operationGroupMasterRelationDto);
}
mCallBack.callback(2);
}
// 作業担当グループ登録
mTaskWorkerGroupDao.deleteByOperationId(serverOperationDto.operationId);
for (TaskWorkerGroupDto taskWorkerGroupDto : serverOperationDto.taskWorkerGroupDtoList) {
taskWorkerGroupDto.operationId = serverOperationDto.operationId;
for (Integer groupId : taskWorkerGroupDto.groupList) {
taskWorkerGroupDto.groupId = groupId;
mTaskWorkerGroupDao.insert(taskWorkerGroupDto);
}
}
for (PushMessageDto dto : serverOperationDto.pushMessageList) {
mPushMessageDao.insert(dto);
}
}
List<OperationDto> deleteListDtoArray = new ArrayList<OperationDto>();
for (OperationDto localProjcetDto : localOperations) {
boolean deleteFlg = true;
for (OperationDto serverOperationDto : serverOperations) {
if (localProjcetDto.operationId.equals(serverOperationDto.operationId)) {
deleteFlg = false;
break;
}
}
if (deleteFlg) {
deleteListDtoArray.add(localProjcetDto);
}
}
// サーバーから取得した作業情報がローカルに存在しないので削除する
for (OperationDto deleteOperationDto : deleteListDtoArray) {
List<TaskDto> taskDtoList = mTaskDao.selectAllTaskByOperationId(deleteOperationDto.operationId);
List<Long> contentIds = mOperationContentDao.getContentIds(deleteOperationDto.operationId);
for(TaskDto taskDto : taskDtoList) {
mTaskDao.delete(taskDto);
}
mPushMessageDao.delete(deleteOperationDto.operationId);
mOperationDao.delete(deleteOperationDto);
// 作業削除時、紐づいた資料を削除
for (Long contentId : contentIds) {
if (mOperationContentDao.isDeleteContent(contentId)) {
ContentDto contentDto = mContentDao.getContent(contentId);
mContentLogic.deleteContent(contentDto, true);
}
}
if (mCallBack != null) {
mCallBack.callback(5);
}
String operationTaskDirPath = ABVEnvironment.getInstance().getOperationDirFile(deleteOperationDto.operationId);
FileUtil.delete(operationTaskDirPath);
}
}
/**
* サーバーから作業者グループ取得し、m_worker_groupテーブルへ登録
*
......
......@@ -2,6 +2,7 @@ package jp.agentec.abook.abv.ui.common.activity;
import jp.agentec.abook.abv.bl.acms.type.DownloadStatusType;
import jp.agentec.abook.abv.bl.common.ABVEnvironment;
import jp.agentec.abook.abv.bl.common.Callback;
import jp.agentec.abook.abv.bl.common.CommonExecutor;
import jp.agentec.abook.abv.bl.common.exception.ABVException;
import jp.agentec.abook.abv.bl.common.exception.ABVExceptionCode;
......@@ -27,6 +28,7 @@ import jp.agentec.abook.abv.ui.common.util.LogUtil;
import jp.agentec.abook.abv.ui.home.activity.ABookSettingActivity;
import jp.agentec.abook.abv.ui.home.helper.ActivityHandlingHelper;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
......@@ -159,7 +161,7 @@ public abstract class ABVUIActivity extends ABVAuthenticatedActivity {
return super.onKeyUp(keyCode, event);
}
public boolean refreshContent(boolean isAutoRefresh) throws NetworkDisconnectedException {
boolean result = true;
try {
......@@ -167,7 +169,6 @@ public abstract class ABVUIActivity extends ABVAuthenticatedActivity {
Logger.d(TAG, "contentDownloader.isRefreshing() %s", result);
getABVUIDataCache().preIsCatalogEdition = ABVDataCache.getInstance().serviceOption.isCatalogEdition();
if (!result) {
startUpdateAnimation();
// contentDownloadObserverがnullだと更新マークのアニメーションが完了しない TODO 2014/11/12 Jang
......@@ -223,6 +224,33 @@ public abstract class ABVUIActivity extends ABVAuthenticatedActivity {
return result;
}
public boolean refreshContent(boolean isAutoRefresh, Callback progressCallback) throws Exception {
boolean result = true;
try {
result = contentRefresher.isRefreshing();
Logger.d(TAG, "contentDownloader.isRefreshing() %s", result);
getABVUIDataCache().preIsCatalogEdition = ABVDataCache.getInstance().serviceOption.isCatalogEdition();
if (!result) {
startUpdateAnimation();
// contentDownloadObserverがnullだと更新マークのアニメーションが完了しない TODO 2014/11/12 Jang
// onCreateでrefresh処理をcallしたときに起きる
contentRefresher.refreshContentList(this, progressCallback);
// ログ送信可否を確認
LogUtil.checkSendLogFlag();
}
} catch (Exception e) {
stopUpdateAnimation();
if (startRefresh) {
startRefresh = false;
}
throw e;
}
return result;
}
/** 
* グリッド初期化
* onCreateでは呼ばないないこと!!
......@@ -246,6 +274,15 @@ public abstract class ABVUIActivity extends ABVAuthenticatedActivity {
return false;
}
protected boolean dataRefresh(boolean isAutoRefresh, Callback progressCallback) throws NetworkDisconnectedException {
try {
return refreshContent(isAutoRefresh, progressCallback);
} catch (Exception e) {
Logger.e(TAG, "dataRefresh Fail" + e);
throw e;
}
}
// // @{ABVAuthenticatedActivity.contentLinkCheckDeliverable}と同じ
// //非公開と期間終了のコンテンツがある場合削除
......
......@@ -77,11 +77,16 @@ import jp.agentec.abook.abv.bl.dto.OperationGroupMasterDto;
import jp.agentec.abook.abv.bl.dto.TaskDto;
import jp.agentec.abook.abv.bl.dto.TaskReportDto;
import jp.agentec.abook.abv.bl.logic.AbstractLogic;
import jp.agentec.abook.abv.bl.logic.ApertureMasterDataLogic;
import jp.agentec.abook.abv.bl.logic.CategoryLogic;
import jp.agentec.abook.abv.bl.logic.ContractLogic;
import jp.agentec.abook.abv.bl.logic.GroupLogic;
import jp.agentec.abook.abv.bl.logic.OperationGroupMasterLogic;
import jp.agentec.abook.abv.bl.logic.OperationLogic;
import jp.agentec.abook.abv.bl.logic.PushMessageLogic;
import jp.agentec.abook.abv.cl.util.PreferenceUtil;
import jp.agentec.abook.abv.launcher.android.R;
import jp.agentec.abook.abv.ui.common.util.LogUtil;
import jp.agentec.abook.abv.ui.viewer.activity.OnlineHTMLWebViewActivity;
import jp.agentec.abook.abv.ui.common.activity.ABVUIActivity;
import jp.agentec.abook.abv.ui.common.appinfo.AppDefType.OperationLocationType;
......@@ -142,6 +147,8 @@ public class OperationListActivity extends ABVUIActivity {
private OperationLogic mOperationLogic = AbstractLogic.getLogic(OperationLogic.class);
private OperationGroupMasterLogic mOperationGroupMasterLogic = AbstractLogic.getLogic(OperationGroupMasterLogic.class);
private PushMessageLogic mPushMessageLogic = AbstractLogic.getLogic(PushMessageLogic.class);
private TaskDao mTaskDao = AbstractDao.getDao(TaskDao.class);
private boolean activityResultFlg;
......@@ -348,10 +355,37 @@ public class OperationListActivity extends ABVUIActivity {
handler.post(new Runnable() {
@Override
public void run() {
showProgressPopup();
showProgressView("");
}
});
dataRefresh(true);
final Callback progressCallback = new Callback() {
@Override
public Object callback(Object ret) {
final int progress = (int)ret;
runOnUiThread(new Runnable() {
@Override
public void run() {
if ((progressDialogHorizontal.getProgress() + progress) < 100) {
progressDialogHorizontal.setProgress(progressDialogHorizontal.getProgress() + progress);
} else {
progressDialogHorizontal.setProgress(100);
}
}
});
return null;
}
};
try {
dataRefresh(true, progressCallback);
} catch (Exception e) {
handler.post(new Runnable() {
@Override
public void run() {
closeProgressPopup();
}
});
}
break;
case ABookKeys.CMD_KEY.CHANGE_OPERATION_GROUP_MASTER:
......
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