Skip to content

Commit

Permalink
Merge pull request #4547 from Isira-Seneviratne/Use_Core_KTX_functions
Browse files Browse the repository at this point in the history
Use Core KTX functions.
  • Loading branch information
Stypox authored Oct 18, 2020
2 parents 333cf0a + 03d9988 commit a73baf3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 47 deletions.
13 changes: 4 additions & 9 deletions app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import androidx.core.os.bundleOf
import androidx.core.view.isVisible
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.preference.PreferenceManager
Expand Down Expand Up @@ -253,11 +255,9 @@ class FeedFragment : BaseListFragment<FeedState, Unit>() {

oldestSubscriptionUpdate = loadedState.oldestUpdate

refresh_subtitle_text.isVisible = 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)
} else {
refresh_subtitle_text.visibility = View.GONE
}

if (loadedState.itemsErrors.isNotEmpty()) {
Expand Down Expand Up @@ -330,12 +330,7 @@ class FeedFragment : BaseListFragment<FeedState, Unit>() {
@JvmStatic
fun newInstance(groupId: Long = FeedGroupEntity.GROUP_ALL_ID, groupName: String? = null): FeedFragment {
val feedFragment = FeedFragment()

feedFragment.arguments = Bundle().apply {
putLong(KEY_GROUP_ID, groupId)
putString(KEY_GROUP_NAME, groupName)
}

feedFragment.arguments = bundleOf(KEY_GROUP_ID to groupId, KEY_GROUP_NAME to groupName)
return feedFragment
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ package org.schabi.newpipe.local.subscription.dialog
import android.app.Dialog
import android.os.Bundle
import android.os.Parcelable
import android.text.Editable
import android.text.TextUtils
import android.text.TextWatcher
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import android.widget.Toast
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.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
Expand Down Expand Up @@ -191,16 +193,11 @@ class FeedGroupDialog : DialogFragment(), BackPressable {
}

group_name_input_container.error = null
group_name_input.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable?) {}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}

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
}
group_name_input.doOnTextChanged { text, _, _, _ ->
if (group_name_input_container.isErrorEnabled && !text.isNullOrBlank()) {
group_name_input_container.error = null
}
})
}

confirm_button.setOnClickListener { handlePositiveButton() }

Expand Down Expand Up @@ -242,15 +239,11 @@ class FeedGroupDialog : DialogFragment(), BackPressable {
}
}

toolbar_search_edit_text.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) = Unit
override fun afterTextChanged(s: Editable) = Unit
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
val newQuery: String = toolbar_search_edit_text.text.toString()
subscriptionsCurrentSearchQuery = newQuery
viewModel.filterSubscriptionsBy(newQuery)
}
})
toolbar_search_edit_text.doOnTextChanged { _, _, _, _ ->
val newQuery: String = toolbar_search_edit_text.text.toString()
subscriptionsCurrentSearchQuery = newQuery
viewModel.filterSubscriptionsBy(newQuery)
}

subscriptionGroupAdapter.setOnItemClickListener(subscriptionPickerItemListener)
}
Expand Down Expand Up @@ -414,21 +407,14 @@ class FeedGroupDialog : DialogFragment(), BackPressable {
else -> android.R.string.ok
})

delete_button.visibility = when {
currentScreen != InitialScreen -> View.GONE
groupId == NO_GROUP_SELECTED -> View.GONE
else -> View.VISIBLE
}
delete_button.isGone = currentScreen != InitialScreen || groupId == NO_GROUP_SELECTED

hideKeyboard()
hideSearch()
}

private fun View.onlyVisibleIn(vararg screens: ScreenState) {
visibility = when (currentScreen) {
in screens -> View.VISIBLE
else -> View.GONE
}
isVisible = currentScreen in screens
}

/*/​//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -501,11 +487,7 @@ class FeedGroupDialog : DialogFragment(), BackPressable {

fun newInstance(groupId: Long = NO_GROUP_SELECTED): FeedGroupDialog {
val dialog = FeedGroupDialog()

dialog.arguments = Bundle().apply {
putLong(KEY_GROUP_ID, groupId)
}

dialog.arguments = bundleOf(KEY_GROUP_ID to groupId)
return dialog
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.schabi.newpipe.local.subscription.item

import android.view.View.GONE
import android.view.View.OnClickListener
import android.view.View.VISIBLE
import androidx.annotation.DrawableRes
import androidx.core.view.isVisible
import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder
import com.xwray.groupie.kotlinandroidextensions.Item
import kotlinx.android.synthetic.main.header_with_menu_item.header_menu_item
Expand Down Expand Up @@ -47,6 +46,6 @@ class HeaderWithMenuItem(
}

private fun updateMenuItemVisibility(viewHolder: GroupieViewHolder) {
viewHolder.header_menu_item.visibility = if (showMenuItem) VISIBLE else GONE
viewHolder.header_menu_item.isVisible = showMenuItem
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.schabi.newpipe.local.subscription.item

import android.view.View
import androidx.core.view.isVisible
import com.nostra13.universalimageloader.core.ImageLoader
import com.xwray.groupie.kotlinandroidextensions.GroupieViewHolder
import com.xwray.groupie.kotlinandroidextensions.Item
Expand All @@ -25,7 +26,7 @@ data class PickerSubscriptionItem(
viewHolder.thumbnail_view, ImageDisplayConstants.DISPLAY_AVATAR_OPTIONS)

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) {
Expand Down

0 comments on commit a73baf3

Please sign in to comment.