Przeglądaj źródła

Merge pull request #12100 from nextcloud/refactor/convert-ActivityInjector-to-kt

Convert ActivityInjector to Kotlin
Andy Scherzinger 1 rok temu
rodzic
commit
7da69ea448

+ 0 - 73
app/src/main/java/com/nextcloud/client/di/ActivityInjector.java

@@ -1,73 +0,0 @@
-/*
- * Nextcloud Android client application
- *
- * @author Chris Narkiewicz
- * Copyright (C) 2019 Chris Narkiewicz <hello@ezaquarii.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package com.nextcloud.client.di;
-
-import android.app.Activity;
-import android.app.Application;
-import android.os.Bundle;
-import androidx.fragment.app.FragmentActivity;
-import androidx.fragment.app.FragmentManager;
-import dagger.android.AndroidInjection;
-
-public class ActivityInjector implements Application.ActivityLifecycleCallbacks {
-
-    @Override
-    public final void onActivityCreated(Activity activity, Bundle savedInstanceState) {
-        if (activity instanceof Injectable) {
-            AndroidInjection.inject(activity);
-        }
-
-        if (activity instanceof FragmentActivity) {
-            final FragmentManager fm = ((FragmentActivity) activity).getSupportFragmentManager();
-            fm.registerFragmentLifecycleCallbacks(new FragmentInjector(), true);
-        }
-    }
-
-    @Override
-    public final void onActivityStarted(Activity activity) {
-        // not needed
-    }
-
-    @Override
-    public final void onActivityResumed(Activity activity) {
-        // not needed
-    }
-
-    @Override
-    public final void onActivityPaused(Activity activity) {
-        // not needed
-    }
-
-    @Override
-    public final void onActivityStopped(Activity activity) {
-        // not needed
-    }
-
-    @Override
-    public final void onActivitySaveInstanceState(Activity activity, Bundle outState) {
-        // not needed
-    }
-
-    @Override
-    public final void onActivityDestroyed(Activity activity) {
-        // not needed
-    }
-}

+ 62 - 0
app/src/main/java/com/nextcloud/client/di/ActivityInjector.kt

@@ -0,0 +1,62 @@
+/*
+ * Nextcloud Android client application
+ *
+ * @author Chris Narkiewicz
+ * Copyright (C) 2019 Chris Narkiewicz <hello@ezaquarii.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.nextcloud.client.di
+
+import android.app.Activity
+import android.app.Application.ActivityLifecycleCallbacks
+import android.os.Bundle
+import androidx.fragment.app.FragmentActivity
+import dagger.android.AndroidInjection
+
+class ActivityInjector : ActivityLifecycleCallbacks {
+    override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
+        if (activity is Injectable) {
+            AndroidInjection.inject(activity)
+        }
+        if (activity is FragmentActivity) {
+            val fm = activity.supportFragmentManager
+            fm.registerFragmentLifecycleCallbacks(FragmentInjector(), true)
+        }
+    }
+
+    override fun onActivityStarted(activity: Activity) {
+        // unused atm
+    }
+
+    override fun onActivityResumed(activity: Activity) {
+        // unused atm
+    }
+
+    override fun onActivityPaused(activity: Activity) {
+        // unused atm
+    }
+
+    override fun onActivityStopped(activity: Activity) {
+        // unused atm
+    }
+
+    override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
+        // unused atm
+    }
+
+    override fun onActivityDestroyed(activity: Activity) {
+        // unused atm
+    }
+}