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 @@
package org.transdroid.core.app.settings; package org.transdroid.core.app.settings;
import android.content.Context;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDelegate; import android.support.v7.app.AppCompatDelegate;
import com.afollestad.materialdialogs.MaterialDialog;
import com.afollestad.materialdialogs.Theme;
public class SettingsUtils { public class SettingsUtils {
/** /**
* Set the theme according to the user preference. * Set the theme according to the user preference.
@ -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;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import com.afollestad.materialdialogs.Theme;
/** /**
* Allows instantiation of the settings specified in R.xml.pref_system. * Allows instantiation of the settings specified in R.xml.pref_system.
@ -67,10 +66,6 @@ public class SystemSettings {
return prefs.getBoolean("system_usedarktheme", false); 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. * 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 * @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;
import com.nispok.snackbar.SnackbarManager; import com.nispok.snackbar.SnackbarManager;
import org.transdroid.R; 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.Iterator;
import java.util.List; import java.util.List;
@ -56,23 +56,30 @@ public class SetLabelDialog {
final ListView labelsList = (ListView) setLabelLayout.findViewById(R.id.labels_list); final ListView labelsList = (ListView) setLabelLayout.findViewById(R.id.labels_list);
final EditText newLabelEdit = (EditText) setLabelLayout.findViewById(R.id.newlabel_edit); 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) MaterialDialog.Builder builder = new MaterialDialog.Builder(context)
.neutralText(R.string.status_label_remove).negativeText(android.R.string.cancel).callback(new MaterialDialog.ButtonCallback() { .customView(setLabelLayout, false)
@Override .positiveText(R.string.status_update)
public void onPositive(MaterialDialog dialog) { .neutralText(R.string.status_label_remove)
// User should have provided a new label .negativeText(android.R.string.cancel)
if (TextUtils.isEmpty(newLabelEdit.getText())) { .callback(new MaterialDialog.ButtonCallback() {
SnackbarManager.show(Snackbar.with(context).text(R.string.error_notalabel).colorResource(R.color.red)); @Override
return; public void onPositive(MaterialDialog dialog) {
} // User should have provided a new label
onLabelPickedListener.onLabelPicked(newLabelEdit.getText().toString()); 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 @Override
public void onNeutral(MaterialDialog dialog) { public void onNeutral(MaterialDialog dialog) {
onLabelPickedListener.onLabelPicked(null); onLabelPickedListener.onLabelPicked(null);
} }
}).theme(SystemSettings_.getInstance_(context).getMaterialDialogtheme()).build(); });
final MaterialDialog dialog = SettingsUtils
.applyDialogTheme(builder)
.build();
if (currentLabels.size() == 0) { if (currentLabels.size() == 0) {
// Hide the list (and its label) if there are no labels yet // 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;
import com.afollestad.materialdialogs.MaterialDialog; import com.afollestad.materialdialogs.MaterialDialog;
import org.transdroid.R; import org.transdroid.R;
import org.transdroid.core.app.settings.SystemSettings_; import org.transdroid.core.app.settings.SettingsUtils;
public class SetStorageLocationDialog { public class SetStorageLocationDialog {
@ -38,14 +38,21 @@ public class SetStorageLocationDialog {
View locationLayout = LayoutInflater.from(context).inflate(R.layout.dialog_storagelocation, null); View locationLayout = LayoutInflater.from(context).inflate(R.layout.dialog_storagelocation, null);
final EditText locationText = (EditText) locationLayout.findViewById(R.id.location_edit); final EditText locationText = (EditText) locationLayout.findViewById(R.id.location_edit);
locationText.setText(currentLocation); locationText.setText(currentLocation);
new MaterialDialog.Builder(context).customView(locationLayout, false).positiveText(R.string.status_update) MaterialDialog.Builder builder = new MaterialDialog.Builder(context)
.negativeText(android.R.string.cancel).callback(new MaterialDialog.ButtonCallback() { .customView(locationLayout, false)
@Override .positiveText(R.string.status_update)
public void onPositive(MaterialDialog dialog) { .negativeText(android.R.string.cancel)
// User is done editing and requested to update given the text input .callback(new MaterialDialog.ButtonCallback() {
onStorageLocationUpdatedListener.onStorageLocationUpdated(locationText.getText().toString()); @Override
} public void onPositive(MaterialDialog dialog) {
}).theme(SystemSettings_.getInstance_(context).getMaterialDialogtheme()).show(); // User is done editing and requested to update given the text input
onStorageLocationUpdatedListener.onStorageLocationUpdated(locationText.getText().toString());
}
});
SettingsUtils
.applyDialogTheme(builder)
.show();
} }
public interface OnStorageLocationUpdatedListener { public interface OnStorageLocationUpdatedListener {

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

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

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

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

Loading…
Cancel
Save