1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-01-10 17:30:31 +00:00

Merge pull request #4547 from Isira-Seneviratne/Use_Core_KTX_functions

Use Core KTX functions.
This commit is contained in:
Stypox 2020-10-18 09:39:28 +02:00 committed by GitHub
commit a73baf32f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 47 deletions

View File

@ -29,6 +29,8 @@ import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.core.os.bundleOf
import androidx.core.view.isVisible
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
@ -253,11 +255,9 @@ class FeedFragment : BaseListFragment<FeedState, Unit>() {
oldestSubscriptionUpdate = loadedState.oldestUpdate oldestSubscriptionUpdate = loadedState.oldestUpdate
refresh_subtitle_text.isVisible = loadedState.notLoadedCount > 0
if (loadedState.notLoadedCount > 0) { if (loadedState.notLoadedCount > 0) {
refresh_subtitle_text.visibility = View.VISIBLE
refresh_subtitle_text.text = getString(R.string.feed_subscription_not_loaded_count, loadedState.notLoadedCount) refresh_subtitle_text.text = getString(R.string.feed_subscription_not_loaded_count, loadedState.notLoadedCount)
} else {
refresh_subtitle_text.visibility = View.GONE
} }
if (loadedState.itemsErrors.isNotEmpty()) { if (loadedState.itemsErrors.isNotEmpty()) {
@ -330,12 +330,7 @@ class FeedFragment : BaseListFragment<FeedState, Unit>() {
@JvmStatic @JvmStatic
fun newInstance(groupId: Long = FeedGroupEntity.GROUP_ALL_ID, groupName: String? = null): FeedFragment { fun newInstance(groupId: Long = FeedGroupEntity.GROUP_ALL_ID, groupName: String? = null): FeedFragment {
val feedFragment = FeedFragment() val feedFragment = FeedFragment()
feedFragment.arguments = bundleOf(KEY_GROUP_ID to groupId, KEY_GROUP_NAME to groupName)
feedFragment.arguments = Bundle().apply {
putLong(KEY_GROUP_ID, groupId)
putString(KEY_GROUP_NAME, groupName)
}
return feedFragment return feedFragment
} }
} }

View File

@ -3,15 +3,17 @@ package org.schabi.newpipe.local.subscription.dialog
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import android.os.Parcelable import android.os.Parcelable
import android.text.Editable
import android.text.TextUtils import android.text.TextUtils
import android.text.TextWatcher
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import android.widget.Toast import android.widget.Toast
import androidx.core.content.getSystemService import androidx.core.content.getSystemService
import androidx.core.os.bundleOf
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.widget.doOnTextChanged
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
@ -191,16 +193,11 @@ class FeedGroupDialog : DialogFragment(), BackPressable {
} }
group_name_input_container.error = null group_name_input_container.error = null
group_name_input.addTextChangedListener(object : TextWatcher { group_name_input.doOnTextChanged { text, _, _, _ ->
override fun afterTextChanged(s: Editable?) {} if (group_name_input_container.isErrorEnabled && !text.isNullOrBlank()) {
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} group_name_input_container.error = null
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
if (group_name_input_container.isErrorEnabled && !s.isNullOrBlank()) {
group_name_input_container.error = null
}
} }
}) }
confirm_button.setOnClickListener { handlePositiveButton() } confirm_button.setOnClickListener { handlePositiveButton() }
@ -242,15 +239,11 @@ class FeedGroupDialog : DialogFragment(), BackPressable {
} }
} }
toolbar_search_edit_text.addTextChangedListener(object : TextWatcher { toolbar_search_edit_text.doOnTextChanged { _, _, _, _ ->
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) = Unit val newQuery: String = toolbar_search_edit_text.text.toString()
override fun afterTextChanged(s: Editable) = Unit subscriptionsCurrentSearchQuery = newQuery
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { viewModel.filterSubscriptionsBy(newQuery)
val newQuery: String = toolbar_search_edit_text.text.toString() }
subscriptionsCurrentSearchQuery = newQuery
viewModel.filterSubscriptionsBy(newQuery)
}
})
subscriptionGroupAdapter.setOnItemClickListener(subscriptionPickerItemListener) subscriptionGroupAdapter.setOnItemClickListener(subscriptionPickerItemListener)
} }
@ -414,21 +407,14 @@ class FeedGroupDialog : DialogFragment(), BackPressable {
else -> android.R.string.ok else -> android.R.string.ok
}) })
delete_button.visibility = when { delete_button.isGone = currentScreen != InitialScreen || groupId == NO_GROUP_SELECTED
currentScreen != InitialScreen -> View.GONE
groupId == NO_GROUP_SELECTED -> View.GONE
else -> View.VISIBLE
}
hideKeyboard() hideKeyboard()
hideSearch() hideSearch()
} }
private fun View.onlyVisibleIn(vararg screens: ScreenState) { private fun View.onlyVisibleIn(vararg screens: ScreenState) {
visibility = when (currentScreen) { isVisible = currentScreen in screens
in screens -> View.VISIBLE
else -> View.GONE
}
} }
/*/////////////////////////////////////////////////////////////////////////// /*///////////////////////////////////////////////////////////////////////////
@ -501,11 +487,7 @@ class FeedGroupDialog : DialogFragment(), BackPressable {
fun newInstance(groupId: Long = NO_GROUP_SELECTED): FeedGroupDialog { fun newInstance(groupId: Long = NO_GROUP_SELECTED): FeedGroupDialog {
val dialog = FeedGroupDialog() val dialog = FeedGroupDialog()
dialog.arguments = bundleOf(KEY_GROUP_ID to groupId)
dialog.arguments = Bundle().apply {
putLong(KEY_GROUP_ID, groupId)
}
return dialog return dialog
} }
} }

