Browse Source

AppInfo: add getVersionName, remove getFormattedVersionCode

Only used for WhatsNewActivity, and showing the human-readable string makes more sense.
Also convert the appinfo package to kotlin, since we're at it

Signed-off-by: Álvaro Brey Vilas <alvaro.brey@nextcloud.com>
Álvaro Brey Vilas 3 years ago
parent
commit
40860d98be

+ 7 - 16
src/main/java/com/nextcloud/client/appinfo/AppInfo.java → src/main/java/com/nextcloud/client/appinfo/AppInfo.kt

@@ -17,9 +17,9 @@
  * 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.appinfo;
+package com.nextcloud.client.appinfo
 
-import android.content.Context;
+import android.content.Context
 
 /**
  * This class provides general, static information about application
@@ -27,18 +27,9 @@ import android.content.Context;
  *
  * All methods should be thread-safe.
  */
-public interface AppInfo {
-
-    /**
-     * Get application version code as formatted string.
-     *
-     * @return Formatted version code as defined in AndroidManifest.xml
-     */
-    String getFormattedVersionCode();
-
-    int getVersionCode();
-
-    boolean isDebugBuild();
-
-    String getAppVersion(Context context);
+interface AppInfo {
+    val versionName: String
+    val versionCode: Int
+    val isDebugBuild: Boolean
+    fun getAppVersion(context: Context): String
 }

+ 0 - 61
src/main/java/com/nextcloud/client/appinfo/AppInfoImpl.java

@@ -1,61 +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.appinfo;
-
-import android.content.Context;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-
-import com.owncloud.android.BuildConfig;
-import com.owncloud.android.lib.common.utils.Log_OC;
-
-class AppInfoImpl implements AppInfo {
-
-    @Override
-    public String getFormattedVersionCode() {
-        return Integer.toString(BuildConfig.VERSION_CODE);
-    }
-
-    @Override
-    public int getVersionCode() {
-        return BuildConfig.VERSION_CODE;
-    }
-
-    @Override
-    public boolean isDebugBuild() {
-        return BuildConfig.DEBUG;
-    }
-
-    @Override
-    public String getAppVersion(Context context) {
-        try {
-            PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
-            if (pInfo != null) {
-                return pInfo.versionName;
-            } else {
-                return "n/a";
-            }
-        } catch (PackageManager.NameNotFoundException e) {
-            Log_OC.e(this, "Trying to get packageName", e.getCause());
-
-            return "n/a";
-        }
-    }
-}

+ 45 - 0
src/main/java/com/nextcloud/client/appinfo/AppInfoImpl.kt

@@ -0,0 +1,45 @@
+/*
+ * 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.appinfo
+
+import android.content.Context
+import android.content.pm.PackageManager
+import com.owncloud.android.BuildConfig
+import com.owncloud.android.lib.common.utils.Log_OC
+
+class AppInfoImpl : AppInfo {
+    override val versionName: String = BuildConfig.VERSION_NAME
+    override val versionCode: Int = BuildConfig.VERSION_CODE
+    override val isDebugBuild: Boolean = BuildConfig.DEBUG
+
+    override fun getAppVersion(context: Context): String {
+        return try {
+            val pInfo = context.packageManager.getPackageInfo(context.packageName, 0)
+            if (pInfo != null) {
+                pInfo.versionName
+            } else {
+                "n/a"
+            }
+        } catch (e: PackageManager.NameNotFoundException) {
+            Log_OC.e(this, "Trying to get packageName", e.cause)
+            "n/a"
+        }
+    }
+}

+ 6 - 6
src/main/java/com/nextcloud/client/appinfo/AppInfoModule.java → src/main/java/com/nextcloud/client/appinfo/AppInfoModule.kt

@@ -17,15 +17,15 @@
  * 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.appinfo;
+package com.nextcloud.client.appinfo
 
-import dagger.Module;
-import dagger.Provides;
+import dagger.Module
+import dagger.Provides
 
 @Module
-public class AppInfoModule {
+class AppInfoModule {
     @Provides
-    AppInfo appInfo() {
-        return new AppInfoImpl();
+    fun appInfo(): AppInfo {
+        return AppInfoImpl()
     }
 }

+ 1 - 2
src/main/java/com/nextcloud/client/onboarding/WhatsNewActivity.java

@@ -38,7 +38,6 @@ import com.owncloud.android.ui.adapter.FeaturesViewAdapter;
 import com.owncloud.android.ui.adapter.FeaturesWebViewAdapter;
 import com.owncloud.android.ui.whatsnew.ProgressIndicator;
 import com.owncloud.android.utils.theme.ThemeButtonUtils;
-import com.owncloud.android.utils.theme.ThemeUtils;
 
 import javax.inject.Inject;
 
@@ -113,7 +112,7 @@ public class WhatsNewActivity extends FragmentActivity implements ViewPager.OnPa
         if (showWebView) {
             tv.setText(R.string.app_name);
         } else {
-            tv.setText(String.format(getString(R.string.whats_new_title), BuildConfig.VERSION_NAME));
+            tv.setText(String.format(getString(R.string.whats_new_title), appInfo.getVersionName()));
         }
 
         updateNextButtonIfNeeded();