Commit 8e93e325 authored by Erik Duisters's avatar Erik Duisters

Use androidx version of AlertDialog

Summary:
Use androidx version of AlertDialog to get properly styled AlertDialog buttons
Use PreferenceManager context to style Device Name AlertDialog

|{F6551907}|{F6551908}|
|Before|After|

Test Plan: Apply patch and verify that AlertDialogs have properly styled buttons

Reviewers: #kde_connect, albertvaka

Reviewed By: #kde_connect, albertvaka

Subscribers: albertvaka, kdeconnect

Tags: #kde_connect

Differential Revision: https://phabricator.kde.org/D18298
parent a6ae97af
......@@ -21,7 +21,6 @@
package org.kde.kdeconnect.Plugins.MprisReceiverPlugin;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
......@@ -45,6 +44,7 @@ import java.util.List;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public class MprisReceiverPlugin extends Plugin implements MediaSessionManager.OnActiveSessionsChangedListener {
......
......@@ -20,7 +20,6 @@
package org.kde.kdeconnect.Plugins.NotificationsPlugin;
import android.app.AlertDialog;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
......@@ -46,6 +45,7 @@ import org.kde.kdeconnect_tp.R;
import java.util.Arrays;
import java.util.List;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
//TODO: Turn this into a PluginSettingsFragment
......
......@@ -22,7 +22,6 @@ package org.kde.kdeconnect.Plugins.NotificationsPlugin;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.RemoteInput;
......@@ -58,6 +57,7 @@ import java.util.Map;
import java.util.Set;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.NotificationCompat;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
......
......@@ -21,7 +21,6 @@
package org.kde.kdeconnect.Plugins;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
......@@ -34,6 +33,7 @@ import org.kde.kdeconnect.UserInterface.PluginSettingsFragment;
import org.kde.kdeconnect_tp.R;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
......
......@@ -20,7 +20,6 @@
package org.kde.kdeconnect.UserInterface;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Build;
......@@ -41,6 +40,7 @@ import org.kde.kdeconnect_tp.R;
import java.util.ArrayList;
import java.util.Collections;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
public class CustomDevicesActivity extends AppCompatActivity {
......
......@@ -21,7 +21,6 @@
package org.kde.kdeconnect.UserInterface;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
......@@ -55,6 +54,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.Fragment;
import butterknife.BindView;
import butterknife.ButterKnife;
......
package org.kde.kdeconnect.UserInterface;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
......@@ -30,6 +29,7 @@ import java.util.Set;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
......@@ -381,13 +381,13 @@ public class MainActivity extends AppCompatActivity {
nameChangeSubscribers.remove(cb);
}
public void openRenameDeviceDialog() {
public void openRenameDeviceDialog(Context context) {
final EditText deviceNameEdit = new EditText(this);
String deviceName = DeviceHelper.getDeviceName(this);
deviceNameEdit.setText(deviceName);
float dpi = this.getResources().getDisplayMetrics().density;
deviceNameEdit.setPadding( ((int) (18 * dpi)), ((int) (16 * dpi)), ((int) (18 * dpi)), ((int) (12 * dpi)) );
new AlertDialog.Builder(this)
new AlertDialog.Builder(context)
.setView(deviceNameEdit)
.setPositiveButton(R.string.device_rename_confirm, (dialog, which) -> {
String newDeviceName = deviceNameEdit.getText().toString();
......
......@@ -40,11 +40,12 @@ public class SettingsFragment extends PreferenceFragmentCompat implements MainAc
// Rename device
mainActivity.addNameChangeCallback(this);
//TODO: Use an EditTextPreference
renameDevice = new Preference(context);
renameDevice.setPersistent(false);
renameDevice.setSelectable(true);
renameDevice.setOnPreferenceClickListener(preference -> {
mainActivity.openRenameDeviceDialog();
mainActivity.openRenameDeviceDialog(context);
return true;
});
String deviceName = DeviceHelper.getDeviceName(context);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment