Skip to content

updated to use api 28. migrated to androidX #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 28
defaultConfig {
applicationId "com.saulmm.cui"
minSdkVersion 19
targetSdkVersion 25
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

jackOptions {
enabled true
}
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

dataBinding {
Expand All @@ -26,16 +21,19 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

def SUPPORT = '25.2.0'
compileOptions{
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile "com.android.support:appcompat-v7:$SUPPORT"
compile "com.android.support:design:$SUPPORT"
compile "com.android.support:recyclerview-v7:$SUPPORT"
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'de.hdodenhof:circleimageview:3.0.1'
implementation 'uk.co.chrisjenx:calligraphy:2.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
}
10 changes: 4 additions & 6 deletions app/src/main/java/com/saulmm/cui/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
package com.saulmm.cui;

import android.content.Context;
import android.databinding.DataBindingUtil;
import androidx.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import com.saulmm.cui.databinding.ActivityHomeBinding;
import com.saulmm.cui.model.Product;
Expand All @@ -39,8 +38,7 @@ public class HomeActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

ActivityHomeBinding binding = DataBindingUtil.setContentView(
this, R.layout.activity_home);
ActivityHomeBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_home);

initRecycler(binding.productsRecycler);
}
Expand Down
76 changes: 38 additions & 38 deletions app/src/main/java/com/saulmm/cui/OrderDialogFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.saulmm.cui;

import android.databinding.BindingAdapter;
import androidx.databinding.BindingAdapter;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
Expand All @@ -24,12 +24,12 @@
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.constraint.ConstraintLayout;
import android.support.design.widget.BottomSheetDialogFragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewCompat;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import androidx.core.content.ContextCompat;
import androidx.core.view.ViewCompat;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.RelativeSizeSpan;
Expand Down Expand Up @@ -113,13 +113,13 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
orderSelection = new OrderSelection();

selectedViewTransition = TransitionInflater.from(getContext())
.inflateTransition(R.transition.transition_selected_view);
.inflateTransition(R.transition.transition_selected_view);

binding.setProduct(getProduct());
binding.imgProduct.setImageDrawable(createProductImageDrawable(getProduct()));

binding.btnGo.setBackground(new ColorDrawable(ContextCompat.getColor(
getContext(), getProduct().color)));
getContext(), getProduct().color)));

initOrderStepOneView(binding.layoutStep1);
}
Expand All @@ -145,11 +145,11 @@ private void transitionSelectedView(View v) {

private void startCloneAnimation(View clonedView, View targetView) {
clonedView.post(() -> {
TransitionManager.beginDelayedTransition(
TransitionManager.beginDelayedTransition(
(ViewGroup) binding.getRoot(), selectedViewTransition);

// Fires the transition
clonedView.setLayoutParams(SelectedParamsFactory
// Fires the transition
clonedView.setLayoutParams(SelectedParamsFactory
.endParams(clonedView, targetView));
});
}
Expand All @@ -158,20 +158,20 @@ private View createSelectionView(View v) {
final String resourceName = getResources().getResourceEntryName(v.getId());

return (resourceName.startsWith(ID_COLOR_SUFFIX))
? createSelectedColorView((ImageView) v)
: createSelectedTextView(v);
? createSelectedColorView((ImageView) v)
: createSelectedTextView(v);
}

private View getTargetView(View v) {
final String resourceName = getResources().getResourceEntryName(v.getId());

if (resourceName.startsWith(ID_SIZE_SUFFIX) ||
resourceName.startsWith(ID_DATE_SUFFIX)) {
resourceName.startsWith(ID_DATE_SUFFIX)) {
v.setId(R.id.first_position);
return binding.txtLabelSize;

} else if (resourceName.startsWith(ID_COLOR_SUFFIX) ||
resourceName.startsWith(ID_TIME_SUFFIX)) {
resourceName.startsWith(ID_TIME_SUFFIX)) {
v.setId(R.id.second_position);
return binding.txtLabelColour;
}
Expand All @@ -185,7 +185,7 @@ public static void setItemSpan(View v, int spanOffset) {
final SpannableString sString = new SpannableString(itemText);

sString.setSpan(new RelativeSizeSpan(1.65f), itemText.length() - spanOffset, itemText.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

((TextView) v).setText(sString);
}
Expand Down Expand Up @@ -254,7 +254,7 @@ private String getCleanedText(View v) {

private View createSelectedTextView(View v) {
final TextView fakeSelectedTextView = new TextView(
getContext(), null, R.attr.selectedTextStyle);
getContext(), null, R.attr.selectedTextStyle);

final String resourceName = getResources().getResourceEntryName(v.getId());

Expand All @@ -273,7 +273,7 @@ else if (resourceName.startsWith(ID_SIZE_SUFFIX))

private View createSelectedColorView(ImageView selectedView) {
final ImageView fakeImageView = new CircleImageView(
getContext(), null, R.attr.colorStyle);
getContext(), null, R.attr.colorStyle);

fakeImageView.setImageDrawable(selectedView.getDrawable());
fakeImageView.setLayoutParams(SelectedParamsFactory.startColorParams(selectedView));
Expand All @@ -284,31 +284,31 @@ private void changeToConfirmScene() {
final LayoutOrderConfirmationBinding confBinding = prepareConfirmationBinding();

final Scene scene = new Scene(binding.content,
((ViewGroup) confBinding.getRoot()));
((ViewGroup) confBinding.getRoot()));

scene.setEnterAction(onEnterConfirmScene(confBinding));

final Transition transition = TransitionInflater.from(getContext())
.inflateTransition(R.transition.transition_confirmation_view);
.inflateTransition(R.transition.transition_confirmation_view);

TransitionManager.go(scene, transition);
}

private LayoutOrderConfirmationBinding prepareConfirmationBinding() {
LayoutOrderConfirmationBinding confBinding = LayoutOrderConfirmationBinding
.inflate(LayoutInflater.from(getContext()), binding.mainContainer, false);
.inflate(LayoutInflater.from(getContext()), binding.mainContainer, false);

confBinding.getRoot().setBackground(new ColorDrawable(ContextCompat.getColor(
getContext(), getProduct().color)));
getContext(), getProduct().color)));

confBinding.setProduct(getProduct());
confBinding.setSelection(orderSelection);

confBinding.imgProduct.setImageDrawable(ContextCompat
.getDrawable(getContext(), getProduct().image));
.getDrawable(getContext(), getProduct().image));

confBinding.txtColor.setText(getString(R.string.txt_label_conf_color, String.format(
"#%06X", (0xFFFFFF & getProduct().color))));
"#%06X", (0xFFFFFF & getProduct().color))));

