-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new feature: Foreign transaction fee + bump version to 1.1.0
- Loading branch information
Showing
17 changed files
with
350 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package de.salomax.currencies.util | ||
|
||
import android.content.Context | ||
import de.salomax.currencies.R | ||
import java.lang.StringBuilder | ||
|
||
|
||
fun Float.humanReadableFee(context: Context): String { | ||
val sb = StringBuilder() | ||
if (this >= 0) | ||
sb.append("+ ") | ||
sb.append(this.toString() | ||
.replace(".", context.getString(R.string.decimal_separator)) | ||
.replace("-", "- ") | ||
) | ||
sb.append(" %") | ||
return sb.toString() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
app/src/main/java/de/salomax/currencies/widget/EditTextSwitchPreference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package de.salomax.currencies.widget; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
|
||
import androidx.appcompat.widget.SwitchCompat; | ||
import androidx.preference.EditTextPreference; | ||
import androidx.preference.PreferenceDataStore; | ||
import androidx.preference.PreferenceViewHolder; | ||
|
||
import de.salomax.currencies.R; | ||
|
||
@SuppressWarnings("unused") | ||
public class EditTextSwitchPreference extends EditTextPreference { | ||
|
||
private PreferenceViewHolder holder; | ||
|
||
private final String KEY_SWITCH; | ||
|
||
public EditTextSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { | ||
super(context, attrs, defStyleAttr, defStyleRes); | ||
setWidgetLayoutResource(R.layout.preference_edit_text_switch); | ||
KEY_SWITCH = getKey() + "_switch"; | ||
} | ||
|
||
public EditTextSwitchPreference(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
setWidgetLayoutResource(R.layout.preference_edit_text_switch); | ||
KEY_SWITCH = getKey() + "_switch"; | ||
} | ||
|
||
public EditTextSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) { | ||
this(context, attrs, defStyleAttr, 0); | ||
} | ||
|
||
public EditTextSwitchPreference(Context context) { | ||
this(context, null); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(PreferenceViewHolder holder) { | ||
super.onBindViewHolder(holder); | ||
|
||
this.holder = holder; | ||
SwitchCompat btnSwitch = (SwitchCompat) holder.findViewById(android.R.id.toggle); | ||
// state stuff | ||
btnSwitch.setChecked(isChecked()); | ||
setEditTextEnabled(isChecked()); | ||
btnSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> setChecked(isChecked)); | ||
} | ||
|
||
@Override | ||
protected void onSetInitialValue(Object defaultValue) { | ||
setEditTextEnabled(isChecked()); | ||
} | ||
|
||
private void setChecked(boolean checked) { | ||
persistBoolean(checked); | ||
setEditTextEnabled(checked); | ||
} | ||
|
||
private boolean isChecked() { | ||
return getPersistedBoolean(false); | ||
} | ||
|
||
private void setEditTextEnabled(boolean enabled) { | ||
if (holder != null) { | ||
holder.itemView.setEnabled(enabled); | ||
holder.findViewById(android.R.id.title).setEnabled(enabled); | ||
holder.findViewById(android.R.id.summary).setEnabled(enabled); | ||
} | ||
} | ||
|
||
@Override | ||
protected boolean persistBoolean(boolean value) { | ||
if (!shouldPersist()) { | ||
return false; | ||
} | ||
|
||
// It's already there, so the same as persisting | ||
if (value == isChecked()) { | ||
return true; | ||
} | ||
|
||
PreferenceDataStore dataStore = getPreferenceDataStore(); | ||
if (dataStore != null) { | ||
dataStore.putBoolean(KEY_SWITCH, value); | ||
} else { | ||
getPreferenceManager() | ||
.getSharedPreferences() | ||
.edit() | ||
.putBoolean(KEY_SWITCH, value) | ||
.apply(); | ||
} | ||
callChangeListener(value); | ||
return true; | ||
} | ||
|
||
@Override | ||
protected boolean getPersistedBoolean(boolean defaultReturnValue) { | ||
if (!shouldPersist()) { | ||
return defaultReturnValue; | ||
} | ||
|
||
PreferenceDataStore dataStore = getPreferenceDataStore(); | ||
if (dataStore != null) { | ||
return dataStore.getBoolean(KEY_SWITCH, defaultReturnValue); | ||
} else { | ||
return getPreferenceManager() | ||
.getSharedPreferences() | ||
.getBoolean(KEY_SWITCH, defaultReturnValue); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.