Skip to content

Commit

Permalink
Merge pull request #13 from puutaro/edit/grid_view
Browse files Browse the repository at this point in the history
add grid veiw implement
  • Loading branch information
puutaro authored Apr 20, 2024
2 parents ab1c758 + 6c74508 commit 9032081
Show file tree
Hide file tree
Showing 14 changed files with 571 additions and 124 deletions.
170 changes: 122 additions & 48 deletions app/src/main/java/com/puutaro/commandclick/component/adapter/ListIndexForEditAdapter.kt
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.puutaro.commandclick.component.adapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.RelativeLayout
import androidx.appcompat.widget.AppCompatImageView
import androidx.appcompat.widget.AppCompatTextView
import androidx.appcompat.widget.LinearLayoutCompat
Expand All @@ -13,8 +14,10 @@ import com.google.android.material.card.MaterialCardView
import com.puutaro.commandclick.common.variable.variables.CommandClickScriptVariable
import com.puutaro.commandclick.common.variable.variables.FannelListVariable
import com.puutaro.commandclick.common.variable.variant.SettingVariableSelects
import com.puutaro.commandclick.component.adapter.lib.ImageAdapterTool
import com.puutaro.commandclick.fragment.EditFragment
import com.puutaro.commandclick.proccess.list_index_for_edit.ListIndexEditConfig
import com.puutaro.commandclick.proccess.list_index_for_edit.config_settings.LayoutSettingsForListIndex
import com.puutaro.commandclick.proccess.list_index_for_edit.config_settings.ListSettingsForListIndex
import com.puutaro.commandclick.proccess.list_index_for_edit.config_settings.PerformSettingForListIndex
import com.puutaro.commandclick.proccess.list_index_for_edit.config_settings.TypeSettingsForListIndex
Expand All @@ -23,6 +26,7 @@ import com.puutaro.commandclick.proccess.qr.qr_dialog_config.config_settings.QrL
import com.puutaro.commandclick.proccess.qr.qr_dialog_config.config_settings.QrModeSettingKeysForQrDialog
import com.puutaro.commandclick.util.CommandClickVariables
import com.puutaro.commandclick.util.SettingVariableReader
import com.puutaro.commandclick.util.file.AssetsFileManager
import com.puutaro.commandclick.util.file.FileSystems
import com.puutaro.commandclick.util.file.ReadText
import com.puutaro.commandclick.util.map.CmdClickMap
Expand All @@ -47,9 +51,27 @@ class ListIndexForEditAdapter(
private val editExecuteAlways = SettingVariableSelects.EditExecuteSelects.ALWAYS.name
private val busyboxExecutor = editFragment.busyboxExecutor

private val listIndexConfigMap = editFragment.listIndexConfigMap
private val layoutConfigMap = LayoutSettingsForListIndex.getLayoutConfigMap(
listIndexConfigMap
)
private val layoutType = LayoutSettingsForListIndex.decideLayoutType(
layoutConfigMap
)
private var performMap: Map<String, String> = mapOf()

val checkItemConfigMap = CmdClickMap.createMap(
listIndexConfigMap?.get(
ListIndexEditConfig.ListIndexConfigKey.CHECK_ITEM.key
),
'|'
).toMap()
private val qrDialogConfigMap =
editFragment.qrDialogConfig ?: mapOf()

private val textImagePngBitMap = ImageAdapterTool.makeFileMarkBitMap(
context,
AssetsFileManager.textImagePingPath
)
private val qrLogoConfigMap = QrLogoSettingsForQrDialog.makeLogoConfigMap(
qrDialogConfigMap
)
Expand All @@ -62,15 +84,6 @@ class ListIndexForEditAdapter(
editFragment,
iconConfigMap,
)
private val listIndexConfigMap = editFragment.listIndexConfigMap
private var performMap: Map<String, String> = mapOf()

val checkItemConfigMap = CmdClickMap.createMap(
listIndexConfigMap?.get(
ListIndexEditConfig.ListIndexConfigKey.CHECK_ITEM.key
),
'|'
).toMap()
private var recentAppDirPath = String()
private var filterDir = String()
private var filterPrefix = String()
Expand All @@ -82,7 +95,6 @@ class ListIndexForEditAdapter(
}
}


