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