Skip to content
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

Replaced Butter Knife view binding with Jetpack View Binding #935

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ ext {
supportConstraintLayout = 'androidx.constraintlayout:constraintlayout:2.0.1'

androidxPreference = 'androidx.preference:preference:1.1.1'
androidRoom = 'androidx.room:room-runtime:2.2.5'
androidRoom = 'androidx.room:room-runtime:2.4.0-alpha03'
androidRoomRxJava = 'androidx.room:room-rxjava2:2.2.5'
supportRoom = 'androidx.room:room-compiler:2.2.5'
supportRoom = 'androidx.room:room-compiler:2.4.0-alpha03'


def lifecycle_version = "2.2.0"
Expand Down
5 changes: 5 additions & 0 deletions org.envirocar.app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ android {
buildToolsVersion rootProject.ext.buildToolsVersion
ndkVersion rootProject.ext.ndkVersion

buildFeatures{
viewBinding true
dataBinding true
}

signingConfigs {
release {
storeFile file(project.properties['RELEASE_STORE_FILE'] ?: "/tmp/tmp.key")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/spacing_medium"
tools:viewBindingIgnore="true"
tools:context="org.envirocar.app.views.trackdetails.TrackStatisticsActivity$PlaceholderFragment">

<lecho.lib.hellocharts.view.LineChartView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;

import androidx.activity.OnBackPressedCallback;
Expand All @@ -40,6 +41,7 @@

import org.envirocar.app.BaseApplicationComponent;
import org.envirocar.app.R;
import org.envirocar.app.databinding.ActivityBaseMainBottomBarBinding;
import org.envirocar.app.handler.ApplicationSettings;
import org.envirocar.app.handler.BluetoothHandler;
import org.envirocar.app.handler.DAOProvider;
Expand All @@ -64,8 +66,8 @@

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;


import io.reactivex.Scheduler;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
Expand Down Expand Up @@ -112,10 +114,10 @@ public class BaseMainActivity extends BaseInjectorActivity {
@Inject
protected ValidateAcceptedTerms validateTermsOfUse;

@BindView(R.id.navigation)

protected BottomNavigationView navigationBottomBar;

@BindView(R.id.fragmentContainer)

protected ViewPager viewPager;

private CompositeDisposable subscriptions = new CompositeDisposable();
Expand Down Expand Up @@ -147,13 +149,16 @@ protected void injectDependencies(BaseApplicationComponent baseApplicationCompon
.plus(new MainActivityModule(this))
.inject(this);
}

private ActivityBaseMainBottomBarBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
// LOGGER.info("BaseMainActivity : onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_base_main_bottom_bar);
ButterKnife.bind(this);
binding = ActivityBaseMainBottomBarBinding.inflate(getLayoutInflater());
View view = binding.getRoot();
setContentView(view);
navigationBottomBar = binding.navigation;
viewPager = binding.fragmentContainer;

navigationBottomBar.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
navigationBottomBar.setSelectedItemId(R.id.navigation_dashboard);
Expand Down Expand Up @@ -379,4 +384,4 @@ public int getCount() {
return 3;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

import javax.inject.Inject;

import butterknife.ButterKnife;

import io.reactivex.Completable;
import io.reactivex.Observable;
import io.reactivex.Single;
Expand Down Expand Up @@ -93,7 +93,6 @@ public void onComplete() {

setContentView(R.layout.activity_splashscreen);
getWindow().setNavigationBarColor(getResources().getColor(R.color.cario_color_primary_dark));
ButterKnife.bind(this);

if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
finish();
Expand Down Expand Up @@ -132,4 +131,4 @@ private void startMainActivity() {
this.startActivity(intent);
finish();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,28 @@
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;

import org.envirocar.app.R;
import org.envirocar.app.databinding.CarAttributesDetailBottomsheetBinding;
import org.envirocar.core.entity.Car;
import org.envirocar.core.entity.Vehicles;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;




public class BottomSheetFragment extends BottomSheetDialogFragment {

@BindView(R.id.activity_car_details_attr_manufacturer_value)
TextView manufacturer;
@BindView(R.id.activity_car_details_attr_car_value)

TextView model;
@BindView(R.id.activity_car_details_attr_year_value)

TextView year;
@BindView(R.id.activity_car_details_attr_fuel_value)

TextView fuel;
@BindView(R.id.activity_car_details_attr_power_value)

TextView power;
@BindView(R.id.activity_car_details_attr_engine_value)

TextView engine;
@BindView(R.id.bottomSheetEngineLayout)

View engineLayout;

Vehicles vehicle;
Expand All @@ -63,11 +63,22 @@ public class BottomSheetFragment extends BottomSheetDialogFragment {
this.vehicle = vehicles;
}

private CarAttributesDetailBottomsheetBinding binding;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.car_attributes_detail_bottomsheet, container,false);
ButterKnife.bind(this, view);

binding = CarAttributesDetailBottomsheetBinding.inflate(inflater,container,false);
View view = binding.getRoot();
manufacturer=binding.activityCarDetailsAttrManufacturerValue;
model=binding.activityCarDetailsAttrCarValue;
year=binding.activityCarDetailsAttrYearValue;
fuel=binding.activityCarDetailsAttrFuelValue;
power=binding.activityCarDetailsAttrPowerValue;
engine=binding.activityCarDetailsAttrEngineValue;
engineLayout=binding.bottomSheetEngineLayout;


manufacturer.setText(vehicle.getManufacturer());
model.setText(vehicle.getCommerical_name());
year.setText(vehicle.getAllotment_date());
Expand All @@ -82,14 +93,12 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
return view;
}

@OnClick(R.id.activity_car_details_cancel)
void cancelSheet() {
void cancelSheet(View view) {
dismiss();
}

@OnClick(R.id.activity_car_details_create)
void proceed() {
void proceed(View view) {
((CarSelectionActivity)getActivity()).registerCar(vehicle);
dismiss();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,33 @@
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;

import org.envirocar.app.R;
import org.envirocar.app.databinding.FragmentCarListBinding;
import org.envirocar.app.databinding.FragmentDashboardViewNewBinding;
import org.envirocar.core.entity.Vehicles;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;




public class CarListFragment extends BottomSheetDialogFragment {

@BindView(R.id.fragment_car_list_view)
RecyclerView recyclerView;
List<Vehicles> vehiclesList;

List<Vehicles> vehiclesList;


private FragmentCarListBinding binding;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.fragment_car_list, container, false);
ButterKnife.bind(this, view);
binding = FragmentCarListBinding.inflate(inflater,container,false);
View view = binding.getRoot();

recyclerView = binding.fragmentCarListView;


CarSelectionAttributeListAdapter carListAdapter = new CarSelectionAttributeListAdapter(getContext(), vehiclesList,
new OnCarInteractionCallback() {

Expand All @@ -73,16 +78,15 @@ public void addAndRegisterCar(Vehicles vehicle) {
}

CarListFragment(List<Vehicles> vehiclesList) {
this.vehiclesList = vehiclesList;
this.vehiclesList = vehiclesList;
}

@Override
public void onDestroy() {
super.onDestroy();
}

@OnClick(R.id.fragment_car_list_layout_cancel)
void cancelSheet() {
void cancelSheet(View view) {
dismiss();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

import org.envirocar.app.BaseApplicationComponent;
import org.envirocar.app.R;
import org.envirocar.app.databinding.ActivityCarSelectionLayoutBinding;
import org.envirocar.app.handler.preferences.CarPreferenceHandler;
import org.envirocar.app.handler.preferences.UserPreferenceHandler;
import org.envirocar.app.views.utils.ECAnimationUtils;
Expand All @@ -55,9 +56,9 @@

import javax.inject.Inject;

import butterknife.ButterKnife;
import butterknife.BindView;
import butterknife.OnClick;



import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
Expand All @@ -69,40 +70,29 @@
*/
public class CarSelectionActivity extends BaseInjectorActivity implements CarSelectionUiListener, CarSelectionCreation {
private static final Logger LOG = Logger.getLogger(CarSelectionActivity.class);

private static final int DURATION_SHEET_ANIMATION = 350;

@BindView(R.id.activity_car_selection_layout_content)
protected View mContentView;
@BindView(R.id.envirocar_toolbar)
protected Toolbar mToolbar;
@BindView(R.id.activity_car_selection_layout_exptoolbar)
protected Toolbar mExpToolbar;
@BindView(R.id.actvity_car_selection_layout_loading)
protected View loadingView;

@BindView(R.id.activity_car_selection_new_car_fab)
protected FloatingActionButton mFab;

@BindView(R.id.activity_car_selection_layout_carlist)
protected ListView mCarListView;

@Inject
protected DAOProvider mDAOProvider;
@Inject
protected CarPreferenceHandler mCarManager;
@Inject
protected UserPreferenceHandler mUserHandler;

@BindView(R.id.layout_general_info_background)

protected View infoBackground;
@BindView(R.id.layout_general_info_background_img)

protected ImageView infoBackgroundImg;
@BindView(R.id.layout_general_info_background_firstline)

protected TextView infoBackgroundFirst;
@BindView(R.id.layout_general_info_background_secondline)

protected TextView infoBackgroundSecond;
@BindView(R.id.activity_car_selection_header)

protected View headerView;

private CarSelectionAddCarFragment addCarFragment;
Expand All @@ -114,16 +104,28 @@ public class CarSelectionActivity extends BaseInjectorActivity implements CarSel
protected void injectDependencies(BaseApplicationComponent appComponent) {
appComponent.inject(this);
}

private ActivityCarSelectionLayoutBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Set the content view of this activity.
setContentView(R.layout.activity_car_selection_layout);
binding = ActivityCarSelectionLayoutBinding.inflate(getLayoutInflater());
View view = binding.getRoot();
setContentView(view);

infoBackground = binding.layoutGeneralInfoBackground.getRoot();
infoBackgroundImg = binding.layoutGeneralInfoBackground.layoutGeneralInfoBackgroundImg;
infoBackgroundFirst = binding.layoutGeneralInfoBackground.layoutGeneralInfoBackgroundFirstline;
infoBackgroundSecond = binding.layoutGeneralInfoBackground.layoutGeneralInfoBackgroundSecondline;
headerView = binding.activityCarSelectionHeader;
mContentView= binding.activityCarSelectionLayoutContent;
mToolbar = binding.activityCarSelectionLayoutExptoolbar;
mExpToolbar = binding.activityCarSelectionLayoutExptoolbar;
loadingView =binding.actvityCarSelectionLayoutLoading;
mFab = binding.activityCarSelectionNewCarFab;
mFab.setOnClickListener(this::onClickNewCarButton);
mCarListView = binding.activityCarSelectionLayoutCarlist;

// Inject all annotated views.
ButterKnife.bind(this);

// Set the toolbar as default actionbar.
setSupportActionBar(mToolbar);
Expand Down Expand Up @@ -166,8 +168,7 @@ public void onBackPressed() {

// Set the onClick listener for the FloatingActionButton. When triggered, the sheet view
// gets shown.
@OnClick(R.id.activity_car_selection_new_car_fab)
public void onClickNewCarButton() {
public void onClickNewCarButton(View view) {
showAddCarFragment();
}

Expand Down Expand Up @@ -411,7 +412,7 @@ public Car createCar(Vehicles vehicle) {

result.setWeight(weight);
result.setVehicleType(vehicleType);

return result;
}

Expand Down Expand Up @@ -481,4 +482,4 @@ public int getCount() {
return Math.min(2, super.getCount());
}
}
}
}
Loading