| | |
| | | import android.provider.Settings; |
| | | import android.text.TextUtils; |
| | | import android.util.Log; |
| | | import android.view.ViewGroup; |
| | | import android.widget.EditText; |
| | | import android.widget.LinearLayout; |
| | | import android.widget.Toast; |
| | | |
| | | import androidx.appcompat.app.AlertDialog; |
| | | |
| | | import com.auto.lyric.base.activities.BaseActivity; |
| | | import com.auto.lyric.data.ActiveResult; |
| | |
| | | import com.auto.lyric.retrofit.observable.LoadingHttpObserver; |
| | | import com.auto.lyric.service.AutoInputService; |
| | | import com.auto.lyric.service.FloatingWindowService; |
| | | import com.auto.lyric.util.DeviceUtil; |
| | | import com.auto.lyric.ui.collect.CollectActivity; |
| | | import com.auto.lyric.vm.MainViewModel; |
| | | import com.google.gson.Gson; |
| | | |
| | |
| | | |
| | | public class MainActivity extends BaseActivity<ActivityMainBinding, MainViewModel> { |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); |
| | | |
| | | UserInfo userInfo; |
| | | @Override |
| | | public void initViews() { |
| | | Intent floatService = new Intent(getApplicationContext(), FloatingWindowService.class); |
| | | String key = getStringProjectPrefrence("activeKey"); |
| | | UserInfo result = new Gson().fromJson(key,UserInfo.class); |
| | | userInfo = new Gson().fromJson(key,UserInfo.class); |
| | | try { |
| | | if(TextUtils.isEmpty(key) || TextUtils.isEmpty(result.keyDateValid)|| |
| | | new Date().getTime() > dateFormat.parse(result.keyDateValid).getTime()){ |
| | | if(TextUtils.isEmpty(key) || TextUtils.isEmpty(userInfo.keyDateValid)|| |
| | | new Date().getTime() > dateFormat.parse(userInfo.keyDateValid).getTime()){ |
| | | activeDialog(); |
| | | }else{ |
| | | |
| | | viewModel.checkActive(result.userId,result.activeKey,new LoadingHttpObserver<ActiveResult>(this) { |
| | | viewModel.checkActive(userInfo.userId,userInfo.activeKey,new LoadingHttpObserver<ActiveResult>(this) { |
| | | |
| | | @Override |
| | | public void onError(ActiveResult error) { |
| | | super.onError(error); |
| | | if(error.result.equals("108")){ |
| | | activeDialog(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onComplete(ActiveResult result) { |
| | | userInfo = result.userInfo; |
| | | } |
| | | }); |
| | | } |
| | |
| | | //startService(floatService); |
| | | } |
| | | }); |
| | | binding.collect.setOnClickListener(v -> addCollectDailog(userInfo.userId,userInfo.activeKey,binding.edit.getText().toString())); |
| | | binding.txtFavorite.setOnClickListener(v -> startActivity(new Intent(mContext, CollectActivity.class))); |
| | | } |
| | | |
| | | public boolean isAccessibilitySettingsOn() { |
| | |
| | | return false; |
| | | } |
| | | |
| | | private void addCollectDailog(String userId,String activeKey,String lrc ){ |
| | | |
| | | showInputDialog("收藏歌词","填写歌词名称","收藏","取消",(dialog1,editText, which) -> { |
| | | viewModel.addToCollect(userId, activeKey, editText.getText().toString(), lrc, new LoadingHttpObserver<ActiveResult>(this) { |
| | | @Override |
| | | public void onComplete(ActiveResult error) { |
| | | |
| | | } |
| | | }); |
| | | },(dialog1,editText, which) -> {}); |
| | | } |
| | | |
| | | 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) -> { |
| | | showInputDialog("软件尚未激活或已过期", "请输入激活码", "激活", "退出程序", (dialog1,editText, 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) { |
| | | dialog1.dismiss(); |
| | | userInfo = result.userInfo; |
| | | putStringProjectPrefrence("activeKey",new Gson().toJson(result.userInfo)); |
| | | } |
| | | }); |
| | | }); |
| | | dialg.setButton(AlertDialog.BUTTON_POSITIVE,"退出程序",(dialog,which) ->{ |
| | | }, (dialog1,editText, which) -> { |
| | | System.exit(0); |
| | | }); |
| | | dialg.show(); |
| | | } |
| | | |
| | | } |