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 MainActivity : BaseActivity() { | |
/* | |
... | |
*/ | |
override fun onBackPressed() { | |
when (NavHostFragment.findNavController(container_fragment).currentDestination?.id) { | |
R.id.coinsFragment -> { | |
val builder = AlertDialog.Builder(this@MainActivity) |
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 CatalogueViewModel : ViewModel() { | |
// KÖTÜ: Erişilebilir MutableLiveData | |
val products = MutableLiveData<Products>() | |
// İYİ: Getter ile Encapsulate edilmiş MutableLiveData | |
private val promotions = MutableLiveData<Promotions>() | |
fun getPromotions(): LiveData<Promotions> = promotions |
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 fun init() { | |
super.init() | |
// Delete previous episodes. | |
doAsync { | |
viewModel.db?.episodesDao()?.deleteAllEpisodes() | |
} | |
if (!isStateSaved) | |
getData() |
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 Resource<T> constructor(val status: Status, val data: T?, val error: Throwable? = null) { | |
companion object { | |
fun <T> success(@NonNull data: T): Resource<T> { | |
return Resource(Status.SUCCESS, data) | |
} | |
fun <T> error(throwable: Throwable): Resource<T> { | |
return Resource(status = Status.ERROR, data = null, error = throwable) |
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 initBestPodcasts() { | |
viewModel.getBestPodcasts(viewModel.currentLocation, 0) | |
viewModel.bestPodcastsLiveData.observe( | |
viewLifecycleOwner, | |
Observer<Resource<BestPodcasts>> { | |
showTitles() | |
(mBinding.recyclerViewBestPodcasts.adapter as? BestPodcastsAdapter)?.submitList(it.data?.podcasts) | |
} |
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 HomeViewModel @Inject constructor(api: PodpocketAPI, appDatabase: AppDatabase) : BaseViewModel(api, appDatabase) { | |
private val _bestPodcastsLiveData = MutableLiveData<Resource<BestPodcasts>>() | |
val bestPodcastsLiveData: LiveData<Resource<BestPodcasts>> get() = _bestPodcastsLiveData | |
fun getBestPodcasts(region: String, explicitContent: Int) { | |
baseApi?.let { baseApi -> | |
baseApi.getBestPodcasts(region, explicitContent) | |
.subscribeOn(Schedulers.io()) | |
.map { Resource.success(it) } |
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
public void doSomething() { | |
System.out.print("doSomething start"); | |
System.out.print("doSomethingElse"); | |
} |
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
System.out.println("before"); | |
System.out.println("do something here"); | |
System.out.println("after"); |