Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions astronauts/build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,6 +18,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
Expand All @@ -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
Expand All @@ -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
Expand Down
14 changes: 0 additions & 14 deletions astronauts/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,6 @@ public *;
public *;
}

# ButterKnife 7

-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }

-keepclasseswithmembernames class * {
@butterknife.* <fields>;
}

-keepclasseswithmembernames class * {
@butterknife.* <methods>;
}

# Crashlytics 2.+

-keep class com.crashlytics.** { *; }
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
}
Expand All @@ -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);
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand All @@ -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();
}
Expand All @@ -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));
}


Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}

Expand Down
Loading
Loading