Skip to content

Instantly share code, notes, and snippets.

View MrNtlu's full-sized avatar
👨‍💻
Coding

Burak Fidan MrNtlu

👨‍💻
Coding
View GitHub Profile
@MrNtlu
MrNtlu / MainScreen.kt
Created December 11, 2022 13:29
TabRow P2
Column(
modifier = Modifier
.padding(contentPadding)
) {
TabRow(
//..
) {
tabRowItems.forEachIndexed { index, item ->
Tab(
selected = pagerState.currentPage == index,
@MrNtlu
MrNtlu / MainScreen.kt
Created December 11, 2022 13:34
TabRow P3
Column(
modifier = Modifier
.padding(contentPadding)
) {
TabRow(
//...
) {
//...
}
HorizontalPager(
@MrNtlu
MrNtlu / FAB.kt
Last active December 12, 2022 14:02
Column(
horizontalAlignment = Alignment.End,
verticalArrangement = Arrangement.Center,
) {
SmallFloatingActionButton(
onClick = { sharedViewModel.smallFabOnClick.value.invoke() },
containerColor = colors.secondaryVariant,
shape = RoundedCornerShape(12.dp),
) {
Icon(
@Composable
fun ExampleScreen(
sharedViewModel: SharedViewModel,
) {
val context = LocalContext.current
val listState = rememberLazyListState()
val expandedFabState = remember {
derivedStateOf {
listState.firstVisibleItemIndex == 0
}
var mInterstitialAd: InterstitialAd? = null
fun loadInterstitial(context: Context) {
InterstitialAd.load(
context,
"ca-app-pub-3940256099942544/1033173712", //Change this with your own AdUnitID!
AdRequest.Builder().build(),
object : InterstitialAdLoadCallback() {
override fun onAdFailedToLoad(adError: LoadAdError) {
mInterstitialAd = null
@Composable
fun PagingListScreen() {
val viewModel = hiltViewModel<NewsViewModel>()
val articles = viewModel.getBreakingNews().collectAsLazyPagingItems()
LazyColumn {
items(
items = articles,
key = { it.url }
@HiltViewModel
class NewsManuelPagingViewModel @Inject constructor(
private val repository: NewsManuelPagingRepository,
): ViewModel() {
val newsList = mutableStateListOf<Article>()
private var page by mutableStateOf(1)
var canPaginate by mutableStateOf(false)
var listState by mutableStateOf(ListState.IDLE)
LazyColumn(state = lazyColumnListState) {
items(
items = articles,
key = { it.url },
) { article ->
Text(
modifier = Modifier
.height(75.dp),
text = article.title,
)
@MrNtlu
MrNtlu / SingletonModule.kt
Created December 28, 2022 13:15
Token Auth SingletonModule
val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "data_store")
@Module
@InstallIn(SingletonComponent::class)
class SingletonModule {
@Singleton
@Provides
fun provideTokenManager(@ApplicationContext context: Context): TokenManager = TokenManager(context)
@MrNtlu
MrNtlu / LoginFragment.kt
Created December 28, 2022 14:12
Token Auth Login Fragment
@AndroidEntryPoint
class LoginFragment : Fragment() {
private val viewModel: AuthViewModel by viewModels()
private val tokenViewModel: TokenViewModel by activityViewModels()
private lateinit var navController: NavController
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?