From 43f5dfe1746a9986d0c4ffa9a0c193aa3cf509a1 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 28 Sep 2016 12:35:52 +0200 Subject: [PATCH] simplified code that invokes the export logs service --- .../ui/ExportLogsPreference.java | 36 ------------------- .../conversations/ui/SettingsActivity.java | 10 ++++-- src/main/res/xml/preferences.xml | 2 +- 3 files changed, 9 insertions(+), 39 deletions(-) delete mode 100644 src/main/java/eu/siacs/conversations/ui/ExportLogsPreference.java diff --git a/src/main/java/eu/siacs/conversations/ui/ExportLogsPreference.java b/src/main/java/eu/siacs/conversations/ui/ExportLogsPreference.java deleted file mode 100644 index bedb4172d..000000000 --- a/src/main/java/eu/siacs/conversations/ui/ExportLogsPreference.java +++ /dev/null @@ -1,36 +0,0 @@ -package eu.siacs.conversations.ui; - -import android.Manifest; -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.os.Build; -import android.preference.Preference; -import android.util.AttributeSet; - -import eu.siacs.conversations.services.ExportLogsService; - -public class ExportLogsPreference extends Preference { - - public ExportLogsPreference(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - public ExportLogsPreference(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public ExportLogsPreference(Context context) { - super(context); - } - - protected void onClick() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M - && getContext().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { - return; - } - final Intent startIntent = new Intent(getContext(), ExportLogsService.class); - getContext().startService(startIntent); - super.onClick(); - } -} \ No newline at end of file diff --git a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java index fd81c6210..c2bf20ac4 100644 --- a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java @@ -149,7 +149,9 @@ public class SettingsActivity extends XmppActivity implements exportLogsPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { - hasStoragePermission(REQUEST_WRITE_LOGS); + if (hasStoragePermission(REQUEST_WRITE_LOGS)) { + startExport(); + } return true; } }); @@ -273,13 +275,17 @@ public class SettingsActivity extends XmppActivity implements if (grantResults.length > 0) if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { if (requestCode == REQUEST_WRITE_LOGS) { - getApplicationContext().startService(new Intent(getApplicationContext(), ExportLogsService.class)); + startExport(); } } else { Toast.makeText(this, R.string.no_storage_permission, Toast.LENGTH_SHORT).show(); } } + private void startExport() { + startService(new Intent(getApplicationContext(), ExportLogsService.class)); + } + private void displayToast(final String msg) { runOnUiThread(new Runnable() { @Override diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index b01faa6b8..cee434917 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -257,7 +257,7 @@ android:key="keep_foreground_service" android:summary="@string/pref_keep_foreground_service_summary" android:title="@string/pref_keep_foreground_service"/> -