diff --git a/astronauts/build.gradle b/astronauts/build.gradle index 13f9c1b7c..63f8a9ac0 100644 --- a/astronauts/build.gradle +++ b/astronauts/build.gradle @@ -1,7 +1,9 @@ apply plugin: 'com.android.library' -apply plugin: 'com.jakewharton.butterknife' android { + buildFeatures { + viewBinding true + } compileSdkVersion rootProject.ext.compileSdkVersion defaultConfig { minSdkVersion rootProject.minSdkVersion @@ -16,6 +18,7 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + compileOptions { sourceCompatibility = '1.8' targetCompatibility = '1.8' @@ -29,10 +32,12 @@ dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation project(':data') implementation project(':common') + //Networking implementation deps.retrofit implementation deps.converter_gson implementation deps.gson + //Utils implementation deps.timber implementation deps.constraintLayout @@ -50,10 +55,9 @@ dependencies { implementation deps.communityMaterialTypeface implementation deps.weathericon implementation deps.fontawesomeTypeface + //Views implementation deps.statefulLayout - implementation deps.butterknife - annotationProcessor deps.butterknifeCompiler implementation deps.glide annotationProcessor deps.glideCompiler implementation deps.playAds diff --git a/astronauts/proguard-rules.pro b/astronauts/proguard-rules.pro index c7ee06a95..c54d450e2 100644 --- a/astronauts/proguard-rules.pro +++ b/astronauts/proguard-rules.pro @@ -99,20 +99,6 @@ public *; public *; } -# ButterKnife 7 - --keep class butterknife.** { *; } --dontwarn butterknife.internal.** --keep class **$$ViewBinder { *; } - --keepclasseswithmembernames class * { - @butterknife.* ; -} - --keepclasseswithmembernames class * { - @butterknife.* ; -} - # Crashlytics 2.+ -keep class com.crashlytics.** { *; } diff --git a/astronauts/src/main/java/me/calebjones/spacelaunchnow/astronauts/detail/AstronautDetailsActivity.java b/astronauts/src/main/java/me/calebjones/spacelaunchnow/astronauts/detail/AstronautDetailsActivity.java index 0d04cbf1f..5949e265f 100644 --- a/astronauts/src/main/java/me/calebjones/spacelaunchnow/astronauts/detail/AstronautDetailsActivity.java +++ b/astronauts/src/main/java/me/calebjones/spacelaunchnow/astronauts/detail/AstronautDetailsActivity.java @@ -1,24 +1,19 @@ package me.calebjones.spacelaunchnow.astronauts.detail; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; import com.google.android.gms.ads.AdListener; import com.google.android.gms.ads.AdRequest; -import com.google.android.gms.ads.AdView; import com.google.android.material.appbar.AppBarLayout; -import com.google.android.material.appbar.CollapsingToolbarLayout; -import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.tabs.TabLayout; import androidx.annotation.Nullable; -import androidx.appcompat.widget.Toolbar; -import androidx.coordinatorlayout.widget.CoordinatorLayout; + import androidx.core.app.ShareCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -29,11 +24,6 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.ViewPager; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import cz.kinst.jakub.view.SimpleStatefulLayout; -import de.hdodenhof.circleimageview.CircleImageView; import jonathanfinerty.once.Amount; import jonathanfinerty.once.Once; import me.calebjones.spacelaunchnow.astronauts.data.AstronautDataRepository; @@ -44,41 +34,12 @@ import me.calebjones.spacelaunchnow.data.models.main.Agency; import me.calebjones.spacelaunchnow.data.models.main.astronaut.Astronaut; import me.spacelaunchnow.astronauts.R; -import me.spacelaunchnow.astronauts.R2; +import me.spacelaunchnow.astronauts.databinding.ActivityAstronautDetailsBinding; import timber.log.Timber; public class AstronautDetailsActivity extends BaseActivity implements AppBarLayout.OnOffsetChangedListener, SwipeRefreshLayout.OnRefreshListener { - @BindView(R2.id.astronaut_profile_backdrop) - ImageView astronautProfileBackdrop; - @BindView(R2.id.astronaut_collapsing) - CollapsingToolbarLayout astronautCollapsing; - @BindView(R2.id.astronaut_profile_image) - CircleImageView astronautProfileImage; - @BindView(R2.id.astronaut_detail_toolbar) - Toolbar toolbar; - @BindView(R2.id.astronaut_title) - TextView astronautTitle; - @BindView(R2.id.astronaut_subtitle) - TextView astronautSubtitle; - @BindView(R2.id.astronaut_detail_tabs) - TabLayout tabs; - @BindView(R2.id.appbar) - AppBarLayout appbar; - @BindView(R2.id.astronaut_detail_viewpager) - ViewPager viewPager; - @BindView(R2.id.astronaut_adView) - AdView astronautAdView; - @BindView(R2.id.astronaut_stateful_view) - SimpleStatefulLayout astronautStatefulView; - @BindView(R2.id.astronaut_detail_swipe_refresh) - SwipeRefreshLayout astronautDetailSwipeRefresh; - @BindView(R2.id.astronaut_fab_share) - FloatingActionButton astronautFabShare; - @BindView(R2.id.rootview) - CoordinatorLayout rootview; - private static final int PERCENTAGE_TO_ANIMATE_AVATAR = 20; private boolean mIsAvatarShown = true; private int mMaxScrollSize; @@ -96,21 +57,22 @@ public class AstronautDetailsActivity extends BaseActivity implements AppBarLayo private Astronaut astronaut; private Agency agency; private int astronautId; + private ActivityAstronautDetailsBinding bindings; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_astronaut_details); - ButterKnife.bind(this); - astronautFabShare.setVisibility(View.GONE); - setSupportActionBar(toolbar); + bindings = ActivityAstronautDetailsBinding.inflate(getLayoutInflater()); + + bindings.astronautFabShare.setVisibility(View.GONE); + setSupportActionBar(bindings.astronautDetailToolbar); // Create the adapter that will return a fragment for each of the three // primary sections of the activity. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); - astronautDetailSwipeRefresh.setOnRefreshListener(this); - viewPager.setAdapter(mSectionsPagerAdapter); - viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabs)); - viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { + bindings.astronautDetailSwipeRefresh.setOnRefreshListener(this); + bindings.astronautDetailViewpager.setAdapter(mSectionsPagerAdapter); + bindings.astronautDetailViewpager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(bindings.astronautDetailTabs)); + bindings.astronautDetailViewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float v, int i1) { } @@ -124,19 +86,20 @@ public void onPageScrollStateChanged(int state) { enableDisableSwipeRefresh(state == ViewPager.SCROLL_STATE_IDLE); } }); - tabs.addTab(tabs.newTab().setText(getString(R.string.profile))); - tabs.addTab(tabs.newTab().setText(getString(R.string.flights))); - tabs.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager)); + bindings.astronautDetailTabs.addTab(bindings.astronautDetailTabs.newTab().setText(getString(R.string.profile))); + bindings.astronautDetailTabs.addTab(bindings.astronautDetailTabs.newTab().setText(getString(R.string.flights))); + bindings.astronautDetailTabs.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(bindings.astronautDetailViewpager)); astronautDataRepository = new AstronautDataRepository(this, getRealm()); //Grab information from Intent Intent mIntent = getIntent(); + Context context = this; astronautId = mIntent.getIntExtra("astronautId", 0); fetchData(astronautId); - if (toolbar != null) { - setSupportActionBar(toolbar); + if (bindings.astronautDetailToolbar != null) { + setSupportActionBar(bindings.astronautDetailToolbar); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); @@ -160,23 +123,30 @@ public void onPageScrollStateChanged(int state) { if (!SupporterHelper.isSupporter() && Once.beenDone("appOpen", Amount.moreThan(3))) { AdRequest adRequest = new AdRequest.Builder().build(); - astronautAdView.loadAd(adRequest); - astronautAdView.setAdListener(new AdListener() { + bindings.astronautAdView.loadAd(adRequest); + bindings.astronautAdView.setAdListener(new AdListener() { @Override public void onAdLoaded() { - astronautAdView.setVisibility(View.VISIBLE); + bindings.astronautAdView.setVisibility(View.VISIBLE); } }); } else { - astronautAdView.setVisibility(View.GONE); + bindings.astronautAdView.setVisibility(View.GONE); } + + bindings.astronautFabShare.setOnClickListener(view -> new ShareCompat.IntentBuilder( + AstronautDetailsActivity.this) + .setType("text/plain") + .setChooserTitle(astronaut.getName()) + .setText(astronaut.getUrl()) + .startChooser()); } private void enableDisableSwipeRefresh(boolean enable) { - if (astronautDetailSwipeRefresh != null) { - astronautDetailSwipeRefresh.setEnabled(enable); + if (bindings.astronautDetailSwipeRefresh != null) { + bindings.astronautDetailSwipeRefresh.setEnabled(enable); } } @@ -233,15 +203,15 @@ public void onError(String message, @Nullable Throwable throwable) { private void updateAstronautViews(Astronaut astronaut) { this.astronaut = astronaut; try { - astronautTitle.setText(astronaut.getName()); - astronautSubtitle.setText(astronaut.getNationality()); + bindings.astronautTitle.setText(astronaut.getName()); + bindings.astronautSubtitle.setText(astronaut.getNationality()); GlideApp.with(this) .load(astronaut.getProfileImage()) .thumbnail(GlideApp.with(this) .load(astronaut.getProfileImageThumbnail())) .placeholder(R.drawable.placeholder) - .into(astronautProfileImage); + .into(bindings.astronautProfileImage); } catch (Exception e) { Timber.e(e); } @@ -270,7 +240,7 @@ public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { if (percentage >= PERCENTAGE_TO_ANIMATE_AVATAR && mIsAvatarShown) { mIsAvatarShown = false; - astronautProfileImage.animate() + bindings.astronautProfileImage.animate() .scaleY(0).scaleX(0) .setDuration(300) .start(); @@ -279,7 +249,7 @@ public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { if (percentage <= PERCENTAGE_TO_ANIMATE_AVATAR && !mIsAvatarShown) { mIsAvatarShown = true; - astronautProfileImage.animate() + bindings.astronautProfileImage.animate() .scaleY(1).scaleX(1) .start(); } @@ -295,12 +265,12 @@ private void showNetworkLoading(boolean loading) { private void showLoading() { Timber.v("Show Loading..."); - astronautDetailSwipeRefresh.post(() -> astronautDetailSwipeRefresh.setRefreshing(true)); + bindings.astronautDetailSwipeRefresh.post(() -> bindings.astronautDetailSwipeRefresh.setRefreshing(true)); } private void hideLoading() { Timber.v("Hide Loading..."); - astronautDetailSwipeRefresh.post(() -> astronautDetailSwipeRefresh.setRefreshing(false)); + bindings.astronautDetailSwipeRefresh.post(() -> bindings.astronautDetailSwipeRefresh.setRefreshing(false)); } @@ -318,16 +288,6 @@ public boolean onOptionsItemSelected(MenuItem item) { return super.onOptionsItemSelected(item); } - //TODO Get URL for SLN website. - @OnClick(R2.id.astronaut_fab_share) - void fabClicked() { - ShareCompat.IntentBuilder.from(this) - .setType("text/plain") - .setChooserTitle(astronaut.getName()) - .setText(astronaut.getUrl()) - .startChooser(); - } - @Override public void onRefresh() { fetchData(astronautId); diff --git a/astronauts/src/main/java/me/calebjones/spacelaunchnow/astronauts/detail/AstronautFlightsFragment.java b/astronauts/src/main/java/me/calebjones/spacelaunchnow/astronauts/detail/AstronautFlightsFragment.java index dce2e490b..d7591e71e 100644 --- a/astronauts/src/main/java/me/calebjones/spacelaunchnow/astronauts/detail/AstronautFlightsFragment.java +++ b/astronauts/src/main/java/me/calebjones/spacelaunchnow/astronauts/detail/AstronautFlightsFragment.java @@ -10,29 +10,21 @@ import androidx.annotation.Nullable; import androidx.lifecycle.ViewModelProviders; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; import me.calebjones.spacelaunchnow.common.base.BaseFragment; import me.calebjones.spacelaunchnow.common.prefs.ThemeHelper; import me.calebjones.spacelaunchnow.common.ui.adapters.ListAdapter; import me.calebjones.spacelaunchnow.common.utils.SimpleDividerItemDecoration; import me.calebjones.spacelaunchnow.data.models.main.astronaut.Astronaut; -import me.spacelaunchnow.astronauts.R; -import me.spacelaunchnow.astronauts.R2; +import me.spacelaunchnow.astronauts.databinding.AstronautFlightFragmentBinding; public class AstronautFlightsFragment extends BaseFragment { - @BindView(R2.id.recycler_view) - RecyclerView recyclerView; - private AstronautDetailViewModel mViewModel; - private Unbinder unbinder; private LinearLayoutManager linearLayoutManager; private ListAdapter adapter; private Context context; + private AstronautFlightFragmentBinding binding; public static AstronautFlightsFragment newInstance() { return new AstronautFlightsFragment(); @@ -47,14 +39,14 @@ public void onCreate(Bundle savedInstanceState) { @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.astronaut_flight_fragment, container, false); - unbinder = ButterKnife.bind(this, view); + binding = AstronautFlightFragmentBinding.inflate(inflater, container, false); + View view = binding.getRoot(); linearLayoutManager = new LinearLayoutManager(context); adapter = new ListAdapter(context, ThemeHelper.isDarkMode(getActivity())); - recyclerView.setLayoutManager(linearLayoutManager); - recyclerView.addItemDecoration(new SimpleDividerItemDecoration(context)); - recyclerView.setAdapter(adapter); + binding.recyclerView.setLayoutManager(linearLayoutManager); + binding.recyclerView.addItemDecoration(new SimpleDividerItemDecoration(context)); + binding.recyclerView.setAdapter(adapter); return view; } diff --git a/astronauts/src/main/java/me/calebjones/spacelaunchnow/astronauts/detail/AstronautProfileFragment.java b/astronauts/src/main/java/me/calebjones/spacelaunchnow/astronauts/detail/AstronautProfileFragment.java index 872ff1e15..a5af8e5f0 100644 --- a/astronauts/src/main/java/me/calebjones/spacelaunchnow/astronauts/detail/AstronautProfileFragment.java +++ b/astronauts/src/main/java/me/calebjones/spacelaunchnow/astronauts/detail/AstronautProfileFragment.java @@ -2,35 +2,21 @@ import static me.calebjones.spacelaunchnow.common.utils.LinkHandler.openCustomTab; -import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; -import android.content.res.Resources; -import android.net.Uri; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; import com.mikepenz.fontawesome_typeface_library.FontAwesome; import com.mikepenz.iconics.IconicsDrawable; -import java.text.DateFormat; import java.util.Calendar; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.widget.AppCompatButton; -import androidx.appcompat.widget.AppCompatImageButton; -import androidx.cardview.widget.CardView; -import androidx.core.content.ContextCompat; import androidx.lifecycle.ViewModelProviders; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import butterknife.Unbinder; import me.calebjones.spacelaunchnow.common.GlideApp; import me.calebjones.spacelaunchnow.common.base.BaseFragment; import me.calebjones.spacelaunchnow.common.prefs.ThemeHelper; @@ -39,50 +25,14 @@ import me.calebjones.spacelaunchnow.data.models.main.Agency; import me.calebjones.spacelaunchnow.data.models.main.astronaut.Astronaut; import me.spacelaunchnow.astronauts.R; -import me.spacelaunchnow.astronauts.R2; +import me.spacelaunchnow.astronauts.databinding.AstronautProfileFragmentBinding; import timber.log.Timber; public class AstronautProfileFragment extends BaseFragment { - @BindView(R2.id.astronaut_bio_text) - TextView astronautBio; - @BindView(R2.id.astronaut_twitter_button) - AppCompatImageButton astronautTwitterButton; - @BindView(R2.id.astronaut_instagram_button) - AppCompatImageButton astronautInstagramButton; - @BindView(R2.id.astronaut_wiki_button) - AppCompatImageButton astronautWikiButton; - @BindView(R2.id.astronaut_wiki_button_solo) - AppCompatButton astronautWikiButtonSolo; - @BindView(R2.id.astronaut_status) - TextView astronautStatus; - @BindView(R2.id.lsp_logo) - ImageView lspLogo; - @BindView(R2.id.lsp_name) - TextView lspName; - @BindView(R2.id.lsp_type) - TextView lspType; - @BindView(R2.id.lsp_summary) - TextView lspSummary; - @BindView(R2.id.lsp_infoButton_one) - AppCompatButton lspInfoButtonOne; - @BindView(R2.id.lsp_wikiButton_one) - AppCompatButton lspWikiButtonOne; - @BindView(R2.id.lsp_card) - CardView lspCard; - @BindView(R2.id.lsp_administrator) - TextView lspAdministrator; - @BindView(R2.id.lsp_founded_year) - TextView lspFoundedYear; - @BindView(R2.id.lsp_agency) - AppCompatButton lspAgency; - @BindView(R2.id.astronaut_born) - TextView astronautBorn; - @BindView(R2.id.astronaut_died) - TextView astronautDied; private AstronautDetailViewModel mViewModel; - private Unbinder unbinder; private Context context; + private AstronautProfileFragmentBinding binding; public static AstronautProfileFragment newInstance() { return new AstronautProfileFragment(); @@ -97,8 +47,8 @@ public void onCreate(Bundle savedInstanceState) { @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.astronaut_profile_fragment, container, false); - unbinder = ButterKnife.bind(this, view); + binding = AstronautProfileFragmentBinding.inflate(inflater, container, false); + View view = binding.getRoot(); return view; } @@ -112,46 +62,46 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) { } private void setAstronaut(Astronaut astronaut) { - astronautBio.setText(astronaut.getBio()); - astronautStatus.setText(astronaut.getStatus().getName()); + binding.astronautBioText.setText(astronaut.getBio()); + binding.astronautStatus.setText(astronaut.getStatus().getName()); int color = ThemeHelper.getIconColor(getActivity()); - astronautInstagramButton.setImageDrawable(new IconicsDrawable(context).icon(FontAwesome.Icon.faw_instagram).sizeDp(24).color(color)); - astronautWikiButton.setImageDrawable(new IconicsDrawable(context).icon(FontAwesome.Icon.faw_wikipedia_w).sizeDp(24).color(color)); - astronautTwitterButton.setImageDrawable(new IconicsDrawable(context).icon(FontAwesome.Icon.faw_twitter).sizeDp(24).color(color)); + binding.astronautInstagramButton.setImageDrawable(new IconicsDrawable(context).icon(FontAwesome.Icon.faw_instagram).sizeDp(24).color(color)); + binding.astronautWikiButton.setImageDrawable(new IconicsDrawable(context).icon(FontAwesome.Icon.faw_wikipedia_w).sizeDp(24).color(color)); + binding.astronautTwitterButton.setImageDrawable(new IconicsDrawable(context).icon(FontAwesome.Icon.faw_twitter).sizeDp(24).color(color)); if (astronaut.getInstagram() != null) { - astronautInstagramButton.setVisibility(View.VISIBLE); - astronautInstagramButton.setOnClickListener(v -> { + binding.astronautInstagramButton.setVisibility(View.VISIBLE); + binding.astronautInstagramButton.setOnClickListener(v -> { openCustomTab(context, astronaut.getInstagram()); }); } else { - astronautInstagramButton.setVisibility(View.GONE); + binding.astronautInstagramButton.setVisibility(View.GONE); } if (astronaut.getTwitter() != null) { - astronautTwitterButton.setVisibility(View.VISIBLE); - astronautTwitterButton.setOnClickListener(v -> { + binding.astronautTwitterButton.setVisibility(View.VISIBLE); + binding.astronautTwitterButton.setOnClickListener(v -> { openCustomTab(context, astronaut.getTwitter()); }); } else { - astronautTwitterButton.setVisibility(View.GONE); + binding.astronautTwitterButton.setVisibility(View.GONE); } if (astronaut.getTwitter() == null & astronaut.getInstagram() == null & astronaut.getWiki() != null) { - astronautWikiButtonSolo.setVisibility(View.VISIBLE); - astronautWikiButton.setVisibility(View.GONE); - astronautWikiButtonSolo.setOnClickListener(v -> { + binding.astronautWikiButtonSolo.setVisibility(View.VISIBLE); + binding.astronautWikiButton.setVisibility(View.GONE); + binding.astronautWikiButtonSolo.setOnClickListener(v -> { openCustomTab(context, astronaut.getWiki()); }); } else if (astronaut.getWiki() != null) { - astronautWikiButton.setVisibility(View.VISIBLE); - astronautWikiButton.setOnClickListener(v -> { + binding.astronautWikiButton.setVisibility(View.VISIBLE); + binding.astronautWikiButton.setOnClickListener(v -> { openCustomTab(context, astronaut.getWiki()); }); } else { - astronautWikiButton.setVisibility(View.GONE); + binding.astronautWikiButton.setVisibility(View.GONE); } @@ -170,15 +120,15 @@ private void setAstronaut(Astronaut astronaut) { if (bornDate != null && deathDate == null) { int bornYear = astronaut.getDateOfBirth().getYear(); int currentYear = Calendar.getInstance().getTime().getYear(); - astronautBorn.setText(getString(R.string.born, bornDate, currentYear - bornYear)); - astronautDied.setVisibility(View.GONE); + binding.astronautBorn.setText(getString(R.string.born, bornDate, currentYear - bornYear)); + binding.astronautDied.setVisibility(View.GONE); } if (deathDate != null && bornDate != null) { int bornYear = astronaut.getDateOfBirth().getYear(); int diedYear = astronaut.getDateOfDeath().getYear(); - astronautBorn.setText(getString(R.string.born_one_argument, bornDate)); - astronautDied.setText(getString(R.string.died_two_arguments, deathDate, diedYear - bornYear)); - astronautDied.setVisibility(View.VISIBLE); + binding.astronautBorn.setText(getString(R.string.born_one_argument, bornDate)); + binding.astronautDied.setText(getString(R.string.died_two_arguments, deathDate, diedYear - bornYear)); + binding.astronautDied.setVisibility(View.VISIBLE); } } @@ -186,42 +136,43 @@ private void setAgency(Agency agency) { try { Timber.v("Setting up views..."); if (agency != null) { - lspCard.setVisibility(View.VISIBLE); + binding.lspAgency.setOnClickListener(view -> launchesClicked()); + binding.lspCard.setVisibility(View.VISIBLE); - lspAgency.setText(String.format(this.getString(me.calebjones.spacelaunchnow.common.R.string.view_rocket_launches), agency.getName())); + binding.lspAgency.setText(String.format(this.getString(me.calebjones.spacelaunchnow.common.R.string.view_rocket_launches), agency.getName())); if (agency.getLogoUrl() != null) { - lspLogo.setVisibility(View.VISIBLE); + binding.lspLogo.setVisibility(View.VISIBLE); GlideApp.with(context) .load(agency.getLogoUrl()) .centerInside() - .into(lspLogo); + .into(binding.lspLogo); } else { - lspLogo.setVisibility(View.GONE); + binding.lspLogo.setVisibility(View.GONE); } - lspName.setText(agency.getName()); - lspType.setText(agency.getType()); + binding.lspName.setText(agency.getName()); + binding.lspType.setText(agency.getType()); if (agency.getAdministrator() != null) { - lspAdministrator.setText(String.format("%s", agency.getAdministrator())); + binding.lspAdministrator.setText(String.format("%s", agency.getAdministrator())); } else { - lspAdministrator.setText(me.calebjones.spacelaunchnow.common.R.string.unknown_administrator); + binding.lspAdministrator.setText(me.calebjones.spacelaunchnow.common.R.string.unknown_administrator); } if (agency.getFoundingYear() != null) { - lspFoundedYear.setText(String.format(getString(me.calebjones.spacelaunchnow.common.R.string.founded_in), agency.getFoundingYear())); + binding.lspFoundedYear.setText(String.format(getString(me.calebjones.spacelaunchnow.common.R.string.founded_in), agency.getFoundingYear())); } else { - lspFoundedYear.setText(me.calebjones.spacelaunchnow.common.R.string.unknown_year); + binding.lspFoundedYear.setText(me.calebjones.spacelaunchnow.common.R.string.unknown_year); } - lspSummary.setText(agency.getDescription()); + binding.lspSummary.setText(agency.getDescription()); if (agency.getInfoUrl() == null) { - lspInfoButtonOne.setVisibility(View.GONE); + binding.lspInfoButtonOne.setVisibility(View.GONE); } if (agency.getWikiUrl() == null) { - lspWikiButtonOne.setVisibility(View.GONE); + binding.lspWikiButtonOne.setVisibility(View.GONE); } - lspAgency.setVisibility(View.VISIBLE); + binding.lspAgency.setVisibility(View.VISIBLE); } else { - lspCard.setVisibility(View.GONE); + binding.lspCard.setVisibility(View.GONE); } } catch (NullPointerException e) { @@ -229,7 +180,6 @@ private void setAgency(Agency agency) { } } - @OnClick(R2.id.lsp_agency) void launchesClicked(){ try { Intent intent = new Intent(context, AgencyLaunchActivity.class); diff --git a/astronauts/src/main/java/me/calebjones/spacelaunchnow/astronauts/list/AstronautListFragment.java b/astronauts/src/main/java/me/calebjones/spacelaunchnow/astronauts/list/AstronautListFragment.java index b22f44836..99d1f0547 100644 --- a/astronauts/src/main/java/me/calebjones/spacelaunchnow/astronauts/list/AstronautListFragment.java +++ b/astronauts/src/main/java/me/calebjones/spacelaunchnow/astronauts/list/AstronautListFragment.java @@ -5,7 +5,6 @@ import androidx.annotation.Nullable; import androidx.appcompat.widget.SearchView; -import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.view.MenuItemCompat; import androidx.lifecycle.Lifecycle; import androidx.recyclerview.widget.LinearLayoutManager; @@ -17,31 +16,24 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; import com.afollestad.materialdialogs.MaterialDialog; -import com.google.android.material.floatingactionbutton.FloatingActionButton; import java.util.ArrayList; import java.util.List; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import butterknife.Unbinder; -import cz.kinst.jakub.view.SimpleStatefulLayout; + import io.realm.RealmResults; import me.calebjones.spacelaunchnow.astronauts.data.Callbacks; import me.calebjones.spacelaunchnow.common.base.BaseFragment; import me.calebjones.spacelaunchnow.common.utils.EndlessRecyclerViewScrollListener; import me.calebjones.spacelaunchnow.common.utils.SimpleDividerItemDecoration; -import me.calebjones.spacelaunchnow.common.utils.Utils; import me.calebjones.spacelaunchnow.data.models.main.Agency; import me.calebjones.spacelaunchnow.data.models.main.astronaut.Astronaut; import me.spacelaunchnow.astronauts.R; -import me.spacelaunchnow.astronauts.R2; import me.calebjones.spacelaunchnow.astronauts.data.AstronautDataRepository; +import me.spacelaunchnow.astronauts.databinding.FragmentAstronautListBinding; import timber.log.Timber; /** @@ -59,7 +51,6 @@ public class AstronautListFragment extends BaseFragment implements SwipeRefreshL private boolean canLoadMore; private boolean statefulStateContentShow = false; private boolean firstLaunch = true; - private Unbinder unbinder; private AstronautRecyclerViewAdapter adapter; private EndlessRecyclerViewScrollListener scrollListener; private LinearLayoutManager linearLayoutManager; @@ -67,17 +58,8 @@ public class AstronautListFragment extends BaseFragment implements SwipeRefreshL private Integer[] statusIDsSelection; private boolean limitReached; private SearchView searchView; + private FragmentAstronautListBinding binding; - @BindView(R2.id.astronaut_recycler_view) - RecyclerView recyclerView; - @BindView(R2.id.astronaut_stateful_view) - SimpleStatefulLayout statefulView; - @BindView(R2.id.astronaut_coordinator) - CoordinatorLayout coordinatorLayout; - @BindView(R2.id.astronaut_refresh_layout) - SwipeRefreshLayout swipeRefreshLayout; - @BindView(R2.id.astronaut_filter) - FloatingActionButton floatingActionButton; /** * Mandatory empty constructor for the fragment manager to instantiate the @@ -101,25 +83,26 @@ public void onCreate(Bundle savedInstanceState) { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_astronaut_list, container, false); - unbinder = ButterKnife.bind(this, view); + binding = FragmentAstronautListBinding.inflate(inflater, container, false); + View view = binding.getRoot(); + setHasOptionsMenu(true); // Set the adapter Context context = view.getContext(); adapter = new AstronautRecyclerViewAdapter(context); linearLayoutManager = new LinearLayoutManager(context, RecyclerView.VERTICAL, false); - recyclerView.setLayoutManager(linearLayoutManager); - recyclerView.setAdapter(adapter); + binding.astronautRecyclerView.setLayoutManager(linearLayoutManager); + binding.astronautRecyclerView.setAdapter(adapter); if(firstLaunch) { - statefulView.showProgress(); + binding.astronautStatefulView.showProgress(); } else { - statefulView.showContent(); + binding.astronautStatefulView.showContent(); } canLoadMore = true; limitReached = false; - statefulView.setOfflineRetryOnClickListener(v -> onRefresh()); + binding.astronautStatefulView.setOfflineRetryOnClickListener(v -> onRefresh()); scrollListener = new EndlessRecyclerViewScrollListener(linearLayoutManager) { @Override public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { @@ -134,11 +117,12 @@ public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { } } }; - recyclerView.addItemDecoration(new SimpleDividerItemDecoration(context)); - recyclerView.addOnScrollListener(scrollListener); + binding.astronautRecyclerView.addItemDecoration(new SimpleDividerItemDecoration(context)); + binding.astronautRecyclerView.addOnScrollListener(scrollListener); fetchData(false, firstLaunch, false); firstLaunch = false; - swipeRefreshLayout.setOnRefreshListener(this); + binding.astronautRefreshLayout.setOnRefreshListener(this); + binding.astronautFilter.setOnClickListener(view1 -> filterClicked()); return view; } @@ -181,7 +165,7 @@ public void onNetworkStateChanged(boolean refreshing) { @Override public void onError(String message, @Nullable Throwable throwable) { if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) { - statefulView.showOffline(); + binding.astronautStatefulView.showOffline(); statefulStateContentShow = false; if (throwable != null) { Timber.e(throwable); @@ -226,19 +210,19 @@ public boolean onOptionsItemSelected(MenuItem item) { } private void showNetworkLoading(boolean refreshing) { - swipeRefreshLayout.setRefreshing(refreshing); + binding.astronautRefreshLayout.setRefreshing(refreshing); } private void updateAdapter(List astronauts) { if (astronauts.size() > 0) { if (!statefulStateContentShow) { - statefulView.showContent(); + binding.astronautStatefulView.showContent(); statefulStateContentShow = true; } adapter.addItems(astronauts); } else { - statefulView.showEmpty(); + binding.astronautStatefulView.showEmpty(); statefulStateContentShow = false; if (adapter != null) { adapter.clear(); @@ -259,7 +243,7 @@ public void onRefresh() { if (searchTerm != null || statusIDs != null) { statusIDs = null; searchTerm = null; - swipeRefreshLayout.setRefreshing(false); + binding.astronautRefreshLayout.setRefreshing(false); fetchData(false, false, false); } else { fetchData(true, false, false); @@ -286,7 +270,7 @@ public boolean onClose() { return false; } - @OnClick(R2.id.astronaut_filter) +// @OnClick(R2.id.astronaut_filter) void filterClicked(){ new MaterialDialog.Builder(getContext()) .title("Astronaut Status") diff --git a/astronauts/src/main/java/me/calebjones/spacelaunchnow/astronauts/list/AstronautRecyclerViewAdapter.java b/astronauts/src/main/java/me/calebjones/spacelaunchnow/astronauts/list/AstronautRecyclerViewAdapter.java index e4dea7f42..c3fa005f8 100644 --- a/astronauts/src/main/java/me/calebjones/spacelaunchnow/astronauts/list/AstronautRecyclerViewAdapter.java +++ b/astronauts/src/main/java/me/calebjones/spacelaunchnow/astronauts/list/AstronautRecyclerViewAdapter.java @@ -5,22 +5,16 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; - import java.util.ArrayList; import java.util.List; -import androidx.constraintlayout.widget.ConstraintLayout; import androidx.recyclerview.widget.RecyclerView; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; + import me.calebjones.spacelaunchnow.common.GlideApp; import me.calebjones.spacelaunchnow.data.models.main.astronaut.Astronaut; import me.spacelaunchnow.astronauts.R; -import me.spacelaunchnow.astronauts.R2; import me.calebjones.spacelaunchnow.astronauts.detail.AstronautDetailsActivity; +import me.spacelaunchnow.astronauts.databinding.AstronautItemBinding; public class AstronautRecyclerViewAdapter extends RecyclerView.Adapter { @@ -54,20 +48,20 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { @Override public void onBindViewHolder(final ViewHolder holder, int position) { holder.mItem = astronauts.get(position); - holder.astronautName.setText(holder.mItem.getName()); - holder.astronautStatus.setText(holder.mItem.getStatus().getName()); + holder.bindings.astronautName.setText(holder.mItem.getName()); + holder.bindings.astronautStatus.setText(holder.mItem.getStatus().getName()); String abbrev = ""; if (holder.mItem.getAgency() != null && holder.mItem.getAgency().getAbbrev() != null){ abbrev = holder.mItem.getAgency().getAbbrev(); } - holder.astronautNationality.setText(String.format("%s (%s)", + holder.bindings.astronautNationality.setText(String.format("%s (%s)", holder.mItem.getNationality(), abbrev)); GlideApp.with(context) .load(holder.mItem.getProfileImageThumbnail()) .placeholder(R.drawable.placeholder) .circleCrop() - .into(holder.astronautImage); + .into(holder.bindings.astronautImage); } @Override @@ -76,29 +70,19 @@ public int getItemCount() { } public class ViewHolder extends RecyclerView.ViewHolder { - @BindView(R2.id.astronaut_image) - ImageView astronautImage; - @BindView(R2.id.astronaut_name) - TextView astronautName; - @BindView(R2.id.astronaut_nationality) - TextView astronautNationality; - @BindView(R2.id.astronaut_status) - TextView astronautStatus; - @BindView(R2.id.rootview) - ConstraintLayout rootview; public Astronaut mItem; + private AstronautItemBinding bindings; public ViewHolder(View view) { super(view); - ButterKnife.bind(this, view); + bindings = AstronautItemBinding.bind(view); + bindings.rootview.setOnClickListener(view1 -> { + Astronaut astronaut = astronauts.get(getAdapterPosition()); + Intent exploreIntent = new Intent(context, AstronautDetailsActivity.class); + exploreIntent.putExtra("astronautId", astronaut.getId()); + context.startActivity(exploreIntent); + }); } - @OnClick(R2.id.rootview) - void onClick(View v){ - Astronaut astronaut = astronauts.get(getAdapterPosition()); - Intent exploreIntent = new Intent(context, AstronautDetailsActivity.class); - exploreIntent.putExtra("astronautId", astronaut.getId()); - context.startActivity(exploreIntent); - } } } diff --git a/astronauts/src/main/res/layout-w500dp/astronaut_flight_fragment.xml b/astronauts/src/main/res/layout-w500dp/astronaut_flight_fragment.xml index 712aef748..8137412e2 100644 --- a/astronauts/src/main/res/layout-w500dp/astronaut_flight_fragment.xml +++ b/astronauts/src/main/res/layout-w500dp/astronaut_flight_fragment.xml @@ -1,9 +1,10 @@ - @@ -11,11 +12,10 @@ android:layout_width="@dimen/max_width" android:layout_height="match_parent" android:layout_gravity="center" - app:cardElevation="8dp" - app:cardCornerRadius="0dp"> + app:cardCornerRadius="0dp" + app:cardElevation="8dp"> - diff --git a/astronauts/src/main/res/layout-w500dp/astronaut_profile_fragment.xml b/astronauts/src/main/res/layout-w500dp/astronaut_profile_fragment.xml index 8c2be3734..b57ca04a5 100644 --- a/astronauts/src/main/res/layout-w500dp/astronaut_profile_fragment.xml +++ b/astronauts/src/main/res/layout-w500dp/astronaut_profile_fragment.xml @@ -253,7 +253,6 @@ android:paddingStart="32dp" android:layout_marginStart="32dp" android:layout_marginEnd="32dp" - tools:src="@drawable/ic_splash" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/lsp_type" /> diff --git a/astronauts/src/main/res/layout/astronaut_flight_fragment.xml b/astronauts/src/main/res/layout/astronaut_flight_fragment.xml index 567681f16..40a8d62fb 100644 --- a/astronauts/src/main/res/layout/astronaut_flight_fragment.xml +++ b/astronauts/src/main/res/layout/astronaut_flight_fragment.xml @@ -1,8 +1,14 @@ - \ No newline at end of file + tools:context="me.calebjones.spacelaunchnow.astronauts.detail.AstronautProfileFragment"> + + + \ No newline at end of file diff --git a/astronauts/src/main/res/layout/astronaut_profile_fragment.xml b/astronauts/src/main/res/layout/astronaut_profile_fragment.xml index a93f39db9..0ea243dcf 100644 --- a/astronauts/src/main/res/layout/astronaut_profile_fragment.xml +++ b/astronauts/src/main/res/layout/astronaut_profile_fragment.xml @@ -250,7 +250,6 @@ android:paddingStart="32dp" android:layout_marginStart="32dp" android:layout_marginEnd="32dp" - tools:src="@drawable/ic_splash" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/lsp_type" /> diff --git a/build.gradle b/build.gradle index 3125d5ff1..93a5295a1 100644 --- a/build.gradle +++ b/build.gradle @@ -16,10 +16,9 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:4.1.2' + classpath plugs.gradle classpath plugs.playPublisher classpath plugs.realm - classpath plugs.butterknife classpath plugs.advancedBuildVersion classpath plugs.gradleBintrayPlugin classpath plugs.androidMavenGradle diff --git a/common/build.gradle b/common/build.gradle index d1e650e12..229c72fa1 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -1,12 +1,13 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' apply plugin: 'realm-android' -apply plugin: 'com.jakewharton.butterknife' android { compileSdkVersion rootProject.ext.compileSdkVersion + buildFeatures { + viewBinding true + } defaultConfig { minSdkVersion rootProject.minSdkVersion targetSdkVersion rootProject.targetSdkVersion @@ -36,7 +37,6 @@ android { buildConfigField("long", "VERSION_CODE", "${defaultConfig.versionCode}") buildConfigField("String","VERSION_NAME","\"${defaultConfig.versionName}\"") - //.. } release { buildConfigField("long", "VERSION_CODE", "${defaultConfig.versionCode}") @@ -100,11 +100,7 @@ dependencies { kapt deps.glideCompiler implementation deps.glideTransformation implementation deps.timber - implementation deps.butterknife - kapt deps.butterknifeCompiler implementation deps.materialValue - implementation deps.autoValue - annotationProcessor deps.autoValueProcessor implementation deps.statefulLayout //Twitter implementation deps.twitterCore diff --git a/common/proguard-rules.pro b/common/proguard-rules.pro index 3093cb7aa..71f7d830d 100644 --- a/common/proguard-rules.pro +++ b/common/proguard-rules.pro @@ -100,20 +100,6 @@ public *; public *; } -# ButterKnife 7 - --keep class butterknife.** { *; } --dontwarn butterknife.internal.** --keep class **$$ViewBinder { *; } - --keepclasseswithmembernames class * { - @butterknife.* ; -} - --keepclasseswithmembernames class * { - @butterknife.* ; -} - # Crashlytics 2.+ -keep class com.crashlytics.** { *; } diff --git a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/adapters/ListAdapter.java b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/adapters/ListAdapter.java index fafbf051b..cd74bfd92 100644 --- a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/adapters/ListAdapter.java +++ b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/adapters/ListAdapter.java @@ -2,16 +2,12 @@ import android.content.Context; import android.content.Intent; -import android.preference.PreferenceManager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.cardview.widget.CardView; import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; @@ -19,23 +15,18 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.util.ViewPreloadSizeProvider; -import java.text.SimpleDateFormat; -import java.util.Calendar; import java.util.List; -import butterknife.BindView; -import butterknife.ButterKnife; import io.realm.RealmList; import jp.wasabeef.glide.transformations.ColorFilterTransformation; import me.calebjones.spacelaunchnow.common.GlideApp; import me.calebjones.spacelaunchnow.common.R; -import me.calebjones.spacelaunchnow.common.R2; import me.calebjones.spacelaunchnow.common.content.LaunchStatusUtil; -import me.calebjones.spacelaunchnow.common.prefs.ListPreferences; +import me.calebjones.spacelaunchnow.common.databinding.LaunchListItemBinding; import me.calebjones.spacelaunchnow.common.ui.launchdetail.activity.LaunchDetailActivity; import me.calebjones.spacelaunchnow.common.utils.Utils; import me.calebjones.spacelaunchnow.data.models.main.LaunchList; -import timber.log.Timber; + /** * This adapter takes data from ListPreferences/LoaderService and applies it to RecyclerView @@ -46,6 +37,7 @@ public class ListAdapter extends RecyclerView.Adapter { private Context mContext; private final ListPreloader.PreloadSizeProvider sizeProvider = new ViewPreloadSizeProvider(); private int color; + private LaunchListItemBinding binding; public ListAdapter(Context context, boolean night) { launchList = new RealmList<>(); @@ -74,9 +66,8 @@ public void clear() { @Override public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { - Timber.v("onCreate ViewHolder."); - View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.launch_list_item, viewGroup, false); - return new ViewHolder(v); + binding = LaunchListItemBinding.inflate(LayoutInflater.from(viewGroup.getContext()), viewGroup, false); + return new ViewHolder(binding); } @@ -97,7 +88,7 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder rHolder, int i) { .load(launchItem.getImage()) .diskCacheStrategy(DiskCacheStrategy.ALL) .circleCrop() - .into(holder.categoryIcon); + .into(holder.binding.categoryIcon); } else { if (launchItem.getMission() != null) { @@ -106,7 +97,7 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder rHolder, int i) { .diskCacheStrategy(DiskCacheStrategy.ALL) .circleCrop() .transform(new ColorFilterTransformation(color)) - .into(holder.categoryIcon); + .into(holder.binding.categoryIcon); } else { GlideApp.with(mContext) @@ -114,61 +105,61 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder rHolder, int i) { .diskCacheStrategy(DiskCacheStrategy.ALL) .circleCrop() .transform(new ColorFilterTransformation(color)) - .into(holder.categoryIcon); + .into(holder.binding.categoryIcon); } } // holder.launch_date.setText(Utils.getStatusBasedDateFormat(launchItem.getNet(), launchItem.getStatus())); - holder.launch_date.setText(Utils.getSimpleDateFormatForUIWithPrecision(launchItem.getNetPrecision()).format(launchItem.getNet())); + holder.binding.launchDate.setText(Utils.getSimpleDateFormatForUIWithPrecision(launchItem.getNetPrecision()).format(launchItem.getNet())); //If pad and agency exist add it to location, otherwise get whats always available if (launchItem.getLocation() != null) { - holder.location.setText(launchItem.getLocation()); + holder.binding.location.setText(launchItem.getLocation()); } else { - holder.location.setText(mContext.getString(R.string.click_for_info)); + holder.binding.location.setText(mContext.getString(R.string.click_for_info)); } if (launchItem.getName() != null) { title = launchItem.getName().split("\\|"); try { if (title.length > 0) { - holder.title.setText(title[1].trim()); - holder.mission.setText(title[0].trim()); + holder.binding.launchRocket.setText(title[1].trim()); + holder.binding.mission.setText(title[0].trim()); } else { - holder.title.setText(launchItem.getName()); + holder.binding.launchRocket.setText(launchItem.getName()); if (launchItem.getMission() != null) { - holder.title.setText(launchItem.getMission()); + holder.binding.launchRocket.setText(launchItem.getMission()); } } } catch (ArrayIndexOutOfBoundsException exception) { - holder.title.setText(launchItem.getName()); + holder.binding.launchRocket.setText(launchItem.getName()); if (launchItem.getMission() != null) { - holder.title.setText(launchItem.getMission()); + holder.binding.launchRocket.setText(launchItem.getMission()); } } } if (launchItem.getLanding() != null) { - holder.landingCard.setVisibility(View.VISIBLE); - holder.landingLocation.setText(launchItem.getLanding()); - holder.landingCard.setCardBackgroundColor(LaunchStatusUtil.getLandingStatusColor(mContext, launchItem.getLandingSuccess())); + holder.binding.landingPillMini.getRoot().setVisibility(View.VISIBLE); + holder.binding.landingPillMini.landing.setText(launchItem.getLanding()); + holder.binding.landingPillMini.getRoot().setCardBackgroundColor(LaunchStatusUtil.getLandingStatusColor(mContext, launchItem.getLandingSuccess())); } else { - holder.landingCard.setVisibility(View.GONE); + holder.binding.landingPillMini.getRoot().setVisibility(View.GONE); } if (launchItem.getOrbit() != null) { - holder.orbitCard.setVisibility(View.VISIBLE); - holder.orbitName.setText(launchItem.getOrbit()); + holder.binding.launcherPillMini.getRoot().setVisibility(View.VISIBLE); + holder.binding.launcherPillMini.launcherName.setText(launchItem.getOrbit()); } else { - holder.orbitCard.setVisibility(View.GONE); + holder.binding.launcherPillMini.getRoot().setVisibility(View.GONE); } - holder.status.setText(launchItem.getStatus().getAbbrev()); - holder.status.setOnClickListener(v -> { + holder.binding.statusPillMini.status.setText(launchItem.getStatus().getAbbrev()); + holder.binding.statusPillMini.status.setOnClickListener(v -> { Toast.makeText(mContext, launchItem.getStatus().getDescription(), Toast.LENGTH_LONG).show(); }); - holder.statusCard.setCardBackgroundColor(LaunchStatusUtil.getLaunchStatusColor(mContext, launchItem.getStatus().getId())); - holder.rootView.setOnClickListener(v -> { + holder.binding.statusPillMini.getRoot().setCardBackgroundColor(LaunchStatusUtil.getLaunchStatusColor(mContext, launchItem.getStatus().getId())); + holder.binding.getRoot().setOnClickListener(v -> { Intent intent = new Intent(mContext, LaunchDetailActivity.class); intent.putExtra("TYPE", "launch"); intent.putExtra("launchID", launchItem.getId()); @@ -182,37 +173,13 @@ public int getItemCount() { } public class ViewHolder extends RecyclerView.ViewHolder { - @BindView(R2.id.status) - TextView status; - @BindView(R2.id.status_pill_mini) - CardView statusCard; - @BindView(R2.id.landing) - TextView landingLocation; - @BindView(R2.id.landing_pill_mini) - CardView landingCard; - @BindView(R2.id.launcher_name) - TextView orbitName; - @BindView(R2.id.launcher_pill_mini) - CardView orbitCard; - @BindView(R2.id.launch_rocket) - TextView title; - @BindView(R2.id.location) - TextView location; - @BindView(R2.id.launch_date) - TextView launch_date; - @BindView(R2.id.mission) - TextView mission; - @BindView(R2.id.categoryIcon) - ImageView categoryIcon; - @BindView(R2.id.rootview) - View rootView; + private LaunchListItemBinding binding; //Add content to the card - public ViewHolder(View view) { - super(view); - ButterKnife.bind(this, view); - + public ViewHolder(LaunchListItemBinding binding) { + super(binding.getRoot()); + this.binding = binding; } } diff --git a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/adapters/NewsListAdapter.java b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/adapters/NewsListAdapter.java index 14229c887..8ee5d6767 100644 --- a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/adapters/NewsListAdapter.java +++ b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/adapters/NewsListAdapter.java @@ -6,20 +6,14 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; - import androidx.recyclerview.widget.RecyclerView; import java.util.List; -import butterknife.BindView; -import butterknife.ButterKnife; import io.realm.RealmList; import me.calebjones.spacelaunchnow.common.GlideApp; import me.calebjones.spacelaunchnow.common.R; -import me.calebjones.spacelaunchnow.common.R2; -import me.calebjones.spacelaunchnow.common.utils.Utils; +import me.calebjones.spacelaunchnow.common.databinding.NewsListItemBinding; import me.calebjones.spacelaunchnow.data.models.main.news.NewsItem; import timber.log.Timber; @@ -30,6 +24,7 @@ public class NewsListAdapter extends RecyclerView.Adapter newsList; private Context mContext; + private NewsListItemBinding binding; public NewsListAdapter(Context context) { newsList = new RealmList<>(); @@ -56,8 +51,8 @@ public void clear() { @Override public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { Timber.v("onCreate ViewHolder."); - View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.news_list_item, viewGroup, false); - return new ViewHolder(v); + binding = NewsListItemBinding.inflate(LayoutInflater.from(viewGroup.getContext()), viewGroup, false); + return new ViewHolder(binding); } @Override @@ -69,10 +64,10 @@ public void onBindViewHolder(final ViewHolder holder, int i) { .placeholder(R.drawable.placeholder) .thumbnail(0.5f) .circleCrop() - .into(holder.newsIcon); + .into(holder.binding.newsIcon); } - holder.title.setText(item.getTitle()); - holder.subtitle.setText(item.getNewsSite()); + holder.binding.newsTitle.setText(item.getTitle()); + holder.binding.newsSubtitle.setText(item.getNewsSite()); } @Override @@ -81,21 +76,15 @@ public int getItemCount() { } public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { - @BindView(R2.id.news_subtitle) - TextView subtitle; - @BindView(R2.id.news_title) - TextView title; - @BindView(R2.id.news_icon) - ImageView newsIcon; - @BindView(R2.id.rootView) - View rootView; + + private NewsListItemBinding binding; //Add content to the card - public ViewHolder(View view) { - super(view); - ButterKnife.bind(this, view); - rootView.setOnClickListener(this); + public ViewHolder(NewsListItemBinding binding) { + super(binding.getRoot()); + this.binding = binding; + binding.getRoot().setOnClickListener(this); } //React to click events. diff --git a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/adapters/SpacestationAdapter.java b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/adapters/SpacestationAdapter.java index 2e3f508e2..017b82c8d 100644 --- a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/adapters/SpacestationAdapter.java +++ b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/adapters/SpacestationAdapter.java @@ -5,26 +5,18 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; -import com.bumptech.glide.ListPreloader; + import com.bumptech.glide.load.engine.DiskCacheStrategy; -import com.bumptech.glide.util.ViewPreloadSizeProvider; -import java.text.SimpleDateFormat; import java.util.List; -import androidx.constraintlayout.widget.ConstraintLayout; -import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.recyclerview.widget.RecyclerView; -import butterknife.BindView; -import butterknife.ButterKnife; + import io.realm.RealmList; -import jp.wasabeef.glide.transformations.ColorFilterTransformation; import me.calebjones.spacelaunchnow.common.GlideApp; import me.calebjones.spacelaunchnow.common.R; -import me.calebjones.spacelaunchnow.common.R2; +import me.calebjones.spacelaunchnow.common.databinding.SpacestationListItemBinding; import me.calebjones.spacelaunchnow.data.models.main.spacestation.Spacestation; import timber.log.Timber; @@ -35,6 +27,7 @@ public class SpacestationAdapter extends RecyclerView.Adapter spacestations; private Context mContext; + private SpacestationListItemBinding binding; public SpacestationAdapter(Context context) { spacestations = new RealmList<>(); @@ -60,8 +53,9 @@ public void clear() { @Override public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { Timber.v("onCreate ViewHolder."); - View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.spacestation_list_item, viewGroup, false); - return new ViewHolder(v); + binding = SpacestationListItemBinding.inflate(LayoutInflater.from(viewGroup.getContext()), viewGroup, false); + + return new ViewHolder(binding); } @Override @@ -73,18 +67,18 @@ public void onBindViewHolder(final ViewHolder holder, int i) { .load(item.getImageUrl()) .diskCacheStrategy(DiskCacheStrategy.ALL) .circleCrop() - .into(holder.spacestationIcon); + .into(holder.binding.spacestationIcon); } else { GlideApp.with(mContext) .load(R.drawable.ic_satellite) .diskCacheStrategy(DiskCacheStrategy.ALL) .circleCrop() - .into(holder.spacestationIcon); + .into(holder.binding.spacestationIcon); } - holder.spacestationName.setText(item.getName()); - holder.spacestationLocation.setText(item.getOrbit()); - holder.spacestationStatus.setText(item.getStatus().getName()); + holder.binding.spacestationName.setText(item.getName()); + holder.binding.spacestationLocation.setText(item.getOrbit()); + holder.binding.spacestationStatus.setText(item.getStatus().getName()); } @Override @@ -93,22 +87,13 @@ public int getItemCount() { } public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { - @BindView(R2.id.spacestation_icon) - ImageView spacestationIcon; - @BindView(R2.id.spacestation_name) - TextView spacestationName; - @BindView(R2.id.spacestation_status) - TextView spacestationStatus; - @BindView(R2.id.spacestation_location) - TextView spacestationLocation; - @BindView(R2.id.rootview) - ConstraintLayout rootview; + private SpacestationListItemBinding binding; //Add content to the card - public ViewHolder(View view) { - super(view); - ButterKnife.bind(this, view); - rootview.setOnClickListener(this); + public ViewHolder(SpacestationListItemBinding binding) { + super(binding.getRoot()); + this.binding = binding; + binding.getRoot().setOnClickListener(this); } //React to click events. diff --git a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/activity/LaunchDetailActivity.java b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/activity/LaunchDetailActivity.java index 337f643e1..e9c8b882e 100644 --- a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/activity/LaunchDetailActivity.java +++ b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/activity/LaunchDetailActivity.java @@ -13,26 +13,18 @@ import android.os.Bundle; import android.preference.PreferenceManager; -import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.app.ShareCompat; import androidx.core.content.ContextCompat; -import androidx.appcompat.widget.Toolbar; import android.view.MenuItem; import android.view.View; -import android.widget.ImageView; -import android.widget.TextView; import android.widget.Toast; import com.afollestad.materialdialogs.MaterialDialog; import com.airbnb.deeplinkdispatch.DeepLink; import com.google.android.gms.ads.AdListener; import com.google.android.gms.ads.AdRequest; -import com.google.android.gms.ads.AdView; import com.google.android.material.appbar.AppBarLayout; -import com.google.android.material.floatingactionbutton.FloatingActionButton; -import com.google.android.material.tabs.TabLayout; - import java.util.Date; import java.util.Scanner; import java.util.concurrent.TimeUnit; @@ -40,18 +32,13 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import androidx.viewpager.widget.ViewPager; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import cz.kinst.jakub.view.SimpleStatefulLayout; -import de.hdodenhof.circleimageview.CircleImageView; import io.realm.Realm; import jonathanfinerty.once.Amount; import jonathanfinerty.once.Once; import me.calebjones.spacelaunchnow.common.R; -import me.calebjones.spacelaunchnow.common.R2; import me.calebjones.spacelaunchnow.common.base.BaseActivity; import me.calebjones.spacelaunchnow.common.customtab.CustomTabActivityHelper; +import me.calebjones.spacelaunchnow.common.databinding.ActivityLaunchDetailBinding; import me.calebjones.spacelaunchnow.common.ui.generate.Rate; import me.calebjones.spacelaunchnow.common.ui.launchdetail.data.Callbacks; import me.calebjones.spacelaunchnow.common.ui.launchdetail.data.DetailsDataRepository; @@ -73,32 +60,32 @@ public class LaunchDetailActivity extends BaseActivity implements AppBarLayout.OnOffsetChangedListener, SwipeRefreshLayout.OnRefreshListener { - @BindView(R2.id.fab_share) - FloatingActionButton fabShare; - @BindView(R2.id.stateful_view) - SimpleStatefulLayout statefulView; - @BindView(R2.id.adView) - AdView adView; - @BindView(R2.id.detail_profile_image) - CircleImageView detail_profile_image; - @BindView(R2.id.detail_title) - TextView detail_rocket; - @BindView(R2.id.detail_mission_location) - TextView detail_mission_location; - @BindView(R2.id.detail_viewpager) - ViewPager viewPager; - @BindView(R2.id.rootview) - CoordinatorLayout coordinatorLayout; - @BindView(R2.id.detail_swipe_refresh) - SwipeRefreshLayout detailSwipeRefresh; - @BindView(R2.id.detail_tabs) - TabLayout tabLayout; - @BindView(R2.id.detail_profile_backdrop) - ImageView detail_profile_backdrop; - @BindView(R2.id.detail_appbar) - AppBarLayout appBarLayout; - @BindView(R2.id.detail_toolbar) - Toolbar toolbar; +// @BindView(R2.id.fab_share) +// FloatingActionButton fabShare; +// @BindView(R2.id.stateful_view) +// SimpleStatefulLayout statefulView; +// @BindView(R2.id.adView) +// AdView adView; +// @BindView(R2.id.detail_profile_image) +// CircleImageView detail_profile_image; +// @BindView(R2.id.detail_title) +// TextView detail_rocket; +// @BindView(R2.id.detail_mission_location) +// TextView detail_mission_location; +// @BindView(R2.id.detail_viewpager) +// ViewPager viewPager; +// @BindView(R2.id.rootview) +// CoordinatorLayout coordinatorLayout; +// @BindView(R2.id.detail_swipe_refresh) +// SwipeRefreshLayout detailSwipeRefresh; +// @BindView(R2.id.detail_tabs) +// TabLayout tabLayout; +// @BindView(R2.id.detail_profile_backdrop) +// ImageView detail_profile_backdrop; +// @BindView(R2.id.detail_appbar) +// AppBarLayout appBarLayout; +// @BindView(R2.id.detail_toolbar) +// Toolbar toolbar; private static final int PERCENTAGE_TO_ANIMATE_AVATAR = 20; private boolean mIsAvatarShown = true; @@ -122,12 +109,17 @@ public class LaunchDetailActivity extends BaseActivity private Boolean fromNotification = false; private Boolean fromLink = false; private static final String ACTION_DEEP_LINK = "deep_link"; + private ActivityLaunchDetailBinding binding; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + binding = ActivityLaunchDetailBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); + setContentView(view); + realm = getRealm(); sharedPref = PreferenceManager.getDefaultSharedPreferences(this); context = getApplicationContext(); @@ -135,8 +127,6 @@ public void onCreate(Bundle savedInstanceState) { sharedPreference = ListPreferences.getInstance(context); detailsDataRepository = new DetailsDataRepository(context, getRealm()); -// statusColor = getCyanea().getPrimaryDark(); - if (getSharedPreferences("theme_changed", 0).getBoolean("recreate", false)) { SharedPreferences.Editor editor = getSharedPreferences("theme_changed", 0).edit(); editor.putBoolean("recreate", false); @@ -144,51 +134,48 @@ public void onCreate(Bundle savedInstanceState) { recreate(); } - setContentView(R.layout.activity_launch_detail); - ButterKnife.bind(this); model = ViewModelProviders.of(this).get(DetailsViewModel.class); // update UI model.getLaunch().observe(this, this::updateViews); - - detailSwipeRefresh.setOnRefreshListener(this); - fabShare.hide(); - statefulView.showProgress(); - statefulView.setOfflineRetryOnClickListener(v -> fetchDataFromNetwork(launchId)); + binding.detailSwipeRefresh.setOnRefreshListener(this); + binding.fabShare.hide(); + binding.statefulView.showProgress(); + binding.statefulView.setOfflineRetryOnClickListener(v -> fetchDataFromNetwork(launchId)); rate = new Rate.Builder(context) .setTriggerCount(10) .setMinimumInstallTime(TimeUnit.DAYS.toMillis(3)) .setMessage(R.string.please_rate_short) - .setFeedbackAction(() -> showFeedback()) - .setSnackBarParent(coordinatorLayout) + .setFeedbackAction(this::showFeedback) + .setSnackBarParent(binding.rootview) .build(); rate.showRequest(); if (!SupporterHelper.isSupporter() && Once.beenDone("appOpen", Amount.moreThan(3))) { AdRequest adRequest = new AdRequest.Builder().build(); - adView.loadAd(adRequest); - adView.setAdListener(new AdListener() { + binding.adView.loadAd(adRequest); + binding.adView.setAdListener(new AdListener() { @Override public void onAdLoaded() { - adView.setVisibility(View.VISIBLE); + binding.adView.setVisibility(View.VISIBLE); } }); } else { - adView.setVisibility(View.GONE); + binding.adView.setVisibility(View.GONE); } - appBarLayout.addOnOffsetChangedListener(new CustomOnOffsetChangedListener(statusColor, getWindow())); - appBarLayout.addOnOffsetChangedListener(this); - mMaxScrollSize = appBarLayout.getTotalScrollRange(); + binding.detailAppbar.addOnOffsetChangedListener(new CustomOnOffsetChangedListener(statusColor, getWindow())); + binding.detailAppbar.addOnOffsetChangedListener(this); + mMaxScrollSize = binding.detailAppbar.getTotalScrollRange(); tabAdapter = new TabsAdapter(this); - viewPager.setAdapter(tabAdapter); - viewPager.setOffscreenPageLimit(3); - viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { + binding.detailViewpager.setAdapter(tabAdapter); + binding.detailViewpager.setOffscreenPageLimit(3); + binding.detailViewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float v, int i1) { } @@ -203,7 +190,7 @@ public void onPageScrollStateChanged(int state) { } }); - tabLayout.setupWithViewPager(viewPager); + binding.detailTabs.setupWithViewPager(binding.detailViewpager); //Grab information from Intent Intent mIntent = getIntent(); @@ -227,20 +214,17 @@ public void onPageScrollStateChanged(int state) { } - if (toolbar != null) { - setSupportActionBar(toolbar); - if (getSupportActionBar() != null) { - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setHomeButtonEnabled(true); - getSupportActionBar().setDisplayShowTitleEnabled(false); - } + setSupportActionBar(binding.detailToolbar); + if (getSupportActionBar() != null) { + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setHomeButtonEnabled(true); + getSupportActionBar().setDisplayShowTitleEnabled(false); } + binding.fabShare.setOnClickListener(v -> onViewClicked()); } private void enableDisableSwipeRefresh(boolean enable) { - if (detailSwipeRefresh != null) { - detailSwipeRefresh.setEnabled(enable); - } + binding.detailSwipeRefresh.setEnabled(enable); } private void fetchDataFromNetworkBySlug(String launchId) { @@ -260,10 +244,10 @@ public void onError(String message, @Nullable Throwable throwable) { if (throwable != null) { Timber.e(throwable); - SnackbarHandler.showErrorSnackbar(context, coordinatorLayout, String.format("Error: %s", throwable.getLocalizedMessage())); + SnackbarHandler.showErrorSnackbar(context, binding.rootview, String.format("Error: %s", throwable.getLocalizedMessage())); } else { Timber.e(message); - SnackbarHandler.showErrorSnackbar(context, coordinatorLayout, message); + SnackbarHandler.showErrorSnackbar(context, binding.rootview, message); } if (fromLink) { Toast.makeText(context, message, Toast.LENGTH_LONG).show(); @@ -275,7 +259,7 @@ public void onError(String message, @Nullable Throwable throwable) { @Override public void onLaunchDeleted() { - SnackbarHandler.showErrorSnackbar(context, coordinatorLayout, "Error: Launch not found."); + SnackbarHandler.showErrorSnackbar(context, binding.rootview, "Error: Launch not found."); } }); } @@ -296,17 +280,17 @@ public void onNetworkStateChanged(boolean refreshing) { public void onError(String message, @Nullable Throwable throwable) { if (throwable != null) { Timber.e(throwable); - SnackbarHandler.showErrorSnackbar(context, coordinatorLayout, String.format("Error: %s", throwable.getLocalizedMessage())); + SnackbarHandler.showErrorSnackbar(context, binding.rootview, String.format("Error: %s", throwable.getLocalizedMessage())); } else { Timber.e(message); - SnackbarHandler.showErrorSnackbar(context, coordinatorLayout, message); + SnackbarHandler.showErrorSnackbar(context, binding.rootview, message); } fetchDataFromDatabase(launchId); } @Override public void onLaunchDeleted() { - SnackbarHandler.showErrorSnackbar(context, coordinatorLayout, "Error: Launch not found."); + SnackbarHandler.showErrorSnackbar(context, binding.rootview, "Error: Launch not found."); } }); } @@ -316,8 +300,8 @@ private void fetchDataFromDatabase(String launchId) { if (launch != null) { updateViewModel(launch); } else { - statefulView.showEmpty(); - SnackbarHandler.showErrorSnackbar(context, coordinatorLayout, "Unable to load launch."); + binding.statefulView.showEmpty(); + SnackbarHandler.showErrorSnackbar(context, binding.rootview, "Unable to load launch."); } } @@ -349,12 +333,12 @@ private void showNetworkLoading(boolean loading) { private void showLoading() { Timber.v("Show Loading..."); - detailSwipeRefresh.post(() -> detailSwipeRefresh.setRefreshing(true)); + binding.detailSwipeRefresh.post(() -> binding.detailSwipeRefresh.setRefreshing(true)); } private void hideLoading() { Timber.v("Hide Loading..."); - detailSwipeRefresh.post(() -> detailSwipeRefresh.setRefreshing(false)); + binding.detailSwipeRefresh.post(() -> binding.detailSwipeRefresh.setRefreshing(false)); } private void showFeedback() { @@ -403,10 +387,10 @@ private void updateViews(Launch launch) { fabShowable = true; this.launch = launch; setTitleView(launch); - fabShare.show(); - statefulView.showContent(); + binding.fabShare.show(); + binding.statefulView.showContent(); } else { - statefulView.showEmpty(); + binding.statefulView.showEmpty(); } } @@ -415,26 +399,26 @@ private void setTitleView(Launch launch) { Timber.v("Loading detailLaunch %s", launch.getId()); findProfileLogo(launch); findRocketImage(launch); - detail_mission_location.setText(launch.getPad().getName()); - detail_rocket.setText(launch.getName()); + binding.detailMissionLocation.setText(launch.getPad().getName()); + binding.detailTitle.setText(launch.getName()); } else if (this.isDestroyed()) { Timber.v("DetailLaunch is destroyed, stopping loading data."); } } private void findRocketImage(Launch launch) { - if (launch.getImgUrl() != null && launch.getImgUrl().length() > 0) { + if (launch.getImgUrl() != null && !launch.getImgUrl().isEmpty()) { GlideApp.with(this) .load(launch.getImgUrl()) - .into(detail_profile_backdrop); + .into(binding.detailProfileBackdrop); } else if (launch.getRocket().getConfiguration().getName() != null) { if (launch.getRocket().getConfiguration().getImageUrl() != null - && launch.getRocket().getConfiguration().getImageUrl().length() > 0 + && !launch.getRocket().getConfiguration().getImageUrl().isEmpty() && !launch.getRocket().getConfiguration().getImageUrl().contains("placeholder")) { final String image = launch.getRocket().getConfiguration().getImageUrl(); GlideApp.with(this) .load(image) - .into(detail_profile_backdrop); + .into(binding.detailProfileBackdrop); } } } @@ -484,7 +468,7 @@ private void applyProfileLogo(String url) { .load(url) .placeholder(R.drawable.icon_international) .error(R.drawable.icon_international) - .into(detail_profile_image); + .into(binding.detailProfileImage); } @Override @@ -515,22 +499,22 @@ public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { if (percentage >= PERCENTAGE_TO_ANIMATE_AVATAR && mIsAvatarShown) { mIsAvatarShown = false; - detail_profile_image.animate() + binding.detailProfileImage.animate() .scaleY(0).scaleX(0) .setDuration(200) .start(); - fabShare.hide(); + binding.fabShare.hide(); } if (percentage <= PERCENTAGE_TO_ANIMATE_AVATAR && !mIsAvatarShown) { mIsAvatarShown = true; - detail_profile_image.animate() + binding.detailProfileImage.animate() .scaleY(1).scaleX(1) .start(); if (fabShowable) { - fabShare.show(); + binding.fabShare.show(); } } } @@ -557,7 +541,6 @@ public void mayLaunchUrl(Uri parse) { } } - @OnClick(R2.id.fab_share) public void onViewClicked() { String launchDate = ""; String message = ""; @@ -570,10 +553,6 @@ public void onViewClicked() { } if (launch.getPad().getLocation() != null) { - message = launch.getName() + " launching from " - + launch.getPad().getLocation().getName() + "\n\n" - + launchDate; - } else if (launch.getPad().getLocation() != null) { message = launch.getName() + " launching from " + launch.getPad().getLocation().getName() + "\n\n" + launchDate; @@ -592,7 +571,7 @@ public void onViewClicked() { .setText(launch.getSlug()) .startChooser(); } else { - SnackbarHandler.showErrorSnackbar(this, coordinatorLayout, "Error - unable to share this launch."); + SnackbarHandler.showErrorSnackbar(this, binding.rootview, "Error - unable to share this launch."); } } @@ -643,7 +622,7 @@ private void navigateHome() { fromLink = false; finish(); } catch (ClassNotFoundException e) { - e.printStackTrace(); + Timber.e(e); } } diff --git a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/fragments/AgencyDetailFragment.java b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/fragments/AgencyDetailFragment.java index 191142876..ec7594e77 100644 --- a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/fragments/AgencyDetailFragment.java +++ b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/fragments/AgencyDetailFragment.java @@ -6,30 +6,15 @@ import androidx.lifecycle.ViewModelProviders; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.os.Bundle; -import android.preference.PreferenceManager; import androidx.annotation.Nullable; -import androidx.appcompat.widget.AppCompatButton; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; -import androidx.cardview.widget.CardView; - -import org.w3c.dom.Text; - -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import butterknife.Unbinder; import me.calebjones.spacelaunchnow.common.R; -import me.calebjones.spacelaunchnow.common.R2; import me.calebjones.spacelaunchnow.common.base.BaseFragment; -import me.calebjones.spacelaunchnow.common.utils.Utils; -import me.calebjones.spacelaunchnow.common.prefs.ListPreferences; +import me.calebjones.spacelaunchnow.common.databinding.DetailLaunchAgencyBinding; import me.calebjones.spacelaunchnow.data.models.main.Agency; import me.calebjones.spacelaunchnow.data.models.main.Launch; import me.calebjones.spacelaunchnow.common.ui.launchdetail.DetailsViewModel; @@ -39,95 +24,31 @@ public class AgencyDetailFragment extends BaseFragment { - @BindView(R2.id.lsp_logo) - ImageView lspLogo; - @BindView(R2.id.lsp_name) - TextView lspName; - @BindView(R2.id.lsp_type) - TextView lspType; - @BindView(R2.id.lsp_summary) - TextView lspSummary; - @BindView(R2.id.lsp_infoButton_one) - AppCompatButton lspInfoButtonOne; - @BindView(R2.id.lsp_wikiButton_one) - AppCompatButton lspWikiButtonOne; - @BindView(R2.id.lsp_card) - CardView lspCard; - @BindView(R2.id.lsp_administrator) - TextView lspAdministrator; - @BindView(R2.id.lsp_founded_year) - TextView lspFoundedYear; - @BindView(R2.id.lsp_agency) - AppCompatButton lspAgency; - - @BindView(R2.id.launch_total_value) - TextView launchTotal; - @BindView(R2.id.consecutive_success_value) - TextView consecutiveTotal; - @BindView(R2.id.launch_success_value) - TextView successTotal; - @BindView(R2.id.launch_failure_value) - TextView failureTotal; - - @BindView(R2.id.landing_total_value) - TextView landingTotal; - @BindView(R2.id.consecutive_landing_success_value) - TextView consecutiveLandingTotal; - @BindView(R2.id.landing_success_value) - TextView landingSuccessTotal; - @BindView(R2.id.landing_failure_value) - TextView landingFailureTotal; - - - - private SharedPreferences sharedPref; - private static ListPreferences sharedPreference; private Context context; public static Launch detailLaunch; - private Unbinder unbinder; private DetailsViewModel model; + private DetailLaunchAgencyBinding binding; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setScreenName("Agency Detail Fragment"); - // retain this fragment setRetainInstance(true); } @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view; - this.sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); - this.context = getContext(); - setScreenName("LauncherAgency Detail Fragment"); - - sharedPreference = ListPreferences.getInstance(this.context); - - view = inflater.inflate(R.layout.detail_launch_agency, container, false); - - unbinder = ButterKnife.bind(this, view); - - Timber.v("Creating views..."); - return view; - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - Timber.v("onDestroyView"); - unbinder.unbind(); - } - - @Override - public void onResume() { - super.onResume(); + binding = DetailLaunchAgencyBinding.inflate(inflater, container, false); + binding.lspInfoButtonOne.setOnClickListener(view -> onLspInfoButtonOneClicked()); + binding.lspWikiButtonOne.setOnClickListener(view -> onLspWikiButtonOneClicked()); + binding.lspAgency.setOnClickListener(view -> onViewClicked()); + context = getContext(); + return binding.getRoot(); } public void setLaunch(Launch launch) { - Timber.v("Launch update received: %s", launch.getName()); detailLaunch = launch; setUpViews(launch); } @@ -137,104 +58,101 @@ private void setUpViews(Launch launch) { detailLaunch = launch; Timber.v("Setting up views..."); - lspCard.setVisibility(View.VISIBLE); + binding.lspCard.setVisibility(View.VISIBLE); - lspAgency.setText(String.format(this.getString(R.string.view_rocket_launches), launch.getLaunchServiceProvider().getName())); + binding.lspAgency.setText(String.format(this.getString(R.string.view_rocket_launches), + launch.getLaunchServiceProvider().getName())); if (detailLaunch.getLaunchServiceProvider().getLogoUrl() != null) { - lspLogo.setVisibility(View.VISIBLE); + binding.lspLogo.setVisibility(View.VISIBLE); GlideApp.with(context) .load(detailLaunch.getLaunchServiceProvider().getLogoUrl()) .centerInside() - .into(lspLogo); + .into(binding.lspLogo); } else { - lspLogo.setVisibility(View.GONE); + binding.lspLogo.setVisibility(View.GONE); } - lspName.setText(detailLaunch.getLaunchServiceProvider().getName()); - lspType.setText(detailLaunch.getLaunchServiceProvider().getType()); + binding.lspName.setText(detailLaunch.getLaunchServiceProvider().getName()); + binding.lspType.setText(detailLaunch.getLaunchServiceProvider().getType()); if (detailLaunch.getLaunchServiceProvider().getAdministrator() != null) { - lspAdministrator.setText(String.format("%s", detailLaunch.getLaunchServiceProvider().getAdministrator())); + binding.lspAdministrator.setText(String.format("%s", detailLaunch.getLaunchServiceProvider().getAdministrator())); } else { - lspAdministrator.setText(R.string.unknown_administrator); + binding.lspAdministrator.setText(R.string.unknown_administrator); } if (detailLaunch.getLaunchServiceProvider().getFoundingYear() != null) { - lspFoundedYear.setText(String.format(getString(R.string.founded_in), detailLaunch.getLaunchServiceProvider().getFoundingYear())); + binding.lspFoundedYear.setText(String.format(getString(R.string.founded_in), detailLaunch.getLaunchServiceProvider().getFoundingYear())); } else { - lspFoundedYear.setText(R.string.unknown_year); + binding.lspFoundedYear.setText(R.string.unknown_year); } - lspSummary.setText(detailLaunch.getLaunchServiceProvider().getDescription()); + binding.lspSummary.setText(detailLaunch.getLaunchServiceProvider().getDescription()); if (detailLaunch.getLaunchServiceProvider().getInfoUrl() == null) { - lspInfoButtonOne.setVisibility(View.GONE); + binding.lspInfoButtonOne.setVisibility(View.GONE); } if (detailLaunch.getLaunchServiceProvider().getWikiUrl() == null) { - lspWikiButtonOne.setVisibility(View.GONE); + binding.lspWikiButtonOne.setVisibility(View.GONE); } - lspAgency.setVisibility(View.VISIBLE); + binding.lspAgency.setVisibility(View.VISIBLE); if (detailLaunch.getLaunchServiceProvider() != null) { Agency agency = detailLaunch.getLaunchServiceProvider(); if (agency.getTotalLaunchCount() != null) { - launchTotal.setText(String.valueOf(agency.getTotalLaunchCount())); + binding.launchTotalValue.setText(String.valueOf(agency.getTotalLaunchCount())); } else { - launchTotal.setText(" - "); + binding.launchTotalValue.setText(" - "); } if (agency.getSuccessfulLaunches() != null) { - successTotal.setText(String.valueOf(agency.getSuccessfulLaunches())); + binding.launchSuccessValue.setText(String.valueOf(agency.getSuccessfulLaunches())); } else { - successTotal.setText(" - "); + binding.launchSuccessValue.setText(" - "); } if (agency.getConsecutiveSuccessfulLaunches() != null) { - consecutiveTotal.setText(String.valueOf(agency.getConsecutiveSuccessfulLaunches())); + binding.consecutiveSuccessValue.setText(String.valueOf(agency.getConsecutiveSuccessfulLaunches())); } else { - consecutiveTotal.setText(" - "); + binding.consecutiveSuccessValue.setText(" - "); } if (agency.getFailedLaunches() != null) { - failureTotal.setText(String.valueOf(agency.getFailedLaunches())); + binding.launchFailureValue.setText(String.valueOf(agency.getFailedLaunches())); } else { - failureTotal.setText(" - "); + binding.launchFailureValue.setText(" - "); } if (agency.getAttemptedLandings() != null) { - landingTotal.setText(String.valueOf(agency.getAttemptedLandings())); + binding.landingTotalValue.setText(String.valueOf(agency.getAttemptedLandings())); } else { - launchTotal.setText(" - "); + binding.landingTotalValue.setText(" - "); } if (agency.getSuccessfulLandings() != null) { - landingSuccessTotal.setText(String.valueOf(agency.getSuccessfulLandings())); + binding.landingSuccessValue.setText(String.valueOf(agency.getSuccessfulLandings())); } else { - landingSuccessTotal.setText(" - "); + binding.landingSuccessValue.setText(" - "); } if (agency.getConsecutiveSuccessfulLandings() != null) { - consecutiveLandingTotal.setText(String.valueOf(agency.getConsecutiveSuccessfulLandings())); + binding.consecutiveLandingSuccessValue.setText(String.valueOf(agency.getConsecutiveSuccessfulLandings())); } else { - consecutiveLandingTotal.setText(" - "); + binding.consecutiveLandingSuccessValue.setText(" - "); } if (agency.getFailedLandings() != null) { - landingFailureTotal.setText(String.valueOf(agency.getFailedLandings())); + binding.landingFailureValue.setText(String.valueOf(agency.getFailedLandings())); } else { - landingFailureTotal.setText(" - "); + binding.landingFailureValue.setText(" - "); } - } - } catch (NullPointerException e) { Timber.e(e); } } - @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); model = ViewModelProviders.of(getActivity()).get(DetailsViewModel.class); - // update UI model.getLaunch().observe(this, this::setLaunch); } @@ -242,24 +160,19 @@ public static AgencyDetailFragment newInstance() { return new AgencyDetailFragment(); } - @OnClick(R2.id.lsp_infoButton_one) public void onLspInfoButtonOneClicked() { Activity activity = (Activity) context; openCustomTab(activity, context, detailLaunch.getLaunchServiceProvider().getInfoUrl()); } - @OnClick(R2.id.lsp_wikiButton_one) public void onLspWikiButtonOneClicked() { Activity activity = (Activity) context; openCustomTab(activity, context, detailLaunch.getLaunchServiceProvider().getWikiUrl()); } - @OnClick(R2.id.lsp_agency) public void onViewClicked() { Intent intent = new Intent(context, AgencyLaunchActivity.class); intent.putExtra("lspName", detailLaunch.getLaunchServiceProvider().getName()); startActivity(intent); } - - } diff --git a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/fragments/SummaryDetailFragment.java b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/fragments/SummaryDetailFragment.java index 7ec843fb7..f25d5e1b0 100644 --- a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/fragments/SummaryDetailFragment.java +++ b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/fragments/SummaryDetailFragment.java @@ -13,12 +13,10 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; import com.afollestad.materialdialogs.MaterialDialog; import com.pierfrancescosoffritti.androidyoutubeplayer.player.PlayerConstants; import com.pierfrancescosoffritti.androidyoutubeplayer.player.YouTubePlayer; -import com.pierfrancescosoffritti.androidyoutubeplayer.player.YouTubePlayerView; import com.pierfrancescosoffritti.androidyoutubeplayer.player.listeners.AbstractYouTubePlayerListener; import com.pierfrancescosoffritti.androidyoutubeplayer.player.listeners.YouTubePlayerListener; @@ -27,21 +25,15 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.widget.AppCompatButton; -import androidx.core.widget.NestedScrollView; import androidx.lifecycle.Lifecycle; import androidx.lifecycle.ViewModelProviders; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; import io.reactivex.disposables.Disposable; import io.realm.RealmResults; import me.calebjones.spacelaunchnow.common.R; -import me.calebjones.spacelaunchnow.common.R2; import me.calebjones.spacelaunchnow.common.base.BaseFragment; +import me.calebjones.spacelaunchnow.common.databinding.DetailLaunchSummaryBinding; import me.calebjones.spacelaunchnow.common.prefs.ListPreferences; import me.calebjones.spacelaunchnow.common.ui.adapters.NewsListAdapter; import me.calebjones.spacelaunchnow.common.ui.adapters.UpdateAdapter; @@ -57,8 +49,6 @@ import me.calebjones.spacelaunchnow.data.models.main.VidURL; import me.calebjones.spacelaunchnow.data.models.main.news.NewsItem; -import me.calebjones.spacelaunchnow.common.ui.views.custom.CountDownView; -import me.calebjones.spacelaunchnow.common.ui.views.custom.WeatherCard; import me.calebjones.spacelaunchnow.data.networking.news.data.Callbacks; import me.calebjones.spacelaunchnow.data.networking.news.data.NewsDataRepository; import retrofit2.Call; @@ -68,34 +58,6 @@ public class SummaryDetailFragment extends BaseFragment implements YouTubePlayerListener { - @BindView(R2.id.countdown_status) - TextView countdownStatus; - @BindView(R2.id.countdown_layout) - CountDownView countDownView; - @BindView(R2.id.launch_summary) - NestedScrollView launchSummary; - @BindView(R2.id.date) - TextView launchDate; - @BindView(R2.id.watchButton) - AppCompatButton watchButton; - @BindView(R2.id.launch_window_text) - TextView launchWindowText; - @BindView(R2.id.error_message) - TextView errorMessage; - @BindView(R2.id.weather_card) - WeatherCard weatherCard; - @BindView(R2.id.videos_empty) - TextView videosEmpty; - @BindView(R2.id.news_recycler_view) - RecyclerView recyclerView; - @BindView(R2.id.youtube_view) - YouTubePlayerView youTubePlayerView; - @BindView(R2.id.related_card) - View relatedCard; - @BindView(R2.id.update_card) - View updateCard; - @BindView(R2.id.update_recycler_view) - RecyclerView updateRecyclerView; private SharedPreferences sharedPref; private ListPreferences sharedPreference; @@ -109,13 +71,13 @@ public class SummaryDetailFragment extends BaseFragment implements YouTubePlayer private int youTubeProgress = 0; public Disposable var; private boolean future = true; - private Unbinder unbinder; private DetailsViewModel model; private YouTubePlayer youTubePlayer; private NewsDataRepository dataRepository; private NewsListAdapter listAdapter; boolean isYouTubePlaying = false; private UpdateAdapter updateAdapter; + private DetailLaunchSummaryBinding binding; @Override public void onCreate(Bundle savedInstanceState) { @@ -127,6 +89,9 @@ public void onCreate(Bundle savedInstanceState) { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + binding = DetailLaunchSummaryBinding.inflate(inflater, container, false); + View view = binding.getRoot(); + this.sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); this.context = getContext(); @@ -137,9 +102,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa nightMode = false; } - View view = inflater.inflate(R.layout.detail_launch_summary, container, false); - - unbinder = ButterKnife.bind(this, view); dataRepository = new NewsDataRepository(getContext(), getRealm()); if (savedInstanceState != null) { @@ -186,8 +148,8 @@ public void onSaveInstanceState(Bundle outState) { private void setUpViews(Launch launch) { try { - getLifecycle().addObserver(youTubePlayerView); - videosEmpty.setVisibility(View.GONE); + getLifecycle().addObserver(binding.youtubeView); + binding.videosEmpty.setVisibility(View.GONE); detailLaunch = launch; fetchRelatedNews(launch.getId()); @@ -197,7 +159,7 @@ private void setUpViews(Launch launch) { Date mDate; String dateText; - if (detailLaunch.getVidURLs() != null && detailLaunch.getVidURLs().size() > 0) { + if (detailLaunch.getVidURLs() != null && !detailLaunch.getVidURLs().isEmpty()) { for (VidURL url : detailLaunch.getVidURLs()) { youTubeURL = Utils.getYouTubeID(url.getUrl()); @@ -206,11 +168,11 @@ private void setUpViews(Launch launch) { if (youTubeURL != null) { Timber.v("Loading %s", youTubeURL); - youTubePlayerView.setVisibility(View.VISIBLE); - errorMessage.setVisibility(View.GONE); + binding.youtubeView.setVisibility(View.VISIBLE); + binding.errorMessage.setVisibility(View.GONE); // youTubePlayerView.getPlayerUIController().enableLiveVideoUI(true); - youTubePlayerView.getPlayerUIController().showFullscreenButton(false); - youTubePlayerView.initialize(youTubePlayer -> { + binding.youtubeView.getPlayerUIController().showFullscreenButton(false); + binding.youtubeView.initialize(youTubePlayer -> { youTubePlayer.addListener(new AbstractYouTubePlayerListener() { @Override public void onReady() { @@ -220,10 +182,10 @@ public void onReady() { }, true); } - watchButton.setVisibility(View.VISIBLE); - watchButton.setOnClickListener(v -> { + binding.watchButton.setVisibility(View.VISIBLE); + binding.watchButton.setOnClickListener(v -> { Timber.d("Watch: %s", detailLaunch.getVidURLs().size()); - if (detailLaunch.getVidURLs().size() > 0) { + if (!detailLaunch.getVidURLs().isEmpty()) { final DialogAdapter adapter = new DialogAdapter((index, item, longClick) -> { if (longClick) { Intent sendIntent = new Intent(); @@ -267,21 +229,21 @@ public void onReady() { } else { if (future) { - videosEmpty.setVisibility(View.VISIBLE); + binding.videosEmpty.setVisibility(View.VISIBLE); } - watchButton.setVisibility(View.GONE); - errorMessage.setText(getString(R.string.video_source_unavailable)); - errorMessage.setVisibility(View.VISIBLE); + binding.watchButton.setVisibility(View.GONE); + binding.errorMessage.setText(getString(R.string.video_source_unavailable)); + binding.errorMessage.setVisibility(View.VISIBLE); } if (detailLaunch.getUpdates() != null && detailLaunch.getUpdates().size() > 0){ updateAdapter = new UpdateAdapter(context); - updateRecyclerView.setLayoutManager(new LinearLayoutManager(context)); - updateRecyclerView.setAdapter(updateAdapter); + binding.updateRecyclerView.setLayoutManager(new LinearLayoutManager(context)); + binding.updateRecyclerView.setAdapter(updateAdapter); updateAdapter.addItems(detailLaunch.getUpdates()); - updateCard.setVisibility(View.VISIBLE); + binding.updateCard.setVisibility(View.VISIBLE); } else { - updateCard.setVisibility(View.GONE); + binding.updateCard.setVisibility(View.GONE); } Date date = detailLaunch.getNet(); @@ -289,13 +251,13 @@ public void onReady() { //Get launch date // dateText = Utils.getStatusBasedDateFormat(launch.getNet(), launch.getStatus()); dateText = Utils.getSimpleDateFormatForUIWithPrecision(launch.getNetPrecision()).format(launch.getNet()); - launchDate.setText(Html.fromHtml(String.format(getString(R.string.launch_date), dateText))); + binding.date.setText(Html.fromHtml(String.format(getString(R.string.launch_date), dateText))); - if (detailLaunch.getWindowStart() != null && detailLaunch.getWindowStart() != null && launch.getStatus().getId() != 2) { + if (detailLaunch.getWindowStart() != null && launch.getStatus().getId() != 2) { setWindowStamp(); } else { - launchWindowText.setVisibility(View.GONE); + binding.launchWindowText.setVisibility(View.GONE); } } catch (NullPointerException e) { @@ -309,12 +271,12 @@ private void fetchRelatedNews(String id) { public void onNewsLoaded(RealmResults news) { if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.CREATED)) { Timber.v(news.toString()); - if (news.size() > 0) { + if (!news.isEmpty()) { listAdapter = new NewsListAdapter(context); - recyclerView.setLayoutManager(new LinearLayoutManager(context)); - recyclerView.setAdapter(listAdapter); + binding.newsRecyclerView.setLayoutManager(new LinearLayoutManager(context)); + binding.newsRecyclerView.setAdapter(listAdapter); listAdapter.addItems(news); - relatedCard.setVisibility(View.VISIBLE); + binding.relatedCard.setVisibility(View.VISIBLE); } } } @@ -352,7 +314,7 @@ private void loadVideo(YouTubePlayer youTubePlayer, String videoId) { private void setupCountdownTimer(Launch launch) { //If timestamp is available calculate TMinus and launchDate. if (launch.getNet() != null) { - countDownView.setLaunch(launch); + binding.countdownLayout.setLaunch(launch); } } @@ -388,19 +350,19 @@ private void setWindowStamp() { TimeZone timeZone = dateFormat.getTimeZone(); - launchWindowText.setText(Html.fromHtml(String.format(getString(R.string.instantaneous_launch_window), + binding.launchWindowText.setText(Html.fromHtml(String.format(getString(R.string.instantaneous_launch_window), dateFormat.format(windowStart)))); } else if (windowStart.after(windowEnd)) { // Launch data is not trustworthy - start is after end. TimeZone timeZone = dateFormat.getTimeZone(); - launchWindowText.setText(dateFormat.format(windowStart)); + binding.launchWindowText.setText(dateFormat.format(windowStart)); } else if (windowStart.before(windowEnd)) { // Launch Window is properly configured String difference = Utils.printDifference(windowStart, windowEnd); - launchWindowText.setText(Html.fromHtml(String.format(getString(R.string.launch_window_extras), + binding.launchWindowText.setText(Html.fromHtml(String.format(getString(R.string.launch_window_extras), dateFormat.format(windowStart), dateFormat.format(windowEnd), difference))); @@ -425,7 +387,6 @@ public void onDestroyView() { if (timer != null) { timer.cancel(); } - unbinder.unbind(); } @Override public void onReady() { @@ -480,7 +441,7 @@ public void onVideoLoadedFraction(float loadedFraction) { public void onVideoId(@NonNull String videoId) { YouTubeAPIHelper youTubeAPIHelper = new YouTubeAPIHelper(context, context.getResources().getString(R.string.GoogleMapsKey)); - youTubePlayerView.getPlayerUIController().enableLiveVideoUI(false); + binding.youtubeView.getPlayerUIController().enableLiveVideoUI(false); youTubeAPIHelper.getVideoById(videoId, new retrofit2.Callback() { @Override public void onResponse(Call call, Response response) { @@ -489,7 +450,7 @@ public void onResponse(Call call, Response respons if (videos.size() > 0) { try { if (videos.get(0).getSnippet().getLiveBroadcastContent().contains("live")){ - youTubePlayerView.getPlayerUIController().enableLiveVideoUI(true); + binding.youtubeView.getPlayerUIController().enableLiveVideoUI(true); } } catch (Exception e) { Timber.e(e); diff --git a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/fragments/mission/MissionDetailFragment.java b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/fragments/mission/MissionDetailFragment.java index f02e83763..7d46cd970 100644 --- a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/fragments/mission/MissionDetailFragment.java +++ b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/fragments/mission/MissionDetailFragment.java @@ -10,24 +10,16 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; -import android.widget.ImageView; -import android.widget.TextView; import androidx.annotation.Nullable; -import androidx.cardview.widget.CardView; -import androidx.constraintlayout.widget.Guideline; import androidx.lifecycle.ViewModelProviders; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; + import me.calebjones.spacelaunchnow.common.GlideApp; import me.calebjones.spacelaunchnow.common.R; -import me.calebjones.spacelaunchnow.common.R2; import me.calebjones.spacelaunchnow.common.base.RetroFitFragment; +import me.calebjones.spacelaunchnow.common.databinding.DetailLaunchPayloadBinding; import me.calebjones.spacelaunchnow.common.ui.adapters.CrewAdapter; import me.calebjones.spacelaunchnow.common.ui.launchdetail.DetailsViewModel; import me.calebjones.spacelaunchnow.common.ui.launchdetail.launches.launcher.LauncherLaunchActivity; @@ -40,92 +32,11 @@ public class MissionDetailFragment extends RetroFitFragment { - @BindView(R2.id.coreRecyclerView) - RecyclerView coreRecyclerView; - @BindView(R2.id.payload_type) - TextView payloadType; - @BindView(R2.id.payload_description) - TextView payloadDescription; - @BindView(R2.id.orbit) - TextView orbit; - @BindView(R2.id.payload_status) - TextView payloadStatus; - @BindView(R2.id.payload_infoButton) - TextView payloadInfoButton; - @BindView(R2.id.payload_wikiButton) - TextView payloadWikiButton; - @BindView(R2.id.launch_vehicle) - TextView launchVehicleView; - @BindView(R2.id.launch_configuration) - TextView launchConfiguration; - @BindView(R2.id.launch_family) - TextView launchFamily; - @BindView(R2.id.maiden_value) - TextView maidenLaunch; - - @BindView(R2.id.launch_vehicle_specs_height_value) - TextView launchVehicleSpecsHeight; - @BindView(R2.id.launch_vehicle_specs_diameter_value) - TextView launchVehicleSpecsDiameter; - @BindView(R2.id.launch_vehicle_specs_stages_value) - TextView launchVehicleSpecsStages; - @BindView(R2.id.launch_vehicle_specs_leo_value) - TextView launchVehicleSpecsLeo; - @BindView(R2.id.launch_vehicle_specs_gto_value) - TextView launchVehicleSpecsGto; - @BindView(R2.id.launch_vehicle_specs_launch_mass_value) - TextView launchVehicleSpecsLaunchMass; - @BindView(R2.id.launch_vehicle_specs_thrust_value) - TextView launchVehicleSpecsThrust; - - - @BindView(R2.id.launch_success_value) - TextView launchSuccess; - @BindView(R2.id.consecutive_success_value) - TextView consecutiveSuccess; - @BindView(R2.id.launch_total_value) - TextView launchTotal; - @BindView(R2.id.launch_failure_value) - TextView launchFailure; - - - @BindView(R2.id.launch_vehicle_description) - TextView launchVehicleDescription; - @BindView(R2.id.vehicle_infoButton) - Button vehicleInfoButton; - @BindView(R2.id.vehicle_wikiButton) - Button vehicleWikiButton; - @BindView(R2.id.flightclub_infoButton) - Button flightclubButton; - @BindView(R2.id.launcher_launches) - Button launchesButton; - @BindView(R2.id.spacecraft_image) - ImageView spacecraftImage; - @BindView(R2.id.spacecraft_title) - TextView spacecraftTitle; - @BindView(R2.id.spacecraft_sub_title) - TextView spacecraftSubTitle; - @BindView(R2.id.spacecraft_guideline) - Guideline spacecraftGuideline; - @BindView(R2.id.destination_text) - TextView destinationText; - @BindView(R2.id.serial_number_text) - TextView serialNumberText; - @BindView(R2.id.status_text) - TextView statusText; - @BindView(R2.id.description) - TextView description; - @BindView(R2.id.spacecraft_card) - CardView spacecraftCard; - @BindView(R2.id.crew_recycler_view) - RecyclerView crewReycler; - @BindView(R2.id.mission_patch) - ImageView missionPatch; private Context context; public Launch detailLaunch; - private Unbinder unbinder; private DetailsViewModel model; + private DetailLaunchPayloadBinding binding; @Override public void onCreate(Bundle savedInstanceState) { @@ -138,25 +49,9 @@ public void onCreate(Bundle savedInstanceState) { @Nullable @Override public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { - View view; context = getContext(); - view = inflater.inflate(R.layout.detail_launch_payload, container, false); - - unbinder = ButterKnife.bind(this, view); - - return view; - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - Timber.v("onDestroyView"); - unbinder.unbind(); - } - - @Override - public void onResume() { - super.onResume(); + binding = DetailLaunchPayloadBinding.inflate(inflater, container, false); + return binding.getRoot(); } public void setLaunch(Launch launch) { @@ -172,101 +67,102 @@ private void setUpViews(Launch launch) { if (detailLaunch.getMission() != null) { final Mission mission = detailLaunch.getMission(); - payloadStatus.setText(mission.getName()); - payloadDescription.setText(mission.getDescription()); - payloadType.setText(mission.getTypeName()); + binding.payloadStatus.setText(mission.getName()); + binding.payloadDescription.setText(mission.getDescription()); + binding.payloadType.setText(mission.getTypeName()); if (mission.getOrbit() != null && mission.getOrbit().getAbbrev() != null) { - orbit.setVisibility(View.VISIBLE); - orbit.setText(String.format("%s (%s)", mission.getOrbit().getName(), mission.getOrbit().getAbbrev())); + binding.orbit.setVisibility(View.VISIBLE); + binding.orbit.setText(String.format("%s (%s)", mission.getOrbit().getName(), mission.getOrbit().getAbbrev())); } else { - orbit.setVisibility(View.GONE); + binding.orbit.setVisibility(View.GONE); } - payloadInfoButton.setVisibility(View.GONE); - payloadWikiButton.setVisibility(View.GONE); + binding.payloadInfoButton.setVisibility(View.GONE); + binding.payloadWikiButton.setVisibility(View.GONE); } else { - payloadStatus.setText(R.string.unknown_mission_or_payload); + binding.payloadStatus.setText(R.string.unknown_mission_or_payload); - payloadInfoButton.setVisibility(View.GONE); - payloadWikiButton.setVisibility(View.GONE); + binding.payloadInfoButton.setVisibility(View.GONE); + binding.payloadWikiButton.setVisibility(View.GONE); } if(detailLaunch.getFlightclub() != null){ - flightclubButton.setVisibility(View.VISIBLE); - flightclubButton.setOnClickListener(v -> { + binding.flightclubInfoButton.setVisibility(View.VISIBLE); + binding.flightclubInfoButton.setOnClickListener(v -> { Activity activity = (Activity) context; openCustomTab(activity, context, detailLaunch.getFlightclub()); }); } else { - flightclubButton.setVisibility(View.GONE); + binding.flightclubInfoButton.setVisibility(View.GONE); } - launchVehicleView.setText(detailLaunch.getRocket().getConfiguration().getFullName()); - launchConfiguration.setText(detailLaunch.getRocket().getConfiguration().getVariant()); - launchFamily.setText(detailLaunch.getRocket().getConfiguration().getFamily()); - if (detailLaunch.getRocket().getConfiguration().getInfoUrl() != null && detailLaunch.getRocket().getConfiguration().getInfoUrl().length() > 0) { - vehicleInfoButton.setOnClickListener(view -> { + binding.launchVehicle.setText(detailLaunch.getRocket().getConfiguration().getFullName()); + binding.launchConfiguration.setText(detailLaunch.getRocket().getConfiguration().getVariant()); + binding.launchFamily.setText(detailLaunch.getRocket().getConfiguration().getFamily()); + if (detailLaunch.getRocket().getConfiguration().getInfoUrl() != null && + !detailLaunch.getRocket().getConfiguration().getInfoUrl().isEmpty()) { + binding.vehicleInfoButton.setOnClickListener(view -> { Activity activity = (Activity) context; openCustomTab(activity, context, detailLaunch.getRocket().getConfiguration().getInfoUrl()); }); } else { - vehicleInfoButton.setVisibility(View.GONE); + binding.vehicleInfoButton.setVisibility(View.GONE); } if (detailLaunch.getPatches() != null && detailLaunch.getPatches().size() > 0){ - missionPatch.setVisibility(View.VISIBLE); + binding.missionPatch.setVisibility(View.VISIBLE); GlideApp.with(context) .load(detailLaunch.getPatches().get(0).getImageUrl()) .centerInside() - .into(missionPatch); + .into(binding.missionPatch); } else { - missionPatch.setVisibility(View.GONE); + binding.missionPatch.setVisibility(View.GONE); } if (detailLaunch.getRocket().getConfiguration().getWikiUrl() != null && detailLaunch.getRocket().getConfiguration().getWikiUrl().length() > 0) { - vehicleWikiButton.setOnClickListener(view -> { + binding.vehicleWikiButton.setOnClickListener(view -> { Activity activity = (Activity) context; openCustomTab(activity, context, detailLaunch.getRocket().getConfiguration().getWikiUrl()); }); } else { - vehicleWikiButton.setVisibility(View.GONE); + binding.vehicleWikiButton.setVisibility(View.GONE); } configureLaunchVehicle(launch.getRocket().getConfiguration()); if (launch.getRocket().getLauncherStage() != null && launch.getRocket().getLauncherStage().size() > 0) { - coreRecyclerView.setVisibility(View.VISIBLE); + binding.coreRecyclerView.setVisibility(View.VISIBLE); LinearLayoutManager layoutManager = new LinearLayoutManager(context); - coreRecyclerView.setLayoutManager(layoutManager); + binding.coreRecyclerView.setLayoutManager(layoutManager); StageInformationAdapter stageInformationAdapter = new StageInformationAdapter(launch, context); - coreRecyclerView.setAdapter(stageInformationAdapter); - coreRecyclerView.setHasFixedSize(true); + binding.coreRecyclerView.setAdapter(stageInformationAdapter); + binding.coreRecyclerView.setHasFixedSize(true); } else { - coreRecyclerView.setVisibility(View.GONE); + binding.coreRecyclerView.setVisibility(View.GONE); } if (launch.getRocket().getSpacecraftStage() != null) { - spacecraftCard.setVisibility(View.VISIBLE); + binding.spacecraftCard.setVisibility(View.VISIBLE); SpacecraftStage stage = launch.getRocket().getSpacecraftStage(); GlideApp.with(context) .load(stage.getSpacecraft().getConfiguration().getImageUrl()) .placeholder(R.drawable.placeholder) .centerCrop() - .into(spacecraftImage); - spacecraftTitle.setText(stage.getSpacecraft().getConfiguration().getName()); - spacecraftSubTitle.setText(stage.getSpacecraft().getConfiguration().getAgency().getName()); - destinationText.setText(stage.getDestination()); - serialNumberText.setText(stage.getSpacecraft().getSerialNumber()); - statusText.setText(stage.getSpacecraft().getStatus().getName()); - description.setText(stage.getSpacecraft().getDescription()); + .into(binding.spacecraftImage); + binding.spacecraftTitle.setText(stage.getSpacecraft().getConfiguration().getName()); + binding.spacecraftSubTitle.setText(stage.getSpacecraft().getConfiguration().getAgency().getName()); + binding.destinationText.setText(stage.getDestination()); + binding.serialNumberText.setText(stage.getSpacecraft().getSerialNumber()); + binding.statusText.setText(stage.getSpacecraft().getStatus().getName()); + binding.description.setText(stage.getSpacecraft().getDescription()); if (launch.getRocket().getSpacecraftStage().getLaunchCrew() != null - && launch.getRocket().getSpacecraftStage().getLaunchCrew().size() > 0) { - crewReycler.setLayoutManager(new LinearLayoutManager(context)); - crewReycler.setAdapter(new CrewAdapter(context, + && !launch.getRocket().getSpacecraftStage().getLaunchCrew().isEmpty()) { + binding.crewRecyclerView.setLayoutManager(new LinearLayoutManager(context)); + binding.crewRecyclerView.setAdapter(new CrewAdapter(context, launch.getRocket().getSpacecraftStage().getLaunchCrew())); } } else { - spacecraftCard.setVisibility(View.GONE); + binding.spacecraftCard.setVisibility(View.GONE); } } catch (NullPointerException e) { @@ -278,90 +174,92 @@ private void configureLaunchVehicle(LauncherConfig launchVehicle) { if (launchVehicle != null) { try { if (launchVehicle.getLength() != null) { - launchVehicleSpecsHeight.setText(String.format(context.getString(R.string.height_value), launchVehicle.getLength())); + binding.launchVehicleSpecsHeight.setText(String.format(context.getString(R.string.height_value), launchVehicle.getLength())); } else { - launchVehicleSpecsHeight.setText(" - "); + binding.launchVehicleSpecsHeight.setText(" - "); } if (launchVehicle.getDiameter() != null) { - launchVehicleSpecsDiameter.setText(String.format(context.getString(R.string.diameter_value), launchVehicle.getDiameter())); + binding.launchVehicleSpecsDiameter.setText(String.format(context.getString(R.string.diameter_value), launchVehicle.getDiameter())); } else { - launchVehicleSpecsDiameter.setText(" - "); + binding.launchVehicleSpecsDiameter.setText(" - "); } if (launchVehicle.getMaxStage() != null) { - launchVehicleSpecsStages.setText(String.format(context.getString(R.string.stage_value), launchVehicle.getMaxStage())); + binding.launchVehicleSpecsStages.setText(String.format(context.getString(R.string.stage_value), launchVehicle.getMaxStage())); } else { - launchVehicleSpecsStages.setText(" - "); + binding.launchVehicleSpecsStages.setText(" - "); } if (launchVehicle.getLeoCapacity() != null) { - launchVehicleSpecsLeo.setText(String.format(context.getString(R.string.mass_leo_value), launchVehicle.getLeoCapacity())); + binding.launchVehicleSpecsLeo.setText(String.format(context.getString(R.string.mass_leo_value), launchVehicle.getLeoCapacity())); } else { - launchVehicleSpecsLeo.setText(" - "); + binding.launchVehicleSpecsLeo.setText(" - "); } if (launchVehicle.getGtoCapacity() != null) { - launchVehicleSpecsGto.setText(String.format(context.getString(R.string.mass_gto_value), launchVehicle.getGtoCapacity())); + binding.launchVehicleSpecsGto.setText(String.format(context.getString(R.string.mass_gto_value), launchVehicle.getGtoCapacity())); } else { - launchVehicleSpecsGto.setText(" - "); + binding.launchVehicleSpecsGto.setText(" - "); } if (launchVehicle.getLaunchMass() != null) { - launchVehicleSpecsLaunchMass.setText(String.format(context.getString(R.string.mass_launch_value), launchVehicle.getLaunchMass())); + binding.launchVehicleSpecsLaunchMass.setText(String.format(context.getString(R.string.mass_launch_value), launchVehicle.getLaunchMass())); } else { - launchVehicleSpecsLaunchMass.setText(" - "); + binding.launchVehicleSpecsLaunchMass.setText(" - "); } if (launchVehicle.getToThrust() != null) { - launchVehicleSpecsThrust.setText(String.format(context.getString(R.string.thrust_value), launchVehicle.getToThrust())); + binding.launchVehicleSpecsThrust.setText(String.format(context.getString(R.string.thrust_value), launchVehicle.getToThrust())); } else { - launchVehicleSpecsThrust.setText(" - "); + binding.launchVehicleSpecsThrust.setText(" - "); } if (launchVehicle.getConsecutiveSuccessfulLaunches() != null) { - consecutiveSuccess.setText(String.valueOf(launchVehicle.getConsecutiveSuccessfulLaunches())); + binding.consecutiveSuccessValue.setText(String.valueOf(launchVehicle.getConsecutiveSuccessfulLaunches())); } else { - consecutiveSuccess.setText(" - "); + binding.consecutiveSuccessValue.setText(" - "); } if (launchVehicle.getSuccessfulLaunches() != null) { - launchSuccess.setText(String.valueOf(launchVehicle.getSuccessfulLaunches())); + binding.launchSuccessValue.setText(String.valueOf(launchVehicle.getSuccessfulLaunches())); } else { - launchSuccess.setText(" - "); + binding.launchSuccessValue.setText(" - "); } if (launchVehicle.getTotalLaunchCount() != null) { - launchTotal.setText(String.valueOf(launchVehicle.getTotalLaunchCount())); + binding.launchTotalValue.setText(String.valueOf(launchVehicle.getTotalLaunchCount())); } else { - launchTotal.setText(" - "); + binding.launchTotalValue.setText(" - "); } if (launchVehicle.getFailedLaunches() != null) { - launchFailure.setText(String.valueOf(launchVehicle.getFailedLaunches())); + binding.launchFailureValue.setText(String.valueOf(launchVehicle.getFailedLaunches())); } else { - launchFailure.setText(" - "); + binding.launchFailureValue.setText(" - "); } if (launchVehicle.getMaidenFlight() != null){ //Setup SimpleDateFormat to parse out getNet launchDate. SimpleDateFormat output = Utils.getSimpleDateFormatForUI("MMMM dd, yyyy"); - maidenLaunch.setText(output.format(launchVehicle.getMaidenFlight())); + binding.maidenValue.setText(output.format(launchVehicle.getMaidenFlight())); } - if (launchVehicle.getDescription() != null && launchVehicle.getDescription().length() > 0) { - launchVehicleDescription.setText(launchVehicle.getDescription()); - launchVehicleDescription.setVisibility(View.VISIBLE); + if (launchVehicle.getDescription() != null && !launchVehicle.getDescription().isEmpty()) { + binding.launchVehicleDescription.setText(launchVehicle.getDescription()); + binding.launchVehicleDescription.setVisibility(View.VISIBLE); } else { - launchVehicleDescription.setVisibility(View.GONE); + binding.launchVehicleDescription.setVisibility(View.GONE); } - launchesButton.setText(String.format(getString(R.string.view_rocket_launches), launchVehicle.getName())); - launchesButton.setOnClickListener(v -> { + + binding.launcherLaunches.setText(String.format(getString(R.string.view_rocket_launches), launchVehicle.getName())); + binding.launcherLaunches.setOnClickListener(v -> { Intent launches = new Intent(context, LauncherLaunchActivity.class); launches.putExtra("launcherId", launchVehicle.getId()); launches.putExtra("launcherName", launchVehicle.getName()); context.startActivity(launches); }); + } catch (NullPointerException e) { Timber.e(e); } diff --git a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/fragments/mission/StageInformationAdapter.java b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/fragments/mission/StageInformationAdapter.java index 1273a8295..2226d13fe 100644 --- a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/fragments/mission/StageInformationAdapter.java +++ b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/fragments/mission/StageInformationAdapter.java @@ -1,34 +1,27 @@ package me.calebjones.spacelaunchnow.common.ui.launchdetail.fragments.mission; +import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; -import android.widget.ImageView; import android.widget.TextView; import com.afollestad.materialdialogs.MaterialDialog; -import com.bumptech.glide.Glide; import java.util.List; -import androidx.appcompat.widget.AppCompatButton; -import androidx.constraintlayout.widget.Group; import androidx.recyclerview.widget.RecyclerView; -import at.blogc.android.views.ExpandableTextView; -import butterknife.BindView; -import butterknife.ButterKnife; + import me.calebjones.spacelaunchnow.common.GlideApp; import me.calebjones.spacelaunchnow.common.R; -import me.calebjones.spacelaunchnow.common.R2; +import me.calebjones.spacelaunchnow.common.databinding.CoreInformationBinding; import me.calebjones.spacelaunchnow.data.models.main.Landing; import me.calebjones.spacelaunchnow.data.models.main.Launch; import me.calebjones.spacelaunchnow.data.models.main.launcher.Launcher; import me.calebjones.spacelaunchnow.data.models.main.launcher.LauncherStage; import me.calebjones.spacelaunchnow.common.ui.launchdetail.launches.launcher.LauncherLaunchActivity; -import timber.log.Timber; /** * This adapter takes data from ListPreferences/LoaderService and applies it to RecyclerView @@ -38,6 +31,7 @@ public class StageInformationAdapter extends RecyclerView.Adapter launcherList; private Context context; private Launch launch; + private CoreInformationBinding binding; public StageInformationAdapter(Launch launch, Context context) { this.launch = launch; @@ -49,126 +43,148 @@ public StageInformationAdapter(Launch launch, Context context) { @Override public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { - Timber.v("onCreate ViewHolder."); - View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.core_information, viewGroup, false); - return new ViewHolder(v); + binding = CoreInformationBinding.inflate(LayoutInflater.from(viewGroup.getContext()), + viewGroup, + false + ); + return new ViewHolder(binding); } + @SuppressLint("DefaultLocale") @Override public void onBindViewHolder(final ViewHolder holder, int position) { LauncherStage stage = launcherList.get(position); if (stage.getLauncher() != null) { Launcher launcher = stage.getLauncher(); - holder.viewCoreLaunches.setVisibility(View.VISIBLE); - holder.viewCoreLaunches.setText(String.format(context.getString(R.string.view_x_launches), stage.getLauncher().getSerialNumber())); - holder.viewCoreLaunches.setOnClickListener(v -> { + holder.binding.viewCoreLaunches.setVisibility(View.VISIBLE); + holder.binding.viewCoreLaunches.setText(String.format( + context.getString(R.string.view_x_launches), + stage.getLauncher().getSerialNumber() + )); + holder.binding.viewCoreLaunches.setOnClickListener(v -> { Intent launches = new Intent(context, LauncherLaunchActivity.class); launches.putExtra("serialNumber", launcher.getSerialNumber()); context.startActivity(launches); }); - if (launcher.getImageUrl() != null){ + if (launcher.getImageUrl() != null) { GlideApp.with(context) .load(launcher.getImageUrl()) .placeholder(R.drawable.placeholder) - .into(holder.coreImage); + .into(holder.binding.coreImage); } - holder.coreInformation.setText(String.format(context.getString(R.string.booster_information), launcher.getSerialNumber())); + holder.binding.coreInformation.setText(String.format( + context.getString(R.string.booster_information), + launcher.getSerialNumber() + )); if (stage.getType() != null) { - holder.coreInformationSubtitle.setText(String.format(context.getString(R.string.first_stage_x), stage.getType())); + holder.binding.coreInformationSubtitle.setText(String.format( + context.getString(R.string.first_stage_x), + stage.getType() + )); } - holder.details.setText(launcher.getDetails()); - holder.serialNumberText.setText(stage.getLauncher().getSerialNumber()); - String cap = launcher.getStatus().substring(0, 1).toUpperCase() + stage.getLauncher().getStatus().substring(1); - holder.statusText.setText(cap); - holder.previousText.setText(""); + holder.binding.details.setText(launcher.getDetails()); + holder.binding.serialNumberText.setText(stage.getLauncher().getSerialNumber()); + String cap = launcher.getStatus().substring(0, 1).toUpperCase() + + stage.getLauncher().getStatus().substring(1); + holder.binding.statusText.setText(cap); + holder.binding.previousText.setText(""); + if (launcher.getFlightProven() == null) { - holder.flightProven.setImageResource(R.drawable.ic_question_mark); + holder.binding.flightProven.setImageResource(R.drawable.ic_question_mark); } else if (launcher.getFlightProven()) { - holder.flightProven.setImageResource(R.drawable.ic_checkmark); + holder.binding.flightProven.setImageResource(R.drawable.ic_checkmark); } else if (!launcher.getFlightProven()) { - holder.flightProven.setImageResource(R.drawable.ic_failed); + holder.binding.flightProven.setImageResource(R.drawable.ic_failed); } - holder.previousText.setText(String.format("%d", stage.getLauncher().getPreviousFlights())); + + holder.binding.previousText.setText(String.format( + "%d", + stage.getLauncher().getPreviousFlights() + )); if (launcher.getAttemptedLandings() != null) { - holder.landingTotal.setText(String.valueOf(launcher.getAttemptedLandings())); + holder.binding.landingTotalValue.setText(String.valueOf(launcher.getAttemptedLandings())); } else { - holder.landingTotal.setText(" - "); + holder.binding.landingTotalValue.setText(" - "); } if (launcher.getSuccessfulLandings() != null) { - holder.landingSuccess.setText(String.valueOf(launcher.getSuccessfulLandings())); + holder.binding.landingSuccessCountValue.setText(String.valueOf(launcher.getSuccessfulLandings())); } else { - holder.landingSuccess.setText(" - "); + holder.binding.landingSuccessCountValue.setText(" - "); } } else { - holder.viewCoreLaunches.setVisibility(View.GONE); + holder.binding.viewCoreLaunches.setVisibility(View.GONE); } if (launch.getMission() != null && launch.getMission().getName() != null) { if (stage.getLanding() != null) { - holder.landingInformationTitle.setText(String.format(context.getString(R.string.x_landing_information), launch.getMission().getName())); + holder.binding.landingInformationTitle.setText(String.format( + context.getString(R.string.x_landing_information), + launch.getMission().getName() + )); } else { - holder.landingInformationTitle.setText("Landing Information Unavailable"); + holder.binding.landingInformationTitle.setText("Landing Information Unavailable"); } } - - holder.landingGroup.setVisibility(View.GONE); - holder.landingLocationGroup.setVisibility(View.GONE); - holder.landingTypeGroup.setVisibility(View.GONE); - holder.landingMore.setVisibility(View.GONE); + + holder.binding.landingGroup.setVisibility(View.GONE); + holder.binding.landingGroupLandingtype.setVisibility(View.GONE); + holder.binding.landingGroupLandinglocation.setVisibility(View.GONE); + holder.binding.landingMore.setVisibility(View.GONE); if (stage.getLanding() != null) { - holder.landingGroup.setVisibility(View.VISIBLE); + holder.binding.landingGroup.setVisibility(View.VISIBLE); Landing landing = stage.getLanding(); if (landing.getAttempt() == null) { - holder.attemptIcon.setImageResource(R.drawable.ic_question_mark); + holder.binding.attemptIcon.setImageResource(R.drawable.ic_question_mark); } else if (landing.getAttempt()) { - holder.attemptIcon.setImageResource(R.drawable.ic_checkmark); + holder.binding.attemptIcon.setImageResource(R.drawable.ic_checkmark); } else if (!landing.getAttempt()) { - holder.attemptIcon.setImageResource(R.drawable.ic_failed); + holder.binding.attemptIcon.setImageResource(R.drawable.ic_failed); } if (landing.getSuccess() == null) { - holder.successIcon.setImageResource(R.drawable.ic_question_mark); + holder.binding.successIcon.setImageResource(R.drawable.ic_question_mark); } else if (landing.getSuccess()) { - holder.successIcon.setImageResource(R.drawable.ic_checkmark); + holder.binding.successIcon.setImageResource(R.drawable.ic_checkmark); } else if (!landing.getSuccess()) { - holder.successIcon.setImageResource(R.drawable.ic_failed); + holder.binding.successIcon.setImageResource(R.drawable.ic_failed); } - if (landing.getDescription().length() != 0) { - holder.landingDescription.setText(landing.getDescription()); - holder.landingDescription.setOnClickListener(v -> { - if (!holder.landingDescription.isExpanded()) { - holder.landingDescription.expand(); + if (!landing.getDescription().isEmpty()) { + holder.binding.landingDescription.setText(landing.getDescription()); + holder.binding.landingDescription.setOnClickListener(v -> { + if (!holder.binding.landingDescription.isExpanded()) { + holder.binding.landingDescription.expand(); } }); } else { - holder.landingDescription.setVisibility(View.GONE); + holder.binding.landingDescription.setVisibility(View.GONE); } if (landing.getLandingType() != null && landing.getLandingType().getName() != null) { - holder.landingType.setText(landing.getLandingType().getName()); - holder.landingLocationGroup.setVisibility(View.VISIBLE); + holder.binding.landingType.setText(landing.getLandingType().getName()); + holder.binding.landingGroupLandingtype.setVisibility(View.VISIBLE); } - if (landing.getLandingLocation() != null && landing.getLandingLocation().getName() != null) { - holder.landingLocation.setText(landing.getLandingLocation().getName()); - holder.landingTypeGroup.setVisibility(View.VISIBLE); + if (landing.getLandingLocation() != null && + landing.getLandingLocation().getName() != null) { + holder.binding.landingLocation.setText(landing.getLandingLocation().getName()); + holder.binding.landingGroupLandinglocation.setVisibility(View.VISIBLE); } if (landing.getLandingLocation() != null - && landing.getLandingLocation().getName() != null - && landing.getLandingLocation().getDescription() != null - && landing.getLandingType() != null - && landing.getLandingType().getName() != null - && landing.getLandingType().getDescription() != null) { - holder.landingMore.setVisibility(View.VISIBLE); - holder.landingMore.setOnClickListener((View v) -> { + && landing.getLandingLocation().getName() != null + && landing.getLandingLocation().getDescription() != null + && landing.getLandingType() != null + && landing.getLandingType().getName() != null + && landing.getLandingType().getDescription() != null) { + holder.binding.landingMore.setVisibility(View.VISIBLE); + holder.binding.landingMore.setOnClickListener((View v) -> { MaterialDialog dialog = new MaterialDialog.Builder(context) .title(context.getString(R.string.additional_landing_information)) .customView(R.layout.landing_information, true) @@ -177,24 +193,27 @@ public void onBindViewHolder(final ViewHolder holder, int position) { View view = dialog.getCustomView(); TextView landingType = view.findViewById(R.id.landing_type); - TextView landingTypeDescription = view.findViewById(R.id.landing_type_description); + TextView landingTypeDescription = + view.findViewById(R.id.landing_type_description); TextView landingLocation = view.findViewById(R.id.landing_location); - TextView landingLocationDescription = view.findViewById(R.id.landing_location_description); + TextView landingLocationDescription = + view.findViewById(R.id.landing_location_description); landingType.setText(landing.getLandingType().getName()); landingTypeDescription.setText(landing.getLandingType().getDescription()); landingLocation.setText(landing.getLandingLocation().getName()); - landingLocationDescription.setText(landing.getLandingLocation().getDescription()); + landingLocationDescription.setText(landing.getLandingLocation() + .getDescription()); }); } else { - holder.landingMore.setVisibility(View.GONE); + holder.binding.landingMore.setVisibility(View.GONE); } } else { - holder.landingGroup.setVisibility(View.GONE); - holder.landingLocationGroup.setVisibility(View.GONE); - holder.landingTypeGroup.setVisibility(View.GONE); - holder.landingMore.setVisibility(View.GONE); + holder.binding.landingGroup.setVisibility(View.GONE); + holder.binding.landingGroupLandingtype.setVisibility(View.GONE); + holder.binding.landingGroupLandinglocation.setVisibility(View.GONE); + holder.binding.landingMore.setVisibility(View.GONE); } } @@ -206,71 +225,12 @@ public int getItemCount() { public class ViewHolder extends RecyclerView.ViewHolder { - @BindView(R2.id.core_information) - TextView coreInformation; - @BindView(R2.id.core_information_subtitle) - TextView coreInformationSubtitle; - @BindView(R2.id.serial_number_title) - TextView serialNumberTitle; - @BindView(R2.id.serial_number_text) - TextView serialNumberText; - @BindView(R2.id.status_title) - TextView statusTitle; - @BindView(R2.id.status_text) - TextView statusText; - @BindView(R2.id.previous_title) - TextView previousTitle; - @BindView(R2.id.previous_text) - TextView previousText; - @BindView(R2.id.flight_proven) - ImageView flightProven; - @BindView(R2.id.flight_proven_title) - TextView flightProvenTitle; - @BindView(R2.id.landing_attempt_title) - TextView landingAttemptTitle; - @BindView(R2.id.attempt_icon) - ImageView attemptIcon; - @BindView(R2.id.landing_success_title) - TextView landingSuccessTitle; - @BindView(R2.id.success_icon) - ImageView successIcon; - @BindView(R2.id.landing_description) - ExpandableTextView landingDescription; - @BindView(R2.id.landing_type) - TextView landingType; - @BindView(R2.id.landing_type_title) - TextView landingTypeTitle; - @BindView(R2.id.landing_location) - TextView landingLocation; - @BindView(R2.id.landing_location_title) - TextView landingLocationTitle; - @BindView(R2.id.landing_more) - Button landingMore; - @BindView(R2.id.view_core_launches) - AppCompatButton viewCoreLaunches; - @BindView(R2.id.landing_group) - Group landingGroup; - @BindView(R2.id.landing_group_landingtype) - Group landingLocationGroup; - @BindView(R2.id.landing_group_landinglocation) - Group landingTypeGroup; - @BindView(R2.id.details) - TextView details; - @BindView(R2.id.landing_information_title) - TextView landingInformationTitle; - @BindView(R2.id.coreImage) - ImageView coreImage; - - @BindView(R2.id.landing_success_count_value) - TextView landingSuccess; - @BindView(R2.id.landing_total_value) - TextView landingTotal; - + private CoreInformationBinding binding; //Add content to the card - public ViewHolder(View view) { - super(view); - ButterKnife.bind(this, view); + public ViewHolder(CoreInformationBinding binding) { + super(binding.getRoot()); + this.binding = binding; } } } diff --git a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/agency/AgencyLaunchActivity.java b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/agency/AgencyLaunchActivity.java index 3146859cb..fc222911a 100644 --- a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/agency/AgencyLaunchActivity.java +++ b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/agency/AgencyLaunchActivity.java @@ -4,8 +4,6 @@ import android.os.Bundle; import androidx.annotation.NonNull; -import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.appcompat.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; @@ -13,8 +11,6 @@ import android.view.ViewGroup; import com.afollestad.materialdialogs.MaterialDialog; -import com.google.android.material.appbar.AppBarLayout; -import com.google.android.material.floatingactionbutton.FloatingActionButton; import java.util.ArrayList; import java.util.List; @@ -24,15 +20,11 @@ import androidx.fragment.app.FragmentPagerAdapter; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import androidx.viewpager.widget.ViewPager; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; + import me.calebjones.spacelaunchnow.common.R; -import me.calebjones.spacelaunchnow.common.R2; import me.calebjones.spacelaunchnow.common.base.BaseActivityOld; +import me.calebjones.spacelaunchnow.common.databinding.ActivityAgencyLaunchBinding; import me.calebjones.spacelaunchnow.common.ui.settings.SettingsActivity; -import me.calebjones.spacelaunchnow.common.ui.views.custom.BadgeTabLayout; -import me.calebjones.spacelaunchnow.common.utils.Utils; import me.calebjones.spacelaunchnow.data.models.main.Agency; import me.calebjones.spacelaunchnow.data.networking.DataClient; import me.calebjones.spacelaunchnow.data.networking.responses.base.AgencyResponse; @@ -43,23 +35,9 @@ import timber.log.Timber; public class AgencyLaunchActivity extends BaseActivityOld implements UpcomingAgencyLaunchesFragment.OnFragmentInteractionListener, - PreviousAgencyLaunchesFragment.OnFragmentInteractionListener, SwipeRefreshLayout.OnRefreshListener { - - - @BindView(R2.id.toolbar) - Toolbar toolbar; - @BindView(R2.id.tabs) - BadgeTabLayout tabLayout; - @BindView(R2.id.appbar) - AppBarLayout appbar; - @BindView(R2.id.container) - ViewPager viewPager; - @BindView(R2.id.main_content) - CoordinatorLayout mainContent; - @BindView(R2.id.swipeRefresh) - SwipeRefreshLayout swipeRefresh; - @BindView(R2.id.menu) - FloatingActionButton menu; + PreviousAgencyLaunchesFragment.OnFragmentInteractionListener, + SwipeRefreshLayout.OnRefreshListener +{ private SectionsPagerAdapter mSectionsPagerAdapter; private UpcomingAgencyLaunchesFragment upcomingFragment; @@ -70,13 +48,16 @@ public class AgencyLaunchActivity extends BaseActivityOld implements UpcomingAge private boolean previousLoading = false; String lspName; String searchTerm; + private ActivityAgencyLaunchBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_agency_launch); - ButterKnife.bind(this); + + binding = ActivityAgencyLaunchBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); + setContentView(view); Intent intent = getIntent(); if (null != intent) { //Null Checking @@ -84,7 +65,7 @@ protected void onCreate(Bundle savedInstanceState) { } setTitle(); - setSupportActionBar(toolbar); + setSupportActionBar(binding.toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); // Create the adapter that will return a fragment for each of the three @@ -92,30 +73,30 @@ protected void onCreate(Bundle savedInstanceState) { mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. - viewPager.setAdapter(mSectionsPagerAdapter); - viewPager.addOnPageChangeListener( new ViewPager.OnPageChangeListener() { + binding.container.setAdapter(mSectionsPagerAdapter); + binding.container.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override - public void onPageScrolled( int position, float v, int i1 ) { + public void onPageScrolled(int position, float v, int i1) { } @Override - public void onPageSelected( int position ) { + public void onPageSelected(int position) { } @Override - public void onPageScrollStateChanged( int state ) { - enableDisableSwipeRefresh( state == ViewPager.SCROLL_STATE_IDLE ); + public void onPageScrollStateChanged(int state) { + enableDisableSwipeRefresh(state == ViewPager.SCROLL_STATE_IDLE); } - } ); - tabLayout.setupWithViewPager(viewPager); - swipeRefresh.setOnRefreshListener(this); + }); + binding.tabs.setupWithViewPager(binding.container); + binding.swipeRefresh.setOnRefreshListener(this); getFeaturedAgencies(); + + binding.menu.setOnClickListener(v -> onViewClicked()); } private void enableDisableSwipeRefresh(boolean enable) { - if (swipeRefresh != null) { - swipeRefresh.setEnabled(enable); - } + binding.swipeRefresh.setEnabled(enable); } @Override @@ -134,30 +115,30 @@ public void onResponse(Call call, Response respo for (Agency agency : agencies) { agencyList.add(agency.getName()); } - menu.setVisibility(View.VISIBLE); + binding.menu.setVisibility(View.VISIBLE); } else { - menu.setVisibility(View.GONE); + binding.menu.setVisibility(View.GONE); } } @Override public void onFailure(Call call, Throwable t) { - menu.setVisibility(View.GONE); + binding.menu.setVisibility(View.GONE); } }, 50); } @Override public void setUpcomingBadge(int count) { - if (tabLayout != null && count > 0) { - tabLayout.with(0).badge(true).badgeCount(count).name("UPCOMING").build(); + if (count > 0) { + binding.tabs.with(0).badge(true).badgeCount(count).name("UPCOMING").build(); } } @Override public void setPreviousBadge(int count) { - if (tabLayout != null && count > 0) { - tabLayout.with(1).badge(true).badgeCount(count).name("PREVIOUS").build(); + if (count > 0) { + binding.tabs.with(1).badge(true).badgeCount(count).name("PREVIOUS").build(); } } @@ -240,11 +221,11 @@ private void refresh() { private void setTitle() { if (lspName != null) { - toolbar.setTitle(lspName); + binding.toolbar.setTitle(lspName); } else if (searchTerm != null) { - toolbar.setTitle(searchTerm); + binding.toolbar.setTitle(searchTerm); } else { - toolbar.setTitle("Select an Agency"); + binding.toolbar.setTitle("Select an Agency"); } } @@ -258,12 +239,12 @@ private void showNetworkLoading() { private void showLoading() { Timber.v("Show Loading..."); - swipeRefresh.post(() -> swipeRefresh.setRefreshing(true)); + binding.swipeRefresh.post(() -> binding.swipeRefresh.setRefreshing(true)); } private void hideLoading() { Timber.v("Hide Loading..."); - swipeRefresh.post(() -> swipeRefresh.setRefreshing(false)); + binding.swipeRefresh.post(() -> binding.swipeRefresh.setRefreshing(false)); } @@ -330,8 +311,6 @@ public int getCount() { } } - - @OnClick(R2.id.menu) public void onViewClicked() { showAgencyDialog(); } diff --git a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/agency/PreviousAgencyLaunchesFragment.java b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/agency/PreviousAgencyLaunchesFragment.java index fb216e0b8..9cc68fbf5 100644 --- a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/agency/PreviousAgencyLaunchesFragment.java +++ b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/agency/PreviousAgencyLaunchesFragment.java @@ -9,19 +9,13 @@ import java.util.List; -import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; - -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; -import cz.kinst.jakub.view.SimpleStatefulLayout; import me.calebjones.spacelaunchnow.common.R; -import me.calebjones.spacelaunchnow.common.R2; import me.calebjones.spacelaunchnow.common.base.BaseFragment; import me.calebjones.spacelaunchnow.common.content.data.Callbacks; +import me.calebjones.spacelaunchnow.common.databinding.FragmentLaunchListBinding; import me.calebjones.spacelaunchnow.common.prefs.ThemeHelper; import me.calebjones.spacelaunchnow.common.utils.EndlessRecyclerViewScrollListener; import me.calebjones.spacelaunchnow.common.utils.SimpleDividerItemDecoration; @@ -36,12 +30,12 @@ public class PreviousAgencyLaunchesFragment extends BaseFragment { private static final String SEARCH_TERM = "searchTerm"; private static final String LSP_NAME = "lspName"; - @BindView(R2.id.recycler_view) - RecyclerView recyclerView; - @BindView(R2.id.stateful_view) - SimpleStatefulLayout statefulView; - @BindView(R2.id.coordinator) - CoordinatorLayout coordinatorLayout; +// @BindView(R2.id.recycler_view) +// RecyclerView recyclerView; +// @BindView(R2.id.stateful_view) +// SimpleStatefulLayout statefulView; +// @BindView(R2.id.coordinator) +// CoordinatorLayout coordinatorLayout; private LinearLayoutManager linearLayoutManager; private ListAdapter adapter; @@ -53,9 +47,8 @@ public class PreviousAgencyLaunchesFragment extends BaseFragment { public boolean canLoadMore; private boolean statefulStateContentShow = false; private Context context; - private OnFragmentInteractionListener mListener; - private Unbinder unbinder; + private FragmentLaunchListBinding binding; public PreviousAgencyLaunchesFragment() { // Required empty public constructor @@ -93,20 +86,20 @@ public void onCreate(Bundle savedInstanceState) { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_launch_list, container, false); - unbinder = ButterKnife.bind(this, view); + binding = FragmentLaunchListBinding.inflate(inflater, container, false); adapter = new ListAdapter(context, ThemeHelper.isDarkMode(getActivity())); linearLayoutManager = new LinearLayoutManager(context, RecyclerView.VERTICAL, false); - recyclerView.setLayoutManager(linearLayoutManager); - recyclerView.addItemDecoration(new SimpleDividerItemDecoration(context)); - recyclerView.setAdapter(adapter); + binding.recyclerView.setLayoutManager(linearLayoutManager); + binding.recyclerView.addItemDecoration(new SimpleDividerItemDecoration(context)); + binding.recyclerView.setAdapter(adapter); if (adapter.getItemCount() == 0) { - statefulView.showProgress(); + binding.statefulView.showProgress(); } else { - statefulView.showContent(); + binding.statefulView.showContent(); } - statefulView.setOfflineRetryOnClickListener(v -> fetchData(true)); + + binding.statefulView.setOfflineRetryOnClickListener(v -> fetchData(true)); scrollListener = new EndlessRecyclerViewScrollListener(linearLayoutManager) { @Override public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { @@ -119,17 +112,11 @@ public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { } } }; - recyclerView.addOnScrollListener(scrollListener); + + binding.recyclerView.addOnScrollListener(scrollListener); fetchData(true); // Inflate the layout for this fragment - return view; - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - Timber.v("onDestroyView"); - unbinder.unbind(); + return binding.getRoot(); } @Override @@ -143,8 +130,6 @@ public void onAttach(Context context) { } } - - public void fetchData(boolean forceRefresh) { Timber.v("Sending GET_UP_LAUNCHES"); if (forceRefresh) { @@ -170,7 +155,7 @@ public void onNetworkStateChanged(boolean refreshing) { @Override public void onError(String message, @Nullable Throwable throwable) { - statefulView.showOffline(); + binding.statefulView.showOffline(); statefulStateContentShow = false; if (throwable != null) { Timber.e(throwable); @@ -183,16 +168,16 @@ public void onError(String message, @Nullable Throwable throwable) { private void updateAdapter(List launches) { - if (launches.size() > 0) { + if (!launches.isEmpty()) { if (!statefulStateContentShow) { - statefulView.showContent(); + binding.statefulView.showContent(); statefulStateContentShow = true; } adapter.addItems(launches); adapter.notifyDataSetChanged(); } else { - statefulView.showEmpty(); + binding.statefulView.showEmpty(); statefulStateContentShow = false; if (adapter != null) { adapter.clear(); diff --git a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/agency/UpcomingAgencyLaunchesFragment.java b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/agency/UpcomingAgencyLaunchesFragment.java index 458824cb6..526cf4bbb 100644 --- a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/agency/UpcomingAgencyLaunchesFragment.java +++ b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/agency/UpcomingAgencyLaunchesFragment.java @@ -1,9 +1,10 @@ package me.calebjones.spacelaunchnow.common.ui.launchdetail.launches.agency; - import android.content.Context; import android.os.Bundle; + import androidx.annotation.Nullable; + import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -11,18 +12,12 @@ import java.util.ArrayList; import java.util.List; -import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; -import cz.kinst.jakub.view.SimpleStatefulLayout; -import me.calebjones.spacelaunchnow.common.R; -import me.calebjones.spacelaunchnow.common.R2; import me.calebjones.spacelaunchnow.common.base.BaseFragment; import me.calebjones.spacelaunchnow.common.content.data.Callbacks; +import me.calebjones.spacelaunchnow.common.databinding.FragmentLaunchListBinding; import me.calebjones.spacelaunchnow.common.prefs.ThemeHelper; import me.calebjones.spacelaunchnow.common.utils.EndlessRecyclerViewScrollListener; import me.calebjones.spacelaunchnow.common.utils.SimpleDividerItemDecoration; @@ -38,12 +33,7 @@ public class UpcomingAgencyLaunchesFragment extends BaseFragment { private static final String SEARCH_TERM = "searchTerm"; private static final String LSP_NAME = "lspName"; - @BindView(R2.id.recycler_view) - RecyclerView recyclerView; - @BindView(R2.id.stateful_view) - SimpleStatefulLayout statefulView; - @BindView(R2.id.coordinator) - CoordinatorLayout coordinatorLayout; + private LinearLayoutManager linearLayoutManager; private ListAdapter adapter; @@ -57,23 +47,13 @@ public class UpcomingAgencyLaunchesFragment extends BaseFragment { public boolean canLoadMore; private boolean statefulStateContentShow = false; private Context context; - + private FragmentLaunchListBinding binding; private UpcomingAgencyLaunchesFragment.OnFragmentInteractionListener mListener; - private Unbinder unbinder; public UpcomingAgencyLaunchesFragment() { // Required empty public constructor } - /** - * Use this factory method to create a new instance of - * this fragment using the provided parameters. - * - * @param searchTerm Parameter 1. - * @param lspName Parameter 2. - * @return A new instance of fragment PreviousLauncherLaunchesFragment. - */ - // TODO: Rename and change types and number of parameters public static UpcomingAgencyLaunchesFragment newInstance(String searchTerm, String lspName) { UpcomingAgencyLaunchesFragment fragment = new UpcomingAgencyLaunchesFragment(); Bundle args = new Bundle(); @@ -97,16 +77,14 @@ public void onCreate(Bundle savedInstanceState) { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_launch_list, container, false); - unbinder = ButterKnife.bind(this, view); - + binding = FragmentLaunchListBinding.inflate(inflater, container, false); adapter = new ListAdapter(context, ThemeHelper.isDarkMode(getActivity())); linearLayoutManager = new LinearLayoutManager(context, RecyclerView.VERTICAL, false); - recyclerView.setLayoutManager(linearLayoutManager); - recyclerView.addItemDecoration(new SimpleDividerItemDecoration(context)); - recyclerView.setAdapter(adapter); - statefulView.showProgress(); - statefulView.setOfflineRetryOnClickListener(v -> fetchData(true)); + binding.recyclerView.setLayoutManager(linearLayoutManager); + binding.recyclerView.addItemDecoration(new SimpleDividerItemDecoration(context)); + binding.recyclerView.setAdapter(adapter); + binding.statefulView.showProgress(); + binding.statefulView.setOfflineRetryOnClickListener(v -> fetchData(true)); scrollListener = new EndlessRecyclerViewScrollListener(linearLayoutManager) { @Override public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { @@ -118,20 +96,12 @@ public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { } } }; - recyclerView.addOnScrollListener(scrollListener); + binding.recyclerView.addOnScrollListener(scrollListener); fetchData(true); // Inflate the layout for this fragment - return view; - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - Timber.v("onDestroyView"); - unbinder.unbind(); + return binding.getRoot(); } - @Override public void onAttach(Context context) { super.onAttach(context); @@ -139,58 +109,63 @@ public void onAttach(Context context) { mListener = (UpcomingAgencyLaunchesFragment.OnFragmentInteractionListener) context; } else { throw new RuntimeException(context.toString() - + " must implement OnFragmentInteractionListener"); + + " must implement OnFragmentInteractionListener"); } } - - public void fetchData(boolean forceRefresh) { Timber.v("Sending GET_UP_LAUNCHES"); if (forceRefresh) { nextOffset = 0; adapter.clear(); } - upcomingDataRepository.getUpcomingLaunches(nextOffset, searchTerm, lspName, null, null, new Callbacks.ListCallbackMini() { - @Override - public void onLaunchesLoaded(List launches, int next, int total) { - Timber.v("Offset - %s", next); - nextOffset = next; - canLoadMore = next > 0; - updateAdapter(launches); - mListener.setUpcomingBadge(total); - } - - @Override - public void onNetworkStateChanged(boolean refreshing) { - mListener.showUpcomingLoading(refreshing); - } - - @Override - public void onError(String message, @Nullable Throwable throwable) { - statefulView.showOffline(); - statefulStateContentShow = false; - if (throwable != null) { - Timber.e(throwable); - } else { - Timber.e(message); + upcomingDataRepository.getUpcomingLaunches( + nextOffset, + searchTerm, + lspName, + null, + null, + new Callbacks.ListCallbackMini() { + @Override + public void onLaunchesLoaded(List launches, int next, int total) { + Timber.v("Offset - %s", next); + nextOffset = next; + canLoadMore = next > 0; + updateAdapter(launches); + mListener.setUpcomingBadge(total); + } + + @Override + public void onNetworkStateChanged(boolean refreshing) { + mListener.showUpcomingLoading(refreshing); + } + + @Override + public void onError(String message, @Nullable Throwable throwable) { + binding.statefulView.showOffline(); + statefulStateContentShow = false; + if (throwable != null) { + Timber.e(throwable); + } else { + Timber.e(message); + } + } } - } - }); + ); } private void updateAdapter(List launches) { - if (launches.size() > 0) { + if (!launches.isEmpty()) { if (!statefulStateContentShow) { - statefulView.showContent(); + binding.statefulView.showContent(); statefulStateContentShow = true; } adapter.addItems(launches); adapter.notifyDataSetChanged(); } else { - statefulView.showEmpty(); + binding.statefulView.showEmpty(); statefulStateContentShow = false; if (adapter != null) { adapter.clear(); diff --git a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/launcher/LauncherLaunchActivity.java b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/launcher/LauncherLaunchActivity.java index 12bafae59..92940071f 100644 --- a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/launcher/LauncherLaunchActivity.java +++ b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/launcher/LauncherLaunchActivity.java @@ -4,17 +4,13 @@ import android.os.Bundle; import androidx.annotation.NonNull; -import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.content.ContextCompat; -import androidx.appcompat.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import com.google.android.material.appbar.AppBarLayout; -import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.tabs.TabLayout; import java.util.ArrayList; @@ -25,36 +21,21 @@ import androidx.fragment.app.FragmentPagerAdapter; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import androidx.viewpager.widget.ViewPager; -import butterknife.BindView; -import butterknife.ButterKnife; + import me.calebjones.spacelaunchnow.common.R; -import me.calebjones.spacelaunchnow.common.R2; import me.calebjones.spacelaunchnow.common.base.BaseActivityOld; +import me.calebjones.spacelaunchnow.common.databinding.ActivityAgencyLaunchBinding; import me.calebjones.spacelaunchnow.common.ui.settings.SettingsActivity; -import me.calebjones.spacelaunchnow.common.ui.views.custom.BadgeTabLayout; -import me.calebjones.spacelaunchnow.common.utils.Utils; import me.calebjones.spacelaunchnow.data.models.main.Agency; import me.calebjones.spacelaunchnow.common.ui.supporter.SupporterActivity; import timber.log.Timber; -public class LauncherLaunchActivity extends BaseActivityOld implements UpcomingLauncherLaunchesFragment.OnFragmentInteractionListener, - PreviousLauncherLaunchesFragment.OnFragmentInteractionListener, SwipeRefreshLayout.OnRefreshListener { - - - @BindView(R2.id.toolbar) - Toolbar toolbar; - @BindView(R2.id.tabs) - BadgeTabLayout tabLayout; - @BindView(R2.id.appbar) - AppBarLayout appbar; - @BindView(R2.id.container) - ViewPager viewPager; - @BindView(R2.id.main_content) - CoordinatorLayout mainContent; - @BindView(R2.id.swipeRefresh) - SwipeRefreshLayout swipeRefresh; - @BindView(R2.id.menu) - FloatingActionButton menu; +public class LauncherLaunchActivity extends BaseActivityOld implements + UpcomingLauncherLaunchesFragment.OnFragmentInteractionListener, + PreviousLauncherLaunchesFragment.OnFragmentInteractionListener, + SwipeRefreshLayout.OnRefreshListener +{ + private SectionsPagerAdapter mSectionsPagerAdapter; private UpcomingLauncherLaunchesFragment upcomingFragment; @@ -68,15 +49,16 @@ public class LauncherLaunchActivity extends BaseActivityOld implements UpcomingL private String launcherName = null; private String serialNumber = null; private Integer launcherId = null; - private int color; + private ActivityAgencyLaunchBinding binding; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_agency_launch); - ButterKnife.bind(this); - color = ContextCompat.getColor(this, R.color.accent); + binding = ActivityAgencyLaunchBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); + setContentView(view); + Bundle extras = getIntent().getExtras(); if (extras != null) { lspName = extras.getString("lspName"); @@ -86,7 +68,7 @@ protected void onCreate(Bundle savedInstanceState) { } setTitle(); - setSupportActionBar(toolbar); + setSupportActionBar(binding.toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); // Create the adapter that will return a fragment for each of the three @@ -94,33 +76,32 @@ protected void onCreate(Bundle savedInstanceState) { mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. - viewPager.setAdapter(mSectionsPagerAdapter); - viewPager.addOnPageChangeListener( new ViewPager.OnPageChangeListener() { + binding.container.setAdapter(mSectionsPagerAdapter); + binding.container.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override - public void onPageScrolled( int position, float v, int i1 ) { + public void onPageScrolled(int position, float v, int i1) { } @Override - public void onPageSelected( int position ) { + public void onPageSelected(int position) { } @Override - public void onPageScrollStateChanged( int state ) { - enableDisableSwipeRefresh( state == ViewPager.SCROLL_STATE_IDLE ); + public void onPageScrollStateChanged(int state) { + enableDisableSwipeRefresh(state == ViewPager.SCROLL_STATE_IDLE); } - } ); - tabLayout.setupWithViewPager(viewPager); - swipeRefresh.setOnRefreshListener(this); - - viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); - tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager)); - menu.setVisibility(View.GONE); + }); + binding.tabs.setupWithViewPager(binding.container); + binding.swipeRefresh.setOnRefreshListener(this); + + binding.container.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener( + binding.tabs)); + binding.tabs.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(binding.container)); + binding.menu.setVisibility(View.GONE); } private void enableDisableSwipeRefresh(boolean enable) { - if (swipeRefresh != null) { - swipeRefresh.setEnabled(enable); - } + binding.swipeRefresh.setEnabled(enable); } @Override @@ -130,7 +111,6 @@ public void onResume() { } - @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. @@ -197,11 +177,11 @@ private void refresh() { private void setTitle() { if (launcherName != null) { - toolbar.setTitle(launcherName); + binding.toolbar.setTitle(launcherName); } else if (serialNumber != null) { - toolbar.setTitle(serialNumber); + binding.toolbar.setTitle(serialNumber); } else { - toolbar.setTitle("Launches"); + binding.toolbar.setTitle("Launches"); } } @@ -215,25 +195,25 @@ private void showNetworkLoading() { private void showLoading() { Timber.v("Show Loading..."); - swipeRefresh.post(() -> swipeRefresh.setRefreshing(true)); + binding.swipeRefresh.post(() -> binding.swipeRefresh.setRefreshing(true)); } private void hideLoading() { Timber.v("Hide Loading..."); - swipeRefresh.post(() -> swipeRefresh.setRefreshing(false)); + binding.swipeRefresh.post(() -> binding.swipeRefresh.setRefreshing(false)); } @Override public void setUpcomingBadge(int count) { - if (tabLayout != null && count > 0) { - tabLayout.with(0).badge(true).badgeCount(count).name("UPCOMING").build(); + if (count > 0) { + binding.tabs.with(0).badge(true).badgeCount(count).name("UPCOMING").build(); } } @Override public void setPreviousBadge(int count) { - if (tabLayout != null && count > 0) { - tabLayout.with(1).badge(true).badgeCount(count).name("PREVIOUS").build(); + if (count > 0) { + binding.tabs.with(1).badge(true).badgeCount(count).name("PREVIOUS").build(); } } @@ -249,9 +229,19 @@ public Fragment getItem(int position) { switch (position) { case 0: - return UpcomingLauncherLaunchesFragment.newInstance(searchTerm, lspName, launcherId, serialNumber); + return UpcomingLauncherLaunchesFragment.newInstance( + searchTerm, + lspName, + launcherId, + serialNumber + ); case 1: - return PreviousLauncherLaunchesFragment.newInstance(searchTerm, lspName, launcherId, serialNumber); + return PreviousLauncherLaunchesFragment.newInstance( + searchTerm, + lspName, + launcherId, + serialNumber + ); default: return null; } diff --git a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/launcher/PreviousLauncherLaunchesFragment.java b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/launcher/PreviousLauncherLaunchesFragment.java index 534d86950..ad0e40741 100644 --- a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/launcher/PreviousLauncherLaunchesFragment.java +++ b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/launcher/PreviousLauncherLaunchesFragment.java @@ -9,18 +9,12 @@ import java.util.List; -import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; -import cz.kinst.jakub.view.SimpleStatefulLayout; -import me.calebjones.spacelaunchnow.common.R; -import me.calebjones.spacelaunchnow.common.R2; import me.calebjones.spacelaunchnow.common.base.BaseFragment; import me.calebjones.spacelaunchnow.common.content.data.Callbacks; +import me.calebjones.spacelaunchnow.common.databinding.FragmentLaunchListBinding; import me.calebjones.spacelaunchnow.common.utils.EndlessRecyclerViewScrollListener; import me.calebjones.spacelaunchnow.common.utils.SimpleDividerItemDecoration; import me.calebjones.spacelaunchnow.common.content.data.previous.PreviousDataRepository; @@ -36,12 +30,6 @@ public class PreviousLauncherLaunchesFragment extends BaseFragment { private static final String SERIAL_NUMBER = "serialNumber"; private static final String LAUNCHER_ID = "launcherId"; - @BindView(R2.id.recycler_view) - RecyclerView recyclerView; - @BindView(R2.id.stateful_view) - SimpleStatefulLayout statefulView; - @BindView(R2.id.coordinator) - CoordinatorLayout coordinatorLayout; private LinearLayoutManager linearLayoutManager; private ListAdapter adapter; @@ -55,9 +43,8 @@ public class PreviousLauncherLaunchesFragment extends BaseFragment { private boolean statefulStateContentShow = false; private Context context; private Integer launcherId = null; - private OnFragmentInteractionListener mListener; - private Unbinder unbinder; + private FragmentLaunchListBinding binding; public PreviousLauncherLaunchesFragment() { // Required empty public constructor @@ -71,7 +58,6 @@ public PreviousLauncherLaunchesFragment() { * @param lspName Parameter 2. * @return A new instance of fragment PreviousLauncherLaunchesFragment. */ - // TODO: Rename and change types and number of parameters public static PreviousLauncherLaunchesFragment newInstance(String searchTerm, String lspName, Integer launcherId, String serialNumber) { PreviousLauncherLaunchesFragment fragment = new PreviousLauncherLaunchesFragment(); Bundle args = new Bundle(); @@ -102,16 +88,16 @@ public void onCreate(Bundle savedInstanceState) { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_launch_list, container, false); - unbinder = ButterKnife.bind(this, view); + binding = FragmentLaunchListBinding.inflate(inflater, container, false); + adapter = new ListAdapter(context, false); linearLayoutManager = new LinearLayoutManager(context, RecyclerView.VERTICAL, false); - recyclerView.setLayoutManager(linearLayoutManager); - recyclerView.addItemDecoration(new SimpleDividerItemDecoration(context)); - recyclerView.setAdapter(adapter); - statefulView.showProgress(); - statefulView.setOfflineRetryOnClickListener(v -> fetchData(true)); + binding.recyclerView.setLayoutManager(linearLayoutManager); + binding.recyclerView.addItemDecoration(new SimpleDividerItemDecoration(context)); + binding.recyclerView.setAdapter(adapter); + binding.statefulView.showProgress(); + binding.statefulView.setOfflineRetryOnClickListener(v -> fetchData(true)); scrollListener = new EndlessRecyclerViewScrollListener(linearLayoutManager) { @Override public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { @@ -123,17 +109,10 @@ public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { } } }; - recyclerView.addOnScrollListener(scrollListener); + binding.recyclerView.addOnScrollListener(scrollListener); fetchData(true); // Inflate the layout for this fragment - return view; - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - Timber.v("onDestroyView"); - unbinder.unbind(); + return binding.getRoot(); } @Override @@ -148,7 +127,6 @@ public void onAttach(Context context) { } - public void fetchData(boolean forceRefresh) { Timber.v("Sending GET_UP_LAUNCHES"); if (forceRefresh) { @@ -173,7 +151,7 @@ public void onNetworkStateChanged(boolean refreshing) { @Override public void onError(String message, @Nullable Throwable throwable) { - statefulView.showOffline(); + binding.statefulView.showOffline(); statefulStateContentShow = false; if (throwable != null) { Timber.e(throwable); @@ -186,16 +164,16 @@ public void onError(String message, @Nullable Throwable throwable) { private void updateAdapter(List launches) { - if (launches.size() > 0) { + if (!launches.isEmpty()) { if (!statefulStateContentShow) { - statefulView.showContent(); + binding.statefulView.showContent(); statefulStateContentShow = true; } adapter.addItems(launches); adapter.notifyDataSetChanged(); } else { - statefulView.showEmpty(); + binding.statefulView.showEmpty(); statefulStateContentShow = false; if (adapter != null) { adapter.clear(); diff --git a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/launcher/UpcomingLauncherLaunchesFragment.java b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/launcher/UpcomingLauncherLaunchesFragment.java index 2254d3545..15f7b36b5 100644 --- a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/launcher/UpcomingLauncherLaunchesFragment.java +++ b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/launchdetail/launches/launcher/UpcomingLauncherLaunchesFragment.java @@ -3,7 +3,9 @@ import android.content.Context; import android.os.Bundle; + import androidx.annotation.Nullable; + import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -11,19 +13,14 @@ import java.util.ArrayList; import java.util.List; -import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; -import cz.kinst.jakub.view.SimpleStatefulLayout; import me.calebjones.spacelaunchnow.common.R; -import me.calebjones.spacelaunchnow.common.R2; import me.calebjones.spacelaunchnow.common.base.BaseFragment; import me.calebjones.spacelaunchnow.common.content.data.Callbacks; +import me.calebjones.spacelaunchnow.common.databinding.FragmentLaunchListBinding; import me.calebjones.spacelaunchnow.common.utils.EndlessRecyclerViewScrollListener; import me.calebjones.spacelaunchnow.common.utils.SimpleDividerItemDecoration; import me.calebjones.spacelaunchnow.common.content.data.upcoming.UpcomingDataRepository; @@ -40,13 +37,6 @@ public class UpcomingLauncherLaunchesFragment extends BaseFragment { private static final String SERIAL_NUMBER = "serialNumber"; private static final String LAUNCHER_ID = "launcherId"; - @BindView(R2.id.recycler_view) - RecyclerView recyclerView; - @BindView(R2.id.stateful_view) - SimpleStatefulLayout statefulView; - @BindView(R2.id.coordinator) - CoordinatorLayout coordinatorLayout; - private LinearLayoutManager linearLayoutManager; private ListAdapter adapter; private String searchTerm = null; @@ -61,9 +51,9 @@ public class UpcomingLauncherLaunchesFragment extends BaseFragment { private boolean statefulStateContentShow = false; private Context context; private Integer launcherId = null; - private UpcomingLauncherLaunchesFragment.OnFragmentInteractionListener mListener; - private Unbinder unbinder; + private FragmentLaunchListBinding binding; + public UpcomingLauncherLaunchesFragment() { // Required empty public constructor @@ -78,8 +68,10 @@ public UpcomingLauncherLaunchesFragment() { * @return A new instance of fragment PreviousLauncherLaunchesFragment. */ // TODO: Rename and change types and number of parameters - public static UpcomingLauncherLaunchesFragment newInstance(String searchTerm, String lspName, - Integer launcherId, String serialNumber) { + public static UpcomingLauncherLaunchesFragment newInstance(String searchTerm, + String lspName, + Integer launcherId, + String serialNumber) { UpcomingLauncherLaunchesFragment fragment = new UpcomingLauncherLaunchesFragment(); Bundle args = new Bundle(); args.putString(SEARCH_TERM, searchTerm); @@ -98,7 +90,7 @@ public void onCreate(Bundle savedInstanceState) { lspName = getArguments().getString(LSP_NAME); launcherId = getArguments().getInt(LAUNCHER_ID); serialNumber = getArguments().getString(SERIAL_NUMBER); - if (launcherId == 0){ + if (launcherId == 0) { launcherId = null; } } @@ -109,16 +101,16 @@ public void onCreate(Bundle savedInstanceState) { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + binding = FragmentLaunchListBinding.inflate(inflater, container, false); View view = inflater.inflate(R.layout.fragment_launch_list, container, false); - unbinder = ButterKnife.bind(this, view); adapter = new ListAdapter(context, false); linearLayoutManager = new LinearLayoutManager(context, RecyclerView.VERTICAL, false); - recyclerView.setLayoutManager(linearLayoutManager); - recyclerView.addItemDecoration(new SimpleDividerItemDecoration(context)); - recyclerView.setAdapter(adapter); - statefulView.showProgress(); - statefulView.setOfflineRetryOnClickListener(v -> fetchData(true)); + binding.recyclerView.setLayoutManager(linearLayoutManager); + binding.recyclerView.addItemDecoration(new SimpleDividerItemDecoration(context)); + binding.recyclerView.setAdapter(adapter); + binding.statefulView.showProgress(); + binding.statefulView.setOfflineRetryOnClickListener(v -> fetchData(true)); scrollListener = new EndlessRecyclerViewScrollListener(linearLayoutManager) { @Override public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { @@ -130,20 +122,12 @@ public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { } } }; - recyclerView.addOnScrollListener(scrollListener); + binding.recyclerView.addOnScrollListener(scrollListener); fetchData(true); // Inflate the layout for this fragment return view; } - @Override - public void onDestroyView() { - super.onDestroyView(); - Timber.v("onDestroyView"); - unbinder.unbind(); - } - - @Override public void onAttach(Context context) { super.onAttach(context); @@ -151,7 +135,7 @@ public void onAttach(Context context) { mListener = (UpcomingLauncherLaunchesFragment.OnFragmentInteractionListener) context; } else { throw new RuntimeException(context.toString() - + " must implement OnFragmentInteractionListener"); + + " must implement OnFragmentInteractionListener"); } } @@ -162,46 +146,53 @@ public void fetchData(boolean forceRefresh) { nextOffset = 0; adapter.clear(); } - upcomingDataRepository.getUpcomingLaunches(nextOffset, searchTerm, lspName, serialNumber, launcherId, new Callbacks.ListCallbackMini() { - @Override - public void onLaunchesLoaded(List launches, int next, int total) { - Timber.v("Offset - %s", next); - nextOffset = next; - canLoadMore = next > 0; - updateAdapter(launches); - mListener.setUpcomingBadge(total); - } - - @Override - public void onNetworkStateChanged(boolean refreshing) { - mListener.showUpcomingLoading(refreshing); - } - - @Override - public void onError(String message, @Nullable Throwable throwable) { - statefulView.showOffline(); - statefulStateContentShow = false; - if (throwable != null) { - Timber.e(throwable); - } else { - Timber.e(message); + upcomingDataRepository.getUpcomingLaunches( + nextOffset, + searchTerm, + lspName, + serialNumber, + launcherId, + new Callbacks.ListCallbackMini() { + @Override + public void onLaunchesLoaded(List launches, int next, int total) { + Timber.v("Offset - %s", next); + nextOffset = next; + canLoadMore = next > 0; + updateAdapter(launches); + mListener.setUpcomingBadge(total); + } + + @Override + public void onNetworkStateChanged(boolean refreshing) { + mListener.showUpcomingLoading(refreshing); + } + + @Override + public void onError(String message, @Nullable Throwable throwable) { + binding.statefulView.showOffline(); + statefulStateContentShow = false; + if (throwable != null) { + Timber.e(throwable); + } else { + Timber.e(message); + } + } } - } - }); + ); } private void updateAdapter(List launches) { - if (launches.size() > 0) { + if (!launches.isEmpty()) { if (!statefulStateContentShow) { - statefulView.showContent(); + binding.statefulView.showContent(); statefulStateContentShow = true; } adapter.addItems(launches); adapter.notifyDataSetChanged(); } else { - statefulView.showEmpty(); + binding.statefulView.showEmpty(); statefulStateContentShow = false; if (adapter != null) { adapter.clear(); diff --git a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/supporter/SupporterActivity.java b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/supporter/SupporterActivity.java index 9d78ce7f3..d2f784552 100644 --- a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/supporter/SupporterActivity.java +++ b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/supporter/SupporterActivity.java @@ -7,11 +7,8 @@ import android.net.Uri; import android.os.Bundle; -import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.content.ContextCompat; -import androidx.core.widget.NestedScrollView; import androidx.appcompat.widget.AppCompatButton; -import androidx.appcompat.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; @@ -24,21 +21,17 @@ import com.android.billingclient.api.ConsumeParams; import com.android.billingclient.api.ConsumeResponseListener; import com.android.billingclient.api.ProductDetails; -import com.android.billingclient.api.ProductDetailsResponseListener; import com.google.common.collect.ImmutableList; import com.android.billingclient.api.BillingClient; import com.android.billingclient.api.BillingClientStateListener; import com.android.billingclient.api.BillingResult; import com.android.billingclient.api.Purchase; import com.android.billingclient.api.PurchaseHistoryRecord; -import com.android.billingclient.api.PurchaseHistoryResponseListener; import com.android.billingclient.api.PurchasesUpdatedListener; import com.android.billingclient.api.QueryProductDetailsParams; import com.android.billingclient.api.QueryPurchaseHistoryParams; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.bottomsheet.BottomSheetDialog; -import com.google.android.material.floatingactionbutton.FloatingActionButton; -import com.google.firebase.analytics.FirebaseAnalytics; import com.mikepenz.fontawesome_typeface_library.FontAwesome; import com.mikepenz.google_material_typeface_library.GoogleMaterial; import com.mikepenz.iconics.IconicsDrawable; @@ -48,43 +41,22 @@ import java.util.ArrayList; import java.util.List; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import io.realm.Realm; + import me.calebjones.spacelaunchnow.common.R; -import me.calebjones.spacelaunchnow.common.R2; import me.calebjones.spacelaunchnow.common.base.BaseActivity; -import me.calebjones.spacelaunchnow.data.models.Products; +import me.calebjones.spacelaunchnow.common.databinding.ActivitySupportBinding; import timber.log.Timber; import static me.calebjones.spacelaunchnow.common.ui.supporter.SupporterHelper.isOwned; public class SupporterActivity extends BaseActivity { - @BindView(R2.id.purchase) - AppCompatButton purchaseButton; - @BindView(R2.id.coordinatorLayout) - CoordinatorLayout coordinatorLayout; - @BindView(R2.id.toolbar) - Toolbar toolbar; - @BindView(R2.id.app_bar_layout) - AppBarLayout appBarLayout; - @BindView(R2.id.support_thank_you) - View supportThankYou; - @BindView(R2.id.fab_supporter) - FloatingActionButton fabSupporter; - @BindView(R2.id.nested_scroll_view) - NestedScrollView nestedScrollView; - @BindView(R2.id.detail_title) - TextView title; - @BindView(R2.id.detail_sub_title) - TextView subtitle; private boolean isAvailable = false; private boolean isRefreshable = true; private Dialog dialog; private List ownedProducts; + private ActivitySupportBinding binding; private PurchasesUpdatedListener purchasesUpdatedListener = (billingResult, purchases) -> { @@ -128,29 +100,30 @@ private void handlePurchase(Purchase purchase) { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + binding = ActivitySupportBinding.inflate(getLayoutInflater()); + View view = binding.getRoot(); + setContentView(view); + context = this; - setContentView(R.layout.activity_support); - ButterKnife.bind(this); ownedProducts = new ArrayList<>(); - if (SupporterHelper.is2024Supporter()) { - purchaseButton.setText(R.string.support_us_2022); - title.setText("Thank You!"); - subtitle.setText("Here's to another year..."); + binding.purchase.setText(R.string.support_us_2022); + binding.detailTitle.setText("Thank You!"); + binding.detailSubTitle.setText("Here's to another year..."); } else if (SupporterHelper.isSupporter() && !SupporterHelper.is2024Supporter()) { - purchaseButton.setText(R.string.support_again_2024); - title.setText("Become a 2024 Supporter"); - subtitle.setText("Continue Your Support!"); + binding.purchase.setText(R.string.support_again_2024); + binding.detailTitle.setText("Become a 2024 Supporter"); + binding.detailSubTitle.setText("Continue Your Support!"); } else { - title.setText("Become a Supporter"); - subtitle.setText("Get Pro Features"); - purchaseButton.setText(R.string.supporter_title_2022); + binding.purchase.setText(R.string.supporter_title_2022); + binding.detailTitle.setText("Become a Supporter"); + binding.detailSubTitle.setText("Get Pro Features"); } - setSupportActionBar(toolbar); + setSupportActionBar(binding.toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - toolbar.setTitle(""); + binding.toolbar.setTitle(""); billingClient = BillingClient.newBuilder(context) .setListener(purchasesUpdatedListener) @@ -175,6 +148,8 @@ public void onBillingServiceDisconnected() { } }); + binding.purchase.setOnClickListener(v -> checkClick()); + binding.fabSupporter.setOnClickListener(v -> checkClick()); } private void restorePurchases() { @@ -188,7 +163,7 @@ private void restorePurchases() { // process returned purchase history list, e.g. display purchase history Timber.v(billingResult.getDebugMessage()); if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) { - if (purchasesHistoryList.size() > 0) { + if (purchasesHistoryList != null && !purchasesHistoryList.isEmpty()) { for (PurchaseHistoryRecord purchase : purchasesHistoryList) { handlePurchaseHistoryRecord(purchase); } @@ -266,7 +241,6 @@ public boolean onCreateOptionsMenu(Menu menu) { return true; } - @OnClick({R2.id.purchase, R2.id.fab_supporter}) public void checkClick() { if (billingClient.isReady()) { QueryProductDetailsParams queryProductDetailsParams = @@ -475,20 +449,20 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { private void animatePurchase() { runOnUiThread(() -> { - if (supportThankYou.getVisibility() != View.VISIBLE) { - enterReveal(supportThankYou); + if (binding.supportThankYou.getVisibility() != View.VISIBLE) { + enterReveal(binding.supportThankYou); if (SupporterHelper.is2024Supporter()) { - purchaseButton.setText(R.string.support_us_2022); - title.setText("Thank You!"); - subtitle.setText("Here's to another year..."); + binding.purchase.setText(R.string.support_us_2022); + binding.detailTitle.setText("Thank You!"); + binding.detailSubTitle.setText("Here's to another year..."); } else if (SupporterHelper.isSupporter() && !SupporterHelper.is2024Supporter()) { - purchaseButton.setText(R.string.support_again_2024); - title.setText("Become a 2024 Supporter"); - subtitle.setText("Continue Your Support!"); + binding.purchase.setText(R.string.support_again_2024); + binding.detailTitle.setText("Become a 2024 Supporter"); + binding.detailSubTitle.setText("Continue Your Support!"); } else { - title.setText("Become a Supporter"); - subtitle.setText("Get Pro Features"); - purchaseButton.setText(R.string.supporter_title_2022); + binding.purchase.setText(R.string.supporter_title_2022); + binding.detailTitle.setText("Become a Supporter"); + binding.detailSubTitle.setText("Get Pro Features"); } } }); @@ -505,7 +479,7 @@ void enterReveal(View view) { AppBarLayout.LayoutParams.MATCH_PARENT, AppBarLayout.LayoutParams.WRAP_CONTENT )); - TransitionManager.beginDelayedTransition(coordinatorLayout); + TransitionManager.beginDelayedTransition(binding.coordinatorLayout); myView.setVisibility(View.VISIBLE); }); } diff --git a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/views/custom/CountDownView.java b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/views/custom/CountDownView.java index 9a7170dd2..1c09494c7 100644 --- a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/views/custom/CountDownView.java +++ b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/views/custom/CountDownView.java @@ -2,10 +2,9 @@ import android.content.Context; import android.util.AttributeSet; +import android.view.LayoutInflater; import android.view.View; -import android.widget.TextView; -import java.text.DateFormat; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; @@ -14,42 +13,22 @@ import androidx.annotation.Nullable; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintSet; -import androidx.constraintlayout.widget.Group; -import butterknife.BindView; -import butterknife.ButterKnife; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import me.calebjones.spacelaunchnow.common.R; -import me.calebjones.spacelaunchnow.common.R2; +import me.calebjones.spacelaunchnow.common.databinding.CountdownLayoutViewBinding; import me.calebjones.spacelaunchnow.data.models.main.Launch; import me.calebjones.spacelaunchnow.common.ui.views.CountDownTimer; import timber.log.Timber; public class CountDownView extends ConstraintLayout { - @BindView(R2.id.common_countdown_layout) - ConstraintLayout constraintLayout; - @BindView(R2.id.countdown_days) - TextView countdownDays; - @BindView(R2.id.countdown_hours) - TextView countdownHours; - @BindView(R2.id.countdown_minutes) - TextView countdownMinutes; - @BindView(R2.id.countdown_seconds) - TextView countdownSeconds; - @BindView(R2.id.countdown_status) - TextView countdownStatus; - @BindView(R2.id.status_pill) - StatusPillView statusPill; - @BindView(R2.id.common_status_reason) - TextView statusReason; - @BindView(R2.id.countdown_view_group) - Group countdownGroup; private CountDownTimer timer; private Disposable var; private Launch launch; private Context context; + private CountdownLayoutViewBinding binding; public CountDownView(Context context) { super(context); @@ -68,9 +47,8 @@ public CountDownView(Context context, @Nullable AttributeSet attrs, int defStyle private void init(Context context) { - inflate(context, R.layout.countdown_layout_view, this); - ButterKnife.setDebug(true); - ButterKnife.bind(this); + LayoutInflater inflater = LayoutInflater.from(context); + binding = CountdownLayoutViewBinding.inflate(inflater); this.context = context; } @@ -92,12 +70,12 @@ private void startLaunchCountdown(long timeToFinish) { @Override public void onFinish() { Timber.v("Countdown finished."); - countdownDays.setText("00"); - countdownHours.setText("00"); - countdownMinutes.setText("00"); - countdownSeconds.setText("00"); - countdownStatus.setVisibility(View.VISIBLE); - countdownStatus.setText("+"); + binding.countdownDays.setText("00"); + binding.countdownHours.setText("00"); + binding.countdownMinutes.setText("00"); + binding.countdownSeconds.setText("00"); + binding.countdownStatus.setVisibility(View.VISIBLE); + binding.countdownStatus.setText("+"); if (launch.isValid()) { countUpTimer(launch.getNet().getTime()); } @@ -112,23 +90,23 @@ public void onTick(long millisUntilFinished) { } private void setLaunchCountdownComplete() { - countdownDays.setText("00"); - countdownHours.setText("00"); - countdownMinutes.setText("00"); - countdownSeconds.setText("00"); + binding.countdownDays.setText("00"); + binding.countdownHours.setText("00"); + binding.countdownMinutes.setText("00"); + binding.countdownSeconds.setText("00"); } private void launchInFlight() { - countdownStatus.setVisibility(View.VISIBLE); + binding.countdownStatus.setVisibility(View.VISIBLE); countUpTimer(launch.getNet().getTime()); } private void launchStatusUnknown() { - countdownDays.setText("- -"); - countdownHours.setText("- -"); - countdownMinutes.setText("- -"); - countdownSeconds.setText("- -"); - countdownGroup.setVisibility(GONE); + binding.countdownDays.setText("- -"); + binding.countdownHours.setText("- -"); + binding.countdownMinutes.setText("- -"); + binding.countdownSeconds.setText("- -"); + binding.countdownViewGroup.setVisibility(GONE); } private void countUpTimer(long longDate) { @@ -185,46 +163,46 @@ private void setCountdownView(long millisUntilFinished) { try { // Update the views if (Integer.valueOf(days) > 0) { - countdownDays.setText(days); + binding.countdownDays.setText(days); } else { - countdownDays.setText("00"); + binding.countdownDays.setText("00"); } if (Integer.valueOf(hours) > 0) { - countdownHours.setText(hours); + binding.countdownHours.setText(hours); } else if (Integer.valueOf(days) > 0) { - countdownHours.setText("00"); + binding.countdownHours.setText("00"); } else { - countdownHours.setText("00"); + binding.countdownHours.setText("00"); } if (Integer.valueOf(minutes) > 0) { - countdownMinutes.setText(minutes); + binding.countdownMinutes.setText(minutes); } else if (Integer.valueOf(hours) > 0 || Integer.valueOf(days) > 0) { - countdownMinutes.setText("00"); + binding.countdownMinutes.setText("00"); } else { - countdownMinutes.setText("00"); + binding.countdownMinutes.setText("00"); } if (Integer.valueOf(seconds) > 0) { - countdownSeconds.setText(seconds); + binding.countdownSeconds.setText(seconds); } else if (Integer.valueOf(minutes) > 0 || Integer.valueOf(hours) > 0 || Integer.valueOf(days) > 0) { - countdownSeconds.setText("00"); + binding.countdownSeconds.setText("00"); } else { - countdownSeconds.setText("00"); + binding.countdownSeconds.setText("00"); } } catch (NumberFormatException e) { - countdownHours.setText("00"); - countdownDays.setText("00"); - countdownMinutes.setText("00"); - countdownSeconds.setText("00"); + binding.countdownHours.setText("00"); + binding.countdownDays.setText("00"); + binding.countdownMinutes.setText("00"); + binding.countdownSeconds.setText("00"); } } public void setLaunch(Launch launch) { this.launch = launch; checkCountdownTimer(this.launch); - statusPill.setStatus(launch); + binding.statusPill.setStatus(launch); } private void checkCountdownTimer(Launch launch) { @@ -240,34 +218,34 @@ private void checkCountdownTimer(Launch launch) { String hold = launch.getHoldreason(); String failure = launch.getFailreason(); - statusReason.setVisibility(GONE); + binding.commonStatusReason.setVisibility(GONE); if (hold != null && hold.length() > 0) { - statusReason.setText(hold); + binding.commonStatusReason.setText(hold); setReasonConstraintToBottom(); - statusReason.setVisibility(VISIBLE); + binding.commonStatusReason.setVisibility(VISIBLE); } if (failure != null && failure.length() > 0) { - statusReason.setText(failure); + binding.commonStatusReason.setText(failure); setReasonConstraintToBottom(); - statusReason.setVisibility(VISIBLE); + binding.commonStatusReason.setVisibility(VISIBLE); } if (launch.getStatus().getId() == 2){ - statusReason.setText(R.string.date_unconfirmed); - statusReason.setVisibility(VISIBLE); + binding.commonStatusReason.setText(R.string.date_unconfirmed); + binding.commonStatusReason.setVisibility(VISIBLE); setReasonConstraintToStatusPill(); } else if (launch.getStatus().getId() == 8){ - statusReason.setText(R.string.to_be_confirmed); + binding.commonStatusReason.setText(R.string.to_be_confirmed); setReasonConstraintToStatusPill(); - statusReason.setVisibility(VISIBLE); + binding.commonStatusReason.setVisibility(VISIBLE); } else { - statusReason.setVisibility(GONE); + binding.commonStatusReason.setVisibility(GONE); } long timeToFinish = launchDate.getTimeInMillis() - now.getTimeInMillis(); - countdownGroup.setVisibility(VISIBLE); - if (timeToFinish > 0 && (launch.getStatus().getId() == 1 || launch.getStatus().getId() == 1)) { + binding.countdownViewGroup.setVisibility(VISIBLE); + if (timeToFinish > 0 && launch.getStatus().getId() == 1) { startLaunchCountdown(timeToFinish); } else if (launch.getStatus().getId() == 3 || launch.getStatus().getId() == 4 || launch.getStatus().getId() == 7) { setLaunchCountdownComplete(); @@ -280,16 +258,16 @@ private void checkCountdownTimer(Launch launch) { private void setReasonConstraintToBottom() { ConstraintSet constraintSet = new ConstraintSet(); - constraintSet.clone(constraintLayout); + constraintSet.clone(binding.commonCountdownLayout); constraintSet.connect(R.id.common_status_reason, ConstraintSet.TOP, R.id.bottom_divider, ConstraintSet.BOTTOM,60); - constraintSet.applyTo(constraintLayout); + constraintSet.applyTo(binding.commonCountdownLayout); } private void setReasonConstraintToStatusPill() { ConstraintSet constraintSet = new ConstraintSet(); - constraintSet.clone(constraintLayout); + constraintSet.clone(binding.commonCountdownLayout); constraintSet.connect(R.id.common_status_reason, ConstraintSet.TOP, R.id.status_pill, ConstraintSet.BOTTOM,20); - constraintSet.applyTo(constraintLayout); + constraintSet.applyTo(binding.commonCountdownLayout); } public Calendar DateToCalendar(Date date) { diff --git a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/views/custom/StatusPillView.java b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/views/custom/StatusPillView.java index 25d6fb50a..78e2f3bf6 100644 --- a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/views/custom/StatusPillView.java +++ b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/views/custom/StatusPillView.java @@ -2,25 +2,19 @@ import android.content.Context; import android.util.AttributeSet; +import android.view.LayoutInflater; import android.widget.FrameLayout; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.cardview.widget.CardView; -import butterknife.BindView; -import butterknife.ButterKnife; -import me.calebjones.spacelaunchnow.common.R; -import me.calebjones.spacelaunchnow.common.R2; + import me.calebjones.spacelaunchnow.common.content.LaunchStatusUtil; +import me.calebjones.spacelaunchnow.common.databinding.StatusPillBinding; import me.calebjones.spacelaunchnow.data.models.main.Launch; public class StatusPillView extends FrameLayout { - @BindView(R2.id.status) - TextView status; - @BindView(R2.id.status_pill_layout) - CardView statusPill; + private StatusPillBinding binding; private Context context; public StatusPillView(@NonNull Context context) { @@ -33,19 +27,27 @@ public StatusPillView(@NonNull Context context, @Nullable AttributeSet attrs) { init(context); } - public StatusPillView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + public StatusPillView(@NonNull Context context, + @Nullable AttributeSet attrs, + int defStyleAttr) { super(context, attrs, defStyleAttr); init(context); } private void init(Context context) { - inflate(context, R.layout.status_pill, this); - ButterKnife.bind(this); + LayoutInflater inflater = LayoutInflater.from(context); + binding = StatusPillBinding.inflate(inflater); this.context = context; } public void setStatus(Launch launch) { - status.setText(LaunchStatusUtil.getLaunchStatusTitle(context, launch.getStatus().getId())); - statusPill.setCardBackgroundColor(LaunchStatusUtil.getLaunchStatusColor(context, launch.getStatus().getId())); + binding.status.setText(LaunchStatusUtil.getLaunchStatusTitle( + context, + launch.getStatus().getId() + )); + binding.statusPillLayout.setCardBackgroundColor(LaunchStatusUtil.getLaunchStatusColor( + context, + launch.getStatus().getId() + )); } } diff --git a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/views/custom/WeatherCard.java b/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/views/custom/WeatherCard.java deleted file mode 100644 index 62edc1452..000000000 --- a/common/src/main/java/me/calebjones/spacelaunchnow/common/ui/views/custom/WeatherCard.java +++ /dev/null @@ -1,408 +0,0 @@ -package me.calebjones.spacelaunchnow.common.ui.views.custom; - -import android.content.Context; -import android.content.SharedPreferences; -import android.graphics.Color; -import android.preference.PreferenceManager; -import android.util.AttributeSet; -import android.view.View; -import android.widget.TextView; -import android.zetterstrom.com.forecast.models.DataPoint; -import android.zetterstrom.com.forecast.models.Forecast; - -import com.github.pwittchen.weathericonview.WeatherIconView; - -import java.text.SimpleDateFormat; - -import androidx.annotation.Nullable; -import androidx.cardview.widget.CardView; -import androidx.constraintlayout.widget.ConstraintLayout; -import androidx.constraintlayout.widget.Group; -import butterknife.BindView; -import butterknife.ButterKnife; -import me.calebjones.spacelaunchnow.common.R; -import me.calebjones.spacelaunchnow.common.R2; -import me.calebjones.spacelaunchnow.common.utils.Utils; - -public class WeatherCard extends CardView { - - @BindView(R2.id.weather_title) - TextView weatherTitle; - @BindView(R2.id.weather_icon) - WeatherIconView weatherIcon; - @BindView(R2.id.weather_percip_chance_icon) - WeatherIconView weatherPrecipIcon; - @BindView(R2.id.weather_percip_chance) - TextView weatherPercipChance; - @BindView(R2.id.weather_wind_speed_icon) - WeatherIconView weatherSpeedIcon; - @BindView(R2.id.weather_wind_speed) - TextView weatherWindSpeed; - @BindView(R2.id.weather_current_temp) - TextView weatherCurrentTemp; - @BindView(R2.id.weather_feels_like) - TextView weatherFeelsLike; - @BindView(R2.id.weather_low_high) - TextView weatherLowHigh; - @BindView(R2.id.weather_summary_day) - TextView weatherSummaryDay; - @BindView(R2.id.weather_location) - TextView weatherLocation; - @BindView(R2.id.day_two_weather_icon) - WeatherIconView dayTwoWeatherIcon; - @BindView(R2.id.day_two_day) - TextView dayTwoDay; - @BindView(R2.id.day_two_low_high) - TextView dayTwoWeatherLowHigh; - @BindView(R2.id.day_two_precip_prob_icon) - WeatherIconView dayTwoWeatherPrecipIcon; - @BindView(R2.id.day_two_precip_prob) - TextView dayTwoWeatherPrecip; - @BindView(R2.id.day_two_weather_wind_speed_icon) - WeatherIconView dayTwoWeatherWindIcon; - @BindView(R2.id.day_two_weather_wind_speed) - TextView dayTwoWeatherWindSpeed; - @BindView(R2.id.day_three_weather_icon) - WeatherIconView dayThreeWeatherIcon; - @BindView(R2.id.day_three_day) - TextView dayThreeDay; - @BindView(R2.id.day_three_low_high) - TextView dayThreeWeatherLowHigh; - @BindView(R2.id.day_three_precip_prob_icon) - WeatherIconView dayThreeWeatherPrecipIcon; - @BindView(R2.id.day_three_precip_prob) - TextView dayThreeWeatherPrecip; - @BindView(R2.id.day_three_weather_wind_speed_icon) - WeatherIconView dayThreeWeatherWindIcon; - @BindView(R2.id.day_three_weather_wind_speed) - TextView dayThreeWeatherWindSpeed; - @BindView(R2.id.day_four_weather_icon) - WeatherIconView dayFourWeatherIcon; - @BindView(R2.id.day_four_day) - TextView dayFourDay; - @BindView(R2.id.day_four_low_high) - TextView dayFourWeatherLowHigh; - @BindView(R2.id.day_four_precip_prob_icon) - WeatherIconView dayFourWeatherPrecipIcon; - @BindView(R2.id.day_four_precip_prob) - TextView dayFourWeatherPrecip; - @BindView(R2.id.day_four_weather_wind_speed_icon) - WeatherIconView dayFourWeatherWindIcon; - @BindView(R2.id.day_four_weather_wind_speed) - TextView dayFourWeatherWindSpeed; - @BindView(R2.id.three_day_forecast) - Group threeDayForecast; - @BindView(R2.id.constraintLayout) - ConstraintLayout constraintLayout; - - private SharedPreferences sharedPref; - private boolean nightMode = false; - private boolean current = true; - private Forecast forecast; - private String location; - - public WeatherCard(Context context) { - super(context); - init(context); - } - - public WeatherCard(Context context, @Nullable AttributeSet attrs) { - super(context, attrs); - init(context); - } - - public WeatherCard(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - init(context); - } - - private void init(Context context) { - inflate(context, R.layout.custom_weather_card, this); - ButterKnife.bind(this); - sharedPref = PreferenceManager.getDefaultSharedPreferences(context); - } - - public void setNightMode(boolean nightMode) { - this.nightMode = nightMode; - } - - ; - - public void setWeather(Forecast forecast, String location, boolean current, boolean nightMode) { - this.forecast = forecast; - this.current = current; - this.location = location; - this.nightMode = nightMode; - if (current) { - updateCurrentWeatherView(forecast, location); - } else { - updatePastWeatherView(forecast, location); - } - } - - public void setTitle(String title) { - weatherTitle.setText(title); - } - - private void updateCurrentWeatherView(Forecast forecast, String location) { - final String temp; - final String speed; - String precip; - String pressure; - String visibility; - - if (sharedPref.getBoolean("weather_US_SI", true)) { - temp = "F"; - speed = "Mph"; - precip = "in."; - pressure = "mb"; - visibility = "mile"; - } else { - temp = "C"; - speed = "m/s"; - precip = "cm"; - pressure = "hPa"; - visibility = "km"; - } - if (forecast.getCurrently() != null) { - if (forecast.getCurrently().getTemperature() != null) { - String currentTemp = String.valueOf(Math.round(forecast.getCurrently().getTemperature())) + (char) 0x00B0 + " " + temp; - weatherCurrentTemp.setText(currentTemp); - } - if (forecast.getCurrently().getApparentTemperature() != null) { - String feelsLikeTemp = "Feels like "; - feelsLikeTemp = feelsLikeTemp + String.valueOf(Math.round(forecast.getCurrently().getApparentTemperature())) + (char) 0x00B0; - weatherFeelsLike.setText(feelsLikeTemp); - } - - if (forecast.getCurrently().getWindSpeed() != null) { - String windSpeed = String.valueOf(Math.round(forecast.getCurrently().getWindSpeed())) + " " + speed; - weatherWindSpeed.setText(windSpeed); - } - } - if (forecast.getDaily() != null && forecast.getDaily().getDataPoints() != null && forecast.getDaily().getDataPoints().size() > 0) { - String highTemp = String.valueOf(Math.round(forecast.getDaily().getDataPoints().get(0).getTemperatureMax())); - String lowTemp = String.valueOf(Math.round(forecast.getDaily().getDataPoints().get(0).getTemperatureMin())); - String lowHigh = lowTemp + (char) 0x00B0 + " " + temp + " | " + highTemp + (char) 0x00B0 + " " + temp; - weatherLowHigh.setText(lowHigh); - - if (forecast.getDaily().getDataPoints().get(0).getPrecipProbability() != null) { - String precipProb = String.valueOf(Math.round(forecast.getDaily().getDataPoints().get(0).getPrecipProbability() * 100) + "%"); - weatherPercipChance.setText(precipProb); - } - - if (forecast.getDaily().getDataPoints().size() >= 3) { - - DataPoint dayOne = forecast.getDaily().getDataPoints().get(1); - - if (dayOne.getIcon() != null && dayOne.getIcon().getText() != null) { - //Day One! - setIconView(dayTwoWeatherIcon, dayOne.getIcon().getText()); - } - - String dayTwoLowHigh = ""; - if (dayOne.getTemperatureMax() != null && dayOne.getTemperatureMin() != null) { - //Get Low - High temp - String dayTwoHighTemp = String.valueOf(Math.round(dayOne.getTemperatureMax())); - String dayTwoLowTemp = String.valueOf(Math.round(dayOne.getTemperatureMin())); - dayTwoLowHigh = dayTwoLowTemp + (char) 0x00B0 + " " + temp + " | " + dayTwoHighTemp + (char) 0x00B0 + " " + temp; - } - - //Get rain prop - String dayTwoPrecipProb = String.valueOf(Math.round(forecast.getDaily().getDataPoints().get(1).getPrecipProbability() * 100) + "%"); - - //Get Wind speed - String dayTwoWindSpeed = String.valueOf(Math.round(forecast.getDaily().getDataPoints().get(1).getWindSpeed())) + " " + speed; - - //Get day date - String dayTwoDate = new SimpleDateFormat("EE ").format(forecast.getDaily().getDataPoints().get(1).getTime()); - - dayTwoWeatherLowHigh.setText(dayTwoLowHigh); - dayTwoWeatherPrecip.setText(dayTwoPrecipProb); - dayTwoWeatherWindSpeed.setText(dayTwoWindSpeed); - dayTwoDay.setText(dayTwoDate); - - //Day Two! - setIconView(dayThreeWeatherIcon, forecast.getDaily().getDataPoints().get(2).getIcon().getText()); - - //Get Low - High temp - String dayThreeHighTemp = String.valueOf(Math.round(forecast.getDaily().getDataPoints().get(2).getTemperatureMax())); - String dayThreeLowTemp = String.valueOf(Math.round(forecast.getDaily().getDataPoints().get(2).getTemperatureMin())); - String dayThreeLowHigh = dayThreeLowTemp + (char) 0x00B0 + " " + temp + " | " + dayThreeHighTemp + (char) 0x00B0 + " " + temp; - - //Get rain prop - String dayThreePrecipProb = String.valueOf(Math.round(forecast.getDaily().getDataPoints().get(2).getPrecipProbability() * 100) + "%"); - - //Get Wind speed - String dayThreeWindSpeed = String.valueOf(Math.round(forecast.getDaily().getDataPoints().get(2).getWindSpeed())) + " " + speed; - - //Get day date - String dayThreeDate = new SimpleDateFormat("EE").format(forecast.getDaily().getDataPoints().get(2).getTime()); - - dayThreeWeatherLowHigh.setText(dayThreeLowHigh); - dayThreeWeatherPrecip.setText(dayThreePrecipProb); - dayThreeWeatherWindSpeed.setText(dayThreeWindSpeed); - dayThreeDay.setText(dayThreeDate); - - //Day Three! - setIconView(dayFourWeatherIcon, forecast.getDaily().getDataPoints().get(3).getIcon().getText()); - - //Get Low - High temp - String dayFourHighTemp = String.valueOf(Math.round(forecast.getDaily().getDataPoints().get(3).getTemperatureMax())); - String dayFourLowTemp = String.valueOf(Math.round(forecast.getDaily().getDataPoints().get(3).getTemperatureMin())); - String dayFourLowHigh = dayFourLowTemp + (char) 0x00B0 + " " + temp + " | " + dayFourHighTemp + (char) 0x00B0 + " " + temp; - - String dayFourPrecipProb = String.valueOf(Math.round(forecast.getDaily().getDataPoints().get(3).getPrecipProbability() * 100) + "%"); - - //Get Wind speed - String dayFourWindSpeed = String.valueOf(Math.round(forecast.getDaily().getDataPoints().get(3).getWindSpeed())) + " " + speed; - - //Get day date - String dayFourDate = new SimpleDateFormat("EE").format(forecast.getDaily().getDataPoints().get(3).getTime()); - - dayFourWeatherLowHigh.setText(dayFourLowHigh); - dayFourWeatherPrecip.setText(dayFourPrecipProb); - dayFourWeatherWindSpeed.setText(dayFourWindSpeed); - dayFourDay.setText(dayFourDate); - } else { - threeDayForecast.setVisibility(View.GONE); - } - } - - if (forecast.getCurrently().getIcon() != null && forecast.getCurrently().getIcon().getText() != null) { - setIconView(weatherIcon, forecast.getCurrently().getIcon().getText()); - } - - if (forecast.getDaily() != null && forecast.getDaily().getSummary() != null) { - weatherSummaryDay.setText(forecast.getDaily().getSummary()); - } else if (forecast.getCurrently() != null && forecast.getCurrently().getSummary() != null) { - weatherSummaryDay.setText(forecast.getCurrently().getSummary()); - } else { - weatherSummaryDay.setVisibility(View.GONE); - } - - weatherLocation.setText(location); - - if (nightMode) { - dayTwoWeatherWindIcon.setIconColor(Color.WHITE); - dayTwoWeatherPrecipIcon.setIconColor(Color.WHITE); - dayThreeWeatherWindIcon.setIconColor(Color.WHITE); - dayThreeWeatherPrecipIcon.setIconColor(Color.WHITE); - dayFourWeatherWindIcon.setIconColor(Color.WHITE); - dayFourWeatherPrecipIcon.setIconColor(Color.WHITE); - weatherPrecipIcon.setIconColor(Color.WHITE); - weatherSpeedIcon.setIconColor(Color.WHITE); - } - } - - private void updatePastWeatherView(Forecast forecast, String location) { - final String temp; - final String speed; - String precip; - String pressure; - String visibility; - - if (sharedPref.getBoolean("weather_US_SI", true)) { - temp = "F"; - speed = "Mph"; - precip = "in."; - pressure = "mb"; - visibility = "mile"; - } else { - temp = "C"; - speed = "m/s"; - precip = "cm"; - pressure = "hPa"; - visibility = "km"; - } - if (forecast.getCurrently() != null) { - if (forecast.getCurrently().getTemperature() != null) { - String currentTemp = String.valueOf(Math.round(forecast.getCurrently().getTemperature())) + (char) 0x00B0 + " " + temp; - weatherCurrentTemp.setText(currentTemp); - } - if (forecast.getCurrently().getApparentTemperature() != null) { - String feelsLikeTemp = "Feels like "; - feelsLikeTemp = feelsLikeTemp + String.valueOf(Math.round(forecast.getCurrently().getApparentTemperature())) + (char) 0x00B0; - weatherFeelsLike.setText(feelsLikeTemp); - } - - if (forecast.getCurrently().getWindSpeed() != null) { - String windSpeed = String.valueOf(Math.round(forecast.getCurrently().getWindSpeed())) + " " + speed; - weatherWindSpeed.setText(windSpeed); - } - } - if (forecast.getDaily() != null && forecast.getDaily().getDataPoints() != null && forecast.getDaily().getDataPoints().size() > 0) { - String highTemp = String.valueOf(Math.round(forecast.getDaily().getDataPoints().get(0).getTemperatureMax())); - String lowTemp = String.valueOf(Math.round(forecast.getDaily().getDataPoints().get(0).getTemperatureMin())); - String lowHigh = lowTemp + (char) 0x00B0 + " " + temp + " | " + highTemp + (char) 0x00B0 + " " + temp; - weatherLowHigh.setText(lowHigh); - - if (forecast.getDaily().getDataPoints().get(0).getPrecipProbability() != null) { - String precipProb = String.valueOf(Math.round(forecast.getDaily().getDataPoints().get(0).getPrecipProbability() * 100) + "%"); - weatherPercipChance.setText(precipProb); - } - threeDayForecast.setVisibility(View.GONE); - } - - if (forecast.getCurrently().getIcon() != null && forecast.getCurrently().getIcon().getText() != null) { - setIconView(weatherIcon, forecast.getCurrently().getIcon().getText()); - } - - if (forecast.getDaily() != null && forecast.getDaily().getDataPoints() != null && forecast.getDaily().getDataPoints().size() > 0 && forecast.getDaily().getDataPoints().get(0).getSummary() != null) { - weatherSummaryDay.setText(forecast.getDaily().getDataPoints().get(0).getSummary()); - } else if (forecast.getCurrently() != null && forecast.getCurrently().getSummary() != null) { - weatherSummaryDay.setText(forecast.getCurrently().getSummary()); - } else { - weatherSummaryDay.setVisibility(View.GONE); - } - - weatherLocation.setText(location); - - if (nightMode) { - dayTwoWeatherWindIcon.setIconColor(Color.WHITE); - dayTwoWeatherPrecipIcon.setIconColor(Color.WHITE); - dayThreeWeatherWindIcon.setIconColor(Color.WHITE); - dayThreeWeatherPrecipIcon.setIconColor(Color.WHITE); - dayFourWeatherWindIcon.setIconColor(Color.WHITE); - dayFourWeatherPrecipIcon.setIconColor(Color.WHITE); - weatherPrecipIcon.setIconColor(Color.WHITE); - weatherSpeedIcon.setIconColor(Color.WHITE); - } - } - - private void setIconView(WeatherIconView view, String icon) { - if (icon.contains("partly-cloudy-day")) { - view.setIconResource(getContext().getString(R.string.wi_forecast_io_partly_cloudy_day)); - } else if (icon.contains("partly-cloudy-night")) { - view.setIconResource(getContext().getString(R.string.wi_forecast_io_partly_cloudy_night)); - } else if (icon.contains("clear-day")) { - view.setIconResource(getContext().getString(R.string.wi_forecast_io_clear_day)); - } else if (icon.contains("clear-night")) { - view.setIconResource(getContext().getString(R.string.wi_forecast_io_clear_night)); - } else if (icon.contains("rain")) { - view.setIconResource(getContext().getString(R.string.wi_forecast_io_rain)); - } else if (icon.contains("snow")) { - view.setIconResource(getContext().getString(R.string.wi_forecast_io_snow)); - } else if (icon.contains("sleet")) { - view.setIconResource(getContext().getString(R.string.wi_forecast_io_sleet)); - } else if (icon.contains("wind")) { - view.setIconResource(getContext().getString(R.string.wi_forecast_io_wind)); - } else if (icon.contains("fog")) { - view.setIconResource(getContext().getString(R.string.wi_forecast_io_fog)); - } else if (icon.contains("cloudy")) { - view.setIconResource(getContext().getString(R.string.wi_forecast_io_cloudy)); - } else if (icon.contains("hail")) { - view.setIconResource(getContext().getString(R.string.wi_forecast_io_hail)); - } else if (icon.contains("thunderstorm")) { - view.setIconResource(getContext().getString(R.string.wi_forecast_io_thunderstorm)); - } else if (icon.contains("tornado")) { - view.setIconResource(getContext().getString(R.string.wi_forecast_io_tornado)); - } - if (nightMode) { - view.setIconColor(Color.WHITE); - } else { - view.setIconColor(Color.BLACK); - } - } - -} diff --git a/common/src/main/res/layout-w500dp/detail_launch_summary.xml b/common/src/main/res/layout-w500dp/detail_launch_summary.xml index 03fdcfc16..036420b7d 100644 --- a/common/src/main/res/layout-w500dp/detail_launch_summary.xml +++ b/common/src/main/res/layout-w500dp/detail_launch_summary.xml @@ -266,27 +266,6 @@ - - \ No newline at end of file diff --git a/common/src/main/res/layout/detail_launch_summary.xml b/common/src/main/res/layout/detail_launch_summary.xml index a35f80903..a28b8a0c2 100644 --- a/common/src/main/res/layout/detail_launch_summary.xml +++ b/common/src/main/res/layout/detail_launch_summary.xml @@ -260,27 +260,5 @@ - - - \ No newline at end of file diff --git a/common/src/main/res/layout/item_native_ad.xml b/common/src/main/res/layout/item_native_ad.xml deleted file mode 100644 index 996560f5f..000000000 --- a/common/src/main/res/layout/item_native_ad.xml +++ /dev/null @@ -1,102 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - -