From d3e77c2b9bfb2b786f90215e40e8cef1933da07a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20=C3=87erri?= <64997243+deniscerri@users.noreply.github.com> Date: Sun, 29 May 2022 00:10:22 +0200 Subject: [PATCH] Improved app layout for other devices - Other general design fixes - Implemented a default theme for devices below android 12 - Added more colors to android 12 devices --- .idea/deploymentTargetDropDown.xml | 17 +++++++++ app/src/main/AndroidManifest.xml | 2 +- .../com/deniscerri/ytdl/HistoryFragment.java | 14 ++++---- .../com/deniscerri/ytdl/HomeFragment.java | 36 +++++++++++-------- .../com/deniscerri/ytdl/MainActivity.java | 28 +++++++++++++-- app/src/main/res/layout/activity_main.xml | 2 +- app/src/main/res/values/styles.xml | 22 +++++++++--- 7 files changed, 89 insertions(+), 32 deletions(-) create mode 100644 .idea/deploymentTargetDropDown.xml diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 00000000..f6a9ccc2 --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 57200b73..c999f2fa 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,7 +12,7 @@ android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" - android:theme="@style/AppTheme" + android:theme="@style/AppDefaultTheme" android:extractNativeLibs="true" android:requestLegacyExternalStorage="true"> diff --git a/app/src/main/java/com/deniscerri/ytdl/HistoryFragment.java b/app/src/main/java/com/deniscerri/ytdl/HistoryFragment.java index b9a1c0d8..fb0c4c05 100644 --- a/app/src/main/java/com/deniscerri/ytdl/HistoryFragment.java +++ b/app/src/main/java/com/deniscerri/ytdl/HistoryFragment.java @@ -102,7 +102,7 @@ public class HistoryFragment extends Fragment { CardView card = new CardView(requireContext()); card.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); - card.setRadius(50); + card.setRadius(getDp(10)); card.setCardElevation(10); card.setMaxCardElevation(12); card.setPreventCornerOverlap(true); @@ -129,22 +129,20 @@ public class HistoryFragment extends Fragment { videoTitle.setText(video.getTitle()); videoTitle.setTextSize(getDp(5)); videoTitle.setTextColor(ContextCompat.getColor(requireContext(), R.color.white)); - videoTitle.setShadowLayer(1, 1, 1, ContextCompat.getColor(requireContext(), R.color.colorPrimaryDark)); videoTitle.setTypeface(null, Typeface.BOLD); - videoTitle.setShadowLayer(1.5f, 4f, 4f, R.color.black); + videoTitle.setShadowLayer(2f, 4f, 4f, ContextCompat.getColor(requireContext(), R.color.black)); // AUTHOR ---------------------------------- TextView videoAuthor = new TextView(getContext()); videoAuthor.setGravity(Gravity.BOTTOM); - videoAuthor.setLayoutParams(new RelativeLayout.LayoutParams(getDp(100), getDp(100))); + videoAuthor.setLayoutParams(new RelativeLayout.LayoutParams(getDp(150), getDp(100))); videoAuthor.setPadding(getDp(20), 0, 0, getDp(10)); - videoAuthor.setShadowLayer(1.5f, 4f, 4f, R.color.black); videoAuthor.setText(video.getAuthor()); videoAuthor.setTextSize(getDp(3)); videoAuthor.setTextColor(ContextCompat.getColor(requireContext(), R.color.white)); - videoAuthor.setShadowLayer(1, 1, 1, ContextCompat.getColor(requireContext(), R.color.colorPrimaryDark)); + videoAuthor.setShadowLayer(2f, 4f, 4f, ContextCompat.getColor(requireContext(), R.color.black)); videoAuthor.setTypeface(null, Typeface.BOLD); // DATE --------------------------------------------- @@ -166,9 +164,9 @@ public class HistoryFragment extends Fragment { LinearLayout buttonLayout = new LinearLayout(requireContext()); buttonLayout.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); - buttonLayout.setGravity(Gravity.BOTTOM); + buttonLayout.setGravity(Gravity.BOTTOM | Gravity.RIGHT); buttonLayout.setOrientation(LinearLayout.HORIZONTAL); - buttonLayout.setPadding(getDp(300), 0, getDp(20), getDp(40)); + buttonLayout.setPadding(getDp(10), 0, getDp(20), getDp(40)); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( getDp(48), getDp(48) diff --git a/app/src/main/java/com/deniscerri/ytdl/HomeFragment.java b/app/src/main/java/com/deniscerri/ytdl/HomeFragment.java index 44d5ed9e..3197f3d6 100644 --- a/app/src/main/java/com/deniscerri/ytdl/HomeFragment.java +++ b/app/src/main/java/com/deniscerri/ytdl/HomeFragment.java @@ -29,6 +29,7 @@ import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; +import androidx.annotation.Px; import androidx.appcompat.widget.SearchView; import androidx.cardview.widget.CardView; import androidx.core.app.ActivityCompat; @@ -355,7 +356,7 @@ public class HomeFragment extends Fragment implements View.OnClickListener{ CardView card = new CardView(requireContext()); card.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); - card.setRadius(50); + card.setRadius(getDp(10)); card.setCardElevation(10); card.setMaxCardElevation(12); card.setPreventCornerOverlap(true); @@ -371,22 +372,21 @@ public class HomeFragment extends Fragment implements View.OnClickListener{ videoTitle.setText("Shkarko të gjitha"); videoTitle.setTextSize(getDp(5)); videoTitle.setTextColor(ContextCompat.getColor(requireContext(), R.color.white)); - videoTitle.setShadowLayer(1, 1, 1, ContextCompat.getColor(requireContext(), R.color.colorPrimaryDark)); videoTitle.setTypeface(null, Typeface.BOLD); - videoTitle.setShadowLayer(1.5f, 4f, 4f, R.color.black); + videoTitle.setShadowLayer(2f, 4f, 4f, ContextCompat.getColor(requireContext(), R.color.black)); // BUTTONS ------------------------------------------- LinearLayout buttonLayout = new LinearLayout(requireContext()); buttonLayout.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); - buttonLayout.setGravity(Gravity.BOTTOM); + buttonLayout.setGravity(Gravity.BOTTOM | Gravity.RIGHT); buttonLayout.setOrientation(LinearLayout.HORIZONTAL); - buttonLayout.setPadding(getDp(250), 0, getDp(20), getDp(10)); + buttonLayout.setPadding(0, 0, getDp(20), getDp(10)); Button musicBtn = new Button(getContext()); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( getDp(48), getDp(48) ); - params.setMargins(0,0, getDp(10), 0); + params.setMargins(10,0, 10, 10); musicBtn.setLayoutParams(params); //musicBtn.setIconSize(getDp(24)); musicBtn.setBackground(ContextCompat.getDrawable(requireContext(), R.drawable.ic_music)); @@ -475,6 +475,10 @@ public class HomeFragment extends Fragment implements View.OnClickListener{ return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, getResources().getDisplayMetrics()); } + private int getSp(int value){ + return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, value, getResources().getDisplayMetrics()); + } + private void createCard(Video video){ RelativeLayout r = new RelativeLayout(getContext()); @@ -483,7 +487,7 @@ public class HomeFragment extends Fragment implements View.OnClickListener{ CardView card = new CardView(requireContext()); card.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); - card.setRadius(50); + card.setRadius(getDp(10)); card.setCardElevation(10); card.setMaxCardElevation(12); card.setPreventCornerOverlap(true); @@ -511,11 +515,10 @@ public class HomeFragment extends Fragment implements View.OnClickListener{ title = title.substring(0, 40) + "..."; } videoTitle.setText(title); - videoTitle.setTextSize(getDp(5)); + videoTitle.setTextSize(getSp(5)); videoTitle.setTextColor(ContextCompat.getColor(requireContext(), R.color.white)); - videoTitle.setShadowLayer(1, 1, 1, ContextCompat.getColor(requireContext(), R.color.colorPrimaryDark)); videoTitle.setTypeface(null, Typeface.BOLD); - videoTitle.setShadowLayer(1.5f, 4f, 4f, R.color.black); + videoTitle.setShadowLayer(2f, 4f, 4f, ContextCompat.getColor(requireContext(), R.color.black)); // AUTHOR ---------------------------------- @@ -528,9 +531,9 @@ public class HomeFragment extends Fragment implements View.OnClickListener{ String author = video.getAuthor(); videoAuthor.setText(author); - videoAuthor.setTextSize(getDp(3)); + videoAuthor.setTextSize(getSp(3)); videoAuthor.setTextColor(ContextCompat.getColor(requireContext(), R.color.white)); - videoAuthor.setShadowLayer(1, 1, 1, ContextCompat.getColor(requireContext(), R.color.colorPrimaryDark)); + videoAuthor.setShadowLayer(2f, 4f, 4f, ContextCompat.getColor(requireContext(), R.color.black)); videoAuthor.setTypeface(null, Typeface.BOLD); // BUTTONS ---------------------------------- @@ -539,9 +542,10 @@ public class HomeFragment extends Fragment implements View.OnClickListener{ LinearLayout buttonLayout = new LinearLayout(requireContext()); buttonLayout.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); - buttonLayout.setGravity(Gravity.BOTTOM); + buttonLayout.setGravity(Gravity.BOTTOM | Gravity.RIGHT); + buttonLayout.setOrientation(LinearLayout.HORIZONTAL); - buttonLayout.setPadding(getDp(250), 0, getDp(20), getDp(10)); + buttonLayout.setPadding(getDp(10), 0, getDp(10), getDp(10)); Button musicBtn = new Button(getContext()); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( @@ -570,10 +574,12 @@ public class HomeFragment extends Fragment implements View.OnClickListener{ ProgressBar progressBar = new ProgressBar(requireContext(), null, android.R.attr.progressBarStyleHorizontal); progressBar.setVisibility(View.GONE); RelativeLayout.LayoutParams progressParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, getDp(5)); - progressParams.setMargins(0, getDp(210), 0 ,0); + progressParams.setMargins(0, r.getLayoutParams().height - 70, 0 ,0); progressBar.setLayoutParams(progressParams); progressBar.setBackgroundTintMode(PorterDuff.Mode.SRC_IN); progressBar.setScaleY(2); + + progressBar.setY(card.getY() - progressBar.getHeight() / 2); progressBar.setTag(videoID + "##progress"); if(video.getDownloadedTime() != null){ diff --git a/app/src/main/java/com/deniscerri/ytdl/MainActivity.java b/app/src/main/java/com/deniscerri/ytdl/MainActivity.java index 6c84a906..0e9115ef 100644 --- a/app/src/main/java/com/deniscerri/ytdl/MainActivity.java +++ b/app/src/main/java/com/deniscerri/ytdl/MainActivity.java @@ -1,17 +1,22 @@ package com.deniscerri.ytdl; import android.content.Intent; +import android.content.res.ColorStateList; +import android.os.Build; import android.os.Bundle; import android.util.Log; +import android.view.Menu; import android.view.WindowManager; import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; +import androidx.core.content.res.ComplexColorCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; import com.deniscerri.ytdl.databinding.ActivityMainBinding; +import com.google.android.material.bottomnavigation.BottomNavigationView; import io.reactivex.disposables.CompositeDisposable; @@ -31,11 +36,30 @@ public class MainActivity extends AppCompatActivity{ @Override protected void onCreate(Bundle savedInstanceState) { + binding = ActivityMainBinding.inflate(getLayoutInflater()); + + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S){ + this.setTheme(R.style.AppTheme); + + ColorStateList list = new ColorStateList( + new int[][]{ + new int[]{} + }, + new int[]{ + ContextCompat.getColor(getApplicationContext(), R.color.material_dynamic_primary50) + } + ); + binding.bottomNavigationView.setItemActiveIndicatorColor(list); + binding.bottomNavigationView.setItemRippleColor(list); + binding.bottomNavigationView.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.material_dynamic_neutral10)); + } + super.onCreate(savedInstanceState); + + setContentView(R.layout.activity_main); - binding = ActivityMainBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); homeFragment = new HomeFragment(); @@ -44,8 +68,6 @@ public class MainActivity extends AppCompatActivity{ replaceFragment(homeFragment); - - binding.bottomNavigationView.setOnItemSelectedListener(item -> { switch(item.getItemId()){ case R.id.home: diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index ef247713..0eb40255 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -20,7 +20,7 @@ android:id="@+id/bottomNavigationView" android:layout_width="match_parent" android:layout_height="wrap_content" - app:itemActiveIndicatorStyle="@style/BottomNav" + app:itemActiveIndicatorStyle="@style/BottomNavDefault" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index c36d5f2b..d942fa6d 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -3,13 +3,20 @@ + + @@ -24,4 +31,11 @@ @color/material_dynamic_primary50 + + + + +