From a550743f2f35ed0f9f58561a48edee0bf33be5ab Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 27 Jun 2019 13:53:19 +0200 Subject: [PATCH] Report suggestion feature --- .../features/home/HomeActivity.kt | 10 ++--- .../features/rageshake/BugReportActivity.kt | 39 +++++++++++++++++-- .../features/rageshake/BugReporter.kt | 20 +++++++++- .../main/res/layout/activity_bug_report.xml | 5 ++- vector/src/main/res/menu/home.xml | 6 +-- vector/src/main/res/values/strings_riotX.xml | 6 +++ 6 files changed, 70 insertions(+), 16 deletions(-) diff --git a/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt b/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt index 1d04e376..e25e270e 100644 --- a/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/home/HomeActivity.kt @@ -165,12 +165,10 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable { override fun onOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { -// TODO Remove -// R.id.sliding_menu_sign_out -> { -// SignOutUiWorker(this, notificationDrawerManager) -// .perform(Matrix.getInstance().currentSession!!) -// return true -// } + R.id.menu_home_suggestion -> { + BugReporter.openBugReportScreen(this, true) + return true + } } return true diff --git a/vector/src/main/java/im/vector/riotredesign/features/rageshake/BugReportActivity.kt b/vector/src/main/java/im/vector/riotredesign/features/rageshake/BugReportActivity.kt index 28e3f212..45486ee1 100755 --- a/vector/src/main/java/im/vector/riotredesign/features/rageshake/BugReportActivity.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/rageshake/BugReportActivity.kt @@ -28,7 +28,6 @@ import im.vector.riotredesign.core.di.ScreenComponent import im.vector.riotredesign.core.platform.VectorBaseActivity import kotlinx.android.synthetic.main.activity_bug_report.* import timber.log.Timber -import javax.inject.Inject /** * Form to send a bug report @@ -42,6 +41,8 @@ class BugReportActivity : VectorBaseActivity() { override fun getLayoutRes() = R.layout.activity_bug_report + private var forSuggestion: Boolean = false + override fun initUiAndData() { configureToolbar(bugReportToolbar) @@ -52,6 +53,26 @@ class BugReportActivity : VectorBaseActivity() { bug_report_button_include_screenshot.isChecked = false bug_report_button_include_screenshot.isEnabled = false } + + forSuggestion = intent.getBooleanExtra("FOR_SUGGESTION", false) + + // Default screen is for bug report, so modify it for suggestion + if (forSuggestion) { + supportActionBar?.setTitle(R.string.send_suggestion) + + bug_report_first_text.setText(R.string.send_suggestion_content) + bug_report_text_input_layout.hint = getString(R.string.send_suggestion_report_placeholder) + + bug_report_logs_description.isVisible = false + + bug_report_button_include_logs.isChecked = false + bug_report_button_include_logs.isVisible = false + + bug_report_button_include_crash_logs.isChecked = false + bug_report_button_include_crash_logs.isVisible = false + + // Keep the screenshot + } } override fun getMenuRes() = R.menu.bug_report @@ -95,6 +116,7 @@ class BugReportActivity : VectorBaseActivity() { bug_report_progress_view.progress = 0 bugReporter.sendBugReport(this, + forSuggestion, bug_report_button_include_logs.isChecked, bug_report_button_include_crash_logs.isChecked, bug_report_button_include_screenshot.isChecked, @@ -103,8 +125,13 @@ class BugReportActivity : VectorBaseActivity() { override fun onUploadFailed(reason: String?) { try { if (!TextUtils.isEmpty(reason)) { - Toast.makeText(this@BugReportActivity, - getString(R.string.send_bug_report_failed, reason), Toast.LENGTH_LONG).show() + if (forSuggestion) { + Toast.makeText(this@BugReportActivity, + getString(R.string.send_suggestion_failed, reason), Toast.LENGTH_LONG).show() + } else { + Toast.makeText(this@BugReportActivity, + getString(R.string.send_bug_report_failed, reason), Toast.LENGTH_LONG).show() + } } } catch (e: Exception) { Timber.e(e, "## onUploadFailed() : failed to display the toast " + e.message) @@ -131,7 +158,11 @@ class BugReportActivity : VectorBaseActivity() { override fun onUploadSucceed() { try { - Toast.makeText(this@BugReportActivity, R.string.send_bug_report_sent, Toast.LENGTH_LONG).show() + if (forSuggestion) { + Toast.makeText(this@BugReportActivity, R.string.send_suggestion_sent, Toast.LENGTH_LONG).show() + } else { + Toast.makeText(this@BugReportActivity, R.string.send_bug_report_sent, Toast.LENGTH_LONG).show() + } } catch (e: Exception) { Timber.e(e, "## onUploadSucceed() : failed to dismiss the toast " + e.message) } diff --git a/vector/src/main/java/im/vector/riotredesign/features/rageshake/BugReporter.kt b/vector/src/main/java/im/vector/riotredesign/features/rageshake/BugReporter.kt index 1808b471..4b2a7150 100755 --- a/vector/src/main/java/im/vector/riotredesign/features/rageshake/BugReporter.kt +++ b/vector/src/main/java/im/vector/riotredesign/features/rageshake/BugReporter.kt @@ -128,6 +128,7 @@ class BugReporter @Inject constructor(private val activeSessionHolder: ActiveSes * Send a bug report. * * @param context the application context + * @param forSuggestion true to send a suggestion * @param withDevicesLogs true to include the device log * @param withCrashLogs true to include the crash logs * @param withScreenshot true to include the screenshot @@ -136,6 +137,7 @@ class BugReporter @Inject constructor(private val activeSessionHolder: ActiveSes */ @SuppressLint("StaticFieldLeak") fun sendBugReport(context: Context, + forSuggestion: Boolean, withDevicesLogs: Boolean, withCrashLogs: Boolean, withScreenshot: Boolean, @@ -208,9 +210,17 @@ class BugReporter @Inject constructor(private val activeSessionHolder: ActiveSes } if (!mIsCancelled) { + val text = "[RiotX] " + + if (forSuggestion) { + "[Suggestion] " + } else { + "" + } + + bugDescription + // build the multi part request val builder = BugReporterMultipartBody.Builder() - .addFormDataPart("text", "[RiotX] $bugDescription") + .addFormDataPart("text", text) .addFormDataPart("app", "riot-android") .addFormDataPart("user_agent", Matrix.getInstance(context).getUserAgent()) .addFormDataPart("user_id", userId) @@ -276,6 +286,11 @@ class BugReporter @Inject constructor(private val activeSessionHolder: ActiveSes // Special for RiotX builder.addFormDataPart("label", "[RiotX]") + // Suggestion + if (forSuggestion) { + builder.addFormDataPart("label", "[Suggestion]") + } + if (getCrashFile(context).exists()) { builder.addFormDataPart("label", "crash") deleteCrashFile(context) @@ -418,10 +433,11 @@ class BugReporter @Inject constructor(private val activeSessionHolder: ActiveSes /** * Send a bug report either with email or with Vector. */ - fun openBugReportScreen(activity: Activity) { + fun openBugReportScreen(activity: Activity, forSuggestion: Boolean = true) { screenshot = takeScreenshot(activity) val intent = Intent(activity, BugReportActivity::class.java) + intent.putExtra("FOR_SUGGESTION", forSuggestion) activity.startActivity(intent) } diff --git a/vector/src/main/res/layout/activity_bug_report.xml b/vector/src/main/res/layout/activity_bug_report.xml index 4ccb9c5e..bbe81976 100644 --- a/vector/src/main/res/layout/activity_bug_report.xml +++ b/vector/src/main/res/layout/activity_bug_report.xml @@ -61,6 +61,7 @@ android:orientation="vertical"> @@ -103,6 +105,7 @@ android:textSize="12sp" /> + android:id="@+id/menu_home_suggestion" + android:icon="@drawable/ic_material_bug_report" + android:title="@string/send_suggestion" /> \ No newline at end of file diff --git a/vector/src/main/res/values/strings_riotX.xml b/vector/src/main/res/values/strings_riotX.xml index e2fd753e..a338a207 100644 --- a/vector/src/main/res/values/strings_riotX.xml +++ b/vector/src/main/res/values/strings_riotX.xml @@ -40,4 +40,10 @@ Register token + Propose a suggestion + Please write your suggestion below. + Describe your suggestion here + Thanks, the suggestion has been successfully sent + The suggestion failed to be sent (%s) + \ No newline at end of file