Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/rebelonion/Dantotsu into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed Apr 21, 2024
2 parents 4477e3a + 3fd01d5 commit 233f4bf
Show file tree
Hide file tree
Showing 15 changed files with 127 additions and 75 deletions.
13 changes: 6 additions & 7 deletions app/src/main/java/ani/dantotsu/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import ani.dantotsu.addons.torrent.TorrentAddonManager
import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.connections.anilist.AnilistHomeViewModel
import ani.dantotsu.databinding.ActivityMainBinding
import ani.dantotsu.databinding.DialogUserAgentBinding
import ani.dantotsu.databinding.SplashScreenBinding
import ani.dantotsu.home.AnimeFragment
import ani.dantotsu.home.HomeFragment
Expand Down Expand Up @@ -493,16 +494,14 @@ class MainActivity : AppCompatActivity() {
val password = CharArray(16).apply { fill('0') }

// Inflate the dialog layout
val dialogView =
LayoutInflater.from(this).inflate(R.layout.dialog_user_agent, null)
dialogView.findViewById<TextInputEditText>(R.id.userAgentTextBox)?.hint = "Password"
val subtitleTextView = dialogView.findViewById<TextView>(R.id.subtitle)
subtitleTextView?.visibility = View.VISIBLE
subtitleTextView?.text = getString(R.string.enter_password_to_decrypt_file)
val dialogView = DialogUserAgentBinding.inflate(layoutInflater)
dialogView.userAgentTextBox.hint = "Password"
dialogView.subtitle.visibility = View.VISIBLE
dialogView.subtitle.text = getString(R.string.enter_password_to_decrypt_file)

val dialog = AlertDialog.Builder(this, R.style.MyPopup)
.setTitle("Enter Password")
.setView(dialogView)
.setView(dialogView.root)
.setPositiveButton("OK", null)
.setNegativeButton("Cancel") { dialog, _ ->
password.fill('0')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package ani.dantotsu.addons.download
package ani.dantotsu.addons

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import androidx.core.content.ContextCompat
import ani.dantotsu.addons.AddonListener
import ani.dantotsu.addons.AddonLoader
import ani.dantotsu.addons.download.DownloadAddonManager
import ani.dantotsu.addons.torrent.TorrentAddonManager
import ani.dantotsu.media.AddonType
import eu.kanade.tachiyomi.extension.util.ExtensionInstallReceiver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import ani.dantotsu.R
import ani.dantotsu.addons.AddonDownloader
import ani.dantotsu.addons.AddonInstallReceiver
import ani.dantotsu.addons.AddonListener
import ani.dantotsu.addons.AddonLoader
import ani.dantotsu.addons.AddonManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ani.dantotsu.addons.AddonListener
import ani.dantotsu.addons.AddonLoader
import ani.dantotsu.addons.AddonManager
import ani.dantotsu.addons.LoadResult
import ani.dantotsu.addons.download.AddonInstallReceiver
import ani.dantotsu.addons.AddonInstallReceiver
import ani.dantotsu.media.AddonType
import ani.dantotsu.util.Logger
import eu.kanade.tachiyomi.extension.InstallStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import ani.dantotsu.BottomSheetDialogFragment
import ani.dantotsu.R
import ani.dantotsu.addons.download.DownloadAddonManager
import ani.dantotsu.addons.torrent.TorrentAddonManager
import ani.dantotsu.connections.crashlytics.CrashlyticsInterface
import ani.dantotsu.copyToClipboard
Expand All @@ -48,6 +49,7 @@ import ani.dantotsu.setSafeOnClickListener
import ani.dantotsu.settings.saving.PrefManager
import ani.dantotsu.settings.saving.PrefName
import ani.dantotsu.snackString
import ani.dantotsu.toast
import ani.dantotsu.tryWith
import ani.dantotsu.util.Logger
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -478,6 +480,11 @@ class SelectorDialogFragment : BottomSheetDialogFragment() {
media!!.userPreferredName
)
} else {
val downloadAddonManager: DownloadAddonManager = Injekt.get()
if (!downloadAddonManager.isAvailable()){
toast("Download Extension not available")
return@setSafeOnClickListener
}
val episode = media!!.anime!!.episodes!![media!!.anime!!.selectedEpisode!!]!!
val selectedVideo =
if (extractor.videos.size > episode.selectedVideo) extractor.videos[episode.selectedVideo] else null
Expand All @@ -488,7 +495,7 @@ class SelectorDialogFragment : BottomSheetDialogFragment() {
if (url.startsWith("magnet:") || url.endsWith(".torrent")) {
val torrentExtension = Injekt.get<TorrentAddonManager>()
if (!torrentExtension.isAvailable()) {
snackString("Torrent Extension not available")
toast("Torrent Extension not available")
return@setSafeOnClickListener
}
runBlocking {
Expand Down
21 changes: 13 additions & 8 deletions app/src/main/java/ani/dantotsu/settings/SettingsAddonActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SettingsAddonActivity : AppCompatActivity() {
type = 1,
name = getString(R.string.anime_downloader_addon),
desc = getString(R.string.not_installed),
icon = R.drawable.anim_play_to_pause,
icon = R.drawable.ic_download_24,
isActivity = true,
attach = {
setStatus(
Expand All @@ -85,7 +85,7 @@ class SettingsAddonActivity : AppCompatActivity() {
it.settingsIconRight.setOnClickListener { _ ->
if (it.settingsDesc.text == getString(R.string.installed)) {
downloadAddonManager.uninstall()
return@setOnClickListener //uninstall logic here
return@setOnClickListener
} else {
job = Job()
val scope = CoroutineScope(Dispatchers.Main + job)
Expand Down Expand Up @@ -118,7 +118,7 @@ class SettingsAddonActivity : AppCompatActivity() {
type = 1,
name = getString(R.string.torrent_addon),
desc = getString(R.string.not_installed),
icon = R.drawable.anim_play_to_pause,
icon = R.drawable.ic_round_magnet_24,
isActivity = true,
attach = {
setStatus(
Expand Down Expand Up @@ -176,15 +176,21 @@ class SettingsAddonActivity : AppCompatActivity() {
Settings(
type = 2,
name = getString(R.string.enable_torrent),
desc = getString(R.string.enable_torrent),
desc = getString(R.string.enable_torrent_desc),
icon = R.drawable.ic_round_dns_24,
isChecked = PrefManager.getVal(PrefName.TorrentEnabled),
switch = { isChecked, _ ->
switch = { isChecked, it ->
if (isChecked && !torrentAddonManager.isAvailable()) {
snackString(getString(R.string.install_torrent_addon))
it.settingsButton.isChecked = false
PrefManager.setVal(PrefName.TorrentEnabled, false)
return@Settings
}
PrefManager.setVal(PrefName.TorrentEnabled, isChecked)
Injekt.get<TorrentAddonManager>().extension?.let {
if (isChecked) {
lifecycleScope.launchIO {
if (!ServerService.isRunning() && torrentAddonManager.isAvailable()) {
if (!ServerService.isRunning()) {
ServerService.start()
}
}
Expand All @@ -196,14 +202,13 @@ class SettingsAddonActivity : AppCompatActivity() {
}
}
}
}
},
)
)
)
binding.settingsRecyclerView.layoutManager =
LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)


}
}

Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/ani/dantotsu/settings/SettingsAnimeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class SettingsAnimeActivity : AppCompatActivity() {
Settings(
type = 1,
name = getString(R.string.player_settings),
desc = getString(R.string.player_settings),
desc = getString(R.string.player_settings_desc),
icon = R.drawable.ic_round_video_settings_24,
onClick = {
startActivity(Intent(context, PlayerSettingsActivity::class.java))
Expand All @@ -54,7 +54,7 @@ class SettingsAnimeActivity : AppCompatActivity() {
Settings(
type = 1,
name = getString(R.string.purge_anime_downloads),
desc = getString(R.string.purge_anime_downloads),
desc = getString(R.string.purge_anime_downloads_desc),
icon = R.drawable.ic_round_delete_24,
onClick = {
val dialog = AlertDialog.Builder(context, R.style.MyPopup)
Expand All @@ -80,7 +80,7 @@ class SettingsAnimeActivity : AppCompatActivity() {
Settings(
type = 2,
name = getString(R.string.prefer_dub),
desc = getString(R.string.prefer_dub),
desc = getString(R.string.prefer_dub_desc),
icon = R.drawable.ic_round_audiotrack_24,
isChecked = PrefManager.getVal(PrefName.SettingsPreferDub),
switch = { isChecked, _ ->
Expand All @@ -90,7 +90,7 @@ class SettingsAnimeActivity : AppCompatActivity() {
Settings(
type = 2,
name = getString(R.string.show_yt),
desc = getString(R.string.show_yt),
desc = getString(R.string.show_yt_desc),
icon = R.drawable.ic_round_play_circle_24,
isChecked = PrefManager.getVal(PrefName.ShowYtButton),
switch = { isChecked, _ ->
Expand All @@ -100,7 +100,7 @@ class SettingsAnimeActivity : AppCompatActivity() {
Settings(
type = 2,
name = getString(R.string.include_list),
desc = getString(R.string.include_list),
desc = getString(R.string.include_list_anime_desc),
icon = R.drawable.view_list_24,
isChecked = PrefManager.getVal(PrefName.IncludeAnimeList),
switch = { isChecked, _ ->
Expand Down
40 changes: 20 additions & 20 deletions app/src/main/java/ani/dantotsu/settings/SettingsCommonActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import ani.dantotsu.R
import ani.dantotsu.connections.anilist.Anilist
import ani.dantotsu.databinding.ActivitySettingsCommonBinding
import ani.dantotsu.databinding.DialogUserAgentBinding
import ani.dantotsu.download.DownloadsManager
import ani.dantotsu.initActivity
import ani.dantotsu.navBarHeight
Expand All @@ -33,7 +34,6 @@ import ani.dantotsu.themes.ThemeManager
import ani.dantotsu.toast
import ani.dantotsu.util.LauncherWrapper
import ani.dantotsu.util.StoragePermissions
import com.google.android.material.textfield.TextInputEditText
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
Expand Down Expand Up @@ -136,7 +136,7 @@ class SettingsCommonActivity : AppCompatActivity() {
Settings(
type = 1,
name = getString(R.string.ui_settings),
desc = getString(R.string.ui_settings),
desc = getString(R.string.ui_settings_desc),
icon = R.drawable.ic_round_auto_awesome_24,
onClick = {
startActivity(
Expand All @@ -151,7 +151,7 @@ class SettingsCommonActivity : AppCompatActivity() {
Settings(
type = 1,
name = getString(R.string.download_manager_select),
desc = getString(R.string.download_manager_select),
desc = getString(R.string.download_manager_select_desc),
icon = R.drawable.ic_download_24,
onClick = {
val managers = arrayOf("Default", "1DM", "ADM")
Expand All @@ -172,7 +172,7 @@ class SettingsCommonActivity : AppCompatActivity() {
Settings(
type = 1,
name = getString(R.string.backup_restore),
desc = getString(R.string.backup_restore),
desc = getString(R.string.backup_restore_desc),
icon = R.drawable.backup_restore,
onClick = {
StoragePermissions.downloadsPermission(context)
Expand Down Expand Up @@ -227,7 +227,7 @@ class SettingsCommonActivity : AppCompatActivity() {
Settings(
type = 1,
name = getString(R.string.change_download_location),
desc = getString(R.string.change_download_location),
desc = getString(R.string.change_download_location_desc),
icon = R.drawable.ic_round_source_24,
onClick = {
val dialog = AlertDialog.Builder(context, R.style.MyPopup)
Expand Down Expand Up @@ -267,7 +267,7 @@ class SettingsCommonActivity : AppCompatActivity() {
Settings(
type = 2,
name = getString(R.string.always_continue_content),
desc = getString(R.string.always_continue_content),
desc = getString(R.string.always_continue_content_desc),
icon = R.drawable.ic_round_delete_24,
isChecked = PrefManager.getVal(PrefName.ContinueMedia),
switch = { isChecked, _ ->
Expand All @@ -277,7 +277,7 @@ class SettingsCommonActivity : AppCompatActivity() {
Settings(
type = 2,
name = getString(R.string.search_source_list),
desc = getString(R.string.search_source_list),
desc = getString(R.string.search_source_list_desc),
icon = R.drawable.ic_round_search_sources_24,
isChecked = PrefManager.getVal(PrefName.SearchSources),
switch = { isChecked, _ ->
Expand All @@ -287,7 +287,7 @@ class SettingsCommonActivity : AppCompatActivity() {
Settings(
type = 2,
name = getString(R.string.recentlyListOnly),
desc = getString(R.string.recentlyListOnly),
desc = getString(R.string.recentlyListOnly_desc),
icon = R.drawable.ic_round_new_releases_24,
isChecked = PrefManager.getVal(PrefName.RecentlyListOnly),
switch = { isChecked, _ ->
Expand All @@ -297,7 +297,7 @@ class SettingsCommonActivity : AppCompatActivity() {
Settings(
type = 2,
name = getString(R.string.adult_only_content),
desc = getString(R.string.adult_only_content),
desc = getString(R.string.adult_only_content_desc),
icon = R.drawable.ic_round_nsfw_24,
isChecked = PrefManager.getVal(PrefName.AdultOnly),
switch = { isChecked, _ ->
Expand Down Expand Up @@ -347,41 +347,41 @@ class SettingsCommonActivity : AppCompatActivity() {
val password = CharArray(16).apply { fill('0') }

// Inflate the dialog layout
val dialogView = LayoutInflater.from(this).inflate(R.layout.dialog_user_agent, null)
val box = dialogView.findViewById<TextInputEditText>(R.id.userAgentTextBox)
box?.hint = getString(R.string.password)
box?.setSingleLine()
val dialogView = DialogUserAgentBinding.inflate(layoutInflater)
val box = dialogView.userAgentTextBox
box.hint = getString(R.string.password)
box.setSingleLine()

val dialog =
AlertDialog.Builder(this, R.style.MyPopup).setTitle(getString(R.string.enter_password))
.setView(dialogView).setPositiveButton(R.string.ok, null)
.setView(dialogView.root)
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel) { dialog, _ ->
password.fill('0')
dialog.dismiss()
callback(null)
}.create()

fun handleOkAction() {
val editText = dialog.findViewById<TextInputEditText>(R.id.userAgentTextBox)
if (editText?.text?.isNotBlank() == true) {
val editText = dialogView.userAgentTextBox
if (editText.text?.isNotBlank() == true) {
editText.text?.toString()?.trim()?.toCharArray(password)
dialog.dismiss()
callback(password)
} else {
toast(getString(R.string.password_cannot_be_empty))
}
}
box?.setOnEditorActionListener { _, actionId, _ ->
box.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
handleOkAction()
true
} else {
false
}
}
val subtitleTextView = dialogView.findViewById<TextView>(R.id.subtitle)
subtitleTextView?.visibility = View.VISIBLE
if (!isExporting) subtitleTextView?.text =
dialogView.subtitle.visibility = View.VISIBLE
if (!isExporting) dialogView.subtitle.text =
getString(R.string.enter_password_to_decrypt_file)


Expand Down
Loading

0 comments on commit 233f4bf

Please sign in to comment.