From b78578f2f2c64f902aca22fcf9d2f13f7fd8add9 Mon Sep 17 00:00:00 2001 From: Noah Santacruz Date: Mon, 14 May 2018 19:41:34 +0300 Subject: [PATCH] 357 --- app/app.iml | 35 ++++++++++----- app/build.gradle | 4 +- .../sefaria/database/DailyLearning.java | 44 ++++++++++++++++++- 3 files changed, 70 insertions(+), 13 deletions(-) diff --git a/app/app.iml b/app/app.iml index 334d3c7..f749fbb 100644 --- a/app/app.iml +++ b/app/app.iml @@ -22,7 +22,7 @@ - + @@ -79,16 +79,31 @@ + + + + + + + + + + + + + + + @@ -97,14 +112,14 @@ - - - - - - - - - + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index ffbb810..8020e2f 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "org.sefaria.sefaria" minSdkVersion 14 targetSdkVersion 23 - versionCode 354 - versionName "3.54" + versionCode 357 + versionName "3.57" // Enabling multidex support //multiDexEnabled true } diff --git a/app/src/main/java/org/sefaria/sefaria/database/DailyLearning.java b/app/src/main/java/org/sefaria/sefaria/database/DailyLearning.java index 4add439..e2a9766 100755 --- a/app/src/main/java/org/sefaria/sefaria/database/DailyLearning.java +++ b/app/src/main/java/org/sefaria/sefaria/database/DailyLearning.java @@ -5,13 +5,18 @@ import android.util.Log; import org.json.JSONArray; +import org.json.JSONException; import org.json.JSONObject; import org.sefaria.sefaria.MenuElements.MenuDirectRef; import org.sefaria.sefaria.Settings; import org.sefaria.sefaria.Util; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; import java.util.List; public class DailyLearning { @@ -128,10 +133,37 @@ private static ChapVersePath getChapVerses(String fullNumber){ return chapVersePath; } + private static boolean shouldOverrideParsha() { + boolean isBeforeIsraelMeetsUS = false; + try { + SimpleDateFormat sdf = new SimpleDateFormat("dd/mm/yyyy"); + Date strDate = sdf.parse("12/05/2018"); + Calendar dayIsraelMeetsUS = new GregorianCalendar(); + dayIsraelMeetsUS.setTime(strDate); + isBeforeIsraelMeetsUS = Calendar.getInstance().after(dayIsraelMeetsUS); + if (isBeforeIsraelMeetsUS) { + String data = API.getDataFromURL("http://ip-api.com/json"); + JSONObject response = new JSONObject(data); + return response.getString("countryCode").equals("IL"); + } else { + return false; + } + } catch (API.APIException e) { + return false; + } catch (JSONException e) { + return false; + } catch (ParseException e) { + return false; + } + + } + public static MenuDirectRef [] getParsha(Context context){ String todaysDate = getLongDate(1); + boolean shouldOverrideParsha = shouldOverrideParsha(); + JSONArray weeks = null; - // todaysDate = "26-Sep-2020"; //fake date for testing + //todaysDate = "12-May-2018"; //fake date for testing try { //Log.d("DailyLearning", "getParsha..today: "+ todaysDate); weeks = Util.openJSONArrayFromAssets("calendar/parshiot.json"); @@ -142,6 +174,16 @@ private static ChapVersePath getChapVerses(String fullNumber){ String parsha = week.getString("parasha"); String [] multiParshas = parsha.split("-"); // If it's a double parsha only get the first String aliyah = week.getJSONArray("aliyot").getString(0); + if (shouldOverrideParsha && parsha.equals("Emor")) { + parsha = "Behar"; + multiParshas = parsha.split("-"); + aliyah = "Leviticus 25:1-25:18"; + } else if (shouldOverrideParsha && parsha.equals("Behar-Bechukotai")) { + parsha = "Bechukotai"; + multiParshas = parsha.split("-"); + aliyah = "Leviticus 26:3-26:5"; + } + String bookName = aliyah.replaceFirst("\\s[0-9]+.*$", ""); Book book = new Book(bookName); Node node = getParshaFromSefar(book, multiParshas[0]);