Browse Source

Merge pull request #12173 from nextcloud/refactor/convert-CommunityActivity-to-kt

Convert CommunityActivity to Kotlin
Andy Scherzinger 1 year ago
parent
commit
e4b9be195c

+ 3 - 2
app/src/huawei/java/com/owncloud/android/ui/activity/HuaweiCommunityActivity.kt

@@ -20,14 +20,15 @@
  */
  */
 package com.owncloud.android.ui.activity
 package com.owncloud.android.ui.activity
 
 
+import android.os.Bundle
 import android.view.View
 import android.view.View
 
 
 /**
 /**
  * Activity providing information about ways to participate in the app's development.
  * Activity providing information about ways to participate in the app's development.
  */
  */
 class HuaweiCommunityActivity : CommunityActivity() {
 class HuaweiCommunityActivity : CommunityActivity() {
-    override fun setupContent() {
-        super.setupContent()
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
         binding.communityReleaseCandidatePlaystore.visibility = View.GONE
         binding.communityReleaseCandidatePlaystore.visibility = View.GONE
     }
     }
 }
 }

+ 32 - 0
app/src/main/java/com/nextcloud/utils/extensions/TextViewExtensions.kt

@@ -0,0 +1,32 @@
+/*
+ * Nextcloud Android client application
+ *
+ * @author Alper Ozturk
+ * Copyright (C) 2023 Alper Ozturk
+ * Copyright (C) 2023 Nextcloud GmbH
+ *
+ * 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 <https://www.gnu.org/licenses/>.
+ */
+
+package com.nextcloud.utils.extensions
+
+import android.text.method.LinkMovementMethod
+import android.widget.TextView
+import androidx.core.text.HtmlCompat
+
+@Suppress("NewLineAtEndOfFile")
+fun TextView.setHtmlContent(value: String) {
+    movementMethod = LinkMovementMethod.getInstance()
+    text = HtmlCompat.fromHtml(value, HtmlCompat.FROM_HTML_MODE_LEGACY)
+}

+ 0 - 128
app/src/main/java/com/owncloud/android/ui/activity/CommunityActivity.java

@@ -1,128 +0,0 @@
-/*
- * Nextcloud Android client application
- *
- * @author Andy Scherzinger
- * @author Tobias Kaminsky
- * Copyright (C) 2016 Andy Scherzinger
- * Copyright (C) 2016 Nextcloud
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or 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.owncloud.android.ui.activity;
-
-import android.os.Bundle;
-import android.text.Html;
-import android.text.method.LinkMovementMethod;
-import android.view.MenuItem;
-import android.widget.TextView;
-
-import com.google.android.material.button.MaterialButton;
-import com.owncloud.android.R;
-import com.owncloud.android.databinding.CommunityLayoutBinding;
-import com.owncloud.android.utils.DisplayUtils;
-
-/**
- * Activity providing information about ways to participate in the app's development.
- */
-public class CommunityActivity extends DrawerActivity {
-
-    protected CommunityLayoutBinding binding;
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-
-        binding = CommunityLayoutBinding.inflate(getLayoutInflater());
-        setContentView(binding.getRoot());
-
-        // setup toolbar
-        setupToolbar();
-
-        updateActionBarTitleAndHomeButtonByString(getString(R.string.drawer_community));
-
-        // setup drawer
-        setupDrawer(R.id.nav_community);
-
-        setupContent();
-    }
-
-    protected void setupContent() {
-        binding.communityReleaseCandidateText.setMovementMethod(LinkMovementMethod.getInstance());
-
-        TextView contributeForumView = binding.communityContributeForumText;
-        contributeForumView.setMovementMethod(LinkMovementMethod.getInstance());
-        contributeForumView.setText(Html.fromHtml(getString(R.string.community_contribute_forum_text) + " " +
-                                                      getString(R.string.community_contribute_forum_text_link,
-                                                                viewThemeUtils
-                                                                    .files
-                                                                    .primaryColorToHexString(this),
-                                                                getString(R.string.help_link),
-                                                                getString(R.string.community_contribute_forum_forum))));
-
-        TextView contributeTranslationView = binding.communityContributeTranslateText;
-        contributeTranslationView.setMovementMethod(LinkMovementMethod.getInstance());
-        contributeTranslationView.setText(Html.fromHtml(
-            getString(R.string.community_contribute_translate_link,
-                      viewThemeUtils.files.primaryColorToHexString(this),
-                      getString(R.string.translation_link),
-                      getString(R.string.community_contribute_translate_translate)) + " " +
-                getString(R.string.community_contribute_translate_text)));
-
-        TextView contributeGithubView = binding.communityContributeGithubText;
-        contributeGithubView.setMovementMethod(LinkMovementMethod.getInstance());
-        contributeGithubView.setText(Html.fromHtml(
-            getString(R.string.community_contribute_github_text,
-                      getString(R.string.community_contribute_github_text_link,
-                                viewThemeUtils.files.primaryColorToHexString(this),
-                                getString(R.string.contributing_link)))));
-
-        MaterialButton reportButton = binding.communityTestingReport;
-        viewThemeUtils.material.colorMaterialButtonPrimaryFilled(reportButton);
-        reportButton.setOnClickListener(v -> DisplayUtils.startLinkIntent(this, R.string.report_issue_empty_link));
-
-        binding.communityBetaFdroid.setOnClickListener(
-            l -> DisplayUtils.startLinkIntent(this, R.string.fdroid_beta_link));
-
-        binding.communityReleaseCandidateFdroid.setOnClickListener(
-            l -> DisplayUtils.startLinkIntent(this, R.string.fdroid_link));
-
-        binding.communityReleaseCandidatePlaystore.setOnClickListener(
-            l -> DisplayUtils.startLinkIntent(this, R.string.play_store_register_beta));
-
-        binding.communityBetaApk.setOnClickListener(
-            l -> DisplayUtils.startLinkIntent(this, R.string.beta_apk_link));
-    }
-
-    @Override
-    public boolean onOptionsItemSelected(MenuItem item) {
-        boolean retval = true;
-        if (item.getItemId() == android.R.id.home) {
-            if (isDrawerOpen()) {
-                closeDrawer();
-            } else {
-                openDrawer();
-            }
-        } else {
-            retval = super.onOptionsItemSelected(item);
-        }
-        return retval;
-    }
-
-    @Override
-    protected void onResume() {
-        super.onResume();
-
-        setDrawerMenuItemChecked(R.id.nav_community);
-    }
-}

