Skip to content

Commit

Permalink
remove unused resources + reformat
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Hibbe <[email protected]>
  • Loading branch information
mahibi committed Oct 2, 2023
1 parent 726215e commit 27563a2
Show file tree
Hide file tree
Showing 16 changed files with 343 additions and 734 deletions.
128 changes: 61 additions & 67 deletions app/src/main/java/com/nextcloud/talk/contacts/ContactsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import org.parceler.Parcels
import java.io.IOException
import java.util.Collections
import java.util.Locale
import javax.inject.Inject

Expand Down Expand Up @@ -436,14 +435,14 @@ class ContactsActivity :
private fun fetchData() {
dispose(null)
alreadyFetching = true
userHeaderItems = HashMap<String, GenericTextHeaderItem>()
val query = adapter!!.getFilter(String::class.java) as String?
userHeaderItems = HashMap()
val query = adapter!!.getFilter(String::class.java)
val retrofitBucket: RetrofitBucket =
ApiUtils.getRetrofitBucketForContactsSearchFor14(currentUser!!.baseUrl, query)
val modifiedQueryMap: HashMap<String, Any?> = HashMap<String, Any?>(retrofitBucket.queryMap)
modifiedQueryMap.put("limit", CONTACTS_BATCH_SIZE)
val modifiedQueryMap: HashMap<String, Any?> = HashMap(retrofitBucket.queryMap)
modifiedQueryMap["limit"] = CONTACTS_BATCH_SIZE
if (isAddingParticipantsView) {
modifiedQueryMap.put("itemId", conversationToken)
modifiedQueryMap["itemId"] = conversationToken
}
val shareTypesList: ArrayList<String> = ArrayList()
// users
Expand All @@ -461,7 +460,7 @@ class ContactsActivity :
// circles
shareTypesList.add("7")
}
modifiedQueryMap.put("shareTypes[]", shareTypesList)
modifiedQueryMap["shareTypes[]"] = shareTypesList
ncApi.getContactsWithSearchParam(
credentials,
retrofitBucket.url,
Expand All @@ -479,7 +478,7 @@ class ContactsActivity :
override fun onNext(responseBody: ResponseBody) {
val newUserItemList = processAutocompleteUserList(responseBody)

userHeaderItems = HashMap<String, GenericTextHeaderItem>()
userHeaderItems = HashMap()
contactItems!!.addAll(newUserItemList)

sortUserItems(newUserItemList)
Expand All @@ -490,16 +489,16 @@ class ContactsActivity :
adapter?.filterItems()
}

binding.controllerGenericRv.swipeRefreshLayout?.isRefreshing = false
binding.controllerGenericRv.swipeRefreshLayout.isRefreshing = false
}

override fun onError(e: Throwable) {
binding.controllerGenericRv.swipeRefreshLayout?.isRefreshing = false
binding.controllerGenericRv.swipeRefreshLayout.isRefreshing = false
dispose(contactsQueryDisposable)
}

