Skip to content

Commit

Permalink
[fix #42] Customize the ability to have screen and logs capturing cap…
Browse files Browse the repository at this point in the history
…abilities

Test the behavior of this through the sample app, which now exposes settings.
  • Loading branch information
rm3l committed Aug 7, 2017
1 parent 036827b commit 492bafe
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package org.rm3l.maoni.sample.ui;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.FloatingActionButton;
Expand Down Expand Up @@ -70,7 +71,14 @@ public void onClick(View view) {
//Note that if no handler/listener is specified,
//Maoni will fall back to opening an Email Intent, so your users can send
//their feedback via email
mMaoni = maoniBuilder.withHandler(handlerForMaoni).build();
final SharedPreferences defaultSharedPreferences =
PreferenceManager.getDefaultSharedPreferences(MaoniSampleMainActivity.this);
mMaoni = maoniBuilder
.withScreenCapturingFeature(defaultSharedPreferences
.getBoolean("maoni_screen_capturing_enabled", true))
.withLogsCapturingFeature(defaultSharedPreferences
.getBoolean("maoni_logs_capturing_enabled", true))
.withHandler(handlerForMaoni).build();
mMaoni.start(MaoniSampleMainActivity.this);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package org.rm3l.maoni.sample.extensions

import android.content.Context
import org.jetbrains.anko.defaultSharedPreferences
import org.rm3l.maoni.Maoni
import org.rm3l.maoni.common.contract.Handler
import org.rm3l.maoni.sample.BuildConfig
Expand All @@ -15,8 +16,7 @@ fun Context.getMaoniFeedbackHandler(): Handler = MaoniSampleCallbackHandler(this

fun Context.getMaoniFeedbackBuilder() =
Maoni.Builder(this, MY_FILE_PROVIDER_AUTHORITY)
.withWindowTitle(
getString(R.string.send_feedback_activity_title)) //Set to an empty string to clear it
.withWindowTitle(getString(R.string.send_feedback_activity_title)) //Set to an empty string to clear it
.withMessage(getString(R.string.send_feedback_activity_intro))
.withExtraLayout(R.layout.my_feedback_activity_extra_content)
.withFeedbackContentHint(getString(R.string.feedback_content_hint))
Expand All @@ -25,4 +25,4 @@ fun Context.getMaoniFeedbackBuilder() =
.withTouchToPreviewScreenshotText(getString(R.string.touch_edit_screenshot))
.withContentErrorMessage(getString(R.string.content_error_message))
.withDefaultToEmailAddress("apps+maoni_sample@rm3l.org")
.withScreenshotHint(getString(R.string.screenshot_hint))
.withScreenshotHint(getString(R.string.screenshot_hint))
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.view.Menu
import android.view.MenuItem
import org.jetbrains.anko.defaultSharedPreferences
import org.jetbrains.anko.find
import org.rm3l.maoni.Maoni
import org.rm3l.maoni.common.contract.Handler
Expand Down Expand Up @@ -60,7 +61,10 @@ class MaoniSampleSettingsActivity: AppCompatActivity() {
//Note that if no handler/listener is specified,
//Maoni will fall back to opening an Email Intent, so your users can send
//their feedback via email
mMaoni = mMaoniBuilder.withHandler(mHandlerForMaoni).build()
mMaoni = mMaoniBuilder
.withScreenCapturingFeature(this.defaultSharedPreferences.getBoolean("maoni_screen_capturing_enabled", true))
.withLogsCapturingFeature(this.defaultSharedPreferences.getBoolean("maoni_logs_capturing_enabled", true))
.withHandler(mHandlerForMaoni).build()
mMaoni?.start(this@MaoniSampleSettingsActivity)
return true
}
Expand Down
11 changes: 11 additions & 0 deletions maoni-sample/src/main/res/xml/maoni_sample_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
android:key="general"
android:title="General"
android:summary="General Options">
<SwitchPreference
android:key="maoni_screen_capturing_enabled"
android:defaultValue="true"
android:title="Enable Screen Capturing" >
</SwitchPreference>
<SwitchPreference
android:key="maoni_logs_capturing_enabled"
android:defaultValue="true"
android:title="Enable Logs Capturing" >
</SwitchPreference>

</PreferenceCategory>

<!-- Callbacks -->
Expand Down
18 changes: 18 additions & 0 deletions maoni/src/main/java/org/rm3l/maoni/Maoni.java
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,15 @@ public Builder enableScreenCapturingFeature() {
return this;
}

public Builder withScreenCapturingFeature(final boolean screenCapturingFeature) {
if (screenCapturingFeature) {
this.enableScreenCapturingFeature();
} else {
this.disableScreenCapturingFeature();
}
return this;
}

public Builder disableLogsCapturingFeature() {
this.logsCapturingFeatureEnabled = false;
return this;
Expand All @@ -763,6 +772,15 @@ public Builder enableLogsCapturingFeature() {
return this;
}

public Builder withLogsCapturingFeature(final boolean logsCapturingFeature) {
if (logsCapturingFeature) {
this.enableLogsCapturingFeature();
} else {
this.disableLogsCapturingFeature();
}
return this;
}

public Builder disableCapturingFeature() {
this.disableLogsCapturingFeature();
this.disableScreenCapturingFeature();
Expand Down

0 comments on commit 492bafe

Please sign in to comment.