Skip to content

Commit

Permalink
恢复自定义 UI 顺序功能
Browse files Browse the repository at this point in the history
  • Loading branch information
xz-dev committed Mar 14, 2020
1 parent a1b460b commit 1737b2a
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 57 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ android {
minSdkVersion 21
targetSdkVersion 29
versionCode 37
versionName "0.1.1-beta.4"
versionName "0.1.1-rc"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ class UCropActivity : AppCompatActivity() {

private const val PERMISSIONS_REQUEST_WRITE_CONTACTS = 1
private const val READ_PIC_REQUEST_CODE = 2
private val cacheImageFile = FileUtil.IMAGE_CACHE_FILE
private val cacheImageFile = FileUtil.IMAGE_CACHE_FILE.also {
it.parentFile?.mkdirs()
it.createNewFile()
}

private val mutex = Mutex()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import net.xzos.upgradeall.R
import net.xzos.upgradeall.ui.activity.MainActivity.Companion.setNavigationItemId
import net.xzos.upgradeall.ui.viewmodels.fragment.AppInfoFragment
import net.xzos.upgradeall.ui.viewmodels.fragment.ApplicationsFragment
import net.xzos.upgradeall.ui.viewmodels.pageradapter.AppTabSectionsPagerAdapter
import net.xzos.upgradeall.ui.viewmodels.view.ItemCardView
import net.xzos.upgradeall.ui.viewmodels.view.holder.CardViewRecyclerViewHolder
import net.xzos.upgradeall.ui.viewmodels.viewmodel.AppListPageViewModel
Expand Down Expand Up @@ -56,59 +57,60 @@ class AppListItemAdapter(private val appListPageViewModel: AppListPageViewModel,
}
// TODO: 长按删除,暂时添加删除功能
holder.itemCardView.setOnLongClickListener { view ->
GlobalScope.launch {
mItemCardViewList.getByHolder(holder).extraData.app?.run {
val context = view.context
PopupMenu(context, view).let { popupMenu ->
popupMenu.menu.let { menu ->
menu.add(context.getString(
if (appListPageViewModel.editableTab.value == true)
R.string.edit_group
else R.string.add_to_group
)).let { menuItem ->
menuItem.setOnMenuItemClickListener {
GlobalScope.launch(Dispatchers.Main) {
showSelectGroupPopMenu(view, holder)
if (AppTabSectionsPagerAdapter.editTabMode.value == false)
GlobalScope.launch {
mItemCardViewList.getByHolder(holder).extraData.app?.run {
val context = view.context
PopupMenu(context, view).let { popupMenu ->
popupMenu.menu.let { menu ->
menu.add(context.getString(
if (appListPageViewModel.editableTab.value == true)
R.string.edit_group
else R.string.add_to_group
)).let { menuItem ->
menuItem.setOnMenuItemClickListener {
GlobalScope.launch(Dispatchers.Main) {
showSelectGroupPopMenu(view, holder)
}
return@setOnMenuItemClickListener true
}
return@setOnMenuItemClickListener true
}
}
// 从分组中删除
if (appListPageViewModel.editableTab.value == true) {
menu.add(R.string.delete_from_group).let { menuItem ->
// 从分组中删除
if (appListPageViewModel.editableTab.value == true) {
menu.add(R.string.delete_from_group).let { menuItem ->
menuItem.setOnMenuItemClickListener {
if (appListPageViewModel.removeItemFromGroup(holder.adapterPosition))
onItemDismiss(holder.adapterPosition)
return@setOnMenuItemClickListener true
}
}
}
// 导出
menu.add(R.string.export).let { menuItem ->
menuItem.setOnMenuItemClickListener {
if (appListPageViewModel.removeItemFromGroup(holder.adapterPosition))
onItemDismiss(holder.adapterPosition)
val appConfigGson = AppDatabaseManager.translateAppConfig(this.appInfo)
FileUtil.clipStringToClipboard(
GsonBuilder().setPrettyPrinting().create().toJson(appConfigGson),
context
)
return@setOnMenuItemClickListener true
}
}
}
// 导出
menu.add(R.string.export).let { menuItem ->
menuItem.setOnMenuItemClickListener {
val appConfigGson = AppDatabaseManager.translateAppConfig(this.appInfo)
FileUtil.clipStringToClipboard(
GsonBuilder().setPrettyPrinting().create().toJson(appConfigGson),
context
)
return@setOnMenuItemClickListener true
// 删除数据库
menu.add(R.string.delete).let { menuItem ->
menuItem.setOnMenuItemClickListener {
this.appInfo.delete()
onItemDismiss(holder.adapterPosition)
return@setOnMenuItemClickListener true
}
}
}
// 删除数据库
menu.add(R.string.delete).let { menuItem ->
menuItem.setOnMenuItemClickListener {
this.appInfo.delete()
onItemDismiss(holder.adapterPosition)
return@setOnMenuItemClickListener true
withContext(Dispatchers.Main) {
popupMenu.show()
}
}
withContext(Dispatchers.Main) {
popupMenu.show()
}
}
}
}
}
return@setOnLongClickListener true
}
return holder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ package net.xzos.upgradeall.ui.viewmodels.callback
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import net.xzos.upgradeall.data_manager.UIConfig
import net.xzos.upgradeall.data_manager.UIConfig.Companion.uiConfig
import net.xzos.upgradeall.ui.viewmodels.adapters.AppItemAdapter
import net.xzos.upgradeall.ui.viewmodels.pageradapter.AppTabSectionsPagerAdapter


class AppItemTouchHelperCallback(private val mAdapter: AppItemAdapter) : ItemTouchHelper.Callback() {
class AppItemTouchHelperCallback(
private val mAdapter: AppItemAdapter,
private val appIdList: MutableList<UIConfig.CustomContainerTabListBean.ItemListBean>
) : ItemTouchHelper.Callback() {

override fun isLongPressDragEnabled(): Boolean {
return true
Expand All @@ -25,7 +31,14 @@ class AppItemTouchHelperCallback(private val mAdapter: AppItemAdapter) : ItemTou

override fun onMove(recyclerView: RecyclerView, viewHolder: ViewHolder,
target: ViewHolder): Boolean {
mAdapter.onItemMove(viewHolder.adapterPosition, target.adapterPosition)
if (AppTabSectionsPagerAdapter.editTabMode.value == true) {
val fromPosition = viewHolder.adapterPosition
val toPosition = target.adapterPosition
mAdapter.onItemMove(fromPosition, toPosition)
appIdList[fromPosition] = appIdList[toPosition]
.also { appIdList[toPosition] = appIdList[fromPosition] }
uiConfig.save()
}
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import android.os.Bundle
import android.view.View
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.ItemTouchHelper
import kotlinx.android.synthetic.main.content_list.*
import net.xzos.upgradeall.data_manager.UIConfig.Companion.uiConfig
import net.xzos.upgradeall.ui.viewmodels.adapters.AppListItemAdapter
import net.xzos.upgradeall.ui.viewmodels.callback.AppItemTouchHelperCallback
import net.xzos.upgradeall.ui.viewmodels.pageradapter.AppTabSectionsPagerAdapter.Companion.USER_STAR_PAGE_INDEX
import net.xzos.upgradeall.ui.viewmodels.viewmodel.AppListPageViewModel


internal class AppListPlaceholderFragment(private val tabPageIndex: Int)
: AppListContainerFragment() {

Expand All @@ -29,6 +34,14 @@ internal class AppListPlaceholderFragment(private val tabPageIndex: Int)
cardItemRecyclerView.layoutManager = layoutManager
val adapter = AppListItemAdapter(appListPageViewModel, appListPageViewModel.appCardViewList, this)
cardItemRecyclerView.adapter = adapter
if (tabPageIndex > 0 || tabPageIndex == USER_STAR_PAGE_INDEX) {
val list = if (tabPageIndex > 0)
uiConfig.userTabList[tabPageIndex].itemList
else uiConfig.userStarTab.itemList
val callback: ItemTouchHelper.Callback = AppItemTouchHelperCallback(adapter, list)
val touchHelper = ItemTouchHelper(callback)
touchHelper.attachToRecyclerView(cardItemRecyclerView)
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,15 @@ class AppTabSectionsPagerAdapter(private val tabLayout: TabLayout, fm: FragmentM
groupIconImageView: ImageView,
textView: View
): UIConfig.BasicInfo {
var tabIconDrawableId: Int? = null
val tabIconDrawableId = getTabIconDrawableId(tabIndex)
val tabBasicInfo = when (tabIndex) {
UPDATE_PAGE_INDEX -> {
tabIconDrawableId = R.drawable.ic_update
uiConfig.updateTab
}
USER_STAR_PAGE_INDEX -> {
tabIconDrawableId = R.drawable.ic_start
uiConfig.userStarTab
}
ALL_APP_PAGE_INDEX -> {
tabIconDrawableId = R.drawable.ic_app
uiConfig.allAppTab
}
else -> {
Expand All @@ -206,6 +203,21 @@ class AppTabSectionsPagerAdapter(private val tabLayout: TabLayout, fm: FragmentM
return tabBasicInfo
}

private fun getTabIconDrawableId(tabIndex: Int): Int? {
return when (tabIndex) {
UPDATE_PAGE_INDEX -> {
R.drawable.ic_update
}
USER_STAR_PAGE_INDEX -> {
R.drawable.ic_start
}
ALL_APP_PAGE_INDEX -> {
R.drawable.ic_app
}
else -> null
}
}

private fun getCustomTabView(position: Int): View {
return LayoutInflater.from(tabLayout.context)
.inflate(R.layout.group_item, tabLayout, false).apply {
Expand Down Expand Up @@ -306,7 +318,15 @@ class AppTabSectionsPagerAdapter(private val tabLayout: TabLayout, fm: FragmentM
}
groupCardView.setOnLongClickListener {
tabBasicInfo?.icon = null
uiConfig.save()
val tabIconDrawableId = getTabIconDrawableId(tabIndex)
IconPalette.loadHubIconView(
iconImageView = groupIconImageView,
hubIconDrawableId = tabIconDrawableId
)
IconPalette.loadHubIconView(
iconImageView = view.groupIconImageView,
hubIconDrawableId = tabIconDrawableId
)
return@setOnLongClickListener true
}
groupCardView.setOnClickListener {
Expand Down Expand Up @@ -351,14 +371,14 @@ class AppTabSectionsPagerAdapter(private val tabLayout: TabLayout, fm: FragmentM
}

companion object {
internal const val ADD_TAB_BUTTON_INDEX = -4
internal const val UPDATE_PAGE_INDEX = -3
internal const val USER_STAR_PAGE_INDEX = -2
internal const val ALL_APP_PAGE_INDEX = -1
const val ADD_TAB_BUTTON_INDEX = -4
const val UPDATE_PAGE_INDEX = -3
const val USER_STAR_PAGE_INDEX = -2
const val ALL_APP_PAGE_INDEX = -1

internal val editTabMode = MutableLiveData(false)
val editTabMode = MutableLiveData(false)

internal fun newInstance(
fun newInstance(
tabLayout: TabLayout,
viewPager: ViewPager,
childFragmentManager: FragmentManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ abstract class AppListContainerViewModel : ViewModel() {
AppConfigGson.AppConfigBean.TargetCheckerBean.API_TYPE_MAGISK_MODULE -> context.getString(R.string.magisk_module)
AppConfigGson.AppConfigBean.TargetCheckerBean.API_TYPE_SHELL -> context.getString(R.string.shell)
AppConfigGson.AppConfigBean.TargetCheckerBean.API_TYPE_SHELL_ROOT -> context.getString(R.string.shell_root)
else -> ""
else -> context.getString(R.string.app)
}
}
AppDatabase.APPLICATIONS_TYPE_TAG.toLowerCase(local) -> context.getString(R.string.applications)
Expand Down

0 comments on commit 1737b2a

Please sign in to comment.