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

mostly just code cleanup and library updates #28

Merged
merged 22 commits into from Dec 18, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions smash-ranks-android/app/build.gradle
Expand Up @@ -25,13 +25,13 @@ repositories {

android {
compileSdkVersion 27
buildToolsVersion '27.0.1'
buildToolsVersion "27.0.2"

defaultConfig {
minSdkVersion 17
targetSdkVersion 27
versionCode 10303
versionName '1.3.3'
versionCode 10304
versionName "1.3.4"
}

buildTypes {
Expand Down Expand Up @@ -92,7 +92,7 @@ dependencies {
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"

// Fabric
implementation("com.crashlytics.sdk.android:crashlytics:2.7.1@aar") {
implementation("com.crashlytics.sdk.android:crashlytics:2.8.0@aar") {
transitive = true
}
}
Expand Up @@ -19,7 +19,7 @@ import com.garpr.android.models.*
import com.garpr.android.networking.ApiCall
import com.garpr.android.networking.ApiListener
import com.garpr.android.networking.ServerApi
import com.garpr.android.views.ErrorLinearLayout
import com.garpr.android.views.ErrorContentLinearLayout
import kotterknife.bindView
import javax.inject.Inject

Expand All @@ -44,10 +44,10 @@ class HeadToHeadActivity : BaseActivity(), ApiListener<HeadToHead>,
@Inject
protected lateinit var mThreadUtils: ThreadUtils

private val mError: ErrorLinearLayout by bindView(R.id.error)
private val mError: ErrorContentLinearLayout by bindView(R.id.error)
private val mRecyclerView: RecyclerView by bindView(R.id.recyclerView)
private val mRefreshLayout: SwipeRefreshLayout by bindView(R.id.refreshLayout)
private val mEmpty : View by bindView(R.id.empty)
private val mEmpty: View by bindView(R.id.empty)


companion object {
Expand Down
Expand Up @@ -18,7 +18,7 @@ import com.garpr.android.models.*
import com.garpr.android.networking.ApiCall
import com.garpr.android.networking.ApiListener
import com.garpr.android.networking.ServerApi
import com.garpr.android.views.ErrorLinearLayout
import com.garpr.android.views.ErrorContentLinearLayout
import com.garpr.android.views.MatchItemView
import com.garpr.android.views.TournamentDividerView
import com.garpr.android.views.toolbars.PlayerToolbar
Expand Down Expand Up @@ -55,7 +55,7 @@ class PlayerActivity : BaseActivity(), ApiListener<PlayerMatchesBundle>,
@Inject
protected lateinit var mThreadUtils: ThreadUtils

private val mError: ErrorLinearLayout by bindView(R.id.error)
private val mError: ErrorContentLinearLayout by bindView(R.id.error)
private val mPlayerToolbar: PlayerToolbar by bindView(R.id.toolbar)
private val mRecyclerView: RecyclerView by bindView(R.id.recyclerView)
private val mRefreshLayout: SwipeRefreshLayout by bindView(R.id.refreshLayout)
Expand Down Expand Up @@ -153,23 +153,22 @@ class PlayerActivity : BaseActivity(), ApiListener<PlayerMatchesBundle>,

override fun onClick(v: MatchItemView) {
val fullPlayer = mPlayerMatchesBundle?.fullPlayer ?: return
val content = v.mContent ?: return
startActivity(HeadToHeadActivity.getLaunchIntent(this, fullPlayer, content,
val match = v.match ?: return
startActivity(HeadToHeadActivity.getLaunchIntent(this, fullPlayer, match,
mRegionManager.getRegion(this)))
}

override fun onClick(v: TournamentDividerView) {
val content = v.mContent ?: return
startActivity(TournamentActivity.getLaunchIntent(this, content.id, content.name,
content.date, mRegionManager.getRegion(this)))
val tournament = v.tournament ?: return
startActivity(TournamentActivity.getLaunchIntent(this, tournament.id,
tournament.name, tournament.date, mRegionManager.getRegion(this)))
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
App.get().appComponent.inject(this)
setContentView(R.layout.activity_player)

val intent = intent
mPlayerId = intent.getStringExtra(EXTRA_PLAYER_ID)

setTitle()
Expand Down
Expand Up @@ -76,8 +76,7 @@ class SetRegionActivity : BaseActivity(), ApiListener<RegionsBundle>,
AlertDialog.Builder(this)
.setMessage(R.string.youve_selected_a_region_but_havent_saved)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.yes) { dialog, which ->
super@SetRegionActivity.navigateUp() }
.setPositiveButton(R.string.yes) { dialog, which -> super.navigateUp() }
.show()
}

Expand All @@ -96,7 +95,7 @@ class SetRegionActivity : BaseActivity(), ApiListener<RegionsBundle>,
}

override fun onClick(v: RegionSelectionItemView) {
val region = v.mContent
val region = v.region

mSelectedRegion = if (region == mRegionManager.getRegion()) null else region

Expand Down
Expand Up @@ -21,7 +21,7 @@ import com.garpr.android.models.*
import com.garpr.android.networking.ApiCall
import com.garpr.android.networking.ApiListener
import com.garpr.android.networking.ServerApi
import com.garpr.android.views.ErrorLinearLayout
import com.garpr.android.views.ErrorContentLinearLayout
import com.garpr.android.views.toolbars.SearchToolbar
import com.garpr.android.views.toolbars.TournamentToolbar
import kotterknife.bindView
Expand All @@ -44,7 +44,7 @@ class TournamentActivity : BaseActivity(), ApiListener<FullTournament>, Searchab
@Inject
protected lateinit var mShareUtils: ShareUtils

private val mError: ErrorLinearLayout by bindView(R.id.error)
private val mError: ErrorContentLinearLayout by bindView(R.id.error)
private val mRefreshLayout: SwipeRefreshLayout by bindView(R.id.refreshLayout)
private val mTabLayout: TabLayout by bindView(R.id.tabLayout)
private val mTournamentToolbar: TournamentToolbar by bindView(R.id.toolbar)
Expand Down
Expand Up @@ -86,8 +86,8 @@ public abstract class BaseAppModule {
private static final String SMASH_ROSTER_KEY_VALUE_STORE = "SMASH_ROSTER_KEY_VALUE_STORE";
private static final String SMASH_ROSTER_RETROFIT = "SMASH_ROSTER_RETROFIT";

private final Application mApplication;
private final Region mDefaultRegion;
@NonNull private final Application mApplication;
@NonNull private final Region mDefaultRegion;


public BaseAppModule(@NonNull final Application application,
Expand Down
Expand Up @@ -4,7 +4,7 @@ import java.lang.ref.WeakReference

class ApiCall<in T>(listener: ApiListener<T>) : ApiListener<T> {

private val mReference: WeakReference<ApiListener<T>> = WeakReference(listener)
private val mReference = WeakReference<ApiListener<T>>(listener)


override fun failure(errorCode: Int) {
Expand Down
Expand Up @@ -44,7 +44,7 @@ class PlayerMatchesBundleApiCall(

fullPlayer?.let {
listener.success(PlayerMatchesBundle(it, matchesBundle))
} ?: listener.failure(Constants.ERROR_CODE_UNKNOWN)
} ?: listener.failure()
}

private val fullPlayerListener = object : ApiListener<FullPlayer> {
Expand Down
@@ -1,6 +1,5 @@
package com.garpr.android.networking

import com.garpr.android.misc.Constants
import com.garpr.android.misc.Heartbeat
import com.garpr.android.models.AbsRegion
import com.garpr.android.models.Endpoint
Expand Down Expand Up @@ -44,7 +43,7 @@ class RegionsBundleApiCall(
}

if (regionsSet.isEmpty()) {
listener.failure(Constants.ERROR_CODE_UNKNOWN)
listener.failure()
return
}

Expand Down
Expand Up @@ -13,11 +13,11 @@ class PersistentBooleanPreference(
) {

override fun get(): Boolean? {
if (hasValueInStore) {
return if (hasValueInStore) {
// at this point, returning the fallback value is impossible
return keyValueStore.getBoolean(key, false)
keyValueStore.getBoolean(key, false)
} else {
return defaultValue
defaultValue
}
}

Expand Down
Expand Up @@ -13,11 +13,11 @@ class PersistentFloatPreference(
) {

override fun get(): Float? {
if (hasValueInStore) {
return if (hasValueInStore) {
// at this point, returning the fallback value is impossible
return keyValueStore.getFloat(key, 0f)
keyValueStore.getFloat(key, 0f)
} else {
return defaultValue
defaultValue
}
}

Expand Down
Expand Up @@ -23,10 +23,10 @@ class PersistentGsonPreference<T>(
get() = backingPreference.exists || defaultValue != null

override fun get(): T? {
if (backingPreference.exists) {
return gson.fromJson<T>(backingPreference.get(), type)
return if (backingPreference.exists) {
gson.fromJson<T>(backingPreference.get(), type)
} else {
return defaultValue
defaultValue
}
}

Expand Down
Expand Up @@ -13,11 +13,11 @@ class PersistentIntegerPreference(
) {

override fun get(): Int? {
if (hasValueInStore) {
return if (hasValueInStore) {
// at this point, returning the fallback value is impossible
return keyValueStore.getInteger(key, 0)
keyValueStore.getInteger(key, 0)
} else {
return defaultValue
defaultValue
}
}

Expand Down
Expand Up @@ -13,11 +13,11 @@ class PersistentLongPreference(
) {

override fun get(): Long? {
if (hasValueInStore) {
return if (hasValueInStore) {
// at this point, returning the fallback value is impossible
return keyValueStore.getLong(key, 0L)
keyValueStore.getLong(key, 0L)
} else {
return defaultValue
defaultValue
}
}

Expand Down
Expand Up @@ -13,11 +13,11 @@ class PersistentStringPreference(
) {

override fun get(): String? {
if (hasValueInStore) {
return if (hasValueInStore) {
// at this point, returning the fallback value is impossible
return keyValueStore.getString(key, null)
keyValueStore.getString(key, null)
} else {
return defaultValue
defaultValue
}
}

Expand Down
Expand Up @@ -15,16 +15,15 @@ class PersistentUriPreference(

private val backingPreference = PersistentStringPreference(key, null, keyValueStore)


override val exists: Boolean
get() = backingPreference.exists || defaultValue != null

override fun get(): Uri? {
val string = backingPreference.get()

if (string == null) {
return defaultValue
return if (backingPreference.exists) {
Uri.parse(backingPreference.get())
} else {
return Uri.parse(string)
defaultValue
}
}

Expand Down
Expand Up @@ -6,18 +6,12 @@ import android.os.Build
import android.support.annotation.AttrRes
import android.support.annotation.StyleRes
import android.util.AttributeSet
import android.widget.LinearLayout
import android.widget.TextView
import com.garpr.android.R
import com.garpr.android.misc.Constants
import kotterknife.bindView

class ErrorLinearLayout : LinearLayout {
class ErrorContentLinearLayout : NoContentLinearLayout {

private var mOriginalLine2: CharSequence? = null

private val mLine1: TextView by bindView(R.id.recyclerViewLine1)
private val mLine2: TextView by bindView(R.id.recyclerViewLine2)
private var mOriginalLine2Text: CharSequence? = null


constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
Expand All @@ -31,7 +25,8 @@ class ErrorLinearLayout : LinearLayout {

override fun onFinishInflate() {
super.onFinishInflate()
mOriginalLine2 = mLine2.text

mOriginalLine2Text = mLine2.text
}

fun setVisibility(visibility: Int, errorCode: Int) {
Expand All @@ -40,7 +35,7 @@ class ErrorLinearLayout : LinearLayout {
if (errorCode == Constants.ERROR_CODE_BAD_REQUEST) {
mLine2.setText(R.string.region_mismatch_error)
} else {
mLine2.text = mOriginalLine2
mLine2.text = mOriginalLine2Text
}
}

Expand Down
Expand Up @@ -25,14 +25,13 @@ import javax.inject.Inject
class MatchItemView : IdentityFrameLayout, BaseAdapterView<Match>, View.OnClickListener,
View.OnLongClickListener {

var mContent: Match? = null
private set
private var mContent: Match? = null

@Inject
lateinit protected var mFavoritePlayersManager: FavoritePlayersManager
protected lateinit var mFavoritePlayersManager: FavoritePlayersManager

@Inject
lateinit protected var mRegionManager: RegionManager
protected lateinit var mRegionManager: RegionManager

private val mName: TextView by bindView(R.id.tvName)

Expand Down Expand Up @@ -68,19 +67,18 @@ class MatchItemView : IdentityFrameLayout, BaseAdapterView<Match>, View.OnClickL
activity.onClick(this)
} else {
val opponent = content.opponent
context.startActivity(PlayerActivity.getLaunchIntent(context,
opponent.id, opponent.name, mRegionManager.getRegion(context)))
context.startActivity(PlayerActivity.getLaunchIntent(context, opponent.id,
opponent.name, mRegionManager.getRegion(context)))
}
}

override fun onFinishInflate() {
super.onFinishInflate()

if (isInEditMode) {
return
if (!isInEditMode) {
App.get().appComponent.inject(this)
}

App.get().appComponent.inject(this)
setOnClickListener(this)
setOnLongClickListener(this)
}
Expand All @@ -91,6 +89,9 @@ class MatchItemView : IdentityFrameLayout, BaseAdapterView<Match>, View.OnClickL
mRegionManager.getRegion(context))
}

val match: Match?
get() = mContent

override fun setContent(content: Match) {
mContent = content
mIdentity = content.opponent
Expand Down