aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.idea/deploymentTargetDropDown.xml39
-rw-r--r--app/src/main/java/com/jopek/taupngamoni/Currency.java32
-rw-r--r--app/src/main/java/com/jopek/taupngamoni/HomeFragment.java64
-rw-r--r--app/src/main/java/com/jopek/taupngamoni/HomeRecyclerAdapter.java58
-rw-r--r--app/src/main/java/com/jopek/taupngamoni/MainActivity.java15
-rw-r--r--app/src/main/res/layout/fragment_screen_home.xml61
-rw-r--r--app/src/main/res/layout/fragment_screen_home_list.xml8
-rw-r--r--app/src/main/res/layout/spinner_item.xml3
8 files changed, 206 insertions, 74 deletions
diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
new file mode 100644
index 0000000..0fe15b4
--- /dev/null
+++ b/.idea/deploymentTargetDropDown.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="deploymentTargetDropDown">
+ <targetSelectedWithDropDown>
+ <Target>
+ <type value="QUICK_BOOT_TARGET" />
+ <deviceKey>
+ <Key>
+ <type value="VIRTUAL_DEVICE_PATH" />
+ <value value="$USER_HOME$/.config/android/.android/avd/Samsung_S9_API_28.avd" />
+ </Key>
+ </deviceKey>
+ </Target>
+ </targetSelectedWithDropDown>
+ <timeTargetWasSelectedWithDropDown value="2022-10-11T20:12:36.180808Z" />
+ <runningDeviceTargetsSelectedWithDialog>
+ <Target>
+ <type value="RUNNING_DEVICE_TARGET" />
+ <deviceKey>
+ <Key>
+ <type value="SERIAL_NUMBER" />
+ <value value="290c726c731c7ece" />
+ </Key>
+ </deviceKey>
+ </Target>
+ </runningDeviceTargetsSelectedWithDialog>
+ <targetsSelectedWithDialog>
+ <Target>
+ <type value="QUICK_BOOT_TARGET" />
+ <deviceKey>
+ <Key>
+ <type value="VIRTUAL_DEVICE_PATH" />
+ <value value="$USER_HOME$/.config/android/.android/avd/Samsung_S9_API_28.avd" />
+ </Key>
+ </deviceKey>
+ </Target>
+ </targetsSelectedWithDialog>
+ </component>
+</project> \ No newline at end of file
diff --git a/app/src/main/java/com/jopek/taupngamoni/Currency.java b/app/src/main/java/com/jopek/taupngamoni/Currency.java
new file mode 100644
index 0000000..e6c0779
--- /dev/null
+++ b/app/src/main/java/com/jopek/taupngamoni/Currency.java
@@ -0,0 +1,32 @@
+package com.jopek.taupngamoni;
+
+import android.graphics.Bitmap;
+
+public class Currency {
+ public String code;
+ public String description;
+ public Bitmap img;
+ public String symbol;
+ public double conversionFactor;
+ public Currency conversionTo;
+
+ public Currency(String code, String description, Bitmap img, String symbol, double conversionFactor, Currency conversionTo) {
+ this.code = code;
+ this.description = description;
+ this.img = img;
+ this.symbol = symbol;
+ this.conversionFactor = conversionFactor;
+ this.conversionTo = conversionTo;
+ }
+
+ public static final Currency USD = new Currency("USD", "United States Dollar", null, "$", 0.0, null);
+ public static final Currency GBP = new Currency("GBP", "British Pound Sterling", null, "£", 2.123, null);
+ public static final Currency CHF = new Currency("CHF", "Swiss Franc", null, "Fr", 0.0, null);
+ public static final Currency PLN = new Currency("PLN", "Polish Zloty", null, "zł", 0.0, null);
+ public static final Currency EUR = new Currency("EUR", "Euro", null, "€", 0.0, null);
+ public static final Currency JPY = new Currency("JPY", "Japanese Yen", null, "¥", 0.0, null);
+ public static final Currency CNY = new Currency("CNY", "Chinese Yuan", null, "¥", 0.0, null);
+ public static final Currency UAH = new Currency("UAH", "Ukrainian Hryvnia", null, "₴", 0.0, null);
+ public static final Currency CZK = new Currency("CZK", "Czech Republic Koruna", null, "Kč", 0.0, null);
+ public static final Currency TWD = new Currency("TWD", "New Taiwan Dollar", null, "圓", 0.0, null);
+}
diff --git a/app/src/main/java/com/jopek/taupngamoni/HomeFragment.java b/app/src/main/java/com/jopek/taupngamoni/HomeFragment.java
index 604e337..9a25328 100644
--- a/app/src/main/java/com/jopek/taupngamoni/HomeFragment.java
+++ b/app/src/main/java/com/jopek/taupngamoni/HomeFragment.java
@@ -1,8 +1,10 @@
package com.jopek.taupngamoni;
+import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -29,6 +31,10 @@ public class HomeFragment extends Fragment implements AdapterView.OnItemSelected
// TODO: Customize parameters
private int mColumnCount = 1;
private ArrayList<Currency> currencies = new ArrayList<>();
+ private ArrayList<Currency> selectedCurrencies = new ArrayList<>();
+ private HomeRecyclerAdapter recyclerAdapter = new HomeRecyclerAdapter(selectedCurrencies);
+ private RecyclerView recyclerView;
+ private Currency selectedCurrency = Currency.USD;
private MySpinnerAdapter spinnerAdapter;
private Spinner spinner;
@@ -52,26 +58,31 @@ public class HomeFragment extends Fragment implements AdapterView.OnItemSelected
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- currencies.add(new Currency("USD", "United States Dollar", null));
- currencies.add(new Currency("GBP", "British Pound Sterling", null));
- currencies.add(new Currency("CHF", "Swiss Franc", null));
- currencies.add(new Currency("PLN", "Polish Zloty", null));
- currencies.add(new Currency("EUR", "Euro", null));
- currencies.add(new Currency("JPY", "Japanese Yen", null));
- currencies.add(new Currency("CNY", "Chinese Yuan", null));
- currencies.add(new Currency("UAH", "Ukrainian Hryvnia", null));
- currencies.add(new Currency("CZK", "Czech Republic Koruna", null));
- currencies.add(new Currency("TWD", "New Taiwan Dollar", null));
+ currencies.add(Currency.USD);
+ currencies.add(Currency.GBP);
+ currencies.add(Currency.CHF);
+ currencies.add(Currency.PLN);
+ currencies.add(Currency.EUR);
+ currencies.add(Currency.JPY);
+ currencies.add(Currency.CNY);
+ currencies.add(Currency.UAH);
+ currencies.add(Currency.CZK);
+ currencies.add(Currency.TWD);
+
+ selectedCurrencies.add(Currency.USD);
+ selectedCurrencies.add(Currency.GBP);
+ selectedCurrencies.add(Currency.PLN);
- ArrayList<Currency> currenciesCopy = (ArrayList<Currency>) currencies.clone();
for (int i = 0; i < currencies.size(); i++) {
Currency cur = currencies.get(i);
RequestImage requestImage = new RequestImage();
int finalI = i;
requestImage.getBitmap("https://wise.com/public-resources/assets/flags/rectangle/" + cur.code.toLowerCase() + ".png", bitmap -> {
cur.img = bitmap;
+ cur.conversionTo = Currency.USD;
if (finalI + 1 == currencies.size()) {
spinner.setAdapter(spinnerAdapter);
+ recyclerAdapter.notifyDataSetChanged();
}
});
}
@@ -87,26 +98,21 @@ public class HomeFragment extends Fragment implements AdapterView.OnItemSelected
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_screen_home_list, container, false);
+ RecyclerView recyclerView = view.findViewById(R.id.list);
+ Log.d("maks", "onCreateView: " + view + container + recyclerView);
spinner = view.findViewById(R.id.spinner);
spinner.setOnItemSelectedListener(this);
-// spinner.setAdapter(spinnerAdapter);
- //Creating the ArrayAdapter instance having the country list
- // ArrayAdapter aa = new ArrayAdapter(requireContext(), R.layout.spinner_item, currenciesCodes.toArray(new String[0]));
- // aa.setDropDownViewResource(R.layout.spinner_item);
- // Setting the ArrayAdapter data on the Spinner
- // spin.setAdapter(new MySpinnerAdapter(requireContext(), currenciesCodes));
- // Set the adapter
- if (view instanceof RecyclerView) {
+ if (recyclerView instanceof RecyclerView) {
Context context = view.getContext();
- RecyclerView recyclerView = (RecyclerView) view;
+// recyclerView = (RecyclerView) view;
if (mColumnCount <= 1) {
recyclerView.setLayoutManager(new LinearLayoutManager(context));
} else {
recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount));
}
- recyclerView.setAdapter(new HomeRecyclerAdapter(PlaceholderContent.ITEMS));
+ recyclerView.setAdapter(recyclerAdapter);
}
return view;
}
@@ -115,6 +121,10 @@ public class HomeFragment extends Fragment implements AdapterView.OnItemSelected
@Override
public void onItemSelected(AdapterView<?> arg0, View view, int position, long id) {
Toast.makeText(requireContext(), currencies.get(position).code, Toast.LENGTH_LONG).show();
+ for (Currency cur: selectedCurrencies) {
+ cur.conversionTo = currencies.get(position);
+ }
+ recyclerAdapter.notifyDataSetChanged();
}
@Override
@@ -122,15 +132,3 @@ public class HomeFragment extends Fragment implements AdapterView.OnItemSelected
// TODO Auto-generated method stub
}
}
-
-class Currency {
- public String code;
- public String description;
- public Bitmap img;
-
- public Currency(String code, String description, Bitmap img) {
- this.code = code;
- this.description = description;
- this.img = img;
- }
-} \ No newline at end of file
diff --git a/app/src/main/java/com/jopek/taupngamoni/HomeRecyclerAdapter.java b/app/src/main/java/com/jopek/taupngamoni/HomeRecyclerAdapter.java
index 43fcad2..40c9614 100644
--- a/app/src/main/java/com/jopek/taupngamoni/HomeRecyclerAdapter.java
+++ b/app/src/main/java/com/jopek/taupngamoni/HomeRecyclerAdapter.java
@@ -1,61 +1,81 @@
package com.jopek.taupngamoni;
-import androidx.recyclerview.widget.RecyclerView;
-
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.ViewGroup;
+import android.widget.ImageView;
import android.widget.TextView;
-import com.jopek.taupngamoni.placeholder.PlaceholderContent.PlaceholderItem;
+import androidx.recyclerview.widget.RecyclerView;
+
import com.jopek.taupngamoni.databinding.FragmentScreenHomeBinding;
+import com.jopek.taupngamoni.placeholder.PlaceholderContent.PlaceholderItem;
import java.util.List;
/**
- * {@link RecyclerView.Adapter} that can display a {@link PlaceholderItem}.
+ * {@link RecyclerView.Adapter} that can display a {@link Currency}.
* TODO: Replace the implementation with code for your data type.
*/
public class HomeRecyclerAdapter extends RecyclerView.Adapter<HomeRecyclerAdapter.ViewHolder> {
- private final List<PlaceholderItem> mValues;
+ private final List<Currency> currencies;
- public HomeRecyclerAdapter(List<PlaceholderItem> items) {
- mValues = items;
+ public HomeRecyclerAdapter(List<Currency> items) {
+ currencies = items;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
-
+ Log.d("maks", "onCreateViewHolder: " + parent);
return new ViewHolder(FragmentScreenHomeBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
-
}
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
- holder.mItem = mValues.get(position);
- holder.mIdView.setText(mValues.get(position).id);
- holder.mContentView.setText(mValues.get(position).content);
+ Currency item = currencies.get(position);
+ holder.mItem = item;
+ holder.img.setImageBitmap(item.img);
+ holder.code.setText(item.code);
+ holder.description.setText(item.description);
+ String valueToForeign;
+ String oneToForeign;
+ try {
+ valueToForeign = item.conversionTo.symbol + MainActivity.round(1 / item.conversionFactor, 4);
+ oneToForeign = "1 " + item.code + " = " + item.conversionFactor + " " + item.conversionTo.code;
+ } catch (NullPointerException exception) {
+ valueToForeign = "Error";
+ oneToForeign = "Error";
+ }
+ holder.valueToForeign.setText(valueToForeign);
+ holder.oneToForeign.setText(oneToForeign);
}
@Override
public int getItemCount() {
- return mValues.size();
+ return currencies.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
- public final TextView mIdView;
- public final TextView mContentView;
- public PlaceholderItem mItem;
+ public final ImageView img;
+ public final TextView code;
+ public final TextView description;
+ public final TextView valueToForeign;
+ public final TextView oneToForeign;
+ public Currency mItem;
public ViewHolder(FragmentScreenHomeBinding binding) {
super(binding.getRoot());
- mIdView = binding.itemNumber;
- mContentView = binding.content;
+ img = binding.img;
+ code = binding.code;
+ description = binding.description;
+ valueToForeign = binding.valueToForeign;
+ oneToForeign = binding.oneToForeign;
}
@Override
public String toString() {
- return super.toString() + " '" + mContentView.getText() + "'";
+ return super.toString() + " '" + code.getText() + "'";
}
}
} \ No newline at end of file
diff --git a/app/src/main/java/com/jopek/taupngamoni/MainActivity.java b/app/src/main/java/com/jopek/taupngamoni/MainActivity.java
index 5d30048..dc33dfe 100644
--- a/app/src/main/java/com/jopek/taupngamoni/MainActivity.java
+++ b/app/src/main/java/com/jopek/taupngamoni/MainActivity.java
@@ -8,6 +8,10 @@ import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.MenuItem;
+import java.math.RoundingMode;
+import java.text.DecimalFormat;
+import java.util.Collections;
+
public class MainActivity extends AppCompatActivity implements BottomNavigationView.OnItemSelectedListener {
public static final String TAG = "maks";
@@ -40,13 +44,10 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationV
}
return false;
}
-}
-class Tuple<X, Y> {
- public final X x;
- public final Y y;
- public Tuple(X x, Y y) {
- this.x = x;
- this.y = y;
+ public static String round(double num, int nPlaces) {
+ DecimalFormat df = new DecimalFormat("#." + String.join("", Collections.nCopies(nPlaces, "#")));
+ df.setRoundingMode(RoundingMode.CEILING);
+ return df.format(num);
}
}
diff --git a/app/src/main/res/layout/fragment_screen_home.xml b/app/src/main/res/layout/fragment_screen_home.xml
index 1877568..1758dbe 100644
--- a/app/src/main/res/layout/fragment_screen_home.xml
+++ b/app/src/main/res/layout/fragment_screen_home.xml
@@ -1,20 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
- <TextView
- android:id="@+id/item_number"
+ <ImageView
+ android:id="@+id/img"
+ android:scaleType="centerCrop"
+ android:layout_gravity="center"
+ android:layout_width="40dp"
+ android:layout_height="30dp"/>
+ <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_margin="@dimen/text_margin"
- android:textAppearance="?attr/textAppearanceListItem" />
-
- <TextView
- android:id="@+id/content"
+ android:layout_marginStart="15dp"
+ android:orientation="vertical">
+ <TextView
+ android:id="@+id/code"
+ android:text="USD"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="21sp"
+ android:textAppearance="?attr/textAppearanceListItem" />
+ <TextView
+ android:id="@+id/description"
+ android:text="United States Dollar"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?attr/textAppearanceListItem" />
+ </LinearLayout>
+ <View
+ android:layout_width="0dp"
+ android:layout_height="0dp"
+ android:layout_weight="1"
+ />
+ <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_margin="@dimen/text_margin"
- android:textAppearance="?attr/textAppearanceListItem" />
+ android:layout_gravity="right"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@+id/valueToForeign"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="right"
+ android:text="$1.3015"
+ android:textAppearance="?attr/textAppearanceListItem"
+ android:textSize="21sp"
+ android:textStyle="bold" />
+
+ <TextView
+ android:id="@+id/oneToForeign"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="right"
+ android:text="1 USD = 1.3015 CAD"
+ android:textAppearance="?attr/textAppearanceListItem" />
+ </LinearLayout>
</LinearLayout> \ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_screen_home_list.xml b/app/src/main/res/layout/fragment_screen_home_list.xml
index 53ce2a3..32d2ab3 100644
--- a/app/src/main/res/layout/fragment_screen_home_list.xml
+++ b/app/src/main/res/layout/fragment_screen_home_list.xml
@@ -31,11 +31,11 @@
<TextView
android:layout_width="wrap_content"
android:background="@color/teal_700"
- android:text="+"
+ android:text="Add new currency to list"
android:id="@+id/btn_add"
android:textSize="25sp"
- android:paddingLeft="5dp"
- android:paddingRight="5dp"
+ android:paddingLeft="7dp"
+ android:paddingRight="7dp"
android:layout_gravity="center"
android:layout_height="wrap_content"/>
@@ -44,7 +44,7 @@
android:id="@+id/list"
android:name="com.jopek.taupngamoni.ScreenHome"
android:layout_width="match_parent"
- android:layout_height="match_parent"
+ android:layout_height="0dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
diff --git a/app/src/main/res/layout/spinner_item.xml b/app/src/main/res/layout/spinner_item.xml
index b545f45..c96b159 100644
--- a/app/src/main/res/layout/spinner_item.xml
+++ b/app/src/main/res/layout/spinner_item.xml
@@ -2,7 +2,8 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:paddingBottom="15dp"
+ android:paddingTop="7dp"
+ android:paddingBottom="7dp"
android:orientation="horizontal">
<ImageView