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
// ... | |
fun getSubscribersCount(blogUrl: String) = liveData(Dispatchers.IO) { | |
try { | |
emit(Resource.success(data = repository.getSubscribersCount(blogUrl))) | |
} catch (exception: Exception) { | |
emit(Resource.error(data = null, message = exception.message ?: "Error!!!")) | |
} | |
} | |
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 PostsAdapter( | |
private val posts: List<PostAdapterModel>, | |
private val viewLifecycleOwner: LifecycleOwner, | |
private val viewModel: PostsViewModel, | |
private val clickListener: OnPostClickListener | |
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { | |
val inflater = LayoutInflater.from(parent.context) | |
// Deciding whether to inflate the header view or the item view based on the #viewType |
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 fetchPosts() { | |
// Verify if Internet is present | |
if (!isNetworkAvailable(requireContext())) { | |
hideLoadingAnimation() | |
showErrorView(R.string.no_internet) | |
return | |
} | |
mViewModel.getPosts() |
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 JetFilesApplication : Application() { | |
// AppContainer instance used by the rest of classes to obtain dependencies. | |
lateinit var container: AppContainer | |
override fun onCreate() { | |
super.onCreate() | |
container = AppContainerImpl() | |
} | |
} |
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
data class ErrorMessage(val id: Long, @StringRes val messageId: Int) |
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
fun Long.formattedDate(): String { | |
val sdf = SimpleDateFormat("dd MMM, yyyy HH:mm", Locale.getDefault()) | |
return sdf.format(this) | |
} |
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 : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
if (hasPermissions()) { | |
renderComposeView() | |
} else { | |
requestPermission() | |
} | |
} |
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
@Composable | |
fun JetFilesApp( | |
appContainer: AppContainer | |
) { | |
JetFilesTheme { | |
ProvideWindowInsets { | |
// Drawing content behind the system windows. Just a UX thing! | |
val systemUiController = rememberSystemUiController() | |
SideEffect { | |
systemUiController.setSystemBarsColor(Color.Transparent, darkIcons = true) |
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
@Composable | |
fun StarButton( | |
isFavorite: Boolean, | |
onClick: () -> Unit, | |
modifier: Modifier = Modifier | |
) { | |
val clickLabel = stringResource(if (isFavorite) R.string.unstar else R.string.star) | |
IconToggleButton( | |
checked = isFavorite, |
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
object DialogUtils { | |
fun showAlertDialog( | |
context: Context, | |
@StringRes title: Int, | |
@StringRes message: Int, | |
@StringRes buttonText: Int, | |
action: () -> Unit | |
) { | |
val resources = context.resources |
NewerOlder