companion object {
var indexListMap: Map<String, String> = mapOf()
var deleteConfigMap: Map<String, String> = mapOf()
Expand All @@ -92,18 +104,31 @@ class ListIndexForEditAdapter(
val activity: FragmentActivity?,
val view: View
): RecyclerView.ViewHolder(view) {
val baseLinearLayout =
view.findViewById<LinearLayoutCompat>(
com.puutaro.commandclick.R.id.list_index_edit_adapter_horizontal_linearlayout
)
val materialCardView =
view.findViewById<MaterialCardView>(
com.puutaro.commandclick.R.id.list_index_edit_adapter_mterial_card_view
)
val fileContentsQrLogoLinearLayout =
view.findViewById<LinearLayoutCompat>(
view.findViewById<RelativeLayout>(
com.puutaro.commandclick.R.id.list_index_edit_adapter_logo_linearlayout
)
val fileContentsQrLogoView =
view.findViewById<AppCompatImageView>(
com.puutaro.commandclick.R.id.list_index_edit_adapter_contents
)
val qrLogoImageCaptionTextView =
view.findViewById<AppCompatTextView>(
com.puutaro.commandclick.R.id.list_index_edit_adapter_image_caption
)

val rightLinearlayout =
view.findViewById<LinearLayoutCompat>(
com.puutaro.commandclick.R.id.list_index_edit_adapter_vertical_linearlayout
)
val fileNameTextView =
view.findViewById<AppCompatTextView>(
com.puutaro.commandclick.R.id.list_index_edit_adapter_file_name
Expand Down Expand Up @@ -147,6 +172,13 @@ class ListIndexForEditAdapter(
) return
initListProperty(listIndexPosition)
CoroutineScope(Dispatchers.IO).launch {
// withContext(Dispatchers.Main) {
// delay(200)
//// val backstackCount = TitleImageAndViewSetter.makeBackstackCount(editFragment)
//// if (backstackCount == 0) {
//// delay(100)
//// }
// }
withContext(Dispatchers.Main) {
ListIndexEditConfig.setCheckToMaterialCardView(
holder.materialCardView,
Expand All @@ -162,47 +194,41 @@ class ListIndexForEditAdapter(
holder.fileName = FannelListVariable.getFannelName(
fileNameOrInstallFannelLine
)
withContext(Dispatchers.Main) {
ListIndexEditConfig.setFileNameTextView(
val fileNameText = withContext(Dispatchers.Main) {
ListIndexEditConfig.makeFileNameText(
listIndexTypeKey,
holder.fileNameTextView,
holder.fileName,
listIndexConfigMap,
busyboxExecutor,
)
}

val fileConList = withContext(Dispatchers.IO) {
if (
listIndexConfigMap.isNullOrEmpty()
) return@withContext emptyList()
if(
PerformSettingForListIndex.howFastMode(performMap)
|| listIndexTypeKey == TypeSettingsForListIndex.ListIndexTypeKey.TSV_EDIT
) return@withContext emptyList()
ReadText(
File(filterDir, holder.fileName).absolutePath,
).textToList().take(maxTakeSize)
}
val descCon = withContext(Dispatchers.IO){
val makeFileDescArgsMaker = ListIndexEditConfig.MakeFileDescArgsMaker(
filterDir,
fileNameOrInstallFannelLine,
fileConList.joinToString("\n"),
listIndexConfigMap,
busyboxExecutor,
)
ListIndexEditConfig.makeFileDesc(
makeFileDescArgsMaker,
)
}
withContext(Dispatchers.Main) {
when(descCon.isNullOrEmpty()){
true -> holder.fileDescTextView.isVisible = false
else -> holder.fileDescTextView.text = descCon
val fileConList = makeFileConList(holder.fileName)
when(layoutType){
LayoutSettingsForListIndex.LayoutTypeValueStr.LINEAR -> {
withContext(Dispatchers.Main){
if(
fileNameText.isNullOrEmpty()
) return@withContext
holder.fileNameTextView?.text = fileNameText
}
setDescView(
holder.fileDescTextView,
fileNameOrInstallFannelLine,
fileConList.joinToString("\n"),
)
}
LayoutSettingsForListIndex.LayoutTypeValueStr.GRID -> {
withContext(Dispatchers.Main){
holder.rightLinearlayout.isVisible = false
if(
fileNameText.isNullOrEmpty()
) return@withContext
holder.qrLogoImageCaptionTextView.isVisible = true
holder.qrLogoImageCaptionTextView.text = fileNameText
}
}
}

val fileConBackGroundColorInt = withContext(Dispatchers.IO) {
val editExecuteValueForInstallFannel = when(
listIndexTypeKey
Expand All @@ -219,17 +245,21 @@ class ListIndexForEditAdapter(
editExecuteValueForInstallFannel,
)
}

withContext(Dispatchers.Main) {
context?.let {
holder.fileContentsQrLogoLinearLayout.backgroundTintList =
it.getColorStateList(fileConBackGroundColorInt)
}
}
withContext(Dispatchers.Main) {
QrLogoSettingsForQrDialog.OneSideLength.set(
QrLogoSettingsForQrDialog.OneSideLength.setLayout(
editFragment,
holder.baseLinearLayout,
holder.materialCardView,
holder.fileContentsQrLogoLinearLayout,
qrLogoConfigMap
qrLogoConfigMap,
layoutType
)
}
withContext(Dispatchers.Main) {
Expand Down Expand Up @@ -316,6 +346,44 @@ class ListIndexForEditAdapter(
)
}

private fun makeFileConList(
fileName: String,
): List<String> {
if (
listIndexConfigMap.isNullOrEmpty()
) return emptyList()
if(
PerformSettingForListIndex.howFastMode(performMap)
|| listIndexTypeKey == TypeSettingsForListIndex.ListIndexTypeKey.TSV_EDIT
) return emptyList()
return ReadText(
File(filterDir, fileName).absolutePath,
).textToList().take(maxTakeSize)
}

private suspend fun setDescView(
fileDescTextView: AppCompatTextView,
fileNameOrInstallFannelLine: String,
fileCon: String,
){
val makeFileDescArgsMaker = ListIndexEditConfig.MakeFileDescArgsMaker(
filterDir,
fileNameOrInstallFannelLine,
fileCon,
listIndexConfigMap,
busyboxExecutor,
)
val descCon = ListIndexEditConfig.makeFileDesc(
makeFileDescArgsMaker,
)
withContext(Dispatchers.Main) {
when (descCon.isNullOrEmpty()) {
true -> fileDescTextView.isVisible = false
else -> fileDescTextView.text = descCon
}
}
}

private fun setFileContentsBackColor(
fileConList: List<String>,
fileName: String,
Expand Down Expand Up @@ -362,12 +430,15 @@ class ListIndexForEditAdapter(
val itemName = holder.fileName.split("\t").lastOrNull() ?: String()
val okSetIcon = QrLogoSettingsForQrDialog.QrIconSettingKeysForQrDialog.set(
context,
filterDir,
listIndexTypeKey,
itemName,
holder.fileContentsQrLogoView,
holder.fileContentsQrLogoLinearLayout,
qrLogoConfigMap,
iconConfigMap,
itemNameToNameColorConfigMap
itemNameToNameColorConfigMap,
textImagePngBitMap
)
if(okSetIcon) return
val qrMode = QrModeSettingKeysForQrDialog.getQrMode(qrDialogConfigMap)
Expand All @@ -384,7 +455,7 @@ class ListIndexForEditAdapter(
filterDir,
holder.fileName,
holder.fileContentsQrLogoView,
holder.fileContentsQrLogoLinearLayout,
// holder.fileContentsQrLogoLinearLayout,
)
}
withContext(Dispatchers.Main) {
Expand Down Expand Up @@ -444,4 +515,7 @@ class ListIndexForEditAdapter(
ListSettingsForListIndex.ListSettingKey.SUFFIX.key
) ?: String()
}
fun getLayoutConfigMap(): Map<String, String> {
return layoutConfigMap
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.puutaro.commandclick.component.adapter.lib.list_index_adapter

import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.puutaro.commandclick.component.adapter.ListIndexForEditAdapter
import com.puutaro.commandclick.custom_manager.PreLoadLayoutManager
import com.puutaro.commandclick.fragment.EditFragment
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -46,7 +46,8 @@ object ListViewToolForListIndexAdapter {
){
listIndexScrollToBottomJob?.cancel()
listIndexScrollToBottomJob = CoroutineScope(Dispatchers.Main).launch {
val layoutManager = editListRecyclerView.layoutManager as? PreLoadLayoutManager
val layoutManager =
editListRecyclerView.layoutManager as? LinearLayoutManager
val scrollToPosi = listIndexForEditAdapter.itemCount - 1
withContext(Dispatchers.Main){
for(i in 1..30){
Expand Down Expand Up @@ -74,7 +75,7 @@ object ListViewToolForListIndexAdapter {
}

private fun execScroll(
layoutManager: PreLoadLayoutManager?,
layoutManager: LinearLayoutManager?,
scrollToPosi: Int,
){
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
package com.puutaro.commandclick.custom_manager

class PreLoadGridLayoutManager {
import android.content.Context
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

class PreLoadGridLayoutManager(
context: Context?,
col: Int,
reverseLayout: Boolean = false
) :
GridLayoutManager(
context,
col,
LinearLayoutManager.VERTICAL,
reverseLayout
) {
private val mDisplayHeight: Int


init {
mDisplayHeight = context?.resources?.displayMetrics?.heightPixels ?: 0
}
override fun calculateExtraLayoutSpace(
state: RecyclerView.State,
extraLayoutSpace: IntArray
) {
extraLayoutSpace[0] = mDisplayHeight * 100
extraLayoutSpace[1] = mDisplayHeight * 100
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import androidx.recyclerview.widget.RecyclerView


class PreLoadLayoutManager(
private val context: Context?) :
context: Context?,
reverseLayout: Boolean = false
) :
LinearLayoutManager(
context,
LinearLayoutManager.VERTICAL,
false
reverseLayout
) {
private val mDisplayHeight: Int

Expand Down
Loading

0 comments on commit 9032081

Please sign in to comment.