+ 146 - 0
app/src/main/java/com/owncloud/android/ui/activity/CommunityActivity.kt

@@ -0,0 +1,146 @@
+/*
+ * Nextcloud Android client application
+ *
+ * @author Andy Scherzinger
+ * @author Tobias Kaminsky
+ * Copyright (C) 2016 Andy Scherzinger
+ * Copyright (C) 2016 Nextcloud
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or 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.owncloud.android.ui.activity
+
+import android.os.Bundle
+import android.text.method.LinkMovementMethod
+import android.view.MenuItem
+import com.nextcloud.utils.extensions.setHtmlContent
+import com.owncloud.android.R
+import com.owncloud.android.databinding.CommunityLayoutBinding
+import com.owncloud.android.utils.DisplayUtils
+
+/**
+ * Activity providing information about ways to participate in the app's development.
+ */
+open class CommunityActivity : DrawerActivity() {
+    lateinit var binding: CommunityLayoutBinding
+
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+        binding = CommunityLayoutBinding.inflate(layoutInflater)
+        setContentView(binding.root)
+
+        setupToolbar()
+        updateActionBarTitleAndHomeButtonByString(getString(R.string.drawer_community))
+
+        setupDrawer(R.id.nav_community)
+        binding.communityReleaseCandidateText.movementMethod = LinkMovementMethod.getInstance()
+        setupContributeForumView()
+        setupContributeTranslationView()
+        setupContributeGithubView()
+        setupReportButton()
+        setOnClickListeners()
+    }
+
+    private fun setupContributeForumView() {
+        val htmlContent = getString(R.string.community_contribute_forum_text) + " " +
+            getString(
+                R.string.community_contribute_forum_text_link,
+                viewThemeUtils.files
+                    .primaryColorToHexString(this),
+                getString(R.string.help_link),
+                getString(R.string.community_contribute_forum_forum)
+            )
+        binding.communityContributeForumText.setHtmlContent(htmlContent)
+    }
+
+    private fun setupContributeTranslationView() {
+        val htmlContent = getString(
+            R.string.community_contribute_translate_link,
+            viewThemeUtils.files.primaryColorToHexString(this),
+            getString(R.string.translation_link),
+            getString(R.string.community_contribute_translate_translate)
+        ) + " " +
+            getString(R.string.community_contribute_translate_text)
+        binding.communityContributeTranslateText.setHtmlContent(htmlContent)
+    }
+
+    private fun setupContributeGithubView() {
+        val htmlContent = getString(
+            R.string.community_contribute_github_text,
+            getString(
+                R.string.community_contribute_github_text_link,
+                viewThemeUtils.files.primaryColorToHexString(this),
+                getString(R.string.contributing_link)
+            )
+        )
+        binding.communityContributeGithubText.setHtmlContent(htmlContent)
+    }
+
+    private fun setupReportButton() {
+        val reportButton = binding.communityTestingReport
+        viewThemeUtils.material.colorMaterialButtonPrimaryFilled(reportButton)
+        reportButton.setOnClickListener {
+            DisplayUtils.startLinkIntent(
+                this,
+                R.string.report_issue_empty_link
+            )
+        }
+    }
+
+    private fun setOnClickListeners() {
+        binding.communityBetaFdroid.setOnClickListener {
+            DisplayUtils.startLinkIntent(
+                this,
+                R.string.fdroid_beta_link
+            )
+        }
+        binding.communityReleaseCandidateFdroid.setOnClickListener {
+            DisplayUtils.startLinkIntent(
+                this,
+                R.string.fdroid_link
+            )
+        }
+        binding.communityReleaseCandidatePlaystore.setOnClickListener {
+            DisplayUtils.startLinkIntent(
+                this,
+                R.string.play_store_register_beta
+            )
+        }
+        binding.communityBetaApk.setOnClickListener {
+            DisplayUtils.startLinkIntent(
+                this,
+                R.string.beta_apk_link
+            )
+        }
+    }
+
+    override fun onOptionsItemSelected(item: MenuItem): Boolean {
+        var retval = true
+        if (item.itemId == android.R.id.home) {
+            if (isDrawerOpen) {
+                closeDrawer()
+            } else {
+                openDrawer()
+            }
+        } else {
+            retval = super.onOptionsItemSelected(item)
+        }
+        return retval
+    }
+
+    override fun onResume() {
+        super.onResume()
+        setDrawerMenuItemChecked(R.id.nav_community)
+    }
+}