This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override suspend fun getPokemonList(offset: Int): PokemonPageResponse { | |
val listResult = api.getPokemonList(offset) | |
val uiList = listResult.results.map { item -> | |
val id = item.url.extractIdFromUrl() | |
val deferred: Deferred<PokemonDetailUI> = repoScope.async(start = CoroutineStart.LAZY) { | |
val result = api.getPokemonDetails(id) | |
PokemonDetailUI(result.sprites.frontDefault, emptyList(), PokemonType("f")) | |
} | |
PokemonUI(item.name, id, deferred) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import androidx.databinding.DataBindingUtil | |
import androidx.databinding.ViewDataBinding | |
import androidx.lifecycle.LifecycleOwner | |
import androidx.recyclerview.widget.DiffUtil | |
import androidx.recyclerview.widget.RecyclerView | |
import androidx.viewbinding.ViewBinding |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.view.View | |
import android.view.ViewGroup | |
import androidx.recyclerview.widget.RecyclerView | |
/** | |
* A generic RecyclerView Adapter that is useful for quick spin up.. | |
* This removes the need of having to define a bunch of ViewHolders or repeated Adapter classes, by delegating the work to the | |
* CustomViewAdapterConfig where you can define you View Types [CustomViewAdapterConfig.getViewType], associate your View Types to different "views" | |
* [CustomViewAdapterConfig.viewHolderCreate], and final bind or set you data to the view [CustomViewAdapterConfig.bind] via callback/closures | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Module | |
class FitAPIModule(val ctx:Context) { | |
@Provides fun provideSignInOptions() : FitnessOptions = FitnessOptions.builder() | |
.addDataType(DataType.TYPE_STEP_COUNT_DELTA, FitnessOptions.ACCESS_READ) | |
.addDataType(DataType.AGGREGATE_STEP_COUNT_DELTA, FitnessOptions.ACCESS_READ) | |
.build(); | |
@Inject @Singleton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* For more than simple apps this is sufficient, larger apps the actual data fetch would | |
* be through a repository or a usecase class | |
*/ | |
fun fetchData() { | |
val cal = Calendar.getInstance(); | |
cal.setTime(Date()); | |
val endTime = cal.getTimeInMillis (); | |
cal.add(Calendar.DATE, -14); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StepDataAdapter(var stepList : List<StepData>) : RecyclerView.Adapter<StepDataVH>() { | |
var mirrorList : List<StepData>? = null | |
override fun getItemViewType(position: Int): Int = when (position) { | |
0 -> HEADER | |
else -> DATA | |
} | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): StepDataVH { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun setupRecyclerView(steps: List<StepData>) { | |
binding.recyclerView.apply { | |
binding.progress.visibility = View.GONE | |
adapter = StepDataAdapter(steps) | |
layoutManager = LinearLayoutManager(requireContext()) | |
if (steps.isEmpty()) | |
Snackbar.make(this, R.string.nosteps, Snackbar.LENGTH_INDEFINITE).apply { | |
this.setAction(R.string.refresh){ | |
viewModel.fetchData() | |
dismiss() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context | |
import android.util.AttributeSet | |
import android.view.View | |
import android.widget.Toast | |
import androidx.annotation.NonNull | |
import androidx.lifecycle.LifecycleOwner | |
import androidx.lifecycle.observe | |
import com.google.android.material.floatingactionbutton.FloatingActionButton | |
class NetworkConnectionFab: FloatingActionButton { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context | |
import android.net.ConnectivityManager | |
import android.net.Network | |
import android.net.NetworkCapabilities | |
import android.net.NetworkRequest | |
import androidx.lifecycle.LiveData | |
object NetworkDetectorLiveData : LiveData<Boolean>() { | |
private val manager: ConnectivityManager by lazy { | |
ManagementApp.instance.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.support.v4.widget.SwipeRefreshLayout; | |
import android.util.AttributeSet; | |
import your.R; | |
/** | |
* Created by Bobby Hargett | |
*/ | |
public class SaneSwipeRefreshLayout extends SwipeRefreshLayout { |
NewerOlder