override fun onComplete() {
binding.controllerGenericRv.swipeRefreshLayout?.isRefreshing = false
binding.controllerGenericRv.swipeRefreshLayout.isRefreshing = false
dispose(contactsQueryDisposable)
alreadyFetching = false
disengageProgressBar()
Expand All @@ -509,26 +508,26 @@ class ContactsActivity :

private fun processAutocompleteUserList(responseBody: ResponseBody): MutableList<AbstractFlexibleItem<*>> {
try {
val autocompleteOverall: AutocompleteOverall = LoganSquare.parse<AutocompleteOverall>(
val autocompleteOverall: AutocompleteOverall = LoganSquare.parse(
responseBody.string(),
AutocompleteOverall::class.java
)
val autocompleteUsersList: ArrayList<AutocompleteUser> = ArrayList<AutocompleteUser>()
val autocompleteUsersList: ArrayList<AutocompleteUser> = ArrayList()
autocompleteUsersList.addAll(autocompleteOverall.ocs!!.data!!)
return processAutocompleteUserList(autocompleteUsersList)
} catch (ioe: IOException) {
Log.e(TAG, "Parsing response body failed while getting contacts", ioe)
}

return ArrayList<AbstractFlexibleItem<*>>()
return ArrayList()
}

private fun processAutocompleteUserList(
autocompleteUsersList: ArrayList<AutocompleteUser>
): MutableList<AbstractFlexibleItem<*>> {
var participant: Participant
val actorTypeConverter = EnumActorTypeConverter()
val newUserItemList: MutableList<AbstractFlexibleItem<*>> = ArrayList<AbstractFlexibleItem<*>>()
val newUserItemList: MutableList<AbstractFlexibleItem<*>> = ArrayList()
for (autocompleteUser in autocompleteUsersList) {
if (autocompleteUser.id != null &&
autocompleteUser.id != currentUser!!.userId &&
Expand Down Expand Up @@ -564,7 +563,7 @@ class ContactsActivity :
resources!!.getString(R.string.nc_circles)
}
else -> {
participant.displayName!!.substring(0, 1).toUpperCase(Locale.getDefault())
participant.displayName!!.substring(0, 1).uppercase(Locale.getDefault())
}
}
}
Expand All @@ -582,76 +581,72 @@ class ContactsActivity :
return participant
}

@Suppress("LongMethod")
private fun sortUserItems(newUserItemList: MutableList<AbstractFlexibleItem<*>>) {
Collections.sort(
newUserItemList,
{ o1: AbstractFlexibleItem<*>, o2: AbstractFlexibleItem<*> ->
val firstName: String = if (o1 is ContactItem) {
(o1 as ContactItem).model.displayName!!
} else {
(o1 as GenericTextHeaderItem).model
}
val secondName: String = if (o2 is ContactItem) {
(o2 as ContactItem).model.displayName!!
} else {
(o2 as GenericTextHeaderItem).model
newUserItemList.sortWith sort@{ o1: AbstractFlexibleItem<*>, o2: AbstractFlexibleItem<*> ->
val firstName: String = if (o1 is ContactItem) {
o1.model.displayName!!
} else {
(o1 as GenericTextHeaderItem).model
}
val secondName: String = if (o2 is ContactItem) {
o2.model.displayName!!
} else {
(o2 as GenericTextHeaderItem).model
}
if (o1 is ContactItem && o2 is ContactItem) {
val firstSource: String = o1.model.source!!
val secondSource: String = o2.model.source!!
if (firstSource == secondSource) {
return@sort firstName.compareTo(secondName, ignoreCase = true)
}
if (o1 is ContactItem && o2 is ContactItem) {
val firstSource: String = (o1 as ContactItem).model.source!!
val secondSource: String = (o2 as ContactItem).model.source!!
if (firstSource == secondSource) {
return@sort firstName.compareTo(secondName, ignoreCase = true)
}

// First users
if ("users" == firstSource) {
return@sort -1
} else if ("users" == secondSource) {
return@sort 1
}

// Then groups
if ("groups" == firstSource) {
return@sort -1
} else if ("groups" == secondSource) {
return@sort 1
}
// First users
if ("users" == firstSource) {
return@sort -1
} else if ("users" == secondSource) {
return@sort 1
}

// Then circles
if ("circles" == firstSource) {
return@sort -1
} else if ("circles" == secondSource) {
return@sort 1
}
// Then groups
if ("groups" == firstSource) {
return@sort -1
} else if ("groups" == secondSource) {
return@sort 1
}

// Otherwise fall back to name sorting
return@sort firstName.compareTo(secondName, ignoreCase = true)
// Then circles
if ("circles" == firstSource) {
return@sort -1
} else if ("circles" == secondSource) {
return@sort 1
}
firstName.compareTo(secondName, ignoreCase = true)

// Otherwise fall back to name sorting
return@sort firstName.compareTo(secondName, ignoreCase = true)
}
)
firstName.compareTo(secondName, ignoreCase = true)
}

Collections.sort(
contactItems
) { o1: AbstractFlexibleItem<*>, o2: AbstractFlexibleItem<*> ->
contactItems?.sortWith sort@{ o1: AbstractFlexibleItem<*>, o2: AbstractFlexibleItem<*> ->
val firstName: String = if (o1 is ContactItem) {
(o1 as ContactItem).model.displayName!!
o1.model.displayName!!
} else {
(o1 as GenericTextHeaderItem).model
}
val secondName: String = if (o2 is ContactItem) {
(o2 as ContactItem).model.displayName!!
o2.model.displayName!!
} else {
(o2 as GenericTextHeaderItem).model
}
if (o1 is ContactItem && o2 is ContactItem) {
if ("groups" == (o1 as ContactItem).model.source &&
"groups" == (o2 as ContactItem).model.source
if ("groups" == o1.model.source &&
"groups" == o2.model.source
) {
return@sort firstName.compareTo(secondName, ignoreCase = true)
} else if ("groups" == (o1 as ContactItem).model.source) {
} else if ("groups" == o1.model.source) {
return@sort -1
} else if ("groups" == (o2 as ContactItem).model.source) {
} else if ("groups" == o2.model.source) {
return@sort 1
}
}
Expand Down Expand Up @@ -750,7 +745,6 @@ class ContactsActivity :
if (!isNewConversationView && !isAddingParticipantsView) {
createRoom(adapter?.getItem(position) as ContactItem)
} else {
val participant: Participant = (adapter?.getItem(position) as ContactItem).model
updateSelection((adapter?.getItem(position) as ContactItem))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ class CreateConversationDialogFragment : DialogFragment() {
.setTitle(resources.getString(R.string.nc_call_name))
// listener is null for now to avoid closing after button was clicked.
// listener is set later in onStart
.setPositiveButton("create", null)
.setNegativeButton("cancel", null)
.setPositiveButton(R.string.nc_common_create, null)
.setNegativeButton(R.string.nc_common_dismiss, null)
.setView(binding.root)
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(binding.root.context, dialogBuilder)

Expand All @@ -133,8 +133,6 @@ class CreateConversationDialogFragment : DialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

themeDialog()

setupListeners()
setupStateObserver()

Expand Down Expand Up @@ -178,21 +176,6 @@ class CreateConversationDialogFragment : DialogFragment() {
}
}

private fun themeDialog() {
// viewThemeUtils.platform.colorTextView(binding.pollQuestion)
// viewThemeUtils.platform.colorTextView(binding.pollOptions)
// viewThemeUtils.platform.colorTextView(binding.pollSettings)
//
// viewThemeUtils.material.colorTextInputLayout(binding.pollCreateQuestionTextInputLayout)
//
// viewThemeUtils.material.colorMaterialButtonText(binding.pollAddOptionsItem)
// viewThemeUtils.material.colorMaterialButtonText(binding.pollDismiss)
// viewThemeUtils.material.colorMaterialButtonPrimaryFilled(binding.pollCreateButton)
//
// viewThemeUtils.platform.themeCheckbox(binding.pollPrivatePollCheckbox)
// viewThemeUtils.platform.themeCheckbox(binding.pollMultipleAnswersCheckbox)
}

private fun setupListeners() {
binding.smileyButton.setOnClickListener { emojiPopup?.toggle() }
binding.textEdit.addTextChangedListener(object : TextWatcher {
Expand Down Expand Up @@ -250,7 +233,7 @@ class CreateConversationDialogFragment : DialogFragment() {
.setInputData(data.build())
.build()

WorkManager.getInstance().enqueue(addParticipantsToConversationWorker)
WorkManager.getInstance(requireContext()).enqueue(addParticipantsToConversationWorker)

WorkManager.getInstance(requireContext()).getWorkInfoByIdLiveData(addParticipantsToConversationWorker.id)
.observeForever { workInfo: WorkInfo? ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class RenameConversationDialogFragment : DialogFragment() {

viewModel = ViewModelProvider(this, viewModelFactory)[RenameConversationViewModel::class.java]
roomToken = arguments?.getString(KEY_ROOM_TOKEN)!!
initialName = arguments?.getString(INITIAL_NAME_TO_DISPLAY)!!
initialName = arguments?.getString(INITIAL_NAME)!!
}

@SuppressLint("InflateParams")
Expand All @@ -88,8 +88,8 @@ class RenameConversationDialogFragment : DialogFragment() {
.setTitle(resources.getString(R.string.nc_call_name))
// listener is null for now to avoid closing after button was clicked.
// listener is set later in onStart
.setPositiveButton("rename", null)
.setNegativeButton("cancel", null)
.setPositiveButton(R.string.nc_rename_confirm, null)
.setNegativeButton(R.string.nc_common_dismiss, null)
.setView(binding.root)
viewThemeUtils.dialog.colorMaterialAlertDialogBackground(binding.root.context, dialogBuilder)

Expand Down Expand Up @@ -214,13 +214,13 @@ class RenameConversationDialogFragment : DialogFragment() {
companion object {
private val TAG = RenameConversationDialogFragment::class.java.simpleName
private const val KEY_ROOM_TOKEN = "keyRoomToken"
private const val INITIAL_NAME_TO_DISPLAY = "initialNameToDisplay"
private const val INITIAL_NAME = "initialName"

@JvmStatic
fun newInstance(roomTokenParam: String, initialName: String): RenameConversationDialogFragment {
val args = Bundle()
args.putString(KEY_ROOM_TOKEN, roomTokenParam)
args.putString(INITIAL_NAME_TO_DISPLAY, initialName)
args.putString(INITIAL_NAME, initialName)
val fragment = RenameConversationDialogFragment()
fragment.arguments = args
return fragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

class ConversationRepositoryImpl(private val ncApi: NcApi, private val currentUserProvider: CurrentUserProviderNew) :
class ConversationRepositoryImpl(private val ncApi: NcApi, currentUserProvider: CurrentUserProviderNew) :
ConversationRepository {

val currentUser: User = currentUserProvider.currentUser.blockingGet()
Expand All @@ -55,7 +55,7 @@ class ConversationRepositoryImpl(private val ncApi: NcApi, private val currentUs
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.retry(1)
.retry(API_RETRIES)
}

override fun createConversation(
Expand All @@ -68,7 +68,7 @@ class ConversationRepositoryImpl(private val ncApi: NcApi, private val currentUs
ApiUtils.getRetrofitBucketForCreateRoom(
apiVersion,
currentUser.baseUrl,
"3",
ROOM_TYPE_PUBLIC,
null,
null,
roomName
Expand All @@ -77,7 +77,7 @@ class ConversationRepositoryImpl(private val ncApi: NcApi, private val currentUs
ApiUtils.getRetrofitBucketForCreateRoom(
apiVersion,
currentUser.baseUrl,
"2",
ROOM_TYPE_GROUP,
null,
null,
roomName
Expand All @@ -90,5 +90,8 @@ class ConversationRepositoryImpl(private val ncApi: NcApi, private val currentUs
}

companion object {
private const val ROOM_TYPE_PUBLIC = "3"
private const val ROOM_TYPE_GROUP = "2"
const val API_RETRIES: Long = 3
}
}

This file was deleted.

Loading

0 comments on commit 27563a2

Please sign in to comment.