From f8065b298a11e0db63ac19d7b934a037b196245c Mon Sep 17 00:00:00 2001 From: Zhehua Zhang Date: Mon, 29 Feb 2016 13:27:55 +0800 Subject: [PATCH] Modified fetch week logic and add force-refresh entry. --- app/app.iml | 40 +++++++------------ app/build.gradle | 4 +- .../zchang/onchart/config/ConfigManager.java | 15 +++---- .../me/zchang/onchart/ui/MainActivity.java | 31 +++++++++----- app/src/main/res/values-v21/styles.xml | 1 - app/src/main/res/values-zh/strings.xml | 1 + app/src/main/res/values/strings.xml | 3 +- 7 files changed, 47 insertions(+), 48 deletions(-) diff --git a/app/app.iml b/app/app.iml index 50acdf6..0735baa 100644 --- a/app/app.iml +++ b/app/app.iml @@ -65,56 +65,46 @@ - - + - - - - - - - - - - + - - - - - - - - - - - + + + + - - + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 915fa2e..88f01d4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "me.zchang.onchart" minSdkVersion 16 targetSdkVersion 23 - versionCode 8 - versionName "1.4.2" + versionCode 9 + versionName "1.4.3" } buildTypes { release { diff --git a/app/src/main/java/me/zchang/onchart/config/ConfigManager.java b/app/src/main/java/me/zchang/onchart/config/ConfigManager.java index a279488..5e13313 100644 --- a/app/src/main/java/me/zchang/onchart/config/ConfigManager.java +++ b/app/src/main/java/me/zchang/onchart/config/ConfigManager.java @@ -29,13 +29,11 @@ public class ConfigManager { private static String SETTING_FILE; - final static String CHART_FILE_NAME = "chart.js"; - Context context; SharedPreferences sp; CourseSQLiteHelper courseSQLiteHelper; - OnConfigChangeListener configChangeListner; + OnConfigChangeListener configChangeListener; private boolean firstLaunch = false; @@ -48,12 +46,12 @@ public class ConfigManager { }; public void registerListener(OnConfigChangeListener listener) { - configChangeListner = listener; + configChangeListener = listener; sp.registerOnSharedPreferenceChangeListener(listener); } public void unRegisterListener(OnConfigChangeListener listener) { - configChangeListner = null; + configChangeListener = null; sp.unregisterOnSharedPreferenceChangeListener(listener); } @@ -89,14 +87,14 @@ public ConfigManager deleteSchedule() { public boolean insertCourse(Course course) { boolean result = courseSQLiteHelper.insertCourse(course); - if (configChangeListner != null && result) - configChangeListner.onInsertCourse(course); + if (configChangeListener != null && result) + configChangeListener.onInsertCourse(course); return result; } public void deleteCourse(long id) { courseSQLiteHelper.deleteCourse(id); - configChangeListner.onDeleteCourse(id); + configChangeListener.onDeleteCourse(id); } public ConfigManager saveImgPathIndex(long key, int resIndex) { @@ -174,7 +172,6 @@ public ConfigManager saveLastVersionCode(int code) { public interface OnConfigChangeListener extends SharedPreferences.OnSharedPreferenceChangeListener { void onInsertCourse(Course course); - void onDeleteCourse(long id); } } diff --git a/app/src/main/java/me/zchang/onchart/ui/MainActivity.java b/app/src/main/java/me/zchang/onchart/ui/MainActivity.java index bef4a63..0e2fda4 100644 --- a/app/src/main/java/me/zchang/onchart/ui/MainActivity.java +++ b/app/src/main/java/me/zchang/onchart/ui/MainActivity.java @@ -23,7 +23,6 @@ import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; -import android.os.PersistableBundle; import android.support.design.widget.AppBarLayout; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.NavigationView; @@ -35,8 +34,6 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; -import android.transition.Explode; -import android.transition.Slide; import android.util.Log; import android.view.Menu; import android.view.MenuItem; @@ -44,7 +41,6 @@ import android.view.ViewGroup; import android.view.WindowManager; import android.view.animation.AccelerateDecelerateInterpolator; -import android.widget.DialerFilter; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; @@ -81,6 +77,7 @@ public class MainActivity extends AppCompatActivity public final static int REQ_SETTING = 1; public final static long MILLISECONDS_IN_A_DAY = 24 * 3600 * 1000; + public final static long MILLISECONDS_IN_A_WEEK = MILLISECONDS_IN_A_DAY * 7; public final static String TAG = "MainActivity"; private Toolbar mainToolbar; @@ -180,7 +177,7 @@ public void onClick(View view) { setupDrawer(); // if haven't refreshed week for a week. - if (Math.abs(configManager.getLastFetchWeekTime() - today.getTimeInMillis()) > 7 * MILLISECONDS_IN_A_DAY) { + if (Math.abs(configManager.getLastFetchWeekTime() - today.getTimeInMillis()) > MILLISECONDS_IN_A_WEEK) { refreshWeek(); } @@ -256,8 +253,21 @@ else if (curWeek % 2 == course.getWeekParity()) // odd or even week num } // update week number - if (weekNumText != null) - weekNumText.setText(String.format(getString(R.string.weekday_week), curWeek)); + if (weekNumText != null) { + weekNumText.setText(String.format(getString(R.string.weekday_week), curWeek)); + weekNumText.setLongClickable(true); + weekNumText.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + refreshWeek(); + new AlertDialog.Builder(MainActivity.this) + .setTitle("Warning") + .setMessage("This is a testing function, and the stability is not guaranteed.") + .show(); + return false; + } + }); + } } private void setupDrawer() { @@ -556,9 +566,10 @@ public void onHomepageFetchOverEvent(HomepageFetchOverEvent event) { return; } // save the nearest past Monday - configManager.saveLastFetchWeekTime( - today.getTimeInMillis() - - ((today.get(Calendar.DAY_OF_WEEK) - Calendar.MONDAY) % 7) * MILLISECONDS_IN_A_DAY); + long onePastMonday = 946828800000L; // Jan.3rd, 2000. + long lastFetchTime = today.getTimeInMillis() - + (today.getTimeInMillis() - onePastMonday) % MILLISECONDS_IN_A_WEEK; + configManager.saveLastFetchWeekTime(lastFetchTime); if (curWeek != integer && integer > 0) { curWeek = integer; diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml index 9575920..39596ce 100644 --- a/app/src/main/res/values-v21/styles.xml +++ b/app/src/main/res/values-v21/styles.xml @@ -12,7 +12,6 @@