Skip to content

Instantly share code, notes, and snippets.

View demonar's full-sized avatar
😄
(¯`•._.•«<ÐêMøN>»•._.•´¯) -> Building mobile apps with Kotlin and Swift

Alejandro Moya demonar

😄
(¯`•._.•«<ÐêMøN>»•._.•´¯) -> Building mobile apps with Kotlin and Swift
View GitHub Profile
@demonar
demonar / delete-orphan-branches.sh
Created August 22, 2023 15:56
This script deletes branches that doesn't exist on the remote
cd $1
declare -a BRANCHES=(`git for-each-ref --format='%(refname:short)' refs/heads/`)
CURRENT=(`git rev-parse --abbrev-ref HEAD`)
for BRANCH in "${BRANCHES[@]}"
do
EXISTS=(`git ls-remote --heads origin refs/heads/"$BRANCH" | wc -l`)
if [ "$CURRENT" != "$BRANCH" ] && [ "$EXISTS" = 0 ]
then
git branch -D "$BRANCH"
fi
@demonar
demonar / pull-all-branches.sh
Last active August 22, 2023 15:57
This script updates all the branches, like running pull on every local branch
#!/bin/bash
cd $1
declare -a BRANCHES=(`git for-each-ref --format='%(refname:short)' refs/heads/`)
CURRENT=(`git rev-parse --abbrev-ref HEAD`)
for BRANCH in "${BRANCHES[@]}"
do
if [ "$CURRENT" = "$BRANCH" ]
then
git pull
else
#Gradle
org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx2048M"
org.gradle.java.installations.fromEnv=JDK_17
org.gradle.configureondemand=true
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.workers.max=8
java.mainToolchainVersion=17
java.modularToolchainVersion=17
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
versionCatalogs {
create("commonlibs") {
from(files("./catalogs/common.versions.toml"))
}
}
[versions]
library-group = "com.my.library"
library-version = "0.0.1"
android = "8.0.2"
kotlin = "1.8.20"
kover = "0.6.1"
ksp = "1.8.20-1.0.11"
[libraries]
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib-common", version.ref = "kotlin" }
class DemoApp : Application() {
override fun onCreate() {
super.onCreate()
startKoin {
androidContext(this@DemoApp)
modules(searchViewActivityModule)
}
val searchViewActivityModule = module {
viewModel { SearchViewModel() }
factory { DataSource() }
factory { (elements: ArrayList<DesiredObject>) -> SearchRecyclerViewAdapter(elements) }
}
class SearchRecyclerViewAdapter(var elements: ArrayList<DesiredObject>):
RecyclerView.Adapter<SearchRecyclerViewAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val layout = LayoutInflater.from(parent.context)
.inflate(R.layout.list_item, parent, false)
return ViewHolder(layout)
}
override fun getItemCount(): Int {
data class DesiredObject(var text: String)
class DataSource() {
var elements: MutableArrayList<DesiredObject>
}
class SearchViewModel(): ViewModel(), KoinComponent {
val datasource: DataSource by inject()
val adapter: SearchRecyclerViewAdapter by inject {
parametersOf(datasource.elements)
}
var searchOrder = SortOrder.ASCENDING
set(value) {