theme improvements

This commit is contained in:
Mariotaku Lee 2016-03-15 14:16:07 +08:00
parent db764f9326
commit 50fc1e75c8
3 changed files with 8 additions and 19 deletions

View File

@ -42,7 +42,7 @@ public abstract class ThemedPreferenceDialogFragmentCompat extends PreferenceDia
if (needInputMethod()) { if (needInputMethod()) {
supportRequestInputMethod(dialog); supportRequestInputMethod(dialog);
} }
return builder.create(); return dialog;
} }
@Override @Override

View File

@ -19,12 +19,10 @@
package org.mariotaku.twidere.preference; package org.mariotaku.twidere.preference;
import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.preference.DialogPreference; import android.support.v7.preference.DialogPreference;
import android.support.v7.preference.PreferenceDialogFragmentCompat; import android.support.v7.preference.PreferenceDialogFragmentCompat;
import android.support.v7.preference.PreferenceFragmentCompat; import android.support.v7.preference.PreferenceFragmentCompat;
@ -98,7 +96,7 @@ public class NotificationTypePreference extends DialogPreference implements Cons
@Override @Override
public void displayDialog(PreferenceFragmentCompat fragment) { public void displayDialog(PreferenceFragmentCompat fragment) {
final MultiSelectListDialogFragment df = MultiSelectListDialogFragment.newInstance(getKey()); final NotificationTypeDialogFragment df = NotificationTypeDialogFragment.newInstance(getKey());
df.setTargetFragment(fragment, 0); df.setTargetFragment(fragment, 0);
df.show(fragment.getFragmentManager(), getKey()); df.show(fragment.getFragmentManager(), getKey());
} }
@ -107,27 +105,17 @@ public class NotificationTypePreference extends DialogPreference implements Cons
return mDefaultValue; return mDefaultValue;
} }
public final static class MultiSelectListDialogFragment extends ThemedPreferenceDialogFragmentCompat public final static class NotificationTypeDialogFragment extends ThemedPreferenceDialogFragmentCompat
implements DialogInterface.OnMultiChoiceClickListener { implements DialogInterface.OnMultiChoiceClickListener {
private boolean[] mCheckedItems; private boolean[] mCheckedItems;
@NonNull
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { protected void onPrepareDialogBuilder(AlertDialogWrapper.Builder builder) {
final Context context = getContext();
NotificationTypePreference preference = (NotificationTypePreference) getPreference(); NotificationTypePreference preference = (NotificationTypePreference) getPreference();
onClick(null, DialogInterface.BUTTON_NEGATIVE);
final AlertDialogWrapper.Builder builder = new AlertDialogWrapper.Builder(context)
.setTitle(preference.getDialogTitle())
.setIcon(preference.getDialogIcon())
.setPositiveButton(preference.getPositiveButtonText(), this)
.setNegativeButton(preference.getNegativeButtonText(), this);
final int value = preference.getPersistedInt(preference.getDefaultValue()); final int value = preference.getPersistedInt(preference.getDefaultValue());
mCheckedItems = preference.getCheckedItems(value); mCheckedItems = preference.getCheckedItems(value);
builder.setMultiChoiceItems(preference.getEntries(), mCheckedItems, this); builder.setMultiChoiceItems(preference.getEntries(), mCheckedItems, this);
// Create the dialog
return builder.create();
} }
@Override @Override
@ -145,8 +133,8 @@ public class NotificationTypePreference extends DialogPreference implements Cons
preference.notifyChanged(); preference.notifyChanged();
} }
public static MultiSelectListDialogFragment newInstance(String key) { public static NotificationTypeDialogFragment newInstance(String key) {
final MultiSelectListDialogFragment df = new MultiSelectListDialogFragment(); final NotificationTypeDialogFragment df = new NotificationTypeDialogFragment();
final Bundle args = new Bundle(); final Bundle args = new Bundle();
args.putString(PreferenceDialogFragmentCompat.ARG_KEY, key); args.putString(PreferenceDialogFragmentCompat.ARG_KEY, key);
df.setArguments(args); df.setArguments(args);

View File

@ -29,6 +29,7 @@
android:id="@android:id/toggle" android:id="@android:id/toggle"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center"/> android:layout_gravity="center"
android:tag="tint|primary_color_dependent"/>
</FrameLayout> </FrameLayout>