simplified code that invokes the export logs service

This commit is contained in:
Daniel Gultsch 2016-09-28 12:35:52 +02:00
parent f0dbcce58f
commit 43f5dfe174
3 changed files with 9 additions and 39 deletions

View file

@ -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();
}
}

View file

@ -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

View file

@ -257,7 +257,7 @@
android:key="keep_foreground_service"
android:summary="@string/pref_keep_foreground_service_summary"
android:title="@string/pref_keep_foreground_service"/>
<eu.siacs.conversations.ui.ExportLogsPreference
<Preference
android:key="export_logs"
android:summary="@string/pref_export_logs_summary"
android:title="@string/pref_export_logs"/>