Skip to content

Commit

Permalink
fix: use bundle to pass torrent name instead of constructor arg
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash-Garg committed Oct 13, 2022
1 parent 5c53e71 commit b50d509
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.google.android.material.textfield.TextInputEditText
import com.google.android.material.textfield.TextInputLayout
import dev.yashgarg.qbit.R

class RenameTorrentDialog(private val title: String) : DialogFragment() {
class RenameTorrentDialog : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
super.onCreateDialog(savedInstanceState)
val alertDialogBuilder = MaterialAlertDialogBuilder(requireContext())
Expand All @@ -24,14 +24,15 @@ class RenameTorrentDialog(private val title: String) : DialogFragment() {
setPositiveButton("Rename", null)
}

val title = arguments?.getString(TORRENT_NAME_KEY)
val dialog = alertDialogBuilder.create()
dialog.window?.setSoftInputMode(5)

dialog.setOnShowListener {
val nameTil = dialog.findViewById<TextInputLayout>(R.id.torrentName_til)
val nameTiet = dialog.findViewById<TextInputEditText>(R.id.torrentName_tiet)
nameTiet?.setText(title)
nameTiet?.setSelection(title.length)
nameTiet?.setSelection(title?.length ?: 0)

dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
if (!nameTiet?.text.isNullOrEmpty()) {
Expand All @@ -50,8 +51,9 @@ class RenameTorrentDialog(private val title: String) : DialogFragment() {
}

companion object {
fun newInstance(title: String): RenameTorrentDialog = RenameTorrentDialog(title)
fun newInstance(): RenameTorrentDialog = RenameTorrentDialog()
const val TAG = "RenameTorrentDialogFragment"
const val TORRENT_NAME_KEY = "torrent_name"
const val RENAME_TORRENT_KEY = "rename_torrent"
const val RENAME_KEY = "rename_fragment"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dev.yashgarg.qbit.ui.torrent
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.flowWithLifecycle
Expand Down Expand Up @@ -118,8 +119,10 @@ class TorrentDetailsFragment : Fragment(R.layout.torrent_details_fragment) {
add("Rename")
.setIcon(R.drawable.twotone_drive_file_rename_outline_24)
.setOnMenuItemClickListener {
RenameTorrentDialog.newInstance(torrent.name)
.show(childFragmentManager, RenameTorrentDialog.TAG)
val dialog = RenameTorrentDialog.newInstance()
dialog.arguments =
bundleOf(RenameTorrentDialog.TORRENT_NAME_KEY to torrent.name)
dialog.show(childFragmentManager, RenameTorrentDialog.TAG)
true
}
}
Expand Down

0 comments on commit b50d509

Please sign in to comment.