Browse Source

- fixed dialogs from applying the wrong theme when autoDarkTheme is on

pull/529/head
Twig N 5 years ago
parent
commit
320c5d9935
  1. 15
      app/src/main/java/org/transdroid/core/app/settings/SettingsUtils.java
  2. 5
      app/src/main/java/org/transdroid/core/app/settings/SystemSettings.java
  3. 39
      app/src/main/java/org/transdroid/core/gui/navigation/SetLabelDialog.java
  4. 25
      app/src/main/java/org/transdroid/core/gui/navigation/SetStorageLocationDialog.java
  5. 22
      app/src/main/java/org/transdroid/core/gui/navigation/SetTrackersDialog.java
  6. 49
      app/src/main/java/org/transdroid/core/gui/navigation/SetTransferRatesDialog.java

15
app/src/main/java/org/transdroid/core/app/settings/SettingsUtils.java

@ -1,9 +1,13 @@ @@ -1,9 +1,13 @@
package org.transdroid.core.app.settings;
import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDelegate;
import com.afollestad.materialdialogs.MaterialDialog;
import com.afollestad.materialdialogs.Theme;
public class SettingsUtils {
/**
* Set the theme according to the user preference.
@ -20,4 +24,15 @@ public class SettingsUtils { @@ -20,4 +24,15 @@ public class SettingsUtils {
);
}
}
public static MaterialDialog.Builder applyDialogTheme(MaterialDialog.Builder builder) {
SystemSettings settings = SystemSettings_.getInstance_(builder.getContext());
if (settings.autoDarkTheme()) {
return builder;
}
return builder.theme(settings.useDarkTheme() ? Theme.DARK: Theme.LIGHT);
}
}

5
app/src/main/java/org/transdroid/core/app/settings/SystemSettings.java

@ -26,7 +26,6 @@ import android.content.Context; @@ -26,7 +26,6 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import com.afollestad.materialdialogs.Theme;
/**
* Allows instantiation of the settings specified in R.xml.pref_system.
@ -67,10 +66,6 @@ public class SystemSettings { @@ -67,10 +66,6 @@ public class SystemSettings {
return prefs.getBoolean("system_usedarktheme", false);
}
public Theme getMaterialDialogtheme() {
return useDarkTheme() ? Theme.DARK: Theme.LIGHT;
}
/**
* Returns the date when we last checked transdroid.org for the latest app version.
* @return The date/time when the {@link org.transdroid.core.service.AppUpdateJob} checked on the server for updates

39
app/src/main/java/org/transdroid/core/gui/navigation/SetLabelDialog.java

@ -30,7 +30,7 @@ import com.nispok.snackbar.Snackbar; @@ -30,7 +30,7 @@ import com.nispok.snackbar.Snackbar;
import com.nispok.snackbar.SnackbarManager;
import org.transdroid.R;
import org.transdroid.core.app.settings.SystemSettings_;
import org.transdroid.core.app.settings.SettingsUtils;
import java.util.Iterator;
import java.util.List;
@ -56,23 +56,30 @@ public class SetLabelDialog { @@ -56,23 +56,30 @@ public class SetLabelDialog {
final ListView labelsList = (ListView) setLabelLayout.findViewById(R.id.labels_list);
final EditText newLabelEdit = (EditText) setLabelLayout.findViewById(R.id.newlabel_edit);
final MaterialDialog dialog = new MaterialDialog.Builder(context).customView(setLabelLayout, false).positiveText(R.string.status_update)
.neutralText(R.string.status_label_remove).negativeText(android.R.string.cancel).callback(new MaterialDialog.ButtonCallback() {
@Override
public void onPositive(MaterialDialog dialog) {
// User should have provided a new label
if (TextUtils.isEmpty(newLabelEdit.getText())) {
SnackbarManager.show(Snackbar.with(context).text(R.string.error_notalabel).colorResource(R.color.red));
return;
}
onLabelPickedListener.onLabelPicked(newLabelEdit.getText().toString());
MaterialDialog.Builder builder = new MaterialDialog.Builder(context)
.customView(setLabelLayout, false)
.positiveText(R.string.status_update)
.neutralText(R.string.status_label_remove)
.negativeText(android.R.string.cancel)
.callback(new MaterialDialog.ButtonCallback() {
@Override
public void onPositive(MaterialDialog dialog) {
// User should have provided a new label
if (TextUtils.isEmpty(newLabelEdit.getText())) {
SnackbarManager.show(Snackbar.with(context).text(R.string.error_notalabel).colorResource(R.color.red));
return;
}
onLabelPickedListener.onLabelPicked(newLabelEdit.getText().toString());
}
@Override
public void onNeutral(MaterialDialog dialog) {
onLabelPickedListener.onLabelPicked(null);
}
}).theme(SystemSettings_.getInstance_(context).getMaterialDialogtheme()).build();
@Override
public void onNeutral(MaterialDialog dialog) {
onLabelPickedListener.onLabelPicked(null);
}
});
final MaterialDialog dialog = SettingsUtils
.applyDialogTheme(builder)
.build();
if (currentLabels.size() == 0) {
// Hide the list (and its label) if there are no labels yet

25
app/src/main/java/org/transdroid/core/gui/navigation/SetStorageLocationDialog.java

@ -24,7 +24,7 @@ import android.widget.EditText; @@ -24,7 +24,7 @@ import android.widget.EditText;
import com.afollestad.materialdialogs.MaterialDialog;
import org.transdroid.R;
import org.transdroid.core.app.settings.SystemSettings_;
import org.transdroid.core.app.settings.SettingsUtils;
public class SetStorageLocationDialog {
@ -38,14 +38,21 @@ public class SetStorageLocationDialog { @@ -38,14 +38,21 @@ public class SetStorageLocationDialog {
View locationLayout = LayoutInflater.from(context).inflate(R.layout.dialog_storagelocation, null);
final EditText locationText = (EditText) locationLayout.findViewById(R.id.location_edit);
locationText.setText(currentLocation);
new MaterialDialog.Builder(context).customView(locationLayout, false).positiveText(R.string.status_update)
.negativeText(android.R.string.cancel).callback(new MaterialDialog.ButtonCallback() {
@Override
public void onPositive(MaterialDialog dialog) {
// User is done editing and requested to update given the text input
onStorageLocationUpdatedListener.onStorageLocationUpdated(locationText.getText().toString());
}
}).theme(SystemSettings_.getInstance_(context).getMaterialDialogtheme()).show();
MaterialDialog.Builder builder = new MaterialDialog.Builder(context)
.customView(locationLayout, false)
.positiveText(R.string.status_update)
.negativeText(android.R.string.cancel)
.callback(new MaterialDialog.ButtonCallback() {
@Override
public void onPositive(MaterialDialog dialog) {
// User is done editing and requested to update given the text input
onStorageLocationUpdatedListener.onStorageLocationUpdated(locationText.getText().toString());
}
});
SettingsUtils
.applyDialogTheme(builder)
.show();
}
public interface OnStorageLocationUpdatedListener {

22
app/src/main/java/org/transdroid/core/gui/navigation/SetTrackersDialog.java

@ -25,7 +25,7 @@ import android.widget.EditText; @@ -25,7 +25,7 @@ import android.widget.EditText;
import com.afollestad.materialdialogs.MaterialDialog;
import org.transdroid.R;
import org.transdroid.core.app.settings.SystemSettings_;
import org.transdroid.core.app.settings.SettingsUtils;
import java.util.Arrays;
import java.util.List;
@ -42,14 +42,18 @@ public class SetTrackersDialog extends DialogFragment { @@ -42,14 +42,18 @@ public class SetTrackersDialog extends DialogFragment {
View trackersLayout = LayoutInflater.from(context).inflate(R.layout.dialog_trackers, null);
final EditText trackersText = (EditText) trackersLayout.findViewById(R.id.trackers_edit);
trackersText.setText(currentTrackers);
new MaterialDialog.Builder(context).customView(trackersLayout, false).positiveText(R.string.status_update)
.negativeText(android.R.string.cancel).callback(new MaterialDialog.ButtonCallback() {
@Override
public void onPositive(MaterialDialog dialog) {
// User is done editing and requested to update given the text input
onTrackersUpdatedListener.onTrackersUpdated(Arrays.asList(trackersText.getText().toString().split("\n")));
}
}).theme(SystemSettings_.getInstance_(context).getMaterialDialogtheme()).show();
MaterialDialog.Builder builder = new MaterialDialog.Builder(context)
.customView(trackersLayout, false)
.positiveText(R.string.status_update)
.negativeText(android.R.string.cancel)
.callback(new MaterialDialog.ButtonCallback() {
@Override
public void onPositive(MaterialDialog dialog) {
// User is done editing and requested to update given the text input
onTrackersUpdatedListener.onTrackersUpdated(Arrays.asList(trackersText.getText().toString().split("\n")));
}
});
SettingsUtils.applyDialogTheme(builder).show();
}
public interface OnTrackersUpdatedListener {

49
app/src/main/java/org/transdroid/core/gui/navigation/SetTransferRatesDialog.java

@ -26,7 +26,7 @@ import android.widget.TextView; @@ -26,7 +26,7 @@ import android.widget.TextView;
import com.afollestad.materialdialogs.MaterialDialog;
import org.transdroid.R;
import org.transdroid.core.app.settings.SystemSettings_;
import org.transdroid.core.app.settings.SettingsUtils;
public class SetTransferRatesDialog {
@ -41,29 +41,34 @@ public class SetTransferRatesDialog { @@ -41,29 +41,34 @@ public class SetTransferRatesDialog {
final TextView maxSpeedDown = (TextView) transferRatesLayout.findViewById(R.id.maxspeeddown_text);
final TextView maxSpeedUp = (TextView) transferRatesLayout.findViewById(R.id.maxspeedup_text);
MaterialDialog dialog = new MaterialDialog.Builder(context).customView(transferRatesLayout, false).positiveText(R.string.status_update)
.neutralText(R.string.status_maxspeed_reset).negativeText(android.R.string.cancel).callback(new MaterialDialog.ButtonCallback() {
@Override
public void onPositive(MaterialDialog dialog) {
int maxDown = -1, maxUp = -1;
try {
maxDown = Integer.parseInt(maxSpeedDown.getText().toString());
maxUp = Integer.parseInt(maxSpeedUp.getText().toString());
} catch (NumberFormatException e) {
// Impossible as we only input via the number buttons
}
if (maxDown <= 0 || maxUp <= 0) {
onRatesPickedListener.onInvalidNumber();
return;
}
onRatesPickedListener.onRatesPicked(maxDown, maxUp);
MaterialDialog.Builder builder = new MaterialDialog.Builder(context)
.customView(transferRatesLayout, false)
.positiveText(R.string.status_update)
.neutralText(R.string.status_maxspeed_reset)
.negativeText(android.R.string.cancel)
.callback(new MaterialDialog.ButtonCallback() {
@Override
public void onPositive(MaterialDialog dialog) {
int maxDown = -1, maxUp = -1;
try {
maxDown = Integer.parseInt(maxSpeedDown.getText().toString());
maxUp = Integer.parseInt(maxSpeedUp.getText().toString());
} catch (NumberFormatException e) {
// Impossible as we only input via the number buttons
}
@Override
public void onNeutral(MaterialDialog dialog) {
onRatesPickedListener.resetRates();
if (maxDown <= 0 || maxUp <= 0) {
onRatesPickedListener.onInvalidNumber();
return;
}
}).theme(SystemSettings_.getInstance_(context).getMaterialDialogtheme()).build();
onRatesPickedListener.onRatesPicked(maxDown, maxUp);
}
@Override
public void onNeutral(MaterialDialog dialog) {
onRatesPickedListener.resetRates();
}
});
MaterialDialog dialog = SettingsUtils.applyDialogTheme(builder).build();
bindButtons(dialog.getCustomView(), maxSpeedDown, R.id.down1Button, R.id.down2Button, R.id.down3Button, R.id.down4Button, R.id.down5Button,
R.id.down6Button, R.id.down7Button, R.id.down8Button, R.id.down9Button, R.id.down0Button);

Loading…
Cancel
Save