| | |
| | | import com.auto.lyric.data.ActiveResult; |
| | | import com.auto.lyric.data.LyricServer; |
| | | import com.auto.lyric.data.TextBean; |
| | | import com.auto.lyric.data.UserInfo; |
| | | import com.auto.lyric.databinding.ActivityMainBinding; |
| | | import com.auto.lyric.retrofit.observable.LoadingHttpObserver; |
| | | import com.auto.lyric.service.AutoInputService; |
| | |
| | | public void initViews() { |
| | | Intent floatService = new Intent(getApplicationContext(), FloatingWindowService.class); |
| | | String key = getStringProjectPrefrence("activeKey"); |
| | | ActiveResult result = new Gson().fromJson(key,ActiveResult.class); |
| | | UserInfo result = new Gson().fromJson(key,UserInfo.class); |
| | | try { |
| | | if(TextUtils.isEmpty(key) || TextUtils.isEmpty(result.validDate)|| |
| | | new Date().getTime() > dateFormat.parse(result.validDate).getTime()){ |
| | | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
| | | builder.setTitle("软件尚未激活或已过期"); |
| | | EditText editText = new EditText(this); |
| | | editText.setHint("请输入激活码"); |
| | | ViewGroup.MarginLayoutParams params = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); |
| | | params.setMargins(DeviceUtil.convertDpToPixel(30,this),DeviceUtil.convertDpToPixel(20,this),DeviceUtil.convertDpToPixel(30,this),0); |
| | | editText.setLayoutParams(params); |
| | | LinearLayout lin = new LinearLayout(this); |
| | | lin.addView(editText); |
| | | builder.setView(lin); |
| | | builder.setCancelable(false); |
| | | AlertDialog dialg = builder.create(); |
| | | dialg.setButton(AlertDialog.BUTTON_NEGATIVE,"激活", (dialog, which) -> { |
| | | viewModel.checkActive(editText.getText().toString().trim(),new LoadingHttpObserver<ActiveResult>(this) { |
| | | if(TextUtils.isEmpty(key) || TextUtils.isEmpty(result.keyDateValid)|| |
| | | new Date().getTime() > dateFormat.parse(result.keyDateValid).getTime()){ |
| | | activeDialog(); |
| | | }else{ |
| | | |
| | | @Override |
| | | public void onError(ActiveResult error) { |
| | | super.onError(error); |
| | | dialg.show(); |
| | | } |
| | | viewModel.checkActive(result.userId,result.activeKey,new LoadingHttpObserver<ActiveResult>(this) { |
| | | |
| | | @Override |
| | | public void onComplete(ActiveResult result) { |
| | | @Override |
| | | public void onError(ActiveResult error) { |
| | | super.onError(error); |
| | | } |
| | | |
| | | } |
| | | }); |
| | | @Override |
| | | public void onComplete(ActiveResult result) { |
| | | } |
| | | }); |
| | | dialg.setButton(AlertDialog.BUTTON_POSITIVE,"退出程序",(dialog,which) ->{ |
| | | System.exit(0); |
| | | }); |
| | | dialg.show(); |
| | | } |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | |
| | | } |
| | | |
| | | |
| | | private void activeDialog(){ |
| | | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
| | | builder.setTitle("软件尚未激活或已过期"); |
| | | EditText editText = new EditText(this); |
| | | editText.setHint("请输入激活码"); |
| | | ViewGroup.MarginLayoutParams params = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); |
| | | params.setMargins(DeviceUtil.convertDpToPixel(30,this),DeviceUtil.convertDpToPixel(20,this),DeviceUtil.convertDpToPixel(30,this),0); |
| | | editText.setLayoutParams(params); |
| | | LinearLayout lin = new LinearLayout(this); |
| | | lin.addView(editText); |
| | | builder.setView(lin); |
| | | builder.setCancelable(false); |
| | | AlertDialog dialg = builder.create(); |
| | | dialg.setButton(AlertDialog.BUTTON_NEGATIVE,"激活", (dialog, which) -> { |
| | | viewModel.register(editText.getText().toString().trim(),new LoadingHttpObserver<ActiveResult>(this) { |
| | | |
| | | @Override |
| | | public void onError(ActiveResult error) { |
| | | super.onError(error); |
| | | dialg.show(); |
| | | } |
| | | |
| | | @Override |
| | | public void onComplete(ActiveResult result) { |
| | | putStringProjectPrefrence("activeKey",new Gson().toJson(result.userInfo)); |
| | | } |
| | | }); |
| | | }); |
| | | dialg.setButton(AlertDialog.BUTTON_POSITIVE,"退出程序",(dialog,which) ->{ |
| | | System.exit(0); |
| | | }); |
| | | dialg.show(); |
| | | } |
| | | |
| | | } |