add light mode res

This commit is contained in:
wangcongtao
2020-09-02 10:26:08 +08:00
parent 5673ec457f
commit bc4dd4547d
96 changed files with 555 additions and 69 deletions

View File

@@ -0,0 +1,39 @@
package com.mogo.module.push;
import android.content.Context;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.mogo.module.push.base.PushUIConstants;
import com.mogo.module.push.fragment.MessageHistoryFragment;
import com.mogo.service.fragmentmanager.IFragmentProvider;
public
/**
* @author congtaowang
* @since 2020/9/1
*
* 描述
*/
@Route( path = PushUIConstants.Push_MESSAGE_ACTIVITY_PATH )
class PushHistoryUiProvider implements IFragmentProvider {
@Override
public Fragment createFragment( FragmentActivity activity, int containerId, Bundle date ) {
Fragment fragment = new MessageHistoryFragment();
activity.getSupportFragmentManager()
.beginTransaction()
.add( containerId, fragment, PushUIConstants.Push_MESSAGE_ACTIVITY_PATH )
.show( fragment )
.commitNowAllowingStateLoss();
return fragment;
}
@Override
public void init( Context context ) {
}
}

View File

@@ -5,11 +5,9 @@ import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.mogo.module.push.Config
import com.mogo.module.push.R
import com.mogo.module.push.adapter.PushMessageAdapter
import com.mogo.module.push.base.PushUIConstants
import com.mogo.module.push.model.PushBean
import com.mogo.module.push.repository.PushRepository
import com.mogo.module.push.utils.AnalyticsUtils
@@ -24,7 +22,6 @@ import com.mogo.utils.UiThreadHandler
import com.mogo.utils.logger.Logger
import kotlinx.android.synthetic.main.module_push_message_activity.*
@Route(path = PushUIConstants.Push_MESSAGE_ACTIVITY_PATH)
class PushMessageActivity : AppCompatActivity(), IMogoIntentListener {
private lateinit var viewModel: MessageViewModel
private var adapter = PushMessageAdapter()

View File

@@ -45,7 +45,7 @@ class PushMessageAdapter : RecyclerView.Adapter<PushMessageAdapter.MessageViewHo
val position = it.indexOf(bean)
if (position >= 0) {
it.removeAt(position)
notifyItemRemoved(position)
notifyDataSetChanged()
}
if (itemCount == 0) {
deletePushBean.lastItemShow(false)

View File

@@ -0,0 +1,187 @@
package com.mogo.module.push.fragment;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.commons.analytics.AnalyticsUtils;
import com.mogo.commons.mvp.MvpFragment;
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.AnimatorUtilsKt;
import com.mogo.module.push.utils.HandlerUtils;
import com.mogo.module.push.view.GlobalToolsKt;
import com.mogo.module.push.view.PushItemAnimator;
import com.mogo.module.push.view.SwipeItemLayout;
import com.mogo.module.push.viewmodel.MessageViewModel;
import com.mogo.service.statusmanager.IMogoMsgCenterListener;
import com.mogo.utils.UiThreadHandler;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
public
/**
* @author congtaowang
* @since 2020/9/1
*
* 描述
*/
class MessageHistoryFragment extends MvpFragment< MessageHistoryView, MessageHistoryPresenter > implements MessageHistoryView, IMogoMsgCenterListener {
private View mClear;
private RecyclerView mHistoryList;
private TextView mTitle;
private View mEmptyPlaceHolder;
private View mClose;
private boolean mClearing = false;
private PushMessageAdapter mAdapter = new PushMessageAdapter();
private MessageViewModel mViewModel;
@Override
protected int getLayoutId() {
return R.layout.module_push_message_hisotry_fragment;
}
@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 );
AnalyticsUtils.track( Config.NEWS_HISTORY_OPEN, null );
mClose.setOnClickListener( view -> {
exitSelf();
} );
mClear.setOnClickListener( view -> {
AnalyticsUtils.track( Config.NEWS_HISTORY_ALL_CLEAR, null );
if ( !mClearing ) {
mClearing = true;
AnimatorUtilsKt.startClearAnimator(
mHistoryList,
() -> {
mViewModel.deleteAll();
mClearing = false;
return null;
}
);
}
} );
mAdapter.deletePushBean = new PushMessageAdapter.PushAdapterListener() {
@Override
public void deleteBean( @NotNull PushBean bean, boolean action ) {
if ( mClearing ) {
return;
}
mViewModel.delete( bean );
if ( action ) {
Map< String, Object > prop = new HashMap<>();
prop.put( "title", bean.getTitle() );
AnalyticsUtils.track( Config.NEWS_HISTORY_ONE_CLICK, prop );
exitSelf();
} else {
AnalyticsUtils.track( Config.NEWS_HISTORY_ONE_CLEAR, null );
mAdapter.removeItem( bean );
if ( mAdapter.getItemCount() == 0 ) {
mEmptyPlaceHolder.setVisibility( View.VISIBLE );
}
updateHistoryMessageCount();
}
}
@Override
public void lastItemShow( boolean show ) {
if ( !show && !mClearing ) {
int size = mViewModel.getList().size();
if ( size > 0 && size < mHistoryList.getChildCount() ) {
return;
}
mClear.setVisibility( show ? View.VISIBLE : View.GONE );
}
}
};
mViewModel = new MessageViewModel( list -> {
UiThreadHandler.post( () -> {
int size = list == null ? 0 : list.size();
mAdapter.setDatas( list );
mEmptyPlaceHolder.setVisibility( size > 0 ? View.GONE : View.VISIBLE );
updateHistoryMessageCount();
} );
} );
mHistoryList.setLayoutManager( new LinearLayoutManager( AbsMogoApplication.getApp() ) );
mHistoryList.setAdapter( mAdapter );
mHistoryList.setItemAnimator( new PushItemAnimator() );
mHistoryList.addOnItemTouchListener( new SwipeItemLayout.OnSwipeItemTouchListener( getContext() ) );
GlobalToolsKt.getApis( getContext() ).getMsgCenterApi().registerMsgCenterListener( this );
}
private void exitSelf() {
try {
getActivity().getSupportFragmentManager().beginTransaction()
.remove( this )
.commitNowAllowingStateLoss();
} catch ( Exception e ) {
e.printStackTrace();
}
}
private void updateHistoryMessageCount() {
HandlerUtils.INSTANCE.getMBgHandler().post( () -> {
int count = 0;
try {
count = PushRepository.Companion.getPushRepository().getPushBeanDao().getAllCount();
} catch ( Exception e ) {
count = 0;
}
renderHistoryMessageCount( count );
} );
}
private void renderHistoryMessageCount( int count ) {
UiThreadHandler.post( () -> {
try {
mTitle.setText( count > 0 ? "历史消息(" + count + ")" : "历史消息" );
} catch ( Exception e ) {
e.printStackTrace();
}
} );
}
@Override
public void onMsgChanged( boolean hasMsg, int amount ) {
HandlerUtils.INSTANCE.getMBgHandler().post( () -> {
mViewModel.setList( PushRepository.Companion.getPushRepository().getAll() );
} );
}
@Override
public void onResume() {
super.onResume();
}
@NonNull
@Override
protected MessageHistoryPresenter createPresenter() {
return new MessageHistoryPresenter( this );
}
@Override
public void onDestroyView() {
super.onDestroyView();
GlobalToolsKt.getApis( getContext() ).getMsgCenterApi().unregisterMsgCenterListener( this );
}
}