return confBinding;
}
Expand All @@ -323,10 +323,10 @@ private Drawable createProductImageDrawable(Product product) {
background.getPaint().setColor(ContextCompat.getColor(getContext(), product.color));

final BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(),
BitmapFactory.decodeResource(getResources(), product.image));
BitmapFactory.decodeResource(getResources(), product.image));

final LayerDrawable layerDrawable = new LayerDrawable
(new Drawable[]{background, bitmapDrawable});
(new Drawable[]{background, bitmapDrawable});

final int padding = (int) getResources().getDimension(R.dimen.spacing_huge);
layerDrawable.setLayerInset(1, padding, padding, padding, padding);
Expand All @@ -338,30 +338,30 @@ private Drawable createProductImageDrawable(Product product) {
private Runnable onEnterConfirmScene(LayoutOrderConfirmationBinding confirmationBinding) {
return () -> {
ViewCompat.animate(confirmationBinding.txtSubtitle)
.scaleX(1).scaleY(1)
.setInterpolator(new OvershootInterpolator())
.setStartDelay(200)
.start();
.scaleX(1).scaleY(1)
.setInterpolator(new OvershootInterpolator())
.setStartDelay(200)
.start();
};
}

private static class SelectedParamsFactory {
private static ConstraintLayout.LayoutParams startColorParams(View selectedView) {
final int colorSize = selectedView.getContext().getResources()
.getDimensionPixelOffset(R.dimen.product_color_size);
.getDimensionPixelOffset(R.dimen.product_color_size);

final ConstraintLayout.LayoutParams layoutParams =
new ConstraintLayout.LayoutParams(colorSize, colorSize);
new ConstraintLayout.LayoutParams(colorSize, colorSize);

setStartState(selectedView, layoutParams);
return layoutParams;
}

private static ConstraintLayout.LayoutParams startTextParams(View selectedView) {
final ConstraintLayout.LayoutParams layoutParams =
new ConstraintLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
new ConstraintLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);

setStartState(selectedView, layoutParams);
return layoutParams;
Expand All @@ -375,10 +375,10 @@ private static void setStartState(View selectedView, ConstraintLayout.LayoutPara

private static ConstraintLayout.LayoutParams endParams(View v, View targetView) {
final ConstraintLayout.LayoutParams layoutParams =
(ConstraintLayout.LayoutParams) v.getLayoutParams();
(ConstraintLayout.LayoutParams) v.getLayoutParams();

final int marginLeft = v.getContext().getResources()
.getDimensionPixelOffset(R.dimen.spacing_medium);
.getDimensionPixelOffset(R.dimen.spacing_medium);

layoutParams.setMargins(marginLeft, 0, 0, 0);
layoutParams.topToTop = targetView.getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package com.saulmm.cui.recycler;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/com/saulmm/cui/recycler/ProductAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

Expand All @@ -39,7 +39,7 @@ public ProductAdapter(List<Product> products) {
@Override
public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
final ItemProductBinding productBinding = ItemProductBinding.inflate(
LayoutInflater.from(parent.getContext()), parent, false);
LayoutInflater.from(parent.getContext()), parent, false);

return new ProductViewHolder(productBinding);
}
Expand Down Expand Up @@ -72,10 +72,10 @@ void bind(Product product) {
@NonNull
private GradientDrawable createProductBackground(Product product) {
final GradientDrawable gradientDrawable = (GradientDrawable) ContextCompat.getDrawable(
itemView.getContext(), R.drawable.bg_product);
itemView.getContext(), R.drawable.bg_product);

gradientDrawable.setColor(ContextCompat.getColor(
itemView.getContext(), product.color));
itemView.getContext(), product.color));

gradientDrawable.setSize(itemView.getWidth(), getDrawableHeight());
gradientDrawable.mutate();
Expand All @@ -86,8 +86,8 @@ private int getDrawableHeight() {
final Context context = itemView.getContext();

return getAdapterPosition() % 2 == 0
? context.getResources().getDimensionPixelOffset(R.dimen.product_regular_height)
: context.getResources().getDimensionPixelOffset(R.dimen.product_large_height);
? context.getResources().getDimensionPixelOffset(R.dimen.product_regular_height)
: context.getResources().getDimensionPixelOffset(R.dimen.product_large_height);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import android.content.Context;
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

import com.saulmm.cui.R;
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/layout/activity_home.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layout>

<android.support.design.widget.CoordinatorLayout
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
Expand All @@ -10,7 +10,7 @@
tools:context="com.saulmm.cui.HomeActivity"
>

<android.support.v7.widget.RecyclerView
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/products_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -21,6 +21,6 @@
app:spanCount="@integer/product_columns"
tools:listitem="@layout/item_product"
/>
</android.support.design.widget.CoordinatorLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>

Loading