Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
android_20250623
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
android_20250623
Commits
da0f1c5b
Commit
da0f1c5b
authored
Jun 24, 2025
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pobieranie walut wdrożone do aplikacji
parent
cc32734e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
97 additions
and
27 deletions
+97
-27
AndroidManifest.xml
Projekt4/app/src/main/AndroidManifest.xml
+2
-0
FirstFragment.java
...app/src/main/java/com/example/projekt4/FirstFragment.java
+47
-1
ObslugaNBP.java
...ekt4/app/src/main/java/com/example/waluty/ObslugaNBP.java
+1
-1
fragment_first.xml
Projekt4/app/src/main/res/layout/fragment_first.xml
+44
-25
strings.xml
Projekt4/app/src/main/res/values/strings.xml
+3
-0
No files found.
Projekt4/app/src/main/AndroidManifest.xml
View file @
da0f1c5b
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
>
xmlns:tools=
"http://schemas.android.com/tools"
>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<application
<application
android:allowBackup=
"true"
android:allowBackup=
"true"
android:dataExtractionRules=
"@xml/data_extraction_rules"
android:dataExtractionRules=
"@xml/data_extraction_rules"
...
...
Projekt4/app/src/main/java/com/example/projekt4/FirstFragment.java
View file @
da0f1c5b
package
com
.
example
.
projekt4
;
package
com
.
example
.
projekt4
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.ViewGroup
;
import
android.widget.LinearLayout
;
import
android.widget.TextView
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.NonNull
;
import
androidx.fragment.app.Fragment
;
import
androidx.fragment.app.Fragment
;
import
androidx.navigation.fragment.NavHostFragment
;
import
androidx.navigation.fragment.NavHostFragment
;
import
com.example.projekt4.databinding.FragmentFirstBinding
;
import
com.example.projekt4.databinding.FragmentFirstBinding
;
import
com.example.waluty.ExchangeRatesTable
;
import
com.example.waluty.ObslugaNBP
;
import
com.example.waluty.Rate
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
public
class
FirstFragment
extends
Fragment
{
public
class
FirstFragment
extends
Fragment
{
private
ExecutorService
watkiPobierajace
=
Executors
.
newSingleThreadExecutor
();
// albo fixedThreadPool
private
FragmentFirstBinding
binding
;
private
FragmentFirstBinding
binding
;
...
@@ -20,7 +30,6 @@ public class FirstFragment extends Fragment {
...
@@ -20,7 +30,6 @@ public class FirstFragment extends Fragment {
@NonNull
LayoutInflater
inflater
,
ViewGroup
container
,
@NonNull
LayoutInflater
inflater
,
ViewGroup
container
,
Bundle
savedInstanceState
Bundle
savedInstanceState
)
{
)
{
binding
=
FragmentFirstBinding
.
inflate
(
inflater
,
container
,
false
);
binding
=
FragmentFirstBinding
.
inflate
(
inflater
,
container
,
false
);
return
binding
.
getRoot
();
return
binding
.
getRoot
();
...
@@ -33,6 +42,43 @@ public class FirstFragment extends Fragment {
...
@@ -33,6 +42,43 @@ public class FirstFragment extends Fragment {
NavHostFragment
.
findNavController
(
FirstFragment
.
this
)
NavHostFragment
.
findNavController
(
FirstFragment
.
this
)
.
navigate
(
R
.
id
.
action_FirstFragment_to_SecondFragment
)
.
navigate
(
R
.
id
.
action_FirstFragment_to_SecondFragment
)
);
);
binding
.
buttonPobierzBiezace
.
setOnClickListener
(
v
->
{
wykonajCalePobieranie
();
});
}
private
void
wykonajCalePobieranie
()
{
Log
.
d
(
"Waluty"
,
"pobieranie rozpoczęte"
);
// komunikacji sieciowej nie wolno robić w wątku głównym
watkiPobierajace
.
submit
(()
->
{
Log
.
d
(
"Waluty"
,
"a kuku 1"
);
ExchangeRatesTable
table
=
ObslugaNBP
.
pobierzBiezaceKursy
();
Log
.
d
(
"Waluty"
,
"a kuku 2"
);
// jednak zmiany w wyglądzie UI powinny być wykonane przez wątek główny
this
.
getActivity
().
runOnUiThread
(()
->
{
odswiezWidok
(
table
);
});
});
Log
.
d
(
"Waluty"
,
"pobieranie zlecone"
);
}
private
void
odswiezWidok
(
ExchangeRatesTable
table
)
{
Log
.
d
(
"Waluty"
,
"odswiezWidok"
);
// gdy mamy binding, nie trzeba już find
TextView
textViewStatus
=
binding
.
textViewStatus
;
LinearLayout
ll
=
binding
.
linearLayoutWaluty
;
if
(
table
==
null
)
{
textViewStatus
.
setText
(
R
.
string
.
brak_danych
);
}
else
{
textViewStatus
.
setText
(
table
.
toString
());
ll
.
removeAllViews
();
for
(
Rate
rate
:
table
.
getRates
())
{
TextView
textView
=
new
TextView
(
this
.
getContext
());
textView
.
setText
(
rate
.
toString
());
ll
.
addView
(
textView
);
}
}
}
}
@Override
@Override
...
...
Projekt4/app/src/main/java/com/example/waluty/ObslugaNBP.java
View file @
da0f1c5b
...
@@ -20,7 +20,7 @@ import org.w3c.dom.NodeList;
...
@@ -20,7 +20,7 @@ import org.w3c.dom.NodeList;
import
org.xml.sax.SAXException
;
import
org.xml.sax.SAXException
;
public
class
ObslugaNBP
{
public
class
ObslugaNBP
{
private
static
final
String
ADRES
=
"http://api.nbp.pl/api/exchangerates/tables"
;
private
static
final
String
ADRES
=
"http
s
://api.nbp.pl/api/exchangerates/tables"
;
/** Pobiera tabelę z bieżącymi kursami walut.
/** Pobiera tabelę z bieżącymi kursami walut.
* Zwraca null w przypadku błędów.
* Zwraca null w przypadku błędów.
...
...
Projekt4/app/src/main/res/layout/fragment_first.xml
View file @
da0f1c5b
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<androidx.co
re.widget.NestedScrollView
xmlns:android=
"http://schemas.android.com/apk/res/android"
<androidx.co
nstraintlayout.widget.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
tools:context=
".FirstFragment"
>
tools:context=
".FirstFragment"
>
<androidx.constraintlayout.widget.ConstraintLayout
<Button
android:id=
"@+id/button_pobierz_biezace"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"@string/pobierz"
app:layout_constraintEnd_toStartOf=
"@id/button_first"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
<Button
android:id=
"@+id/button_first"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"@string/next"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toEndOf=
"@id/button_pobierz_biezace"
app:layout_constraintTop_toTopOf=
"parent"
/>
<TextView
android:id=
"@+id/text_view_status"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"wrap_content"
android:padding=
"16dp"
>
android:layout_marginTop=
"16dp"
android:text=
"status"
android:textAlignment=
"center"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/button_pobierz_biezace"
/>
<Button
<ScrollView
android:id=
"@+id/button_firs
t"
android:id=
"@+id/scroll_lista_walu
t"
android:layout_width=
"wrap_cont
ent"
android:layout_width=
"match_par
ent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"@string/next
"
android:layout_marginTop=
"24dp
"
app:layout_constraintBottom_toTopOf=
"@id/textview_firs
t"
app:layout_constraintBottom_toBottomOf=
"paren
t"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/
>
app:layout_constraintTop_toBottomOf=
"@+id/text_view_status"
>
<
TextView
<
LinearLayout
android:id=
"@+id/
textview_first
"
android:id=
"@+id/
linear_layout_waluty
"
android:layout_width=
"
wrap_cont
ent"
android:layout_width=
"
match_par
ent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"16dp"
android:orientation=
"vertical"
/>
android:text=
"@string/lorem_ipsum"
</ScrollView>
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
</androidx.constraintlayout.widget.ConstraintLayout>
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@id/button_first"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
\ No newline at end of file
Projekt4/app/src/main/res/values/strings.xml
View file @
da0f1c5b
...
@@ -43,4 +43,6 @@
...
@@ -43,4 +43,6 @@
libero vel nunc consequat, quis tincidunt nisl eleifend. Cras bibendum enim a justo luctus
libero vel nunc consequat, quis tincidunt nisl eleifend. Cras bibendum enim a justo luctus
vestibulum. Fusce dictum libero quis erat maximus, vitae volutpat diam dignissim.
vestibulum. Fusce dictum libero quis erat maximus, vitae volutpat diam dignissim.
</string>
</string>
<string
name=
"pobierz"
>
Pobierz bieżące
</string>
<string
name=
"brak_danych"
>
Brak danych
</string>
</resources>
</resources>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment