Skip to content

Commit 093265f

Browse files
Update dependencies
- Update gradle to latest version - Update buildToolsVersion - Update CompileSdkVerson - Update TargetSdkVersion - Migrate ButterKnife to ViewBinding - Fix manifest issues - Fix OpenGl issues
1 parent a947b5a commit 093265f

File tree

16 files changed

+156
-243
lines changed

16 files changed

+156
-243
lines changed

build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
buildscript {
44
repositories {
5-
jcenter()
6-
maven { url 'https://maven.fabric.io/public' }
5+
google()
6+
mavenCentral()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:2.1.0-alpha3'
10-
classpath 'io.fabric.tools:gradle:1.21.0'
9+
classpath 'com.android.tools.build:gradle:7.3.0'
1110

1211
// NOTE: Do not place your application dependencies here; they belong
1312
// in the individual module build.gradle files
@@ -16,7 +15,8 @@ buildscript {
1615

1716
allprojects {
1817
repositories {
19-
jcenter()
18+
google()
19+
mavenCentral()
2020
}
2121
}
2222

demo/build.gradle

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
1-
buildscript {
2-
repositories {
3-
maven { url 'https://maven.fabric.io/public' }
4-
}
5-
6-
dependencies {
7-
classpath 'io.fabric.tools:gradle:1.21.0'
8-
}
9-
}
101
apply plugin: 'com.android.application'
112

12-
repositories {
13-
maven { url 'https://maven.fabric.io/public' }
14-
}
15-
16-
apply plugin: 'io.fabric'
17-
18-
193
android {
20-
compileSdkVersion 23
21-
buildToolsVersion '23.0.2'
4+
compileSdkVersion 33
5+
buildToolsVersion '30.0.3'
226

237
defaultConfig {
248
applicationId "com.yalantis.starwarsdemo"
259
minSdkVersion 15
26-
targetSdkVersion 23
10+
targetSdkVersion 33
2711
versionCode 1
2812
versionName "0.1.0"
2913
}
@@ -33,22 +17,20 @@ android {
3317
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
3418
}
3519
}
36-
dataBinding {
37-
enabled = false
20+
buildFeatures {
21+
viewBinding = true
3822
}
3923
}
4024

4125
dependencies {
42-
compile fileTree(dir: 'libs', include: ['*.jar'])
43-
testCompile 'junit:junit:4.12'
44-
compile 'com.android.support:appcompat-v7:23.1.1'
45-
compile 'com.android.support:design:23.1.1'
46-
compile 'com.jakewharton.timber:timber:4.1.0'
47-
compile 'com.jakewharton:butterknife:7.0.1'
48-
compile 'com.android.support:recyclerview-v7:23.1.1'
49-
compile 'com.android.support:percent:23.1.1'
50-
compile project(':library')
51-
compile('com.crashlytics.sdk.android:crashlytics:2.5.3@aar') {
52-
transitive = true;
53-
}
26+
implementation project(':library')
27+
implementation fileTree(dir: 'libs', include: ['*.jar'])
28+
29+
implementation 'com.android.support:appcompat-v7:23.1.1'
30+
implementation 'com.android.support:design:23.1.1'
31+
implementation 'com.android.support:recyclerview-v7:23.1.1'
32+
implementation 'com.android.support:percent:23.1.1'
33+
34+
implementation "com.jakewharton.timber:timber:4.7.1"
35+
testImplementation 'junit:junit:4.13.2'
5436
}

demo/src/main/AndroidManifest.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.yalantis.starwarsdemo" >
3+
package="com.yalantis.starwarsdemo">
44

55

6-
<uses-permission android:name="android.permission.INTERNET"/>
6+
<uses-permission android:name="android.permission.INTERNET" />
77

88
<application
99
android:name="com.yalantis.starwarsdemo.App"
1010
android:allowBackup="true"
1111
android:icon="@mipmap/ic_launcher"
12-
android:label="@string/app_name"
13-
>
12+
android:label="@string/sw_lib_name">
1413

1514
<activity
1615
android:name=".view.DemoActivity"
1716
android:label="StarWars"
17+
android:screenOrientation="portrait"
1818
android:theme="@style/StarWarsAppTheme"
19-
android:screenOrientation="portrait">
19+
android:exported="true">
2020
<intent-filter>
2121
<action android:name="android.intent.action.MAIN" />
2222

demo/src/main/java/com/yalantis/starwarsdemo/App.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
import android.app.Application;
44
import android.content.Context;
5-
6-
import com.crashlytics.android.Crashlytics;
7-
import io.fabric.sdk.android.Fabric;
85
import timber.log.Timber;
96

107
/**
@@ -16,9 +13,7 @@ public class App extends Application{
1613
@Override
1714
public void onCreate() {
1815
super.onCreate();
19-
Fabric.with(this, new Crashlytics());
2016
app = this;
21-
2217
Timber.plant(new Timber.DebugTree());
2318
}
2419

demo/src/main/java/com/yalantis/starwarsdemo/adapter/ProfileAdapter.java

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
package com.yalantis.starwarsdemo.adapter;
22

33
import android.content.Context;
4-
import android.support.annotation.LayoutRes;
54
import android.support.annotation.Nullable;
65
import android.support.v7.widget.RecyclerView;
76
import android.view.LayoutInflater;
8-
import android.view.View;
97
import android.view.ViewGroup;
108
import android.widget.CompoundButton;
119
import android.widget.TextView;
1210

11+
import androidx.viewbinding.ViewBinding;
12+
1313
import com.yalantis.starwarsdemo.R;
14+
import com.yalantis.starwarsdemo.databinding.ItemProfileGenderBinding;
15+
import com.yalantis.starwarsdemo.databinding.ItemProfileOtherBinding;
16+
import com.yalantis.starwarsdemo.databinding.ItemProfileSideBinding;
1417
import com.yalantis.starwarsdemo.interfaces.ProfileAdapterListener;
1518
import com.yalantis.starwarsdemo.model.User;
1619
import com.yalantis.starwarsdemo.widget.BackgroundDrawableSwitchCompat;
1720

18-
import butterknife.Bind;
19-
import butterknife.ButterKnife;
20-
2121
/**
2222
* Created by Artem Kholodnyi on 11/17/15.
2323
*/
@@ -61,21 +61,19 @@ public int getItemViewType(int position) {
6161

6262
@Override
6363
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
64-
@LayoutRes int layoutRes = getLayoutId(viewType);
65-
66-
View itemView = LayoutInflater.from(parent.getContext()).inflate(layoutRes, parent, false);
67-
return new ViewHolder(itemView);
64+
ViewBinding binding = inflateWithBinding(parent, viewType);
65+
return new ViewHolder(binding);
6866
}
6967

70-
@LayoutRes
71-
private int getLayoutId(int viewType) {
68+
private ViewBinding inflateWithBinding(ViewGroup parent, int viewType) {
69+
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
7270
switch (viewType) {
7371
case VIEW_TYPE_SIDE:
74-
return R.layout.item_profile_side;
72+
return ItemProfileSideBinding.inflate(inflater, parent, false);
7573
case VIEW_TYPE_TEXT_FIELD:
76-
return R.layout.item_profile_other;
74+
return ItemProfileOtherBinding.inflate(inflater, parent, false);
7775
case VIEW_GENDER_FIELD:
78-
return R.layout.item_profile_gender;
76+
return ItemProfileGenderBinding.inflate(inflater, parent, false);
7977
default:
8078
throw new IllegalStateException();
8179
}
@@ -89,12 +87,9 @@ public void onBindViewHolder(final ViewHolder holder, int position) {
8987
// holder.getBinding().setVariable(BR.callback, mListener);
9088
// holder.getBinding().setVariable(BR.user, mUser);
9189
holder.mySwitch.setCheckedImmediate(mUser.isDarkSide());
92-
holder.mySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
93-
@Override
94-
public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) {
95-
mListener.onSideSwitch(holder.mySwitch);
96-
}
97-
});
90+
holder.mySwitch.setOnCheckedChangeListener((CompoundButton.OnCheckedChangeListener)
91+
(buttonView, isChecked) ->
92+
mListener.onSideSwitch(holder.mySwitch));
9893
holder.label.setText(mUser.getSideText());
9994
break;
10095
case 1:
@@ -122,22 +117,25 @@ public int getItemCount() {
122117
return 5;
123118
}
124119

125-
public class ViewHolder extends RecyclerView.ViewHolder {
120+
class ViewHolder extends RecyclerView.ViewHolder {
126121
@Nullable
127-
@Bind(R.id.side_switch)
128122
BackgroundDrawableSwitchCompat mySwitch;
129-
130123
@Nullable
131-
@Bind(R.id.tv_label)
132124
TextView label;
133-
134125
@Nullable
135-
@Bind(R.id.tv_value)
136126
TextView value;
137127

138-
public ViewHolder(View itemView) {
139-
super(itemView);
140-
ButterKnife.bind(this, itemView);
128+
public ViewHolder(ViewBinding binding) {
129+
super(binding.getRoot());
130+
if (binding instanceof ItemProfileSideBinding) {
131+
mySwitch = ((ItemProfileSideBinding) binding).sideSwitch;
132+
label = ((ItemProfileSideBinding) binding).tvLabel;
133+
} else if (binding instanceof ItemProfileOtherBinding) {
134+
label = ((ItemProfileOtherBinding) binding).tvLabel;
135+
value = ((ItemProfileOtherBinding) binding).tvValue;
136+
} else if (binding instanceof ItemProfileGenderBinding) {
137+
label = ((ItemProfileGenderBinding) binding).tvLabel;
138+
}
141139
}
142140
}
143141
}

demo/src/main/java/com/yalantis/starwarsdemo/view/DemoActivity.java

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,22 @@
1212
import android.support.v7.app.AppCompatActivity;
1313

1414
import com.yalantis.starwarsdemo.R;
15+
import com.yalantis.starwarsdemo.databinding.ActivityDemoBinding;
1516
import com.yalantis.starwarsdemo.interfaces.DemoActivityInterface;
1617
import com.yalantis.starwarsdemo.interfaces.GreetingFragmentInterface;
1718
import com.yalantis.starwarsdemo.interfaces.TilesRendererInterface;
1819
import com.yalantis.starwarsdemo.particlesys.ParticleSystemRenderer;
1920

2021
import java.util.List;
2122

22-
import butterknife.Bind;
23-
import butterknife.ButterKnife;
2423

2524
/**
2625
* Created by Artem Kholodnyi on 11/11/15.
2726
*/
2827
public class DemoActivity extends AppCompatActivity implements GreetingFragmentInterface,
2928
DemoActivityInterface, TilesRendererInterface {
30-
@Bind(R.id.gl_surface_view)
31-
GLSurfaceView mGlSurfaceView;
29+
30+
private ActivityDemoBinding binding;
3231

3332
private SideFragment mDarkFragment;
3433
private SideFragment mBrightFragment;
@@ -37,9 +36,8 @@ public class DemoActivity extends AppCompatActivity implements GreetingFragmentI
3736
@Override
3837
protected void onCreate(Bundle savedInstanceState) {
3938
super.onCreate(savedInstanceState);
40-
41-
setContentView(R.layout.activity_demo);
42-
ButterKnife.bind(this);
39+
binding = ActivityDemoBinding.inflate(getLayoutInflater());
40+
setContentView(binding.getRoot());
4341

4442
// Check if the system supports OpenGL ES 2.0.
4543
final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
@@ -48,12 +46,12 @@ protected void onCreate(Bundle savedInstanceState) {
4846

4947
if (supportsEs2) {
5048
// Request an OpenGL ES 2.0 compatible context.
51-
mGlSurfaceView.setEGLContextClientVersion(2);
49+
binding.glSurfaceView.setEGLContextClientVersion(2);
5250

5351
// Set the renderer to our demo renderer, defined below.
54-
ParticleSystemRenderer mRenderer = new ParticleSystemRenderer(mGlSurfaceView);
55-
mGlSurfaceView.setRenderer(mRenderer);
56-
mGlSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
52+
ParticleSystemRenderer mRenderer = new ParticleSystemRenderer(binding.glSurfaceView);
53+
binding.glSurfaceView.setRenderer(mRenderer);
54+
binding.glSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
5755
} else {
5856
throw new UnsupportedOperationException();
5957
}
@@ -67,13 +65,13 @@ protected void onCreate(Bundle savedInstanceState) {
6765
@Override
6866
protected void onPause() {
6967
super.onPause();
70-
mGlSurfaceView.onPause();
68+
binding.glSurfaceView.onPause();
7169
}
7270

7371
@Override
7472
protected void onResume() {
7573
super.onResume();
76-
mGlSurfaceView.onResume();
74+
binding.glSurfaceView.onResume();
7775
}
7876

7977
private void showGreetings() {
@@ -86,15 +84,10 @@ private void showGreetings() {
8684

8785
@Override
8886
public void onSetupProfileClick() {
89-
new Handler().post(new Runnable() {
90-
@Override
91-
public void run() {
92-
getSupportFragmentManager().beginTransaction()
93-
.setCustomAnimations(R.anim.slide_upward, 0)
94-
.add(R.id.container, BrightSideFragment.newInstance(), "bright")
95-
.commit();
96-
}
97-
});
87+
new Handler().post(() -> getSupportFragmentManager().beginTransaction()
88+
.setCustomAnimations(R.anim.slide_upward, 0)
89+
.add(R.id.container, BrightSideFragment.newInstance(), "bright")
90+
.commit());
9891

9992
}
10093

0 commit comments

Comments
 (0)