parent
72dcbfa1d2
commit
1d4d03e590
@ -0,0 +1,227 @@ |
||||
package xyz.fycz.myreader.ui.activity |
||||
|
||||
import android.app.Activity |
||||
import android.content.Intent |
||||
import android.os.Bundle |
||||
import android.util.Log |
||||
import android.view.View |
||||
import androidx.appcompat.widget.Toolbar |
||||
import io.reactivex.Single |
||||
import io.reactivex.SingleEmitter |
||||
import io.reactivex.disposables.Disposable |
||||
import org.jetbrains.anko.startActivityForResult |
||||
import xyz.fycz.myreader.R |
||||
import xyz.fycz.myreader.application.App |
||||
import xyz.fycz.myreader.base.BaseActivity |
||||
import xyz.fycz.myreader.base.adapter2.onClick |
||||
import xyz.fycz.myreader.base.observer.MySingleObserver |
||||
import xyz.fycz.myreader.common.APPCONST |
||||
import xyz.fycz.myreader.databinding.ActivityUserInfoBinding |
||||
import xyz.fycz.myreader.greendao.entity.rule.BookSource |
||||
import xyz.fycz.myreader.model.user.Result |
||||
import xyz.fycz.myreader.model.user.User |
||||
import xyz.fycz.myreader.model.user.UserService |
||||
import xyz.fycz.myreader.ui.dialog.LoadingDialog |
||||
import xyz.fycz.myreader.ui.dialog.MyAlertDialog |
||||
import xyz.fycz.myreader.util.ToastUtils |
||||
import xyz.fycz.myreader.util.utils.* |
||||
|
||||
/** |
||||
* @author fengyue |
||||
* @date 2022/3/4 18:38 |
||||
*/ |
||||
class UserInfoActivity : BaseActivity<ActivityUserInfoBinding>() { |
||||
|
||||
private var user: User? = null |
||||
private lateinit var dialog: LoadingDialog |
||||
private var dis: Disposable? = null |
||||
|
||||
override fun bindView() { |
||||
binding = ActivityUserInfoBinding.inflate(layoutInflater) |
||||
setContentView(binding.root) |
||||
} |
||||
|
||||
override fun setUpToolbar(toolbar: Toolbar?) { |
||||
super.setUpToolbar(toolbar) |
||||
setStatusBarColor(R.color.colorPrimary, true) |
||||
supportActionBar?.title = getString(R.string.userinfo) |
||||
} |
||||
|
||||
override fun initData(savedInstanceState: Bundle?) { |
||||
dialog = LoadingDialog(this, "正在请求") { |
||||
dis?.dispose() |
||||
if (user == null || user?.email.isNullOrEmpty()) |
||||
finish() |
||||
} |
||||
initData() |
||||
} |
||||
|
||||
private fun initData() { |
||||
dialog.show() |
||||
user = UserService.readConfig() |
||||
if (user == null) { |
||||
ToastUtils.showWarring("用户未登录") |
||||
dialog.dismiss() |
||||
finish() |
||||
return |
||||
} |
||||
UserService.getInfo(user!!).subscribe(object : MySingleObserver<Result>() { |
||||
override fun onSubscribe(d: Disposable) { |
||||
addDisposable(d) |
||||
dis = d |
||||
} |
||||
|
||||
override fun onSuccess(t: Result) { |
||||
if (t.code < 200) { |
||||
user = GSON.fromJsonObject<User>(GSON.toJson(t.result)) |
||||
dialog.dismiss() |
||||
initInfo() |
||||
} else { |
||||
ToastUtils.showError(t.result.toString()) |
||||
dialog.dismiss() |
||||
finish() |
||||
} |
||||
} |
||||
|
||||
override fun onError(e: Throwable) { |
||||
ToastUtils.showError("用户信息获取失败\n" + e.localizedMessage) |
||||
dialog.dismiss() |
||||
finish() |
||||
} |
||||
}) |
||||
} |
||||
|
||||
private fun initInfo() { |
||||
binding.tvUsername.text = user?.userName |
||||
binding.tvEmail.text = |
||||
StringUtils.getStarString2( |
||||
user?.email, 3, |
||||
user?.email!!.length - user?.email!!.indexOf("@") |
||||
) |
||||
if (user?.backupTime.isNullOrEmpty()) { |
||||
binding.tvLastWebBackTime.text = "未同步" |
||||
} else { |
||||
binding.tvLastWebBackTime.text = user?.backupTime |
||||
} |
||||
if (user?.noAdTime.isNullOrEmpty()) { |
||||
binding.tvNoAdTime.text = "无记录" |
||||
} else { |
||||
binding.tvNoAdTime.text = user?.noAdTime |
||||
} |
||||
if (UserService.getUUID() == user?.noAdId) { |
||||
binding.tvNoAdDevice.text = "已绑定此设备" |
||||
} else { |
||||
binding.tvNoAdDevice.text = "点击绑定" |
||||
} |
||||
} |
||||
|
||||
override fun initWidget() { |
||||
AdUtils.checkHasAd(true, false) |
||||
.subscribe(object : MySingleObserver<Boolean>() { |
||||
override fun onSubscribe(d: Disposable) { |
||||
addDisposable(d) |
||||
} |
||||
|
||||
override fun onSuccess(t: Boolean) { |
||||
if (t) { |
||||
binding.llNoAdService.visibility = View.VISIBLE |
||||
} else { |
||||
binding.llNoAdService.visibility = View.GONE |
||||
} |
||||
} |
||||
|
||||
override fun onError(e: Throwable) { |
||||
binding.llNoAdService.visibility = View.GONE |
||||
} |
||||
}) |
||||
} |
||||
|
||||
override fun initClick() { |
||||
binding.rlResetPwd.onClick { |
||||
val intent = Intent(this, AuthEmailActivity::class.java) |
||||
startActivityForResult(intent, APPCONST.REQUEST_RESET_PWD) |
||||
} |
||||
|
||||
binding.rlNoAdDevice.onClick { |
||||
if (UserService.getUUID() != user?.noAdId) { |
||||
dialog.show() |
||||
UserService.bindId(user!!.userName) |
||||
.subscribe(object : MySingleObserver<Result>() { |
||||
override fun onSubscribe(d: Disposable) { |
||||
addDisposable(d) |
||||
dis = d |
||||
} |
||||
|
||||
override fun onSuccess(t: Result) { |
||||
if (t.code < 200) { |
||||
user?.noAdId = UserService.getUUID() |
||||
ToastUtils.showSuccess("设备绑定成功") |
||||
binding.tvNoAdDevice.text = "已绑定此设备" |
||||
} else { |
||||
ToastUtils.showError(t.result.toString()) |
||||
} |
||||
dialog.dismiss() |
||||
} |
||||
|
||||
override fun onError(e: Throwable) { |
||||
ToastUtils.showError("设备绑定失败\n" + e.localizedMessage) |
||||
dialog.dismiss() |
||||
} |
||||
}) |
||||
} |
||||
} |
||||
|
||||
binding.rlCammyEnter.onClick { |
||||
var cammy = "" |
||||
MyAlertDialog.createInputDia(this, getString(R.string.cammy_enter), |
||||
"请输入卡密", "", true, 25, { |
||||
cammy = it |
||||
}, { _, _ -> |
||||
dialog.show() |
||||
UserService.bindCammy(user?.userName!!, cammy) |
||||
.subscribe(object : MySingleObserver<Result>() { |
||||
override fun onSubscribe(d: Disposable) { |
||||
addDisposable(d) |
||||
dis = d |
||||
} |
||||
|
||||
override fun onSuccess(t: Result) { |
||||
if (t.code < 200) { |
||||
ToastUtils.showSuccess("卡密绑定成功,免广告服务重启后生效") |
||||
dialog.dismiss() |
||||
initData() |
||||
} else { |
||||
dialog.dismiss() |
||||
ToastUtils.showError(t.result.toString()) |
||||
} |
||||
} |
||||
|
||||
override fun onError(e: Throwable) { |
||||
ToastUtils.showError("卡密绑定成功\n" + e.localizedMessage) |
||||
dialog.dismiss() |
||||
} |
||||
}) |
||||
}) |
||||
} |
||||
|
||||
binding.tvLogout.onClick { |
||||
val file = App.getApplication().getFileStreamPath("userConfig.fy") |
||||
if (file.delete()) { |
||||
ToastUtils.showSuccess("退出成功") |
||||
setResult(Activity.RESULT_OK) |
||||
finish() |
||||
} else { |
||||
ToastUtils.showError("退出失败(Error:file.delete())") |
||||
} |
||||
} |
||||
} |
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
||||
super.onActivityResult(requestCode, resultCode, data) |
||||
if (resultCode == Activity.RESULT_OK){ |
||||
if (requestCode == APPCONST.REQUEST_RESET_PWD){ |
||||
binding.tvLogout.performClick() |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,265 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:orientation="vertical"> |
||||
|
||||
<include layout="@layout/toolbar" /> |
||||
|
||||
<RelativeLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="25dp" |
||||
android:paddingLeft="5dp" |
||||
android:paddingRight="5dp"> |
||||
|
||||
<TextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_alignParentStart="true" |
||||
android:layout_centerInParent="true" |
||||
android:text="@string/basic_service" |
||||
android:textColor="@color/textPrimary" /> |
||||
|
||||
</RelativeLayout> |
||||
|
||||
<RelativeLayout |
||||
android:id="@+id/rl_username" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="50dp" |
||||
android:background="@drawable/selector_common_bg" |
||||
android:gravity="center" |
||||
android:paddingHorizontal="20dp"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_alignParentStart="true" |
||||
android:layout_centerVertical="true" |
||||
android:text="@string/username" |
||||
android:textColor="@color/textPrimary" |
||||
android:textSize="@dimen/text_normal_size" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/tv_username" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_alignParentEnd="true" |
||||
android:layout_centerVertical="true" |
||||
android:text="@string/app_name" |
||||
android:textColor="@color/textSecondary" |
||||
android:textSize="@dimen/text_normal_size" /> |
||||
</RelativeLayout> |
||||
|
||||
<RelativeLayout |
||||
android:id="@+id/rl_last_web_back_time" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="50dp" |
||||
android:background="@drawable/selector_common_bg" |
||||
android:gravity="center" |
||||
android:paddingHorizontal="20dp"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_alignParentStart="true" |
||||
android:layout_centerVertical="true" |
||||
android:text="@string/last_web_back_time" |
||||
android:textColor="@color/textPrimary" |
||||
android:textSize="@dimen/text_normal_size" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/tv_last_web_back_time" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_alignParentEnd="true" |
||||
android:layout_centerVertical="true" |
||||
android:text="@string/app_name" |
||||
android:textColor="@color/textSecondary" |
||||
android:textSize="@dimen/text_normal_size" /> |
||||
</RelativeLayout> |
||||
|
||||
<RelativeLayout |
||||
android:id="@+id/rl_email" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="50dp" |
||||
android:background="@drawable/selector_common_bg" |
||||
android:gravity="center" |
||||
android:paddingHorizontal="20dp"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_alignParentStart="true" |
||||
android:layout_centerVertical="true" |
||||
android:text="@string/email" |
||||
android:textColor="@color/textPrimary" |
||||
android:textSize="@dimen/text_normal_size" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/tv_email" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_alignParentEnd="true" |
||||
android:layout_centerVertical="true" |
||||
android:text="@string/app_name" |
||||
android:textColor="@color/textSecondary" |
||||
android:textSize="@dimen/text_normal_size" /> |
||||
</RelativeLayout> |
||||
|
||||
<RelativeLayout |
||||
android:id="@+id/rl_reset_pwd" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="50dp" |
||||
android:background="@drawable/selector_common_bg" |
||||
android:gravity="center" |
||||
android:paddingStart="20dp" |
||||
android:paddingEnd="10dp"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_centerVertical="true" |
||||
android:text="@string/rest_pwd" |
||||
android:textColor="@color/textPrimary" |
||||
android:textSize="@dimen/text_normal_size" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_alignParentEnd="true" |
||||
android:layout_centerVertical="true" |
||||
app:srcCompat="@drawable/ic_right_arrow" |
||||
app:tint="@color/textSecondary" /> |
||||
</RelativeLayout> |
||||
|
||||
|
||||
<LinearLayout |
||||
android:id="@+id/ll_no_ad_service" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:orientation="vertical"> |
||||
|
||||
<RelativeLayout |
||||
android:layout_width="match_parent" |
||||
android:layout_height="25dp" |
||||
android:paddingLeft="5dp" |
||||
android:paddingRight="5dp"> |
||||
|
||||
<TextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_alignParentStart="true" |
||||
android:layout_centerInParent="true" |
||||
android:text="@string/no_ad_service" |
||||
android:textColor="@color/textPrimary" /> |
||||
|
||||
</RelativeLayout> |
||||
|
||||
<RelativeLayout |
||||
android:id="@+id/rl_no_ad_time" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="50dp" |
||||
android:background="@drawable/selector_common_bg" |
||||
android:gravity="center" |
||||
android:paddingHorizontal="20dp"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_alignParentStart="true" |
||||
android:layout_centerVertical="true" |
||||
android:text="@string/no_ad_time" |
||||
android:textColor="@color/textPrimary" |
||||
android:textSize="@dimen/text_normal_size" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/tv_no_ad_time" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_alignParentEnd="true" |
||||
android:layout_centerVertical="true" |
||||
android:text="@string/app_name" |
||||
android:textColor="@color/textSecondary" |
||||
android:textSize="@dimen/text_normal_size" /> |
||||
</RelativeLayout> |
||||
|
||||
<RelativeLayout |
||||
android:id="@+id/rl_no_ad_device" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="50dp" |
||||
android:background="@drawable/selector_common_bg" |
||||
android:gravity="center" |
||||
android:paddingStart="20dp" |
||||
android:paddingEnd="10dp"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_alignParentStart="true" |
||||
android:layout_centerVertical="true" |
||||
android:text="@string/no_ad_device" |
||||
android:textColor="@color/textPrimary" |
||||
android:textSize="@dimen/text_normal_size" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/tv_no_ad_device" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_centerVertical="true" |
||||
android:text="@string/app_name" |
||||
android:textColor="@color/textSecondary" |
||||
android:textSize="@dimen/text_normal_size" |
||||
android:layout_toStartOf="@+id/iv_no_ad_arrow"/> |
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView |
||||
android:id="@+id/iv_no_ad_arrow" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_alignParentEnd="true" |
||||
android:layout_centerVertical="true" |
||||
app:srcCompat="@drawable/ic_right_arrow" |
||||
app:tint="@color/textSecondary" /> |
||||
</RelativeLayout> |
||||
|
||||
<RelativeLayout |
||||
android:id="@+id/rl_cammy_enter" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="50dp" |
||||
android:background="@drawable/selector_common_bg" |
||||
android:gravity="center" |
||||
android:paddingStart="20dp" |
||||
android:paddingEnd="10dp"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_centerVertical="true" |
||||
android:text="@string/cammy_enter" |
||||
android:textColor="@color/textPrimary" |
||||
android:textSize="@dimen/text_normal_size" /> |
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_alignParentEnd="true" |
||||
android:layout_centerVertical="true" |
||||
app:srcCompat="@drawable/ic_right_arrow" |
||||
app:tint="@color/textSecondary" /> |
||||
</RelativeLayout> |
||||
</LinearLayout> |
||||
|
||||
<View |
||||
android:layout_width="match_parent" |
||||
android:layout_height="15dp" /> |
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/tv_logout" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="50dp" |
||||
android:background="@drawable/selector_common_bg" |
||||
android:gravity="center" |
||||
android:text="@string/logout" |
||||
android:textColor="@color/textError" |
||||
android:textSize="@dimen/text_normal_size" /> |
||||
|
||||
</LinearLayout> |
@ -1,3 +1,3 @@ |
||||
#Fri Jun 18 21:45:31 CST 2021 |
||||
VERSION_CODE=239 |
||||
VERSION_CODE=240 |
||||
NEED_CREATE_RELEASE=true |
||||
|
Loading…
Reference in new issue