From 7f6edfa7cea80f4fa274cac0e44c9f73fd8a8509 Mon Sep 17 00:00:00 2001 From: Akash-Ramjyothi Date: Fri, 1 Jul 2022 01:48:14 +0530 Subject: [PATCH 01/19] Enabled Jetpack ViewBinding --- org.envirocar.app/build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/org.envirocar.app/build.gradle b/org.envirocar.app/build.gradle index 08939fc61..18a5075a7 100644 --- a/org.envirocar.app/build.gradle +++ b/org.envirocar.app/build.gradle @@ -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") From ccb49e6cc8b19c965a9ff2b15fa3110e30f7cdf4 Mon Sep 17 00:00:00 2001 From: Akash-Ramjyothi Date: Fri, 1 Jul 2022 01:52:54 +0530 Subject: [PATCH 02/19] Fixed minor error --- .../res/layout/activity_track_statistics_fragment.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/org.envirocar.app/res/layout/activity_track_statistics_fragment.xml b/org.envirocar.app/res/layout/activity_track_statistics_fragment.xml index 92f500e1c..9423f9b55 100644 --- a/org.envirocar.app/res/layout/activity_track_statistics_fragment.xml +++ b/org.envirocar.app/res/layout/activity_track_statistics_fragment.xml @@ -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"> Date: Sun, 3 Jul 2022 20:03:03 +0530 Subject: [PATCH 03/19] Added ViewBInding for HelpActivity --- .../org/envirocar/app/views/others/HelpActivity.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/org.envirocar.app/src/org/envirocar/app/views/others/HelpActivity.java b/org.envirocar.app/src/org/envirocar/app/views/others/HelpActivity.java index 2f64c3728..4e8552640 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/others/HelpActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/views/others/HelpActivity.java @@ -22,8 +22,11 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import android.view.MenuItem; +import android.view.View; import org.envirocar.app.R; +import org.envirocar.app.databinding.ActivityHelpLayoutBinding; +import org.envirocar.app.databinding.ActivityHelpLayoutGeneralBinding; import butterknife.ButterKnife; import butterknife.BindView; @@ -38,18 +41,22 @@ public class HelpActivity extends AppCompatActivity { @BindView(R.id.activity_help_layout_general_toolbar) protected Toolbar toolbar; + ActivityHelpLayoutGeneralBinding activityHelpLayoutGeneralBinding; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_help_layout_general); + activityHelpLayoutGeneralBinding = ActivityHelpLayoutGeneralBinding.inflate(getLayoutInflater()); + View view = activityHelpLayoutGeneralBinding.getRoot(); + setContentView(view); // Inject views ButterKnife.bind(this); // Set Actionbar setSupportActionBar(toolbar); - getSupportActionBar().setTitle("Help"); + activityHelpLayoutGeneralBinding.activityHelpLayoutGeneralToolbar.setTitle("Help"); getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } From 315d0b97e1734266b07704f2f12d8725e4cdbb8f Mon Sep 17 00:00:00 2001 From: Akash-Ramjyothi Date: Sun, 3 Jul 2022 22:17:49 +0530 Subject: [PATCH 04/19] Added ViewBInding for RermsOfUseActivity --- .../envirocar/app/views/others/HelpActivity.java | 8 ++++---- .../app/views/others/TermsOfUseActivity.java | 14 +++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/org.envirocar.app/src/org/envirocar/app/views/others/HelpActivity.java b/org.envirocar.app/src/org/envirocar/app/views/others/HelpActivity.java index 4e8552640..f42292d6e 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/others/HelpActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/views/others/HelpActivity.java @@ -19,17 +19,17 @@ package org.envirocar.app.views.others; import android.os.Bundle; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.Toolbar; import android.view.MenuItem; import android.view.View; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + import org.envirocar.app.R; -import org.envirocar.app.databinding.ActivityHelpLayoutBinding; import org.envirocar.app.databinding.ActivityHelpLayoutGeneralBinding; -import butterknife.ButterKnife; import butterknife.BindView; +import butterknife.ButterKnife; /** * TODO JavaDoc diff --git a/org.envirocar.app/src/org/envirocar/app/views/others/TermsOfUseActivity.java b/org.envirocar.app/src/org/envirocar/app/views/others/TermsOfUseActivity.java index d13792d8c..0b4aa4db9 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/others/TermsOfUseActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/views/others/TermsOfUseActivity.java @@ -22,6 +22,7 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; import android.view.MenuItem; +import android.view.View; import android.widget.TextView; import android.text.Html; import android.text.Spanned; @@ -40,6 +41,7 @@ import org.envirocar.app.BaseApplicationComponent; import org.envirocar.core.utils.rx.Optional; import org.envirocar.app.handler.preferences.UserPreferenceHandler; +import org.envirocar.app.databinding.ActivityTouLayoutBinding; import butterknife.ButterKnife; import butterknife.BindView; @@ -76,19 +78,22 @@ protected void injectDependencies(BaseApplicationComponent baseApplicationCompon baseApplicationComponent.inject(this); } + ActivityTouLayoutBinding activityTouLayoutBinding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_tou_layout); + activityTouLayoutBinding = ActivityTouLayoutBinding.inflate(getLayoutInflater()); + View view = activityTouLayoutBinding.getRoot(); + setContentView(view); // Inject views ButterKnife.bind(this); // Set Actionbar setSupportActionBar(toolbar); - getSupportActionBar().setTitle(getString(R.string.terms_of_use_simple)); + activityTouLayoutBinding.activityTouLayoutToolbar.setTitle(getString(R.string.terms_of_use_simple)); getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -97,8 +102,7 @@ protected void onCreate(Bundle savedInstanceState) { Spanned htmlAsSpanned = Html.fromHtml(htmlAsString); // set the html content on a TextView - TextView textView = (TextView) findViewById(R.id.tou_text_view); - textView.setText(htmlAsSpanned); + activityTouLayoutBinding.touTextView.setText(htmlAsSpanned); getLatestTermsOfUse.asObservable() .subscribeOn(Schedulers.io()) @@ -107,7 +111,7 @@ protected void onCreate(Bundle savedInstanceState) { LOG.info("Terms Of Use loaded: " + termsOfUse); if (!termsOfUse.isEmpty()) { Spanned htmlContent = Html.fromHtml(termsOfUse.getOptional().getContents()); - textView.setText(htmlContent); + activityTouLayoutBinding.touTextView.setText(htmlContent); } }); From 964f888599d30def6aeb2317129ff84527f36dfc Mon Sep 17 00:00:00 2001 From: Akash-Ramjyothi Date: Sun, 3 Jul 2022 22:49:43 +0530 Subject: [PATCH 05/19] Added ViewBinding for TimePickerPreferenceDialog --- .../custom/TimePickerPreferenceDialog.java | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/org.envirocar.app/src/org/envirocar/app/views/settings/custom/TimePickerPreferenceDialog.java b/org.envirocar.app/src/org/envirocar/app/views/settings/custom/TimePickerPreferenceDialog.java index fa68a94f4..8c2ff6623 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/settings/custom/TimePickerPreferenceDialog.java +++ b/org.envirocar.app/src/org/envirocar/app/views/settings/custom/TimePickerPreferenceDialog.java @@ -69,6 +69,9 @@ public String format(int value) { private int currentSeconds; private int currentMinutes; + // Instance of the binding class to reference any of the views + TimePickerPreferenceDialog binding; + @BindView(R.id.preference_timepicker_text) protected TextView text; @@ -85,37 +88,38 @@ protected void onBindDialogView(View view) { ButterKnife.bind(this, view); // Set the textview text - this.text.setText(R.string.pref_bt_discovery_interval_explanation); + binding.text.setText(R.string.pref_bt_discovery_interval_explanation); // set the settings for the minute NumberPicker. - this.minutePicker.setMinValue(0); - this.minutePicker.setMaxValue(10); - this.minutePicker.setOnLongPressUpdateInterval(100); - this.minutePicker.setFormatter(FORMATTER_TWO_DIGITS); - this.minutePicker.setOnValueChangedListener((picker, oldVal, newVal) -> { - int minValue = minutePicker.getMinValue(); - int maxValue = minutePicker.getMaxValue(); + binding.minutePicker.setMinValue(0); + binding.minutePicker.setMinValue(0); + binding.minutePicker.setMaxValue(10); + binding.minutePicker.setOnLongPressUpdateInterval(100); + binding.minutePicker.setFormatter(FORMATTER_TWO_DIGITS); + binding.minutePicker.setOnValueChangedListener((picker, oldVal, newVal) -> { + int minValue = binding.minutePicker.getMinValue(); + int maxValue = binding.minutePicker.getMaxValue(); if (oldVal == maxValue && newVal == minValue) { } }); // set the settings for the seconds number picker. - this.secondsPicker.setMinValue(0); - this.secondsPicker.setMaxValue(59); + binding.secondsPicker.setMinValue(0); + binding.secondsPicker.setMaxValue(59); // if (this.displaySeconds != null) // this.secondsPicker.setDisplayedValues(displaySeconds); - this.secondsPicker.setOnLongPressUpdateInterval(100); - this.secondsPicker.setFormatter(FORMATTER_TWO_DIGITS); - this.secondsPicker.setOnValueChangedListener((spinner, oldVal, newVal) -> { - int minValue = secondsPicker.getMinValue(); - int maxValue = secondsPicker.getMaxValue(); + binding.secondsPicker.setOnLongPressUpdateInterval(100); + binding.secondsPicker.setFormatter(FORMATTER_TWO_DIGITS); + binding.secondsPicker.setOnValueChangedListener((spinner, oldVal, newVal) -> { + int minValue = binding.secondsPicker.getMinValue(); + int maxValue = binding.secondsPicker.getMaxValue(); if (oldVal == maxValue && newVal == minValue) { - int newMinute = minutePicker.getValue() + 1; - minutePicker.setValue(newMinute); + int newMinute = binding.minutePicker.getValue() + 1; + binding.minutePicker.setValue(newMinute); } else if (oldVal == minValue && newVal == maxValue) { - int newMinute = minutePicker.getValue() - 1; - minutePicker.setValue(newMinute); + int newMinute = binding.minutePicker.getValue() - 1; + binding.minutePicker.setValue(newMinute); } }); @@ -144,18 +148,18 @@ protected void onBindDialogView(View view) { currentMinutes = minutes; currentSeconds = seconds; - secondsPicker.setValue(currentSeconds); - minutePicker.setValue(currentMinutes); + binding.secondsPicker.setValue(currentSeconds); + binding.minutePicker.setValue(currentMinutes); } } @Override public void onDialogClosed(boolean positiveResult) { if (positiveResult) { - currentMinutes = minutePicker.getValue(); - currentSeconds = secondsPicker.getValue(); + currentMinutes = binding.minutePicker.getValue(); + currentSeconds = binding.secondsPicker.getValue(); - int time = minutePicker.getValue() * 60 + secondsPicker.getValue(); + int time = binding.minutePicker.getValue() * 60 + binding.secondsPicker.getValue(); // save the result DialogPreference preference = getPreference(); From 78ceb2a6c0fc1e6369534de78bb2004fe4025e81 Mon Sep 17 00:00:00 2001 From: Akash-Ramjyothi Date: Sun, 3 Jul 2022 22:56:28 +0530 Subject: [PATCH 06/19] Added ViewBinding for BaseMainActivity --- .../envirocar/app/views/BaseMainActivity.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/org.envirocar.app/src/org/envirocar/app/views/BaseMainActivity.java b/org.envirocar.app/src/org/envirocar/app/views/BaseMainActivity.java index c4fedcd89..81a29efc6 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/BaseMainActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/views/BaseMainActivity.java @@ -82,6 +82,9 @@ public class BaseMainActivity extends BaseInjectorActivity { private FragmentStatePagerAdapter fragmentStatePagerAdapter; private MenuItem prevMenuItem; + // Instance of the binding class to reference any of the views + BaseMainActivity binding; + // Custom Callback Stack Stack callbackStack = new Stack(); @@ -129,13 +132,13 @@ public class BaseMainActivity extends BaseInjectorActivity { = item -> { switch (item.getItemId()) { case R.id.navigation_dashboard: - viewPager.setCurrentItem(0); + binding.viewPager.setCurrentItem(0); return true; case R.id.navigation_my_tracks: - viewPager.setCurrentItem(1); + binding.viewPager.setCurrentItem(1); return true; case R.id.navigation_others: - viewPager.setCurrentItem(2); + binding.viewPager.setCurrentItem(2); return true; } return false; @@ -155,11 +158,11 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_base_main_bottom_bar); ButterKnife.bind(this); - navigationBottomBar.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); - navigationBottomBar.setSelectedItemId(R.id.navigation_dashboard); + binding.navigationBottomBar.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); + binding.navigationBottomBar.setSelectedItemId(R.id.navigation_dashboard); fragmentStatePagerAdapter = new PageSlider(getSupportFragmentManager(), FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT); - viewPager.setAdapter(fragmentStatePagerAdapter); + binding.viewPager.setAdapter(fragmentStatePagerAdapter); // Custom Back Navigation for fragments in BaseMainActivity callbackStack.push(0); @@ -168,14 +171,14 @@ protected void onCreate(Bundle savedInstanceState) { public void handleOnBackPressed() { // Handle the back button event callbackStack.pop(); - viewPager.setCurrentItem(callbackStack.peek()); + binding.viewPager.setCurrentItem(callbackStack.peek()); if(callbackStack.size() < 2) this.setEnabled(false); } }; this.getOnBackPressedDispatcher().addCallback(this, callback); - viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { + binding.viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { @@ -186,15 +189,15 @@ public void onPageSelected(int position) { if (prevMenuItem != null) { prevMenuItem.setChecked(false); } else { - navigationBottomBar.getMenu().getItem(0).setChecked(false); + binding.navigationBottomBar.getMenu().getItem(0).setChecked(false); } // add page to callbackStack if (callbackStack.peek() != position) { callbackStack.push(position); callback.setEnabled(true); } - navigationBottomBar.getMenu().getItem(position).setChecked(true); - prevMenuItem = navigationBottomBar.getMenu().getItem(position); + binding.navigationBottomBar.getMenu().getItem(position).setChecked(true); + prevMenuItem = binding.navigationBottomBar.getMenu().getItem(position); fragmentStatePagerAdapter.notifyDataSetChanged(); } @@ -315,10 +318,10 @@ private void addPreferenceSubscriptions() { private void checkKeepScreenOn() { if (ApplicationSettings.getDisplayStaysActiveObservable(this).blockingFirst()) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - this.navigationBottomBar.setKeepScreenOn(true); + binding.navigationBottomBar.setKeepScreenOn(true); } else { getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - this.navigationBottomBar.setKeepScreenOn(false); + binding.navigationBottomBar.setKeepScreenOn(false); } } From b452316f969a1ab0746c1b29a00ceebe6d19fd3f Mon Sep 17 00:00:00 2001 From: Akash-Ramjyothi Date: Tue, 12 Jul 2022 09:14:12 +0530 Subject: [PATCH 07/19] Upgraded androidRoom dependency --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index bd57358c8..82bf8b840 100644 --- a/build.gradle +++ b/build.gradle @@ -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" From 790bcd1d8fdd8435c3e41650e94d361f80ea8894 Mon Sep 17 00:00:00 2001 From: Akash-Ramjyothi Date: Tue, 12 Jul 2022 09:23:05 +0530 Subject: [PATCH 08/19] Added ViewBinding for Basic views --- .../envirocar/app/views/BaseMainActivity.java | 50 ++++++++++--------- .../app/views/SplashScreenActivity.java | 5 +- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/org.envirocar.app/src/org/envirocar/app/views/BaseMainActivity.java b/org.envirocar.app/src/org/envirocar/app/views/BaseMainActivity.java index 81a29efc6..9dd881995 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/BaseMainActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/views/BaseMainActivity.java @@ -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; @@ -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; @@ -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; @@ -82,9 +84,6 @@ public class BaseMainActivity extends BaseInjectorActivity { private FragmentStatePagerAdapter fragmentStatePagerAdapter; private MenuItem prevMenuItem; - // Instance of the binding class to reference any of the views - BaseMainActivity binding; - // Custom Callback Stack Stack callbackStack = new Stack(); @@ -115,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(); @@ -132,13 +131,13 @@ public class BaseMainActivity extends BaseInjectorActivity { = item -> { switch (item.getItemId()) { case R.id.navigation_dashboard: - binding.viewPager.setCurrentItem(0); + viewPager.setCurrentItem(0); return true; case R.id.navigation_my_tracks: - binding.viewPager.setCurrentItem(1); + viewPager.setCurrentItem(1); return true; case R.id.navigation_others: - binding.viewPager.setCurrentItem(2); + viewPager.setCurrentItem(2); return true; } return false; @@ -150,19 +149,22 @@ 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; - binding.navigationBottomBar.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); - binding.navigationBottomBar.setSelectedItemId(R.id.navigation_dashboard); + navigationBottomBar.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); + navigationBottomBar.setSelectedItemId(R.id.navigation_dashboard); fragmentStatePagerAdapter = new PageSlider(getSupportFragmentManager(), FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT); - binding.viewPager.setAdapter(fragmentStatePagerAdapter); + viewPager.setAdapter(fragmentStatePagerAdapter); // Custom Back Navigation for fragments in BaseMainActivity callbackStack.push(0); @@ -171,14 +173,14 @@ protected void onCreate(Bundle savedInstanceState) { public void handleOnBackPressed() { // Handle the back button event callbackStack.pop(); - binding.viewPager.setCurrentItem(callbackStack.peek()); + viewPager.setCurrentItem(callbackStack.peek()); if(callbackStack.size() < 2) this.setEnabled(false); } }; this.getOnBackPressedDispatcher().addCallback(this, callback); - binding.viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { + viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { @@ -189,15 +191,15 @@ public void onPageSelected(int position) { if (prevMenuItem != null) { prevMenuItem.setChecked(false); } else { - binding.navigationBottomBar.getMenu().getItem(0).setChecked(false); + navigationBottomBar.getMenu().getItem(0).setChecked(false); } // add page to callbackStack if (callbackStack.peek() != position) { callbackStack.push(position); callback.setEnabled(true); } - binding.navigationBottomBar.getMenu().getItem(position).setChecked(true); - prevMenuItem = binding.navigationBottomBar.getMenu().getItem(position); + navigationBottomBar.getMenu().getItem(position).setChecked(true); + prevMenuItem = navigationBottomBar.getMenu().getItem(position); fragmentStatePagerAdapter.notifyDataSetChanged(); } @@ -318,10 +320,10 @@ private void addPreferenceSubscriptions() { private void checkKeepScreenOn() { if (ApplicationSettings.getDisplayStaysActiveObservable(this).blockingFirst()) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - binding.navigationBottomBar.setKeepScreenOn(true); + this.navigationBottomBar.setKeepScreenOn(true); } else { getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - binding.navigationBottomBar.setKeepScreenOn(false); + this.navigationBottomBar.setKeepScreenOn(false); } } @@ -382,4 +384,4 @@ public int getCount() { return 3; } } -} +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/SplashScreenActivity.java b/org.envirocar.app/src/org/envirocar/app/views/SplashScreenActivity.java index 3eb38922e..adc9b9d89 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/SplashScreenActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/views/SplashScreenActivity.java @@ -35,7 +35,7 @@ import javax.inject.Inject; -import butterknife.ButterKnife; + import io.reactivex.Completable; import io.reactivex.Observable; import io.reactivex.Single; @@ -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(); @@ -132,4 +131,4 @@ private void startMainActivity() { this.startActivity(intent); finish(); } -} +} \ No newline at end of file From e808e4ddc1e6a8ffe43df3c30c0efc2c66eb2767 Mon Sep 17 00:00:00 2001 From: Akash-Ramjyothi Date: Tue, 12 Jul 2022 09:32:07 +0530 Subject: [PATCH 09/19] Added ViewBinding for carselection Views --- .../carselection/BottomSheetFragment.java | 43 +++++--- .../views/carselection/CarListFragment.java | 28 ++--- .../carselection/CarSelectionActivity.java | 57 +++++----- .../CarSelectionAddCarFragment.java | 30 ++++-- .../CarSelectionAttributeListAdapter.java | 40 ++++--- .../CarSelectionAttributesFragment.java | 102 ++++++++++-------- .../CarSelectionHsnTsnFragment.java | 37 ++++--- .../carselection/CarSelectionListAdapter.java | 24 +++-- 8 files changed, 211 insertions(+), 150 deletions(-) diff --git a/org.envirocar.app/src/org/envirocar/app/views/carselection/BottomSheetFragment.java b/org.envirocar.app/src/org/envirocar/app/views/carselection/BottomSheetFragment.java index 7bcad212f..c9a040b3a 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/carselection/BottomSheetFragment.java +++ b/org.envirocar.app/src/org/envirocar/app/views/carselection/BottomSheetFragment.java @@ -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; @@ -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()); @@ -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(); } -} +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/carselection/CarListFragment.java b/org.envirocar.app/src/org/envirocar/app/views/carselection/CarListFragment.java index 1ac58a490..53b8a871e 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/carselection/CarListFragment.java +++ b/org.envirocar.app/src/org/envirocar/app/views/carselection/CarListFragment.java @@ -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 vehiclesList; - + List 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() { @@ -73,7 +78,7 @@ public void addAndRegisterCar(Vehicles vehicle) { } CarListFragment(List vehiclesList) { - this.vehiclesList = vehiclesList; + this.vehiclesList = vehiclesList; } @Override @@ -81,8 +86,7 @@ public void onDestroy() { super.onDestroy(); } - @OnClick(R.id.fragment_car_list_layout_cancel) - void cancelSheet() { + void cancelSheet(View view) { dismiss(); } -} +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionActivity.java b/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionActivity.java index 657823c50..499f12453 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionActivity.java @@ -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; @@ -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; @@ -69,24 +70,13 @@ */ 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 @@ -94,15 +84,15 @@ public class CarSelectionActivity extends BaseInjectorActivity implements CarSel @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; @@ -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); @@ -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(); } @@ -411,7 +412,7 @@ public Car createCar(Vehicles vehicle) { result.setWeight(weight); result.setVehicleType(vehicleType); - + return result; } @@ -481,4 +482,4 @@ public int getCount() { return Math.min(2, super.getCount()); } } -} +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionAddCarFragment.java b/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionAddCarFragment.java index 44c8218aa..320a75a0d 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionAddCarFragment.java +++ b/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionAddCarFragment.java @@ -38,6 +38,9 @@ import org.envirocar.app.BaseApplicationComponent; import org.envirocar.app.R; +import org.envirocar.app.databinding.ActivityCarSelectionLayoutBinding; +import org.envirocar.app.databinding.ActivityCarSelectionNewcarFragmentBinding; +import org.envirocar.app.databinding.ActivityTrackStatisticsLayoutBinding; import org.envirocar.app.injection.BaseInjectorFragment; import org.envirocar.app.views.utils.ECAnimationUtils; import org.envirocar.core.entity.Manufacturers; @@ -49,9 +52,9 @@ import javax.inject.Inject; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; + + + import info.hoang8f.android.segmented.SegmentedGroup; import io.reactivex.Observable; import io.reactivex.Single; @@ -64,15 +67,15 @@ public class CarSelectionAddCarFragment extends BaseInjectorFragment { private static final Logger LOG = Logger.getLogger(CarSelectionAddCarFragment.class); - @BindView(R.id.envirocar_toolbar) + protected Toolbar toolbar; - @BindView(R.id.activity_car_selection_newcar_toolbar_exp) + protected View toolbarExp; - @BindView(R.id.activity_car_selection_top) + protected View topView; - @BindView(R.id.carSelectionSegmentedGroup) + protected SegmentedGroup segmentedGroup; - @BindView(R.id.activity_car_selection_newcar_content_view) + protected ViewPager mViewPager; @Inject @@ -81,14 +84,21 @@ public class CarSelectionAddCarFragment extends BaseInjectorFragment { private CarSelectionPagerAdapter pagerAdapter; private List manufacturersList; + private ActivityCarSelectionNewcarFragmentBinding binding; @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); + binding = ActivityCarSelectionNewcarFragmentBinding.inflate(inflater,container,false); + View view = binding.getRoot(); + + toolbar = binding.activityCarSelectionLayoutExptoolbar.envirocarToolbar; + toolbarExp = binding.activityCarSelectionNewcarToolbarExp; + topView = binding.activityCarSelectionTop; + segmentedGroup = binding.carSelectionSegmentedGroup; + mViewPager = binding.activityCarSelectionNewcarContentView; - View view = inflater.inflate(R.layout.activity_car_selection_newcar_fragment, container, false); - ButterKnife.bind(this, view); toolbar.setNavigationIcon(R.drawable.ic_close_white_24dp); toolbar.setNavigationOnClickListener(v -> { diff --git a/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionAttributeListAdapter.java b/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionAttributeListAdapter.java index d22e7ec25..cdeb01a89 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionAttributeListAdapter.java +++ b/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionAttributeListAdapter.java @@ -31,12 +31,14 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder; import org.envirocar.app.R; +import org.envirocar.app.databinding.ActivityCarSelectionLayoutCarlistEntryBinding; +import org.envirocar.app.databinding.CarDetailCardLayoutBinding; import org.envirocar.core.entity.Vehicles; import java.util.List; -import butterknife.BindView; -import butterknife.ButterKnife; + + public class CarSelectionAttributeListAdapter extends RecyclerView.Adapter { @@ -118,32 +120,36 @@ public int getItemCount() { public class CarSelectionViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.car_layout_manufacturer_name) TextView manufacturerName; - @BindView(R.id.car_layout_vehcile_name) TextView vehicleName; - @BindView(R.id.car_layout_construction_year) TextView constructionYear; - @BindView(R.id.car_layout_fuel_type) TextView fuelType; - @BindView(R.id.car_layout_engine_capacity) TextView engineCapacity; - @BindView(R.id.car_layout_power) TextView power; - @BindView(R.id.car_layout_card) View carDetailView; - @BindView(R.id.expandView) ImageView imageView1; - @BindView(R.id.car_layout_engine_view) View engineView; - @BindView(R.id.car_layout_expanded_card) View expandCard; - @BindView(R.id.car_layout_hsn_tsn) TextView hsnTsn; - public CarSelectionViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); + CarDetailCardLayoutBinding binding; + public CarSelectionViewHolder(@NonNull View view) { + super(view); + binding = CarDetailCardLayoutBinding.bind(view); + manufacturerName=binding.carLayoutManufacturerName; + vehicleName = binding.carLayoutVehcileName; + constructionYear = binding.carLayoutConstructionYear; + fuelType = binding.carLayoutFuelType; + engineCapacity = binding.carLayoutFuelType; + power = binding.carLayoutFuelType; + carDetailView = binding.carLayoutFuelType; + imageView1 = binding.expandView; + engineView = binding.carLayoutEngineView; + expandCard = binding.carLayoutExpandedCard; + hsnTsn = binding.carLayoutHsnTsn; + } + } -} + +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionAttributesFragment.java b/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionAttributesFragment.java index 44d10cb11..177910b3f 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionAttributesFragment.java +++ b/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionAttributesFragment.java @@ -28,8 +28,10 @@ import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.InputMethodManager; +import android.widget.AdapterView; import android.widget.AutoCompleteTextView; import android.widget.ArrayAdapter; +import android.widget.CompoundButton; import android.widget.EditText; import android.widget.ListAdapter; import android.widget.Spinner; @@ -42,6 +44,8 @@ import org.envirocar.app.BaseApplicationComponent; import org.envirocar.app.R; +import org.envirocar.app.databinding.FragmentCarListBinding; +import org.envirocar.app.databinding.FragmentCarSelectionAttributesBinding; import org.envirocar.app.injection.BaseInjectorFragment; import org.envirocar.core.entity.Manufacturers; import org.envirocar.core.entity.Vehicles; @@ -59,10 +63,7 @@ import javax.inject.Inject; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import butterknife.OnTextChanged; + import io.reactivex.Observable; import io.reactivex.Scheduler; import io.reactivex.Single; @@ -74,22 +75,22 @@ public class CarSelectionAttributesFragment extends BaseInjectorFragment { - @BindView(R.id.fragment_attributes_manufacturer_input) + protected AutoCompleteTextView manufactureEditText; - @BindView(R.id.fragment_attributes_model_input) + protected AutoCompleteTextView modelEditText; - @BindView(R.id.fragment_attributes_year_input) + protected AutoCompleteTextView yearEditText; - @BindView(R.id.fragment_attributes_fueltype_input) + protected AutoCompleteTextView fuelTypeSelection; - @BindView(R.id.fragment_attributes_displacement_input) + protected EditText displacementEditText; - @BindView(R.id.fragment_attributes_weight_input) + protected EditText weightEditText; - @BindView(R.id.fragment_attributes_utility_input) + protected AutoCompleteTextView utilityTypeSelection; - @BindView(R.id.fragment_car_search_button_text) + protected TextView searchButton; @Inject @@ -108,13 +109,27 @@ public class CarSelectionAttributesFragment extends BaseInjectorFragment { this.manufacturersList = manufacturersList; } + private FragmentCarSelectionAttributesBinding binding; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); + binding = FragmentCarSelectionAttributesBinding.inflate(inflater,container,false); + View view = binding.getRoot(); + + + manufactureEditText= binding.fragmentAttributesManufacturerInput; + + modelEditText= binding.fragmentAttributesModelInput; + yearEditText= binding.fragmentAttributesYearInput; + fuelTypeSelection= binding.fragmentAttributesFueltypeInput; + displacementEditText = binding.fragmentAttributesDisplacementInput; + weightEditText= binding.fragmentAttributesWeightInput; + utilityTypeSelection= binding.fragmentAttributesUtilityInput; + searchButton = binding.fragmentCarSearchButtonText; + searchButton.setOnClickListener(this::searchButtonClick); + - View view = inflater.inflate(R.layout.fragment_car_selection_attributes, container, false); - ButterKnife.bind(this, view); fetchManufactures(); initFocusChangedListener(); initManufacturerTextChangeListener(); @@ -128,18 +143,18 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c getContext().getString(R.string.fuel_type_electric), getContext().getString(R.string.fuel_type_gas), getContext().getString(R.string.fuel_type_hybrid)); ArrayAdapter fuelTypesAdapter = new ArrayAdapter<>( - getContext(), - R.layout.activity_car_selection_newcar_fueltype_item, - fuelTypes); + getContext(), + R.layout.activity_car_selection_newcar_fueltype_item, + fuelTypes); fuelTypeSelection.setAdapter(fuelTypesAdapter); fuelTypeSelection.setText(fuelTypesAdapter.getItem(0).toString(), false); String[] utilityTypes = new String[]{getContext().getString(R.string.car_selection_private_vehicle), getContext().getString(R.string.car_selection_utility_car), getContext().getString(R.string.car_selection_taxi)}; ArrayAdapter utilityTypesAdapter = new ArrayAdapter<>( - getContext(), - R.layout.activity_car_selection_newcar_fueltype_item, - utilityTypes); + getContext(), + R.layout.activity_car_selection_newcar_fueltype_item, + utilityTypes); utilityTypeSelection.setAdapter(utilityTypesAdapter); utilityTypeSelection.setText(utilityTypesAdapter.getItem(0).toString(), false); @@ -157,26 +172,25 @@ protected void injectDependencies(BaseApplicationComponent baseApplicationCompon baseApplicationComponent.inject(this); } - @OnTextChanged(value = R.id.fragment_attributes_manufacturer_input, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) - protected void onManufacturerChanged() { + protected void onManufacturerChanged(AdapterView.OnItemSelectedListener listener) { manufactureEditText.setError(null); modelEditText.setText(""); yearEditText.setText(""); } - @OnTextChanged(value = R.id.fragment_attributes_model_input, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) + //@OnTextChanged(value = R.id.fragment_attributes_model_input, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) protected void onModelChanged() { modelEditText.setError(null); yearEditText.setText(""); } - @OnTextChanged(value = R.id.fragment_attributes_year_input, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) + //@OnTextChanged(value = R.id.fragment_attributes_year_input, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED) protected void onYearChanged() { yearEditText.setError(null); } - @OnClick(R.id.fragment_car_search_button) - void searchButtonClick() { + + void searchButtonClick(View view) { String manufacturer = manufactureEditText.getText().toString().trim(); String model = modelEditText.getText().toString().trim(); String year = yearEditText.getText().toString().trim(); @@ -210,20 +224,20 @@ void searchButtonClick() { if (hasStoredVehicle()) { // launch the selection fragment Single> vehicle = enviroCarVehicleDB.vehicleDAO().getVehicleAttributeType(manufacturer, model, year); - vehicle.subscribeOn(Schedulers.io()) - .observeOn(Schedulers.io()) - .subscribeWith(new DisposableSingleObserver>() { - @Override - public void onSuccess(List vehiclesList) { - CarListFragment carListFragment = new CarListFragment(vehiclesList); - carListFragment.show(getFragmentManager(), carListFragment.getTag()); - } + vehicle.subscribeOn(Schedulers.io()) + .observeOn(Schedulers.io()) + .subscribeWith(new DisposableSingleObserver>() { + @Override + public void onSuccess(List vehiclesList) { + CarListFragment carListFragment = new CarListFragment(vehiclesList); + carListFragment.show(getFragmentManager(), carListFragment.getTag()); + } - @Override - public void onError(Throwable e) { - Log.i("fetchError", "" + e.getMessage()); - } - }); + @Override + public void onError(Throwable e) { + Log.i("fetchError", "" + e.getMessage()); + } + }); } else { // create new car without selection Vehicles vehicle = createVehicleFromFields(); @@ -231,7 +245,7 @@ public void onError(Throwable e) { ((CarSelectionActivity) getActivity()).registerCar(vehicle); } } - + } @@ -278,7 +292,7 @@ private Vehicles createVehicleFromFields() { vehicle.setManufacturer(manufacturer); vehicle.setCommerical_name(model); vehicle.setAllotment_date("01.01." + year); - + vehicle.setEngine_capacity(displacement); vehicle.setPower_source_id(getFuelTypeId(fuelType)); @@ -305,10 +319,10 @@ else if (id.equalsIgnoreCase(getContext().getString(R.string.fuel_type_gas))) @NonNull protected String getEnglishString(int res) { Configuration configuration = getEnglishConfiguration(); - + return getContext().createConfigurationContext(configuration).getResources().getString(res); } - + @NonNull private Configuration getEnglishConfiguration() { Configuration configuration = new Configuration(getContext().getResources().getConfiguration()); @@ -546,4 +560,4 @@ public void hideKeyboard(View view) { InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); } -} +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionHsnTsnFragment.java b/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionHsnTsnFragment.java index 488a4bca0..2d34187ee 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionHsnTsnFragment.java +++ b/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionHsnTsnFragment.java @@ -23,6 +23,7 @@ import android.graphics.drawable.Drawable; import android.os.Bundle; import android.util.Log; +import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -38,6 +39,8 @@ import org.envirocar.app.BaseApplicationComponent; import org.envirocar.app.R; +import org.envirocar.app.databinding.FragmentCarSelectionAttributesBinding; +import org.envirocar.app.databinding.FragmentCarSelectionHsnTsnBinding; import org.envirocar.app.injection.BaseInjectorFragment; import org.envirocar.core.entity.Manufacturers; import org.envirocar.core.entity.Vehicles; @@ -53,10 +56,10 @@ import javax.inject.Inject; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import butterknife.OnEditorAction; + + + + import io.reactivex.Observable; import io.reactivex.Scheduler; import io.reactivex.Single; @@ -68,9 +71,9 @@ public class CarSelectionHsnTsnFragment extends BaseInjectorFragment { - @BindView(R.id.fragment_hsntsn_hsn_input) + protected AutoCompleteTextView hsnEditText; - @BindView(R.id.fragment_hsntsn_tsn_input) + protected AutoCompleteTextView tsnEditText; protected BottomSheetFragment bottomSheetFragment; @@ -91,12 +94,18 @@ public class CarSelectionHsnTsnFragment extends BaseInjectorFragment { this.manufacturersList = manufacturersList; } + private FragmentCarSelectionHsnTsnBinding binding; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); - View view = inflater.inflate(R.layout.fragment_car_selection_hsn_tsn, container, false); - ButterKnife.bind(this, view); + binding = FragmentCarSelectionHsnTsnBinding.inflate(inflater,container,false); + View view = binding.getRoot(); + + hsnEditText = binding.fragmentHsntsnHsnInput; + tsnEditText = binding.fragmentHsntsnTsnInput; + //tsnEditText.onEditorAction(this::implicitSubmit); + fetchAllVehicles(); reactiveTexFieldCheck(); focusChangeListener(); @@ -124,8 +133,8 @@ private void requestNextTextFieldFocus(TextView textView) { hideKeyboard(textView); } - @OnClick(R.id.fragment_search_vehicle) - protected void onSearchClicked() { + //@OnClick(R.id.fragment_search_vehicle) + protected void onSearchClicked(View view) { String hsnWithManufactureName = hsnEditText.getText().toString().trim(); String tsn = tsnEditText.getText().toString().trim(); View focusView = null; @@ -172,9 +181,9 @@ protected void injectDependencies(BaseApplicationComponent baseApplicationCompon baseApplicationComponent.inject(this); } - @OnEditorAction(R.id.fragment_hsntsn_tsn_input) - protected void implicitSubmit() { - onSearchClicked(); + //@OnEditorAction(R.id.fragment_hsntsn_tsn_input) + protected void implicitSubmit(TextView var1, int var2, KeyEvent var3) { + onSearchClicked(var1); } private void fetchAllVehicles() { @@ -298,4 +307,4 @@ public void hideKeyboard(View view) { InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE); inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); } -} +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionListAdapter.java b/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionListAdapter.java index 6b71f916d..b6c996a44 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionListAdapter.java +++ b/org.envirocar.app/src/org/envirocar/app/views/carselection/CarSelectionListAdapter.java @@ -34,14 +34,16 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder; import org.envirocar.app.R; +import org.envirocar.app.databinding.ActivityCarSelectionLayoutBinding; +import org.envirocar.app.databinding.ActivityCarSelectionLayoutCarlistEntryBinding; import org.envirocar.core.entity.Car; import org.envirocar.core.logging.Logger; import org.envirocar.core.utils.CarUtils; import java.util.List; -import butterknife.ButterKnife; -import butterknife.BindView; + + /** * @author dewall @@ -231,15 +233,15 @@ static class CarViewHolder { protected final View mCoreView; - @BindView(R.id.activity_car_selection_layout_carlist_entry_icon) + protected ImageView iconView; - @BindView(R.id.activity_car_selection_layout_carlist_entry_firstline) + protected TextView firstLine; - @BindView(R.id.activity_car_selection_layout_carlist_entry_secondline) + protected TextView secondLine; - @BindView(R.id.activity_car_selection_layout_carlist_entry_radio) + protected RadioButton mRadioButton; - @BindView(R.id.activity_car_selection_layout_carlist_delete_icon) + protected ImageButton mDeleteButton; /** @@ -247,9 +249,15 @@ static class CarViewHolder { * * @param view */ + protected ActivityCarSelectionLayoutCarlistEntryBinding binding; CarViewHolder(View view) { this.mCoreView = view; - ButterKnife.bind(this, view); + binding = ActivityCarSelectionLayoutCarlistEntryBinding.bind(view); + iconView = binding.activityCarSelectionLayoutCarlistEntryIcon; + firstLine = binding.activityCarSelectionLayoutCarlistEntryFirstline; + secondLine = binding.activityCarSelectionLayoutCarlistEntrySecondline; + mRadioButton = binding.activityCarSelectionLayoutCarlistEntryRadio; + mDeleteButton = binding.activityCarSelectionLayoutCarlistDeleteIcon; } } } \ No newline at end of file From 6da345c1bcef39cf39e75a89064dcad66d61e688 Mon Sep 17 00:00:00 2001 From: Akash-Ramjyothi Date: Tue, 12 Jul 2022 09:33:40 +0530 Subject: [PATCH 10/19] Added Jetpack ViewBinding for dashboard Views --- .../views/dashboard/DashboardFragment.java | 218 ++++++++++-------- 1 file changed, 126 insertions(+), 92 deletions(-) diff --git a/org.envirocar.app/src/org/envirocar/app/views/dashboard/DashboardFragment.java b/org.envirocar.app/src/org/envirocar/app/views/dashboard/DashboardFragment.java index 79ef72806..6261ea3f7 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/dashboard/DashboardFragment.java +++ b/org.envirocar.app/src/org/envirocar/app/views/dashboard/DashboardFragment.java @@ -74,6 +74,8 @@ import org.envirocar.app.BaseApplicationComponent; import org.envirocar.app.R; +import org.envirocar.app.databinding.ActivityBaseMainBottomBarBinding; +import org.envirocar.app.databinding.FragmentDashboardViewNewBinding; import org.envirocar.app.handler.agreement.AgreementManager; import org.envirocar.app.handler.ApplicationSettings; import org.envirocar.app.handler.BluetoothHandler; @@ -114,10 +116,8 @@ import javax.inject.Inject; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnCheckedChanged; -import butterknife.OnClick; + + import info.hoang8f.android.segmented.SegmentedGroup; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; @@ -136,78 +136,71 @@ public class DashboardFragment extends BaseInjectorFragment { private static final int LOCATION_PERMISSION_REQUEST_CODE = 1203; // View Injections - @BindView(R.id.fragment_dashboard_toolbar) + protected Toolbar toolbar; - @BindView(R.id.fragment_dashboard_username) + protected TextView textView; - @BindView(R.id.fragment_dashboard_logged_in_layout) + protected View loggedInLayout; - @BindView(R.id.fragment_dashboard_user_tracks_layout) protected View userTracksLayout; - @BindView(R.id.fragment_dashboard_user_tracks_textview) + protected TextView userTracksTextView; - @BindView(R.id.fragment_dashboard_user_distance_layout) + protected View userDistanceLayout; - @BindView(R.id.fragment_dashboard_user_distance_textview) + protected TextView userDistanceTextView; - @BindView(R.id.fragment_dashboard_user_duration_layout) + protected View userDurationLayout; - @BindView(R.id.fragment_dashboard_user_duration_textview) + protected TextView userDurationTextView; - @BindView(R.id.fragment_dashboard_user_statistics_progress) + protected ProgressBar userStatProgressBar; - @BindView(R.id.fragment_dashboard_indicator_view) protected ViewGroup indicatorView; - @BindView(R.id.fragment_dashboard_indicator_bluetooth_layout) + protected View bluetoothIndicatorLayout; - @BindView(R.id.fragment_dashboard_indicator_bluetooth) + protected ImageView bluetoothIndicator; - @BindView(R.id.fragment_dashboard_indicator_obd_layout) + protected View obdIndicatorLayout; - @BindView(R.id.fragment_dashboard_indicator_obd) + protected ImageView obdIndicator; - @BindView(R.id.fragment_dashboard_indicator_gps) + protected ImageView gpsIndicator; - @BindView(R.id.fragment_dashboard_indicator_car) + protected ImageView carIndicator; - @BindView(R.id.fragment_dashboard_indicator_bluetooth_text) protected SizeSyncTextView bluetoothIndicatorText; - @BindView(R.id.fragment_dashboard_indicator_obd_text) + protected SizeSyncTextView obdIndicatorText; - @BindView(R.id.fragment_dashboard_indicator_gps_text) + protected SizeSyncTextView gpsIndicatorText; - @BindView(R.id.fragment_dashboard_indicator_car_text) + protected SizeSyncTextView carIndicatorText; - @BindView(R.id.fragment_dashboard_mode_selector) protected SegmentedGroup modeSegmentedGroup; - @BindView(R.id.fragment_dashboard_obd_mode_button) + protected RadioButton obdModeRadioButton; - @BindView(R.id.fragment_dashboard_gps_mode_button) + protected RadioButton gpsModeRadioButton; - @BindView(R.id.fragment_dashboard_obdselection_layout) protected ViewGroup bluetoothSelectionView; - @BindView(R.id.fragment_dashboard_obdselection_text_primary) + protected TextView bluetoothSelectionTextPrimary; - @BindView(R.id.fragment_dashboard_obdselection_text_secondary) + protected TextView bluetoothSelectionTextSecondary; - @BindView(R.id.fragment_dashboard_carselection_text_primary) + protected TextView carSelectionTextPrimary; - @BindView(R.id.fragment_dashboard_carselection_text_secondary) + protected TextView carSelectionTextSecondary; - @BindView(R.id.fragment_dashboard_banner) protected FrameLayout bannerLayout; - @BindView(R.id.fragment_dashboard_main_layout) + protected ConstraintLayout mainLayout; - @BindView(R.id.fragment_dashboard_start_track_button) protected View startTrackButton; - @BindView(R.id.fragment_dashboard_start_track_button_text) + protected TextView startTrackButtonText; // injected variables @@ -244,14 +237,55 @@ public void onCreate(@Nullable Bundle savedInstanceState) { this.disposables = new CompositeDisposable(); } + private FragmentDashboardViewNewBinding binding; @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - // Inflate view first - View contentView = inflater.inflate(R.layout.fragment_dashboard_view_new, container, false); - // Bind views - ButterKnife.bind(this, contentView); + binding = FragmentDashboardViewNewBinding.inflate(inflater,container,false); + View view = binding.getRoot(); + + toolbar = binding.fragmentDashboardToolbar; + textView = binding.fragmentDashboardUsername; + loggedInLayout = binding.fragmentDashboardLoggedInLayout; + userTracksLayout = binding.fragmentDashboardUserTracksLayout; + userTracksTextView = binding.fragmentDashboardUserTracksTextview; + userDistanceLayout = binding.fragmentDashboardUserDistanceLayout; + userDistanceTextView = binding.fragmentDashboardUserDistanceTextview; + userDurationLayout = binding.fragmentDashboardUserDurationLayout; + userDurationTextView = binding.fragmentDashboardUserDurationTextview; + userStatProgressBar = binding.fragmentDashboardUserStatisticsProgress; + indicatorView = binding.fragmentDashboardIndicatorView; + bluetoothIndicatorLayout = binding.fragmentDashboardIndicatorBluetoothLayout; + bluetoothIndicator = binding.fragmentDashboardIndicatorBluetooth; + bluetoothIndicator.setOnClickListener(this::onBluetoothIndicatorClicked); + obdIndicatorLayout = binding.fragmentDashboardIndicatorObdLayout; + obdIndicator = binding.fragmentDashboardIndicatorObd; + obdIndicator.setOnClickListener(this::onObdIndicatorClicked); + gpsIndicator = binding.fragmentDashboardIndicatorGps; + gpsIndicator.setOnClickListener(this::onGPSIndicatorClicked); + carIndicator = binding.fragmentDashboardIndicatorCar; + carIndicator.setOnClickListener(this::onCarIndicatorClicked); + bluetoothIndicatorText = binding.fragmentDashboardIndicatorBluetoothText; + obdIndicatorText = binding.fragmentDashboardIndicatorObdText; + gpsIndicatorText = binding.fragmentDashboardIndicatorGpsText; + carIndicatorText = binding.fragmentDashboardIndicatorCarText; + modeSegmentedGroup = binding.fragmentDashboardModeSelector; + obdModeRadioButton = binding.fragmentDashboardObdModeButton; + gpsModeRadioButton = binding.fragmentDashboardGpsModeButton; + bluetoothSelectionView = binding.fragmentDashboardObdselectionLayout; + bluetoothSelectionView.setOnClickListener(this::onBluetoothSelectionClicked); + bluetoothSelectionTextPrimary = binding.fragmentDashboardObdselectionTextPrimary; + bluetoothSelectionTextSecondary = binding.fragmentDashboardObdselectionTextSecondary; + carSelectionTextPrimary = binding.fragmentDashboardCarselectionTextPrimary; + carSelectionTextSecondary = binding.fragmentDashboardCarselectionTextSecondary; + bannerLayout = binding.fragmentDashboardBanner; + mainLayout = binding.fragmentDashboardMainLayout; + startTrackButton = binding.fragmentDashboardStartTrackButton; + startTrackButton.setOnClickListener(this::onStartTrackButtonClicked); + startTrackButtonText = binding.fragmentDashboardStartTrackButtonText; + + // inflate menus and init toolbar clicks toolbar.inflateMenu(R.menu.menu_dashboard_logged_out); @@ -273,7 +307,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c .doOnError(LOG::error) .blockingFirst(); - return contentView; + return view; } @Override @@ -304,7 +338,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis LOG.info("Location permission has been granted"); Snackbar.make(getView(), "Location Permission granted.", BaseTransientBottomBar.LENGTH_SHORT).show(); - onStartTrackButtonClicked(); + onStartTrackButtonClicked(getView()); } else { LOG.info("Location permission has been denied"); Snackbar.make(getView(), "Location Permission denied.", @@ -342,7 +376,7 @@ private void onToolbarItemClicked(MenuItem menuItem) { } } - + private DisposableCompletableObserver onLogoutSubscriber() { return new DisposableCompletableObserver() { @@ -379,7 +413,7 @@ public void onError(Throwable e) { }; } - @OnCheckedChanged({R.id.fragment_dashboard_obd_mode_button, R.id.fragment_dashboard_gps_mode_button}) + //@OnCheckedChanged({R.id.fragment_dashboard_obd_mode_button, R.id.fragment_dashboard_gps_mode_button}) public void onModeChangedClicked(CompoundButton button, boolean checked) { if (!checked) return; @@ -447,22 +481,22 @@ private void setRecordingMode(RecordingType selectedRT) { } // OnClick Handler - @OnClick(R.id.fragment_dashboard_carselection_layout) - protected void onCarSelectionClicked() { + // @OnClick(R.id.fragment_dashboard_carselection_layout) + protected void onCarSelectionClicked(View view) { LOG.info("Clicked on Carselection."); Intent intent = new Intent(getActivity(), CarSelectionActivity.class); getActivity().startActivity(intent); } - @OnClick(R.id.fragment_dashboard_obdselection_layout) - protected void onBluetoothSelectionClicked() { + //@OnClick(R.id.fragment_dashboard_obdselection_layout) + protected void onBluetoothSelectionClicked(View view) { LOG.info("Clicked on Bluetoothselection."); Intent intent = new Intent(getActivity(), OBDSelectionActivity.class); getActivity().startActivity(intent); } - @OnClick(R.id.fragment_dashboard_start_track_button) - protected void onStartTrackButtonClicked() { + //@OnClick(R.id.fragment_dashboard_start_track_button) + protected void onStartTrackButtonClicked(View view) { LOG.info("Clicked on Start Track Button"); User user = userHandler.getUser(); @@ -474,8 +508,8 @@ protected void onStartTrackButtonClicked() { String[] perms; if (android.os.Build.VERSION.SDK_INT >= 31) { perms = new String[]{ - Manifest.permission.ACCESS_FINE_LOCATION, - Manifest.permission.ACCESS_COARSE_LOCATION + Manifest.permission.ACCESS_FINE_LOCATION, + Manifest.permission.ACCESS_COARSE_LOCATION }; } else { @@ -486,9 +520,9 @@ protected void onStartTrackButtonClicked() { ActivityCompat.requestPermissions(getActivity(), perms, LOCATION_PERMISSION_REQUEST_CODE); } else if (user == null && ApplicationSettings.isTrackchunkUploadEnabled(getContext())) { - // cannot start, we need a user - LOG.info("cannot start, login is required for chunk upload feature"); - Snackbar.make(getView(), + // cannot start, we need a user + LOG.info("cannot start, login is required for chunk upload feature"); + Snackbar.make(getView(), getString(R.string.dashboard_track_chunks_enabled_login), Snackbar.LENGTH_LONG).show(); } else if (user != null) { @@ -496,29 +530,29 @@ protected void onStartTrackButtonClicked() { if (ApplicationSettings.isTrackchunkUploadEnabled(getContext())) { LOG.info("chunk upload is enabled, checking TermsOfUse"); mAgreementManager.verifyTermsOfUse(null, true) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(termsOfUse -> { - if (termsOfUse != null) { - startRecording(); - } else { - LOG.warn("No TermsOfUse received from verification"); - } - }, e -> { - LOG.warn("Error during TermsOfUse verification", e); - // inform the user about ToU acceptance - Snackbar sb = Snackbar.make(getView(), String.format(getString(R.string.dashboard_accept_tou), getString(R.string.title_others)), Snackbar.LENGTH_INDEFINITE).setAction("OK", new View.OnClickListener() { - @Override - public void onClick(View v) { - LOG.info("ToU Snackbar closed"); - Intent intent = new Intent(getActivity(), TermsOfUseActivity.class); - getActivity().startActivity(intent); + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(termsOfUse -> { + if (termsOfUse != null) { + startRecording(); + } else { + LOG.warn("No TermsOfUse received from verification"); } + }, e -> { + LOG.warn("Error during TermsOfUse verification", e); + // inform the user about ToU acceptance + Snackbar sb = Snackbar.make(getView(), String.format(getString(R.string.dashboard_accept_tou), getString(R.string.title_others)), Snackbar.LENGTH_INDEFINITE).setAction("OK", new View.OnClickListener() { + @Override + public void onClick(View v) { + LOG.info("ToU Snackbar closed"); + Intent intent = new Intent(getActivity(), TermsOfUseActivity.class); + getActivity().startActivity(intent); + } + }); + Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) sb.getView(); + layout.setMinimumHeight(100); + sb.show(); }); - Snackbar.SnackbarLayout layout = (Snackbar.SnackbarLayout) sb.getView(); - layout.setMinimumHeight(100); - sb.show(); - }); } else { // we can check the ToUs later before upload LOG.info("A user is logged in, chunk upload is disabled"); @@ -544,9 +578,9 @@ private void startRecording() { Intent obdRecordingIntent = new Intent(getActivity(), RecordingService.class); this.connectingDialog = DialogUtils.createProgressBarDialogBuilder(getContext(), - R.string.dashboard_connecting, - R.drawable.ic_bluetooth_white_24dp, - String.format(getString(R.string.dashboard_connecting_find_template), device.getName())) + R.string.dashboard_connecting, + R.drawable.ic_bluetooth_white_24dp, + String.format(getString(R.string.dashboard_connecting_find_template), device.getName())) .setNegativeButton(R.string.cancel, (dialog, which) -> { ServiceUtils.stopService(getActivity(), obdRecordingIntent); }) @@ -581,38 +615,38 @@ public void onFinish() { } } - - @OnClick(R.id.fragment_dashboard_indicator_car) - protected void onCarIndicatorClicked() { + + //@OnClick(R.id.fragment_dashboard_indicator_car) + protected void onCarIndicatorClicked(View view) { LOG.info("Car Indicator clicked"); Intent intent = new Intent(getActivity(), CarSelectionActivity.class); getActivity().startActivity(intent); } - @OnClick(R.id.fragment_dashboard_indicator_obd) - protected void onObdIndicatorClicked() { + //@OnClick(R.id.fragment_dashboard_indicator_obd) + protected void onObdIndicatorClicked(View view) { LOG.info("OBD indicator clicked"); Intent intent = new Intent(getActivity(), OBDSelectionActivity.class); getActivity().startActivity(intent); } - @OnClick(R.id.fragment_dashboard_indicator_bluetooth) - protected void onBluetoothIndicatorClicked() { + //@OnClick(R.id.fragment_dashboard_indicator_bluetooth) + protected void onBluetoothIndicatorClicked(View view) { LOG.info("Bluetooth indicator clicked"); Intent intent = new Intent(getActivity(), OBDSelectionActivity.class); getActivity().startActivity(intent); } - @OnClick(R.id.fragment_dashboard_indicator_gps) - protected void onGPSIndicatorClicked() { + //@OnClick(R.id.fragment_dashboard_indicator_gps) + protected void onGPSIndicatorClicked(View view) { LOG.info("GPS indicator clicked"); Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); getActivity().startActivity(intent); } - @OnClick(R.id.user_statistics_card_view) - protected void onUserStatsClicked() { + //@OnClick(R.id.user_statistics_card_view) + protected void onUserStatsClicked(View view) { BottomNavigationView bottomView = getActivity().findViewById(R.id.navigation); bottomView.setSelectedItemId(R.id.navigation_my_tracks); } @@ -956,4 +990,4 @@ public void onActivityResult(int requestCode, int resultCode, @Nullable Intent d appUpdateCheck(); } } -} +} \ No newline at end of file From baa3e26bf257bc246c62e3361e3b8b0ae9403b4c Mon Sep 17 00:00:00 2001 From: Akash-Ramjyothi Date: Tue, 12 Jul 2022 09:36:37 +0530 Subject: [PATCH 11/19] Added Jetpack ViewBinding for logbook Views --- .../app/views/logbook/LogbookActivity.java | 52 ++++++++----- .../logbook/LogbookAddFuelingFragment.java | 76 ++++++++++++------- .../logbook/LogbookCarSpinnerAdapter.java | 22 ++++-- .../app/views/logbook/LogbookListAdapter.java | 41 ++++++---- 4 files changed, 127 insertions(+), 64 deletions(-) diff --git a/org.envirocar.app/src/org/envirocar/app/views/logbook/LogbookActivity.java b/org.envirocar.app/src/org/envirocar/app/views/logbook/LogbookActivity.java index 03081a1bf..9ba8fa089 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/logbook/LogbookActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/views/logbook/LogbookActivity.java @@ -39,6 +39,7 @@ import org.envirocar.app.BaseApplicationComponent; import org.envirocar.app.R; +import org.envirocar.app.databinding.ActivityLogbookBinding; import org.envirocar.app.handler.preferences.CarPreferenceHandler; import org.envirocar.app.views.utils.ECAnimationUtils; import org.envirocar.core.ContextInternetAccessProvider; @@ -57,9 +58,9 @@ import javax.inject.Inject; -import butterknife.ButterKnife; -import butterknife.BindView; -import butterknife.OnClick; + + + import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.observers.DisposableObserver; @@ -80,24 +81,24 @@ public class LogbookActivity extends BaseInjectorActivity implements LogbookUiLi @Inject protected UserManager userManager; - @BindView(R.id.activity_logbook_toolbar) + protected Toolbar toolbar; - @BindView(R.id.activity_logbook_header) + protected View headerView; - @BindView(R.id.activity_logbook_toolbar_new_fueling_fab) + protected View newFuelingFab; - @BindView(R.id.activity_logbook_toolbar_fuelinglist) + protected ListView fuelingList; - @BindView(R.id.overlay) + protected View overlayView; - @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_logbook_not_logged_in) @@ -116,16 +117,31 @@ protected void injectDependencies(BaseApplicationComponent baseApplicationCompon baseApplicationComponent.inject(this); } + private ActivityLogbookBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { LOG.info("onCreate()"); super.onCreate(savedInstanceState); - + binding = ActivityLogbookBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); // First, set the content view. - setContentView(R.layout.activity_logbook); + setContentView(view); + + toolbar = binding.activityLogbookToolbar; + headerView = binding.activityLogbookHeader; + newFuelingFab = binding.activityLogbookToolbarNewFuelingFab; + newFuelingFab.setOnClickListener(this::onClickNewFuelingFAB); + fuelingList = binding.activityLogbookToolbarFuelinglist; + overlayView = binding.overlay; + + infoBackground = binding.layoutGeneralInfoBackground.getRoot(); + infoBackgroundImg = binding.layoutGeneralInfoBackground.layoutGeneralInfoBackgroundImg; + infoBackgroundFirst = binding.layoutGeneralInfoBackground.layoutGeneralInfoBackgroundFirstline; + infoBackgroundSecond = binding.layoutGeneralInfoBackground.layoutGeneralInfoBackgroundSecondline; + // Inject the Views. - ButterKnife.bind(this); + // Initializes the Toolbar. setSupportActionBar(toolbar); @@ -187,8 +203,8 @@ public void onBackPressed() { super.onBackPressed(); } - @OnClick(R.id.activity_logbook_toolbar_new_fueling_fab) - protected void onClickNewFuelingFAB() { + //@OnClick(R.id.activity_logbook_toolbar_new_fueling_fab) + protected void onClickNewFuelingFAB(View view) { if(carHandler.hasCars()) { // Click on the fab should first hide the fab and then open the AddFuelingFragment showAddFuelingCard(); @@ -374,4 +390,4 @@ private void hideAddFuelingCard() { private void showSnackbarInfo(int resourceID) { Snackbar.make(newFuelingFab, resourceID, Snackbar.LENGTH_LONG).show(); } -} +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/logbook/LogbookAddFuelingFragment.java b/org.envirocar.app/src/org/envirocar/app/views/logbook/LogbookAddFuelingFragment.java index 53f096cde..0b2eae278 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/logbook/LogbookAddFuelingFragment.java +++ b/org.envirocar.app/src/org/envirocar/app/views/logbook/LogbookAddFuelingFragment.java @@ -48,6 +48,8 @@ import org.envirocar.app.BaseApplicationComponent; import org.envirocar.app.R; +import org.envirocar.app.databinding.ActivityLogbookAddFuelingCardBinding; +import org.envirocar.app.databinding.FragmentDashboardViewNewBinding; import org.envirocar.app.handler.DAOProvider; import org.envirocar.app.handler.preferences.CarPreferenceHandler; import org.envirocar.app.injection.BaseInjectorFragment; @@ -72,8 +74,8 @@ import javax.inject.Inject; -import butterknife.BindView; -import butterknife.ButterKnife; + + import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.observers.DisposableObserver; @@ -98,38 +100,38 @@ public class LogbookAddFuelingFragment extends BaseInjectorFragment { DECIMAL_FORMATTER_3.setDecimalFormatSymbols(symbols); } - @BindView(R.id.logbook_layout_addfueling_toolbar) + protected Toolbar addFuelingToolbar; - @BindView(R.id.activity_log_book_add_fueling_toolbar_exp) + protected View addFuelingToolbarExp; - @BindView(R.id.activity_logbook_add_fueling_card_content) + protected View contentView; - @BindView(R.id.activity_logbook_add_fueling_card_scrollview) + protected View contentScrollview; - @BindView(R.id.activity_logbook_add_fueling_car_selection) + protected Spinner addFuelingCarSelection; - @BindView(R.id.logbook_add_fueling_milagetext) + protected EditText addFuelingMilageText; - @BindView(R.id.logbook_add_fueling_volumetext) + protected EditText addFuelingVolumeText; - @BindView(R.id.logbook_add_fueling_totalpricetext) + protected EditText addFuelingTotalCostText; - @BindView(R.id.logbook_add_fueling_priceperlitretext) + protected EditText addFuelingPricePerLitreText; - @BindView(R.id.logbook_add_fueling_partialfueling_checkbox) + protected CheckBox partialFuelingCheckbox; - @BindView(R.id.logbook_add_fueling_missedfueling_checkbox) + protected CheckBox missedFuelingCheckbox; - @BindView(R.id.logbook_add_fueling_comment) + protected EditText commentText; - @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; @Inject @@ -139,15 +141,35 @@ public class LogbookAddFuelingFragment extends BaseInjectorFragment { private CompositeDisposable subscriptions = new CompositeDisposable(); + private ActivityLogbookAddFuelingCardBinding binding; @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); + binding = ActivityLogbookAddFuelingCardBinding.inflate(inflater,container,false); + View view = binding.getRoot(); + + addFuelingToolbar = binding.logbookLayoutAddfuelingToolbar; + addFuelingToolbarExp = binding.activityLogBookAddFuelingToolbarExp; + contentView = binding.activityLogbookAddFuelingCardContent; + contentScrollview = binding.activityLogbookAddFuelingCardScrollview; + addFuelingCarSelection = binding.activityLogbookAddFuelingCarSelection; + addFuelingMilageText = binding.logbookAddFuelingMilagetext; + addFuelingVolumeText = binding.logbookAddFuelingVolumetext; + addFuelingTotalCostText = binding.logbookAddFuelingTotalpricetext; + addFuelingPricePerLitreText = binding.logbookAddFuelingPriceperlitretext; + partialFuelingCheckbox = binding.logbookAddFuelingPartialfuelingCheckbox; + missedFuelingCheckbox = binding.logbookAddFuelingMissedfuelingCheckbox; + commentText = binding.logbookAddFuelingComment; + + infoBackground = binding.layoutGeneralInfoBackground.getRoot(); + infoBackgroundImg = binding.layoutGeneralInfoBackground.layoutGeneralInfoBackgroundImg; + infoBackgroundFirst = binding.layoutGeneralInfoBackground.layoutGeneralInfoBackgroundFirstline; + infoBackgroundSecond = binding.layoutGeneralInfoBackground.layoutGeneralInfoBackgroundSecondline; // Inflate the view and inject the annotated view. - View view = inflater.inflate(R.layout.activity_logbook_add_fueling_card, container, false); - ButterKnife.bind(this, view); + view.setOnClickListener(v -> hideKeyboard(view)); contentView.setOnClickListener(v -> hideKeyboard(contentView)); @@ -440,9 +462,9 @@ private void uploadCarBeforeFueling(final Car car, final Fueling fueling) { protected void onStart() { LOG.info("uploadCarBeforeFueling() has started"); dialog = DialogUtils.createProgressBarDialogBuilder(getContext(), - R.string.logbook_dialog_uploading_fueling_header, - R.drawable.others_logbook_white_24dp, - R.string.logbook_dialog_uploading_fueling_car) + R.string.logbook_dialog_uploading_fueling_header, + R.drawable.others_logbook_white_24dp, + R.string.logbook_dialog_uploading_fueling_car) .setCancelable(false) .show(); } @@ -498,9 +520,9 @@ private void uploadFueling(Fueling fueling) { public void onStart() { LOG.info("Started the creation of a fueling."); dialog = DialogUtils.createProgressBarDialogBuilder(getContext(), - R.string.logbook_dialog_uploading_fueling_header, - R.drawable.others_logbook_white_24dp, - R.string.logbook_dialog_uploading_fueling_content) + R.string.logbook_dialog_uploading_fueling_header, + R.drawable.others_logbook_white_24dp, + R.string.logbook_dialog_uploading_fueling_content) .setCancelable(false) .show(); } @@ -662,4 +684,4 @@ public void hideKeyboard(View view) { inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); } -} +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/logbook/LogbookCarSpinnerAdapter.java b/org.envirocar.app/src/org/envirocar/app/views/logbook/LogbookCarSpinnerAdapter.java index b43fd8799..4a4053b37 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/logbook/LogbookCarSpinnerAdapter.java +++ b/org.envirocar.app/src/org/envirocar/app/views/logbook/LogbookCarSpinnerAdapter.java @@ -26,12 +26,14 @@ import android.widget.TextView; import org.envirocar.app.R; +import org.envirocar.app.databinding.ActivityCarSelectionLayoutCarlistEntryBinding; +import org.envirocar.app.databinding.ActivityLogbookCarSpinnerEntryBinding; import org.envirocar.core.entity.Car; import java.util.List; -import butterknife.ButterKnife; -import butterknife.BindView; + + /** * TODO JavaDoc @@ -52,6 +54,8 @@ public LogbookCarSpinnerAdapter(Context context, List objects) { super(context, R.layout.activity_logbook_car_spinner_entry, R.id .activity_logbook_car_spinner_entry_firstline, objects); this.cars = objects; + + } @Override @@ -87,9 +91,9 @@ public View getDropDownView(int position, View convertView, ViewGroup parent) { static class CarSpinnerEntryHolder { - @BindView(R.id.activity_logbook_car_spinner_entry_firstline) + protected TextView title; - @BindView(R.id.activity_logbook_car_spinner_entry_secondline) + protected TextView secondLine; @@ -98,8 +102,14 @@ static class CarSpinnerEntryHolder { * * @param view the parent view of an entry in the car spinner. */ + + protected ActivityLogbookCarSpinnerEntryBinding binding; CarSpinnerEntryHolder(View view) { - ButterKnife.bind(this, view); + binding = ActivityLogbookCarSpinnerEntryBinding.bind(view); + title = binding.activityLogbookCarSpinnerEntryFirstline; + secondLine = binding.activityLogbookCarSpinnerEntrySecondline; + + } } -} +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/logbook/LogbookListAdapter.java b/org.envirocar.app/src/org/envirocar/app/views/logbook/LogbookListAdapter.java index 009c8058b..1cb701383 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/logbook/LogbookListAdapter.java +++ b/org.envirocar.app/src/org/envirocar/app/views/logbook/LogbookListAdapter.java @@ -26,6 +26,8 @@ import android.widget.TextView; import org.envirocar.app.R; +import org.envirocar.app.databinding.ActivityCarSelectionLayoutCarlistEntryBinding; +import org.envirocar.app.databinding.ActivityLogbookListentryBinding; import org.envirocar.core.entity.Car; import org.envirocar.core.entity.Fueling; import org.envirocar.app.views.utils.DateUtils; @@ -37,8 +39,8 @@ import java.util.GregorianCalendar; import java.util.List; -import butterknife.ButterKnife; -import butterknife.BindView; + + /** * TODO JavaDoc @@ -119,33 +121,46 @@ public Fueling getItem(int position) { } static class FuelingViewHolder { - @BindView(R.id.activity_logbook_listentry_date) + protected TextView dateText; - @BindView(R.id.activity_logbook_listentry_kmliter) + protected TextView kmAndLiter; - @BindView(R.id.activity_logbook_listentry_priceperliter) + protected TextView pricePerLiter; - @BindView(R.id.activity_logbook_listentry_totalprice) + protected TextView totalPrice; - @BindView(R.id.activity_logbook_listentry_car) + protected TextView car; - @BindView(R.id.activity_logbook_listentry_comment_view) + protected View commentView; - @BindView(R.id.activity_logbook_listentry_comment) + protected TextView commentText; - @BindView(R.id.activity_logbook_listentry_fillup) + protected View filledUpView; - @BindView(R.id.activity_logbook_listentry_missedfillup) + protected View missedFillUpView; + + protected ActivityLogbookListentryBinding binding; /** * Constructor. * * @param view the core view to inject the subviews from. */ FuelingViewHolder(View view) { - ButterKnife.bind(this, view); + binding = ActivityLogbookListentryBinding.bind(view); + dateText = binding.activityLogbookListentryDate; + kmAndLiter = binding.activityLogbookListentryKmliter; + pricePerLiter = binding.activityLogbookListentryPriceperliter; + totalPrice = binding.activityLogbookListentryTotalprice; + + car = binding.activityLogbookListentryCar; + commentView = binding.activityLogbookListentryCommentView; + commentText = binding.activityLogbookListentryComment; + filledUpView = binding.activityLogbookListentryFillup; + missedFillUpView = binding.activityLogbookListentryMissedfillup; + } } -} +} \ No newline at end of file From 2fb042c7f94cf52be98321187a145bdedfa65e09 Mon Sep 17 00:00:00 2001 From: Akash-Ramjyothi Date: Tue, 12 Jul 2022 09:38:11 +0530 Subject: [PATCH 12/19] Added Jetpack ViewBinding for login Views --- .../app/views/login/SigninActivity.java | 95 ++++++++++++------- .../app/views/login/SignupActivity.java | 72 ++++++++------ 2 files changed, 103 insertions(+), 64 deletions(-) diff --git a/org.envirocar.app/src/org/envirocar/app/views/login/SigninActivity.java b/org.envirocar.app/src/org/envirocar/app/views/login/SigninActivity.java index fde6a89bc..37fc8a120 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/login/SigninActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/views/login/SigninActivity.java @@ -23,13 +23,19 @@ import android.graphics.drawable.Drawable; import android.net.ConnectivityManager; import android.net.NetworkInfo; +import android.os.Build; import android.os.Bundle; +import android.view.KeyEvent; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.ImageView; +import android.widget.TextView; +import androidx.annotation.RequiresApi; import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.widget.AppCompatEditText; +import androidx.cardview.widget.CardView; import androidx.core.app.ActivityOptionsCompat; import com.google.android.material.dialog.MaterialAlertDialogBuilder; @@ -37,6 +43,7 @@ import org.envirocar.app.BaseApplicationComponent; import org.envirocar.app.R; +import org.envirocar.app.databinding.ActivitySigninBinding; import org.envirocar.app.exception.LoginException; import org.envirocar.app.handler.DAOProvider; import org.envirocar.app.handler.agreement.AgreementManager; @@ -54,10 +61,7 @@ import javax.inject.Inject; import java.util.function.Consumer; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import butterknife.OnEditorAction; + import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.Observable; @@ -73,6 +77,10 @@ */ public class SigninActivity extends BaseInjectorActivity { private static final Logger LOG = Logger.getLogger(SigninActivity.class); + private ImageView signInBackground; + private TextView registerButton; + private AppCompatEditText loginPasswordInput; + public static void startActivity(Context context) { Intent intent = new Intent(context, SigninActivity.class); @@ -89,13 +97,13 @@ public static void startActivity(Context context) { protected AgreementManager agreementManager; // Injected Views - @BindView(R.id.activity_signin_username_input) + protected EditText usernameEditText; - @BindView(R.id.activity_login_password_input) + protected EditText passwordEditText; - @BindView(R.id.activity_login_logo) - protected ImageView logoImageView; + protected ImageView logoImageView; + protected CardView activitySigninLoginButton; private Disposable loginSubscription; private static Drawable errorPassword; private static Drawable errorUsername; @@ -105,14 +113,31 @@ protected void injectDependencies(BaseApplicationComponent baseApplicationCompon baseApplicationComponent.inject(this); } + private ActivitySigninBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_signin); + binding = ActivitySigninBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); + setContentView(view); + + usernameEditText = binding.activitySigninUsernameInput; + passwordEditText = binding.activityLoginPasswordInput; + logoImageView = binding.activityLoginLogo; + activitySigninLoginButton = binding.activitySigninLoginButton; + activitySigninLoginButton.setOnClickListener(this::onLoginClicked); + signInBackground = binding.signinBackground; + signInBackground.setOnClickListener(this::closeKeyboard); + + registerButton = binding.activitySigninRegisterButton; + registerButton.setOnClickListener(this::onSwitchToRegisterClicked); + + loginPasswordInput = binding.activityLoginPasswordInput; + loginPasswordInput.setOnEditorActionListener(this::implicitSubmit); + getWindow().setNavigationBarColor(getResources().getColor(R.color.cario_color_primary_dark)); // inject the views - ButterKnife.bind(this); errorPassword = getResources().getDrawable(R.drawable.ic_error_red_24dp); errorPassword.setBounds(-70,0,0, errorPassword.getIntrinsicHeight()); @@ -131,17 +156,17 @@ protected void onDestroy() { } } - @OnClick(R.id.signin_background) - protected void closeKeyboard(){ - View view = this.getCurrentFocus(); + + protected void closeKeyboard(View view){ + if (view != null) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } } - @OnClick(R.id.activity_signin_register_button) - protected void onSwitchToRegisterClicked() { + + protected void onSwitchToRegisterClicked(View view) { ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation( this, logoImageView, "imageMain"); @@ -149,16 +174,15 @@ protected void onSwitchToRegisterClicked() { SignupActivity.startActivity(this); } - @OnEditorAction(R.id.activity_login_password_input) - protected boolean implicitSubmit() { + protected boolean implicitSubmit(TextView var1, int var2, KeyEvent var3) { View logInSubmit; logInSubmit = findViewById(R.id.activity_signin_login_button); logInSubmit.performClick(); return true; } - @OnClick(R.id.activity_signin_login_button) - protected void onLoginClicked() { + + protected void onLoginClicked(View view) { LOG.info("Clicked on the login button"); View focusView = null; @@ -211,9 +235,9 @@ private void login(String username, String password) { protected void onStart() { if(checkNetworkConnection()) { dialog = DialogUtils.createProgressBarDialogBuilder(SigninActivity.this, - R.string.activity_login_logging_in_dialog_title, - R.drawable.ic_baseline_login_24, - (String) null) + R.string.activity_login_logging_in_dialog_title, + R.drawable.ic_baseline_login_24, + (String) null) .setCancelable(false) .show(); } @@ -222,15 +246,16 @@ protected void onStart() { @Override public void onComplete() { if(checkNetworkConnection()) - dialog.dismiss(); + dialog.dismiss(); Intent intent = new Intent(getBaseContext(), BaseMainActivity.class); startActivity(intent); } + @RequiresApi(api = Build.VERSION_CODES.N) @Override public void onError(Throwable e) { if(checkNetworkConnection()) - dialog.dismiss(); + dialog.dismiss(); if (e instanceof LoginException) { switch (((LoginException) e).getType()) { case USERNAME_OR_PASSWORD_INCORRECT: @@ -252,20 +277,18 @@ public void onError(Throwable e) { break; case TERMS_NOT_ACCEPTED: LOG.info("User has not accepted the latest terms of use"); - agreementManager.initializeTermsOfUseAcceptanceWorkflow(username, password, SigninActivity.this, BaseMainActivity.class, new Consumer>() { - public void accept(Optional tou) { - if (tou.isEmpty()) { - passwordEditText.setError(getString(R.string.error_terms_not_acceppted), errorPassword); - userHandler.logOut(); - } else { - if (userHandler.isLoggedIn()) { - Intent intent = new Intent(getBaseContext(), BaseMainActivity.class); - startActivity(intent); - } + agreementManager.initializeTermsOfUseAcceptanceWorkflow(username, password, SigninActivity.this, BaseMainActivity.class, tou -> { + if (tou.isEmpty()) { + passwordEditText.setError(getString(R.string.error_terms_not_acceppted), errorPassword); + userHandler.logOut(); + } else { + if (userHandler.isLoggedIn()) { + Intent intent = new Intent(getBaseContext(), BaseMainActivity.class); + startActivity(intent); } } }); - + break; default: passwordEditText.setError(getString(R.string.logbook_invalid_input), errorPassword); @@ -286,4 +309,4 @@ private boolean checkNetworkConnection() { return true; return false; } -} +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/login/SignupActivity.java b/org.envirocar.app/src/org/envirocar/app/views/login/SignupActivity.java index 8c6afff00..9bfa7a140 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/login/SignupActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/views/login/SignupActivity.java @@ -47,6 +47,8 @@ import org.envirocar.app.BaseApplicationComponent; import org.envirocar.app.R; +import org.envirocar.app.databinding.ActivitySigninBinding; +import org.envirocar.app.databinding.ActivitySignupBinding; import org.envirocar.app.handler.DAOProvider; import org.envirocar.app.handler.agreement.AgreementManager; import org.envirocar.app.handler.preferences.UserPreferenceHandler; @@ -66,9 +68,9 @@ import javax.inject.Inject; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; + + + import io.reactivex.Scheduler; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; @@ -102,21 +104,21 @@ public static void startActivity(Context context) { protected AgreementManager agreementManager; // Injected Views - @BindView(R.id.activity_signup_username_input) + protected EditText usernameEditText; - @BindView(R.id.activity_signup_email_input) + protected EditText emailEditText; - @BindView(R.id.activity_signup_password_1) + protected EditText password1EditText; - @BindView(R.id.activity_signup_password_2) + protected EditText password2EditText; - @BindView(R.id.activity_signup_tou_checkbox) + protected CheckBox touCheckbox; - @BindView(R.id.activity_signup_tou_text) + protected TextView touText; - @BindView(R.id.activity_signup_ps_checkbox) + protected CheckBox psCheckbox; - @BindView(R.id.activity_signup_ps_text) + protected TextView psText; private final Scheduler.Worker mainThreadWorker = AndroidSchedulers.mainThread().createWorker(); @@ -130,14 +132,28 @@ protected void injectDependencies(BaseApplicationComponent baseApplicationCompon baseApplicationComponent.inject(this); } + private ActivitySignupBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_signup); + binding = ActivitySignupBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); + setContentView(view); + + usernameEditText = binding.activitySignupUsernameInput; + emailEditText = binding.activitySignupEmailInput; + password1EditText = binding.activitySignupPassword1; + password2EditText = binding.activitySignupPassword2; + touCheckbox = binding.activitySignupTouCheckbox; + touText = binding.activitySignupTouText; + psCheckbox = binding.activitySignupPsCheckbox; + psText = binding.activitySignupPsText; + + getWindow().setNavigationBarColor(getResources().getColor(R.color.cario_color_primary_dark)); // inject the views - ButterKnife.bind(this); + errorPassword = getResources().getDrawable(R.drawable.ic_error_red_24dp); errorPassword.setBounds(-70,0,0, errorPassword.getIntrinsicHeight()); @@ -158,23 +174,23 @@ protected void onDestroy() { } } - @OnClick(R.id.imageView) - protected void closeKeyboard(){ - View view = this.getCurrentFocus(); + //@OnClick(R.id.imageView) + protected void closeKeyboard(View view){ + if (view != null) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } } - @OnClick(R.id.activity_signup_login_button) - protected void onSwitchToRegister() { + //@OnClick(R.id.activity_signup_login_button) + protected void onSwitchToRegister(View view) { Intent intent = new Intent(this, SigninActivity.class); startActivity(intent); } - @OnClick(R.id.activity_signup_register_button) - protected void onRegisterAccountButtonClicked() { + //@OnClick(R.id.activity_signup_register_button) + protected void onRegisterAccountButtonClicked(View view) { // We do not want to have dublicate registration processes. if (this.registerSubscription != null && !this.registerSubscription.isDisposed()) { @@ -231,11 +247,11 @@ private void register(String username, String email, String password) { if(new ContextInternetAccessProvider(getApplicationContext()).isConnected()) { dialog = DialogUtils.createProgressBarDialogBuilder(SignupActivity.this, - R.string.register_progress_signing_in, - R.drawable.ic_baseline_login_24, - (String) null) - .setCancelable(false) - .show(); + R.string.register_progress_signing_in, + R.drawable.ic_baseline_login_24, + (String) null) + .setCancelable(false) + .show(); } registerSubscription = backgroundWorker.schedule(() -> { @@ -249,7 +265,7 @@ private void register(String username, String email, String password) { mainThreadWorker.schedule(() -> { // Dismiss the progress dialog. if(new ContextInternetAccessProvider(getApplicationContext()).isConnected()) - dialog.dismiss(); + dialog.dismiss(); new MaterialAlertDialogBuilder(SignupActivity.this, R.style.MaterialDialog) .setTitle(R.string.register_success_dialog_title) @@ -268,7 +284,7 @@ private void register(String username, String email, String password) { }); }else{ if(new ContextInternetAccessProvider(getApplicationContext()).isConnected()) - dialog.dismiss(); + dialog.dismiss(); showSnackbar(getString(R.string.error_not_connected_to_network)); } } catch (ResourceConflictException e) { @@ -490,4 +506,4 @@ private void observeFormInputs() { .observeOn(AndroidSchedulers.mainThread()) .subscribe(b -> psCheckbox.setError(null), LOG::error); } -} +} \ No newline at end of file From f5aa5a06de02b0f97ea0c3e9bf11b23a869f4ae3 Mon Sep 17 00:00:00 2001 From: Akash-Ramjyothi Date: Tue, 12 Jul 2022 09:40:10 +0530 Subject: [PATCH 13/19] Added Jetpack ViewBinding for obdselection Views --- .../obdselection/OBDDeviceListAdapter.java | 31 +++++++---- .../obdselection/OBDSelectionActivity.java | 25 +++++---- .../obdselection/OBDSelectionFragment.java | 51 +++++++++++-------- 3 files changed, 67 insertions(+), 40 deletions(-) diff --git a/org.envirocar.app/src/org/envirocar/app/views/obdselection/OBDDeviceListAdapter.java b/org.envirocar.app/src/org/envirocar/app/views/obdselection/OBDDeviceListAdapter.java index c1a3bcc2a..790bd3654 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/obdselection/OBDDeviceListAdapter.java +++ b/org.envirocar.app/src/org/envirocar/app/views/obdselection/OBDDeviceListAdapter.java @@ -30,9 +30,11 @@ import android.widget.TextView; import org.envirocar.app.R; +import org.envirocar.app.databinding.ActivityLogbookListentryBinding; +import org.envirocar.app.databinding.ActivityObdSelectionLayoutPairedListEntryBinding; + + -import butterknife.ButterKnife; -import butterknife.BindView; /** * @author dewall @@ -215,24 +217,35 @@ static class ViewHolder { public final View mContentView; // All the views of a row to lookup for. - @BindView(R.id.activity_obd_selection_layout_paired_list_entry_image) + protected ImageView mImageView; - @BindView(R.id.activity_obd_selection_layout_paired_list_entry_text) + protected TextView mTextView; - @BindView(R.id.activity_obd_selection_layout_paired_list_entry_delete) + protected ImageButton mDeleteButton; - @BindView(R.id.activity_obd_selection_layout_paired_list_entry_radio) + protected AppCompatRadioButton mRadioButton; + + + + protected ActivityObdSelectionLayoutPairedListEntryBinding binding; /** * Constructor. * * @param content the parent view of the listrow. */ + ViewHolder(View content) { this.mContentView = content; - // Inject the annotated views. - ButterKnife.bind(this, content); + binding = ActivityObdSelectionLayoutPairedListEntryBinding.bind(content); + + mImageView = binding.activityObdSelectionLayoutPairedListEntryImage; + mTextView = binding.activityObdSelectionLayoutPairedListEntryText; + mDeleteButton = binding.activityObdSelectionLayoutPairedListEntryDelete; + mRadioButton = binding.activityObdSelectionLayoutPairedListEntryRadio; + + } } -} +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/obdselection/OBDSelectionActivity.java b/org.envirocar.app/src/org/envirocar/app/views/obdselection/OBDSelectionActivity.java index a8e693248..2be3b5346 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/obdselection/OBDSelectionActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/views/obdselection/OBDSelectionActivity.java @@ -23,6 +23,7 @@ import androidx.fragment.app.Fragment; import androidx.appcompat.widget.Toolbar; import android.view.MenuItem; +import android.view.View; import android.widget.Switch; import android.widget.TextView; @@ -30,6 +31,7 @@ import org.envirocar.app.BaseApplicationComponent; import org.envirocar.app.R; +import org.envirocar.app.databinding.ActivityObdSelectionLayoutBinding; import org.envirocar.app.handler.BluetoothHandler; import org.envirocar.app.injection.BaseInjectorActivity; import org.envirocar.core.events.bluetooth.BluetoothStateChangedEvent; @@ -40,8 +42,8 @@ import javax.inject.Inject; -import butterknife.BindView; -import butterknife.ButterKnife; + + /** * @dewall @@ -53,11 +55,11 @@ public class OBDSelectionActivity extends BaseInjectorActivity implements @Inject protected BluetoothHandler mBluetoothHandler; - @BindView(R.id.activity_obd_selection_layout_toolbar) + protected Toolbar mToolbar; - @BindView(R.id.activity_obd_selection_layout_enablebt_switch) + protected Switch mSwitch; - @BindView(R.id.activity_obd_selection_layout_enablebt_text) + protected TextView mEnableBTText; protected Fragment mOBDSelectionFragment; @@ -68,15 +70,18 @@ protected void injectDependencies(BaseApplicationComponent baseApplicationCompon baseApplicationComponent.inject(this); } + private ActivityObdSelectionLayoutBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - + binding =ActivityObdSelectionLayoutBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); // Set the content view of this activity. - setContentView(R.layout.activity_obd_selection_layout); + setContentView(view); - // Inject all annotated views. - ButterKnife.bind(this); + mToolbar= binding.activityObdSelectionLayoutToolbar; + mSwitch = binding.activityObdSelectionLayoutEnablebtSwitch; + mEnableBTText = binding.activityObdSelectionLayoutEnablebtText; // Set the toolbar as default actionbar. setSupportActionBar(mToolbar); @@ -163,4 +168,4 @@ private void setSwitchState(float value) { } } -} +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/obdselection/OBDSelectionFragment.java b/org.envirocar.app/src/org/envirocar/app/views/obdselection/OBDSelectionFragment.java index 6f5ed2f17..7c2945dac 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/obdselection/OBDSelectionFragment.java +++ b/org.envirocar.app/src/org/envirocar/app/views/obdselection/OBDSelectionFragment.java @@ -40,6 +40,8 @@ import org.envirocar.app.BaseApplicationComponent; import org.envirocar.app.R; +import org.envirocar.app.databinding.ActivityObdSelectionFragmentBinding; +import org.envirocar.app.databinding.ActivityObdSelectionLayoutBinding; import org.envirocar.app.handler.BluetoothHandler; import org.envirocar.app.injection.BaseInjectorFragment; import org.envirocar.core.events.bluetooth.BluetoothPairingChangedEvent; @@ -53,9 +55,9 @@ import javax.inject.Inject; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; + + + import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.observers.DisposableObserver; @@ -87,22 +89,22 @@ public interface ShowSnackbarListener { @Inject protected BluetoothHandler mBluetoothHandler; - @BindView(R.id.activity_obd_selection_layout_content) + protected View mContentView; - @BindView(R.id.activity_obd_selection_layout_paired_devices_text) + protected TextView mPairedDevicesTextView; - @BindView(R.id.activity_obd_selection_layout_paired_devices_list) + protected ListView mPairedDevicesListView; - @BindView(R.id.activity_obd_selection_layout_available_devices_list) + protected ListView mNewDevicesListView; - @BindView(R.id.activity_obd_selection_layout_search_devices_progressbar) + protected ProgressBar mProgressBar; - @BindView(R.id.activity_obd_selection_layout_rescan_bluetooth) + protected ImageView mRescanImageView; - @BindView(R.id.activity_obd_selection_layout_paired_devices_info) + protected TextView mPairedDevicesInfoTextView; - @BindView(R.id.activity_obd_selection_layout_available_devices_info) + protected TextView mNewDevicesInfoTextView; // ArrayAdapter for the two different list views. @@ -114,18 +116,25 @@ public interface ShowSnackbarListener { private boolean isResumed = false; public boolean pairingIsRunning = false; + private ActivityObdSelectionFragmentBinding binding; @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); + binding = ActivityObdSelectionFragmentBinding.inflate(inflater,container,false); + View contentView = binding.getRoot(); + mContentView= binding.activityObdSelectionLayoutContent; + mPairedDevicesTextView = binding.activityObdSelectionLayoutPairedDevicesText; + mPairedDevicesListView = binding.activityObdSelectionLayoutPairedDevicesList; + mNewDevicesListView = binding.activityObdSelectionLayoutAvailableDevicesList; + mProgressBar = binding.activityObdSelectionLayoutSearchDevicesProgressbar; + mRescanImageView = binding.activityObdSelectionLayoutRescanBluetooth; + mRescanImageView.setOnClickListener(this::rediscover); + mPairedDevicesInfoTextView = binding.activityObdSelectionLayoutPairedDevicesInfo; + mNewDevicesInfoTextView = binding.activityObdSelectionLayoutAvailableDevicesInfo; - // infalte the content view of this activity. - View contentView = inflater.inflate(R.layout.activity_obd_selection_fragment, - container, false); - // Inject all annotated views. - ButterKnife.bind(this, contentView); // Setup the listviews, its adapters, and its onClick listener. setupListViews(); @@ -160,8 +169,8 @@ public void onBluetoothStateChangedEvent(BluetoothStateChangedEvent event) { }); } - @OnClick(R.id.activity_obd_selection_layout_rescan_bluetooth) - protected void rediscover() { + //@OnClick(R.id.activity_obd_selection_layout_rescan_bluetooth) + protected void rediscover(View view) { mBluetoothHandler.stopBluetoothDeviceDiscovery(); checkAndRequestPermissions(); } @@ -237,11 +246,11 @@ public void onPermissionsGranted(int requestCode, @NonNull @NotNull List // if location permissions are granted, start Bluetooth discovery. if (requestCode == BLUETOOTH_PERMISSIONS) { startBluetoothDiscovery(); - + // Check the GPS and Location permissions // before Starting the discovery of bluetooth devices. updateContentView(); - + showSnackbar(getString(R.string.location_permission_granted)); } } @@ -554,4 +563,4 @@ private void showSnackbar(String text) { // Snackbar.make(mContentView, text, Snackbar.LENGTH_LONG).show(); } -} +} \ No newline at end of file From 650559d200132e90ccbcd3692396af9bbbff9173 Mon Sep 17 00:00:00 2001 From: Akash-Ramjyothi Date: Tue, 12 Jul 2022 09:43:47 +0530 Subject: [PATCH 14/19] Added Jetpack ViewBinding for others Views --- .../app/views/others/HelpActivity.java | 27 ++++--- .../app/views/others/OthersFragment.java | 65 ++++++++------- .../app/views/others/SendLogFileActivity.java | 44 +++++----- .../app/views/others/TermsOfUseActivity.java | 81 ++++++++++--------- .../views/others/UserStatisticsAdapter.java | 31 ++++--- 5 files changed, 139 insertions(+), 109 deletions(-) diff --git a/org.envirocar.app/src/org/envirocar/app/views/others/HelpActivity.java b/org.envirocar.app/src/org/envirocar/app/views/others/HelpActivity.java index f42292d6e..532cd2ad5 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/others/HelpActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/views/others/HelpActivity.java @@ -19,17 +19,17 @@ package org.envirocar.app.views.others; import android.os.Bundle; -import android.view.MenuItem; -import android.view.View; - import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; +import android.view.MenuItem; +import android.view.View; import org.envirocar.app.R; +import org.envirocar.app.databinding.ActivityHelpLayoutBinding; import org.envirocar.app.databinding.ActivityHelpLayoutGeneralBinding; -import butterknife.BindView; -import butterknife.ButterKnife; + + /** * TODO JavaDoc @@ -38,25 +38,26 @@ */ public class HelpActivity extends AppCompatActivity { - @BindView(R.id.activity_help_layout_general_toolbar) - protected Toolbar toolbar; - ActivityHelpLayoutGeneralBinding activityHelpLayoutGeneralBinding; + protected Toolbar toolbar; + private ActivityHelpLayoutGeneralBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + binding = ActivityHelpLayoutGeneralBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); - activityHelpLayoutGeneralBinding = ActivityHelpLayoutGeneralBinding.inflate(getLayoutInflater()); - View view = activityHelpLayoutGeneralBinding.getRoot(); setContentView(view); + toolbar = binding.activityHelpLayoutGeneralToolbar; + // Inject views - ButterKnife.bind(this); + // Set Actionbar setSupportActionBar(toolbar); - activityHelpLayoutGeneralBinding.activityHelpLayoutGeneralToolbar.setTitle("Help"); + getSupportActionBar().setTitle("Help"); getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); } @@ -69,4 +70,4 @@ public boolean onOptionsItemSelected(MenuItem item) { super.onOptionsItemSelected(item); return false; } -} +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/others/OthersFragment.java b/org.envirocar.app/src/org/envirocar/app/views/others/OthersFragment.java index 3cf359ad8..b7ffc87ec 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/others/OthersFragment.java +++ b/org.envirocar.app/src/org/envirocar/app/views/others/OthersFragment.java @@ -41,6 +41,8 @@ import org.envirocar.app.BaseApplicationComponent; import org.envirocar.app.BuildConfig; import org.envirocar.app.R; +import org.envirocar.app.databinding.FragmentDashboardViewNewBinding; +import org.envirocar.app.databinding.FragmentOthersBinding; import org.envirocar.app.handler.TrackDAOHandler; import org.envirocar.app.handler.preferences.UserPreferenceHandler; import org.envirocar.app.injection.BaseInjectorFragment; @@ -56,9 +58,9 @@ import javax.inject.Inject; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; + + + import io.reactivex.Scheduler; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.observers.DisposableCompletableObserver; @@ -75,9 +77,9 @@ public class OthersFragment extends BaseInjectorFragment { @Inject protected TrackDAOHandler mTrackDAOHandler; - @BindView(R.id.othersLogOut) + protected LinearLayout othersLogOut; - @BindView(R.id.othersLogOutDivider) + protected View othersLogOutDivider; private Scheduler.Worker mMainThreadWorker = AndroidSchedulers.mainThread().createWorker(); @@ -85,12 +87,15 @@ public class OthersFragment extends BaseInjectorFragment { private int REQUEST_PERMISSIONS_REQUEST_CODE = 101; + private FragmentOthersBinding binding; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_others, container, false); + binding = FragmentOthersBinding.inflate(inflater,container,false); + View view = binding.getRoot(); - ButterKnife.bind(this, view); + othersLogOut = binding.othersLogOut; + othersLogOutDivider = binding.othersLogOutDivider; if (mUserManager.isLoggedIn()) { othersLogOut.setVisibility(View.VISIBLE); @@ -110,43 +115,43 @@ protected void injectDependencies(BaseApplicationComponent baseApplicationCompon } - @OnClick(R.id.othersLogBook) - protected void onLogBookClicked() { + //@OnClick(R.id.othersLogBook) + protected void onLogBookClicked(View view) { Intent intent = new Intent(getActivity(), LogbookActivity.class); startActivity(intent); } - @OnClick(R.id.othersSettings) - protected void onSettingsClicked() { + //@OnClick(R.id.othersSettings) + protected void onSettingsClicked(View view) { Intent intent = new Intent(getActivity(), SettingsActivity.class); startActivity(intent); } - @OnClick(R.id.othersHelp) - protected void onHelpClicked() { + //@OnClick(R.id.othersHelp) + protected void onHelpClicked(View view) { Intent intent = new Intent(getActivity(), HelpActivity.class); startActivity(intent); } - @OnClick(R.id.othersTou) - protected void onTouClicked() { + //@OnClick(R.id.othersTou) + protected void onTouClicked(View view) { Intent intent = new Intent(getActivity(), TermsOfUseActivity.class); startActivity(intent); } - @OnClick(R.id.othersReportIssue) - protected void onReportIssueClicked() { + //@OnClick(R.id.othersReportIssue) + protected void onReportIssueClicked(View view) { // if (checkPermissions()) { - //access granted - Intent intent = new Intent(getActivity(), SendLogFileActivity.class); - startActivity(intent); + //access granted + Intent intent = new Intent(getActivity(), SendLogFileActivity.class); + startActivity(intent); // } else { // requestPermissions(); // } } - @OnClick(R.id.othersRateUs) - protected void onRateUsClicked() { + //@OnClick(R.id.othersRateUs) + protected void onRateUsClicked(View view) { final String appPackageName = "org.envirocar.app"; // getPackageName() from Context or Activity object try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName))); @@ -155,8 +160,8 @@ protected void onRateUsClicked() { } } - @OnClick(R.id.othersLogOut) - protected void onLogOutClicked() { + //@OnClick(R.id.othersLogOut) + protected void onLogOutClicked(View view) { // show dialog new MaterialAlertDialogBuilder(getActivity(), R.style.MaterialDialog) .setTitle(R.string.menu_logout_envirocar_title) @@ -168,8 +173,8 @@ protected void onLogOutClicked() { .show(); } - @OnClick(R.id.othersCloseEnviroCar) - protected void onCloseEnviroCarClicked() { + // @OnClick(R.id.othersCloseEnviroCar) + protected void onCloseEnviroCarClicked(View view) { // show closing dialog new MaterialAlertDialogBuilder(getActivity(), R.style.MaterialDialog) .setTitle(R.string.menu_close_envirocar_title) @@ -276,9 +281,9 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis private void showSnackbar(final int mainTextStringId, final int actionStringId, View.OnClickListener listener) { Snackbar.make( - getActivity().findViewById(R.id.navigation), - getString(mainTextStringId), - Snackbar.LENGTH_INDEFINITE) + getActivity().findViewById(R.id.navigation), + getString(mainTextStringId), + Snackbar.LENGTH_INDEFINITE) .setAction(getString(actionStringId), listener).show(); } @@ -327,4 +332,4 @@ public void onError(Throwable e) { }; } -} +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/others/SendLogFileActivity.java b/org.envirocar.app/src/org/envirocar/app/views/others/SendLogFileActivity.java index 3528ca034..0b11f2d33 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/others/SendLogFileActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/views/others/SendLogFileActivity.java @@ -43,6 +43,8 @@ import org.envirocar.app.BaseApplicationComponent; import org.envirocar.app.R; +import org.envirocar.app.databinding.SendLogLayoutBinding; +import org.envirocar.app.databinding.SendLogLayoutNewBinding; import org.envirocar.app.handler.ApplicationSettings; import org.envirocar.app.handler.BluetoothHandler; import org.envirocar.app.handler.preferences.CarPreferenceHandler; @@ -68,11 +70,6 @@ import javax.inject.Inject; -import butterknife.BindArray; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import butterknife.OnFocusChange; /** * An activity for reporting issues. @@ -89,20 +86,20 @@ public class SendLogFileActivity extends BaseInjectorActivity { private static final String OTHER_DETAILS_PREFIX = "extra-info"; private static final String EXTENSION = ".zip"; - @BindView(R.id.envirocar_toolbar) + protected Toolbar toolbar; - @BindView(R.id.report_issue_time_since_crash) + protected EditText whenField; - @BindView(R.id.report_issue_desc) + protected EditText comments; - @BindView(R.id.report_issue_submit) + protected View submitIssue; - @BindView(R.id.report_issue_checkbox_list) + protected ListView checkBoxListView; - @BindArray(R.array.report_issue_subject_header) + protected String[] subjectHeaders; - @BindArray(R.array.report_issue_subject_tags) + protected String[] subjectTags; @Inject @@ -118,11 +115,24 @@ protected void injectDependencies(BaseApplicationComponent baseApplicationCompon baseApplicationComponent.inject(this); } + private SendLogLayoutNewBinding binding; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.send_log_layout_new); - ButterKnife.bind(this); + binding = SendLogLayoutNewBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); + setContentView(view); + + toolbar = binding.activityCarSelectionLayoutExptoolbar.envirocarToolbar; + whenField = binding.reportIssueTimeSinceCrash; + whenField.setOnFocusChangeListener(this::onWhenFieldFocusChange); + comments = binding.reportIssueDesc; + comments.setOnFocusChangeListener(this::onCommentsFocusChange); + submitIssue = binding.reportIssueSubmit; + submitIssue.setOnClickListener(this::onClickSubmitButton); + checkBoxListView = binding.reportIssueCheckboxList; + subjectHeaders = getResources().getStringArray(R.array.report_issue_subject_header); + subjectTags = getResources().getStringArray(R.array.report_issue_subject_tags); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -137,7 +147,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { } } - @OnClick(R.id.report_issue_submit) public void onClickSubmitButton(View v) { try { final File tmpBundle = createReportBundle(); @@ -151,14 +160,13 @@ public void onClickSubmitButton(View v) { } } - @OnFocusChange(R.id.report_issue_time_since_crash) + public void onWhenFieldFocusChange(View v, boolean hasFocus) { if (!hasFocus) { hideKeyboard(v); } } - @OnFocusChange(R.id.report_issue_desc) public void onCommentsFocusChange(View v, boolean hasFocus) { if (!hasFocus) { hideKeyboard(v); @@ -502,4 +510,4 @@ public void onItemClick(AdapterView adapterView, View view, int itemIndex, lo }); } -} +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/others/TermsOfUseActivity.java b/org.envirocar.app/src/org/envirocar/app/views/others/TermsOfUseActivity.java index 0b4aa4db9..0f4e84701 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/others/TermsOfUseActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/views/others/TermsOfUseActivity.java @@ -31,6 +31,7 @@ import io.reactivex.schedulers.Schedulers; import org.envirocar.app.R; +import org.envirocar.app.databinding.ActivityTouLayoutBinding; import org.envirocar.app.handler.agreement.AgreementManager; import org.envirocar.app.injection.BaseInjectorActivity; import org.envirocar.core.utils.rx.Optional; @@ -41,10 +42,9 @@ import org.envirocar.app.BaseApplicationComponent; import org.envirocar.core.utils.rx.Optional; import org.envirocar.app.handler.preferences.UserPreferenceHandler; -import org.envirocar.app.databinding.ActivityTouLayoutBinding; -import butterknife.ButterKnife; -import butterknife.BindView; + + import java.util.function.Consumer; import javax.inject.Inject; @@ -58,10 +58,10 @@ public class TermsOfUseActivity extends BaseInjectorActivity { private static final Logger LOG = Logger.getLogger(TermsOfUseActivity.class); - @BindView(R.id.tou_text_view) + protected TextView touTextView; - @BindView(R.id.activity_tou_layout_toolbar) + protected Toolbar toolbar; @Inject @@ -78,22 +78,24 @@ protected void injectDependencies(BaseApplicationComponent baseApplicationCompon baseApplicationComponent.inject(this); } - ActivityTouLayoutBinding activityTouLayoutBinding; + private ActivityTouLayoutBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - - activityTouLayoutBinding = ActivityTouLayoutBinding.inflate(getLayoutInflater()); - View view = activityTouLayoutBinding.getRoot(); + binding = ActivityTouLayoutBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); setContentView(view); + touTextView = binding.touTextView; + toolbar = binding.activityTouLayoutToolbar; + // Inject views - ButterKnife.bind(this); + // Set Actionbar setSupportActionBar(toolbar); - activityTouLayoutBinding.activityTouLayoutToolbar.setTitle(getString(R.string.terms_of_use_simple)); + getSupportActionBar().setTitle(getString(R.string.terms_of_use_simple)); getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -102,36 +104,37 @@ protected void onCreate(Bundle savedInstanceState) { Spanned htmlAsSpanned = Html.fromHtml(htmlAsString); // set the html content on a TextView - activityTouLayoutBinding.touTextView.setText(htmlAsSpanned); + TextView textView = (TextView) findViewById(R.id.tou_text_view); + textView.setText(htmlAsSpanned); getLatestTermsOfUse.asObservable() - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(termsOfUse -> { - LOG.info("Terms Of Use loaded: " + termsOfUse); - if (!termsOfUse.isEmpty()) { - Spanned htmlContent = Html.fromHtml(termsOfUse.getOptional().getContents()); - activityTouLayoutBinding.touTextView.setText(htmlContent); - } - }); + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(termsOfUse -> { + LOG.info("Terms Of Use loaded: " + termsOfUse); + if (!termsOfUse.isEmpty()) { + Spanned htmlContent = Html.fromHtml(termsOfUse.getOptional().getContents()); + textView.setText(htmlContent); + } + }); // check if the user accepted the latest terms LOG.info("Checking TermsOfUse"); mAgreementManager.verifyTermsOfUse(null, true) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(termsOfUse -> { - if (termsOfUse != null) { - LOG.warn("TermsOfUse verified"); - } else { - LOG.warn("No TermsOfUse received from verification"); + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(termsOfUse -> { + if (termsOfUse != null) { + LOG.warn("TermsOfUse verified"); + } else { + LOG.warn("No TermsOfUse received from verification"); + initAcceptanceWorkflow(); + } + }, e -> { + LOG.warn("Error during TermsOfUse verification", e); initAcceptanceWorkflow(); - } - }, e -> { - LOG.warn("Error during TermsOfUse verification", e); - initAcceptanceWorkflow(); - }); - + }); + } private void initAcceptanceWorkflow() { @@ -143,7 +146,7 @@ public void accept(Optional tou) { LOG.info("User did not accept ToU"); } else { LOG.info("User accepted ToU"); - } + } } }); } @@ -152,9 +155,9 @@ private TermsOfUse resolveTermsOfUse() { TermsOfUse tous; try { tous = mAgreementManager.verifyTermsOfUse(this, true) - .subscribeOn(Schedulers.io()) - .doOnError(LOG::error) - .blockingFirst(); + .subscribeOn(Schedulers.io()) + .doOnError(LOG::error) + .blockingFirst(); } catch (Exception e) { LOG.warn(e.getMessage(), e); tous = null; @@ -170,4 +173,4 @@ public boolean onOptionsItemSelected(MenuItem item) { super.onOptionsItemSelected(item); return false; } -} +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/others/UserStatisticsAdapter.java b/org.envirocar.app/src/org/envirocar/app/views/others/UserStatisticsAdapter.java index cfbff1873..3a0e24ce7 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/others/UserStatisticsAdapter.java +++ b/org.envirocar.app/src/org/envirocar/app/views/others/UserStatisticsAdapter.java @@ -26,13 +26,14 @@ import android.widget.TextView; import org.envirocar.app.R; +import org.envirocar.app.databinding.ActivityAccountStatisticListEntryBinding; import org.envirocar.core.entity.Phenomenon; import java.text.DecimalFormat; import java.util.List; -import butterknife.ButterKnife; -import butterknife.BindView; + + /** * @author dewall @@ -65,8 +66,8 @@ public View getView(int position, View convertView, ViewGroup parent) { R.layout.activity_account_statistic_list_entry, parent, false); // Create a new viewholder and inject the sub-views of the newly inflated convertView. - viewHolder = new ViewHolder(); - ButterKnife.bind(viewHolder, convertView); + viewHolder = new ViewHolder(convertView); + // Set the viewHolder as tag on the convertView. convertView.setTag(viewHolder); @@ -86,13 +87,25 @@ public View getView(int position, View convertView, ViewGroup parent) { } static final class ViewHolder { - @BindView(R.id.activity_account_statistics_list_entry_phenomenon) + + TextView mPhenomenonTextView; - @BindView(R.id.activity_account_statistics_list_entry_avg_value) + TextView mAvgValue; - @BindView(R.id.activity_account_statistics_list_entry_max_value) + TextView mMaxValue; - @BindView(R.id.activity_account_statistics_list_entry_min_value) + TextView mMinValue; + + protected ActivityAccountStatisticListEntryBinding binding; + ViewHolder(View view){ + binding = ActivityAccountStatisticListEntryBinding.bind(view); + mPhenomenonTextView = binding.activityAccountStatisticsListEntryPhenomenon; + mAvgValue = binding.activityAccountStatisticsListEntryAvgValue; + mMaxValue = binding.activityAccountStatisticsListEntryMaxValue; + mMinValue = binding.activityAccountStatisticsListEntryMinValue; + } + + } -} +} \ No newline at end of file From 7c52d772ccf15e0ad943eedf398489bf994b8360 Mon Sep 17 00:00:00 2001 From: Akash-Ramjyothi Date: Tue, 12 Jul 2022 09:44:46 +0530 Subject: [PATCH 15/19] Added Jetpack ViewBinding for preferences Views --- .../BluetoothPairingPreference.java | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/org.envirocar.app/src/org/envirocar/app/views/preferences/BluetoothPairingPreference.java b/org.envirocar.app/src/org/envirocar/app/views/preferences/BluetoothPairingPreference.java index ad5dc59e6..0b7db6c68 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/preferences/BluetoothPairingPreference.java +++ b/org.envirocar.app/src/org/envirocar/app/views/preferences/BluetoothPairingPreference.java @@ -40,6 +40,7 @@ import com.squareup.otto.Subscribe; import org.envirocar.app.R; +import org.envirocar.app.databinding.BluetoothPairingPreferenceBinding; import org.envirocar.app.handler.BluetoothHandler; import org.envirocar.app.BaseApplication; import org.envirocar.app.views.preferences.bluetooth.BluetoothDeviceListAdapter; @@ -51,8 +52,8 @@ import javax.inject.Inject; -import butterknife.BindView; -import butterknife.ButterKnife; + + import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.observers.DisposableObserver; @@ -65,21 +66,21 @@ public class BluetoothPairingPreference extends DialogPreference { private static final Logger LOGGER = Logger.getLogger(BluetoothPairingPreference.class); // Views for the already paired devices. - @BindView(R.id.bluetooth_pairing_preference_paired_devices_text) + public TextView mPairedDevicesTextView; - @BindView(R.id.bluetooth_pairing_preference_paired_devices_list) + public ListView mPairedDevicesListView; // Views for the newly discovered devices. - @BindView(R.id.bluetooth_pairing_preference_available_devices_text) + public TextView mNewDevicesTextView; - @BindView(R.id.bluetooth_pairing_preference_available_devices_list) + public ListView mNewDevicesListView; // No device found. - @BindView(R.id.bluetooth_pairing_preference_available_devices_info) + public TextView mNewDevicesInfoTextView; - @BindView(R.id.bluetooth_pairing_preference_search_devices_progressbar) + public ProgressBar mProgressBar; // Injected variables. @@ -89,7 +90,7 @@ public class BluetoothPairingPreference extends DialogPreference { protected BluetoothHandler mBluetoothHandler; // Main parent view for the content. - @BindView(R.id.bluetooth_pairing_preference_content) + protected LinearLayout mContentView; // ArrayAdapter for the two different list views. @@ -102,9 +103,12 @@ public class BluetoothPairingPreference extends DialogPreference { * @param context the Context of the current scope. * @param attrs the attribute set. */ + public BluetoothPairingPreference(Context context, AttributeSet attrs) { + super(context, attrs); + // Inject fields. BaseApplication.get(context).getBaseApplicationComponent().inject(this); @@ -112,6 +116,7 @@ public BluetoothPairingPreference(Context context, AttributeSet attrs) { setDialogLayoutResource(R.layout.bluetooth_pairing_preference); } + protected BluetoothPairingPreferenceBinding binding; /** * Binds views in the content View of the dialog to data. * @@ -120,9 +125,20 @@ public BluetoothPairingPreference(Context context, AttributeSet attrs) { @Override protected void onBindDialogView(final View view) { super.onBindDialogView(view); + binding = BluetoothPairingPreferenceBinding.bind(view); + mPairedDevicesTextView = binding.bluetoothPairingPreferencePairedDevicesText; + mPairedDevicesListView = binding.bluetoothPairingPreferencePairedDevicesList; + + mNewDevicesTextView = binding.bluetoothPairingPreferenceAvailableDevicesText; + mNewDevicesListView = binding.bluetoothPairingPreferenceAvailableDevicesList; + + mNewDevicesInfoTextView = binding.bluetoothPairingPreferenceAvailableDevicesInfo; + mProgressBar = binding.bluetoothPairingPreferenceSearchDevicesProgressbar; + + mContentView = binding.bluetoothPairingPreferenceContent; // Inject all views. - ButterKnife.bind(this, view); + // Initialize the array adapter for both list views mNewDevicesArrayAdapter = new BluetoothDeviceListAdapter(getContext(), From b5a4c8e820c85b8335caf541ca1dc069f265d22d Mon Sep 17 00:00:00 2001 From: Akash-Ramjyothi Date: Tue, 12 Jul 2022 09:46:59 +0530 Subject: [PATCH 16/19] Added Jetpack ViewBinding for recordingscreen Views --- .../RecordingScreenActivity.java | 61 ++++++++++++------- .../recordingscreen/TempomatFragment.java | 20 +++--- .../recordingscreen/TrackMapFragment.java | 37 +++++------ 3 files changed, 71 insertions(+), 47 deletions(-) diff --git a/org.envirocar.app/src/org/envirocar/app/views/recordingscreen/RecordingScreenActivity.java b/org.envirocar.app/src/org/envirocar/app/views/recordingscreen/RecordingScreenActivity.java index 1de032ba0..8e57d5a41 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/recordingscreen/RecordingScreenActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/views/recordingscreen/RecordingScreenActivity.java @@ -37,6 +37,7 @@ import org.envirocar.app.BaseApplicationComponent; import org.envirocar.app.R; +import org.envirocar.app.databinding.ActivityRecordingScreenBinding; import org.envirocar.app.events.*; import org.envirocar.app.handler.ApplicationSettings; import org.envirocar.app.handler.TrackRecordingHandler; @@ -55,9 +56,9 @@ import javax.inject.Inject; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; + + + import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; @@ -87,27 +88,27 @@ public static void navigate(Context context) { protected TrackRecordingHandler trackRecordingHandler; // Injected views - @BindView(R.id.activity_recscreen_trackdetails_gps) + protected ImageView gpsImage; - @BindView(R.id.activity_recscreen_trackdetails_bluetooth) + protected ImageView bluetoothImage; - @BindView(R.id.activity_recscreen_trackdetails_bluetooth_text) + protected TextView bluetoothText; - @BindView(R.id.activity_recscreen_trackdetails_timer) + protected Chronometer timerText; - @BindView(R.id.activity_recscreen_trackdetails_distance) + protected TextView distanceText; - @BindView(R.id.activity_recscreen_trackdetails_speed) + protected TextView speedText; - @BindView(R.id.activity_recscreen_trackdetails_container) + protected LinearLayout trackDetailsContainer; - @BindView(R.id.activity_recscreen_trackmap_container) + protected LinearLayout mapContainer; - @BindView(R.id.activity_recscreen_tempomat_container) + protected LinearLayout tempomatContainer; - @BindView(R.id.activity_recscreen_stopbutton) + protected LinearLayout stopTrackRecordingButton; - @BindView(R.id.activity_recscreen_track_upload_status) + protected LinearLayout trackUploadStatus; // state variables @@ -120,11 +121,29 @@ protected void injectDependencies(BaseApplicationComponent baseApplicationCompon .inject(this); } + private ActivityRecordingScreenBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { LOG.info("Creating RecordingScreenActivity"); super.onCreate(savedInstanceState); - setContentView(R.layout.activity_recording_screen); + binding = ActivityRecordingScreenBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); + setContentView(view); + + gpsImage = binding.activityRecscreenTrackdetailsGps; + bluetoothImage = binding.activityRecscreenTrackdetailsBluetooth; + bluetoothText = binding.activityRecscreenTrackdetailsBluetoothText; + timerText = binding.activityRecscreenTrackdetailsTimer; + distanceText = binding.activityRecscreenTrackdetailsDistance; + speedText = binding.activityRecscreenTrackdetailsSpeed; + trackDetailsContainer = binding.activityRecscreenTrackdetailsContainer; + mapContainer = binding.activityRecscreenTrackmapContainer; + tempomatContainer = binding.activityRecscreenTempomatContainer; + + stopTrackRecordingButton = binding.activityRecscreenStopbutton; + + stopTrackRecordingButton.setOnClickListener(this::onStopButtonClicked); + trackUploadStatus = binding.activityRecscreenTrackUploadStatus; //if the track recording service is stopped then finish this activity and goback to bottombar main activity if (RecordingService.RECORDING_STATE == RecordingState.RECORDING_STOPPED) { @@ -133,7 +152,7 @@ protected void onCreate(Bundle savedInstanceState) { } // Inject all dashboard-related views. - ButterKnife.bind(this); + this.recordingType = ApplicationSettings.getSelectedRecordingTypeObservable(this).blockingFirst(); if (recordingType.equals(RecordingType.ACTIVITY_RECOGNITION_BASED)) { @@ -193,8 +212,8 @@ protected void onDestroy() { super.onDestroy(); } - @OnClick(R.id.activity_recscreen_switchbutton) - protected void onSwitchViewsButtonClicked() { + + protected void onSwitchViewsButtonClicked(View view) { LOG.info("Switch views button clicked"); Observable.just(true) .subscribeOn(AndroidSchedulers.mainThread()) @@ -203,8 +222,8 @@ protected void onSwitchViewsButtonClicked() { .subscribe(); } - @OnClick(R.id.activity_recscreen_stopbutton) - protected void onStopButtonClicked() { + //@OnClick(R.id.activity_recscreen_stopbutton) + protected void onStopButtonClicked(View view) { LOG.info("Stop button has been clicked. Showing dialog to request confirmation"); new MaterialAlertDialogBuilder(this,R.style.MaterialDialog) @@ -385,4 +404,4 @@ public void onAnimationRepeat(Animation animation) { view.startAnimation(animation); } } -} +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/recordingscreen/TempomatFragment.java b/org.envirocar.app/src/org/envirocar/app/views/recordingscreen/TempomatFragment.java index 1e44f8cdc..1b45c457e 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/recordingscreen/TempomatFragment.java +++ b/org.envirocar.app/src/org/envirocar/app/views/recordingscreen/TempomatFragment.java @@ -27,6 +27,8 @@ import com.squareup.otto.Subscribe; import org.envirocar.app.BaseApplicationComponent; +import org.envirocar.app.databinding.FragmentOthersBinding; +import org.envirocar.app.databinding.FragmentTempomatViewBinding; import org.envirocar.app.injection.components.MainActivityComponent; import org.envirocar.app.injection.modules.MainActivityModule; import org.envirocar.app.R; @@ -35,8 +37,8 @@ import org.envirocar.core.logging.Logger; import org.envirocar.obd.events.SpeedUpdateEvent; -import butterknife.BindView; -import butterknife.ButterKnife; + + /** * @author dewall @@ -44,23 +46,23 @@ public class TempomatFragment extends BaseInjectorFragment { private static final Logger LOG = Logger.getLogger(TempomatFragment.class); - @BindView(R.id.fragment_dashboard_tempomat_view) + protected Tempomat mTempomatView; + private FragmentTempomatViewBinding binding; @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LOG.info("onCreateView()"); + binding = FragmentTempomatViewBinding.inflate(inflater,container,false); + View view = binding.getRoot(); - // First inflate the general dashboard view. - View contentView = inflater.inflate(R.layout.fragment_tempomat_view, container, false); + mTempomatView = binding.fragmentDashboardTempomatView; - // Inject all dashboard-related views. - ButterKnife.bind(this, contentView); // return the inflated content view. - return contentView; + return view; } @Override @@ -118,4 +120,4 @@ protected void injectDependencies(BaseApplicationComponent baseApplicationCompon MainActivityComponent mainActivityComponent = baseApplicationComponent.plus(new MainActivityModule(getActivity())); mainActivityComponent.inject(this); } -} +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/recordingscreen/TrackMapFragment.java b/org.envirocar.app/src/org/envirocar/app/views/recordingscreen/TrackMapFragment.java index 3a1a5bd99..b2fe4d0fe 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/recordingscreen/TrackMapFragment.java +++ b/org.envirocar.app/src/org/envirocar/app/views/recordingscreen/TrackMapFragment.java @@ -27,6 +27,7 @@ import android.util.Log; import android.view.LayoutInflater; +import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.animation.Animation; @@ -56,6 +57,8 @@ import com.squareup.otto.Subscribe; import org.envirocar.app.BaseApplicationComponent; +import org.envirocar.app.databinding.FragmentTempomatViewBinding; +import org.envirocar.app.databinding.FragmentTrackMapBinding; import org.envirocar.app.injection.components.MainActivityComponent; import org.envirocar.app.injection.modules.MainActivityModule; import org.envirocar.app.R; @@ -68,10 +71,6 @@ import java.util.ArrayList; import java.util.List; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import butterknife.OnTouch; import io.reactivex.Scheduler; import io.reactivex.android.schedulers.AndroidSchedulers; @@ -85,9 +84,9 @@ public class TrackMapFragment extends BaseInjectorFragment implements Permission private MapboxMap mapboxMap; private Style mapStyle; private LocationComponent locationComponent; - @BindView(R.id.fragment_dashboard_frag_map_mapview) + protected MapView mMapView; - @BindView(R.id.activity_map_follow_fab) + protected FloatingActionButton mFollowFab; private MapLayer mPathOverlay; @@ -98,17 +97,21 @@ public class TrackMapFragment extends BaseInjectorFragment implements Permission private boolean mIsFollowingLocation; + private FragmentTrackMapBinding binding; @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LOG.info("onCreateView()"); + binding = FragmentTrackMapBinding.inflate(inflater,container,false); + View view = binding.getRoot(); + + mMapView = binding.fragmentDashboardFragMapMapview; + mMapView.setOnTouchListener(this::onTouchMapView); - // First inflate the general dashboard view. - View contentView = inflater.inflate(R.layout.fragment_track_map, container, false); + mFollowFab = binding.activityMapFollowFab; + mFollowFab.setOnClickListener(this::onClickFollowFab); - // Inject all dashboard-related views. - ButterKnife.bind(this, contentView); // Init the map view mMapView.onCreate(savedInstanceState); @@ -148,7 +151,7 @@ public void onStyleLoaded(@NonNull Style style) { mIsFollowingLocation = true; mFollowFab.setVisibility(View.INVISIBLE); - return contentView; + return view; } private void setCameraTrackingMode(@CameraMode.Mode int mode) { @@ -179,8 +182,8 @@ public void onLocationCameraTransitionCanceled(@CameraMode.Mode int cameraMode) }); } - @OnTouch(R.id.fragment_dashboard_frag_map_mapview) - protected boolean onTouchMapView() { + + protected boolean onTouchMapView(View view, MotionEvent motionEvent) { if (mIsFollowingLocation) { setCameraTrackingMode(CameraMode.NONE); mIsFollowingLocation = false; @@ -191,8 +194,8 @@ protected boolean onTouchMapView() { return false; } - @OnClick(R.id.activity_map_follow_fab) - protected void onClickFollowFab() { + + protected void onClickFollowFab(View view) { if (!mIsFollowingLocation) { setCameraTrackingMode(CameraMode.TRACKING_GPS); mIsFollowingLocation = true; @@ -358,7 +361,7 @@ public void onStart() { @Override public void onResume() { super.onResume(); - onClickFollowFab(); + onClickFollowFab(mMapView); mMapView.onResume(); } @@ -397,4 +400,4 @@ public void onLowMemory() { super.onLowMemory(); mMapView.onLowMemory(); } -} +} \ No newline at end of file From 3af08ce53f1c74b336fe0588f0fb2739a904bd84 Mon Sep 17 00:00:00 2001 From: Akash-Ramjyothi Date: Tue, 12 Jul 2022 09:48:03 +0530 Subject: [PATCH 17/19] Added Jetpack ViewBinding for custom Views --- .../custom/SamplingRatePreference.java | 19 +++-- .../custom/TimePickerPreferenceDialog.java | 71 ++++++++++--------- 2 files changed, 48 insertions(+), 42 deletions(-) diff --git a/org.envirocar.app/src/org/envirocar/app/views/settings/custom/SamplingRatePreference.java b/org.envirocar.app/src/org/envirocar/app/views/settings/custom/SamplingRatePreference.java index fade795db..f6724368f 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/settings/custom/SamplingRatePreference.java +++ b/org.envirocar.app/src/org/envirocar/app/views/settings/custom/SamplingRatePreference.java @@ -29,11 +29,12 @@ import androidx.preference.PreferenceDialogFragmentCompat; import org.envirocar.app.R; +import org.envirocar.app.databinding.PreferenceSamplingRateDialogBinding; import org.envirocar.app.handler.ApplicationSettings; import org.envirocar.core.logging.Logger; -import butterknife.BindView; -import butterknife.ButterKnife; + + /** * @author dewall @@ -77,18 +78,22 @@ public static Dialog newInstance(String key) { return fragment; } - @BindView(R.id.preference_sampling_rate_dialog_text) + protected TextView textView; - @BindView(R.id.preference_sampling_rate_dialog_picker) - protected NumberPicker numberPicker; + protected NumberPicker numberPicker; + private PreferenceSamplingRateDialogBinding binding; @Override protected void onBindDialogView(View view) { super.onBindDialogView(view); + binding = PreferenceSamplingRateDialogBinding.inflate(getLayoutInflater()); + + textView = binding.preferenceSamplingRateDialogText; + numberPicker = binding.preferenceSamplingRateDialogPicker; // inject views - ButterKnife.bind(this, view); + // set min/max values this.numberPicker.setMinValue(MIN_VALUE); @@ -115,4 +120,4 @@ public void onDialogClosed(boolean positiveResult) { } } } -} +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/settings/custom/TimePickerPreferenceDialog.java b/org.envirocar.app/src/org/envirocar/app/views/settings/custom/TimePickerPreferenceDialog.java index 8c2ff6623..6b509c128 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/settings/custom/TimePickerPreferenceDialog.java +++ b/org.envirocar.app/src/org/envirocar/app/views/settings/custom/TimePickerPreferenceDialog.java @@ -29,12 +29,13 @@ import androidx.preference.PreferenceDialogFragmentCompat; import org.envirocar.app.R; +import org.envirocar.app.databinding.PreferenceTimepickerDialogBinding; import org.envirocar.app.handler.ApplicationSettings; import java.lang.reflect.Field; -import butterknife.BindView; -import butterknife.ButterKnife; + + public class TimePickerPreferenceDialog extends PreferenceDialogFragmentCompat { @@ -69,57 +70,57 @@ public String format(int value) { private int currentSeconds; private int currentMinutes; - // Instance of the binding class to reference any of the views - TimePickerPreferenceDialog binding; - @BindView(R.id.preference_timepicker_text) protected TextView text; - @BindView(R.id.preference_timepicker_minutes_picker) + protected NumberPicker minutePicker; - @BindView(R.id.preference_timepicker_seconds_picker) + protected NumberPicker secondsPicker; + protected PreferenceTimepickerDialogBinding binding; @Override protected void onBindDialogView(View view) { super.onBindDialogView(view); + binding = PreferenceTimepickerDialogBinding.bind(view); + text = binding.preferenceTimepickerText; + minutePicker = binding.preferenceTimepickerMinutesPicker; + secondsPicker = binding.preferenceTimepickerSecondsPicker; - // inject views - ButterKnife.bind(this, view); + // inject view // Set the textview text - binding.text.setText(R.string.pref_bt_discovery_interval_explanation); + this.text.setText(R.string.pref_bt_discovery_interval_explanation); // set the settings for the minute NumberPicker. - binding.minutePicker.setMinValue(0); - binding.minutePicker.setMinValue(0); - binding.minutePicker.setMaxValue(10); - binding.minutePicker.setOnLongPressUpdateInterval(100); - binding.minutePicker.setFormatter(FORMATTER_TWO_DIGITS); - binding.minutePicker.setOnValueChangedListener((picker, oldVal, newVal) -> { - int minValue = binding.minutePicker.getMinValue(); - int maxValue = binding.minutePicker.getMaxValue(); + this.minutePicker.setMinValue(0); + this.minutePicker.setMaxValue(10); + this.minutePicker.setOnLongPressUpdateInterval(100); + this.minutePicker.setFormatter(FORMATTER_TWO_DIGITS); + this.minutePicker.setOnValueChangedListener((picker, oldVal, newVal) -> { + int minValue = minutePicker.getMinValue(); + int maxValue = minutePicker.getMaxValue(); if (oldVal == maxValue && newVal == minValue) { } }); // set the settings for the seconds number picker. - binding.secondsPicker.setMinValue(0); - binding.secondsPicker.setMaxValue(59); + this.secondsPicker.setMinValue(0); + this.secondsPicker.setMaxValue(59); // if (this.displaySeconds != null) // this.secondsPicker.setDisplayedValues(displaySeconds); - binding.secondsPicker.setOnLongPressUpdateInterval(100); - binding.secondsPicker.setFormatter(FORMATTER_TWO_DIGITS); - binding.secondsPicker.setOnValueChangedListener((spinner, oldVal, newVal) -> { - int minValue = binding.secondsPicker.getMinValue(); - int maxValue = binding.secondsPicker.getMaxValue(); + this.secondsPicker.setOnLongPressUpdateInterval(100); + this.secondsPicker.setFormatter(FORMATTER_TWO_DIGITS); + this.secondsPicker.setOnValueChangedListener((spinner, oldVal, newVal) -> { + int minValue = secondsPicker.getMinValue(); + int maxValue = secondsPicker.getMaxValue(); if (oldVal == maxValue && newVal == minValue) { - int newMinute = binding.minutePicker.getValue() + 1; - binding.minutePicker.setValue(newMinute); + int newMinute = minutePicker.getValue() + 1; + minutePicker.setValue(newMinute); } else if (oldVal == minValue && newVal == maxValue) { - int newMinute = binding.minutePicker.getValue() - 1; - binding.minutePicker.setValue(newMinute); + int newMinute = minutePicker.getValue() - 1; + minutePicker.setValue(newMinute); } }); @@ -148,18 +149,18 @@ protected void onBindDialogView(View view) { currentMinutes = minutes; currentSeconds = seconds; - binding.secondsPicker.setValue(currentSeconds); - binding.minutePicker.setValue(currentMinutes); + secondsPicker.setValue(currentSeconds); + minutePicker.setValue(currentMinutes); } } @Override public void onDialogClosed(boolean positiveResult) { if (positiveResult) { - currentMinutes = binding.minutePicker.getValue(); - currentSeconds = binding.secondsPicker.getValue(); + currentMinutes = minutePicker.getValue(); + currentSeconds = secondsPicker.getValue(); - int time = binding.minutePicker.getValue() * 60 + binding.secondsPicker.getValue(); + int time = minutePicker.getValue() * 60 + secondsPicker.getValue(); // save the result DialogPreference preference = getPreference(); @@ -172,4 +173,4 @@ public void onDialogClosed(boolean positiveResult) { ApplicationSettings.setDiscoveryInterval(getActivity(), time); } } -} +} \ No newline at end of file From c4597c202b10767729466775756370fc0bb32f06 Mon Sep 17 00:00:00 2001 From: Akash-Ramjyothi Date: Tue, 12 Jul 2022 09:49:39 +0530 Subject: [PATCH 18/19] Added Jetpack ViewBinding for trackdetails Views --- .../trackdetails/MapExpandedActivity.java | 67 +++++++---- .../trackdetails/TrackDetailsActivity.java | 106 ++++++++++++------ .../trackdetails/TrackStatisticsActivity.java | 35 +++--- 3 files changed, 136 insertions(+), 72 deletions(-) diff --git a/org.envirocar.app/src/org/envirocar/app/views/trackdetails/MapExpandedActivity.java b/org.envirocar.app/src/org/envirocar/app/views/trackdetails/MapExpandedActivity.java index b4c830e5e..7704720ab 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/trackdetails/MapExpandedActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/views/trackdetails/MapExpandedActivity.java @@ -26,11 +26,13 @@ import android.graphics.BitmapFactory; import android.os.Bundle; import android.view.Gravity; +import android.view.MotionEvent; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.annotation.PluralsRes; import androidx.cardview.widget.CardView; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.transition.ChangeBounds; @@ -50,6 +52,7 @@ import com.mapbox.mapboxsdk.style.sources.GeoJsonSource; import org.envirocar.app.R; +import org.envirocar.app.databinding.ActivityMapExpandedBinding; import org.envirocar.app.injection.BaseInjectorActivity; import org.envirocar.app.BaseApplicationComponent; import org.envirocar.core.entity.Measurement; @@ -63,10 +66,7 @@ import javax.inject.Inject; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import butterknife.OnTouch; + import io.reactivex.schedulers.Schedulers; import static android.view.View.GONE; @@ -81,27 +81,27 @@ public class MapExpandedActivity extends BaseInjectorActivity { @Inject protected EnviroCarDB enviroCarDB; - @BindView(R.id.activity_map_follow_fab) + protected FloatingActionButton mCentreFab; - @BindView(R.id.activity_map_visualise_fab) + protected FloatingActionButton mVisualiseFab; - @BindView(R.id.activity_track_details_expanded_map_cancel) + protected ImageView mMapViewExpandedCancel; - @BindView(R.id.activity_track_details_expanded_map) + protected MapView mMapViewExpanded; - @BindView(R.id.activity_track_details_expanded_map_container) + protected ConstraintLayout mMapViewExpandedContainer; - @BindView(R.id.legendCard) + protected CardView legendCard; - @BindView(R.id.legend) + protected ImageView legend; - @BindView(R.id.legend_start) + protected TextView legendStart; - @BindView(R.id.legend_mid) + protected TextView legendMid; - @BindView(R.id.legend_end) + protected TextView legendEnd; - @BindView(R.id.legend_unit) + protected TextView legendName; protected MapboxMap mapboxMapExpanded; @@ -123,12 +123,31 @@ protected void injectDependencies(BaseApplicationComponent baseApplicationCompon baseApplicationComponent.inject(this); } + private ActivityMapExpandedBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_map_expanded); + binding = ActivityMapExpandedBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); + setContentView(view); + + mCentreFab = binding.activityMapFollowFab; + mCentreFab.setOnClickListener(this::onClickFollowFab); + mVisualiseFab = binding.activityMapVisualiseFab; + mVisualiseFab.setOnClickListener(this::onClickVisualiseFab); + mMapViewExpandedCancel = binding.activityTrackDetailsExpandedMapCancel; + mMapViewExpanded = binding.activityTrackDetailsExpandedMap; + mMapViewExpanded.setOnTouchListener(this::onTouchMapView); + + mMapViewExpandedContainer = binding.activityTrackDetailsExpandedMapContainer; + legendCard = binding.legendCard; + legend = binding.legend; + legendStart = binding.legendStart; + legendMid = binding.legendMid; + legendEnd = binding.legendEnd; + legendName = binding.legendUnit; // Inject all annotated views. - ButterKnife.bind(this); + mMapViewExpanded.onCreate(savedInstanceState); // Get the track to show. @@ -154,8 +173,8 @@ protected void onCreate(Bundle savedInstanceState) { mMapViewExpandedCancel.setOnClickListener(v -> finish()); } - @OnTouch(R.id.activity_track_details_expanded_map) - protected boolean onTouchMapView() { + //@OnTouch(R.id.activity_track_details_expanded_map) + protected boolean onTouchMapView(View view, MotionEvent motionEvent) { if (mIsCentredOnTrack) { mIsCentredOnTrack = false; TransitionManager.beginDelayedTransition(mMapViewExpandedContainer, new androidx.transition.Slide(Gravity.RIGHT)); @@ -164,8 +183,8 @@ protected boolean onTouchMapView() { return false; } - @OnClick(R.id.activity_map_follow_fab) - protected void onClickFollowFab() { + //@OnClick(R.id.activity_map_follow_fab) + protected void onClickFollowFab(View view) { final LatLngBounds viewBbox = trackMapOverlay.getViewBoundingBox(); if (!mIsCentredOnTrack) { mIsCentredOnTrack = true; @@ -175,8 +194,8 @@ protected void onClickFollowFab() { } } - @OnClick(R.id.activity_map_visualise_fab) - protected void onClickVisualiseFab() { + //@OnClick(R.id.activity_map_visualise_fab) + protected void onClickVisualiseFab(View view) { LOG.info("onClickVisualiseFab"); AlertDialog.Builder b = new AlertDialog.Builder(this); b.setTitle(R.string.mapview_extended_select_phenomena); @@ -367,4 +386,4 @@ protected void onSaveInstanceState(Bundle outState) { mMapViewExpanded.onSaveInstanceState(outState); } -} +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/trackdetails/TrackDetailsActivity.java b/org.envirocar.app/src/org/envirocar/app/views/trackdetails/TrackDetailsActivity.java index b865dcf70..8ac53793f 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/trackdetails/TrackDetailsActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/views/trackdetails/TrackDetailsActivity.java @@ -1,18 +1,18 @@ /** * Copyright (C) 2013 - 2021 the enviroCar community - * + *