View File

@@ -0,0 +1,17 @@
package com.mogo.module.push.fragment;
import com.mogo.commons.mvp.Presenter;
public
/**
* @author congtaowang
* @since 2020/9/1
*
* 描述
*/
class MessageHistoryPresenter extends Presenter< MessageHistoryView > {
public MessageHistoryPresenter( MessageHistoryView view ) {
super( view );
}
}

View File

@@ -0,0 +1,13 @@
package com.mogo.module.push.fragment;
import com.mogo.commons.mvp.IView;
public
/**
* @author congtaowang
* @since 2020/9/1
*
* 描述
*/
interface MessageHistoryView extends IView {
}

View File

@@ -85,6 +85,12 @@ class PushRepository(mContext: Context) {
}
pushBeanQueue.offer(bean)
}
if ( bean != null) {
HandlerUtils.mBgHandler.post {
pushBeanDao.insertAll(bean)
updateMsgNum()
}
}
startIterate()
}
})
@@ -158,13 +164,6 @@ class PushRepository(mContext: Context) {
}
fun iterateNext(needSave: Boolean = false) {
if (needSave && pushViewModel.pushBean != null) {
val bean = pushViewModel.pushBean!!
HandlerUtils.mBgHandler.post {
pushBeanDao.insertAll(bean)
updateMsgNum()
}
}
try {
val nextBean = pushBeanQueue.peek()
if (nextBean == null) {