Skip to content

Commit

Permalink
Merge pull request #3677 from nextcloud/use-default-constructor
Browse files Browse the repository at this point in the history
Fix: Use of parameterized constructor with fragments
  • Loading branch information
mahibi authored Mar 11, 2024
2 parents d863674 + 3866bee commit 36e0c13
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 187 deletions.
7 changes: 1 addition & 6 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4259,12 +4259,7 @@ class ChatActivity :

val chatApiVersion = ApiUtils.getChatApiVersion(spreedCapabilities, intArrayOf(ApiUtils.API_V1, 1))

val newFragment: DialogFragment = DateTimePickerFragment.newInstance(
roomToken,
message!!.id,
chatViewModel,
chatApiVersion
)
val newFragment: DialogFragment = DateTimePickerFragment.newInstance(roomToken, message!!.id, chatApiVersion)
newFragment.show(supportFragmentManager, DateTimePickerFragment.TAG)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -978,10 +978,7 @@ class ConversationsListActivity :
updateFilterConversationButtonColor()

binding.filterConversationsButton.setOnClickListener {
val newFragment: DialogFragment = FilterConversationFragment.newInstance(
filterState,
this
)
val newFragment = FilterConversationFragment.newInstance(filterState)
newFragment.show(supportFragmentManager, FilterConversationFragment.TAG)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.google.android.material.timepicker.TimeFormat
import com.nextcloud.android.common.ui.theme.utils.ColorRole
import com.nextcloud.talk.R
import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.chat.ChatActivity
import com.nextcloud.talk.chat.viewmodels.ChatViewModel
import com.nextcloud.talk.databinding.DialogDateTimePickerBinding
import com.nextcloud.talk.ui.theme.ViewThemeUtils
Expand All @@ -47,18 +48,15 @@ import javax.inject.Inject

@Suppress("TooManyFunctions")
@AutoInjector(NextcloudTalkApplication::class)
class DateTimePickerFragment(
token: String,
id: String,
chatViewModel: ChatViewModel,
private val chatApiVersion: Int
) : DialogFragment() {
class DateTimePickerFragment : DialogFragment() {

lateinit var binding: DialogDateTimePickerBinding
private var dialogView: View? = null
private var viewModel = chatViewModel
private lateinit var viewModel: ChatViewModel
private var currentTimeStamp: Long? = null
private var roomToken = token
private var messageId = id
private lateinit var roomToken: String
private lateinit var messageId: String
private var chatApiVersion: Int = -1
private var laterTodayTimeStamp = 0L
private var tomorrowTimeStamp = 0L
private var weekendTimeStamp = 0L
Expand All @@ -73,6 +71,12 @@ class DateTimePickerFragment(
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
binding = DialogDateTimePickerBinding.inflate(LayoutInflater.from(context))
dialogView = binding.root
viewModel = (requireActivity() as ChatActivity).chatViewModel
arguments?.let {
roomToken = it.getString(TOKEN_ARG, "")
messageId = it.getString(ID_ARG, "")
chatApiVersion = it.getInt(CHAT_API_VERSION_ARG)
}
return MaterialAlertDialogBuilder(requireContext()).setView(dialogView).create()
}

Expand Down Expand Up @@ -304,14 +308,20 @@ class DateTimePickerFragment(
private const val ONE_SEC = 1000
private const val HOUR_EIGHT_AM = 8
private const val HOUR_SIX_PM = 18
private const val TOKEN_ARG = "TOKEN_ARG"
private const val ID_ARG = "ID_ARG"
private const val CHAT_API_VERSION_ARG = "CHAT_API_VERSION_ARG"

@JvmStatic
fun newInstance(token: String, id: String, chatViewModel: ChatViewModel, chatApiVersion: Int) =
DateTimePickerFragment(
token,
id,
chatViewModel,
chatApiVersion
)
fun newInstance(token: String, id: String, chatApiVersion: Int): DateTimePickerFragment {
val args = Bundle()
args.putString(TOKEN_ARG, token)
args.putString(ID_ARG, id)
args.putInt(CHAT_API_VERSION_ARG, chatApiVersion)

val dateTimePickerFragment = DateTimePickerFragment()
dateTimePickerFragment.arguments = args
return dateTimePickerFragment
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package com.nextcloud.talk.ui.dialog

import android.app.Dialog
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand All @@ -38,14 +39,10 @@ import com.nextcloud.talk.utils.UserIdUtils
import javax.inject.Inject

@AutoInjector(NextcloudTalkApplication::class)
class FilterConversationFragment(
savedFilterState: MutableMap<String, Boolean>,
conversationsListActivity: ConversationsListActivity
) : DialogFragment() {
class FilterConversationFragment : DialogFragment() {
lateinit var binding: DialogFilterConversationBinding
private var dialogView: View? = null
private var filterState = savedFilterState
private var conversationsList = conversationsListActivity
private lateinit var filterState: HashMap<String, Boolean>

@Inject
lateinit var userManager: UserManager
Expand All @@ -58,7 +55,11 @@ class FilterConversationFragment(
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
binding = DialogFilterConversationBinding.inflate(LayoutInflater.from(context))
dialogView = binding.root

filterState = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
arguments?.getSerializable(FILTER_STATE_ARG, HashMap::class.java) as HashMap<String, Boolean>
} else {
arguments?.getSerializable(FILTER_STATE_ARG) as HashMap<String, Boolean>
}
return MaterialAlertDialogBuilder(requireContext()).setView(dialogView).create()
}

Expand Down Expand Up @@ -120,15 +121,21 @@ class FilterConversationFragment(
arbitraryStorageManager.storeStorageSetting(accountId, MENTION, mentionValue.toString(), "")
arbitraryStorageManager.storeStorageSetting(accountId, UNREAD, unreadValue.toString(), "")

conversationsList.filterConversation()
(requireActivity() as ConversationsListActivity).filterConversation()
}

companion object {
private const val FILTER_STATE_ARG = "FILTER_STATE_ARG"

@JvmStatic
fun newInstance(
savedFilterState: MutableMap<String, Boolean>,
conversationsListActivity: ConversationsListActivity
) = FilterConversationFragment(savedFilterState, conversationsListActivity)
fun newInstance(savedFilterState: MutableMap<String, Boolean>): FilterConversationFragment {
val filterConversationFragment = FilterConversationFragment()
val args = Bundle()
args.putSerializable(FILTER_STATE_ARG, HashMap(savedFilterState))
filterConversationFragment.arguments = args
return filterConversationFragment
}

val TAG: String = FilterConversationFragment::class.java.simpleName
const val MENTION: String = "mention"
const val UNREAD: String = "unread"
Expand Down
Loading

0 comments on commit 36e0c13

Please sign in to comment.