* This file is part of the enviroCar app. - * + *

* The enviroCar app is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + *

* The enviroCar app is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * Public License for more details. - * + *

* You should have received a copy of the GNU General Public License along * with the enviroCar app. If not, see http://www.gnu.org/licenses/. */ @@ -52,6 +52,8 @@ import org.envirocar.app.BaseApplicationComponent; import org.envirocar.app.R; +import org.envirocar.app.databinding.ActivityTrackDetailsAttributesBinding; +import org.envirocar.app.databinding.ActivityTrackDetailsLayoutBinding; import org.envirocar.app.handler.ApplicationSettings; import org.envirocar.app.injection.BaseInjectorActivity; import org.envirocar.core.EnviroCarDB; @@ -75,8 +77,8 @@ import javax.inject.Inject; -import butterknife.BindView; -import butterknife.ButterKnife; + + import io.reactivex.schedulers.Schedulers; @@ -107,55 +109,55 @@ public static void navigate(Activity activity, View transition, int trackID) { @Inject protected EnviroCarDB mEnvirocarDB; - @BindView(R.id.activity_track_details_fab) + protected FloatingActionButton mFAB; - @BindView(R.id.activity_track_details_header_map) + protected MapView mMapView; - @BindView(R.id.activity_track_details_header_toolbar) + protected Toolbar mToolbar; - @BindView(R.id.activity_track_details_attr_description_value) + protected TextView mDescriptionText; - @BindView(R.id.track_details_attributes_header_duration) + protected TextView mDurationText; - @BindView(R.id.track_details_attributes_header_distance) + protected TextView mDistanceText; - @BindView(R.id.activity_track_details_attr_begin_value) + protected TextView mBeginText; - @BindView(R.id.activity_track_details_attr_end_value) + protected TextView mEndText; - @BindView(R.id.activity_track_details_attr_car_value) + protected TextView mCarText; - @BindView(R.id.activity_track_details_attr_emission_text) + protected TextView mEmissionKey; - @BindView(R.id.activity_track_details_attr_emission_value) + protected TextView mEmissionText; - @BindView(R.id.activity_track_details_attr_consumption_text) + protected TextView mConsumptionKey; - @BindView(R.id.activity_track_details_attr_consumption_value) + protected TextView mConsumptionText; - @BindView(R.id.activity_track_details_appbar_layout) + protected AppBarLayout mAppBarLayout; - @BindView(R.id.activity_track_details_scrollview) + protected NestedScrollView mNestedScrollView; - @BindView(R.id.activity_track_details_header_map_container) + protected FrameLayout mMapViewContainer; - @BindView(R.id.consumption_container) + protected RelativeLayout mConsumptionContainer; - @BindView(R.id.co2_container) + protected RelativeLayout mCo2Container; - @BindView(R.id.descriptionTv) + protected TextView descriptionTv; - @BindView(R.id.activity_track_details_speed_container) + protected RelativeLayout speedLayout; - @BindView(R.id.activity_track_details_speed_value) + protected TextView speedText; - @BindView(R.id.activity_track_details_stops_container) + protected RelativeLayout stopsLayout; - @BindView(R.id.activity_track_details_stops_value) + protected TextView stopsValue; - @BindView(R.id.activity_track_details_stoptime_container) + protected RelativeLayout stoptimeLayout; - @BindView(R.id.activity_track_details_stoptime_value) + protected TextView stoptimeValue; @@ -169,14 +171,50 @@ protected void injectDependencies(BaseApplicationComponent baseApplicationCompon baseApplicationComponent.inject(this); } + private ActivityTrackDetailsLayoutBinding binding; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initActivityTransition(); - setContentView(R.layout.activity_track_details_layout); + binding = ActivityTrackDetailsLayoutBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); + setContentView(view); + + mFAB = binding.activityTrackDetailsFab; + mMapView = binding.activityTrackDetailsHeaderMap; + mToolbar = binding.activityTrackDetailsHeaderToolbar; + mDescriptionText = binding.activityTrackDetailsAttrDescriptionValue; + mDurationText = binding.trackDetailsAttributesHeaderDuration.trackDetailsAttributesHeaderDuration; + mDistanceText = binding.trackDetailsAttributesHeaderDuration.trackDetailsAttributesHeaderDistance; + mBeginText = binding.activityTrackDetailsAttributes.activityTrackDetailsAttrBeginValue; + mEndText = binding.activityTrackDetailsAttributes.activityTrackDetailsAttrEndValue; + mCarText = binding.activityTrackDetailsAttributes.activityTrackDetailsAttrCarText; + mEmissionKey = binding.activityTrackDetailsAttributes.activityTrackDetailsAttrEmissionText; + mEmissionText = binding.activityTrackDetailsAttributes.activityTrackDetailsAttrEmissionValue; + mConsumptionKey = binding.activityTrackDetailsAttributes.activityTrackDetailsAttrConsumptionText; + mConsumptionText = binding.activityTrackDetailsAttributes.activityTrackDetailsAttrConsumptionValue; + mAppBarLayout = binding.activityTrackDetailsAppbarLayout; + mNestedScrollView = binding.activityTrackDetailsScrollview; + mMapViewContainer = binding.activityTrackDetailsHeaderMapContainer; + mConsumptionContainer = binding.activityTrackDetailsAttributes.consumptionContainer; + mCo2Container = binding.activityTrackDetailsAttributes.co2Container; + descriptionTv = binding.activityTrackDetailsAttributes.descriptionTv; + speedLayout = binding.activityTrackDetailsAttributes.activityTrackDetailsSpeedContainer; + speedText = binding.activityTrackDetailsAttributes.activityTrackDetailsSpeedValue; + stopsLayout = binding.activityTrackDetailsAttributes.activityTrackDetailsStopsContainer; + stopsValue = binding.activityTrackDetailsAttributes.activityTrackDetailsStopsValue; + stoptimeLayout = binding.activityTrackDetailsAttributes.activityTrackDetailsStoptimeContainer; + stoptimeValue = binding.activityTrackDetailsAttributes.activityTrackDetailsStoptimeValue; + //mConsumptionContainer = binding. + //mCo2Container = binding. + //descriptionTv = binding. + //speedLayout = binding. + // speedText = binding. + // Inject all annotated views. - ButterKnife.bind(this); + mMapView.onCreate(savedInstanceState); supportPostponeEnterTransition(); @@ -471,4 +509,4 @@ protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); mMapView.onSaveInstanceState(outState); } -} +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/trackdetails/TrackStatisticsActivity.java b/org.envirocar.app/src/org/envirocar/app/views/trackdetails/TrackStatisticsActivity.java index 26e8bf469..a0c979d8f 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/trackdetails/TrackStatisticsActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/views/trackdetails/TrackStatisticsActivity.java @@ -34,6 +34,9 @@ import org.envirocar.app.BaseApplicationComponent; import org.envirocar.app.R; +import org.envirocar.app.databinding.ActivityTrackDetailsLayoutBinding; +import org.envirocar.app.databinding.ActivityTrackStatisticsFragmentBinding; +import org.envirocar.app.databinding.ActivityTrackStatisticsLayoutBinding; import org.envirocar.core.entity.Measurement; import org.envirocar.core.entity.Track; import org.envirocar.app.injection.BaseInjectorActivity; @@ -45,8 +48,8 @@ import javax.inject.Inject; -import butterknife.ButterKnife; -import butterknife.BindView; + + import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; import lecho.lib.hellocharts.formatter.SimpleAxisValueFormatter; @@ -78,7 +81,7 @@ public static void createInstance(Activity activity, int trackID) { @Inject protected EnviroCarDB enviroCarDB; - @BindView(R.id.activity_track_statistics_toolbar) + protected Toolbar mToolbar; private Track mTrack; @@ -88,11 +91,15 @@ public static void createInstance(Activity activity, int trackID) { protected void injectDependencies(BaseApplicationComponent baseApplicationComponent) { baseApplicationComponent.inject(this); } - + private ActivityTrackStatisticsLayoutBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_track_statistics_layout); + binding = ActivityTrackStatisticsLayoutBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); + setContentView(view); + + mToolbar = binding.activityTrackStatisticsToolbar; int trackID = getIntent().getIntExtra(EXTRA_TRACKID, -1); Track.TrackId trackid = new Track.TrackId(trackID); @@ -117,7 +124,6 @@ protected void onCreate(Bundle savedInstanceState) { }); // Inject all annotated views. - ButterKnife.bind(this); // Initializes the Toolbar. setSupportActionBar(mToolbar); @@ -164,9 +170,9 @@ private void inflateMenuProperties(Track track) { public static class PlaceholderFragment extends Fragment { - @BindView(R.id.activity_track_statistics_fragment_chart) + protected LineChartView mChart; - @BindView(R.id.activity_track_statistics_fragment_chart_preview) + protected PreviewLineChartView mPreviewChart; private LineChartData mChartData; @@ -183,15 +189,16 @@ public PlaceholderFragment(Track track) { this.mTrack = track; } + private ActivityTrackStatisticsFragmentBinding binding; @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.activity_track_statistics_fragment, - container, false); + binding = ActivityTrackStatisticsFragmentBinding.inflate(inflater,container,false); + View view = binding.getRoot(); - // Inject all annotated views. - ButterKnife.bind(this, rootView); + mChart = binding.activityTrackStatisticsFragmentChart; + mPreviewChart = binding.activityTrackStatisticsFragmentChartPreview; if(mTrack.hasProperty(Measurement.PropertyKey.SPEED)){ generateData(Measurement.PropertyKey.SPEED); @@ -210,7 +217,7 @@ public void onViewportChanged(Viewport viewport) { } }); - return rootView; + return view; } private void generateData(Measurement.PropertyKey propertyKey) { @@ -317,4 +324,4 @@ private void previewY() { mPreviewChart.setZoomType(ZoomType.VERTICAL); } } -} +} \ No newline at end of file From a5daf1270ed7a46dd1a4c10e74ecbdc5ce8ad111 Mon Sep 17 00:00:00 2001 From: Akash-Ramjyothi Date: Tue, 12 Jul 2022 09:52:02 +0530 Subject: [PATCH 19/19] Added Jetpack ViewBinding for tracklist Views --- .../AbstractTrackListCardAdapter.java | 59 ++++++++++++++----- .../AbstractTrackListCardFragment.java | 47 +++++++++------ .../tracklist/TrackListLocalCardFragment.java | 8 +-- .../tracklist/TrackListPagerFragment.java | 23 +++++--- 4 files changed, 92 insertions(+), 45 deletions(-) diff --git a/org.envirocar.app/src/org/envirocar/app/views/tracklist/AbstractTrackListCardAdapter.java b/org.envirocar.app/src/org/envirocar/app/views/tracklist/AbstractTrackListCardAdapter.java index 9745f972c..76debf39b 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/tracklist/AbstractTrackListCardAdapter.java +++ b/org.envirocar.app/src/org/envirocar/app/views/tracklist/AbstractTrackListCardAdapter.java @@ -38,6 +38,10 @@ import com.mapbox.mapboxsdk.maps.Style; import org.envirocar.app.R; +import org.envirocar.app.databinding.ActivityLogbookListentryBinding; +import org.envirocar.app.databinding.FragmentTrackMapBinding; +import org.envirocar.app.databinding.FragmentTracklistCardlayoutBinding; +import org.envirocar.app.databinding.FragmentTracklistCardlayoutRemoteBinding; import org.envirocar.app.views.trackdetails.TrackMapLayer; import org.envirocar.core.entity.Track; import org.envirocar.core.logging.Logger; @@ -50,8 +54,8 @@ import java.util.Locale; import java.util.TimeZone; -import butterknife.BindView; -import butterknife.ButterKnife; + + import io.reactivex.Scheduler; import io.reactivex.android.schedulers.AndroidSchedulers; @@ -297,34 +301,52 @@ static class TrackCardViewHolder extends RecyclerView.ViewHolder { protected final View mItemView; - @BindView(R.id.fragment_tracklist_cardlayout_toolbar) + protected Toolbar mToolbar; - @BindView(R.id.fragment_tracklist_cardlayout_toolbar_title) + protected TextView mTitleTextView; - @BindView(R.id.fragment_tracklist_cardlayout_content) + protected View mContentView; - @BindView(R.id.track_details_attributes_header_distance) + protected TextView mDistance; - @BindView(R.id.track_details_attributes_header_duration) + protected TextView mDuration; - @BindView(R.id.fragment_tracklist_cardlayout_map) + protected MapView mMapView; - @BindView(R.id.fragment_tracklist_cardlayout_invis_mapbutton) + protected ImageButton mInvisMapButton; - @BindView(R.id.fragment_layout_card_view) + protected LinearLayout cardViewLayout; protected MapView.OnDidFailLoadingMapListener failLoadingMapListener; + + + protected FragmentTracklistCardlayoutBinding binding; /** * Constructor. * * @param itemView the card view of the */ + public TrackCardViewHolder(View itemView) { super(itemView); + this.mItemView = itemView; - ButterKnife.bind(this, itemView); + binding = FragmentTracklistCardlayoutBinding.bind(itemView); + + mToolbar= binding.fragmentTracklistCardlayoutToolbar; + mTitleTextView = binding.fragmentTracklistCardlayoutToolbarTitle; + mContentView = binding.fragmentTracklistCardlayoutContent.getRoot(); + mDistance = binding.fragmentTracklistCardlayoutContent.trackDetailsAttributesHeaderDistance; + mDuration = binding.fragmentTracklistCardlayoutContent.trackDetailsAttributesHeaderDuration; + mMapView = binding.fragmentTracklistCardlayoutContent.fragmentTracklistCardlayoutMap; + mInvisMapButton = binding.fragmentTracklistCardlayoutContent.fragmentTracklistCardlayoutInvisMapbutton; + cardViewLayout = binding.fragmentLayoutCardView; + + + + failLoadingMapListener = new MapView.OnDidFailLoadingMapListener() { @Override public void onDidFailLoadingMap(String errorMessage) { @@ -355,13 +377,15 @@ public LocalTrackCardViewHolder(View itemView) { */ static class RemoteTrackCardViewHolder extends TrackCardViewHolder { - @BindView(R.id.fragment_tracklist_cardlayout_remote_progresscircle) + protected FABProgressCircle mProgressCircle; - @BindView(R.id.fragment_tracklist_cardlayout_remote_downloadfab) + protected FloatingActionButton mDownloadButton; - @BindView(R.id.fragment_tracklist_cardlayout_downloading_notification) + protected TextView mDownloadNotification; + + protected FragmentTracklistCardlayoutRemoteBinding binding; /** * Constructor. * @@ -369,6 +393,11 @@ static class RemoteTrackCardViewHolder extends TrackCardViewHolder { */ public RemoteTrackCardViewHolder(View itemView) { super(itemView); + binding = FragmentTracklistCardlayoutRemoteBinding.bind(itemView); + mProgressCircle = binding.fragmentTracklistCardlayoutRemoteProgresscircle; + mDownloadButton = binding.fragmentTracklistCardlayoutRemoteDownloadfab; + mDownloadNotification = binding.fragmentTracklistCardlayoutDownloadingNotification; + } } -} +} \ No newline at end of file diff --git a/org.envirocar.app/src/org/envirocar/app/views/tracklist/AbstractTrackListCardFragment.java b/org.envirocar.app/src/org/envirocar/app/views/tracklist/AbstractTrackListCardFragment.java index 5036bdec1..ae2adcf31 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/tracklist/AbstractTrackListCardFragment.java +++ b/org.envirocar.app/src/org/envirocar/app/views/tracklist/AbstractTrackListCardFragment.java @@ -44,6 +44,7 @@ import org.envirocar.app.BuildConfig; import org.envirocar.app.R; +import org.envirocar.app.databinding.FragmentTracklistBinding; import org.envirocar.app.handler.DAOProvider; import org.envirocar.app.handler.TrackDAOHandler; import org.envirocar.app.handler.TrackUploadHandler; @@ -66,8 +67,8 @@ import javax.inject.Inject; -import butterknife.BindView; -import butterknife.ButterKnife; + + import io.reactivex.Observable; import io.reactivex.Scheduler; import io.reactivex.android.schedulers.AndroidSchedulers; @@ -93,24 +94,24 @@ public abstract class AbstractTrackListCardFragment