fix: 合并冲突
This commit is contained in:
commit
acbc7c957b
4
.idea/misc.xml
generated
4
.idea/misc.xml
generated
@ -1,7 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<<<<<<< HEAD
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
=======
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK">
|
||||
>>>>>>> e4f8cd19496660f3dc11140134950097331d4957
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
||||
@ -59,7 +59,6 @@ dependencies {
|
||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'
|
||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.1'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.4.1'
|
||||
implementation 'com.google.code.gson:gson:2.10'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
|
||||
@ -81,4 +80,6 @@ dependencies {
|
||||
implementation 'me.rosuh:AndroidFilePicker:0.8.2'
|
||||
// 时间选择器 https://github.com/Gredicer/datetimepicker
|
||||
implementation 'com.github.Gredicer:datetimepicker:V1.0.0'
|
||||
implementation 'com.google.code.gson:gson:2.10'
|
||||
implementation 'com.yanzhenjie.recyclerview:x:1.3.2'
|
||||
}
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:configChanges="locale"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
@ -13,7 +14,7 @@
|
||||
android:theme="@style/Theme.NavinfoVolvo"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:name="com.navinfo.volvo.MainActivity"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
|
||||
@ -6,6 +6,7 @@ import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.navigation.ui.AppBarConfiguration
|
||||
import androidx.navigation.ui.setupWithNavController
|
||||
import com.navinfo.volvo.R
|
||||
import com.navinfo.volvo.databinding.ActivityMainBinding
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
@ -25,7 +26,7 @@ class MainActivity : AppCompatActivity() {
|
||||
// menu should be considered as top level destinations.
|
||||
val appBarConfiguration = AppBarConfiguration(
|
||||
setOf(
|
||||
R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications
|
||||
R.id.navigation_home, R.id.navigation_dashboard, R.id.navigation_notifications, R.id.navigation_obtain_message
|
||||
)
|
||||
)
|
||||
// setupActionBarWithNavController(navController, appBarConfiguration)
|
||||
|
||||
@ -11,6 +11,9 @@ import androidx.sqlite.db.SupportSQLiteDatabase;
|
||||
import androidx.sqlite.db.SupportSQLiteOpenHelper;
|
||||
|
||||
import com.navinfo.volvo.db.dao.entity.Message;
|
||||
import com.navinfo.volvo.db.dao.entity.Attachment;
|
||||
import com.navinfo.volvo.db.dao.entity.Message;
|
||||
import com.navinfo.volvo.db.dao.entity.User;
|
||||
import com.tencent.wcdb.database.SQLiteCipherSpec;
|
||||
import com.tencent.wcdb.database.SQLiteDatabase;
|
||||
|
||||
@ -23,7 +26,7 @@ import com.tencent.wcdb.repair.BackupKit;
|
||||
import com.tencent.wcdb.repair.RecoverKit;
|
||||
import com.tencent.wcdb.room.db.WCDBDatabase;
|
||||
|
||||
@Database(entities = {Message.class}, version = 1, exportSchema = false)
|
||||
@Database(entities = {Message.class, Attachment.class, User.class}, version = 1, exportSchema = false)
|
||||
public abstract class MapLifeDataBase extends RoomDatabase {
|
||||
// marking the instance as volatile to ensure atomic access to the variable
|
||||
/**
|
||||
|
||||
@ -1,30 +1,47 @@
|
||||
package com.navinfo.volvo.db.dao.entity
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import androidx.room.TypeConverter
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import java.lang.reflect.Type
|
||||
import com.navinfo.volvo.tools.GsonUtil
|
||||
|
||||
class Attachment {
|
||||
lateinit var path:String
|
||||
lateinit var attachmentType: attachmentType
|
||||
}
|
||||
@Entity(tableName = "Attachment")
|
||||
data class Attachment(
|
||||
@PrimaryKey()
|
||||
var id: String,
|
||||
var pathUrl: String,
|
||||
var attachmentType: AttachmentType
|
||||
)
|
||||
|
||||
enum class attachmentType {
|
||||
enum class AttachmentType {
|
||||
PIC, AUDIO
|
||||
}
|
||||
|
||||
class AttachmentConvert {
|
||||
private val gson = Gson()
|
||||
|
||||
class AttachmentConverters() {
|
||||
@TypeConverter
|
||||
fun objectToString(list: List<Attachment>): String {
|
||||
return gson.toJson(list)
|
||||
fun stringToAttachment(value: String): Attachment {
|
||||
val type = object : TypeToken<Attachment>() {
|
||||
|
||||
}.type
|
||||
return GsonUtil.getInstance().fromJson(value, type)
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun stringToObject(json: String?): List<Attachment> {
|
||||
val listType: Type = object : TypeToken<List<Attachment>>() {}.type
|
||||
return gson.fromJson(json, listType)
|
||||
fun attachmentToString(attachment: Attachment): String {
|
||||
return GsonUtil.getInstance().toJson(attachment)
|
||||
}
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun listToString(list: MutableList<Attachment>): String {
|
||||
return GsonUtil.getInstance().toJson(list)
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun stringToList(value: String): MutableList<Attachment> {
|
||||
val type = object : TypeToken<MutableList<Attachment>>() {
|
||||
|
||||
}.type
|
||||
return GsonUtil.getInstance().fromJson(value, type)
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,43 +4,43 @@ import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import androidx.room.TypeConverters
|
||||
|
||||
@TypeConverters(AttachmentConvert::class)
|
||||
@Entity(tableName = "message")
|
||||
class Message(
|
||||
@TypeConverters(AttachmentConverters::class)
|
||||
data class Message @JvmOverloads constructor(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var id: Long = 0,
|
||||
|
||||
var netId: String = "",
|
||||
/**
|
||||
*标题
|
||||
*/
|
||||
var title: String,
|
||||
var title: String = "",
|
||||
/**
|
||||
* 信息内容
|
||||
*/
|
||||
var message: String,
|
||||
var message: String = "",
|
||||
/**
|
||||
* 操作时间
|
||||
*/
|
||||
var optionDate: String,
|
||||
var optionDate: String = "",
|
||||
/**
|
||||
* 发送时间
|
||||
*/
|
||||
var sendDate: String,
|
||||
var sendDate: String = "",
|
||||
/**
|
||||
* 信息状态
|
||||
*/
|
||||
var status: Int,
|
||||
var status: Int = 1,
|
||||
/**
|
||||
* 发送者ID
|
||||
*/
|
||||
var fromId: String,
|
||||
var fromId: String = "",
|
||||
/**
|
||||
* 接收者ID
|
||||
*/
|
||||
var toId: String,
|
||||
var toId: String = "",
|
||||
/**
|
||||
* 附件列表
|
||||
*/
|
||||
var attachment: MutableList<Attachment>
|
||||
) {
|
||||
|
||||
}
|
||||
var attachment: MutableList<Attachment> = mutableListOf()
|
||||
)
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
package com.navinfo.volvo.db.dao.entity
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
class User(
|
||||
@Entity(tableName = "User")
|
||||
data class User(
|
||||
@PrimaryKey()
|
||||
val id:String,
|
||||
var name:String,
|
||||
var nickname:String,
|
||||
|
||||
) {
|
||||
}
|
||||
)
|
||||
44
app/src/main/java/com/navinfo/volvo/tools/DisplayUtil.kt
Normal file
44
app/src/main/java/com/navinfo/volvo/tools/DisplayUtil.kt
Normal file
@ -0,0 +1,44 @@
|
||||
package com.navinfo.volvo.tools
|
||||
|
||||
import android.content.Context
|
||||
|
||||
class DisplayUtil {
|
||||
companion object {
|
||||
/**
|
||||
* 获取屏幕宽度
|
||||
*/
|
||||
fun getScreenWidth(context: Context): Int {
|
||||
return context.resources.displayMetrics.widthPixels
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取屏幕高度
|
||||
*/
|
||||
fun getScreenHeight(context: Context): Int {
|
||||
return context.resources.displayMetrics.heightPixels
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取屏幕分辨率
|
||||
*/
|
||||
fun getScreenRatio(context: Context): String {
|
||||
return getScreenHeight(context).toString() + "X" + getScreenWidth(context).toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* dp转px
|
||||
*/
|
||||
fun dip2px(context: Context, dipValue: Float): Int {
|
||||
val scale = context.resources.displayMetrics.density
|
||||
return (dipValue * scale + 0.5f).toInt()
|
||||
}
|
||||
|
||||
/**
|
||||
* px转dp
|
||||
*/
|
||||
fun px2dip(context: Context, pxValue: Float): Int {
|
||||
val scale = context.resources.displayMetrics.density
|
||||
return (pxValue / scale + 0.5f).toInt()
|
||||
}
|
||||
}
|
||||
}
|
||||
13
app/src/main/java/com/navinfo/volvo/tools/GsonUtil.kt
Normal file
13
app/src/main/java/com/navinfo/volvo/tools/GsonUtil.kt
Normal file
@ -0,0 +1,13 @@
|
||||
package com.navinfo.volvo.tools
|
||||
|
||||
import com.google.gson.Gson
|
||||
|
||||
class GsonUtil {
|
||||
companion object {
|
||||
fun getInstance() = InstanceHelper.gson
|
||||
}
|
||||
|
||||
object InstanceHelper {
|
||||
val gson: Gson = Gson()
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
package com.navinfo.volvo.ui.adapter
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.navinfo.volvo.R
|
||||
import com.navinfo.volvo.db.dao.entity.Message
|
||||
|
||||
class MessageAdapter : RecyclerView.Adapter<MessageAdapter.MyViewHolder>() {
|
||||
|
||||
var itemList: MutableList<Message> = mutableListOf()
|
||||
|
||||
fun addItem(message: Message) {
|
||||
itemList.add(message)
|
||||
notifyItemInserted(itemList.size - 1)
|
||||
}
|
||||
|
||||
fun setItem(messageList: MutableList<Message>){
|
||||
itemList = messageList
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
|
||||
val view =
|
||||
LayoutInflater.from(parent.context).inflate(R.layout.adapter_message, parent, false)
|
||||
var viewHolder = MyViewHolder(view)
|
||||
viewHolder.itemView.setOnClickListener {
|
||||
|
||||
}
|
||||
return viewHolder
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
|
||||
val message = itemList[position]
|
||||
holder.toName.text = message.fromId
|
||||
holder.messageText.text = message.message
|
||||
holder.sendTime.text = message.sendDate
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return itemList.size
|
||||
}
|
||||
|
||||
inner class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
var image: ImageView = itemView.findViewById(R.id.message_head_icon)
|
||||
var toName: TextView = itemView.findViewById(R.id.message_to_username)
|
||||
var sendTime: TextView = itemView.findViewById(R.id.message_send_time)
|
||||
var status: TextView = itemView.findViewById(R.id.message_status)
|
||||
var messageText: TextView = itemView.findViewById(R.id.message_text)
|
||||
}
|
||||
}
|
||||
@ -1,19 +1,24 @@
|
||||
package com.navinfo.volvo.ui.home
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.Display
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.Navigation
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.navinfo.volvo.R
|
||||
import com.navinfo.volvo.databinding.FragmentHomeBinding
|
||||
import com.navinfo.volvo.db.dao.entity.Message
|
||||
import com.navinfo.volvo.tools.DisplayUtil
|
||||
import com.navinfo.volvo.ui.adapter.MessageAdapter
|
||||
import com.navinfo.volvo.ui.message.ObtainMessageViewModel
|
||||
import com.yanzhenjie.recyclerview.*
|
||||
import com.yanzhenjie.recyclerview.SwipeRecyclerView.LoadMoreListener
|
||||
|
||||
class HomeFragment : Fragment() {
|
||||
class HomeFragment : Fragment(), OnItemClickListener, OnItemMenuClickListener {
|
||||
|
||||
private var _binding: FragmentHomeBinding? = null
|
||||
|
||||
@ -33,16 +38,55 @@ class HomeFragment : Fragment() {
|
||||
_binding = FragmentHomeBinding.inflate(inflater, container, false)
|
||||
val root: View = binding.root
|
||||
|
||||
val textView: TextView = binding.tvNewMessage
|
||||
textView.setOnClickListener {
|
||||
val message = Message(1, "新建标题", "", "", "", 0, "1", "2", mutableListOf())
|
||||
obtainMessageViewModel.setCurrentMessage(message)
|
||||
// 跳转到新建Message的Fragment
|
||||
Navigation.findNavController(it).navigate(R.id.home_2_obtain_message)
|
||||
}
|
||||
homeViewModel.text.observe(viewLifecycleOwner) {
|
||||
// val textView: TextView = binding.tvNewMessage
|
||||
// textView.setOnClickListener {
|
||||
// val message = Message(1, "新建标题", "", "", "", 0, "1", "2", mutableListOf())
|
||||
// obtainMessageViewModel.setCurrentMessage(message)
|
||||
// // 跳转到新建Message的Fragment
|
||||
// Navigation.findNavController(it).navigate(R.id.home_2_obtain_message)
|
||||
// }
|
||||
// homeViewModel.text.observe(viewLifecycleOwner) {
|
||||
//
|
||||
// }
|
||||
val recyclerview: SwipeRecyclerView = binding.homeMessageRecyclerview
|
||||
recyclerview.adapter = null //先设置null,否则会报错
|
||||
//创建菜单选项
|
||||
//注意:使用滑动菜单不能开启滑动删除,否则只有滑动删除没有滑动菜单
|
||||
var mSwipeMenuCreator =
|
||||
SwipeMenuCreator { _, rightMenu, position ->
|
||||
//添加菜单自动添加至尾部
|
||||
var deleteItem = SwipeMenuItem(context)
|
||||
deleteItem.height = DisplayUtil.dip2px(context!!, 60f)
|
||||
deleteItem.width = DisplayUtil.dip2px(context!!, 80f)
|
||||
deleteItem.background = context!!.getDrawable(R.color.red)
|
||||
deleteItem.text = context!!.getString(R.string.delete)
|
||||
rightMenu.addMenuItem(deleteItem)
|
||||
|
||||
//分享
|
||||
var shareItem = SwipeMenuItem(context)
|
||||
shareItem.height = DisplayUtil.dip2px(context!!, 60f)
|
||||
shareItem.width = DisplayUtil.dip2px(context!!, 80f)
|
||||
shareItem.background = context!!.getDrawable(R.color.gray)
|
||||
shareItem.text = context!!.getString(R.string.share)
|
||||
shareItem.setTextColor(R.color.white)
|
||||
rightMenu.addMenuItem(shareItem)
|
||||
|
||||
|
||||
}
|
||||
val layoutManager = LinearLayoutManager(context)
|
||||
val adapter = MessageAdapter()
|
||||
recyclerview.layoutManager = layoutManager
|
||||
recyclerview.addItemDecoration(DividerItemDecoration(context, layoutManager.orientation))
|
||||
recyclerview.setSwipeMenuCreator(mSwipeMenuCreator)
|
||||
recyclerview.setOnItemClickListener(this)
|
||||
recyclerview.useDefaultLoadMore()
|
||||
recyclerview.setLoadMoreListener {
|
||||
|
||||
}
|
||||
recyclerview.adapter = adapter
|
||||
homeViewModel.getMessageList().observe(viewLifecycleOwner, Observer { contacts ->
|
||||
adapter.setItem(contacts)
|
||||
})
|
||||
return root
|
||||
}
|
||||
|
||||
@ -50,4 +94,11 @@ class HomeFragment : Fragment() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
|
||||
override fun onItemClick(view: View?, adapterPosition: Int) {
|
||||
|
||||
}
|
||||
|
||||
override fun onItemClick(menuBridge: SwipeMenuBridge?, adapterPosition: Int) {
|
||||
}
|
||||
}
|
||||
@ -3,11 +3,32 @@ package com.navinfo.volvo.ui.home
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.navinfo.volvo.db.dao.entity.Message
|
||||
|
||||
class HomeViewModel : ViewModel() {
|
||||
|
||||
private val _text = MutableLiveData<String>().apply {
|
||||
value = "This is home Fragment"
|
||||
private val messageList: LiveData<MutableList<Message>> =
|
||||
MutableLiveData<MutableList<Message>>().apply {
|
||||
value = mutableListOf<Message>()
|
||||
value!!.add(Message())
|
||||
value!!.add(Message())
|
||||
value!!.add(Message())
|
||||
value!!.add(Message())
|
||||
value!!.add(Message())
|
||||
value!!.add(Message())
|
||||
value!!.add(Message())
|
||||
value!!.add(Message())
|
||||
value!!.add(Message())
|
||||
value!!.add(Message())
|
||||
value!!.add(Message())
|
||||
value!!.add(Message())
|
||||
value!!.add(Message())
|
||||
value!!.add(Message())
|
||||
value!!.add(Message())
|
||||
value!!.add(Message())
|
||||
}
|
||||
|
||||
fun getMessageList(): LiveData<MutableList<Message>> {
|
||||
return messageList
|
||||
}
|
||||
val text: LiveData<String> = _text
|
||||
}
|
||||
@ -5,7 +5,7 @@ import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.liveData
|
||||
import com.navinfo.volvo.db.dao.entity.Message
|
||||
import com.navinfo.volvo.db.dao.entity.attachmentType
|
||||
import com.navinfo.volvo.db.dao.entity.AttachmentType
|
||||
|
||||
class ObtainMessageViewModel: ViewModel() {
|
||||
private val msgLiveData: MutableLiveData<Message> by lazy {
|
||||
@ -29,8 +29,8 @@ class ObtainMessageViewModel: ViewModel() {
|
||||
// 更新消息附件中的照片文件
|
||||
fun updateMessagePic(picUrl: String) {
|
||||
for (attachment in this.msgLiveData.value!!.attachment) {
|
||||
if (attachment.attachmentType == attachmentType.PIC) {
|
||||
attachment.path = picUrl
|
||||
if (attachment.attachmentType == AttachmentType.PIC) {
|
||||
attachment.pathUrl = picUrl
|
||||
}
|
||||
}
|
||||
this.msgLiveData.postValue(this.msgLiveData.value)
|
||||
@ -39,8 +39,8 @@ class ObtainMessageViewModel: ViewModel() {
|
||||
// 更新消息附件中的录音文件
|
||||
fun updateMessageAudio(audioUrl: String) {
|
||||
for (attachment in this.msgLiveData.value!!.attachment) {
|
||||
if (attachment.attachmentType == attachmentType.AUDIO) {
|
||||
attachment.path = audioUrl
|
||||
if (attachment.attachmentType == AttachmentType.AUDIO) {
|
||||
attachment.pathUrl = audioUrl
|
||||
}
|
||||
}
|
||||
this.msgLiveData.postValue(this.msgLiveData.value)
|
||||
|
||||
@ -0,0 +1,187 @@
|
||||
package com.navinfo.volvo.ui.widget
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.graphics.Rect
|
||||
import android.util.AttributeSet
|
||||
import android.view.*
|
||||
import android.widget.Scroller
|
||||
import androidx.core.view.forEach
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import java.lang.Math.abs
|
||||
|
||||
class SlideRecyclerView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : RecyclerView(context, attrs, defStyleAttr) {
|
||||
//系统最小移动距离
|
||||
private val mTouchSlop = ViewConfiguration.get(context).scaledTouchSlop
|
||||
|
||||
//最小有效速度
|
||||
private val mMinVelocity = 600
|
||||
|
||||
//增加手势控制,双击快速完成侧滑
|
||||
private var isDoubleClick = false
|
||||
private var mGestureDetector: GestureDetector =
|
||||
GestureDetector(context, object : GestureDetector.SimpleOnGestureListener() {
|
||||
override fun onDoubleTap(e: MotionEvent?): Boolean {
|
||||
e?.let { event ->
|
||||
getSelectItem(event)
|
||||
mItem?.let {
|
||||
val deleteWith = it.getChildAt(it.childCount - 1).width
|
||||
//触发移动至完全展开deleteWidth
|
||||
if (it.scrollX == 0) {
|
||||
mScroller.startScroll(0, 0, deleteWith, 0)
|
||||
} else {
|
||||
mScroller.startScroll(it.scrollX, 0, -it.scrollX, 0)
|
||||
}
|
||||
isDoubleClick = true
|
||||
invalidate()
|
||||
return true
|
||||
}
|
||||
}
|
||||
//不进行拦截,只作为工具判断下双击
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
//使用速度控制器,增加侧滑速度判定滑动成功,
|
||||
//VelocityTracker 由native实现,需要及时释放内存
|
||||
private var mVelocityTracker: VelocityTracker? = null
|
||||
|
||||
//流畅滑动
|
||||
private var mScroller = Scroller(context)
|
||||
|
||||
//当前选中item
|
||||
private var mItem: ViewGroup? = null
|
||||
|
||||
//上次按下的横坐标
|
||||
private var mLastX = 0f
|
||||
|
||||
//当前RecyclerView被上层ViewGroup分发到事件,所有事件都会通过dispatchTouchEvent给到
|
||||
override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
|
||||
mGestureDetector.onTouchEvent(ev)
|
||||
return super.dispatchTouchEvent(ev)
|
||||
}
|
||||
|
||||
//viewGroup对子控件的事件拦截,一旦拦截,后续事件序列不会再调用onInterceptTouchEvent
|
||||
override fun onInterceptTouchEvent(e: MotionEvent?): Boolean {
|
||||
e?.let {
|
||||
when (e.action) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
getSelectItem(e)
|
||||
mLastX = e.x
|
||||
}
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
//移动控件
|
||||
return moveItem(e)
|
||||
}
|
||||
// MotionEvent.ACTION_UP -> {
|
||||
// stopMove(e)
|
||||
// }
|
||||
}
|
||||
}
|
||||
return super.onInterceptTouchEvent(e)
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onTouchEvent(e: MotionEvent?): Boolean {
|
||||
e?.let {
|
||||
when (e.action) {
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
moveItem(e)
|
||||
mLastX = e.x
|
||||
}
|
||||
MotionEvent.ACTION_UP -> {
|
||||
stopMove()
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.onTouchEvent(e)
|
||||
}
|
||||
|
||||
//活动结束
|
||||
//判断一下结束的位置,补充或恢复位置
|
||||
private fun stopMove() {
|
||||
mItem?.let {
|
||||
//如果移动过半,判定左划成功
|
||||
val deleteWidth = it.getChildAt(it.childCount - 1).width
|
||||
//如果整个移动过程速度大于600,也判定滑动成功
|
||||
//注意如果没有拦截ACTION_MOVE,mVelocityTracker是没有初始化的
|
||||
var velocity = 0f
|
||||
mVelocityTracker?.let { tracker ->
|
||||
tracker.computeCurrentVelocity(1000)
|
||||
velocity = tracker.xVelocity
|
||||
}
|
||||
//判断结束情况,移动过半或者向左速度很快都展开
|
||||
if ((abs(it.scrollX) >= deleteWidth / 2f) || (velocity < -mMinVelocity)) {
|
||||
//触发移动至完全展开
|
||||
mScroller.startScroll(it.scrollX, 0, deleteWidth - it.scrollX, 0)
|
||||
invalidate()
|
||||
} else {
|
||||
//如果移动未过半应恢复状态
|
||||
mScroller.startScroll(it.scrollX, 0, -it.scrollX, 0)
|
||||
invalidate()
|
||||
}
|
||||
}
|
||||
//清除状态
|
||||
mLastX = 0f
|
||||
//mVeloctityTracker由native实现,需要及时释放
|
||||
mVelocityTracker?.apply {
|
||||
clear()
|
||||
recycle()
|
||||
}
|
||||
mVelocityTracker = null
|
||||
}
|
||||
|
||||
//移动Item
|
||||
//绝对值小于删除按钮长度随便移动,大于则不移动
|
||||
@SuppressLint("Recycle")
|
||||
private fun moveItem(e: MotionEvent): Boolean {
|
||||
mItem?.let {
|
||||
val dx = mLastX - e.x
|
||||
//最小的移动距离应该舍弃,onInterceptTouchEvent不拦截,onTouchEvent内才更新mLastX
|
||||
// if (abs(dx) > mTouchSlop) {
|
||||
//检查mItem移动后应该在【-deleteLength,0】内
|
||||
val deleteWith = it.getChildAt(it.childCount - 1).width
|
||||
if ((it.scrollX + dx) <= deleteWith && (it.scrollX + dx) >= 0) {
|
||||
//触发移动
|
||||
it.scrollBy(dx.toInt(), 0)
|
||||
//触发速度计算
|
||||
//这里Rectycle不存在问题,一旦返回true,就会拦截事件,就会到达ACTION_UP去回收
|
||||
mVelocityTracker = mVelocityTracker ?: VelocityTracker.obtain()
|
||||
mVelocityTracker!!.addMovement(e)
|
||||
return true
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
//获取点击位置
|
||||
//通过点击的y坐标除以Item高度得出
|
||||
private fun getSelectItem(e: MotionEvent) {
|
||||
val frame = Rect()
|
||||
mItem = null
|
||||
forEach {
|
||||
if (it.visibility != GONE) {
|
||||
it.getHitRect(frame)
|
||||
if (frame.contains(e.x.toInt(), e.y.toInt())) {
|
||||
mItem = it as ViewGroup
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//流畅地滑动
|
||||
override fun computeScroll() {
|
||||
if (mScroller.computeScrollOffset()) {
|
||||
mItem?.scrollBy(mScroller.currX, mScroller.currY)
|
||||
postInvalidate()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
54
app/src/main/res/layout/adapter_message.xml
Normal file
54
app/src/main/res/layout/adapter_message.xml
Normal file
@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/message_head_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:src="@mipmap/ic_launcher"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/message_to_username"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:text="问候对象"
|
||||
android:ellipsize="end"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintLeft_toRightOf="@id/message_head_icon"
|
||||
app:layout_constraintTop_toTopOf="@id/message_head_icon" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/message_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:text="信息内容"
|
||||
app:layout_constraintBottom_toBottomOf="@id/message_head_icon"
|
||||
app:layout_constraintLeft_toRightOf="@id/message_head_icon" />
|
||||
<TextView
|
||||
android:id="@+id/message_send_time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="8dp"
|
||||
android:text="日期"
|
||||
app:layout_constraintTop_toTopOf="@id/message_head_icon"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
/>
|
||||
<TextView
|
||||
android:id="@+id/message_status"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:text="状态"
|
||||
app:layout_constraintBottom_toBottomOf="@id/message_head_icon"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@ -4,7 +4,7 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.dashboard.DashboardFragment">
|
||||
tools:context="com.navinfo.volvo.ui.dashboard.DashboardFragment">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_dashboard"
|
||||
|
||||
@ -1,23 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<com.yanzhenjie.recyclerview.SwipeRecyclerView
|
||||
android:id="@+id/home_message_recyclerview"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.home.HomeFragment">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_new_message"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:textAlignment="center"
|
||||
android:textSize="20sp"
|
||||
android:text="新建问候"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</com.yanzhenjie.recyclerview.SwipeRecyclerView>
|
||||
|
||||
@ -36,7 +36,8 @@
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/tv_message_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content"
|
||||
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textview.MaterialTextView
|
||||
@ -182,8 +183,8 @@
|
||||
android:id="@+id/edt_send_from"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/selector_bg_4_round_corner">
|
||||
</androidx.appcompat.widget.AppCompatEditText>
|
||||
android:background="@drawable/selector_bg_4_round_corner"
|
||||
tools:ignore="TouchTargetSizeCheck,SpeakableTextPresentCheck"></androidx.appcompat.widget.AppCompatEditText>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
@ -208,8 +209,8 @@
|
||||
android:id="@+id/edt_send_to"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/selector_bg_4_round_corner">
|
||||
</androidx.appcompat.widget.AppCompatEditText>
|
||||
android:background="@drawable/selector_bg_4_round_corner"
|
||||
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck"></androidx.appcompat.widget.AppCompatEditText>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
||||
@ -16,4 +16,9 @@
|
||||
android:icon="@drawable/ic_notifications_black_24dp"
|
||||
android:title="@string/title_notifications" />
|
||||
|
||||
<item
|
||||
android:id="@+id/navigation_obtain_message"
|
||||
android:icon="@drawable/ic_baseline_mail_24"
|
||||
android:title="消息" />
|
||||
|
||||
</menu>
|
||||
8
app/src/main/res/values-zh-rCN/strings.xml
Normal file
8
app/src/main/res/values-zh-rCN/strings.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<resources>
|
||||
<string name="app_name">NavinfoVolvo</string>
|
||||
<string name="title_home">Home</string>
|
||||
<string name="title_dashboard">Dashboard</string>
|
||||
<string name="title_notifications">Notifications</string>
|
||||
<string name="delete">删除</string>
|
||||
<string name="share">分享</string>
|
||||
</resources>
|
||||
@ -7,5 +7,6 @@
|
||||
<color name="teal_700">#FF018786</color>
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
<color name="red">#FFFF1111</color>
|
||||
<color name="red">#FFFF0000</color>
|
||||
<color name="gray">#5E5E5E</color>
|
||||
</resources>
|
||||
@ -3,4 +3,6 @@
|
||||
<string name="title_home">Home</string>
|
||||
<string name="title_dashboard">Dashboard</string>
|
||||
<string name="title_notifications">Notifications</string>
|
||||
<string name="delete">Del</string>
|
||||
<string name="share">Share</string>
|
||||
</resources>
|
||||
Loading…
x
Reference in New Issue
Block a user