diff --git a/app/src/main/java/ceui/lisa/activities/UActivity.kt b/app/src/main/java/ceui/lisa/activities/UActivity.kt index 766ecf2fe..345a6b6c0 100644 --- a/app/src/main/java/ceui/lisa/activities/UActivity.kt +++ b/app/src/main/java/ceui/lisa/activities/UActivity.kt @@ -1,279 +1,290 @@ -package ceui.lisa.activities; +package ceui.lisa.activities -import android.content.Intent; -import android.os.Bundle; -import android.view.View; -import android.view.ViewTreeObserver; -import android.view.animation.AlphaAnimation; -import android.view.animation.Animation; +import android.content.DialogInterface +import android.content.Intent +import android.os.Bundle +import android.view.View +import android.view.ViewTreeObserver.OnGlobalLayoutListener +import android.view.animation.AlphaAnimation +import android.view.animation.Animation +import androidx.core.view.isVisible +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentActivity +import androidx.lifecycle.ViewModelProvider +import androidx.lifecycle.lifecycleScope +import ceui.lisa.R +import ceui.lisa.database.AppDatabase +import ceui.lisa.databinding.ActivityNewUserBinding +import ceui.lisa.fragments.FragmentHolder.Companion.newInstance +import ceui.lisa.http.NullCtrl +import ceui.lisa.http.Retro +import ceui.lisa.interfaces.Display +import ceui.lisa.models.UserBean +import ceui.lisa.models.UserDetailResponse +import ceui.lisa.models.UserFollowDetail +import ceui.lisa.utils.Common +import ceui.lisa.utils.GlideUtil +import ceui.lisa.utils.Params +import ceui.lisa.utils.PixivOperate +import ceui.lisa.viewmodel.AppLevelViewModel +import ceui.lisa.viewmodel.UserViewModel +import ceui.loxia.Client +import ceui.loxia.Event +import ceui.loxia.ObjectPool +import ceui.loxia.ProgressTextButton +import ceui.refactor.setOnClick +import com.bumptech.glide.Glide +import com.github.ybq.android.spinkit.style.Wave +import com.qmuiteam.qmui.skin.QMUISkinManager +import com.qmuiteam.qmui.widget.dialog.QMUIDialog.MenuDialogBuilder +import io.reactivex.android.schedulers.AndroidSchedulers +import io.reactivex.schedulers.Schedulers +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch -import androidx.lifecycle.Observer; -import androidx.lifecycle.ViewModelProvider; - -import com.bumptech.glide.Glide; -import com.github.ybq.android.spinkit.style.Wave; -import com.google.android.material.appbar.AppBarLayout; -import com.qmuiteam.qmui.skin.QMUISkinManager; -import com.qmuiteam.qmui.widget.dialog.QMUIDialog; - -import ceui.lisa.R; -import ceui.lisa.database.AppDatabase; -import ceui.lisa.database.MuteEntity; -import ceui.lisa.databinding.ActivityNewUserBinding; -import ceui.lisa.fragments.FragmentHolder; -import ceui.lisa.http.NullCtrl; -import ceui.lisa.http.Retro; -import ceui.lisa.interfaces.Display; -import ceui.lisa.models.UserDetailResponse; -import ceui.lisa.models.UserFollowDetail; -import ceui.lisa.utils.Common; -import ceui.lisa.utils.GlideUtil; -import ceui.lisa.utils.Params; -import ceui.lisa.utils.PixivOperate; -import ceui.lisa.viewmodel.AppLevelViewModel; -import ceui.lisa.viewmodel.UserViewModel; -import ceui.loxia.Event; -import io.reactivex.android.schedulers.AndroidSchedulers; -import io.reactivex.schedulers.Schedulers; - -public class UActivity extends BaseActivity implements Display { - - private int userID; - private UserViewModel mUserViewModel; - - @Override - protected int initLayout() { - return R.layout.activity_new_user; +class UActivity : BaseActivity(), Display { + private var userId = 0 + private lateinit var mUserViewModel: UserViewModel + override fun initLayout(): Int { + return R.layout.activity_new_user } - @Override - protected void initView() { - Wave wave = new Wave(); - baseBind.progress.setIndeterminateDrawable(wave); - baseBind.toolbar.setPadding(0, Shaft.statusHeight, 0, 0); - baseBind.toolbar.setNavigationOnClickListener(v -> finish()); - baseBind.toolbarLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - final int offset = baseBind.toolbarLayout.getHeight() - Shaft.statusHeight - Shaft.toolbarHeight; - baseBind.appBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() { - @Override - public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { - if (Math.abs(verticalOffset) < 15) { - baseBind.centerHeader.setAlpha(1.0f); - baseBind.toolbarTitle.setAlpha(0.0f); - } else if ((offset - Math.abs(verticalOffset)) < 15) { - baseBind.centerHeader.setAlpha(0.0f); - baseBind.toolbarTitle.setAlpha(1.0f); - } else { - baseBind.centerHeader.setAlpha(1 + (float) verticalOffset / offset); - baseBind.toolbarTitle.setAlpha(-(float) verticalOffset / offset); - } - Common.showLog(className + verticalOffset); + override fun initView() { + val wave = Wave() + baseBind.progress.indeterminateDrawable = wave + baseBind.toolbar.setPadding(0, Shaft.statusHeight, 0, 0) + baseBind.toolbar.setNavigationOnClickListener { v: View? -> finish() } + baseBind.toolbarLayout.viewTreeObserver.addOnGlobalLayoutListener(object : + OnGlobalLayoutListener { + override fun onGlobalLayout() { + val offset = + baseBind.toolbarLayout.height - Shaft.statusHeight - Shaft.toolbarHeight + baseBind.appBar.addOnOffsetChangedListener { appBarLayout, verticalOffset -> + if (Math.abs(verticalOffset) < 15) { + baseBind.centerHeader.alpha = 1.0f + baseBind.toolbarTitle.alpha = 0.0f + } else if (offset - Math.abs(verticalOffset) < 15) { + baseBind.centerHeader.alpha = 0.0f + baseBind.toolbarTitle.alpha = 1.0f + } else { + baseBind.centerHeader.alpha = 1 + verticalOffset.toFloat() / offset + baseBind.toolbarTitle.alpha = -verticalOffset.toFloat() / offset } - }); - baseBind.toolbarLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this); + Common.showLog(className + verticalOffset) + } + baseBind.toolbarLayout.viewTreeObserver.removeOnGlobalLayoutListener(this) } - }); + }) } - @Override - protected void initBundle(Bundle bundle) { - userID = bundle.getInt(Params.USER_ID); + override fun initBundle(bundle: Bundle) { + userId = bundle.getInt(Params.USER_ID) } - @Override - public void initModel() { - mUserViewModel = new ViewModelProvider(this).get(UserViewModel.class); - mUserViewModel.getUser().observe(this, new Observer() { - @Override - public void onChanged(UserDetailResponse userDetailResponse) { - invoke(userDetailResponse); - } - }); - final MuteEntity entity = AppDatabase.getAppDatabase(this).searchDao().getUserMuteEntityByID(userID); - mUserViewModel.isUserMuted.setValue(entity != null); - - final MuteEntity block = AppDatabase.getAppDatabase(this).searchDao().getBlockMuteEntityByID(userID); - mUserViewModel.isUserBlocked.setValue(block != null); + override fun initModel() { + mUserViewModel = ViewModelProvider(this)[UserViewModel::class.java] + mUserViewModel.user.observe(this) { userDetailResponse -> invoke(userDetailResponse) } + val entity = AppDatabase.getAppDatabase(this).searchDao().getUserMuteEntityByID(userId) + mUserViewModel.isUserMuted.value = entity != null + val block = AppDatabase.getAppDatabase(this).searchDao().getBlockMuteEntityByID(userId) + mUserViewModel.isUserBlocked.value = block != null + val userLiveData = ObjectPool.get(userId.toLong()) + userLiveData.observe(this) { user -> + updateUser(user) + Common.showLog("updateUser invoke ${user.isIs_followed}") + } + } - Shaft.appViewModel.getFollowUserLiveData(userID).observe(this, new Observer() { - @Override - public void onChanged(Integer integer) { - updateFollowUserUI(integer); + private fun updateUser(user: UserBean) { + if (user.isIs_followed) { + baseBind.follow.isVisible = false + baseBind.unfollow.isVisible = true + baseBind.unfollow.setOnClick { + unfollowUser(it, userId) + } + baseBind.unfollow.setOnLongClickListener { + true } - }); + } else { + baseBind.unfollow.isVisible = false + baseBind.follow.isVisible = true + baseBind.follow.setOnClick { + followUser(it, userId, Params.TYPE_PUBLIC) + } + baseBind.follow.setOnLongClickListener { + followUser(it as ProgressTextButton, userId, Params.TYPE_PRIVATE) + true + } + } } - @Override - protected void initData() { - baseBind.progress.setVisibility(View.VISIBLE); - Retro.getAppApi().getUserDetail(Shaft.sUserModel.getAccess_token(), userID) - .subscribeOn(Schedulers.newThread()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new NullCtrl() { - @Override - public void success(UserDetailResponse user) { - mUserViewModel.getUser().setValue(user); - Shaft.appViewModel.updateFollowUserStatus(userID, user.getUser().isIs_followed() ? AppLevelViewModel.FollowUserStatus.FOLLOWED : AppLevelViewModel.FollowUserStatus.NOT_FOLLOW); - } + override fun initData() { + baseBind.progress.visibility = View.VISIBLE + Retro.getAppApi().getUserDetail(Shaft.sUserModel.access_token, userId) + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(object : NullCtrl() { + override fun success(user: UserDetailResponse) { + mUserViewModel.user.value = user + Shaft.appViewModel.updateFollowUserStatus( + userId, + if (user.user.isIs_followed) AppLevelViewModel.FollowUserStatus.FOLLOWED else AppLevelViewModel.FollowUserStatus.NOT_FOLLOW + ) + } - @Override - public void must() { - baseBind.progress.setVisibility(View.INVISIBLE); - } - }); - Retro.getAppApi().getFollowDetail(Shaft.sUserModel.getAccess_token(), userID) - .subscribeOn(Schedulers.newThread()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new NullCtrl() { - @Override - public void success(UserFollowDetail userFollowDetail) { - //mUserViewModel.getUserFollowDetail().setValue(userFollowDetail); - int followStatus = AppLevelViewModel.FollowUserStatus.NOT_FOLLOW; - if (userFollowDetail.isPublicFollow()) { - followStatus = AppLevelViewModel.FollowUserStatus.FOLLOWED_PUBLIC; - } else if (userFollowDetail.isPrivateFollow()) { - followStatus = AppLevelViewModel.FollowUserStatus.FOLLOWED_PRIVATE; - } else if (userFollowDetail.isFollow()) { - followStatus = AppLevelViewModel.FollowUserStatus.FOLLOWED; - } - Shaft.appViewModel.updateFollowUserStatus(userID, followStatus); + override fun must() { + baseBind.progress.visibility = View.INVISIBLE + } + }) + Retro.getAppApi().getFollowDetail(Shaft.sUserModel.access_token, userId) + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(object : NullCtrl() { + override fun success(userFollowDetail: UserFollowDetail) { + //mUserViewModel.getUserFollowDetail().setValue(userFollowDetail); + var followStatus = AppLevelViewModel.FollowUserStatus.NOT_FOLLOW + if (userFollowDetail.isPublicFollow) { + followStatus = AppLevelViewModel.FollowUserStatus.FOLLOWED_PUBLIC + } else if (userFollowDetail.isPrivateFollow) { + followStatus = AppLevelViewModel.FollowUserStatus.FOLLOWED_PRIVATE + } else if (userFollowDetail.isFollow) { + followStatus = AppLevelViewModel.FollowUserStatus.FOLLOWED } - }); + Shaft.appViewModel.updateFollowUserStatus(userId, followStatus) + } + }) } - @Override - public boolean hideStatusBar() { - return true; + override fun hideStatusBar(): Boolean { + return true } - @Override - public void invoke(UserDetailResponse data) { - getSupportFragmentManager() - .beginTransaction() - .replace(R.id.fragment_container, FragmentHolder.newInstance()) - .commitNowAllowingStateLoss(); - - if (userID == Shaft.sUserModel.getUserId()) { - baseBind.starUser.setVisibility(View.INVISIBLE); - baseBind.moreAction.setVisibility(View.GONE); + override operator fun invoke(data: UserDetailResponse) { + supportFragmentManager + .beginTransaction() + .replace(R.id.fragment_container, newInstance()) + .commitNowAllowingStateLoss() + if (userId == Shaft.sUserModel.userId) { + baseBind.followLayout.visibility = View.GONE + baseBind.moreAction.visibility = View.GONE } else { - baseBind.starUser.setVisibility(View.VISIBLE); - baseBind.moreAction.setVisibility(View.VISIBLE); - baseBind.moreAction.setOnClickListener(v -> { - final boolean isMuted = Boolean.TRUE.equals(mUserViewModel.isUserMuted.getValue()); - String[] OPTIONS = new String[] { - isMuted ? getString(R.string.cancel_block_this_users_work) : getString(R.string.block_this_users_work), -// getString(R.string.add_user_to_blacklist) - }; - new QMUIDialog.MenuDialogBuilder(mActivity) - .setSkinManager(QMUISkinManager.defaultInstance(mActivity)) - .addItems(OPTIONS, (dialog, which) -> { - if (which == 0) { - if (isMuted) { - PixivOperate.unMuteUser(data.getUser()); - mUserViewModel.isUserMuted.setValue(false); - } else { - PixivOperate.muteUser(data.getUser()); - mUserViewModel.isUserMuted.setValue(true); - } - mUserViewModel.refreshEvent.setValue(new Event<>(100, 0L)); - } else if (which == 1) { - + baseBind.followLayout.visibility = View.VISIBLE + baseBind.moreAction.visibility = View.VISIBLE + baseBind.moreAction.setOnClickListener { v: View? -> + val isMuted = java.lang.Boolean.TRUE == mUserViewModel.isUserMuted.value + val OPTIONS = arrayOf( + if (isMuted) getString(R.string.cancel_block_this_users_work) else getString(R.string.block_this_users_work) + ) + MenuDialogBuilder(mActivity) + .setSkinManager(QMUISkinManager.defaultInstance(mActivity)) + .addItems(OPTIONS) { dialog: DialogInterface, which: Int -> + if (which == 0) { + if (isMuted) { + PixivOperate.unMuteUser(data.user) + mUserViewModel.isUserMuted.setValue(false) + } else { + PixivOperate.muteUser(data.user) + mUserViewModel.isUserMuted.setValue(true) } - dialog.dismiss(); - }) - .show(); - }); - - baseBind.starUser.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Integer integerValue = Shaft.appViewModel.getFollowUserLiveData(userID).getValue(); - if (AppLevelViewModel.FollowUserStatus.isFollowed(integerValue)) { - PixivOperate.postUnFollowUser(data.getUser().getId()); - data.getUser().setIs_followed(false); - } else { - PixivOperate.postFollowUser(data.getUser().getId(), Params.TYPE_PUBLIC); - data.getUser().setIs_followed(true); + mUserViewModel.refreshEvent.setValue(Event(100, 0L)) + } else if (which == 1) { + } + dialog.dismiss() } - } - }); - baseBind.starUser.setOnLongClickListener(v1 -> { - Integer integerValue = Shaft.appViewModel.getFollowUserLiveData(userID).getValue(); - if (!AppLevelViewModel.FollowUserStatus.isFollowed(integerValue)) { - data.getUser().setIs_followed(true); - } - PixivOperate.postFollowUser(data.getUser().getId(), Params.TYPE_PRIVATE); - return true; - }); + .show() + } } - - baseBind.centerHeader.setVisibility(View.VISIBLE); - Animation animation = new AlphaAnimation(0.0f, 1.0f); - animation.setDuration(800L); - baseBind.centerHeader.startAnimation(animation); - if (data.getUser().isIs_premium()) { - baseBind.vipImage.setVisibility(View.VISIBLE); + baseBind.centerHeader.visibility = View.VISIBLE + val animation: Animation = AlphaAnimation(0.0f, 1.0f) + animation.duration = 800L + baseBind.centerHeader.startAnimation(animation) + if (data.user.isIs_premium) { + baseBind.vipImage.visibility = View.VISIBLE } else { - baseBind.vipImage.setVisibility(View.GONE); + baseBind.vipImage.visibility = View.GONE } - Glide.with(mContext).load(GlideUtil.getHead(data.getUser())).into(baseBind.userHead); - baseBind.userName.setText(data.getUser().getName()); - baseBind.userName.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Common.copy(mContext, String.valueOf(data.getUser().getId())); - } - }); - baseBind.userName.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - Common.copy(mContext, data.getUser().getName()); - return true; - } - }); - - baseBind.follow.setText(String.valueOf(data.getProfile().getTotal_follow_users())); - baseBind.pFriend.setText(String.valueOf(data.getProfile().getTotal_mypixiv_users())); - - View.OnClickListener pFriend = new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(mContext, TemplateActivity.class); - intent.putExtra(Params.USER_ID, data.getUser().getId()); - intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "好P友"); - startActivity(intent); - } - }; - baseBind.pFriend.setOnClickListener(pFriend); - baseBind.pFriendS.setOnClickListener(pFriend); - - View.OnClickListener follow = new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(mContext, TemplateActivity.class); - intent.putExtra(Params.USER_ID, data.getUser().getId()); - intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "正在关注"); - startActivity(intent); - } - }; - baseBind.follow.setOnClickListener(follow); - baseBind.followS.setOnClickListener(follow); + Glide.with(mContext).load(GlideUtil.getHead(data.user)).into(baseBind.userHead) + baseBind.userName.text = data.user.name + baseBind.userName.setOnClickListener { Common.copy(mContext, data.user.id.toString()) } + baseBind.userName.setOnLongClickListener { + Common.copy(mContext, data.user.name) + true + } + baseBind.followCount.text = data.profile.total_follow_users.toString() + baseBind.pFriend.text = data.profile.total_mypixiv_users.toString() + val pFriend = View.OnClickListener { + val intent = Intent(mContext, TemplateActivity::class.java) + intent.putExtra(Params.USER_ID, data.user.id) + intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "好P友") + startActivity(intent) + } + baseBind.pFriend.setOnClickListener(pFriend) + baseBind.pFriendS.setOnClickListener(pFriend) + val follow = View.OnClickListener { + val intent = Intent(mContext, TemplateActivity::class.java) + intent.putExtra(Params.USER_ID, data.user.id) + intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "正在关注") + startActivity(intent) + } + baseBind.follow.setOnClickListener(follow) + baseBind.followS.setOnClickListener(follow) } +} + +fun Fragment.followUser(sender: ProgressTextButton, userId: Int, followType: String) { + activity?.followUser(sender, userId, followType) +} - private void updateFollowUserUI(int status) { - if (AppLevelViewModel.FollowUserStatus.isFollowed(status)) { - baseBind.starUser.setText(R.string.string_177); - if (AppLevelViewModel.FollowUserStatus.isPrivateFollowed(status)) { - baseBind.starUser.setBackgroundResource(R.drawable.follow_button_stroke_new_dotted); +fun FragmentActivity.followUser(sender: ProgressTextButton, userId: Int, followType: String) { + lifecycleScope.launch { + try { + sender.showProgress() + Client.appApi.postFollow(userId.toLong(), followType) + delay(500L) + ObjectPool.followUser(userId.toLong()) + if (followType == Params.TYPE_PUBLIC) { + Shaft.appViewModel.updateFollowUserStatus( + userId, + AppLevelViewModel.FollowUserStatus.FOLLOWED_PUBLIC + ) + Common.showToast(getString(R.string.like_success_public)) } else { - baseBind.starUser.setBackgroundResource(R.drawable.follow_button_stroke_new); + Shaft.appViewModel.updateFollowUserStatus( + userId, + AppLevelViewModel.FollowUserStatus.FOLLOWED_PRIVATE + ) + Common.showToast(getString(R.string.like_success_private)) } - } else { - baseBind.starUser.setText(R.string.string_178); - baseBind.starUser.setBackgroundResource(R.drawable.follow_button_stroke_new); + } catch (ex: Exception) { + ex.printStackTrace() + Common.showToast(ex.message) + } finally { + sender.hideProgress() } } } + +fun Fragment.unfollowUser(sender: ProgressTextButton, userId: Int) { + activity?.unfollowUser(sender, userId) +} + +fun FragmentActivity.unfollowUser(sender: ProgressTextButton, userId: Int) { + lifecycleScope.launch { + try { + sender.showProgress() + Client.appApi.postUnFollow(userId.toLong()) + delay(500L) + Shaft.appViewModel.updateFollowUserStatus( + userId, + AppLevelViewModel.FollowUserStatus.NOT_FOLLOW + ) + ObjectPool.unFollowUser(userId.toLong()) + Common.showToast(getString(R.string.cancel_like)) + } catch (ex: Exception) { + ex.printStackTrace() + Common.showToast(ex.message) + } finally { + sender.hideProgress() + } + } +} \ No newline at end of file diff --git a/app/src/main/java/ceui/lisa/database/SearchDao.kt b/app/src/main/java/ceui/lisa/database/SearchDao.kt index d90b689be..0eb059b6e 100644 --- a/app/src/main/java/ceui/lisa/database/SearchDao.kt +++ b/app/src/main/java/ceui/lisa/database/SearchDao.kt @@ -59,7 +59,7 @@ interface SearchDao { fun getMutedUser(limit: Int, offset: Int): List @Query("SELECT * FROM tag_mute_table WHERE type = 3 AND id = :userID LIMIT 1") - fun getUserMuteEntityByID(userID: Int): MuteEntity + fun getUserMuteEntityByID(userID: Int): MuteEntity? @Query("SELECT * FROM tag_mute_table WHERE type = 3 AND id = :userID LIMIT 1") fun getUserMuteEntityByIDLiveData(userID: Int): LiveData @@ -68,7 +68,7 @@ interface SearchDao { fun getIllustMuteEntityByID(illustId: Int): LiveData @Query("SELECT * FROM tag_mute_table WHERE type = 4 AND id = :userID LIMIT 1") - fun getBlockMuteEntityByID(userID: Int): MuteEntity + fun getBlockMuteEntityByID(userID: Int): MuteEntity? @Delete fun deleteMuteEntity(muteEntity: MuteEntity) diff --git a/app/src/main/java/ceui/lisa/fragments/FragmentIllust.kt b/app/src/main/java/ceui/lisa/fragments/FragmentIllust.kt index 33eb86970..f82d43a00 100644 --- a/app/src/main/java/ceui/lisa/fragments/FragmentIllust.kt +++ b/app/src/main/java/ceui/lisa/fragments/FragmentIllust.kt @@ -31,7 +31,6 @@ import ceui.lisa.download.IllustDownload import ceui.lisa.models.* import ceui.lisa.notification.CallBackReceiver import ceui.lisa.utils.* -import ceui.lisa.viewmodel.AppLevelViewModel.FollowUserStatus import ceui.loxia.* import ceui.refactor.setOnClick import com.bumptech.glide.Glide @@ -123,34 +122,16 @@ class FragmentIllust : SwipeFragment() { baseBind.follow.isVisible = false baseBind.unfollow.isVisible = true baseBind.unfollow.setOnClick { - viewLifecycleOwner.lifecycleScope.launch { - it.showProgress() - PixivOperate.postUnFollowUser(user.id) - delay(800L) - it.hideProgress() - } - } - baseBind.unfollow.setOnLongClickListener { - true + unfollowUser(it, user.id) } } else { baseBind.unfollow.isVisible = false baseBind.follow.isVisible = true baseBind.follow.setOnClick { - viewLifecycleOwner.lifecycleScope.launch { - it.showProgress() - PixivOperate.postFollowUser(user.id, Params.TYPE_PUBLIC) - delay(800L) - it.hideProgress() - } + followUser(it, user.id, Params.TYPE_PUBLIC) } baseBind.follow.setOnLongClickListener { - viewLifecycleOwner.lifecycleScope.launch { - (it as? ProgressTextButton)?.showProgress() - PixivOperate.postFollowUser(user.id, Params.TYPE_PRIVATE) - delay(800L) - (it as? ProgressTextButton)?.hideProgress() - } + followUser((it as ProgressTextButton), user.id, Params.TYPE_PRIVATE) true } } @@ -170,10 +151,6 @@ class FragmentIllust : SwipeFragment() { } baseBind.userName.text = user.name - Glide.with(mContext) - .load(GlideUtil.getUrl(user.profile_image_urls.medium)) - .error(R.drawable.no_profile) - .into(baseBind.userHead) } private fun updateIllust(illust: IllustsBean) { @@ -509,7 +486,10 @@ class FragmentIllust : SwipeFragment() { } baseBind.illustId.setOnClick { Common.copy(mContext, illust.id.toString()) } baseBind.userId.setOnClick { Common.copy(mContext, illust.user.id.toString()) } - + Glide.with(mContext) + .load(GlideUtil.getUrl(illust.user?.profile_image_urls?.medium)) + .error(R.drawable.no_profile) + .into(baseBind.userHead) } private var mReceiver: CallBackReceiver? = null diff --git a/app/src/main/java/ceui/loxia/API.kt b/app/src/main/java/ceui/loxia/API.kt index db2443cfd..d89aabde1 100644 --- a/app/src/main/java/ceui/loxia/API.kt +++ b/app/src/main/java/ceui/loxia/API.kt @@ -14,4 +14,17 @@ interface API { @Field("type_of_problem") type_of_problem: String?, @Field("message") message: String? ): NullResponse + + @FormUrlEncoded + @POST("/v1/user/follow/add") + suspend fun postFollow( + @Field("user_id") user_id: Long, + @Field("restrict") followType: String + ) + + @FormUrlEncoded + @POST("/v1/user/follow/delete") + suspend fun postUnFollow( + @Field("user_id") user_id: Long + ) } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_new_user.xml b/app/src/main/res/layout/activity_new_user.xml index 995bf1c14..8ffd208c2 100644 --- a/app/src/main/res/layout/activity_new_user.xml +++ b/app/src/main/res/layout/activity_new_user.xml @@ -105,7 +105,7 @@ - - + + + +