diff --git a/app/src/main/java/org/hackillinois/android/ui/MainActivity.java b/app/src/main/java/org/hackillinois/android/ui/MainActivity.java index 2f85ea7..0b4c921 100644 --- a/app/src/main/java/org/hackillinois/android/ui/MainActivity.java +++ b/app/src/main/java/org/hackillinois/android/ui/MainActivity.java @@ -1,7 +1,6 @@ package org.hackillinois.android.ui; import android.content.Intent; -import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.support.annotation.Nullable; @@ -12,13 +11,9 @@ import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.widget.Toolbar; -import android.util.Log; import android.view.MenuItem; -import android.widget.Toast; import org.hackillinois.android.R; -import org.hackillinois.android.api.response.location.LocationResponse; -import org.hackillinois.android.helper.Settings; import org.hackillinois.android.helper.Utils; import org.hackillinois.android.ui.base.BaseActivity; import org.hackillinois.android.ui.modules.announcement.AnnouncementFragment; @@ -29,9 +24,6 @@ import butterknife.BindView; import butterknife.ButterKnife; -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Response; import timber.log.Timber; public class MainActivity extends BaseActivity { @@ -74,6 +66,12 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { fragmentManager = getSupportFragmentManager(); if (savedInstanceState == null) { + fragmentManager.beginTransaction() + .remove(profileFragment) + .remove(announcementFragment) + .remove(scheduleFragment) + .remove(homeFragment) + .commitNow(); fragmentManager.beginTransaction() .add(R.id.content_frame, profileFragment) .hide(profileFragment) @@ -130,12 +128,6 @@ protected void onNewIntent(Intent intent) { } } - @Override - protected void onResumeFragments() { - super.onResumeFragments(); - homeFragment.sync(); - } - private void swapFragments(Fragment newFragment) { // Delay newFragment swapping for increased fluidity (we wait for drawer to close) new Handler().postDelayed(() -> { diff --git a/app/src/main/java/org/hackillinois/android/ui/SplashActivity.java b/app/src/main/java/org/hackillinois/android/ui/SplashActivity.java index 475c38d..279a5ad 100644 --- a/app/src/main/java/org/hackillinois/android/ui/SplashActivity.java +++ b/app/src/main/java/org/hackillinois/android/ui/SplashActivity.java @@ -9,7 +9,6 @@ import com.annimon.stream.Optional; import org.hackillinois.android.R; -import org.hackillinois.android.api.response.location.LocationResponse; import org.hackillinois.android.api.response.login.LoginResponse; import org.hackillinois.android.helper.Settings; import org.hackillinois.android.helper.Utils; @@ -44,14 +43,14 @@ public class SplashActivity extends BaseActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + requestWindowFeature(Window.FEATURE_NO_TITLE); + getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); + setContentView(R.layout.activity_splash); ButterKnife.bind(this); Settings settings = Settings.get(); - Window window = getWindow(); - window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); - window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); Optional lastAuth = settings.getLastAuth(); Timber.d("User last auth: %s", lastAuth.map(DateTime::toString).orElse("Never")); diff --git a/app/src/main/java/org/hackillinois/android/ui/modules/home/HomeClock.java b/app/src/main/java/org/hackillinois/android/ui/modules/home/HomeClock.java index dcbea41..3e89eb5 100644 --- a/app/src/main/java/org/hackillinois/android/ui/modules/home/HomeClock.java +++ b/app/src/main/java/org/hackillinois/android/ui/modules/home/HomeClock.java @@ -1,6 +1,5 @@ package org.hackillinois.android.ui.modules.home; -import android.content.Context; import android.os.CountDownTimer; import com.airbnb.lottie.LottieAnimationView; @@ -15,24 +14,23 @@ import timber.log.Timber; public class HomeClock { + public interface OnFinishListener { + void onFinish(int timerIndex); } - + private CountDownTimer timer; private static final float SECONDS_SPEED_RATIO = 2f;//1f / (2.0f); - private static final String COUNTDOWN_60_JSON = "countdown-60.json"; - private static final String COUNTDOWN_24_JSON = "countdown-24.json"; private OnFinishListener onFinishListener; - private List activeTimers; + private List activeTimers; private int finishedTimers; - private final LottieAnimationView secondAnimation; + private final LottieAnimationView minuteAnimation; private final LottieAnimationView hourAnimation; private final LottieAnimationView daysAnimation; - public HomeClock( LottieAnimationView secondAnimation, LottieAnimationView minuteAnimation, @@ -72,6 +70,22 @@ public void setCountDownTo(OnFinishListener onFinishListener, List dat playNext(); } + public void onPause() { + if(timer != null) { + timer.cancel(); + } + } + + public void onResume() { + secondAnimation.invalidate(); + minuteAnimation.invalidate(); + hourAnimation.invalidate(); + daysAnimation.invalidate(); + if(timer != null) { + timer.start(); + } + } + private void playNext() { if (activeTimers.size() > 0) { DateTime nextTimer = activeTimers.get(0); @@ -85,42 +99,36 @@ private void setCountdownView(DateTime time) { return; } - Context context = secondAnimation.getContext(); - - try { - Period diff = new Period(DateTime.now(), time); - secondAnimation.setFrame(numberToFrame(diff.getSeconds())); - minuteAnimation.setFrame(numberToFrame(diff.getMinutes())); - hourAnimation.setFrame(numberToFrame(diff.getHours())); - daysAnimation.setFrame(numberToFrame(diff.getDays() + 7 * diff.getWeeks())); - - long millisUntilFinish = time.getMillis() - DateTime.now().getMillis(); - CountDownTimer timer = new CountDownTimer(millisUntilFinish, 1000) { - @Override - public void onTick(long millisUntilFinished) { - Period diff = new Period(DateTime.now(), time); - int seconds = diff.getSeconds(); - int hours = diff.getHours(); - int minutes = diff.getMinutes(); - int days = diff.getDays() + 7 * diff.getWeeks(); - tickSecond(seconds, minutes, hours, days); - } + Period diff = new Period(DateTime.now(), time); + secondAnimation.setFrame(numberToFrame(diff.getSeconds())); + minuteAnimation.setFrame(numberToFrame(diff.getMinutes())); + hourAnimation.setFrame(numberToFrame(diff.getHours())); + daysAnimation.setFrame(numberToFrame(diff.getDays() + 7 * diff.getWeeks())); + + long millisUntilFinish = time.getMillis() - DateTime.now().getMillis(); + timer = new CountDownTimer(millisUntilFinish, 1000) { + @Override + public void onTick(long millisUntilFinished) { + Period diff = new Period(DateTime.now(), time); + int seconds = diff.getSeconds(); + int hours = diff.getHours(); + int minutes = diff.getMinutes(); + int days = diff.getDays() + 7 * diff.getWeeks(); + tickSecond(seconds, minutes, hours, days); + } - @Override - public void onFinish() { - if (onFinishListener != null) { - ++finishedTimers; - onFinishListener.onFinish(finishedTimers); - if (activeTimers.size() > 0) { - activeTimers.remove(0); - playNext(); - } + @Override + public void onFinish() { + if (onFinishListener != null) { + ++finishedTimers; + onFinishListener.onFinish(finishedTimers); + if (activeTimers.size() > 0) { + activeTimers.remove(0); + playNext(); } } - }.start(); - } catch (Exception e) { - Timber.wtf(e, "Couldn't play animation"); - } + } + }.start(); } private static int lastSecond = 0; @@ -144,7 +152,6 @@ private void tickSecond(int seconds, int minutes, int hours, int days) { } private void tickMinute(int seconds, int minutes, int hours, int days) { - Timber.d("Tick minute at %s", DateTime.now()); if (minutes == 0) { tickHour(seconds, minutes, hours, days); minuteAnimation.setFrame(numberToFrame(60)); @@ -159,7 +166,6 @@ private void tickMinute(int seconds, int minutes, int hours, int days) { } private void tickHour(int seconds, int minutes, int hours, int days) { - Timber.d("Tick hour at %s", DateTime.now()); if (hours == 0) { tickDay(seconds, minutes, hours, days); hourAnimation.setFrame(numberToFrame(24)); @@ -174,7 +180,6 @@ private void tickHour(int seconds, int minutes, int hours, int days) { } private void tickDay(int seconds, int minutes, int hours, int days) { - Timber.d("Tick day at %s", DateTime.now()); if (days == 0) { daysAnimation.setFrame(numberToFrame(60)); } else { diff --git a/app/src/main/java/org/hackillinois/android/ui/modules/home/HomeFragment.java b/app/src/main/java/org/hackillinois/android/ui/modules/home/HomeFragment.java index 2fd8dab..34c893c 100644 --- a/app/src/main/java/org/hackillinois/android/ui/modules/home/HomeFragment.java +++ b/app/src/main/java/org/hackillinois/android/ui/modules/home/HomeFragment.java @@ -32,6 +32,7 @@ import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; +import timber.log.Timber; public class HomeFragment extends BaseFragment implements HomeClock.OnFinishListener { @BindView(R.id.second_animation) LottieAnimationView seconds; @@ -43,6 +44,12 @@ public class HomeFragment extends BaseFragment implements HomeClock.OnFinishList @BindView(R.id.countdownTitle) TextView countdownTitle; @BindView(R.id.empty_view) View emptyView; + private static final List EVENT_TIMERS = Arrays.asList( + Settings.EVENT_START_TIME, + Settings.HACKING_START_TIME, + Settings.HACKING_END_TIME, + Settings.EVENT_END_TIME + ); private static final int[] TITLE_IDS = new int[]{ R.string.hackillinois_starts_in, R.string.hacking_starts_in, @@ -67,6 +74,8 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c swipeRefresh.setOnRefreshListener(this::fetchEvents); Utils.attachHackIllinoisRefreshView(swipeRefresh, inflater); + clock = new HomeClock(seconds, minutes, hours, days); + clock.setCountDownTo(this, EVENT_TIMERS); sync(); //set our adapters to the RecyclerView @@ -104,9 +113,18 @@ public void stopRefreshing() { public void sync() { fetchEvents(); - clock = new HomeClock(seconds, minutes, hours, days); - List eventTimers = Arrays.asList(Settings.EVENT_START_TIME, Settings.HACKING_START_TIME, Settings.HACKING_END_TIME, Settings.EVENT_END_TIME); - clock.setCountDownTo(this, eventTimers); + } + + @Override + public void onPause() { + super.onPause(); + clock.onPause(); + } + + @Override + public void onResume() { + super.onResume(); + clock.onResume(); } public void fetchEvents() {