@@ -173,8 +173,8 @@ public class MainActivity extends BaseActivity implements MainContract.View {
|
||
| 173 | 173 |
} |
| 174 | 174 |
|
| 175 | 175 |
@Override |
| 176 |
- public void showBoxUpgradeActivity(String bpversion_str) {
|
|
| 177 |
- BoxUpgradeActivity.startBoxUpgradeActivity(this,bpversion_str); |
|
| 176 |
+ public void showBoxUpgradeActivity(String bpversion_str,int updatingVersionCode) {
|
|
| 177 |
+ BoxUpgradeActivity.startBoxUpgradeActivity(this,bpversion_str,updatingVersionCode); |
|
| 178 | 178 |
} |
| 179 | 179 |
|
| 180 | 180 |
private void jumpToSelectedSession(SessionBean sessionBean) {
|
@@ -20,7 +20,7 @@ public class MainContract {
|
||
| 20 | 20 |
void setNewSessionBtnEnabled(boolean isEnabled); |
| 21 | 21 |
void showTimeSyncView(); |
| 22 | 22 |
void showRetrySyncView(int strId); |
| 23 |
- void showBoxUpgradeActivity(String bpversion_str); |
|
| 23 |
+ void showBoxUpgradeActivity(String bpversion_str,int updatingVersionCode); |
|
| 24 | 24 |
} |
| 25 | 25 |
|
| 26 | 26 |
interface Presenter extends BasePresenter{
|
@@ -265,10 +265,10 @@ class MainPresenter implements MainContract.Presenter,SyncTimeInteractor.SyncTim |
||
| 265 | 265 |
} |
| 266 | 266 |
|
| 267 | 267 |
@Override |
| 268 |
- public void onUpgradeInfoFetched(boolean result, String bpversion_str) {
|
|
| 268 |
+ public void onUpgradeInfoFetched(boolean result, String bpversion_str,int versionCode) {
|
|
| 269 | 269 |
isBoxUpdateChecked = true; |
| 270 | 270 |
if(result){
|
| 271 |
- view.showBoxUpgradeActivity(bpversion_str); |
|
| 271 |
+ view.showBoxUpgradeActivity(bpversion_str,versionCode); |
|
| 272 | 272 |
|
| 273 | 273 |
} |
| 274 | 274 |
} |
@@ -36,7 +36,7 @@ public class QueryBoxStatusInteractor implements BaseInteractor{
|
||
| 36 | 36 |
public void run() {
|
| 37 | 37 |
queryBoxStatus(); |
| 38 | 38 |
} |
| 39 |
- },100,6000); |
|
| 39 |
+ },100,5000); |
|
| 40 | 40 |
|
| 41 | 41 |
} |
| 42 | 42 |
|
@@ -95,7 +95,6 @@ public class QueryBoxStatusInteractor implements BaseInteractor{
|
||
| 95 | 95 |
|
| 96 | 96 |
@Override |
| 97 | 97 |
public void cancelJob() {
|
| 98 |
- isCancelled = true; |
|
| 99 | 98 |
if(queryTimer!=null){
|
| 100 | 99 |
queryTimer.cancel(); |
| 101 | 100 |
queryTimer = null; |
@@ -106,6 +105,7 @@ public class QueryBoxStatusInteractor implements BaseInteractor{
|
||
| 106 | 105 |
if(queryBoxTask.getStatus()== AsyncTask.Status.RUNNING){
|
| 107 | 106 |
queryBoxTask.cancel(true); |
| 108 | 107 |
} |
| 108 |
+ isCancelled = true; |
|
| 109 | 109 |
queryBoxTask = null; |
| 110 | 110 |
} |
| 111 | 111 |
|
@@ -7,9 +7,16 @@ import android.text.TextUtils; |
||
| 7 | 7 |
import android.view.KeyEvent; |
| 8 | 8 |
import android.view.View; |
| 9 | 9 |
import android.widget.Button; |
| 10 |
+import android.widget.TextView; |
|
| 11 |
+import android.widget.Toast; |
|
| 12 |
+ |
|
| 13 |
+import com.android.common.utils.LogHelper; |
|
| 14 |
+import com.android.views.loadingdrawable.LoadingView; |
|
| 10 | 15 |
|
| 11 | 16 |
import ai.pai.lensman.R; |
| 12 | 17 |
import ai.pai.lensman.base.BaseActivity; |
| 18 |
+import ai.pai.lensman.db.Preferences; |
|
| 19 |
+import ai.pai.lensman.main.QueryBoxStatusInteractor; |
|
| 13 | 20 |
import butterknife.BindView; |
| 14 | 21 |
import butterknife.ButterKnife; |
| 15 | 22 |
import butterknife.OnClick; |
@@ -18,17 +25,23 @@ import butterknife.OnClick; |
||
| 18 | 25 |
* Created by chengzhenyu on 2017/4/22. |
| 19 | 26 |
*/ |
| 20 | 27 |
|
| 21 |
-public class BoxUpgradeActivity extends BaseActivity implements BoxUpgradeInteractor.BoxUpgradeListener{
|
|
| 28 |
+public class BoxUpgradeActivity extends BaseActivity implements BoxUpgradeInteractor.BoxUpgradeListener,QueryBoxStatusInteractor.BoxStatusListener{
|
|
| 22 | 29 |
|
| 23 | 30 |
@BindView(R.id.layout_choose_update) View chooseUpdateView; |
| 24 |
- |
|
| 25 |
- BoxUpgradeInteractor upgradeInteractor; |
|
| 26 |
- |
|
| 31 |
+ @BindView(R.id.layout_box_updating) View boxUpdatingView; |
|
| 32 |
+ @BindView(R.id.tv_updating_status) TextView updatingStatusTextView; |
|
| 33 |
+ @BindView(R.id.btn_return_work) Button backBtn; |
|
| 34 |
+ @BindView(R.id.loading_gear_view) LoadingView loadingView; |
|
| 35 |
+ private BoxUpgradeInteractor upgradeInteractor; |
|
| 36 |
+ private QueryBoxStatusInteractor boxStatusInteractor; |
|
| 27 | 37 |
private String bpversion_str; |
| 38 |
+ private int updatingVersionCode; |
|
| 39 |
+ private boolean isDestroyed; |
|
| 28 | 40 |
|
| 29 |
- public static void startBoxUpgradeActivity(Context context,String bpversion_str){
|
|
| 41 |
+ public static void startBoxUpgradeActivity(Context context,String bpversion_str,int updatingVersionCode){
|
|
| 30 | 42 |
Intent intent = new Intent(context, BoxUpgradeActivity.class); |
| 31 | 43 |
intent.putExtra("bpversion_str",bpversion_str);
|
| 44 |
+ intent.putExtra("versionCode",updatingVersionCode);
|
|
| 32 | 45 |
context.startActivity(intent); |
| 33 | 46 |
} |
| 34 | 47 |
|
@@ -38,14 +51,22 @@ public class BoxUpgradeActivity extends BaseActivity implements BoxUpgradeIntera |
||
| 38 | 51 |
setContentView(R.layout.activity_box_upgrade); |
| 39 | 52 |
unbinder = ButterKnife.bind(this); |
| 40 | 53 |
bpversion_str = getIntent().getStringExtra("bpversion_str");
|
| 41 |
- if(TextUtils.isEmpty(bpversion_str)){
|
|
| 54 |
+ updatingVersionCode = getIntent().getIntExtra("versionCode",0);
|
|
| 55 |
+ if(TextUtils.isEmpty(bpversion_str)||updatingVersionCode==0){
|
|
| 42 | 56 |
finish(); |
| 43 | 57 |
} |
| 44 | 58 |
} |
| 45 | 59 |
|
| 60 |
+ @Override |
|
| 61 |
+ protected void onDestroy() {
|
|
| 62 |
+ super.onDestroy(); |
|
| 63 |
+ isDestroyed = true; |
|
| 64 |
+ } |
|
| 65 |
+ |
|
| 46 | 66 |
@OnClick(R.id.btn_update_now) |
| 47 | 67 |
public void updateNow(){
|
| 48 | 68 |
chooseUpdateView.setVisibility(View.GONE); |
| 69 |
+ boxUpdatingView.setVisibility(View.VISIBLE); |
|
| 49 | 70 |
upgradeInteractor = new BoxUpgradeInteractor(bpversion_str,this); |
| 50 | 71 |
upgradeInteractor.startJob(); |
| 51 | 72 |
} |
@@ -55,6 +76,18 @@ public class BoxUpgradeActivity extends BaseActivity implements BoxUpgradeIntera |
||
| 55 | 76 |
finish(); |
| 56 | 77 |
} |
| 57 | 78 |
|
| 79 |
+ @OnClick(R.id.btn_return_work) |
|
| 80 |
+ public void back2work(){
|
|
| 81 |
+ if(boxStatusInteractor!=null){
|
|
| 82 |
+ boxStatusInteractor.cancelJob(); |
|
| 83 |
+ boxStatusInteractor = null; |
|
| 84 |
+ } |
|
| 85 |
+ if(upgradeInteractor!=null){
|
|
| 86 |
+ upgradeInteractor.cancelJob(); |
|
| 87 |
+ upgradeInteractor = null; |
|
| 88 |
+ } |
|
| 89 |
+ finish(); |
|
| 90 |
+ } |
|
| 58 | 91 |
@Override |
| 59 | 92 |
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
| 60 | 93 |
if(event.getKeyCode()==KeyEvent.KEYCODE_BACK){
|
@@ -65,10 +98,29 @@ public class BoxUpgradeActivity extends BaseActivity implements BoxUpgradeIntera |
||
| 65 | 98 |
|
| 66 | 99 |
@Override |
| 67 | 100 |
public void onBoxUpgrade(boolean result) {
|
| 101 |
+ if(isDestroyed){
|
|
| 102 |
+ return; |
|
| 103 |
+ } |
|
| 104 |
+ LogHelper.d("czy","box开始升级,开始轮询box状态");
|
|
| 68 | 105 |
if(result){
|
| 69 |
- |
|
| 106 |
+ boxStatusInteractor = new QueryBoxStatusInteractor(this); |
|
| 107 |
+ boxStatusInteractor.startJob(); |
|
| 70 | 108 |
}else{
|
| 109 |
+ boxUpdatingView.setVisibility(View.GONE); |
|
| 110 |
+ chooseUpdateView.setVisibility(View.VISIBLE); |
|
| 111 |
+ Toast.makeText(this,R.string.box_updating_fail,Toast.LENGTH_SHORT).show(); |
|
| 112 |
+ } |
|
| 113 |
+ } |
|
| 71 | 114 |
|
| 115 |
+ @Override |
|
| 116 |
+ public void onBoxStatusFetched(String boxNo, String boxStatus, int boxStatusCode) {
|
|
| 117 |
+ if(isDestroyed){
|
|
| 118 |
+ return; |
|
| 72 | 119 |
} |
| 120 |
+ Preferences.getInstance().setBoxVersionCode(updatingVersionCode); |
|
| 121 |
+ updatingStatusTextView.setText(R.string.box_update_success); |
|
| 122 |
+ loadingView.setVisibility(View.GONE); |
|
| 123 |
+ backBtn.setVisibility(View.VISIBLE); |
|
| 73 | 124 |
} |
| 125 |
+ |
|
| 74 | 126 |
} |
@@ -9,6 +9,7 @@ import org.json.JSONObject; |
||
| 9 | 9 |
|
| 10 | 10 |
import java.util.HashMap; |
| 11 | 11 |
|
| 12 |
+import ai.pai.lensman.BuildConfig; |
|
| 12 | 13 |
import ai.pai.lensman.base.BaseInteractor; |
| 13 | 14 |
import ai.pai.lensman.utils.BoxUrlContainer; |
| 14 | 15 |
import ai.pai.lensman.utils.HttpPostTask; |
@@ -29,12 +30,15 @@ public class BoxUpgradeInteractor implements BaseInteractor {
|
||
| 29 | 30 |
cancelJob(); |
| 30 | 31 |
HashMap<String, String> params = new HashMap<>(); |
| 31 | 32 |
params.put("bpversion_str", bpversion_str);
|
| 32 |
- LogHelper.d("czy", "开始box升级任务");
|
|
| 33 |
+ LogHelper.d("czy", "开始box设置升级任务");
|
|
| 33 | 34 |
upgradeTask = new HttpPostTask(params) {
|
| 34 | 35 |
|
| 35 | 36 |
@Override |
| 36 | 37 |
protected boolean parseResponse(String response) {
|
| 37 |
- LogHelper.d("czy", "box升级任务 box应答=" + response);
|
|
| 38 |
+ LogHelper.d("czy", "box设置升级任务 box应答=" + response);
|
|
| 39 |
+ if(BuildConfig.isTestMode){
|
|
| 40 |
+ return true; |
|
| 41 |
+ } |
|
| 38 | 42 |
try {
|
| 39 | 43 |
JSONObject json = new JSONObject(response); |
| 40 | 44 |
int status = json.getInt("status");
|
@@ -42,7 +46,7 @@ public class BoxUpgradeInteractor implements BaseInteractor {
|
||
| 42 | 46 |
return true; |
| 43 | 47 |
} |
| 44 | 48 |
} catch (Exception e) {
|
| 45 |
- LogHelper.d("czy", "box升级任务 box应答异常 " + e);
|
|
| 49 |
+ LogHelper.d("czy", "box设置升级任务 box应答异常 " + e);
|
|
| 46 | 50 |
} |
| 47 | 51 |
return false; |
| 48 | 52 |
} |
@@ -51,14 +55,14 @@ public class BoxUpgradeInteractor implements BaseInteractor {
|
||
| 51 | 55 |
protected void onPostFail() {
|
| 52 | 56 |
super.onPostFail(); |
| 53 | 57 |
listener.onBoxUpgrade(false); |
| 54 |
- LogHelper.d("czy", "box升级任务失败");
|
|
| 58 |
+ LogHelper.d("czy", "box设置升级任务失败");
|
|
| 55 | 59 |
} |
| 56 | 60 |
|
| 57 | 61 |
@Override |
| 58 | 62 |
protected void onPostSuccess() {
|
| 59 | 63 |
super.onPostSuccess(); |
| 60 | 64 |
listener.onBoxUpgrade(true); |
| 61 |
- LogHelper.d("czy", "box升级任务成功");
|
|
| 65 |
+ LogHelper.d("czy", "box设置升级任务成功");
|
|
| 62 | 66 |
} |
| 63 | 67 |
}; |
| 64 | 68 |
upgradeTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), BoxUrlContainer.SET_VERSION); |
@@ -37,11 +37,11 @@ public class CheckBoxUpgradeInfoInteractor implements BaseInteractor {
|
||
| 37 | 37 |
upgradeTask = new HttpPostTask(params) {
|
| 38 | 38 |
|
| 39 | 39 |
String bpversion_str =""; |
| 40 |
- |
|
| 40 |
+ int latestVersionCode=0; |
|
| 41 | 41 |
@Override |
| 42 | 42 |
protected boolean parseResponse(String response) {
|
| 43 | 43 |
LogHelper.d(TAG, "box升级任务 服务器应答=" + response); |
| 44 |
- int latestVersionCode=0; |
|
| 44 |
+ |
|
| 45 | 45 |
try {
|
| 46 | 46 |
JSONObject json = new JSONObject(response); |
| 47 | 47 |
int status = json.getInt("status");
|
@@ -66,14 +66,14 @@ public class CheckBoxUpgradeInfoInteractor implements BaseInteractor {
|
||
| 66 | 66 |
@Override |
| 67 | 67 |
protected void onPostFail() {
|
| 68 | 68 |
super.onPostFail(); |
| 69 |
- listener.onUpgradeInfoFetched(false, null); |
|
| 69 |
+ listener.onUpgradeInfoFetched(false, bpversion_str,latestVersionCode); |
|
| 70 | 70 |
LogHelper.d(TAG, "box升级任务 获取更新失败或者无需更新"); |
| 71 | 71 |
} |
| 72 | 72 |
|
| 73 | 73 |
@Override |
| 74 | 74 |
protected void onPostSuccess() {
|
| 75 | 75 |
super.onPostSuccess(); |
| 76 |
- listener.onUpgradeInfoFetched(true, bpversion_str); |
|
| 76 |
+ listener.onUpgradeInfoFetched(true, bpversion_str,latestVersionCode); |
|
| 77 | 77 |
LogHelper.d(TAG, "box升级任务 需要更新"); |
| 78 | 78 |
} |
| 79 | 79 |
}; |
@@ -92,7 +92,7 @@ public class CheckBoxUpgradeInfoInteractor implements BaseInteractor {
|
||
| 92 | 92 |
} |
| 93 | 93 |
|
| 94 | 94 |
public interface FetchUpgradeInfoListener {
|
| 95 |
- void onUpgradeInfoFetched(boolean result, String bpversion_str); |
|
| 95 |
+ void onUpgradeInfoFetched(boolean result, String bpversion_str,int versionCode); |
|
| 96 | 96 |
} |
| 97 | 97 |
|
| 98 | 98 |
} |
@@ -2,6 +2,7 @@ |
||
| 2 | 2 |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" |
| 3 | 3 |
android:layout_width="match_parent" |
| 4 | 4 |
android:layout_height="match_parent" |
| 5 |
+ xmlns:app="http://schemas.android.com/apk/res-auto" |
|
| 5 | 6 |
android:background="@color/half_transparent"> |
| 6 | 7 |
|
| 7 | 8 |
<RelativeLayout |
@@ -14,7 +15,7 @@ |
||
| 14 | 15 |
android:layout_width="wrap_content" |
| 15 | 16 |
android:layout_height="wrap_content" |
| 16 | 17 |
android:text="@string/box_upgrade_found" |
| 17 |
- android:layout_centerInParent="true" |
|
| 18 |
+ android:layout_centerHorizontal="true" |
|
| 18 | 19 |
android:textSize="18sp" |
| 19 | 20 |
android:textColor="@color/white" |
| 20 | 21 |
android:id="@+id/tv_box_upgrade_info"/> |
@@ -46,4 +47,46 @@ |
||
| 46 | 47 |
android:layout_below="@+id/btn_update_now" |
| 47 | 48 |
/> |
| 48 | 49 |
</RelativeLayout> |
| 50 |
+ |
|
| 51 |
+ <RelativeLayout |
|
| 52 |
+ android:id="@+id/layout_box_updating" |
|
| 53 |
+ android:layout_width="match_parent" |
|
| 54 |
+ android:layout_height="wrap_content" |
|
| 55 |
+ android:layout_centerInParent="true" |
|
| 56 |
+ android:visibility="gone"> |
|
| 57 |
+ |
|
| 58 |
+ <com.android.views.loadingdrawable.LoadingView |
|
| 59 |
+ android:id="@+id/loading_gear_view" |
|
| 60 |
+ android:layout_width="180dp" |
|
| 61 |
+ android:layout_height="180dp" |
|
| 62 |
+ android:layout_centerHorizontal="true" |
|
| 63 |
+ app:loading_renderer="GearLoadingRenderer"/> |
|
| 64 |
+ |
|
| 65 |
+ <TextView |
|
| 66 |
+ android:id="@+id/tv_updating_status" |
|
| 67 |
+ android:layout_width="wrap_content" |
|
| 68 |
+ android:layout_height="wrap_content" |
|
| 69 |
+ android:textSize="16sp" |
|
| 70 |
+ android:text="@string/box_is_upgrading" |
|
| 71 |
+ android:layout_below="@id/loading_gear_view" |
|
| 72 |
+ android:layout_marginTop="10dp" |
|
| 73 |
+ android:layout_centerHorizontal="true" |
|
| 74 |
+ android:textColor="@color/white"/> |
|
| 75 |
+ |
|
| 76 |
+ <Button |
|
| 77 |
+ android:id="@+id/btn_return_work" |
|
| 78 |
+ android:layout_width="match_parent" |
|
| 79 |
+ android:layout_height="40dp" |
|
| 80 |
+ android:layout_margin="12dp" |
|
| 81 |
+ android:text="@string/back_to_work" |
|
| 82 |
+ android:gravity="center" |
|
| 83 |
+ android:textSize="18sp" |
|
| 84 |
+ android:textColor="@color/white" |
|
| 85 |
+ android:background="@drawable/print_rounded_rect_bg" |
|
| 86 |
+ android:layout_below="@+id/tv_updating_status" |
|
| 87 |
+ android:visibility="gone" |
|
| 88 |
+ /> |
|
| 89 |
+ |
|
| 90 |
+ </RelativeLayout> |
|
| 91 |
+ |
|
| 49 | 92 |
</RelativeLayout> |
@@ -186,4 +186,13 @@ |
||
| 186 | 186 |
<string name="upgrade_now">立即更新</string> |
| 187 | 187 |
|
| 188 | 188 |
<string name="upgrade_later">下次再说</string> |
| 189 |
+ |
|
| 190 |
+ <string name="box_is_upgrading">box软件更新中,约需要一分钟,请勿关闭电源...</string> |
|
| 191 |
+ |
|
| 192 |
+ <string name="box_updating_fail">box软件更新失败,请检查box与手机是否处在同一网络</string> |
|
| 193 |
+ |
|
| 194 |
+ <string name="box_update_success">box软件更新成功,欢迎使用</string> |
|
| 195 |
+ |
|
| 196 |
+ <string name="back_to_work">返回</string> |
|
| 197 |
+ |
|
| 189 | 198 |
</resources> |