Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from Kodein to Koin #1112

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package xyz.nulldev.ts.config

import org.koin.core.module.Module
import org.koin.dsl.module

fun configManagerModule(): Module =
module {
single<ConfigManager> { GlobalConfigManager }
}
6 changes: 3 additions & 3 deletions AndroidCompat/src/main/java/android/app/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import android.util.Log;
import kotlin.NotImplementedError;
import xyz.nulldev.androidcompat.service.ServiceSupport;
import xyz.nulldev.androidcompat.util.KodeinGlobalHelper;
import xyz.nulldev.androidcompat.util.KoinGlobalHelper;

import java.io.FileDescriptor;
import java.io.PrintWriter;
Expand Down Expand Up @@ -299,7 +299,7 @@
*/
public abstract class Service extends ContextWrapper implements ComponentCallbacks2 {

private static final ServiceSupport serviceSupport = KodeinGlobalHelper.instance(ServiceSupport.class);
private static final ServiceSupport serviceSupport = KoinGlobalHelper.instance(ServiceSupport.class);

private static final String TAG = "Service";
/**
Expand Down Expand Up @@ -328,7 +328,7 @@ public abstract class Service extends ContextWrapper implements ComponentCallbac
public Service() {
//==================[THIS LINE MODIFIED FROM ANDROID SOURCE!]==================
//Service must be initialized with a base context!
super(KodeinGlobalHelper.instance(Context.class));
super(KoinGlobalHelper.instance(Context.class));
}
/** Return the application that owns this service. */
public final Application getApplication() {
Expand Down
4 changes: 2 additions & 2 deletions AndroidCompat/src/main/java/android/os/Environment.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package android.os;

import xyz.nulldev.androidcompat.io.AndroidFiles;
import xyz.nulldev.androidcompat.util.KodeinGlobalHelper;
import xyz.nulldev.androidcompat.util.KoinGlobalHelper;

import java.io.File;

/**
* Android compatibility layer for files
*/
public class Environment {
private static AndroidFiles androidFiles = KodeinGlobalHelper.instance(AndroidFiles.class);
private static AndroidFiles androidFiles = KoinGlobalHelper.instance(AndroidFiles.class);

public static String DIRECTORY_ALARMS = getHomeDirectory("Alarms").getAbsolutePath();
public static String DIRECTORY_DCIM = getHomeDirectory("DCIM").getAbsolutePath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import org.jetbrains.annotations.Nullable;
import xyz.nulldev.androidcompat.pm.PackageController;
import xyz.nulldev.androidcompat.util.KodeinGlobalHelper;
import xyz.nulldev.androidcompat.util.KoinGlobalHelper;

import java.io.File;
import java.io.IOException;
Expand All @@ -33,7 +33,7 @@
* {@link ClassLoader} implementations.
*/
public class BaseDexClassLoader extends ClassLoader {
private PackageController controller = KodeinGlobalHelper.instance(PackageController.class);
private PackageController controller = KoinGlobalHelper.instance(PackageController.class);

private final URLClassLoader realClassloader;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package xyz.nulldev.androidcompat

import android.app.Application
import org.kodein.di.DI
import org.kodein.di.conf.global
import org.kodein.di.instance
import org.koin.mp.KoinPlatformTools
import xyz.nulldev.androidcompat.androidimpl.CustomContext

class AndroidCompat {
val context: CustomContext by DI.global.instance()
val context: CustomContext by KoinPlatformTools.defaultContext().get().inject()

fun startApp(application: Application) {
application.attach(context)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package xyz.nulldev.androidcompat

import org.kodein.di.DI
import org.kodein.di.conf.global
import xyz.nulldev.androidcompat.config.ApplicationInfoConfigModule
import xyz.nulldev.androidcompat.config.FilesConfigModule
import xyz.nulldev.androidcompat.config.SystemConfigModule
Expand All @@ -12,8 +10,6 @@ import xyz.nulldev.ts.config.GlobalConfigManager
*/
class AndroidCompatInitializer {
fun init() {
DI.global.addImport(AndroidCompatModule().create())

// Register config modules
GlobalConfigManager.registerModules(
FilesConfigModule.register(GlobalConfigManager.config),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package xyz.nulldev.androidcompat

import android.content.Context
import org.kodein.di.DI
import org.kodein.di.bind
import org.kodein.di.conf.global
import org.kodein.di.instance
import org.kodein.di.singleton
import org.koin.core.module.Module
import org.koin.dsl.module
import xyz.nulldev.androidcompat.androidimpl.CustomContext
import xyz.nulldev.androidcompat.androidimpl.FakePackageManager
import xyz.nulldev.androidcompat.info.ApplicationInfoImpl
Expand All @@ -17,25 +14,19 @@ import xyz.nulldev.androidcompat.service.ServiceSupport
* AndroidCompatModule
*/

class AndroidCompatModule {
fun create() =
DI.Module("AndroidCompat") {
bind<AndroidFiles>() with singleton { AndroidFiles() }
fun androidCompatModule(): Module =
module {
single { AndroidFiles() }

bind<ApplicationInfoImpl>() with singleton { ApplicationInfoImpl() }
single { ApplicationInfoImpl(get()) }

bind<ServiceSupport>() with singleton { ServiceSupport() }
single { ServiceSupport() }

bind<FakePackageManager>() with singleton { FakePackageManager() }
single { FakePackageManager() }

bind<PackageController>() with singleton { PackageController() }
single { PackageController() }

// Context
bind<CustomContext>() with singleton { CustomContext() }
bind<Context>() with
singleton {
val context: Context by DI.global.instance<CustomContext>()
context
}
}
}
single { CustomContext() }

single<Context> { get<CustomContext>() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@
import android.view.Display;
import android.view.DisplayAdjustments;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.kodein.di.*;
import org.koin.core.Koin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import xyz.nulldev.androidcompat.info.ApplicationInfoImpl;
import xyz.nulldev.androidcompat.io.AndroidFiles;
import xyz.nulldev.androidcompat.io.sharedprefs.JavaSharedPreferences;
import xyz.nulldev.androidcompat.service.ServiceSupport;
import xyz.nulldev.androidcompat.util.KodeinGlobalHelper;
import xyz.nulldev.androidcompat.util.KoinGlobalHelper;

import java.io.*;
import java.util.HashMap;
Expand All @@ -51,26 +50,25 @@
* Custom context implementation.
*
*/
public class CustomContext extends Context implements DIAware {
private final DI kodein;
public class CustomContext extends Context {
private final Koin koin;
public CustomContext() {
this(KodeinGlobalHelper.kodein());
this(KoinGlobalHelper.koin());
}

public CustomContext(DI kodein) {
this.kodein = kodein;
public CustomContext(Koin koin) {
this.koin = koin;

//Init configs
androidFiles = KodeinGlobalHelper.instance(AndroidFiles.class, getDi());
applicationInfo = KodeinGlobalHelper.instance(ApplicationInfoImpl.class, getDi());
serviceSupport = KodeinGlobalHelper.instance(ServiceSupport.class, getDi());
fakePackageManager = KodeinGlobalHelper.instance(FakePackageManager.class, getDi());
androidFiles = KoinGlobalHelper.instance(AndroidFiles.class, getDi());
applicationInfo = KoinGlobalHelper.instance(ApplicationInfoImpl.class, getDi());
serviceSupport = KoinGlobalHelper.instance(ServiceSupport.class, getDi());
fakePackageManager = KoinGlobalHelper.instance(FakePackageManager.class, getDi());
}

@NotNull
@Override
public DI getDi() {
return kodein;
public Koin getDi() {
return koin;
}

private AndroidFiles androidFiles;
Expand Down Expand Up @@ -719,17 +717,5 @@ public boolean isDeviceProtectedStorage() {
public boolean isCredentialProtectedStorage() {
return false;
}

@NotNull
@Override
public DIContext<?> getDiContext() {
return getDi().getDiContext();
}

@Nullable
@Override
public DITrigger getDiTrigger() {
return null;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
import kotlin.NotImplementedError;
import xyz.nulldev.androidcompat.pm.InstalledPackage;
import xyz.nulldev.androidcompat.pm.PackageController;
import xyz.nulldev.androidcompat.util.KodeinGlobalHelper;
import xyz.nulldev.androidcompat.util.KoinGlobalHelper;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class FakePackageManager extends PackageManager {
private PackageController controller = KodeinGlobalHelper.instance(PackageController.class);
private PackageController controller = KoinGlobalHelper.instance(PackageController.class);

@Override
public PackageInfo getPackageInfo(String packageName, int flags) throws NameNotFoundException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package xyz.nulldev.androidcompat.info

import android.content.pm.ApplicationInfo
import org.kodein.di.DI
import org.kodein.di.DIAware
import org.kodein.di.conf.global
import org.kodein.di.instance
import xyz.nulldev.androidcompat.config.ApplicationInfoConfigModule
import xyz.nulldev.ts.config.ConfigManager

class ApplicationInfoImpl(
override val di: DI = DI.global,
) : ApplicationInfo(),
DIAware {
val configManager: ConfigManager by di.instance()

private val configManager: ConfigManager,
) : ApplicationInfo() {
val appInfoConfig: ApplicationInfoConfigModule
get() = configManager.module()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package xyz.nulldev.androidcompat.pm

import net.dongliu.apk.parser.ApkParsers
import org.kodein.di.DI
import org.kodein.di.conf.global
import org.kodein.di.instance
import org.koin.mp.KoinPlatformTools
import xyz.nulldev.androidcompat.io.AndroidFiles
import java.io.File

class PackageController {
private val androidFiles by DI.global.instance<AndroidFiles>()
private val androidFiles: AndroidFiles by KoinPlatformTools.defaultContext().get().inject()
private val uninstallListeners = mutableListOf<(String) -> Unit>()

fun registerUninstallListener(listener: (String) -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package xyz.nulldev.androidcompat.res;

import xyz.nulldev.androidcompat.info.ApplicationInfoImpl;
import xyz.nulldev.androidcompat.util.KodeinGlobalHelper;
import xyz.nulldev.androidcompat.util.KoinGlobalHelper;

import java.text.SimpleDateFormat;
import java.util.Calendar;
Expand All @@ -10,7 +10,7 @@
* BuildConfig compat class.
*/
public class BuildConfigCompat {
private static ApplicationInfoImpl applicationInfo = KodeinGlobalHelper.instance(ApplicationInfoImpl.class);
private static ApplicationInfoImpl applicationInfo = KoinGlobalHelper.instance(ApplicationInfoImpl.class);

public static final boolean DEBUG = applicationInfo.getDebug();

Expand Down

This file was deleted.

Loading
Loading