Commit f9af92e0 by NGUYEN HOANG SON

implement auto sync 1->7

parent f3cacd09
...@@ -82,6 +82,9 @@ public class ABVBatchSyncView extends ProgressDialog { ...@@ -82,6 +82,9 @@ public class ABVBatchSyncView extends ProgressDialog {
// Activity破棄フラグがtrue、またはスタックが存在しなければ、全て完了と見做す // Activity破棄フラグがtrue、またはスタックが存在しなければ、全て完了と見做す
closeProgressDialog(); closeProgressDialog();
Logger.d(TAG, "---batchSync is end"); Logger.d(TAG, "---batchSync is end");
if (mOperationListActivity != null && mOperationListActivity.isAutoSyncing) {
mOperationListActivity.autoSyncOperationDone(true);
}
return; return;
} }
// ベース資料のダウンロードチェック // ベース資料のダウンロードチェック
...@@ -97,6 +100,9 @@ public class ABVBatchSyncView extends ProgressDialog { ...@@ -97,6 +100,9 @@ public class ABVBatchSyncView extends ProgressDialog {
// error // error
showBatchSyncErrorAlert(peekOperationDto, mOperationListActivity.getString(R.string.msg_batch_sync_content_download_fail)); showBatchSyncErrorAlert(peekOperationDto, mOperationListActivity.getString(R.string.msg_batch_sync_content_download_fail));
} }
if (mOperationListActivity != null && mOperationListActivity.isAutoSyncing) {
mOperationListActivity.autoSyncOperationDone(false);
}
return; return;
} }
// 同期処理 // 同期処理
......
...@@ -206,6 +206,9 @@ public class OperationListActivity extends OperationActivity { ...@@ -206,6 +206,9 @@ public class OperationListActivity extends OperationActivity {
// 作業種別のサービスオプション値を保持用フラグ // 作業種別のサービスオプション値を保持用フラグ
private boolean mOperationGroupMasterServiceOperationFlg; private boolean mOperationGroupMasterServiceOperationFlg;
public boolean isAutoSyncing;
public Long autoSyncOpenOperationId = null;
public Long mQrCodeOperationId = null; public Long mQrCodeOperationId = null;
// ビューの作成 // ビューの作成
private class ReloadHandler implements Runnable { private class ReloadHandler implements Runnable {
...@@ -478,6 +481,37 @@ public class OperationListActivity extends OperationActivity { ...@@ -478,6 +481,37 @@ public class OperationListActivity extends OperationActivity {
// ビューを作り直す // ビューを作り直す
setOperationListView(); setOperationListView();
} }
if (isAutoSync()) {
if (isAutoSyncing) {
if (result) {
// content update success
List<OperationDto> needSyncOperationList = new ArrayList<>();
if (autoSyncOpenOperationId != null) {
OperationDto operationDto = mOperationLogic.getOperation(autoSyncOpenOperationId);
if (operationDto.needSyncFlg) {
needSyncOperationList.add(operationDto);
}
} else {
for (OperationDto operationDto : mOperationDao.getAllOperation()) {
if (operationDto.needSyncFlg) {
needSyncOperationList.add(operationDto);
}
}
}
needSyncOperationList.addAll(mOperationDao.getAllOperation());
if (needSyncOperationList.size() > 0) {
categoryBatchSync(needSyncOperationList);
} else {
// donot need sync
autoSyncOperationDone(true);
}
} else {
// content update fail
autoSyncOperationDone(false);
}
}
return;
}
//「I/O 帳票使用」がYESのみ、新着更新処理完了後、一括同期処理を開始する。 //「I/O 帳票使用」がYESのみ、新着更新処理完了後、一括同期処理を開始する。
if (ABVDataCache.getInstance().serviceOption.isUnableIOReport()) { if (ABVDataCache.getInstance().serviceOption.isUnableIOReport()) {
if (mAutoBatchSyncFlg) { if (mAutoBatchSyncFlg) {
...@@ -509,68 +543,71 @@ public class OperationListActivity extends OperationActivity { ...@@ -509,68 +543,71 @@ public class OperationListActivity extends OperationActivity {
refreshOperationList(); refreshOperationList();
// 作業指示・報告からプロジェクト一覧へ戻った時の同期処理 // 作業指示・報告からプロジェクト一覧へ戻った時の同期処理
if (ABVEnvironment.getInstance().networkAdapter.isNetworkConnected()) { if (ABVEnvironment.getInstance().networkAdapter.isNetworkConnected()) {
final long operationId = getUserPref(AppDefType.UserPrefKey.SYNC_TARGET_OPERATION_ID, -1L); if (isAutoSync()) {
if (operationId != -1) { autoSyncOperation();
final OperationDto operationDto = mOperationLogic.getOperation(operationId); } else {
// リソースパターンの適用 final long operationId = getUserPref(AppDefType.UserPrefKey.SYNC_TARGET_OPERATION_ID, -1L);
showProgressView(PatternStringUtil.patternToString(getApplicationContext(), if (operationId != -1) {
R.string.synchronizing, final OperationDto operationDto = mOperationLogic.getOperation(operationId);
getUserPref(AppDefType.UserPrefKey.RESOURCE_PATTERN_TYPE, 0))); // リソースパターンの適用
CommonExecutor.execute(new Runnable() { showProgressView(PatternStringUtil.patternToString(getApplicationContext(),
@Override R.string.synchronizing,
public void run() { getUserPref(AppDefType.UserPrefKey.RESOURCE_PATTERN_TYPE, 0)));
Logger.d(TAG, "onResume Sync operationId : " + operationId); CommonExecutor.execute(new Runnable() {
if (operationDto != null && operationDto.needSyncFlg) { @Override
// 同期処理後、直列処理で新着更新を行う。 public void run() {
singleSyncOperation(operationId, operationDto.reportType); Logger.d(TAG, "onResume Sync operationId : " + operationId);
if (operationDto != null && operationDto.needSyncFlg) {
//「I/O 帳票使用」がYESのみ、カテゴリ一括動機実施 // 同期処理後、直列処理で新着更新を行う。
if (ABVDataCache.getInstance().serviceOption.isUnableIOReport()) { singleSyncOperation(operationId, operationDto.reportType);
//同期中のインジケーター表示中には新着更新中のインジケーター表示できないので、チェックする。
while (progressDialogHorizontalShowing()) { //「I/O 帳票使用」がYESのみ、カテゴリ一括動機実施
try { if (ABVDataCache.getInstance().serviceOption.isUnableIOReport()) {
Thread.sleep(100); //同期中のインジケーター表示中には新着更新中のインジケーター表示できないので、チェックする。
} catch (InterruptedException ie) { while (progressDialogHorizontalShowing()) {
Logger.e(TAG, "sleep error = " + ie.getLocalizedMessage()); try {
} Thread.sleep(100);
} } catch (InterruptedException ie) {
//新着更新後、一括同期処理を行うため、インジケーター表示 Logger.e(TAG, "sleep error = " + ie.getLocalizedMessage());
handler.post(new Runnable() { }
@Override
public void run() {
showProgressPopup(PatternStringUtil.patternToString(getApplicationContext(),
R.string.updating,
getUserPref(AppDefType.UserPrefKey.RESOURCE_PATTERN_TYPE, 0)));
} }
}); //新着更新後、一括同期処理を行うため、インジケーター表示
mAutoBatchSyncFlg = true; handler.post(new Runnable() {
//表示作業数が10個以上の場合、2秒待機してから新着更新を行う。10個未満は1秒待機 @Override
List<OperationDto> operationList = mListHelper.getOperationList(); public void run() {
int delaySeconds = 1000; showProgressPopup(PatternStringUtil.patternToString(getApplicationContext(),
if (operationList.size() >= DELAY_2SECONDS_OPERATION_MAX_COUNT) { R.string.updating,
delaySeconds = 2000; getUserPref(AppDefType.UserPrefKey.RESOURCE_PATTERN_TYPE, 0)));
} }
handler.postDelayed(new Runnable() { });
@Override mAutoBatchSyncFlg = true;
public void run() { //表示作業数が10個以上の場合、2秒待機してから新着更新を行う。10個未満は1秒待機
dataRefresh(true); List<OperationDto> operationList = mListHelper.getOperationList();
int delaySeconds = 1000;
if (operationList.size() >= DELAY_2SECONDS_OPERATION_MAX_COUNT) {
delaySeconds = 2000;
} }
}, delaySeconds); handler.postDelayed(new Runnable() {
@Override
public void run() {
dataRefresh(true);
}
}, delaySeconds);
}
} else {
closeProgressPopup();
dataRefresh(true);
} }
} else {
closeProgressPopup();
dataRefresh(true);
}
} }
}); });
} }
if (!activityResultFlg && operationId == -1) { if (!activityResultFlg && operationId == -1) {
dataRefresh(true); dataRefresh(true);
}
} }
} }
putUserPref(AppDefType.UserPrefKey.SYNC_TARGET_OPERATION_ID, -1L); putUserPref(AppDefType.UserPrefKey.SYNC_TARGET_OPERATION_ID, -1L);
activityResultFlg = false; activityResultFlg = false;
...@@ -1855,6 +1892,10 @@ public class OperationListActivity extends OperationActivity { ...@@ -1855,6 +1892,10 @@ public class OperationListActivity extends OperationActivity {
refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(lastUpdateTimeLabel); refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(lastUpdateTimeLabel);
} }
} }
if (needAutoSync()) {
autoSyncOperation();
return;
}
CommonExecutor.execute(new Runnable() { CommonExecutor.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -1892,7 +1933,10 @@ public class OperationListActivity extends OperationActivity { ...@@ -1892,7 +1933,10 @@ public class OperationListActivity extends OperationActivity {
refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(lastUpdateTimeLabel); refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(lastUpdateTimeLabel);
} }
} }
if (needAutoSync()) {
autoSyncOperation();
return;
}
CommonExecutor.execute(new Runnable() { CommonExecutor.execute(new Runnable() {
@Override @Override
public void run() { public void run() {
...@@ -2393,4 +2437,42 @@ public class OperationListActivity extends OperationActivity { ...@@ -2393,4 +2437,42 @@ public class OperationListActivity extends OperationActivity {
Logger.w(TAG,"Camera Permission false"); Logger.w(TAG,"Camera Permission false");
} }
} }
private boolean isAutoSync() {
return PreferenceUtil.get(getApplicationContext(), AppDefType.UserPrefKey.OPERATION_AUTO_SYNC, false);
}
public boolean needAutoSync() {
return (isAutoSync() && ABVEnvironment.getInstance().networkAdapter.isNetworkConnected());
}
public void autoSyncOperation() {
if (isAutoSyncing) {
return;
}
isAutoSyncing = true;
showProgressView(PatternStringUtil.patternToString(getApplicationContext(),
R.string.synchronizing,
getUserPref(AppDefType.UserPrefKey.RESOURCE_PATTERN_TYPE, 0)));
CommonExecutor.execute(new Runnable() {
@Override
public void run() {
dataRefresh(true);
if (!contentRefresher.isRefreshing()) {
autoSyncOperationDone(false);
}
}
});
}
public void autoSyncOperationDone(boolean isSuccess) {
isAutoSyncing = false;
closeProgressPopup();
if (isSuccess) {
if (autoSyncOpenOperationId != null) {
OperationDto operationDto = mOperationLogic.getOperation(autoSyncOpenOperationId);
openReportView(operationDto);
}
}
autoSyncOpenOperationId = null;
}
} }
...@@ -148,18 +148,7 @@ public abstract class OperationListHelper { ...@@ -148,18 +148,7 @@ public abstract class OperationListHelper {
adapter.setAdapterListener(new AbstractOperationAdapter.AbstractOperationListAdapterListener() { adapter.setAdapterListener(new AbstractOperationAdapter.AbstractOperationListAdapterListener() {
@Override @Override
public void openReport(OperationDto operationDto) { public void openReport(OperationDto operationDto) {
if (operationDto.contentId != null && operationDto.contentId != 0) { onClickReport(operationDto);
// 作業画面
mAppActivity.openReportView(operationDto);
} else {
if (operationDto.operationType == PANO) {
// パノラマ登録画面
mAppActivity.showPanoEntryDialog(operationDto);
} else {
// 何もしない
Logger.e("not open target");
}
}
} }
@Override @Override
...@@ -211,18 +200,7 @@ public abstract class OperationListHelper { ...@@ -211,18 +200,7 @@ public abstract class OperationListHelper {
adapter.setAdapterListener(new AbstractOperationAdapter.AbstractOperationListAdapterListener() { adapter.setAdapterListener(new AbstractOperationAdapter.AbstractOperationListAdapterListener() {
@Override @Override
public void openReport(OperationDto operationDto) { public void openReport(OperationDto operationDto) {
if (operationDto.contentId != null && operationDto.contentId != 0) { onClickReport(operationDto);
// 作業画面
mAppActivity.openReportView(operationDto);
} else {
if (operationDto.operationType == PANO) {
// パノラマ登録画面
mAppActivity.showPanoEntryDialog(operationDto);
} else {
// 何もしない
Logger.e("not open target");
}
}
} }
@Override @Override
...@@ -285,4 +263,24 @@ public abstract class OperationListHelper { ...@@ -285,4 +263,24 @@ public abstract class OperationListHelper {
*/ */
abstract protected List<OperationDto> findOperationList() throws Exception; abstract protected List<OperationDto> findOperationList() throws Exception;
public void onClickReport(OperationDto operationDto) {
if (mAppActivity.needAutoSync()) {
mAppActivity.autoSyncOpenOperationId = operationDto.operationId;
mAppActivity.autoSyncOperation();
return;
}
if (operationDto.contentId != null && operationDto.contentId != 0) {
// 作業画面
mAppActivity.openReportView(operationDto);
} else {
if (operationDto.operationType == PANO) {
// パノラマ登録画面
mAppActivity.showPanoEntryDialog(operationDto);
} else {
// 何もしない
Logger.e("not open target");
}
}
}
} }
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