Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.2.6 #86

Merged
merged 6 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions smash-ranks-android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 29
versionCode 22005
versionName "2.2.5"
versionCode 22006
versionName "2.2.6"

// needed for androidTest
testInstrumentationRunner "com.garpr.android.test.AndroidTestRunner"
Expand Down Expand Up @@ -111,6 +111,10 @@ dependencies {
kapt "androidx.room:room-compiler:$room_version"
androidTestImplementation "androidx.room:room-testing:$room_version"

// AndroidX SwipeRefreshLayout
// https://developer.android.com/jetpack/androidx/releases/swiperefreshlayout
implementation "androidx.swiperefreshlayout:swiperefreshlayout:$swipe_refresh_layout_version"

// AndroidX Test
// https://developer.android.com/jetpack/androidx/releases/test
androidTestImplementation "androidx.arch.core:core-testing:$architecture_test_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Optional<T : Any> private constructor(
) {

fun get(): T {
return checkNotNull(item)
return item ?: throw NoSuchElementException()
}

fun isPresent(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class RefreshLayout @JvmOverloads constructor(
attrs: AttributeSet? = null
) : SwipeRefreshLayout(context, attrs), Heartbeat, ListLayout {

override val isAlive: Boolean
get() = ViewCompat.isAttachedToWindow(this)

@IdRes
private val scrollingChildId: Int

Expand All @@ -43,9 +46,6 @@ class RefreshLayout @JvmOverloads constructor(
return scrollingChild as? RecyclerView?
}

override val isAlive: Boolean
get() = ViewCompat.isAttachedToWindow(this)

override fun onFinishInflate() {
super.onFinishInflate()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.garpr.android.features.common.views

import android.content.Context
import android.text.Editable
import android.text.TextWatcher
import android.util.AttributeSet
import android.view.View
import android.view.View.OnClickListener
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
Expand All @@ -26,12 +26,12 @@ open class SearchToolbar @JvmOverloads constructor(
) : GarToolbar(context, attrs), SearchQueryHandle {

val isSearchFieldExpanded: Boolean
get() = searchField.visibility == View.VISIBLE
get() = searchField.visibility == VISIBLE

var showSearchIcon: Boolean
get() = searchIcon.visibility == View.VISIBLE
get() = searchIcon.visibility == VISIBLE
set(value) {
searchIcon.visibility = if (!searchField.isFocused && value) View.VISIBLE else View.GONE
searchIcon.visibility = if (!searchField.isFocused && value) VISIBLE else GONE
}

private val wasShowingUpNavigation = showUpNavigation
Expand All @@ -43,18 +43,20 @@ open class SearchToolbar @JvmOverloads constructor(
openSearchField()
}

var searchableListener: Searchable? = null

private val searchFieldActionListener = TextView.OnEditorActionListener { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
(activity as? Searchable?)?.search(searchQuery?.toString())
searchableListener?.search(searchQuery?.toString())
activity?.hideKeyboard()
}

false
}

private val searchFieldTextWatcher = object : AbstractTextWatcher() {
private val searchFieldTextWatcher: TextWatcher = object : AbstractTextWatcher() {
override fun afterTextChanged(s: Editable?) {
(activity as? Searchable?)?.search(searchQuery?.toString())
searchableListener?.search(searchQuery?.toString())
}
}

Expand Down Expand Up @@ -83,11 +85,11 @@ open class SearchToolbar @JvmOverloads constructor(
protected open fun onCloseSearchField() {
activity?.hideKeyboard()
searchField.clear()
searchField.visibility = View.GONE
searchField.visibility = GONE
showUpNavigation = wasShowingUpNavigation

menuExpansionContainer.layoutParams = (menuExpansionContainer.layoutParams as LayoutParams).apply {
startToEnd = View.NO_ID
startToEnd = NO_ID
width = ViewGroup.LayoutParams.WRAP_CONTENT
}

Expand All @@ -104,7 +106,7 @@ open class SearchToolbar @JvmOverloads constructor(
width = LayoutParams.MATCH_CONSTRAINT
}

searchField.visibility = View.VISIBLE
searchField.visibility = VISIBLE
searchField.requestFocusAndOpenKeyboard()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,6 @@ class HomeActivity : BaseActivity(), BottomNavigationView.OnNavigationItemResele
}
}

companion object {
const val TAG = "HomeActivity"
private val CNAME = HomeActivity::class.java.canonicalName
private val EXTRA_INITIAL_POSITION = "$CNAME.InitialPosition"
private const val KEY_CURRENT_POSITION = "CurrentPosition"

fun getLaunchIntent(context: Context, initialPosition: HomeTab? = null,
restartActivityTask: Boolean = false): Intent {
var intent = Intent(context, HomeActivity::class.java)

if (restartActivityTask) {
intent = Intent.makeRestartActivityTask(intent.component)
}

return intent.putOptionalExtra(EXTRA_INITIAL_POSITION, initialPosition)
}
}

private fun initListeners() {
homeViewModel.stateLiveData.observe(this, Observer {
refreshState(it)
Expand Down Expand Up @@ -143,6 +125,7 @@ class HomeActivity : BaseActivity(), BottomNavigationView.OnNavigationItemResele
override fun onViewsBound() {
super.onViewsBound()

toolbar.searchableListener = this
toolbar.listeners = this

bottomNavigationView.setOnNavigationItemReselectedListener(this)
Expand Down Expand Up @@ -203,4 +186,22 @@ class HomeActivity : BaseActivity(), BottomNavigationView.OnNavigationItemResele
bottomNavigationView.menu.findItem(itemId).isChecked = true
}

companion object {
const val TAG = "HomeActivity"
private val CNAME = HomeActivity::class.java.canonicalName
private val EXTRA_INITIAL_POSITION = "$CNAME.InitialPosition"
private const val KEY_CURRENT_POSITION = "CurrentPosition"

fun getLaunchIntent(context: Context, initialPosition: HomeTab? = null,
restartActivityTask: Boolean = false): Intent {
var intent = Intent(context, HomeActivity::class.java)

if (restartActivityTask) {
intent = Intent.makeRestartActivityTask(intent.component)
}

return intent.putOptionalExtra(EXTRA_INITIAL_POSITION, initialPosition)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ enum class HomeTab : Parcelable {
TOURNAMENTS,
FAVORITE_PLAYERS;

companion object {
@JvmField
val CREATOR = createParcel { values()[it.readInt()] }
}

override fun describeContents(): Int = 0

override fun writeToParcel(dest: Parcel, flags: Int) {
dest.writeInt(ordinal)
}

companion object {
@JvmField
val CREATOR = createParcel { values()[it.readInt()] }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.garpr.android.features.home
import android.content.Context
import android.util.AttributeSet
import android.view.MenuItem
import android.view.View
import androidx.appcompat.widget.PopupMenu
import com.garpr.android.R
import com.garpr.android.extensions.addMenuItem
Expand Down Expand Up @@ -72,12 +71,12 @@ class HomeToolbar @JvmOverloads constructor(

override fun onCloseSearchField() {
super.onCloseSearchField()
overflowButton.visibility = View.VISIBLE
overflowButton.visibility = VISIBLE
}

override fun onOpenSearchField() {
super.onOpenSearchField()
overflowButton.visibility = View.GONE
overflowButton.visibility = GONE
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,6 @@ class PlayerActivity : BaseActivity(), ColorListener, MatchItemView.Listeners,
protected val regionHandleUtils: RegionHandleUtils by inject()
protected val shareUtils: ShareUtils by inject()

companion object {
private const val TAG = "PlayerActivity"
private val CNAME = PlayerActivity::class.java.canonicalName
private val EXTRA_PLAYER_ID = "$CNAME.PlayerId"

fun getLaunchIntent(context: Context, player: AbsPlayer, region: Region? = null): Intent {
var regionCopy = region

if (player is FavoritePlayer) {
regionCopy = player.region
}

return getLaunchIntent(context, player.id, regionCopy)
}

fun getLaunchIntent(context: Context, playerId: String, region: Region? = null): Intent {
return Intent(context, PlayerActivity::class.java)
.putExtra(EXTRA_PLAYER_ID, playerId)
.putOptionalExtra(EXTRA_REGION, region)
}
}

override val activityName = TAG

private fun checkNameAndRegionViewScrollStates() {
Expand Down Expand Up @@ -186,6 +164,8 @@ class PlayerActivity : BaseActivity(), ColorListener, MatchItemView.Listeners,
override fun onViewsBound() {
super.onViewsBound()

toolbar.searchableListener = this

refreshLayout.setOnRefreshListener(this)
recyclerView.setHasFixedSize(true)
recyclerView.addOnScrollListener(onScrollListener)
Expand Down Expand Up @@ -225,6 +205,28 @@ class PlayerActivity : BaseActivity(), ColorListener, MatchItemView.Listeners,
viewModel.search(query)
}

companion object {
private const val TAG = "PlayerActivity"
private val CNAME = PlayerActivity::class.java.canonicalName
private val EXTRA_PLAYER_ID = "$CNAME.PlayerId"

fun getLaunchIntent(context: Context, player: AbsPlayer, region: Region? = null): Intent {
var regionCopy = region

if (player is FavoritePlayer) {
regionCopy = player.region
}

return getLaunchIntent(context, player.id, regionCopy)
}

fun getLaunchIntent(context: Context, playerId: String, region: Region? = null): Intent {
return Intent(context, PlayerActivity::class.java)
.putExtra(EXTRA_PLAYER_ID, playerId)
.putOptionalExtra(EXTRA_REGION, region)
}
}

private class Adapter(
private val matchItemViewListeners: MatchItemView.Listeners,
private val playerProfileItemViewListeners: PlayerProfileItemView.Listeners,
Expand All @@ -237,13 +239,6 @@ class PlayerActivity : BaseActivity(), ColorListener, MatchItemView.Listeners,
private val list = mutableListOf<ListItem>()
private var smashCompetitor: SmashCompetitor? = null

companion object {
private const val VIEW_TYPE_MATCH = 0
private const val VIEW_TYPE_NO_MATCHES = 1
private const val VIEW_TYPE_PLAYER = 2
private const val VIEW_TYPE_TOURNAMENT = 3
}

init {
setHasStableIds(true)
}
Expand Down Expand Up @@ -330,6 +325,13 @@ class PlayerActivity : BaseActivity(), ColorListener, MatchItemView.Listeners,
notifyDataSetChanged()
}

companion object {
private const val VIEW_TYPE_MATCH = 0
private const val VIEW_TYPE_NO_MATCHES = 1
private const val VIEW_TYPE_PLAYER = 2
private const val VIEW_TYPE_TOURNAMENT = 3
}

}

private class MatchViewHolder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@ class PlayersActivity : BaseActivity(), PlayerItemView.Listeners, Refreshable, S

protected val regionHandleUtils: RegionHandleUtils by inject()

companion object {
private const val TAG = "PlayersActivity"

fun getLaunchIntent(context: Context, region: Region? = null): Intent {
return Intent(context, PlayersActivity::class.java)
.putOptionalExtra(EXTRA_REGION, region)
}
}

override val activityName = TAG

private fun fetchPlayers() {
Expand Down Expand Up @@ -93,6 +84,7 @@ class PlayersActivity : BaseActivity(), PlayerItemView.Listeners, Refreshable, S
super.onViewsBound()

toolbar.subtitleText = regionHandleUtils.getRegion(this).displayName
toolbar.searchableListener = this

refreshLayout.setOnRefreshListener(this)
recyclerView.setHasFixedSize(true)
Expand Down Expand Up @@ -135,18 +127,21 @@ class PlayersActivity : BaseActivity(), PlayerItemView.Listeners, Refreshable, S
viewModel.search(query)
}

companion object {
private const val TAG = "PlayersActivity"

fun getLaunchIntent(context: Context, region: Region? = null): Intent {
return Intent(context, PlayersActivity::class.java)
.putOptionalExtra(EXTRA_REGION, region)
}
}

private class Adapter(
private val playerItemViewListeners: PlayerItemView.Listeners
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {

private val list = mutableListOf<PlayerListItem>()

companion object {
private const val VIEW_TYPE_DIVIDER = 0
private const val VIEW_TYPE_NO_RESULTS = 1
private const val VIEW_TYPE_PLAYER = 2
}

init {
setHasStableIds(true)
}
Expand Down Expand Up @@ -223,6 +218,12 @@ class PlayersActivity : BaseActivity(), PlayerItemView.Listeners, Refreshable, S
notifyDataSetChanged()
}

companion object {
private const val VIEW_TYPE_DIVIDER = 0
private const val VIEW_TYPE_NO_RESULTS = 1
private const val VIEW_TYPE_PLAYER = 2
}

}

private class DividerViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
Expand Down
Loading