diff --git a/app/src/main/java/com/huanchengfly/tieba/post/activities/BaseActivity.kt b/app/src/main/java/com/huanchengfly/tieba/post/activities/BaseActivity.kt index 370bf819..909197d4 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/activities/BaseActivity.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/activities/BaseActivity.kt @@ -42,6 +42,7 @@ abstract class BaseActivity : SwipeBackActivity(), ExtraRefreshable { var isActivityRunning = true private set private var customStatusColor = -1 + private var statusBarTinted = false val appPreferences: AppPreferencesUtils get() = AppPreferencesUtils(this) @@ -200,18 +201,21 @@ abstract class BaseActivity : SwipeBackActivity(), ExtraRefreshable { .transparentBar() .init() } else { - val immersionBar = ImmersionBar.with(this) - .fitsSystemWindowsInt(true, ThemeUtils.getColorByAttr(this, R.attr.colorBg)) - .navigationBarColorInt(ThemeUtils.getColorByAttr(this, R.attr.colorNavBar)) - .navigationBarDarkIcon(ThemeUtil.isNavigationBarFontDark(this)) - if (customStatusColor != -1) { - immersionBar.statusBarColorInt(customStatusColor) - .autoStatusBarDarkModeEnable(true) - } else { - immersionBar.statusBarColorInt(calcStatusBarColor(this, ThemeUtils.getColorByAttr(this, R.attr.colorToolbar))) - .statusBarDarkFont(ThemeUtil.isStatusBarFontDark(this)) - } - immersionBar.init() + ImmersionBar.with(this).apply { + if (customStatusColor != -1) { + statusBarColorInt(customStatusColor) + autoStatusBarDarkModeEnable(true) + } else { + statusBarColorInt(calcStatusBarColor(this@BaseActivity, ThemeUtils.getColorByAttr(this@BaseActivity, R.attr.colorToolbar))) + statusBarDarkFont(ThemeUtil.isStatusBarFontDark(this@BaseActivity)) + } + fitsSystemWindowsInt(true, ThemeUtils.getColorByAttr(this@BaseActivity, R.attr.colorBg)) + navigationBarColorInt(ThemeUtils.getColorByAttr(this@BaseActivity, R.attr.colorNavBar)) + navigationBarDarkIcon(ThemeUtil.isNavigationBarFontDark(this@BaseActivity)) + }.init() + } + if (!statusBarTinted) { + statusBarTinted = true } } diff --git a/app/src/main/java/com/huanchengfly/tieba/post/activities/FloorActivity.kt b/app/src/main/java/com/huanchengfly/tieba/post/activities/FloorActivity.kt index 94be1290..8f570d06 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/activities/FloorActivity.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/activities/FloorActivity.kt @@ -213,6 +213,8 @@ class FloorActivity : BaseActivity() { const val EXTRA_POST_ID = "pid" const val EXTRA_SUB_POST_ID = "spid" + @JvmStatic + @JvmOverloads fun launch( context: Context, threadId: String, diff --git a/app/src/main/java/com/huanchengfly/tieba/post/activities/UserActivity.kt b/app/src/main/java/com/huanchengfly/tieba/post/activities/UserActivity.kt index 37af70f7..379ac328 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/activities/UserActivity.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/activities/UserActivity.kt @@ -1,240 +1,244 @@ -package com.huanchengfly.tieba.post.activities; +@file:SuppressLint("NonConstantResourceId") -import android.content.res.ColorStateList; -import android.graphics.Color; -import android.os.Bundle; -import android.text.TextUtils; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.ImageView; -import android.widget.TextView; -import android.widget.Toast; +package com.huanchengfly.tieba.post.activities -import androidx.appcompat.app.ActionBar; -import androidx.appcompat.widget.Toolbar; -import androidx.viewpager.widget.ViewPager; +import android.annotation.SuppressLint +import android.os.Bundle +import android.text.TextUtils +import android.view.Menu +import android.view.MenuItem +import android.view.View +import android.widget.ImageView +import android.widget.TextView +import android.widget.Toast +import androidx.viewpager.widget.ViewPager +import butterknife.BindView +import butterknife.OnClick +import com.google.android.material.appbar.AppBarLayout +import com.google.android.material.appbar.AppBarLayout.OnOffsetChangedListener +import com.google.android.material.appbar.CollapsingToolbarLayout +import com.google.android.material.tabs.TabLayout +import com.huanchengfly.tieba.post.R +import com.huanchengfly.tieba.post.adapters.FragmentTabViewPagerAdapter +import com.huanchengfly.tieba.post.api.TiebaApi.getInstance +import com.huanchengfly.tieba.post.api.models.CommonResponse +import com.huanchengfly.tieba.post.api.models.ProfileBean +import com.huanchengfly.tieba.post.fragments.UserLikeForumFragment +import com.huanchengfly.tieba.post.fragments.UserPostFragment +import com.huanchengfly.tieba.post.models.PhotoViewBean +import com.huanchengfly.tieba.post.models.database.Block +import com.huanchengfly.tieba.post.utils.AccountUtil +import com.huanchengfly.tieba.post.utils.ImageUtil +import com.huanchengfly.tieba.post.utils.StatusBarUtil +import com.huanchengfly.tieba.post.utils.ThemeUtil +import com.huanchengfly.tieba.post.widgets.theme.TintMaterialButton +import com.huanchengfly.tieba.post.widgets.theme.TintToolbar +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response +import kotlin.math.abs -import com.google.android.material.appbar.AppBarLayout; -import com.google.android.material.tabs.TabLayout; -import com.huanchengfly.tieba.post.R; -import com.huanchengfly.tieba.post.adapters.FragmentTabViewPagerAdapter; -import com.huanchengfly.tieba.post.api.TiebaApi; -import com.huanchengfly.tieba.post.api.models.CommonResponse; -import com.huanchengfly.tieba.post.api.models.ProfileBean; -import com.huanchengfly.tieba.post.fragments.UserLikeForumFragment; -import com.huanchengfly.tieba.post.fragments.UserPostFragment; -import com.huanchengfly.tieba.post.models.PhotoViewBean; -import com.huanchengfly.tieba.post.models.database.Account; -import com.huanchengfly.tieba.post.models.database.Block; -import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils; -import com.huanchengfly.tieba.post.utils.AccountUtil; -import com.huanchengfly.tieba.post.utils.ImageUtil; -import com.huanchengfly.tieba.post.utils.ThemeUtil; -import com.huanchengfly.tieba.post.widgets.theme.TintMaterialButton; - -import org.jetbrains.annotations.NotNull; - -import butterknife.BindView; -import butterknife.OnClick; -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Response; - -import static com.huanchengfly.tieba.post.utils.Util.changeAlpha; - -public class UserActivity extends BaseActivity { - public static final String TAG = "UserActivity"; - public static final String EXTRA_UID = "uid"; - public static final String EXTRA_TAB = "tab"; - public static final String EXTRA_AVATAR = "avatar"; - - public static final int TAB_THREAD = 0; - public static final int TAB_REPLY = 1; - public static final int TAB_LIKE_FORUM = 2; +class UserActivity : BaseActivity() { @BindView(R.id.toolbar) - Toolbar toolbar; + lateinit var toolbar: TintToolbar + + @BindView(R.id.appbar) + lateinit var appbar: AppBarLayout + @BindView(R.id.user_center_avatar) - ImageView avatarView; + lateinit var avatarView: ImageView + @BindView(R.id.title_view) - TextView titleView; + lateinit var titleView: TextView + + @BindView(R.id.user_center_slogan) + lateinit var sloganView: TextView + @BindView(R.id.user_center_stat) - TextView statView; + lateinit var statView: TextView + @BindView(R.id.user_center_action_btn) - TintMaterialButton actionBtn; + lateinit var actionBtn: TintMaterialButton + @BindView(R.id.loading_view) - View loadingView; + lateinit var loadingView: View - private ProfileBean profileBean; + @BindView(R.id.fake_status_bar) + lateinit var fakeStatusBarView: View - private String uid; - private int tab; + @BindView(R.id.user_center_header) + lateinit var headerView: View - @Override - public int getLayoutId() { - return R.layout.activity_user; + @BindView(R.id.user_center_header_mask) + lateinit var headerMaskView: View + + private var profileBean: ProfileBean? = null + private var uid: String? = null + private var tab = 0 + + override fun getLayoutId(): Int { + return R.layout.activity_user } - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ThemeUtil.setTranslucentThemeBackground(findViewById(R.id.background)); - uid = getIntent().getStringExtra(EXTRA_UID); - tab = getIntent().getIntExtra(EXTRA_TAB, TAB_THREAD); - String avatar = getIntent().getStringExtra(EXTRA_AVATAR); + override val isNeedImmersionBar: Boolean + get() = false + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + StatusBarUtil.transparentStatusBar(this) + (toolbar.layoutParams as CollapsingToolbarLayout.LayoutParams).topMargin = StatusBarUtil.getStatusBarHeight(this) + fakeStatusBarView.minimumHeight = StatusBarUtil.getStatusBarHeight(this) + ThemeUtil.setTranslucentThemeBackground(findViewById(R.id.background)) + uid = intent.getStringExtra(EXTRA_UID) + tab = intent.getIntExtra(EXTRA_TAB, TAB_THREAD) + val avatar = intent.getStringExtra(EXTRA_AVATAR) if (uid == null) { - finish(); - return; + finish() + return } - FragmentTabViewPagerAdapter adapter = new FragmentTabViewPagerAdapter(getSupportFragmentManager()); - ViewPager viewPager = (ViewPager) findViewById(R.id.user_center_vp); - TabLayout tabLayout = (TabLayout) findViewById(R.id.user_center_tab); - AppBarLayout appBarLayout = (AppBarLayout) findViewById(R.id.appbar); - actionBtn.setVisibility(View.GONE); + val adapter = FragmentTabViewPagerAdapter(supportFragmentManager) + val viewPager = findViewById(R.id.user_center_vp) as ViewPager + val tabLayout = findViewById(R.id.user_center_tab) as TabLayout + actionBtn.visibility = View.GONE if (!TextUtils.isEmpty(avatar)) { - loadingView.setVisibility(View.GONE); - ImageUtil.load(avatarView, ImageUtil.LOAD_TYPE_AVATAR, avatar); - ImageUtil.initImageView(avatarView, new PhotoViewBean(avatar)); + loadingView.visibility = View.GONE + ImageUtil.load(avatarView, ImageUtil.LOAD_TYPE_ALWAYS_ROUND, avatar) + ImageUtil.initImageView(avatarView, PhotoViewBean(avatar)) } - appBarLayout.addOnOffsetChangedListener((appBarLayout1, verticalOffset) -> { - toolbar.setBackgroundColor(changeAlpha(ThemeUtils.getColorByAttr(this, R.attr.colorToolbar), Math.abs(verticalOffset * 1.0f) / appBarLayout1.getTotalScrollRange())); - if (profileBean != null && profileBean.getUser() != null && Math.abs(verticalOffset) >= appBarLayout1.getTotalScrollRange()) { - toolbar.setTitle(profileBean.getUser().getNameShow()); + appbar.addOnOffsetChangedListener(OnOffsetChangedListener { appBarLayout: AppBarLayout, verticalOffset: Int -> + val percent = abs(verticalOffset * 1.0f) / appBarLayout.totalScrollRange + headerView.alpha = 1f - percent + headerMaskView.alpha = percent + if (profileBean != null && profileBean!!.user != null && abs(verticalOffset) >= appBarLayout.totalScrollRange) { + toolbar.title = profileBean!!.user!!.nameShow } else { - toolbar.setTitle(null); + toolbar.title = null } - }); - setSupportActionBar(toolbar); - ActionBar actionBar = getSupportActionBar(); - if (actionBar != null) { - actionBar.setDisplayHomeAsUpEnabled(true); - } - viewPager.setAdapter(adapter); - viewPager.setOffscreenPageLimit(3); - tabLayout.setupWithViewPager(viewPager); - TiebaApi.getInstance().profile(uid).enqueue(new Callback() { - @Override - public void onResponse(@NotNull Call call, @NotNull Response response) { - ProfileBean data = response.body(); - actionBtn.setVisibility(View.VISIBLE); - loadingView.setVisibility(View.GONE); - View dividerView = findViewById(R.id.user_center_divider); - if (ThemeUtils.getColorByAttr(UserActivity.this, R.attr.colorBg) == ThemeUtils.getColorByAttr(UserActivity.this, R.attr.colorToolbar)) { - dividerView.setVisibility(View.VISIBLE); - } - if (ThemeUtils.getColorByAttr(UserActivity.this, R.attr.colorToolbar) == ThemeUtils.getColorByAttr(UserActivity.this, R.attr.colorAccent)) { - actionBtn.setTextColor(ColorStateList.valueOf(Color.WHITE)); - actionBtn.setStrokeColor(ColorStateList.valueOf(Color.WHITE)); - } - profileBean = data; - refreshHeader(); - adapter.clear(); - adapter.addFragment(UserPostFragment.newInstance(uid, true), "贴子 " + data.getUser().getThreadNum()); - adapter.addFragment(UserPostFragment.newInstance(uid, false), "回复 " + data.getUser().getRepostNum()); - adapter.addFragment(UserLikeForumFragment.newInstance(uid), "关注吧 " + data.getUser().getMyLikeNum()); - viewPager.setCurrentItem(tab, false); + }) + viewPager.adapter = adapter + viewPager.offscreenPageLimit = 3 + tabLayout.setupWithViewPager(viewPager) + setSupportActionBar(toolbar) + val actionBar = supportActionBar + actionBar?.setDisplayHomeAsUpEnabled(true) + getInstance().profile(uid!!).enqueue(object : Callback { + override fun onResponse(call: Call, response: Response) { + val data = response.body() + actionBtn.visibility = View.VISIBLE + loadingView.visibility = View.GONE + profileBean = data + refreshHeader() + adapter.clear() + adapter.addFragment(UserPostFragment.newInstance(uid, true), "贴子 " + data!!.user!!.threadNum) + adapter.addFragment(UserPostFragment.newInstance(uid, false), "回复 " + data.user!!.repostNum) + adapter.addFragment(UserLikeForumFragment.newInstance(uid), "关注吧 " + data.user.myLikeNum) + viewPager.setCurrentItem(tab, false) } - @Override - public void onFailure(@NotNull Call call, @NotNull Throwable t) { - } - }); + override fun onFailure(call: Call, t: Throwable) {} + }) } - public void refreshHeader() { - titleView.setText(profileBean.getUser().getNameShow()); - statView.setText(getString(R.string.tip_stat, profileBean.getUser().getConcernNum(), profileBean.getUser().getFansNum())); - if (avatarView.getTag() == null) { - ImageUtil.load(avatarView, ImageUtil.LOAD_TYPE_AVATAR, "http://tb.himg.baidu.com/sys/portrait/item/" + profileBean.getUser().getPortrait()); - ImageUtil.initImageView(avatarView, new PhotoViewBean("http://tb.himg.baidu.com/sys/portrait/item/" + profileBean.getUser().getPortrait())); + fun refreshHeader() { + titleView.text = profileBean!!.user!!.nameShow + sloganView.text = profileBean!!.user!!.intro + statView.text = getString(R.string.tip_stat, profileBean!!.user!!.concernNum, profileBean!!.user!!.fansNum) + if (avatarView.tag == null) { + ImageUtil.load(avatarView, ImageUtil.LOAD_TYPE_ALWAYS_ROUND, "http://tb.himg.baidu.com/sys/portrait/item/" + profileBean!!.user!!.portrait) + ImageUtil.initImageView(avatarView, PhotoViewBean("http://tb.himg.baidu.com/sys/portrait/item/" + profileBean!!.user!!.portrait)) } - if (TextUtils.equals(AccountUtil.getUid(this), profileBean.getUser().getId())) { - actionBtn.setText(R.string.menu_edit_info); + if (TextUtils.equals(AccountUtil.getUid(this), profileBean!!.user!!.id)) { + actionBtn.setText(R.string.menu_edit_info) } else { - if ("1".equals(profileBean.getUser().getHasConcerned())) { - actionBtn.setText(R.string.button_unfollow); + if ("1" == profileBean!!.user!!.hasConcerned) { + actionBtn.setText(R.string.button_unfollow) } else { - actionBtn.setText(R.string.button_follow); + actionBtn.setText(R.string.button_follow) } } } - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.menu_user_space, menu); - Account account = AccountUtil.getLoginInfo(this); - if (account != null && TextUtils.equals(account.getUid(), uid)) { - menu.findItem(R.id.menu_block).setVisible(false); - menu.findItem(R.id.menu_edit_info).setVisible(true); + override fun onCreateOptionsMenu(menu: Menu): Boolean { + menuInflater.inflate(R.menu.menu_user_space, menu) + val account = AccountUtil.getLoginInfo(this) + if (account != null && TextUtils.equals(account.uid, uid)) { + menu.findItem(R.id.menu_block).isVisible = false + menu.findItem(R.id.menu_edit_info).isVisible = true } else { - menu.findItem(R.id.menu_block).setVisible(true); - menu.findItem(R.id.menu_edit_info).setVisible(false); + menu.findItem(R.id.menu_block).isVisible = true + menu.findItem(R.id.menu_edit_info).isVisible = false } - return super.onCreateOptionsMenu(menu); + return super.onCreateOptionsMenu(menu) } - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_block_black: - case R.id.menu_block_white: - int category = item.getItemId() == R.id.menu_block_black ? Block.CATEGORY_BLACK_LIST : Block.CATEGORY_WHITE_LIST; - new Block() - .setUid(profileBean.getUser().getId()) - .setUsername(profileBean.getUser().getName()) + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.menu_block_black, R.id.menu_block_white -> { + val category = if (item.itemId == R.id.menu_block_black) Block.CATEGORY_BLACK_LIST else Block.CATEGORY_WHITE_LIST + Block() + .setUid(profileBean!!.user!!.id) + .setUsername(profileBean!!.user!!.name) .setType(Block.TYPE_USER) .setCategory(category) .saveAsync() - .listen(success -> { + .listen { success: Boolean -> if (success) { - Toast.makeText(this, R.string.toast_add_success, Toast.LENGTH_SHORT).show(); + Toast.makeText(this, R.string.toast_add_success, Toast.LENGTH_SHORT).show() } - }); - return true; - case R.id.menu_edit_info: - startActivity(WebViewActivity.newIntent(this, getString(R.string.url_edit_info))); - return true; + } + return true + } + R.id.menu_edit_info -> { + startActivity(WebViewActivity.newIntent(this, getString(R.string.url_edit_info))) + return true + } } - return super.onOptionsItemSelected(item); + return super.onOptionsItemSelected(item) } @OnClick(R.id.user_center_action_btn) - public void onActionBtnClick(View view) { - if (TextUtils.equals(profileBean.getUser().getId(), AccountUtil.getUid(this))) { - startActivity(WebViewActivity.newIntent(this, getString(R.string.url_edit_info))); - return; + fun onActionBtnClick(view: View?) { + if (TextUtils.equals(profileBean!!.user!!.id, AccountUtil.getUid(this))) { + startActivity(WebViewActivity.newIntent(this, getString(R.string.url_edit_info))) + return } - if ("1".equals(profileBean.getUser().getHasConcerned())) { - TiebaApi.getInstance().unfollow(profileBean.getUser().getPortrait(), AccountUtil.getLoginInfo(this).getTbs()).enqueue(new Callback() { - @Override - public void onResponse(@NotNull Call call, @NotNull Response response) { - CommonResponse data = response.body(); - Toast.makeText(UserActivity.this, data.getErrorMsg(), Toast.LENGTH_SHORT).show(); - profileBean.getUser().setHasConcerned("0"); - refreshHeader(); + if ("1" == profileBean!!.user!!.hasConcerned) { + getInstance().unfollow(profileBean!!.user!!.portrait!!, AccountUtil.getLoginInfo(this)!!.tbs).enqueue(object : Callback { + override fun onResponse(call: Call, response: Response) { + val data = response.body() + Toast.makeText(this@UserActivity, data!!.errorMsg, Toast.LENGTH_SHORT).show() + profileBean!!.user!!.setHasConcerned("0") + refreshHeader() } - @Override - public void onFailure(@NotNull Call call, @NotNull Throwable t) { - Toast.makeText(UserActivity.this, t.getMessage(), Toast.LENGTH_SHORT).show(); + override fun onFailure(call: Call, t: Throwable) { + Toast.makeText(this@UserActivity, t.message, Toast.LENGTH_SHORT).show() } - }); + }) } else { - TiebaApi.getInstance().follow(profileBean.getUser().getPortrait(), AccountUtil.getLoginInfo(this).getTbs()).enqueue(new Callback() { - @Override - public void onResponse(@NotNull Call call, @NotNull Response response) { - CommonResponse data = response.body(); - Toast.makeText(UserActivity.this, data.getErrorMsg(), Toast.LENGTH_SHORT).show(); - profileBean.getUser().setHasConcerned("1"); - refreshHeader(); + getInstance().follow(profileBean!!.user!!.portrait!!, AccountUtil.getLoginInfo(this)!!.tbs).enqueue(object : Callback { + override fun onResponse(call: Call, response: Response) { + val data = response.body() + Toast.makeText(this@UserActivity, data!!.errorMsg, Toast.LENGTH_SHORT).show() + profileBean!!.user!!.setHasConcerned("1") + refreshHeader() } - @Override - public void onFailure(@NotNull Call call, @NotNull Throwable t) { - Toast.makeText(UserActivity.this, t.getMessage(), Toast.LENGTH_SHORT).show(); + override fun onFailure(call: Call, t: Throwable) { + Toast.makeText(this@UserActivity, t.message, Toast.LENGTH_SHORT).show() } - }); + }) } } + + companion object { + const val TAG = "UserActivity" + const val EXTRA_UID = "uid" + const val EXTRA_TAB = "tab" + const val EXTRA_AVATAR = "avatar" + const val TAB_THREAD = 0 + const val TAB_REPLY = 1 + const val TAB_LIKE_FORUM = 2 + } } \ No newline at end of file diff --git a/app/src/main/java/com/huanchengfly/tieba/post/adapters/UserPostAdapter.java b/app/src/main/java/com/huanchengfly/tieba/post/adapters/UserPostAdapter.java index bb933512..009139be 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/adapters/UserPostAdapter.java +++ b/app/src/main/java/com/huanchengfly/tieba/post/adapters/UserPostAdapter.java @@ -5,41 +5,34 @@ import android.text.TextUtils; import android.view.View; import android.widget.TextView; +import com.alibaba.android.vlayout.layout.LinearLayoutHelper; import com.huanchengfly.tieba.post.R; import com.huanchengfly.tieba.post.activities.ThreadActivity; +import com.huanchengfly.tieba.post.adapters.base.BaseMultiTypeDelegateAdapter; import com.huanchengfly.tieba.post.api.models.UserPostBean; +import com.huanchengfly.tieba.post.components.MyViewHolder; import com.huanchengfly.tieba.post.utils.DateTimeUtils; import com.huanchengfly.tieba.post.utils.ImageUtil; -import com.huanchengfly.tieba.post.utils.NavigationHelper; import com.huanchengfly.tieba.post.utils.StringUtil; -import com.othershe.baseadapter.ViewHolder; -import com.othershe.baseadapter.base.MultiBaseAdapter; -import java.util.HashMap; -import java.util.Map; +import org.jetbrains.annotations.NotNull; -public class UserPostAdapter extends MultiBaseAdapter { +public class UserPostAdapter extends BaseMultiTypeDelegateAdapter { public static final int TYPE_THREAD = 0; public static final int TYPE_REPLY = 1; - private NavigationHelper navigationHelper; - public UserPostAdapter(Context context) { - super(context, null, true); - navigationHelper = NavigationHelper.newInstance(mContext); + super(context, new LinearLayoutHelper()); } @Override - protected void convert(ViewHolder viewHolder, UserPostBean.PostBean postBean, int position, int type) { + protected void convert(@NotNull MyViewHolder viewHolder, UserPostBean.PostBean postBean, int position, int type) { if (type == TYPE_THREAD) { + viewHolder.setText(R.id.forum_item_agree_count_text, postBean.getAgree() != null ? postBean.getAgree().getDiffAgreeNum() : null); viewHolder.setText(R.id.forum_item_comment_count_text, postBean.getReplyNum()); viewHolder.setVisibility(R.id.forum_item_good_tip, View.GONE); - viewHolder.setOnClickListener(R.id.forum_item, view -> { - Map map = new HashMap<>(); - map.put("tid", postBean.getThreadId()); - navigationHelper.navigationByData(NavigationHelper.ACTION_THREAD, map); - }); - if ("1".equals(postBean.getIsNoTitle())) { + viewHolder.setOnClickListener(R.id.forum_item, view -> ThreadActivity.launch(getContext(), postBean.getThreadId())); + if ("1".equals(postBean.isNoTitle())) { viewHolder.setVisibility(R.id.forum_item_title_holder, View.GONE); } else { viewHolder.setVisibility(R.id.forum_item_title_holder, View.VISIBLE); @@ -62,15 +55,15 @@ public class UserPostAdapter extends MultiBaseAdapter { textView.setText(""); textView.setVisibility(View.GONE); } - viewHolder.setText(R.id.forum_item_user_name, StringUtil.getUsernameString(mContext, postBean.getUserName(), postBean.getNameShow())); + viewHolder.setText(R.id.forum_item_user_name, StringUtil.getUsernameString(getContext(), postBean.getUserName(), postBean.getNameShow())); TextView timeTextView = viewHolder.getView(R.id.forum_item_user_time); - String relativeTime = DateTimeUtils.getRelativeTimeString(mContext, postBean.getCreateTime()); + String relativeTime = DateTimeUtils.getRelativeTimeString(getContext(), postBean.getCreateTime()); if (!TextUtils.isEmpty(postBean.getForumName())) { timeTextView.setText( - mContext.getString( + getContext().getString( R.string.template_two_string, relativeTime, - mContext.getString(R.string.text_forum_name, postBean.getForumName()) + getContext().getString(R.string.text_forum_name, postBean.getForumName()) ) ); } else { @@ -79,12 +72,12 @@ public class UserPostAdapter extends MultiBaseAdapter { ImageUtil.load(viewHolder.getView(R.id.forum_item_user_avatar), ImageUtil.LOAD_TYPE_AVATAR, postBean.getUserPortrait()); } else if (type == TYPE_REPLY) { ImageUtil.load(viewHolder.getView(R.id.message_list_item_user_avatar), ImageUtil.LOAD_TYPE_AVATAR, postBean.getUserPortrait()); - viewHolder.setText(R.id.message_list_item_user_name, StringUtil.getUsernameString(mContext, postBean.getUserName(), postBean.getNameShow())); + viewHolder.setText(R.id.message_list_item_user_name, StringUtil.getUsernameString(getContext(), postBean.getUserName(), postBean.getNameShow())); viewHolder.setText( R.id.message_list_item_user_time, - mContext.getString(R.string.template_two_string, - DateTimeUtils.getRelativeTimeString(mContext, postBean.getCreateTime()), - mContext.getString(R.string.text_forum_name, postBean.getForumName()) + getContext().getString(R.string.template_two_string, + DateTimeUtils.getRelativeTimeString(getContext(), postBean.getCreateTime()), + getContext().getString(R.string.text_forum_name, postBean.getForumName()) ) ); TextView contentTextView = viewHolder.getView(R.id.message_list_item_content); @@ -94,7 +87,7 @@ public class UserPostAdapter extends MultiBaseAdapter { } contentTextView.setText(content); viewHolder.setText(R.id.message_list_item_quote, postBean.getTitle().replace("回复:", "原贴:")); - viewHolder.setOnClickListener(R.id.message_list_item_quote, v -> ThreadActivity.launch(mContext, postBean.getThreadId())); + viewHolder.setOnClickListener(R.id.message_list_item_quote, v -> ThreadActivity.launch(getContext(), postBean.getThreadId())); } } @@ -105,6 +98,6 @@ public class UserPostAdapter extends MultiBaseAdapter { @Override protected int getViewType(int position, UserPostBean.PostBean postBean) { - return "1".equals(postBean.getIsThread()) ? TYPE_THREAD : TYPE_REPLY; + return "1".equals(postBean.isThread()) ? TYPE_THREAD : TYPE_REPLY; } } diff --git a/app/src/main/java/com/huanchengfly/tieba/post/api/models/UserPostBean.kt b/app/src/main/java/com/huanchengfly/tieba/post/api/models/UserPostBean.kt index 08d311f1..c3c37d6c 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/api/models/UserPostBean.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/api/models/UserPostBean.kt @@ -1,218 +1,153 @@ -package com.huanchengfly.tieba.post.api.models; +package com.huanchengfly.tieba.post.api.models -import com.google.gson.annotations.JsonAdapter; -import com.google.gson.annotations.SerializedName; -import com.huanchengfly.tieba.post.api.adapters.PortraitAdapter; -import com.huanchengfly.tieba.post.api.adapters.UserPostContentAdapter; -import com.huanchengfly.tieba.post.models.BaseBean; +import com.google.gson.annotations.JsonAdapter +import com.google.gson.annotations.SerializedName +import com.huanchengfly.tieba.post.api.adapters.PortraitAdapter +import com.huanchengfly.tieba.post.api.adapters.UserPostContentAdapter +import com.huanchengfly.tieba.post.models.BaseBean +import java.util.* -import java.util.ArrayList; -import java.util.List; - -public class UserPostBean extends BaseBean { +class UserPostBean : BaseBean() { @SerializedName("error_code") - private String errorCode; + val errorCode: String? = null + @SerializedName("error_msg") - private String errorMsg; + val errorMsg: String? = null + @SerializedName("hide_post") - private String hidePost; + val hidePost: String? = null + @SerializedName("post_list") - private List postList; + val postList: List? = null + + class AgreeBean { + @SerializedName("agree_num") + val agreeNum: String? = null + + @SerializedName("disagree_num") + val disagreeNum: String? = null + + @SerializedName("diff_agree_num") + val diffAgreeNum: String? = null + + @SerializedName("has_agree") + val hasAgree: String? = null - public String getErrorCode() { - return errorCode; } - public String getErrorMsg() { - return errorMsg; - } + class PostBean { + val agree: AgreeBean? = null - public String getHidePost() { - return hidePost; - } - - public List getPostList() { - return postList; - } - - public static class PostBean { @SerializedName("forum_id") - private String forumId; + val forumId: String? = null + @SerializedName("thread_id") - private String threadId; + val threadId: String? = null + @SerializedName("post_id") - private String postId; + val postId: String? = null + @SerializedName("is_thread") - private String isThread; + val isThread: String? = null + @SerializedName("create_time") - private String createTime; + val createTime: String? = null + @SerializedName("is_ntitle") - private String isNoTitle; + val isNoTitle: String? = null + @SerializedName("forum_name") - private String forumName; - private String title; + val forumName: String? = null + val title: String? = null + @SerializedName("user_name") - private String userName; + val userName: String? = null + @SerializedName("is_post_deleted") - private String isPostDeleted; + val isPostDeleted: String? = null + @SerializedName("reply_num") - private String replyNum; + val replyNum: String? = null + @SerializedName("freq_num") - private String freqNum; + val freqNum: String? = null + @SerializedName("user_id") - private String userId; + val userId: String? = null + @SerializedName("name_show") - private String nameShow; - @JsonAdapter(PortraitAdapter.class) + val nameShow: String? = null + + @JsonAdapter(PortraitAdapter::class) @SerializedName("user_portrait") - private String userPortrait; + val userPortrait: String? = null + @SerializedName("post_type") - private String postType; - @JsonAdapter(UserPostContentAdapter.class) - private List content; + val postType: String? = null + + @JsonAdapter(UserPostContentAdapter::class) + val content: List? = null + @SerializedName("abstract") - private List abstracts; - - public List getAbstracts() { - return abstracts; - } - - public String getPostType() { - return postType; - } - - public String getIsNoTitle() { - return isNoTitle; - } - - public List getContent() { - return content; - } - - public String getForumId() { - return forumId; - } - - public String getThreadId() { - return threadId; - } - - public String getPostId() { - return postId; - } - - public String getIsThread() { - return isThread; - } - - public String getCreateTime() { - return createTime; - } - - public String getForumName() { - return forumName; - } - - public String getTitle() { - return title; - } - - public String getUserName() { - return userName; - } - - public String getIsPostDeleted() { - return isPostDeleted; - } - - public String getReplyNum() { - return replyNum; - } - - public String getFreqNum() { - return freqNum; - } - - public String getUserId() { - return userId; - } - - public String getNameShow() { - return nameShow; - } - - public String getUserPortrait() { - return userPortrait; - } + val abstracts: List? = null } - public static class ContentBean { + class ContentBean { @SerializedName("post_content") - private List postContent; + var postContent: List? = null + private set + @SerializedName("create_time") - private String createTime; + var createTime: String? = null + private set + @SerializedName("post_id") - private String postId; + var postId: String? = null + private set - public static ContentBean createContentBean(String content) { - List list = new ArrayList<>(); - list.add(new PostContentBean() - .setType("0") - .setText(content)); - return new ContentBean() - .setPostContent(list) - .setCreateTime(null) - .setPostId(null); + fun setCreateTime(createTime: String?): ContentBean { + this.createTime = createTime + return this } - public String getCreateTime() { - return createTime; + fun setPostId(postId: String?): ContentBean { + this.postId = postId + return this } - public ContentBean setCreateTime(String createTime) { - this.createTime = createTime; - return this; + fun setPostContent(postContent: List?): ContentBean { + this.postContent = postContent + return this } - public String getPostId() { - return postId; - } - - public ContentBean setPostId(String postId) { - this.postId = postId; - return this; - } - - public List getPostContent() { - return postContent; - } - - public ContentBean setPostContent(List postContent) { - this.postContent = postContent; - return this; + companion object { + fun createContentBean(content: String?): ContentBean { + val list: MutableList = ArrayList() + list.add(PostContentBean() + .setType("0") + .setText(content)) + return ContentBean() + .setPostContent(list) + .setCreateTime(null) + .setPostId(null) + } } } - public static class PostContentBean { - private String type; - private String text; + class PostContentBean { + var type: String? = null + private set + var text: String? = null + private set - public String getType() { - return type; + fun setType(type: String?): PostContentBean { + this.type = type + return this } - public PostContentBean setType(String type) { - this.type = type; - return this; - } - - public String getText() { - return text; - } - - public PostContentBean setText(String text) { - this.text = text; - return this; + fun setText(text: String?): PostContentBean { + this.text = text + return this } } -} +} \ No newline at end of file diff --git a/app/src/main/java/com/huanchengfly/tieba/post/fragments/UserPostFragment.kt b/app/src/main/java/com/huanchengfly/tieba/post/fragments/UserPostFragment.kt index ba1863be..fe433c2d 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/fragments/UserPostFragment.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/fragments/UserPostFragment.kt @@ -1,197 +1,179 @@ -package com.huanchengfly.tieba.post.fragments; +package com.huanchengfly.tieba.post.fragments +import android.os.Bundle +import android.view.View +import android.widget.Toast +import androidx.recyclerview.widget.RecyclerView +import butterknife.BindView +import com.alibaba.android.vlayout.DelegateAdapter +import com.alibaba.android.vlayout.VirtualLayoutManager +import com.huanchengfly.tieba.post.R +import com.huanchengfly.tieba.post.activities.FloorActivity.Companion.launch +import com.huanchengfly.tieba.post.activities.ThreadActivity +import com.huanchengfly.tieba.post.adapters.SingleLayoutDelegateAdapter +import com.huanchengfly.tieba.post.adapters.UserPostAdapter +import com.huanchengfly.tieba.post.api.TiebaApi.getInstance +import com.huanchengfly.tieba.post.api.models.UserPostBean +import com.huanchengfly.tieba.post.components.MyViewHolder +import com.huanchengfly.tieba.post.components.dividers.SpacesItemDecoration +import com.huanchengfly.tieba.post.utils.DisplayUtil +import com.huanchengfly.tieba.post.utils.ThemeUtil +import com.scwang.smart.refresh.layout.SmartRefreshLayout +import com.scwang.smart.refresh.layout.api.RefreshLayout +import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response -import android.content.Intent; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; -import android.widget.Toast; +class UserPostFragment : BaseFragment() { -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; + @BindView(R.id.refresh) + lateinit var refreshLayout: SmartRefreshLayout -import com.huanchengfly.tieba.post.R; -import com.huanchengfly.tieba.post.activities.FloorActivity; -import com.huanchengfly.tieba.post.activities.ThreadActivity; -import com.huanchengfly.tieba.post.adapters.UserPostAdapter; -import com.huanchengfly.tieba.post.api.TiebaApi; -import com.huanchengfly.tieba.post.api.models.UserPostBean; -import com.huanchengfly.tieba.post.components.MyLinearLayoutManager; -import com.huanchengfly.tieba.post.components.dividers.CommonDivider; -import com.huanchengfly.tieba.post.utils.ThemeUtil; + @BindView(R.id.user_post_reclcyer_view) + lateinit var recyclerView: RecyclerView -import org.jetbrains.annotations.NotNull; + private val virtualLayoutManager: VirtualLayoutManager by lazy { VirtualLayoutManager(attachContext) } + private val delegateAdapter: DelegateAdapter by lazy { DelegateAdapter(virtualLayoutManager) } + private val userPostAdapter: UserPostAdapter by lazy { UserPostAdapter(attachContext) } -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Response; + private var userPostBean: UserPostBean? = null + private var uid: String? = null + private var isThread = false + private var page = 0 + private var hidePost = false -public class UserPostFragment extends BaseFragment { - public static final String PARAM_UID = "uid"; - public static final String PARAM_IS_THREAD = "is_thread"; - public static final String TAG = UserPostFragment.class.getSimpleName(); - - private SwipeRefreshLayout refreshLayout; - private RecyclerView recyclerView; - private UserPostAdapter userPostAdapter; - - private View emptyView; - private TextView emptyTipView; - - private UserPostBean userPostBean; - - private String uid; - private boolean isThread; - private int page; - - public UserPostFragment() { - } - - public static UserPostFragment newInstance(String uid) { - return newInstance(uid, true); - } - - public static UserPostFragment newInstance(String uid, boolean isThread) { - UserPostFragment fragment = new UserPostFragment(); - Bundle args = new Bundle(); - args.putString(PARAM_UID, uid); - args.putBoolean(PARAM_IS_THREAD, isThread); - fragment.setArguments(args); - return fragment; - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - Bundle args = getArguments(); + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val args = arguments if (args != null) { - uid = args.getString(PARAM_UID, null); - isThread = args.getBoolean(PARAM_IS_THREAD, true); + uid = args.getString(PARAM_UID, null) + isThread = args.getBoolean(PARAM_IS_THREAD, true) } } - @Override - int getLayoutId() { - return R.layout.fragment_user_post; + public override fun getLayoutId(): Int { + return R.layout.fragment_user_post } - @NotNull - @Override - public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View contentView = super.onCreateView(inflater, container, savedInstanceState); - refreshLayout = contentView.findViewById(R.id.refresh); - refreshLayout.setNestedScrollingEnabled(true); - ThemeUtil.setThemeForSwipeRefreshLayout(refreshLayout); - refreshLayout.setOnRefreshListener(this::refresh); - recyclerView = contentView.findViewById(R.id.user_post_reclcyer_view); - recyclerView.addItemDecoration(new CommonDivider(getAttachContext(), MyLinearLayoutManager.VERTICAL, R.drawable.drawable_divider_8dp)); - userPostAdapter = new UserPostAdapter(getAttachContext()); - emptyView = View.inflate(getAttachContext(), R.layout.layout_empty_view, null); - emptyTipView = emptyView.findViewById(R.id.empty_tip); - userPostAdapter.setOnMultiItemClickListener((viewHolder, postBean, position, viewType) -> { - switch (viewType) { - case UserPostAdapter.TYPE_THREAD: - getAttachContext().startActivity(new Intent(getAttachContext(), ThreadActivity.class) - .putExtra("tid", postBean.getThreadId())); - break; - case UserPostAdapter.TYPE_REPLY: - if ("0".equals(postBean.getPostType())) { - getAttachContext().startActivity(new Intent(getAttachContext(), FloorActivity.class) - .putExtra("tid", postBean.getThreadId()) - .putExtra("pid", postBean.getPostId())); - } else { - getAttachContext().startActivity(new Intent(getAttachContext(), FloorActivity.class) - .putExtra("tid", postBean.getThreadId()) - .putExtra("spid", postBean.getPostId())); - } - break; + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + refreshLayout.isNestedScrollingEnabled = true + ThemeUtil.setThemeForSmartRefreshLayout(refreshLayout) + refreshLayout.setOnRefreshLoadMoreListener(object : OnRefreshLoadMoreListener { + override fun onRefresh(refreshLayout: RefreshLayout) { + refresh() } - }); - userPostAdapter.setLoadingView(R.layout.layout_footer_loading); - userPostAdapter.setEmptyView(emptyView); - userPostAdapter.setLoadEndView(R.layout.layout_footer_loadend); - userPostAdapter.setLoadFailedView(R.layout.layout_footer_load_failed); - userPostAdapter.setOnLoadMoreListener(this::load); - recyclerView.setLayoutManager(new MyLinearLayoutManager(getAttachContext())); - recyclerView.setAdapter(userPostAdapter); - return contentView; - } - public void load(boolean isReload) { - if (!isReload) { - page += 1; + override fun onLoadMore(refreshLayout: RefreshLayout) { + load() + } + }) + recyclerView.addItemDecoration(SpacesItemDecoration(0, 0, 0, DisplayUtil.dp2px(attachContext, 12f))) + recyclerView.layoutManager = virtualLayoutManager + recyclerView.adapter = delegateAdapter + userPostAdapter.setOnItemClickListener { _, postBean, _ -> + if ("1" == postBean.isThread) { + ThreadActivity.launch(attachContext, postBean.threadId!!) + } else { + if ("0" == postBean.postType) { + launch(attachContext, postBean.threadId!!, postBean.threadId) + } else { + launch(attachContext, postBean.threadId!!, null, postBean.threadId) + } + } } - TiebaApi.getInstance() - .userPost(uid, page, isThread) - .enqueue(new Callback() { - @Override - public void onResponse(@NotNull Call call, @NotNull Response response) { - UserPostBean data = response.body(); - userPostBean = data; - if ("0".equals(data.getHidePost())) { - userPostAdapter.setLoadMoreData(data.getPostList()); - if (data.getPostList().size() <= 0) { - emptyTipView.setText(R.string.tip_empty); - userPostAdapter.loadEnd(); - } + } + + fun refreshAdapter() { + delegateAdapter.clear() + if (hidePost || userPostAdapter.itemCount == 0) { + delegateAdapter.addAdapter(object : SingleLayoutDelegateAdapter(attachContext, R.layout.layout_empty_view) { + override fun convert(viewHolder: MyViewHolder, itemView: View) { + viewHolder.setText( + R.id.empty_tip, + if (hidePost) R.string.tip_user_hide else R.string.tip_empty + ) + } + }) + } else { + delegateAdapter.addAdapter(userPostAdapter) + } + delegateAdapter.notifyDataSetChanged() + } + + fun load() { + getInstance() + .userPost(uid!!, page + 1, isThread) + .enqueue(object : Callback { + override fun onResponse(call: Call, response: Response) { + page += 1 + val data = response.body() + userPostBean = data + refreshLayout.finishLoadMore() + if (data!!.postList.isNullOrEmpty()) { + refreshLayout.setNoMoreData(true) } else { - emptyTipView.setText(R.string.tip_user_hide); - userPostAdapter.loadEnd(); + userPostAdapter.insert(data.postList!!) } } - @Override - public void onFailure(@NotNull Call call, @NotNull Throwable t) { - Toast.makeText(getAttachContext(), t.getMessage(), Toast.LENGTH_SHORT).show(); - userPostAdapter.loadFailed(); + override fun onFailure(call: Call, t: Throwable) { + Toast.makeText(attachContext, t.message, Toast.LENGTH_SHORT).show() + refreshLayout.finishLoadMore(false) } - }); + }) } - public void refresh() { - page = 1; - userPostAdapter.reset(); - refreshLayout.setRefreshing(true); - TiebaApi.getInstance() - .userPost(uid, page, isThread) - .enqueue(new Callback() { - @Override - public void onResponse(@NotNull Call call, @NotNull Response response) { - UserPostBean data = response.body(); - userPostBean = data; - if ("0".equals(data.getHidePost())) { - userPostAdapter.setNewData(data.getPostList()); - if (data.getPostList().size() <= 0) { - emptyTipView.setText(R.string.tip_empty); - } + fun refresh() { + page = 1 + userPostAdapter.reset() + getInstance() + .userPost(uid!!, page, isThread) + .enqueue(object : Callback { + override fun onResponse(call: Call, response: Response) { + val data = response.body() + userPostBean = data + hidePost = "1" == data!!.hidePost + if (!hidePost) { + userPostAdapter.setData(data.postList) } else { - emptyTipView.setText(R.string.tip_user_hide); - userPostAdapter.loadEnd(); + refreshLayout.setNoMoreData(true) } - refreshLayout.setRefreshing(false); + refreshLayout.finishRefresh() + refreshAdapter() } - @Override - public void onFailure(@NotNull Call call, @NotNull Throwable t) { - Toast.makeText(getAttachContext(), t.getMessage(), Toast.LENGTH_SHORT).show(); - refreshLayout.setRefreshing(false); + override fun onFailure(call: Call, t: Throwable) { + Toast.makeText(attachContext, t.message, Toast.LENGTH_SHORT).show() + refreshLayout.finishRefresh(false) } - }); + }) } - @Override - protected void onFragmentFirstVisible() { - refresh(); + override fun onFragmentFirstVisible() { + refreshLayout.autoRefresh() } - @Override - protected void onFragmentVisibleChange(boolean isVisible) { + override fun onFragmentVisibleChange(isVisible: Boolean) { if (isVisible && userPostBean == null) { - refresh(); + refreshLayout.autoRefresh() + } + } + + companion object { + const val PARAM_UID = "uid" + const val PARAM_IS_THREAD = "is_thread" + val TAG = UserPostFragment::class.java.simpleName + + @JvmOverloads + fun newInstance(uid: String?, isThread: Boolean = true): UserPostFragment { + val fragment = UserPostFragment() + val args = Bundle() + args.putString(PARAM_UID, uid) + args.putBoolean(PARAM_IS_THREAD, isThread) + fragment.arguments = args + return fragment } } } \ No newline at end of file diff --git a/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintToolbar.java b/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintToolbar.java index 91eccb0d..35c9131a 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintToolbar.java +++ b/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintToolbar.java @@ -39,7 +39,7 @@ public class TintToolbar extends Toolbar implements Tintable { return; } if (attrs == null) { - mBackgroundTintResId = R.color.default_color_toolbar; + mBackgroundTintResId = 0; mItemTintResId = R.color.default_color_toolbar_item; mSecondaryItemTintResId = R.color.default_color_toolbar_item_secondary; mActiveItemTintResId = R.color.default_color_toolbar_item_active; @@ -47,7 +47,7 @@ public class TintToolbar extends Toolbar implements Tintable { return; } TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.TintToolbar, defStyleAttr, 0); - mBackgroundTintResId = array.getResourceId(R.styleable.TintToolbar_toolbarBackgroundTint, R.color.default_color_toolbar); + mBackgroundTintResId = array.getResourceId(R.styleable.TintToolbar_toolbarBackgroundTint, 0); mItemTintResId = array.getResourceId(R.styleable.TintToolbar_itemTint, R.color.default_color_toolbar_item); mSecondaryItemTintResId = array.getResourceId(R.styleable.TintToolbar_secondaryItemTint, R.color.default_color_toolbar_item_secondary); mActiveItemTintResId = array.getResourceId(R.styleable.TintToolbar_activeItemTint, R.color.default_color_toolbar_item_active); @@ -74,9 +74,6 @@ public class TintToolbar extends Toolbar implements Tintable { } private void fixColor() { - if (mBackgroundTintResId == 0) { - mBackgroundTintResId = R.color.default_color_toolbar; - } if (mItemTintResId == 0) { mItemTintResId = R.color.default_color_toolbar_item; } @@ -89,10 +86,12 @@ public class TintToolbar extends Toolbar implements Tintable { } private void tintBackground() { - if (getBackground() == null) { - setBackgroundColor(ThemeUtils.getColorById(getContext(), mBackgroundTintResId)); - } else { - setBackgroundTintList(ColorStateList.valueOf(ThemeUtils.getColorById(getContext(), mBackgroundTintResId))); + if (mBackgroundTintResId != 0) { + if (getBackground() == null) { + setBackgroundColor(ThemeUtils.getColorById(getContext(), mBackgroundTintResId)); + } else { + setBackgroundTintList(ColorStateList.valueOf(ThemeUtils.getColorById(getContext(), mBackgroundTintResId))); + } } } diff --git a/app/src/main/res/drawable/user_header.jpg b/app/src/main/res/drawable/user_header.jpg new file mode 100644 index 00000000..6855628a Binary files /dev/null and b/app/src/main/res/drawable/user_header.jpg differ diff --git a/app/src/main/res/layout/activity_user.xml b/app/src/main/res/layout/activity_user.xml index 5cf782c4..cfea4152 100644 --- a/app/src/main/res/layout/activity_user.xml +++ b/app/src/main/res/layout/activity_user.xml @@ -1,115 +1,179 @@ - - - + + + - - - + android:layout_height="0dp" + android:scaleType="centerCrop" + android:src="@drawable/user_header" + android:layout_alignParentTop="true" + android:layout_alignParentStart="true" + android:layout_alignParentEnd="true" + android:layout_alignBottom="@id/user_center_header" /> + + + + + - + + - + android:layout_centerVertical="true" + tools:text="编辑资料" + tools:ignore="RelativeOverlap" /> - - - + + + + + + + - + android:layout_height="0dp" + android:alpha="0" + android:background="@color/user_center_header_mask" + android:layout_alignParentTop="true" + android:layout_alignParentStart="true" + android:layout_alignParentEnd="true" + android:layout_alignBottom="@id/user_center_header" /> + + + android:layout_height="wrap_content" /> - - + android:layout_height="wrap_content"> + + + + + + + + - - - \ No newline at end of file + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_user_post.xml b/app/src/main/res/layout/fragment_user_post.xml index b54bfbe4..9f6a2dad 100644 --- a/app/src/main/res/layout/fragment_user_post.xml +++ b/app/src/main/res/layout/fragment_user_post.xml @@ -1,12 +1,33 @@ - + + + - \ No newline at end of file + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_forum_thread_common.xml b/app/src/main/res/layout/item_forum_thread_common.xml index a64ef06a..d1a879ec 100644 --- a/app/src/main/res/layout/item_forum_thread_common.xml +++ b/app/src/main/res/layout/item_forum_thread_common.xml @@ -9,7 +9,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" app:materialCardBackgroundTint="@color/default_color_card" - app:cardCornerRadius="8dp" + app:cardCornerRadius="10dp" app:contentPadding="16dp" app:cardElevation="0dp"> diff --git a/app/src/main/res/layout/item_message_list.xml b/app/src/main/res/layout/item_message_list.xml index 36da8e0e..a77d4438 100644 --- a/app/src/main/res/layout/item_message_list.xml +++ b/app/src/main/res/layout/item_message_list.xml @@ -5,6 +5,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" app:backgroundTint="@color/default_color_card" + android:background="@drawable/bg_radius_10dp" android:paddingStart="@dimen/padding_start_default" android:paddingEnd="@dimen/padding_end_default" android:paddingTop="12dp" diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index f79ed417..42e61c30 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -182,4 +182,6 @@ #FF3373EE #FF8E6DCA #50000000 + #50FFFFFF + #90000000 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f77bec46..d03519a3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -368,7 +368,7 @@ 加载失败 上拉加载更多 释放开始加载 - %1$s·%2$s + %1$s · %2$s 搜吧 搜贴 搜人 @@ -426,4 +426,5 @@ 慢速模式 开启后,一键签到时签到每个吧的时间间隔将会更长 一键签到时签到每个吧的时间间隔将会更长 + 全部贴子(%1$s)