Skip to content

Commit

Permalink
登录-我的界面联通 上
Browse files Browse the repository at this point in the history
  • Loading branch information
linxiangcheer committed Mar 19, 2021
1 parent 709193f commit 9e9c613
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion login/src/debug/java/login/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class LoginActivity : BaseActivity<ActivityLoginBinding>() {
LogUtils.i("登录结果:${it}")

//将数据保存到数据库里
DbHelper.insertUserInfo(context, UserInfo(1, LoginRsp(it.id, it.isBindPhone, it.logo_url, it.token, it.username)))
DbHelper.insertUserInfo(context, it)
//关闭Activity
finish()
}
Expand Down
2 changes: 1 addition & 1 deletion login/src/debug/java/login/net/LoginRsp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ data class RegisterRsp(
* 手机号和密码登录 接口响应
* */
//Room类型别名
typealias LoginRsp = UserInfo.LoginRsp
typealias LoginRsp = UserInfo
3 changes: 3 additions & 0 deletions mine/src/main/java/com/cniao5/mine/MineViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import com.test.service.repo.UserInfo
* */
class MineViewModel: BaseViewModel() {

/*
* MutableLiveData:整个实体类或者数据类型变化后才通知.不会细节到某个字段。
* */
val liveUser = MutableLiveData<UserInfo>()

}
4 changes: 2 additions & 2 deletions mine/src/main/res/layout/fragment_mine.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
app:layout_constraintStart_toStartOf="@id/v_bg_header_mine"
app:layout_constraintTop_toTopOf="@id/v_bg_header_mine"
app:shapeAppearanceOverlay="@style/circleImageStyle"
app:srcCompat="@{vm.liveUser.loginRsp.logo_url,default=@drawable/icon_default_header}"
app:srcCompat="@{vm.liveUser.logo_url,default=@drawable/icon_default_header}"
/>

<!--反引号是默认值,里面只能写英文-->
Expand All @@ -52,7 +52,7 @@
app:layout_constraintStart_toEndOf="@id/iv_user_icon_mine"
app:layout_constraintTop_toTopOf="@id/iv_user_icon_mine"
tools:text="菜鸟窝"
android:text="@{vm.liveUser.loginRsp.username??`NameOfNull`}"
android:text="@{vm.liveUser.username??`NameOfNull`}"
/>

<View
Expand Down
23 changes: 8 additions & 15 deletions service/src/main/java/com/test/service/repo/DataBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,14 @@ abstract class DataBase : RoomDatabase() {
@Entity(tableName = "tv_user")
data class UserInfo(
@PrimaryKey
val id: Int, //主键
@Embedded //内嵌的数据表,User的字段将会被添加到表tv_user中
val loginRsp: LoginRsp?
) {
@Keep
data class LoginRsp (
@ColumnInfo(name = "user_id")
val id: Int, //用户id
@SerializedName("is_bind_phone")
val isBindPhone: Boolean?,
val logo_url: String?, //用户头像
val token: String?,
val username: String? //用户名
)
}
val idd: Int, //主键
val id: Int, //用户id
@SerializedName("is_bind_phone")
val isBindPhone: Boolean?,
val logo_url: String?, //用户头像
val token: String?,
val username: String? //用户名
)

//2、dao层的定义
@Dao
Expand Down

0 comments on commit 9e9c613

Please sign in to comment.