Commit 548ba255 authored by cfabio's avatar cfabio

Redesigned period setting in Settings Activity

parent 2a8d9cb2
......@@ -5,10 +5,10 @@ android {
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "eu.uwot.fabio.altcoinprices"
minSdkVersion 15
minSdkVersion 14
targetSdkVersion 25
versionCode 16
versionName '1.3.4'
versionCode 17
versionName '1.3.5'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
......
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":16},"path":"Altcoin Prices-release.apk","properties":{"packageId":"eu.uwot.fabio.altcoinprices","split":"","minSdkVersion":"15"}}]
\ No newline at end of file
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":17},"path":"Altcoin Prices-release.apk","properties":{"packageId":"eu.uwot.fabio.altcoinprices","split":"","minSdkVersion":"14"}}]
\ No newline at end of file
......@@ -3,38 +3,39 @@ package eu.uwot.fabio.altcoinprices;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Switch;
import android.widget.TextView;
public class SettingsActivity extends AppCompatActivity {
public class SettingsActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
SharedPreferences prefs;
SharedPreferences.Editor editor;
Switch currencySwitch;
String currency;
EditText periodInput;
Spinner periodSpinner;
String period;
String DEFAULT_PERIOD = "60";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
/* load user settings */
// load user settings //
prefs = getApplicationContext().getSharedPreferences("Settings", 0); // 0 for private mode
editor = prefs.edit();
this.currency = prefs.getString("currency", "EUR");
this.period = prefs.getString("period", "15");
editor.commit();
/* end load user settings */
this.period = prefs.getString("period", DEFAULT_PERIOD);
/* currency switch */
// currency switch //
currencySwitch = (Switch) findViewById(R.id.currency_switch);
currencySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
......@@ -57,42 +58,128 @@ public class SettingsActivity extends AppCompatActivity {
} else {
currencySwitch.setChecked(true);
}
/* end currency switch */
/* set candlestick period */
periodInput = (EditText)findViewById(R.id.periodInput);
periodInput.setText(this.period);
// set candlestick period //
periodSpinner = (Spinner) findViewById(R.id.period_spinner);
// Create an ArrayAdapter using the string array and a default altcoinNameSpinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.period_array, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the altcoinNameSpinner
periodSpinner.setAdapter(adapter);
periodSpinner.setOnItemSelectedListener(this);
periodInput.addTextChangedListener(new TextWatcher() {
// Preload spinner with current period setting
String spinnerLabel = periodToLabel(period);
int spinnerPosition = adapter.getPosition(spinnerLabel);
periodSpinner.setSelection(spinnerPosition);
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// empty
}
// about text - makes links clicable //
TextView aboutText = (TextView) findViewById(R.id.about);
aboutText.setMovementMethod(LinkMovementMethod.getInstance());
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// empty
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
period = periodSpinner.getSelectedItem().toString();
@Override
public void afterTextChanged(Editable s) {
period = periodInput.getText().toString();
if (period.equals("")) {
editor.putString("period", "30");
editor.commit();
} else {
editor.putString("period", period);
editor.commit();
}
//Log.d("DEBUG", "period: " + period);
}
});
/* end set candlestick period */
switch (period) {
case "1 minute":
period = "1";
break;
case "3 minutes":
period = "3";
break;
case "5 minutes":
period = "5";
break;
case "15 minutes":
period = "15";
break;
case "30 minutes":
period = "30";
break;
case "1 hour":
period = "60";
break;
case "2 hours":
period = "120";
break;
case "3 hours":
period = "180";
break;
case "4 hours":
period = "240";
break;
case "1 day":
period = "D";
break;
case "1 week":
period = "W";
break;
case "1 month":
period = "M";
break;
default:
period = DEFAULT_PERIOD;
break;
}
/* about text - makes links clicable */
TextView aboutText = (TextView) findViewById(R.id.about);
aboutText.setMovementMethod(LinkMovementMethod.getInstance());
/* end about text */
editor.putString("period", period);
editor.commit();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
private String periodToLabel(String period) {
String label = "";
switch (period) {
case "1":
label = "1 minute";
break;
case "3":
label = "3 minutes";
break;
case "5":
label = "5 minutes";
break;
case "15":
label = "15 minute";
break;
case "30":
label = "30 minutes";
break;
case "60":
label = "1 hour";
break;
case "120":
label = "2 hour";
break;
case "180":
label = "3 hour";
break;
case "240":
label = "4 hour";
break;
case "D":
label = "1 day";
break;
case "W":
label = "1 week";
break;
case "M":
label = "1 month";
break;
default:
label = DEFAULT_PERIOD;
break;
}
return label;
}
}
......@@ -23,10 +23,9 @@
<TextView
android:id="@+id/periodDescription"
android:layout_width="236dp"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:paddingTop="7dp"
android:text="@string/periodDescription"
......@@ -34,17 +33,15 @@
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/currency_switch" />
<EditText
android:id="@+id/periodInput"
android:layout_width="100dp"
android:layout_height="40dp"
<Spinner
android:id="@+id/period_spinner"
android:layout_width="150dp"
android:layout_height="32dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="numberSigned"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/currency_switch" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/currency_switch"
android:layout_marginRight="8dp" />
<TextView
android:id="@+id/about"
......@@ -52,13 +49,11 @@
android:layout_height="254dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="@string/about_text"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/periodDescription" />
</android.support.constraint.ConstraintLayout>
......@@ -9,14 +9,14 @@
<string name="menu_title">Altcoin Prices</string>
<string name="menu_subtitle">Monitor crypto prices in real time</string>
<string name="periodDescription">Set candlestick period in minutes</string>
<string name="periodDescription">Set candlestick period</string>
<string name="periodInput">Minutes</string>
<string name="switch_currency_title">Switch currency from EUR to USD</string>
<string name="about_text">Android application to monitor cryptocurrencies prices in real time.
\nGet the full source code at <a href="https://gitlab.com/cfabio/AltcoinPrices">gitlab.com</a>
\n\n<b>Version 1.3.4</b></string>
\n\n<b>Version 1.3.5</b></string>
<string name="title_activity_portfolio">Portfolio</string>
<string name="title_activity_add_portfolio_item">Add new Altcoin</string>
......@@ -48,4 +48,19 @@
<item>XVG - Verge/USDT</item>
</string-array>
<string-array name="period_array">
<item>1 minute</item>
<item>3 minutes</item>
<item>5 minutes</item>
<item>15 minutes</item>
<item>30 minutes</item>
<item>1 hour</item>
<item>2 hours</item>
<item>3 hours</item>
<item>4 hours</item>
<item>1 day</item>
<item>1 week</item>
<item>1 month</item>
</string-array>
</resources>
......@@ -15,6 +15,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
.:. CHANGELOG
- Version 1.3.5
Redesigned period setting in Settings Activity
- Version 1.3.4
Fix a bug in unit price calculation when switching global currency
and subsequenty adding a cryptocurrency that was already
......
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