Skip to content

Instantly share code, notes, and snippets.

View segunfrancis's full-sized avatar
💭
Coding... 💻

Segun Francis segunfrancis

💭
Coding... 💻
  • Port Harcourt, Nigeria
View GitHub Profile
@segunfrancis
segunfrancis / Grouping.kt
Created September 16, 2022 17:44
An example of using Kotlin's `groupBy` collection function
package collections
class Grouping {
companion object {
val products = listOf(
Product(10, "first_brand", "some_name", "90", "$"),
Product(11, "first_brand", "some_name", "140", "$"),
Product(12, "first_brand", "some_name", "100", "$"),
Product(13, "first_brand", "some_name", "140", "$"),
@segunfrancis
segunfrancis / web2vsweb3.csv
Created March 2, 2022 14:29
Table showing differences between web 2 and web 3
Web 2.0 Web 3.0
Wildly Read-Write Portable and Personal
Community Focus Individual Focus
Blogs / Wikis Live-streams / Waves
Sharing Content Consolidating Content
Web Applications Smart Applications
Tagging User Behaviour
Cost Per Click User Engagement
Interactive Advertising Behavioural Advertising
Wikipedia The Semantic Web
@segunfrancis
segunfrancis / HeaderItemDecoration.kt
Created March 9, 2021 17:40 — forked from filipkowicz/HeaderItemDecoration.kt
Item Decorator for sticky headers in Kotlin
package com.filipkowicz.headeritemdecorator
/*
solution based on - based on Sevastyan answer on StackOverflow
changes:
- take to account views offsets
- transformed to Kotlin
- now works on viewHolders
@segunfrancis
segunfrancis / gist:d01ff930fcc7ee5c06602bbc8197dd8d
Created October 16, 2020 13:36
Kotlin sealed class for state management
// An Example sealed class for state management
sealed class Result<out R> {
data class Success<out T>(val data: T? = null) : Result<T>()
data class Error(val error: Throwable) : Result<Nothing>()
object Loading : Result<Nothing>()
}
// To asign values to it, inside your viewmodel, you can do something like this
private val _someViewModelObject = MutableLiveData<Result<YourDataClass>>()
val someViewModelObject: LiveData<Result<YourDataClass>>
@segunfrancis
segunfrancis / ExtendedFunctionsWithFlow.kt
Last active August 15, 2020 13:04
Example functions that show how Flow can be used with almost anything in the android framewoek
package com.project.segunfrancis.chatseparator.util
import android.content.SharedPreferences
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import android.widget.EditText
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
@segunfrancis
segunfrancis / AddStoryActivity.java
Created October 12, 2019 10:25
kotlin to java refactor
package com.project.android_kidstories;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
@segunfrancis
segunfrancis / MainActivity.java
Created October 11, 2019 12:23
i fixed the errors without getting rid of most of the codes
package com.project.android_kidstories;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
package com.example.computer.codechallenge;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.http.SslError;
import android.support.constraint.Group;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
package com.example.computer.butterknifeandfragments;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
package com.example.computer.butterknifeandfragments;
import android.graphics.drawable.Drawable;
public class MyData {
private Drawable image;
private String description;
public MyData() {