diff options
author | TAMARA JERINIC <tamara.jerinic@gmail.com> | 2022-11-13 00:14:29 +0100 |
---|---|---|
committer | TAMARA JERINIC <tamara.jerinic@gmail.com> | 2022-11-13 00:15:21 +0100 |
commit | b562a184aea115ab898b6efc0de7675a5ee61b31 (patch) | |
tree | 61af993c1eb3f1bcfff240a25650cbb3ec4d2ae1 | |
parent | aca399bfec3542f34897979bed77f4de8a5531fe (diff) |
Dodato prikupljanje i sortiranje objava za početnu stranu. Dodata početna strana u navigacioni meni. Izmenjen fragment za prikaz.
7 files changed, 247 insertions, 104 deletions
diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/NavigationActivity.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/NavigationActivity.kt index c2997ee..78822ab 100644 --- a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/NavigationActivity.kt +++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/NavigationActivity.kt @@ -24,6 +24,7 @@ class NavigationActivity : AppCompatActivity() { Toast.makeText( applicationContext, "Open ", Toast.LENGTH_LONG ).show(); + val fragmentHomePage=FragmentHomePage() val fragmentShowPosts=FragmentShowPosts() val browseFragment=FragmentBrowse() val addPostFragment= FragmentAddNew() @@ -32,7 +33,8 @@ class NavigationActivity : AppCompatActivity() { setCurrentFragment(fragmentShowPosts) bottomNav.setOnNavigationItemSelectedListener { when(it.itemId){ - R.id.navHome->setCurrentFragment(fragmentShowPosts) + R.id.navHomePage->setCurrentFragment(fragmentHomePage) + R.id.navAllPosts->setCurrentFragment(fragmentShowPosts) //R.id.navAddPost->setCurrentFragment(addPostFragment) R.id.navAddPost->showBottomSheetAddNew() R.id.navBrowse->setCurrentFragment(browseFragment) diff --git a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentHomePage.kt b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentHomePage.kt index 7685296..59fa7ee 100644 --- a/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentHomePage.kt +++ b/Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentHomePage.kt @@ -1,60 +1,122 @@ package com.example.brzodolokacije.Fragments +import android.media.CamcorderProfile.getAll import android.os.Bundle +import android.util.Log import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.Button +import android.widget.Toast +import com.example.brzodolokacije.Interfaces.IBackendApi +import com.example.brzodolokacije.Models.PostPreview import com.example.brzodolokacije.R +import com.example.brzodolokacije.Services.RetrofitHelper.baseUrl +import com.example.brzodolokacije.Services.SharedPreferencesHelper +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response +import retrofit2.Retrofit +import retrofit2.converter.gson.GsonConverterFactory -// TODO: Rename parameter arguments, choose names that match -// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER -private const val ARG_PARAM1 = "param1" -private const val ARG_PARAM2 = "param2" - -/** - * A simple [Fragment] subclass. - * Use the [FragmentHomePage.newInstance] factory method to - * create an instance of this fragment. - */ class FragmentHomePage : Fragment() { - // TODO: Rename and change types of parameters - private var param1: String? = null - private var param2: String? = null - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - arguments?.let { - param1 = it.getString(ARG_PARAM1) - param2 = it.getString(ARG_PARAM2) - } - } + private lateinit var posts : MutableList<PostPreview> + private lateinit var mostViewedPosts : MutableList<PostPreview> + private lateinit var recommendedPosts : MutableList<PostPreview> + private lateinit var bestRatedPosts:MutableList<PostPreview> + + /* override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + }*/ override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_home_page, container, false) + var view:View= inflater.inflate(R.layout.fragment_home_page, container, false) + + + //pokupi sve objave iz baze + + /*Toast.makeText( + activity, "get all 1", Toast.LENGTH_LONG + ).show();*/ + getAllPosts() + //getMostViewedPosts() + //getRecommendedPosts() + //getBestRatedPosts() + + + + + return view } + private fun getAllPosts(){ + val api = Retrofit.Builder() + .addConverterFactory(GsonConverterFactory.create()) + .baseUrl(baseUrl) + .build() + .create(IBackendApi::class.java) + val token= SharedPreferencesHelper.getValue("jwt", requireActivity()) + val data=api.getPosts("Bearer "+token) + + data.enqueue(object : Callback<MutableList<PostPreview>>{ + override fun onResponse( + call: Call<MutableList<PostPreview>>, + response: Response<MutableList<PostPreview>> + ) { + if (response.body() == null) { + Toast.makeText( + activity, "get all null", Toast.LENGTH_LONG + ).show(); - companion object { - /** - * Use this factory method to create a new instance of - * this fragment using the provided parameters. - * - * @param param1 Parameter 1. - * @param param2 Parameter 2. - * @return A new instance of fragment FragmentHomePage. - */ - // TODO: Rename and change types and number of parameters - @JvmStatic - fun newInstance(param1: String, param2: String) = - FragmentHomePage().apply { - arguments = Bundle().apply { - putString(ARG_PARAM1, param1) - putString(ARG_PARAM2, param2) + return } + //refresh list + Toast.makeText( + activity, "get all ", Toast.LENGTH_LONG + ).show(); + posts = response.body()!!.toMutableList<PostPreview>() + getMostViewedPosts(posts) + getRecommendedPosts(posts) + getBestRatedPosts(posts) } + + override fun onFailure(call: Call<MutableList<PostPreview>>, t: Throwable) { + Toast.makeText( + activity,"nema objava", Toast.LENGTH_LONG + ).show(); + } + }) + } + + private fun getMostViewedPosts(allPosts:MutableList<PostPreview>){ + Toast.makeText( + activity, "get all mv ", Toast.LENGTH_LONG + ).show(); + mostViewedPosts=allPosts + mostViewedPosts.sortByDescending { it.views } + + } + private fun getRecommendedPosts(allPosts:MutableList<PostPreview>){ + Toast.makeText( + activity, "get all r ", Toast.LENGTH_LONG + ).show(); + recommendedPosts=allPosts + recommendedPosts.sortByDescending { it.ratings } } + + private fun getBestRatedPosts(allPosts:MutableList<PostPreview>){ + Toast.makeText( + activity, "get all br ", Toast.LENGTH_LONG + ).show(); + bestRatedPosts=allPosts + bestRatedPosts.sortByDescending { it.ratings } + } + + + }
\ No newline at end of file diff --git a/Client/BrzoDoLokacije/app/src/main/res/drawable/ic_baseline_list_24.xml b/Client/BrzoDoLokacije/app/src/main/res/drawable/ic_baseline_list_24.xml new file mode 100644 index 0000000..49f6624 --- /dev/null +++ b/Client/BrzoDoLokacije/app/src/main/res/drawable/ic_baseline_list_24.xml @@ -0,0 +1,5 @@ +<vector android:autoMirrored="true" android:height="24dp" + android:tint="#274352" android:viewportHeight="24" + android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> + <path android:fillColor="@android:color/white" android:pathData="M3,13h2v-2L3,11v2zM3,17h2v-2L3,15v2zM3,9h2L5,7L3,7v2zM7,13h14v-2L7,11v2zM7,17h14v-2L7,15v2zM7,7v2h14L21,7L7,7z"/> +</vector> diff --git a/Client/BrzoDoLokacije/app/src/main/res/drawable/ic_baseline_person_24.xml b/Client/BrzoDoLokacije/app/src/main/res/drawable/ic_baseline_person_24.xml new file mode 100644 index 0000000..a1623e2 --- /dev/null +++ b/Client/BrzoDoLokacije/app/src/main/res/drawable/ic_baseline_person_24.xml @@ -0,0 +1,10 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24" + android:viewportHeight="24" + android:tint="?attr/colorControlNormal"> + <path + android:fillColor="@android:color/white" + android:pathData="M12,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM12,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z"/> +</vector> diff --git a/Client/BrzoDoLokacije/app/src/main/res/drawable/location_lake.xml b/Client/BrzoDoLokacije/app/src/main/res/drawable/location_lake.xml new file mode 100644 index 0000000..65648f7 --- /dev/null +++ b/Client/BrzoDoLokacije/app/src/main/res/drawable/location_lake.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="61dp" + android:height="57dp" + android:viewportWidth="61" + android:viewportHeight="57"> + <path + android:fillColor="#FFFFFFFF" + android:strokeColor="#FF093A4C" + android:strokeWidth="1" + android:pathData="M2.5 10c0-5.25 4.25-9.5 9.5-9.5h37c5.25 0 9.5 4.25 9.5 9.5v37c0 5.25-4.25 9.5-9.5 9.5h-37c-5.25 0-9.5-4.25-9.5-9.5z"/> + <path + android:fillColor="#FF093A4C" + android:strokeColor="#FF093A4C" + android:strokeWidth="1" + android:pathData="M2.51 47.5H58.5c-0.26 5.01-4.41 9-9.49 9H12c-5.08 0-9.23-3.99-9.49-9Z"/> + <path + android:fillColor="#FF093A4C" + android:pathData="M33.12 4.62c-3.08-0.45-11.25 5.9-11.25 5.9l5.29 8.39 8.12 8.43 6.51 4.96 6.65 1.38 3.76 1.62H40.6l-22.74-2.84-1.61-4.73 3.3 1.1-2.67-5.44h4.15l-2.16-5.67 2.66-0.81 1.82-2.76-1.48-3.62s-1.5-1.36-2.11-1.34c-2.64 0.08-8 5.6-11.14 8.91-3.46 3.64-6.71 3.86-6.71 3.86v25.5h57.18V35.3h-5.41l-3.51-2.36-5.67-2.36 1.9-1.14-5.03-3-2.52-5.96 3.28 1.14L37.1 16h1.52l-2.2-3.57-0.85-5.53s-1.66-2.17-2.45-2.28m5.53 32.11c1.3 0.23 2.55 0.55 3.99-0.01 2.37-0.89 4.09 0.37 6.37 0.61-2.18 0.24-3.98-1-6.2-0.13-2.05 0.76-3.6-0.07-5.47-0.47h1.3M3.7 32.13l25.34 3.17H3.7v-3.17Zm11.43 5.1c-1.48 0.22-2.8-0.63-4.3-0.03-1.62 0.6-2.8-0.2-4.31-0.47h1.17c0.96 0.13 1.9 0.4 2.93 0h2.61c0.6 0.17 1.22 0.39 1.9 0.5m-3.62 8.23c-2.37 0.88-4.09-0.38-6.38-0.62 2.19-0.23 3.99 1 6.2 0.14 2.37-0.89 4.1 0.37 6.38 0.61-2.18 0.24-3.98-1-6.2-0.13m15.87-5.5c-1.61-0.15-2.9 0.26-4.41 0.68-2.78 0.76-4.8-0.74-7.42-1.17l0.28-0.03c1.32-0.13 2.42 0.36 3.72 0.49 1.61 0.15 2.9-0.26 4.41-0.68 2.78-0.76 4.8 0.74 7.42 1.17-1.45 0.24-2.6-0.32-4-0.45m13.1 3.88c-2.78 0.76-4.8-0.74-7.41-1.17l0.28-0.03c1.31-0.13 2.41 0.36 3.72 0.49 1.6 0.15 2.89-0.26 4.4-0.68 2.78-0.76 4.8 0.74 7.42 1.17-1.45 0.24-2.6-0.32-4-0.45-1.61-0.16-2.9 0.25-4.4 0.67M51.28 46c-2.37 0.88-4.08-0.37-6.37-0.62 2.18-0.23 3.98 1 6.2 0.14 2.37-0.89 4.1 0.37 6.38 0.61-2.19 0.24-3.99-1-6.2-0.13Zm6.37-5.99c-1.48 0.23-2.79-0.62-4.3-0.02-1.68 0.62-2.87-0.26-4.48-0.5 0.1-0.02 0.17-0.02 0.21-0.02 1.4-0.12 2.66 0.6 4.1 0.04 1.67-0.62 2.87 0.26 4.47 0.5"/> + <path + android:fillColor="#FF093A4C" + android:pathData="M40.6 14.48l4.96 9.19 5.03 6.91 1.1-0.85 1.38 1.19 6.02 2.43V16.62s-3.7-1.47-4.99-1.52c-0.8-0.04-3.13 0.66-3.13 0.66l4.98 5.34c-4.17-1.15-4.98-5.34-4.98-5.34s-1.86-1.13-2.54-1.33c-0.7-0.21-2.87-0.28-2.87-0.28L52.2 24.9c-5.67-0.86-4.7-7-6.64-10.75 0 0-1.49-2.79-2.29-3.34-0.74-0.52-2.65-0.31-3.43-0.76-0.91-0.53-2.04-2.72-3-3.15-0.29-0.13-1.26 0-1.26 0l3 5.05 2.03 2.53Z"/> +</vector>
\ No newline at end of file diff --git a/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_home_page.xml b/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_home_page.xml index 01c5f65..eda952d 100644 --- a/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_home_page.xml +++ b/Client/BrzoDoLokacije/app/src/main/res/layout/fragment_home_page.xml @@ -8,7 +8,6 @@ <!-- TODO: Update blank fragment layout --> - <androidx.recyclerview.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="0dp" @@ -25,24 +24,33 @@ android:layout_height="wrap_content" android:layout_marginStart="16dp" - android:layout_marginTop="48dp" - android:layout_marginEnd="100dp" + android:layout_marginTop="56dp" + android:layout_marginEnd="107dp" android:text="Zdravo, Mia" - app:layout_constraintEnd_toStartOf="@+id/imageButton" + app:layout_constraintEnd_toStartOf="@+id/cardView" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> - <ImageButton - android:id="@+id/imageButton" - android:layout_width="wrap_content" - android:layout_height="wrap_content" + <androidx.cardview.widget.CardView + android:id="@+id/cardView" + android:layout_width="85dp" + android:layout_height="85dp" + android:layout_gravity="center" android:layout_marginTop="24dp" android:layout_marginEnd="24dp" - - android:src="@mipmap/ic_launcher_round" + app:cardCornerRadius="250dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/textView8" - app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toTopOf="parent"> + + <ImageView + android:id="@+id/fup_profile_picture_id" + android:layout_width="85dp" + android:layout_height="85dp" + android:scaleType="centerCrop" + android:src="@drawable/ic_baseline_person_24" + tools:ignore="ContentDescription" /> + </androidx.cardview.widget.CardView> <TextView android:id="@+id/textView7" @@ -55,12 +63,12 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/imageButton" /> + app:layout_constraintTop_toBottomOf="@+id/cardView" /> <com.google.android.material.textfield.TextInputEditText android:id="@+id/editTextTextPersonName3" - android:layout_width="376dp" - android:layout_height="31dp" + android:layout_width="0dp" + android:layout_height="48dp" android:layout_marginStart="16dp" android:layout_marginTop="8dp" android:layout_marginEnd="16dp" @@ -89,61 +97,89 @@ <TextView android:id="@+id/textView11" - android:layout_width="wrap_content" - android:layout_height="wrap_content" + android:layout_width="64dp" + android:layout_height="19dp" android:layout_marginTop="36dp" android:layout_marginEnd="16dp" android:clickable="true" + android:minHeight="48dp" android:text="Prikaži sve" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintTop_toBottomOf="@+id/editTextTextPersonName3" /> + app:layout_constraintTop_toBottomOf="@+id/editTextTextPersonName3" + tools:ignore="TouchTargetSizeCheck" /> - <LinearLayout - android:id="@+id/linearLayout2" - android:layout_width="399dp" - android:layout_height="58dp" - android:layout_marginStart="16dp" - android:layout_marginTop="8dp" - android:orientation="horizontal" + <ScrollView + android:id="@+id/scrollview" + android:layout_width="match_parent" + android:layout_height="wrap_content" app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/recyclerView"> - <ImageButton - android:id="@+id/imageButton4" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_weight="1" - android:background='@color/white' - android:src="@drawable/location_beach" /> - - <ImageButton - android:id="@+id/imageButton6" - - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_weight="1" - android:background='@color/white' - android:src="@drawable/location_mountain" /> - - <ImageButton - android:id="@+id/imageButton5" - - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_weight="1" - android:background='@color/white' - android:src="@drawable/location_city" /> - - <ImageButton - android:id="@+id/imageButton7" - - android:layout_width="wrap_content" + <LinearLayout + android:id="@+id/linearLayout2" + android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_weight="1" - android:background='@color/white' - android:src="@drawable/location_waterfall" /> - </LinearLayout> + android:layout_marginStart="16dp" + android:layout_marginTop="8dp" + android:orientation="horizontal" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent"> + + <ImageButton + android:id="@+id/imageButton4" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="1" + android:background='@color/white' + android:src="@drawable/location_beach" + tools:ignore="SpeakableTextPresentCheck" /> + + <ImageButton + android:id="@+id/imageButton6" + + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_weight="1" + android:background='@color/white' + android:src="@drawable/location_mountain" + tools:ignore="SpeakableTextPresentCheck" /> + + <ImageButton + android:id="@+id/imageButton5" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginRight="5dp" + android:layout_weight="1" + android:background='@color/white' + android:src="@drawable/location_city" + tools:ignore="SpeakableTextPresentCheck" /> + + <ImageButton + android:id="@+id/imageView8" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginRight="5dp" + android:layout_weight="1" + android:background="#00FFFFFF" + android:elevation="20dp" + android:src="@drawable/location_lake" + tools:ignore="SpeakableTextPresentCheck" /> + + <ImageButton + android:id="@+id/imageButton7" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginRight="5dp" + android:layout_weight="1" + android:background='@color/white' + android:src="@drawable/location_waterfall" + tools:ignore="SpeakableTextPresentCheck" /> + + + </LinearLayout> + </ScrollView> <TextView android:id="@+id/textView12" @@ -157,7 +193,7 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toBottomOf="@+id/linearLayout2" /> + app:layout_constraintTop_toBottomOf="@+id/scrollview" /> <androidx.recyclerview.widget.RecyclerView android:layout_width="0dp" @@ -178,6 +214,7 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="1.0" app:layout_constraintStart_toEndOf="@+id/textView12" - app:layout_constraintTop_toBottomOf="@+id/linearLayout2" /> + app:layout_constraintTop_toBottomOf="@+id/scrollview" + tools:ignore="TouchTargetSizeCheck" /> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file diff --git a/Client/BrzoDoLokacije/app/src/main/res/menu/bottom_nav_menu.xml b/Client/BrzoDoLokacije/app/src/main/res/menu/bottom_nav_menu.xml index da6577e..c024570 100644 --- a/Client/BrzoDoLokacije/app/src/main/res/menu/bottom_nav_menu.xml +++ b/Client/BrzoDoLokacije/app/src/main/res/menu/bottom_nav_menu.xml @@ -1,19 +1,23 @@ <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item - android:id="@+id/navHome" - android:title="Home" + android:id="@+id/navHomePage" + android:title="Početna strana" android:icon="@drawable/ic_nav_home"/> <item + android:id="@+id/navAllPosts" + android:icon="@drawable/ic_baseline_list_24" + android:title="Sve objave" /> + <item android:id="@+id/navBrowse" - android:title="Browse" + android:title="Pretraga" android:icon="@drawable/ic_nav_browse"/> <item android:id="@+id/navAddPost" - android:title="Post" + android:title="Dodaj" android:icon="@drawable/ic_nav_addpost"/> <item android:id="@+id/navProfile" - android:title="Profile" + android:title="Profil" android:icon="@drawable/ic_nav_profile"/> </menu>
\ No newline at end of file |