修改资源名称和去掉无用代码
This commit is contained in:
@@ -1,123 +0,0 @@
|
||||
package com.mogo.module.push.activity
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.mogo.module.push.Config
|
||||
import com.mogo.module.push.R
|
||||
import com.mogo.module.push.adapter.PushMessageAdapter
|
||||
import com.mogo.module.push.model.PushBean
|
||||
import com.mogo.module.push.repository.PushRepository
|
||||
import com.mogo.module.push.utils.AnalyticsUtils
|
||||
import com.mogo.module.push.utils.HandlerUtils
|
||||
import com.mogo.module.push.utils.startClearAnimator
|
||||
import com.mogo.module.push.view.PushItemAnimator
|
||||
import com.mogo.module.push.view.SwipeItemLayout
|
||||
import com.mogo.module.push.view.getApis
|
||||
import com.mogo.module.push.viewmodel.MessageViewModel
|
||||
import com.mogo.service.intent.IMogoIntentListener
|
||||
import com.mogo.utils.UiThreadHandler
|
||||
import com.mogo.utils.logger.Logger
|
||||
import kotlinx.android.synthetic.main.module_push_message_activity.*
|
||||
|
||||
class PushMessageActivity : AppCompatActivity(), IMogoIntentListener {
|
||||
private lateinit var viewModel: MessageViewModel
|
||||
private var adapter = PushMessageAdapter()
|
||||
private var clearing = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
// window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||
setContentView(R.layout.module_push_message_activity)
|
||||
AnalyticsUtils.track(Config.NEWS_HISTORY_OPEN)
|
||||
module_push_activity_close.setOnClickListener {
|
||||
AnalyticsUtils.track(Config.NEWS_HISTORY_CLOSE)
|
||||
finish()
|
||||
}
|
||||
module_push_activity_clear.setOnClickListener {
|
||||
AnalyticsUtils.track(Config.NEWS_HISTORY_ALL_CLEAR)
|
||||
if (!clearing) {
|
||||
clearing = true
|
||||
startClearAnimator(module_push_activity_recycler_view) {
|
||||
viewModel.deleteAll()
|
||||
clearing = false
|
||||
}
|
||||
}
|
||||
}
|
||||
adapter.deletePushBean = object : PushMessageAdapter.PushAdapterListener {
|
||||
override fun lastItemShow(show: Boolean) {
|
||||
if (!show && !clearing) {
|
||||
val size = viewModel.list?.size ?: 0
|
||||
if (size > 0 && size < module_push_activity_recycler_view.childCount) {
|
||||
return
|
||||
}
|
||||
}
|
||||
module_push_activity_clear.visibility =
|
||||
if (show) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
override fun deleteBean(bean: PushBean, action: Boolean) {
|
||||
if (clearing) return
|
||||
viewModel.delete(bean)
|
||||
if (action) {
|
||||
AnalyticsUtils.track(Config.NEWS_HISTORY_ONE_CLICK, "title", bean.title)
|
||||
finish()
|
||||
} else {
|
||||
AnalyticsUtils.track(Config.NEWS_HISTORY_ONE_CLEAR, "title", bean.title)
|
||||
adapter.removeItem(bean)
|
||||
if (adapter.datas?.size ?: 0 == 0) {
|
||||
module_push_activity_not_data.visibility = View.VISIBLE
|
||||
}
|
||||
updateHistoryMessageCount()
|
||||
}
|
||||
}
|
||||
}
|
||||
module_push_activity_recycler_view.layoutManager = LinearLayoutManager(this)
|
||||
module_push_activity_recycler_view.adapter = adapter
|
||||
module_push_activity_recycler_view.itemAnimator = PushItemAnimator()
|
||||
module_push_activity_recycler_view.addOnItemTouchListener(
|
||||
SwipeItemLayout.OnSwipeItemTouchListener(this)
|
||||
)
|
||||
viewModel = MessageViewModel(object :
|
||||
MessageViewModel.MessageListChange {
|
||||
override fun messageListChange(list: MutableList<PushBean>?) {
|
||||
runOnUiThread {
|
||||
var size = list?.size ?: 0
|
||||
adapter.datas = list
|
||||
module_push_activity_not_data.visibility = if (size > 0) View.GONE else View.VISIBLE
|
||||
updateHistoryMessageCount()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
getApis(this).intentManagerApi.registerIntentListener(Intent.ACTION_CLOSE_SYSTEM_DIALOGS, this)
|
||||
}
|
||||
|
||||
private fun updateHistoryMessageCount(){
|
||||
HandlerUtils.mBgHandler.post{
|
||||
var count = PushRepository.pushRepository.pushBeanDao.getAllCount()
|
||||
UiThreadHandler.post {
|
||||
module_push_activity_title.text = if (count > 0) "历史消息(${count})" else "历史消息"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onIntentReceived(intentStr: String?, intent: Intent?) {
|
||||
if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(intentStr)) {
|
||||
Logger.d("PushMessageActivity", "close by home key.")
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
getApis(this).intentManagerApi.unregisterIntentListener(Intent.ACTION_CLOSE_SYSTEM_DIALOGS, this)
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,8 @@ public
|
||||
*/
|
||||
class MessageHistoryFragment extends MvpFragment< MessageHistoryView, MessageHistoryPresenter > implements MessageHistoryView, IMogoMsgCenterListener {
|
||||
|
||||
private static final String TAG = "MessageHistoryFragment";
|
||||
|
||||
private View mClear;
|
||||
private RecyclerView mHistoryList;
|
||||
private TextView mTitle;
|
||||
@@ -55,11 +57,11 @@ class MessageHistoryFragment extends MvpFragment< MessageHistoryView, MessageHis
|
||||
|
||||
@Override
|
||||
protected void initViews() {
|
||||
mClear = findViewById( R.id.module_push_activity_clear );
|
||||
mHistoryList = findViewById( R.id.module_push_activity_recycler_view );
|
||||
mTitle = findViewById( R.id.module_push_activity_title );
|
||||
mEmptyPlaceHolder = findViewById( R.id.module_push_activity_not_data );
|
||||
mClose = findViewById( R.id.module_push_activity_close );
|
||||
mClear = findViewById( R.id.module_push_id_clear );
|
||||
mHistoryList = findViewById( R.id.module_push_id_recycler_view );
|
||||
mTitle = findViewById( R.id.module_push_id_title );
|
||||
mEmptyPlaceHolder = findViewById( R.id.module_push_id_not_data );
|
||||
mClose = findViewById( R.id.module_push_id_close );
|
||||
|
||||
AnalyticsUtils.track( Config.NEWS_HISTORY_OPEN, null );
|
||||
mClose.setOnClickListener( view -> {
|
||||
@@ -74,7 +76,6 @@ class MessageHistoryFragment extends MvpFragment< MessageHistoryView, MessageHis
|
||||
() -> {
|
||||
mViewModel.deleteAll();
|
||||
mClearing = false;
|
||||
return null;
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -104,9 +105,11 @@ class MessageHistoryFragment extends MvpFragment< MessageHistoryView, MessageHis
|
||||
@Override
|
||||
public void lastItemShow( boolean show ) {
|
||||
if ( !show && !mClearing ) {
|
||||
int size = mViewModel.getList().size();
|
||||
if ( size > 0 && size < mHistoryList.getChildCount() ) {
|
||||
return;
|
||||
if ( mViewModel.getList() != null ) {
|
||||
int size = mViewModel.getList().size();
|
||||
if ( size > 0 && size < mHistoryList.getChildCount() ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
mClear.setVisibility( show ? View.VISIBLE : View.GONE );
|
||||
|
||||
@@ -4,8 +4,11 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.get
|
||||
import androidx.core.view.isNotEmpty
|
||||
import com.mogo.utils.logger.Logger
|
||||
|
||||
fun startClearAnimator(root: ViewGroup, method: () -> Unit) {
|
||||
val TAG: String = "AnimatorUtils.kt"
|
||||
|
||||
fun startClearAnimator(root: ViewGroup, runnable: Runnable) {
|
||||
if (root.isNotEmpty()) {
|
||||
var view: View
|
||||
var size = root.childCount - 1
|
||||
@@ -13,13 +16,19 @@ fun startClearAnimator(root: ViewGroup, method: () -> Unit) {
|
||||
view = root[i]
|
||||
view.animate().translationX(-view.width.toFloat()).apply {
|
||||
if (i == 0) {
|
||||
withEndAction(method)
|
||||
try {
|
||||
withEndAction(runnable)
|
||||
} catch (e: Exception) {
|
||||
Logger.e(TAG, e, "startClearAnimator->withEndAction")
|
||||
}
|
||||
}
|
||||
duration = 200
|
||||
startDelay = 100 * (size - i).toLong()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
method()
|
||||
runnable?.apply {
|
||||
run()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user