Просмотр исходного кода

rewrite error activity in kotlin, harmonize share string

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Andy Scherzinger 5 лет назад
Родитель
Сommit
44c896093f

+ 0 - 50
src/main/java/com/owncloud/android/ui/errorhandling/ErrorShowActivity.java

@@ -1,50 +0,0 @@
-/*
- *   ownCloud Android client application
- *
- *   @author LukeOwncloud
- *   Copyright (C) 2016 ownCloud Inc.
- *
- *   This program is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License version 2,
- *   as published by the Free Software Foundation.
- *
- *   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 General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package com.owncloud.android.ui.errorhandling;
-
-import android.os.Bundle;
-import android.util.Log;
-import android.widget.TextView;
-
-import com.owncloud.android.R;
-
-import androidx.appcompat.app.ActionBar;
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.appcompat.widget.Toolbar;
-
-public class ErrorShowActivity extends AppCompatActivity {
-    private static final String TAG = ErrorShowActivity.class.getSimpleName();
-    public static final String EXTRA_ERROR_TEXT = "error";
-
-    TextView error;
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        Log.e(TAG, "ErrorShowActivity was called. See above for StackTrace.");
-        setContentView(R.layout.errorhandling_showerror);
-        error = findViewById(R.id.errorTextView);
-        error.setText(getIntent().getStringExtra(EXTRA_ERROR_TEXT));
-
-        Toolbar toolbar = findViewById(R.id.toolbar);
-        setSupportActionBar(toolbar);
-
-        setTitle(R.string.common_error);
-    }
-}

+ 68 - 0
src/main/java/com/owncloud/android/ui/errorhandling/ErrorShowActivity.kt

@@ -0,0 +1,68 @@
+/*
+ * Nextcloud Android client application
+ *
+ * @author Andy Scherzinger
+ * Copyright (C) 2019 Andy Scherzinger <info@andy-scherzinger.de>
+ *
+ * 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.owncloud.android.ui.errorhandling;
+
+import android.content.Intent
+import android.os.Bundle
+import android.view.Menu
+import android.view.MenuItem
+import androidx.appcompat.app.AppCompatActivity
+import androidx.appcompat.widget.Toolbar
+import com.owncloud.android.R
+import kotlinx.android.synthetic.main.errorhandling_showerror.*
+import kotlinx.android.synthetic.main.toolbar_standard.*
+
+class ErrorShowActivity : AppCompatActivity() {
+    companion object{
+        const val EXTRA_ERROR_TEXT = "error"
+    }
+
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.errorhandling_showerror);
+
+        text_view_error.text = intent.getStringExtra(EXTRA_ERROR_TEXT);
+
+        setSupportActionBar(toolbar);
+        setTitle(R.string.common_error);
+    }
+
+    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
+        menuInflater.inflate(R.menu.activity_error_show, menu)
+        return super.onCreateOptionsMenu(menu)
+    }
+
+    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
+        return when (item?.itemId) {
+            R.id.error_share -> {
+                onClickedShare(); true
+            }
+            else -> super.onOptionsItemSelected(item)
+        }
+    }
+
+    private fun onClickedShare() {
+        val intent = Intent(Intent.ACTION_SEND)
+        intent.putExtra(Intent.EXTRA_SUBJECT, "Nextcloud Error")
+        intent.putExtra(Intent.EXTRA_TEXT, text_view_error.text)
+        intent.type = "text/plain"
+        startActivity(intent)
+    }
+}

+ 1 - 1
src/main/res/layout/errorhandling_showerror.xml

@@ -32,7 +32,7 @@
         app:layout_behavior="@string/appbar_scrolling_view_behavior">
 
         <TextView
-            android:id="@+id/errorTextView"
+            android:id="@+id/text_view_error"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:padding="@dimen/standard_padding" />

+ 32 - 0
src/main/res/menu/activity_error_show.xml

@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+    Nextcloud Android client application
+
+    @author Andy Scherzinger
+    Copyright (C) 2019 Andy Scherzinger <info@andy-scherzinger.de>
+
+    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/>.
+-->
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    tools:ignore="AppCompatResource">
+
+    <item
+        android:id="@+id/error_share"
+        android:icon="@drawable/ic_share"
+        android:showAsAction="ifRoom"
+        android:title="@string/common_share"
+        app:showAsAction="ifRoom" />
+
+</menu>

+ 1 - 1
src/main/res/menu/etm_preferences.xml

@@ -25,7 +25,7 @@
 
     <item
         android:id="@+id/etm_preferences_share"
-        android:title="@string/etm_share"
+        android:title="@string/common_share"
         app:showAsAction="ifRoom"
         android:showAsAction="ifRoom"
         android:icon="@drawable/ic_share" />

+ 1 - 1
src/main/res/values/strings.xml

@@ -136,6 +136,7 @@
     <string name="common_pending">Pending</string>
     <string name="common_delete">Delete</string>
     <string name="common_send">Send</string>
+    <string name="common_share">Share</string>
     <string name="about_title">About</string>
     <string name="delete_account">Remove account</string>
     <string name="delete_account_warning">Remove account %s and delete all local files?\n\nDeletion cannot be undone.</string>
@@ -875,5 +876,4 @@
 
     <string name="etm_title">Engineering Test Mode</string>
     <string name="etm_preferences">Preferences</string>
-    <string name="etm_share">Share</string>
 </resources>