View File

@ -1,9 +1,8 @@
package org.schabi.newpipe.local.subscription.item package org.schabi.newpipe.local.subscription.item
import android.view.View.GONE
import android.view.View.OnClickListener import android.view.View.OnClickListener
import android.view.View.VISIBLE
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.core.view.isVisible
import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder
import com.xwray.groupie.kotlinandroidextensions.Item import com.xwray.groupie.kotlinandroidextensions.Item
import kotlinx.android.synthetic.main.header_with_menu_item.header_menu_item import kotlinx.android.synthetic.main.header_with_menu_item.header_menu_item
@ -47,6 +46,6 @@ class HeaderWithMenuItem(
} }
private fun updateMenuItemVisibility(viewHolder: GroupieViewHolder) { private fun updateMenuItemVisibility(viewHolder: GroupieViewHolder) {
viewHolder.header_menu_item.visibility = if (showMenuItem) VISIBLE else GONE viewHolder.header_menu_item.isVisible = showMenuItem
} }
} }

View File

@ -1,6 +1,7 @@
package org.schabi.newpipe.local.subscription.item package org.schabi.newpipe.local.subscription.item
import android.view.View import android.view.View
import androidx.core.view.isVisible
import com.nostra13.universalimageloader.core.ImageLoader import com.nostra13.universalimageloader.core.ImageLoader
import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder
import com.xwray.groupie.kotlinandroidextensions.Item import com.xwray.groupie.kotlinandroidextensions.Item
@ -25,7 +26,7 @@ data class PickerSubscriptionItem(
viewHolder.thumbnail_view, ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS) viewHolder.thumbnail_view, ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS)
viewHolder.title_view.text = subscriptionEntity.name viewHolder.title_view.text = subscriptionEntity.name
viewHolder.selected_highlight.visibility = if (isSelected) View.VISIBLE else View.GONE viewHolder.selected_highlight.isVisible = isSelected
} }
override fun unbind(viewHolder: GroupieViewHolder) { override fun unbind(viewHolder: GroupieViewHolder) {