-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] Support for deleting cached torrent files
- Loading branch information
Showing
26 changed files
with
676 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/skyd/anivu/model/bean/settings/SettingsBaseBean.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.skyd.anivu.model.bean.settings | ||
|
||
import android.graphics.drawable.Drawable | ||
import com.skyd.anivu.base.BaseBean | ||
|
||
data class SettingsBaseBean( | ||
val title: String, | ||
val description: String, | ||
val icon: Drawable, | ||
val action: ((SettingsBaseBean) -> Unit)? = null, | ||
) : BaseBean |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/com/skyd/anivu/model/repository/DataRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.skyd.anivu.model.repository | ||
|
||
import com.skyd.anivu.base.BaseRepository | ||
import com.skyd.anivu.config.Const | ||
import com.skyd.anivu.ext.deleteRecursivelyExclude | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.flowOn | ||
import javax.inject.Inject | ||
|
||
class DataRepository @Inject constructor() : BaseRepository() { | ||
fun requestClearCache(): Flow<Long> { | ||
return flow { | ||
var size: Long = 0 | ||
Const.TEMP_TORRENT_DIR.deleteRecursivelyExclude(hook = { | ||
if (!it.canWrite()) return@deleteRecursivelyExclude false | ||
if (it.isFile) size += it.length() | ||
true | ||
}) | ||
emit(size) | ||
}.flowOn(Dispatchers.IO) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/skyd/anivu/ui/adapter/variety/proxy/settings/SettingsBaseProxy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.skyd.anivu.ui.adapter.variety.proxy.settings | ||
|
||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import com.skyd.anivu.databinding.ItemSettingsBaseBinding | ||
import com.skyd.anivu.model.bean.settings.SettingsBaseBean | ||
import com.skyd.anivu.ui.adapter.variety.SettingsBaseViewHolder | ||
import com.skyd.anivu.ui.adapter.variety.VarietyAdapter | ||
|
||
|
||
class SettingsBaseProxy( | ||
private val adapter: VarietyAdapter, | ||
) : | ||
VarietyAdapter.Proxy<SettingsBaseBean, ItemSettingsBaseBinding, SettingsBaseViewHolder>() { | ||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SettingsBaseViewHolder { | ||
val holder = SettingsBaseViewHolder( | ||
ItemSettingsBaseBinding | ||
.inflate(LayoutInflater.from(parent.context), parent, false), | ||
) | ||
holder.itemView.setOnClickListener { | ||
val data = adapter.dataList.getOrNull(holder.bindingAdapterPosition) | ||
if (data !is SettingsBaseBean) return@setOnClickListener | ||
data.action?.invoke(data) | ||
} | ||
return holder | ||
} | ||
|
||
override fun onBindViewHolder( | ||
holder: SettingsBaseViewHolder, | ||
data: SettingsBaseBean, | ||
index: Int, | ||
action: ((Any?) -> Unit)? | ||
) { | ||
holder.binding.apply { | ||
tvSettingsBaseTitle.text = data.title | ||
tvSettingsBaseDesc.text = data.description | ||
ivSettingsBaseIcon.setImageDrawable(data.icon) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
app/src/main/java/com/skyd/anivu/ui/fragment/settings/SettingsFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.skyd.anivu.ui.fragment.settings | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.appcompat.content.res.AppCompatResources | ||
import androidx.core.view.ViewCompat | ||
import androidx.navigation.fragment.findNavController | ||
import androidx.recyclerview.widget.GridLayoutManager | ||
import com.skyd.anivu.R | ||
import com.skyd.anivu.base.BaseFragment | ||
import com.skyd.anivu.databinding.FragmentSettingsBinding | ||
import com.skyd.anivu.ext.addInsetsByPadding | ||
import com.skyd.anivu.ext.findMainNavController | ||
import com.skyd.anivu.ext.popBackStackWithLifecycle | ||
import com.skyd.anivu.model.bean.settings.SettingsBaseBean | ||
import com.skyd.anivu.ui.adapter.variety.AniSpanSize | ||
import com.skyd.anivu.ui.adapter.variety.VarietyAdapter | ||
import com.skyd.anivu.ui.adapter.variety.proxy.settings.SettingsBaseProxy | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
|
||
@AndroidEntryPoint | ||
class SettingsFragment : BaseFragment<FragmentSettingsBinding>() { | ||
private val adapter = VarietyAdapter(mutableListOf()).apply { | ||
addProxy(SettingsBaseProxy(adapter = this)) | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
adapter.dataList = getSettingsList() | ||
} | ||
|
||
override fun FragmentSettingsBinding.initView() { | ||
topAppBar.setNavigationOnClickListener { findNavController().popBackStackWithLifecycle() } | ||
|
||
rvSettingsFragment.layoutManager = GridLayoutManager( | ||
requireContext(), | ||
AniSpanSize.MAX_SPAN_SIZE | ||
).apply { | ||
spanSizeLookup = AniSpanSize(adapter) | ||
} | ||
rvSettingsFragment.adapter = adapter | ||
} | ||
|
||
override fun FragmentSettingsBinding.setWindowInsets() { | ||
ablSettingsFragment.addInsetsByPadding(top = true, left = true, right = true) | ||
// Fix: https://github.com/material-components/material-components-android/issues/1310 | ||
ViewCompat.setOnApplyWindowInsetsListener(ctlSettingsFragment, null) | ||
rvSettingsFragment.addInsetsByPadding(bottom = true, left = true, right = true) | ||
} | ||
|
||
private fun getSettingsList(): List<Any> = mutableListOf( | ||
SettingsBaseBean( | ||
title = getString(R.string.data_fragment_name), | ||
description = getString(R.string.data_fragment_description), | ||
icon = AppCompatResources.getDrawable( | ||
requireContext(), R.drawable.ic_database_24 | ||
)!!, | ||
action = { findMainNavController().navigate(R.id.action_to_data_fragment) } | ||
), | ||
) | ||
|
||
override fun getViewBinding(inflater: LayoutInflater, container: ViewGroup?) = | ||
FragmentSettingsBinding.inflate(inflater, container, false) | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/skyd/anivu/ui/fragment/settings/data/DataEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.skyd.anivu.ui.fragment.settings.data | ||
|
||
import com.skyd.anivu.base.mvi.MviSingleEvent | ||
|
||
sealed interface DataEvent : MviSingleEvent { | ||
sealed interface ClearCacheResultEvent : DataEvent { | ||
data class Success(val msg: String) : ClearCacheResultEvent | ||
data class Failed(val msg: String) : ClearCacheResultEvent | ||
} | ||
} |
Oops, something went wrong.