2018-03-15 17:23:43 +01:00
|
|
|
package jp.juggler.subwaytooter
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.os.Bundle
|
2019-02-15 02:51:22 +01:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
2018-03-15 17:23:43 +01:00
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.widget.TextView
|
|
|
|
|
|
|
|
import com.woxthebox.draglistview.DragItem
|
|
|
|
import com.woxthebox.draglistview.DragItemAdapter
|
|
|
|
import com.woxthebox.draglistview.DragListView
|
|
|
|
import com.woxthebox.draglistview.swipe.ListSwipeHelper
|
|
|
|
import com.woxthebox.draglistview.swipe.ListSwipeItem
|
2020-02-02 15:19:57 +01:00
|
|
|
import jp.juggler.subwaytooter.api.entity.Acct
|
2018-03-15 17:23:43 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList
|
|
|
|
|
|
|
|
import jp.juggler.subwaytooter.table.FavMute
|
2018-12-01 00:02:18 +01:00
|
|
|
import jp.juggler.util.*
|
2018-03-15 17:23:43 +01:00
|
|
|
|
|
|
|
class ActFavMute : AppCompatActivity() {
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
|
|
|
private val log = LogCategory("ActFavMute")
|
|
|
|
}
|
|
|
|
|
|
|
|
private lateinit var listView : DragListView
|
|
|
|
private lateinit var listAdapter : MyListAdapter
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState : Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
2019-10-07 21:39:56 +02:00
|
|
|
App1.setActivityTheme(this)
|
2018-03-15 17:23:43 +01:00
|
|
|
initUI()
|
|
|
|
loadData()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onBackPressed() {
|
|
|
|
setResult(RESULT_OK)
|
|
|
|
super.onBackPressed()
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun initUI() {
|
|
|
|
setContentView(R.layout.act_word_list)
|
2019-08-31 16:33:13 +02:00
|
|
|
App1.initEdgeToEdge(this)
|
2018-03-15 17:23:43 +01:00
|
|
|
|
2019-12-15 20:12:57 +01:00
|
|
|
Styler.fixHorizontalPadding0(findViewById(R.id.llContent))
|
2018-03-15 17:23:43 +01:00
|
|
|
|
|
|
|
// リストのアダプター
|
|
|
|
listAdapter = MyListAdapter()
|
|
|
|
|
|
|
|
// ハンドル部分をドラッグで並べ替えできるRecyclerView
|
|
|
|
listView = findViewById(R.id.drag_list_view)
|
2019-02-15 02:51:22 +01:00
|
|
|
listView.setLayoutManager(androidx.recyclerview.widget.LinearLayoutManager(this))
|
2018-03-15 17:23:43 +01:00
|
|
|
listView.setAdapter(listAdapter, false)
|
|
|
|
|
|
|
|
listView.setCanDragHorizontally(true)
|
|
|
|
listView.isDragEnabled = false
|
|
|
|
listView.setCustomDragItem(MyDragItem(this, R.layout.lv_mute_app))
|
|
|
|
|
|
|
|
listView.recyclerView.isVerticalScrollBarEnabled = true
|
|
|
|
// listView.setDragListListener( new DragListView.DragListListenerAdapter() {
|
|
|
|
// @Override
|
|
|
|
// public void onItemDragStarted( int position ){
|
|
|
|
// // 操作中はリフレッシュ禁止
|
|
|
|
// // mRefreshLayout.setEnabled( false );
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// @Override
|
|
|
|
// public void onItemDragEnded( int fromPosition, int toPosition ){
|
|
|
|
// // 操作完了でリフレッシュ許可
|
|
|
|
// // mRefreshLayout.setEnabled( USE_SWIPE_REFRESH );
|
|
|
|
//
|
|
|
|
//// if( fromPosition != toPosition ){
|
|
|
|
//// // 並べ替えが発生した
|
|
|
|
//// }
|
|
|
|
// }
|
|
|
|
// } );
|
|
|
|
|
|
|
|
// リストを左右スワイプした
|
|
|
|
listView.setSwipeListener(object : ListSwipeHelper.OnSwipeListenerAdapter() {
|
|
|
|
|
|
|
|
override fun onItemSwipeStarted(item : ListSwipeItem?) {
|
|
|
|
// 操作中はリフレッシュ禁止
|
|
|
|
// mRefreshLayout.setEnabled( false );
|
|
|
|
}
|
|
|
|
|
2019-10-07 21:39:56 +02:00
|
|
|
override fun onItemSwipeEnded(
|
|
|
|
item : ListSwipeItem?,
|
|
|
|
swipedDirection : ListSwipeItem.SwipeDirection?
|
|
|
|
) {
|
2018-03-15 17:23:43 +01:00
|
|
|
// 操作完了でリフレッシュ許可
|
|
|
|
// mRefreshLayout.setEnabled( USE_SWIPE_REFRESH );
|
|
|
|
|
|
|
|
// 左にスワイプした(右端に青が見えた) なら要素を削除する
|
|
|
|
if(swipedDirection == ListSwipeItem.SwipeDirection.LEFT) {
|
2019-10-07 21:39:56 +02:00
|
|
|
val o = item?.tag
|
2018-03-15 17:23:43 +01:00
|
|
|
if(o is MyItem) {
|
|
|
|
FavMute.delete(o.name)
|
|
|
|
listAdapter.removeItem(listAdapter.getPositionForItem(o))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun loadData() {
|
|
|
|
|
|
|
|
val tmp_list = ArrayList<MyItem>()
|
|
|
|
try {
|
|
|
|
FavMute.createCursor().use { cursor ->
|
|
|
|
val idx_id = cursor.getColumnIndex(FavMute.COL_ID)
|
|
|
|
val idx_name = cursor.getColumnIndex(FavMute.COL_ACCT)
|
|
|
|
while(cursor.moveToNext()) {
|
|
|
|
val id = cursor.getLong(idx_id)
|
|
|
|
val name = cursor.getString(idx_name)
|
2020-02-02 15:19:57 +01:00
|
|
|
val item = MyItem(id, Acct.parse(name))
|
2018-03-15 17:23:43 +01:00
|
|
|
tmp_list.add(item)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch(ex : Throwable) {
|
|
|
|
log.trace(ex)
|
|
|
|
}
|
|
|
|
|
|
|
|
listAdapter.itemList = tmp_list
|
|
|
|
}
|
|
|
|
|
|
|
|
// リスト要素のデータ
|
2020-02-02 15:19:57 +01:00
|
|
|
internal class MyItem(val id : Long, val name : Acct)
|
2018-03-15 17:23:43 +01:00
|
|
|
|
|
|
|
// リスト要素のViewHolder
|
2019-10-07 21:39:56 +02:00
|
|
|
internal class MyViewHolder(viewRoot : View) :
|
|
|
|
DragItemAdapter.ViewHolder(viewRoot, R.id.ivDragHandle, false) {
|
2018-03-15 17:23:43 +01:00
|
|
|
|
|
|
|
val tvName : TextView
|
|
|
|
|
|
|
|
init {
|
|
|
|
|
|
|
|
tvName = viewRoot.findViewById(R.id.tvName)
|
|
|
|
|
|
|
|
// リスト要素のビューが ListSwipeItem だった場合、Swipe操作を制御できる
|
|
|
|
if(viewRoot is ListSwipeItem) {
|
|
|
|
viewRoot.setSwipeInStyle(ListSwipeItem.SwipeInStyle.SLIDE)
|
|
|
|
viewRoot.supportedSwipeDirection = ListSwipeItem.SwipeDirection.LEFT
|
|
|
|
}
|
|
|
|
|
|
|
|
} // View ID。 ここを押すとドラッグ操作をすぐに開始する
|
|
|
|
// 長押しでドラッグ開始するなら真
|
|
|
|
|
|
|
|
fun bind(item : MyItem) {
|
|
|
|
itemView.tag = item // itemView は親クラスのメンバ変数
|
2020-02-02 15:19:57 +01:00
|
|
|
tvName.text = item.name.pretty
|
2018-03-15 17:23:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
// public boolean onItemLongClicked( View view ){
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
// public void onItemClicked( View view ){
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
// ドラッグ操作中のデータ
|
2020-09-09 21:46:50 +02:00
|
|
|
private inner class MyDragItem(context : Context, layoutId : Int) :
|
2019-10-07 21:39:56 +02:00
|
|
|
DragItem(context, layoutId) {
|
2018-03-15 17:23:43 +01:00
|
|
|
|
|
|
|
override fun onBindDragView(clickedView : View, dragView : View) {
|
2019-10-07 21:39:56 +02:00
|
|
|
dragView.findViewById<TextView>(R.id.tvName).text =
|
|
|
|
clickedView.findViewById<TextView>(R.id.tvName).text
|
2018-03-15 17:23:43 +01:00
|
|
|
|
2020-09-29 19:44:56 +02:00
|
|
|
dragView.findViewById<View>(R.id.item_layout)
|
|
|
|
.setBackgroundColor(getAttributeColor(R.attr.list_item_bg_pressed_dragged))
|
2018-03-15 17:23:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-09 21:46:50 +02:00
|
|
|
private inner class MyListAdapter :
|
2019-10-07 21:39:56 +02:00
|
|
|
DragItemAdapter<MyItem, MyViewHolder>() {
|
2018-03-15 17:23:43 +01:00
|
|
|
|
|
|
|
init {
|
|
|
|
setHasStableIds(true)
|
|
|
|
itemList = ArrayList()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onCreateViewHolder(parent : ViewGroup, viewType : Int) : MyViewHolder {
|
|
|
|
val view = layoutInflater.inflate(R.layout.lv_mute_app, parent, false)
|
|
|
|
return MyViewHolder(view)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder : MyViewHolder, position : Int) {
|
|
|
|
super.onBindViewHolder(holder, position)
|
|
|
|
holder.bind(itemList[position])
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getUniqueItemId(position : Int) : Long {
|
|
|
|
val item = mItemList[position] // mItemList は親クラスのメンバ変数
|
|
|
|
return item.id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|