diff --git a/app/app/app-app.iml b/app/app/app-app.iml
index d985e96..4de4e5c 100644
--- a/app/app/app-app.iml
+++ b/app/app/app-app.iml
@@ -85,9 +85,11 @@
+
+
diff --git a/app/app/build.gradle b/app/app/build.gradle
index 6bd851c..f56d938 100644
--- a/app/app/build.gradle
+++ b/app/app/build.gradle
@@ -38,4 +38,6 @@ dependencies {
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
compile 'com.android.support:support-v4:21.0.3'
compile files('libs/prov-1.51.0.0.jar')
+ compile files('libs/core-1.51.0.0.jar')
+ compile 'com.google.code.gson:gson:2.3.1'
}
diff --git a/app/app/libs/core-1.51.0.0.jar b/app/app/libs/core-1.51.0.0.jar
new file mode 100644
index 0000000..60b24dd
Binary files /dev/null and b/app/app/libs/core-1.51.0.0.jar differ
diff --git a/app/app/src/main/AndroidManifest.xml b/app/app/src/main/AndroidManifest.xml
index 97b1294..b7e07fd 100644
--- a/app/app/src/main/AndroidManifest.xml
+++ b/app/app/src/main/AndroidManifest.xml
@@ -24,7 +24,7 @@
+
+
diff --git a/app/app/src/main/assets/_un_folding_word b/app/app/src/main/assets/_un_folding_word
index be124ec..7ba58de 100644
Binary files a/app/app/src/main/assets/_un_folding_word and b/app/app/src/main/assets/_un_folding_word differ
diff --git a/app/app/src/main/assets/certs/ca.pub b/app/app/src/main/assets/certs/ca.pub
new file mode 100644
index 0000000..c2d4d1e
--- /dev/null
+++ b/app/app/src/main/assets/certs/ca.pub
@@ -0,0 +1,5 @@
+-----BEGIN PUBLIC KEY-----
+MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAESwmkZ0AJIQo9cELigBaEPaVbQYnWOWhq
+ouunp1AGWSgv+KvV/RS9AiRAMjgr4robcgxDjjrdrESyCiTbRehl1yGT0NxfkGhp
+qkjQDUV4/4UH63jfRO3F6d1DtBvrxXJp
+-----END PUBLIC KEY-----
\ No newline at end of file
diff --git a/app/app/src/main/java/activity/SettingsActivity.java b/app/app/src/main/java/activity/SettingsActivity.java
index 3bebcab..e52c410 100644
--- a/app/app/src/main/java/activity/SettingsActivity.java
+++ b/app/app/src/main/java/activity/SettingsActivity.java
@@ -4,19 +4,12 @@
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
-import android.media.Ringtone;
-import android.media.RingtoneManager;
-import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
-import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
-import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
-import android.preference.RingtonePreference;
-import android.text.TextUtils;
import org.unfoldingword.mobile.R;
diff --git a/app/app/src/main/java/activity/SplashScreenActivity.java b/app/app/src/main/java/activity/SplashScreenActivity.java
index 46c7042..8da6cbc 100644
--- a/app/app/src/main/java/activity/SplashScreenActivity.java
+++ b/app/app/src/main/java/activity/SplashScreenActivity.java
@@ -14,7 +14,6 @@
import activity.bookSelection.InitialPageActivity;
import model.database.DBManager;
-import utils.URLUtils;
/**
* Created by Acts Media Inc. on 2/12/14.
diff --git a/app/app/src/main/java/activity/bookSelection/BibleChapterSelectionActivity.java b/app/app/src/main/java/activity/bookSelection/BibleChapterSelectionActivity.java
new file mode 100644
index 0000000..be3574f
--- /dev/null
+++ b/app/app/src/main/java/activity/bookSelection/BibleChapterSelectionActivity.java
@@ -0,0 +1,157 @@
+package activity.bookSelection;
+
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.ListView;
+import android.widget.TextView;
+
+import org.unfoldingword.mobile.R;
+
+import java.util.ArrayList;
+import java.util.Collections;
+
+import activity.reading.ReadingActivity;
+import adapters.selectionAdapters.GeneralAdapter;
+import adapters.selectionAdapters.GeneralRowInterface;
+import model.datasource.BibleChapterDataSource;
+import model.datasource.BookDataSource;
+import model.modelClasses.mainData.BibleChapterModel;
+import model.modelClasses.mainData.BookModel;
+import utils.UWPreferenceManager;
+
+/**
+ * Created by Fechner on 2/27/15.
+ */
+public class BibleChapterSelectionActivity extends GeneralSelectionActivity{
+
+ public static String STORY_CHAPTERS_INDEX_STRING = "STORY_CHAPTERS_INDEX_STRING";
+
+ private int resultCode = 0;
+
+ @Override
+ protected int getContentView() {
+ return R.layout.activity_general_list;
+ }
+
+ @Override
+ protected String getIndexStorageString() {
+ return STORY_CHAPTERS_INDEX_STRING;
+ }
+
+ @Override
+ protected Class getChildClass() {
+ return null;
+ }
+
+ protected String getActionBarTitle() {
+ return "Select Chapter";
+ }
+
+
+ @Override
+ protected void setUI() {
+ setupActionBar();
+ }
+
+ private void setupActionBar(){
+
+ mActionBar = getSupportActionBar();
+ View view = getLayoutInflater().inflate(R.layout.actionbar_base, null);
+ mActionBar.setCustomView(view);
+ mActionBar.setDisplayShowCustomEnabled(true);
+ mActionBar.setDisplayShowHomeEnabled(true);
+ mActionBar.setHomeButtonEnabled(true);
+ mActionBar.setDisplayHomeAsUpEnabled(true);
+
+ actionbarTextView = (TextView) view.findViewById(R.id.actionbarTextView);
+ actionbarTextView.setText(getActionBarTitle());
+ }
+
+
+ @Override
+ protected void prepareListView() {
+
+ ArrayList data = this.getData();
+
+ if (mListView == null) {
+ mListView = (ListView) findViewById(R.id.generalList);
+ }
+ if (data == null) {
+ return;
+ }
+ else if (data != null || data.size() == 0) {
+ actionbarTextView.setText(getActionBarTitle());
+ }
+
+ mListView.setOnItemClickListener(this);
+ GeneralAdapter adapter = new GeneralAdapter(this.getApplicationContext(), data, this.actionbarTextView, this, this.getIndexStorageString());
+ mListView.setAdapter(adapter);
+
+ int scrollPosition = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getInt(STORY_CHAPTERS_INDEX_STRING, -1);
+ mListView.setSelection((scrollPosition > 0)? scrollPosition - 1 : 0);
+ }
+
+ protected ArrayList getData(){
+
+ Bundle extras = getIntent().getExtras();
+ if (extras != null) {
+
+ String chosenBook = extras.getString(CHOSEN_ID);
+
+ BookModel book = new BookDataSource(getApplicationContext()).getModel(chosenBook);
+
+ ArrayList data = new ArrayList();
+
+ ArrayList chapters = book.getBibleChildModels(getApplicationContext());
+ Collections.sort(chapters);
+
+ long chapterId = Long.parseLong(UWPreferenceManager.getSelectedBibleChapter(getApplicationContext()));
+
+ int i = 0;
+ for (BibleChapterModel model : chapters) {
+ if(model.uid == chapterId){
+ PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putInt(STORY_CHAPTERS_INDEX_STRING, i).commit();
+ }
+ data.add(model);
+ i++;
+ }
+ return data;
+ }
+
+ return null;
+ }
+
+ @Override
+ public void onItemClick(AdapterView> adapterView, View view, int position, long rowIndex) {
+
+ Object itemAtPosition = adapterView.getItemAtPosition(position);
+
+ if (itemAtPosition instanceof BibleChapterModel) {
+ BibleChapterModel model = (BibleChapterModel) itemAtPosition;
+
+ UWPreferenceManager.setSelectedBibleChapter(getApplicationContext(), model.uid);
+ }
+ resultCode = 1;
+ setResult(resultCode);
+ PreferenceManager.getDefaultSharedPreferences(this).edit().putInt(ReadingActivity.BOOK_INDEX_STRING, -1).commit();
+ finish();
+ overridePendingTransition(R.anim.enter_center, R.anim.exit_on_bottom);
+ }
+
+ @Override
+ protected void onStop() {
+ setResult(resultCode);
+ super.onStop();
+ }
+
+ @Override
+ protected void onDestroy() {
+ setResult(resultCode);
+ super.onDestroy();
+ }
+
+ public void closeButtonClicked(View view) {
+ }
+}
diff --git a/app/app/src/main/java/activity/bookSelection/BookSelectionActivity.java b/app/app/src/main/java/activity/bookSelection/BookSelectionActivity.java
index 2c77691..ef49a8c 100644
--- a/app/app/src/main/java/activity/bookSelection/BookSelectionActivity.java
+++ b/app/app/src/main/java/activity/bookSelection/BookSelectionActivity.java
@@ -1,21 +1,27 @@
package activity.bookSelection;
import android.content.Context;
-import android.os.Bundle;
+import android.content.Intent;
import android.preference.PreferenceManager;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.Button;
+import android.widget.FrameLayout;
+import android.widget.ImageView;
+import android.widget.ListView;
+import android.widget.TextView;
import org.unfoldingword.mobile.R;
import java.util.ArrayList;
-import java.util.Collections;
+import adapters.selectionAdapters.GeneralAdapter;
import adapters.selectionAdapters.GeneralRowInterface;
-import adapters.selectionAdapters.InitialPageModel;
-import model.database.ModelCaching;
-import model.datasource.ProjectDataSource;
-import model.database.DBManager;
-import model.modelClasses.mainData.LanguageModel;
+import model.datasource.BibleChapterDataSource;
+import model.modelClasses.mainData.BibleChapterModel;
+import model.modelClasses.mainData.BookModel;
import model.modelClasses.mainData.ProjectModel;
+import utils.UWPreferenceManager;
/**
* Created by Fechner on 2/27/15.
@@ -24,7 +30,6 @@ public class BookSelectionActivity extends GeneralSelectionActivity{
static String BOOK_INDEX_STRING = "BOOK_INDEX_STRING";
- ArrayList mProjects = null;
@Override
protected int getContentView() {
@@ -32,13 +37,26 @@ protected int getContentView() {
}
@Override
- protected ArrayList getListOfLanguages() {
+ protected void prepareListView() {
- if (mProjects == null) {
- addProjects();
+ ArrayList data = this.getData();
+
+ if (mListView == null) {
+ mListView = (ListView) findViewById(R.id.generalList);
+ }
+ if (data == null) {
+ return;
+ }
+ else if (data != null || data.size() == 0) {
+ actionbarTextView.setText(getActionBarTitle());
}
- return ModelCaching.getAvailableLanguages(getApplicationContext(), mProjects);
+ mListView.setOnItemClickListener(this);
+ GeneralAdapter adapter = new GeneralAdapter(this.getApplicationContext(), data, this.actionbarTextView, this, this.getIndexStorageString());
+ mListView.setAdapter(adapter);
+
+ int scrollPosition = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getInt(BOOK_INDEX_STRING, -1);
+ mListView.setSelection((scrollPosition > 0) ? scrollPosition - 1 : 0);
}
@Override
@@ -48,53 +66,100 @@ protected String getIndexStorageString() {
@Override
protected Class getChildClass() {
- return VersionSelectionActivity.class;
+ return BibleChapterSelectionActivity.class;
}
- @Override
protected String getActionBarTitle() {
- return mProjects.get(0).meta;
+ return "Select Book";//mProjects.get(0).meta;
}
- protected ArrayList getData(){
+ @Override
+ protected void setUI() {
- ArrayList data = new ArrayList();
- String selectedLanguage = PreferenceManager.getDefaultSharedPreferences(this).getString(
- getResources().getString(R.string.selected_language), "English");
+ View view = getLayoutInflater().inflate(R.layout.actionbar_base, null);
+ setupActionBar(view);
+ setupCloseButton(view);
+ }
- if (mProjects == null) {
- addProjects();
- }
- Context context = getApplicationContext();
+ private void setupActionBar(View view){
+
+ mActionBar = getSupportActionBar();
+ mActionBar.setCustomView(view);
+ mActionBar.setDisplayShowCustomEnabled(true);
+ mActionBar.setDisplayShowHomeEnabled(false);
+ mActionBar.setHomeButtonEnabled(false);
+ mActionBar.setDisplayHomeAsUpEnabled(false);
+
+ actionbarTextView = (TextView) view.findViewById(R.id.actionbarTextView);
+ actionbarTextView.setText(getActionBarTitle());
+ }
- for (ProjectModel project : mProjects) {
+ private void setupCloseButton(View view){
+ FrameLayout closeButton = (FrameLayout) view.findViewById(R.id.close_image_view);
+ closeButton.setVisibility(View.VISIBLE);
+ }
+
+ public void closeButtonClicked(View view) {
+ handleBack();
+ }
- LanguageModel language = project.getLanguageModel(context, selectedLanguage);
+ protected ArrayList getData(){
- if (language != null) {
- data.add(new InitialPageModel(language.projectName, Long.toString(language.uid)));
+ Context context = getApplicationContext();
+
+ String chapterId = UWPreferenceManager.getSelectedBibleChapter(context);
+ if(Long.parseLong(chapterId) < 0) {
+ return null;
+ }
+ else {
+ BibleChapterModel model = new BibleChapterDataSource(context).getModel(chapterId);
+ ArrayList books = model.getParent(context).getParent(context).getChildModels(context);
+
+ long selectedId = model.getParent(context).uid;
+ ArrayList data = new ArrayList();
+ int i = 0;
+ for (BookModel book : books) {
+ if(book.uid == selectedId){
+ PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putInt(BOOK_INDEX_STRING, i).commit();
+ }
+ data.add(book);
+ i++;
}
+
+
+ return data;
}
- return data;
}
- private void addProjects(){
+ @Override
+ public void onItemClick(AdapterView> adapterView, View view, int position, long rowIndex) {
+
+ Object itemAtPosition = adapterView.getItemAtPosition(position);
+ if (itemAtPosition instanceof GeneralRowInterface) {
+ GeneralRowInterface model = (GeneralRowInterface) itemAtPosition;
- Bundle extras = getIntent().getExtras();
- if (extras != null) {
+ // put selected position to sharedprefences
+ PreferenceManager.getDefaultSharedPreferences(this).edit().putInt(this.getIndexStorageString(), (int) rowIndex).commit();
+ startActivityForResult(new Intent(this, this.getChildClass(model)).putExtra(
+ CHOSEN_ID, model.getChildIdentifier()), 1);
+ overridePendingTransition(R.anim.enter_from_right, R.anim.exit_on_left);
+ }
+ }
+
+ @Override
+ protected void handleBack(){
- String chosenProject = extras.getString(CHOSEN_ID);
+ PreferenceManager.getDefaultSharedPreferences(this).edit().putInt(getIndexStorageString(), -1).commit();
+ finish();
+ overridePendingTransition(R.anim.enter_center, R.anim.exit_on_bottom);
+ }
- this.mProjects = new ArrayList();
- ArrayList projects = new ProjectDataSource(this.getApplicationContext()).getAllProjects();
- for (ProjectModel project : projects) {
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (project.meta.equalsIgnoreCase(chosenProject)) {
- mProjects.add(project);
- }
- }
- Collections.sort(mProjects);
+ if(resultCode == 1){
+ finish();
}
}
}
diff --git a/app/app/src/main/java/activity/bookSelection/ChapterSelectionActivity.java b/app/app/src/main/java/activity/bookSelection/ChapterSelectionActivity.java
deleted file mode 100644
index 0ea95f4..0000000
--- a/app/app/src/main/java/activity/bookSelection/ChapterSelectionActivity.java
+++ /dev/null
@@ -1,174 +0,0 @@
-package activity.bookSelection;
-
-import android.os.Bundle;
-import android.preference.PreferenceManager;
-import android.widget.ListView;
-
-import com.nostra13.universalimageloader.core.ImageLoader;
-import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
-
-import org.unfoldingword.mobile.R;
-
-import java.util.ArrayList;
-import java.util.Collections;
-
-import activity.reading.ReadingActivity;
-import activity.reading.StoryReadingActivity;
-import adapters.selectionAdapters.GeneralRowInterface;
-import adapters.selectionAdapters.StoriesChapterAdapter;
-import model.datasource.VersionDataSource;
-import model.modelClasses.mainData.BibleChapterModel;
-import model.modelClasses.mainData.BookModel;
-import model.modelClasses.mainData.LanguageModel;
-import model.modelClasses.mainData.StoriesChapterModel;
-import model.modelClasses.mainData.VersionModel;
-
-/**
- * Created by Fechner on 2/27/15.
- */
-public class ChapterSelectionActivity extends GeneralSelectionActivity{
-
- public static String CHAPTERS_INDEX_STRING = "CHAPTERS_INDEX_STRING";
-
- private VersionModel chosenVersion = null;
- ImageLoader mImageLoader;
- boolean isStoryBook;
-
- @Override
- protected int getContentView() {
- return R.layout.activity_general_list;
- }
-
- @Override
- protected ArrayList getListOfLanguages() {
-
- if (chosenVersion == null) {
- addVersion();
- }
-
- return chosenVersion.getAvailableLanguages(getApplicationContext());
-}
-
- @Override
- protected String getIndexStorageString() {
- return CHAPTERS_INDEX_STRING;
- }
-
- @Override
- protected Class getChildClass() {
- return (isStoryBook)? StoryReadingActivity.class : ReadingActivity.class;
- }
-
- @Override
- protected String getActionBarTitle() {
- return chosenVersion.name;
- }
-
-
- @Override
- protected void setUI() {
- if (chosenVersion == null) {
- addVersion();
- }
- isStoryBook = (chosenVersion.usfmUrl.length() < 2);
- super.setUI();
- }
-
- @Override
- protected void prepareListView() {
-
- if(!isStoryBook){
- super.prepareListView();
- }
- else {
-
- BookModel book = this.chosenVersion.getStoriesChildModels(getApplicationContext()).get(0);
- ArrayList chapterModels = this.getData();
-
- if (chapterModels != null) {
- actionbarTextView.setText(book.appWords.chapters);
-
- mListView = (ListView) findViewById(R.id.generalList);
- mListView.setOnItemClickListener(this);
-
- mImageLoader = ImageLoader.getInstance();
-
- if (mImageLoader.isInited()) {
- ImageLoader.getInstance().destroy();
- }
-
- mImageLoader.init(ImageLoaderConfiguration.createDefault(this));
-
- mListView.setAdapter(new StoriesChapterAdapter(getApplicationContext(), chapterModels, this.actionbarTextView, this, mImageLoader, this.getIndexStorageString()));
- }
- }
- }
-
- @Override
- protected ArrayList getData(){
-
- if (chosenVersion == null) {
- addVersion();
- }
-
- checkForLanguageChange();
-
-
- ArrayList data = new ArrayList();
-
- if(isStoryBook){
- ArrayList chapters = this.chosenVersion.getStoriesChildModels(getApplicationContext()).get(0).getChildModels(getApplicationContext());
- Collections.sort(chapters);
-
- for(StoriesChapterModel model : chapters){
- data.add(model);
- }
- }
-
- else{
- ArrayList chapters = this.chosenVersion.getBibleChildModels(getApplicationContext());
- Collections.sort(chapters);
-
- for(BibleChapterModel model : chapters){
- data.add(model);
- }
- }
-
- return data;
- }
-
- private void checkForLanguageChange(){
-
- String selectedLanguage = PreferenceManager.getDefaultSharedPreferences(this).getString(
- getResources().getString(R.string.selected_language), "English");
-
- if(!chosenVersion.getParent(getApplicationContext()).languageName.equalsIgnoreCase(selectedLanguage)){
- LanguageModel correctLanguage = null;
-
- ArrayList languages = chosenVersion.getParent(getApplicationContext()).getParent(getApplicationContext()).getChildModels(getApplicationContext());
-
- for(LanguageModel model : languages){
- if(selectedLanguage.equalsIgnoreCase(model.languageName)){
- correctLanguage = model;
- break;
- }
- }
- if(correctLanguage != null){
- chosenVersion = correctLanguage.getChildModels(getApplicationContext()).get(0);
- }
-
- }
- }
-
- private void addVersion(){
-
- Bundle extras = getIntent().getExtras();
- if (extras != null) {
-
- String chosenVersion = extras.getString(CHOSEN_ID);
- VersionModel version = (new VersionDataSource(this.getApplicationContext())).getModel(chosenVersion);
-
- this.chosenVersion = version;
- }
- }
-}
diff --git a/app/app/src/main/java/activity/bookSelection/GeneralSelectionActivity.java b/app/app/src/main/java/activity/bookSelection/GeneralSelectionActivity.java
index ed60d53..4c72124 100644
--- a/app/app/src/main/java/activity/bookSelection/GeneralSelectionActivity.java
+++ b/app/app/src/main/java/activity/bookSelection/GeneralSelectionActivity.java
@@ -1,7 +1,6 @@
package activity.bookSelection;
import android.content.Intent;
-import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBar;
@@ -17,6 +16,7 @@
import org.unfoldingword.mobile.R;
import java.util.ArrayList;
+import java.util.Locale;
import activity.SplashScreenActivity;
import adapters.selectionAdapters.GeneralAdapter;
@@ -35,10 +35,9 @@ public abstract class GeneralSelectionActivity extends ActionBarActivity impleme
protected static String SELECTED_POS;
protected ListView mListView = null;
- protected DBManager mDbManager = null;
protected ActionBar mActionBar = null;
protected TextView actionbarTextView = null;
- protected Button languagesButton = null;
+
/**
* should return the main view for the activity
@@ -46,18 +45,6 @@ public abstract class GeneralSelectionActivity extends ActionBarActivity impleme
*/
abstract protected int getContentView();
- /**
- * should return a list of languages for the popover
- * @return
- */
- abstract protected ArrayList getListOfLanguages();
-
- /**
- * should return the data desired to be in the table
- * @return
- */
- abstract protected ArrayList getData();
-
/**
* should return a unique index storage key
* @return
@@ -70,13 +57,6 @@ public abstract class GeneralSelectionActivity extends ActionBarActivity impleme
*/
abstract protected Class getChildClass();
- /**
- * should return the desired title for the actionbar
- * @return
- */
- abstract protected String getActionBarTitle();
-
-
protected Class getChildClass(GeneralRowInterface row){
return this.getChildClass();
}
@@ -86,146 +66,131 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getContentView());
setUI();
+ prepareListView();
}
/**
* Setup UI components and initial statements
*/
- protected void setUI() {
-
- mActionBar = getSupportActionBar();
- View view = getLayoutInflater().inflate(R.layout.actionbar_custom_view, null);
- actionbarTextView = (TextView) view.findViewById(R.id.actionbarTextView);
- mActionBar.setCustomView(view);
- mActionBar.setDisplayShowCustomEnabled(true);
- mActionBar.setDisplayShowHomeEnabled(true);
- mActionBar.setHomeButtonEnabled(true);
- mActionBar.setDisplayHomeAsUpEnabled(true);
-
- mDbManager = DBManager.getInstance(this);
- languagesButton = (Button) view.findViewById(R.id.languageButton);
- languagesButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- addPopover(v);
- }
- });
- languagesButton.setText(getCurrentLanguage());
-
- prepareListView();
- }
-
- private String getCurrentLanguage(){
-
- final ArrayList languages = getListOfLanguages();
-
- if(languages != null) {
-
- String selectedLanguage = PreferenceManager.getDefaultSharedPreferences(this).getString(getResources().getString(R.string.selected_language), "English");
- int i = 0;
- for (String language : languages) {
- if (language.equalsIgnoreCase(selectedLanguage)) {
- return selectedLanguage;
- }
- i++;
- }
- }
-
- Intent refresh = new Intent(this, SplashScreenActivity.class);
- startActivity(refresh);
- this.finish(); //
- return "Language";
- }
-
- private void addPopover(View view) {
-
- //create QuickAction. Use QuickAction.VERTICAL or QuickAction.HORIZONTAL param to define layout
- //orientation
- final QuickAction quickAction = new QuickAction(this, QuickAction.VERTICAL);
- final ArrayList languages = getListOfLanguages();
-
- String selectedLanguage = PreferenceManager.getDefaultSharedPreferences(this).getString(getResources().getString(R.string.selected_language), "English");
- int i = 0;
- for (String language : languages) {
- ActionItem item = new ActionItem(i, language);
-
- item.setSticky(false);
- item.setIcon(getResources().getDrawable(R.drawable.checkmark));
- item.setImageEnabled(selectedLanguage.equalsIgnoreCase(language));
-
- quickAction.addActionItem(item);
- i++;
- }
-
- //Set listener for action item clicked
- quickAction.setOnActionItemClickListener(new QuickAction.OnActionItemClickListener() {
- @Override
- public void onItemClick(QuickAction source, int pos, int actionId) {
- //here we can filter which action item was clicked with pos or actionId parameter
- ActionItem actionItem = quickAction.getActionItem(pos);
- PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString(getResources().getString(R.string.selected_language), actionItem.getTitle()).commit();
- String selectedLanguage = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString(getResources().getString(R.string.selected_language), "English");
-
- int i = 0;
- for (String language : languages) {
- ActionItem item = new ActionItem(i, language);
-
- item.setSticky(false);
- item.setIcon(getResources().getDrawable(R.drawable.checkmark));
- item.setImageEnabled(selectedLanguage.equalsIgnoreCase(language));
-
- quickAction.setActionItem(i, item);
- i++;
- }
-
- languagesButton.setText(selectedLanguage);
- Toast.makeText(getApplicationContext(), actionItem.getTitle() + " selected", Toast.LENGTH_SHORT).show();
-
- updateListView();
- }
- });
-
- //set listener for on dismiss event, this listener will be called only if QuickAction dialog was dismissed
- //by clicking the area outside the dialog.
- quickAction.setOnDismissListener(new QuickAction.OnDismissListener() {
- @Override
- public void onDismiss() {
-// Toast.makeText(getApplicationContext(), "Dismissed", Toast.LENGTH_SHORT).show();
- }
- });
-
- quickAction.show(view);
-
- }
-
- protected void updateListView() {
- this.prepareListView();
- }
-
- protected void prepareListView() {
-
- ArrayList data = this.getData();
-
- if (mListView == null) {
- mListView = (ListView) findViewById(R.id.generalList);
- }
- if (data == null) {
- return;
- }
- else if (data != null || data.size() == 0) {
- actionbarTextView.setText(getActionBarTitle());
- }
-
- mListView.setOnItemClickListener(this);
- GeneralAdapter adapter = new GeneralAdapter(this.getApplicationContext(), data, this.actionbarTextView, this, this.getIndexStorageString());
- mListView.setAdapter(adapter);
-
- int currentItem = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getInt(getIndexStorageString(), -1);
-
- if(currentItem >= 0) {
- mListView.setSelection(currentItem);
- }
- }
+ abstract protected void setUI();// {
+//
+// mActionBar = getSupportActionBar();
+// View view = getLayoutInflater().inflate(R.layout.actionbar_custom_view, null);
+// actionbarTextView = (TextView) view.findViewById(R.id.actionbarTextView);
+// mActionBar.setCustomView(view);
+// mActionBar.setDisplayShowCustomEnabled(true);
+// mActionBar.setDisplayShowHomeEnabled(true);
+// mActionBar.setHomeButtonEnabled(true);
+// mActionBar.setDisplayHomeAsUpEnabled(true);
+//
+// mDbManager = DBManager.getInstance(this);
+// languagesButton = (Button) view.findViewById(R.id.languageButton);
+// languagesButton.setOnClickListener(new View.OnClickListener() {
+// @Override
+// public void onClick(View v) {
+// addPopover(v);
+// }
+// });
+// languagesButton.setText(getCurrentLanguage());
+// }
+
+
+
+// protected void addPopover(View view) {
+//
+// //create QuickAction. Use QuickAction.VERTICAL or QuickAction.HORIZONTAL param to define layout
+// //orientation
+// final QuickAction quickAction = new QuickAction(this, QuickAction.VERTICAL);
+// final ArrayList languages = getListOfLanguages();
+//
+// String selectedLanguage = PreferenceManager.getDefaultSharedPreferences(this).getString(getResources().getString(R.string.selected_language), "English");
+// int i = 0;
+// for (String language : languages) {
+//
+// Locale languageLocal = new Locale(language);
+//
+// ActionItem item = new ActionItem(i, languageLocal.getDisplayLanguage());
+//
+// item.setSticky(false);
+// item.setIcon(getResources().getDrawable(R.drawable.checkmark));
+// item.setImageEnabled(selectedLanguage.equalsIgnoreCase(language));
+//
+// quickAction.addActionItem(item);
+// i++;
+// }
+//
+// //Set listener for action item clicked
+// quickAction.setOnActionItemClickListener(new QuickAction.OnActionItemClickListener() {
+// @Override
+// public void onItemClick(QuickAction source, int pos, int actionId) {
+// //here we can filter which action item was clicked with pos or actionId parameter
+// ActionItem actionItem = quickAction.getActionItem(pos);
+// PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putString(getResources().getString(R.string.selected_language), actionItem.getTitle()).commit();
+// String selectedLanguage = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString(getResources().getString(R.string.selected_language), "English");
+//
+// int i = 0;
+// for (String language : languages) {
+//
+// Locale languageLocal = new Locale(language);
+//
+// ActionItem item = new ActionItem(i, languageLocal.getDisplayLanguage());
+//
+// item.setSticky(false);
+// item.setIcon(getResources().getDrawable(R.drawable.checkmark));
+// item.setImageEnabled(selectedLanguage.equalsIgnoreCase(language));
+//
+// quickAction.setActionItem(i, item);
+// i++;
+// }
+//
+//// languagesButton.setText(selectedLanguage);
+// Toast.makeText(getApplicationContext(), actionItem.getTitle() + " selected", Toast.LENGTH_SHORT).show();
+//
+// updateListView();
+// }
+// });
+//
+// //set listener for on dismiss event, this listener will be called only if QuickAction dialog was dismissed
+// //by clicking the area outside the dialog.
+// quickAction.setOnDismissListener(new QuickAction.OnDismissListener() {
+// @Override
+// public void onDismiss() {
+//// Toast.makeText(getApplicationContext(), "Dismissed", Toast.LENGTH_SHORT).show();
+// }
+// });
+//
+// quickAction.show(view);
+//
+// }
+
+// protected void updateListView() {
+// this.prepareListView();
+// }
+
+ abstract protected void prepareListView();// {
+//
+//// ArrayList data = this.getData();
+//
+// if (mListView == null) {
+// mListView = (ListView) findViewById(R.id.generalList);
+// }
+// if (data == null) {
+// return;
+// }
+// else if (data != null || data.size() == 0) {
+// actionbarTextView.setText(getActionBarTitle());
+// }
+//
+// mListView.setOnItemClickListener(this);
+// GeneralAdapter adapter = new GeneralAdapter(this.getApplicationContext(), data, this.actionbarTextView, this, this.getIndexStorageString());
+// mListView.setAdapter(adapter);
+//
+// int currentItem = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getInt(getIndexStorageString(), -1);
+//
+// if(currentItem >= 0) {
+// mListView.setSelection(currentItem);
+// }
+// }
@Override
public void onBackPressed() {
@@ -239,6 +204,7 @@ protected void onResume() {
}
public void onItemClick(AdapterView> adapterView, View view, int position, long rowIndex) {
+
Object itemAtPosition = adapterView.getItemAtPosition(position);
if (itemAtPosition instanceof GeneralRowInterface) {
GeneralRowInterface model = (GeneralRowInterface) itemAtPosition;
@@ -263,15 +229,15 @@ public boolean onOptionsItemSelected(MenuItem item) {
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
- int width = this.languagesButton.getMeasuredWidth();
- actionbarTextView.setPadding(width - 100, 0, 20, 0);
+// int width = this.languagesButton.getMeasuredWidth();
+// actionbarTextView.setPadding(width - 100, 0, 20, 0);
}
public void onlySuperOnWindowFocusChanged(boolean hasFocus){
super.onWindowFocusChanged(hasFocus);
}
- private void handleBack(){
+ protected void handleBack(){
//reset Preference
PreferenceManager.getDefaultSharedPreferences(this).edit().putInt(getIndexStorageString(), -1).commit();
diff --git a/app/app/src/main/java/activity/bookSelection/InitialPageActivity.java b/app/app/src/main/java/activity/bookSelection/InitialPageActivity.java
index 7d8b73e..66c9802 100644
--- a/app/app/src/main/java/activity/bookSelection/InitialPageActivity.java
+++ b/app/app/src/main/java/activity/bookSelection/InitialPageActivity.java
@@ -5,12 +5,15 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.res.Resources;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.View;
+import android.widget.AdapterView;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ListView;
+import android.widget.TextView;
import android.widget.Toast;
import org.unfoldingword.mobile.R;
@@ -21,13 +24,12 @@
import activity.SettingsActivity;
import activity.SplashScreenActivity;
+import activity.reading.ReadingActivity;
+import activity.reading.StoryReadingActivity;
import adapters.selectionAdapters.GeneralAdapter;
import adapters.selectionAdapters.GeneralRowInterface;
import adapters.selectionAdapters.InitialPageModel;
-import model.database.ModelCaching;
import model.datasource.ProjectDataSource;
-import model.database.DBManager;
-import model.modelClasses.mainData.LanguageModel;
import model.modelClasses.mainData.ProjectModel;
import services.UpdateService;
import utils.NetWorkUtil;
@@ -38,7 +40,9 @@
*/
public class InitialPageActivity extends GeneralSelectionActivity implements View.OnClickListener {
- static String INDEX_STORAGE_STRING = "INDEX_STORAGE_STRING";
+ static final String INDEX_STORAGE_STRING = "INDEX_STORAGE_STRING";
+
+ static final String STORIES_SLUG = "obs";
ArrayList mProjects = null;
@@ -66,13 +70,32 @@ public void onReceive(Context context, Intent intent) {
private void reload(){
mProjects = null;
- mDbManager = DBManager.getInstance(getApplicationContext());
- this.updateListView();
+ this.prepareListView();
}
@Override
+ protected void setUI() {
+
+ setupActionBar();
+ this.prepareListView();
+ }
+
+ private void setupActionBar(){
+
+ mActionBar = getSupportActionBar();
+ View view = getLayoutInflater().inflate(R.layout.actionbar_base, null);
+ TextView actionbarTextView = (TextView) view.findViewById(R.id.actionbarTextView);
+ mActionBar.setCustomView(view);
+ mActionBar.setDisplayShowCustomEnabled(true);
+ mActionBar.setDisplayShowHomeEnabled(false);
+ mActionBar.setHomeButtonEnabled(false);
+ mActionBar.setDisplayHomeAsUpEnabled(false);
+ actionbarTextView.setText(getActionBarTitle());
+ }
+
+// @Override
protected String getActionBarTitle() {
- return "Unfolding Word";
+ return getResources().getString(R.string.app_name);
}
@Override
@@ -96,36 +119,13 @@ protected Class getChildClass(GeneralRowInterface row){
return this.getChildClass();
}
-
- @Override
- protected void setUI() {
- super.setUI();
-
- if(settingsButton == null) {
- LayoutInflater inflater = getLayoutInflater();
- View footerView = inflater.inflate(R.layout.settings_footer, null);
-
-
- // change version number
- settingsButton = (Button) footerView.findViewById(R.id.settings_button);
- settingsButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- moveToSettings();
- }
- });
- mListView.addFooterView(footerView);
- this.actionbarTextView.setText("Unfolding Word");
- }
- }
-
private void moveToSettings(){
startActivity(new Intent(this, SettingsActivity.class));
}
- @Override
+// @Override
protected void prepareListView() {
ArrayList data = this.getData();
@@ -133,19 +133,8 @@ protected void prepareListView() {
if (mListView == null) {
mListView = (ListView) findViewById(R.id.generalList);
}
- if (data == null) {
- return;
- }
- else if (data != null || data.size() == 0) {
- actionbarTextView.setText(getActionBarTitle());
- }
-
mListView.setOnItemClickListener(this);
- mActionBar.setDisplayShowHomeEnabled(false);
- mActionBar.setHomeButtonEnabled(false);
- mActionBar.setDisplayHomeAsUpEnabled(false);
-
if(mRefreshButton == null) {
LayoutInflater inflater = getLayoutInflater();
View mview1 = inflater.inflate(R.layout.header_view, null);
@@ -159,19 +148,28 @@ else if (data != null || data.size() == 0) {
registerReceiver(receiver, filter);
}
+ if (data == null) {
+// return;
+ // test code for adding database.
+ data = new ArrayList();
+// data.add(new InitialPageModel("test", "-1"));
+ }
mListView.setAdapter(new GeneralAdapter(this.getApplicationContext(), data, this.actionbarTextView, this, this.getIndexStorageString()));
- }
- @Override
- public void onWindowFocusChanged(boolean hasFocus) {
+ if(settingsButton == null) {
+ LayoutInflater inflater = getLayoutInflater();
+ View footerView = inflater.inflate(R.layout.settings_footer, null);
- super.onlySuperOnWindowFocusChanged(hasFocus);
- int width = this.languagesButton.getMeasuredWidth();
- if(width > 1) {
- actionbarTextView.setPadding(width, 0, 5, 0);
- }
- else{
- actionbarTextView.setPadding(200, 0, 5, 0);
+
+ // change version number
+ settingsButton = (Button) footerView.findViewById(R.id.settings_button);
+ settingsButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ moveToSettings();
+ }
+ });
+ mListView.addFooterView(footerView);
}
}
@@ -180,12 +178,6 @@ protected int getContentView() {
return R.layout.activity_general_list;
}
- @Override
- protected ArrayList getListOfLanguages() {
- return ModelCaching.getAvailableLanguages(getApplicationContext());
- }
-
- @Override
protected ArrayList getData(){
Map data = new HashMap();
@@ -194,76 +186,47 @@ protected ArrayList getData(){
addProjects();
}
- if(mProjects.size() < 1){
-
- Intent refresh = new Intent(this, SplashScreenActivity.class);
- startActivity(refresh);
- this.finish(); //
+ if(mProjects == null || mProjects.size() < 1){
+// Intent refresh = new Intent(this, SplashScreenActivity.class);
+// startActivity(refresh);
+// this.finish();
return null;
}
- String selectedLanguage = PreferenceManager.getDefaultSharedPreferences(this).getString(
- getResources().getString(R.string.selected_language), "English");
-
- Context context = getApplicationContext();
-
- for(ProjectModel project : mProjects){
- if(project.meta.contains("Stories")){
- ArrayList languages = project.getChildModels(context);
-
- for(LanguageModel language : languages){
- if(language.languageName.equalsIgnoreCase(selectedLanguage)){
- data.put(language.projectName, language);
- }
- }
- }
- else if(project.containsLanguage(selectedLanguage, context)) {
-
- String label = project.meta;
-
- if(label.equalsIgnoreCase("bible-nt")){
- label = "Bible New Testament";
- }
- if(label.equalsIgnoreCase("bible-ot")){
- label = "Bible Old Testament";
- }
-
- data.put(project.meta, new InitialPageModel(label, project.meta));
- }
-
- }
-
ArrayList dataList = new ArrayList(3);
- for(GeneralRowInterface row : data.values()) {
+ for(ProjectModel row : mProjects) {
dataList.add(row);
}
- for(GeneralRowInterface row : data.values()){
- int index = 0;
+ return dataList;
+ }
- if(row.getChildIdentifier().contains("bible-nt")){
- index = dataList.size() - 1;
- }
- else if(row.getChildIdentifier().contains("bible-ot")){
- index = dataList.size() - 2;
- }
- else{
- index = 0;
- }
- if(index < 0)
- {
- index = 0;
- }
- dataList.set(index, row);
+ @Override
+ public void onItemClick(AdapterView> adapterView, View view, int position, long rowIndex) {
+
+ Object itemAtPosition = adapterView.getItemAtPosition(position);
+ if (itemAtPosition instanceof GeneralRowInterface) {
+ PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putInt(INDEX_STORAGE_STRING, (int) rowIndex);
+
+ PreferenceManager.getDefaultSharedPreferences(this).edit().putInt(
+ this.getIndexStorageString(), (int) rowIndex).commit();
+
+ ProjectModel model = (ProjectModel) itemAtPosition;
+ moveToNextActivity(model);
}
+ }
+ private void moveToNextActivity(ProjectModel project){
+ Class nextActivity = (project.slug.equalsIgnoreCase(STORIES_SLUG))?
+ StoryReadingActivity.class : ReadingActivity.class;
- return dataList;
+ startActivity(new Intent(this, nextActivity).putExtra(CHOSEN_ID, project.getChildIdentifier()));
+ overridePendingTransition(R.anim.enter_from_right, R.anim.exit_on_left);
}
- private void addProjects() {
+ private void addProjects() {
if(mProjects == null){
mProjects = new ArrayList();
@@ -276,7 +239,7 @@ public void onClick(View view) {
if (!NetWorkUtil.isConnected(this)) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Alert");
- builder.setMessage("Unable to perform update at this time");
+ builder.setMessage("Failed connecting to the internet.");
builder.setPositiveButton("OK", null);
builder.create().show();
} else {
@@ -287,4 +250,7 @@ public void onClick(View view) {
}
+
+ public void closeButtonClicked(View view) {
+ }
}
diff --git a/app/app/src/main/java/activity/bookSelection/StoryChapterSelectionActivity.java b/app/app/src/main/java/activity/bookSelection/StoryChapterSelectionActivity.java
new file mode 100644
index 0000000..c4988d2
--- /dev/null
+++ b/app/app/src/main/java/activity/bookSelection/StoryChapterSelectionActivity.java
@@ -0,0 +1,160 @@
+package activity.bookSelection;
+
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.FrameLayout;
+import android.widget.ImageView;
+import android.widget.ListView;
+import android.widget.TextView;
+
+import com.nostra13.universalimageloader.core.ImageLoader;
+import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
+
+import org.unfoldingword.mobile.R;
+
+import java.util.ArrayList;
+import java.util.Collections;
+
+import activity.reading.ReadingActivity;
+import activity.reading.StoryReadingActivity;
+import adapters.selectionAdapters.GeneralRowInterface;
+import adapters.selectionAdapters.StoriesChapterAdapter;
+import model.datasource.VersionDataSource;
+import model.modelClasses.mainData.BibleChapterModel;
+import model.modelClasses.mainData.BookModel;
+import model.modelClasses.mainData.LanguageModel;
+import model.modelClasses.mainData.StoriesChapterModel;
+import model.modelClasses.mainData.VersionModel;
+import utils.UWPreferenceManager;
+
+/**
+ * Created by Fechner on 2/27/15.
+ */
+public class StoryChapterSelectionActivity extends GeneralSelectionActivity{
+
+ public static String CHAPTERS_INDEX_STRING = "CHAPTERS_INDEX_STRING";
+
+// private VersionModel chosenVersion = null;
+ ImageLoader mImageLoader;
+
+ @Override
+ protected int getContentView() {
+ return R.layout.activity_general_list;
+ }
+
+ @Override
+ protected String getIndexStorageString() {
+ return CHAPTERS_INDEX_STRING;
+ }
+
+ @Override
+ protected Class getChildClass() {
+ return null;
+ }
+
+ @Override
+ protected void setUI() {
+
+ View view = getLayoutInflater().inflate(R.layout.actionbar_base, null);
+ setupActionBar(view);
+ setupCloseButton(view);
+ }
+
+ private void setupActionBar(View view){
+
+ mActionBar = getSupportActionBar();
+ mActionBar.setCustomView(view);
+ mActionBar.setDisplayShowCustomEnabled(true);
+ mActionBar.setDisplayShowHomeEnabled(false);
+ mActionBar.setHomeButtonEnabled(false);
+ mActionBar.setDisplayHomeAsUpEnabled(false);
+
+ actionbarTextView = (TextView) view.findViewById(R.id.actionbarTextView);
+ actionbarTextView.setText("Select Chapter");
+ }
+
+ private void setupCloseButton(View view){
+ FrameLayout closeButton = (FrameLayout) view.findViewById(R.id.close_image_view);
+ closeButton.setVisibility(View.VISIBLE);
+ }
+
+ public void closeButtonClicked(View view) {
+ handleBack();
+ }
+
+ @Override
+ protected void prepareListView() {
+
+ ArrayList chapterModels = this.getData();
+// BookModel book = this.chosenVersion.getChildModels(getApplicationContext()).get(0);
+
+ if (chapterModels != null) {
+ actionbarTextView.setText("Choose Chapter");
+
+ mListView = (ListView) findViewById(R.id.generalList);
+ mListView.setOnItemClickListener(this);
+
+ mImageLoader = ImageLoader.getInstance();
+
+ if (mImageLoader.isInited()) {
+ ImageLoader.getInstance().destroy();
+ }
+
+ mImageLoader.init(ImageLoaderConfiguration.createDefault(this));
+ mListView.setAdapter(new StoriesChapterAdapter(getApplicationContext(), chapterModels, this.actionbarTextView, this, mImageLoader, this.getIndexStorageString()));
+
+ int scrollPosition = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getInt(CHAPTERS_INDEX_STRING, -1);
+ mListView.setSelection((scrollPosition > 0)? scrollPosition - 1 : 0);
+ }
+ }
+
+
+ protected ArrayList getData(){
+
+ String versionId = UWPreferenceManager.getSelectedStoryVersion(getApplicationContext());
+
+ VersionModel version = new VersionDataSource(getApplicationContext()).getModel(versionId);
+
+ ArrayList chapters = version.getChildModels(
+ getApplicationContext()).get(0).getStoryChildModels(getApplicationContext());
+ Collections.sort(chapters);
+
+ long chapterId = Long.parseLong(UWPreferenceManager.getSelectedStoryChapter(getApplicationContext()));
+
+ ArrayList data = new ArrayList();
+ int i = 0;
+ for(StoriesChapterModel model : chapters){
+ if(chapterId == model.uid){
+ PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putInt(CHAPTERS_INDEX_STRING, i).commit();
+ }
+ data.add(model);
+ i++;
+ }
+
+ return data;
+ }
+
+ @Override
+ public void onItemClick(AdapterView> adapterView, View view, int position, long rowIndex) {
+
+ Object itemAtPosition = adapterView.getItemAtPosition(position);
+
+ if (itemAtPosition instanceof StoriesChapterModel) {
+ StoriesChapterModel model = (StoriesChapterModel) itemAtPosition;
+
+ UWPreferenceManager.setSelectedStoryChapter(getApplicationContext(), model.uid);
+ }
+ PreferenceManager.getDefaultSharedPreferences(this).edit().putInt(StoryReadingActivity.STORY_INDEX_STRING, -1).commit();
+ handleBack();
+ }
+
+ @Override
+ protected void handleBack(){
+
+ finish();
+ overridePendingTransition(R.anim.enter_center, R.anim.exit_on_bottom);
+ }
+
+}
diff --git a/app/app/src/main/java/activity/bookSelection/VersionSelectionActivity.java b/app/app/src/main/java/activity/bookSelection/VersionSelectionActivity.java
index ea06376..b942b2b 100644
--- a/app/app/src/main/java/activity/bookSelection/VersionSelectionActivity.java
+++ b/app/app/src/main/java/activity/bookSelection/VersionSelectionActivity.java
@@ -1,68 +1,102 @@
package activity.bookSelection;
import android.os.Bundle;
-import android.preference.PreferenceManager;
+import android.support.v7.app.ActionBar;
+import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
+import android.view.MenuItem;
import android.view.View;
-import android.widget.ListView;
+import android.widget.ExpandableListView;
+import android.widget.FrameLayout;
+import android.widget.ImageView;
import android.widget.TextView;
import org.unfoldingword.mobile.BuildConfig;
import org.unfoldingword.mobile.R;
-import java.util.ArrayList;
-
-import adapters.selectionAdapters.GeneralRowInterface;
-import adapters.selectionAdapters.VersionAdapter;
-import model.datasource.LanguageDataSource;
-import model.modelClasses.mainData.LanguageModel;
+import adapters.selectionAdapters.CollapsibleVersionAdapter;
+import model.datasource.ProjectDataSource;
+import model.datasource.VersionDataSource;
+import model.modelClasses.mainData.ProjectModel;
import model.modelClasses.mainData.VersionModel;
+import utils.UWPreferenceManager;
/**
* Created by Fechner on 2/27/15.
*/
-public class VersionSelectionActivity extends GeneralSelectionActivity {
+public class VersionSelectionActivity extends ActionBarActivity {
- static String VERSIONS_INDEX_STRING = "VERSIONS_INDEX_STRING";
+ static final String VERSIONS_INDEX_STRING = "VERSIONS_INDEX_STRING";
+ static final String STORIES_SLUG = "obs";
- VersionAdapter adapter;
+ CollapsibleVersionAdapter adapter;
private View footerView = null;
- private LanguageModel chosenLanguage = null;
+ private ProjectModel chosenProject = null;
- @Override
- protected int getContentView() {
- return R.layout.activity_general_list;
- }
+ private ActionBar mActionBar = null;
+
+ protected ExpandableListView mListView = null;
@Override
- protected ArrayList getListOfLanguages() {
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_version_selector);
+ setUI();
+ prepareListView();
+ }
- if (chosenLanguage == null) {
- addLanguage();
- }
+ private void setUI() {
- return chosenLanguage.getAvailableLanguages(getApplicationContext());
+ View view = getLayoutInflater().inflate(R.layout.actionbar_base, null);
+ setupActionBar(view);
+ setupCloseButton(view);
+ }
+ private void setupActionBar(View view){
+
+ mActionBar = getSupportActionBar();
+ TextView actionbarTextView = (TextView) view.findViewById(R.id.actionbarTextView);
+ mActionBar.setCustomView(view);
+ mActionBar.setDisplayShowCustomEnabled(true);
+ mActionBar.setDisplayShowHomeEnabled(false);
+ mActionBar.setHomeButtonEnabled(false);
+ mActionBar.setDisplayHomeAsUpEnabled(false);
+ actionbarTextView.setText("Select Version");
}
- @Override
- protected String getIndexStorageString() {
- return VERSIONS_INDEX_STRING;
+ private void setupCloseButton(View view){
+ FrameLayout closeButton = (FrameLayout) view.findViewById(R.id.close_image_view);
+ closeButton.setVisibility(View.VISIBLE);
}
- @Override
- protected Class getChildClass() {
- return ChapterSelectionActivity.class;
+ public void closeButtonClicked(View view) {
+ handleBack();
}
- @Override
- protected String getActionBarTitle() {
- return chosenLanguage.projectName;
+ private void addProject(){
+
+ Bundle extras = getIntent().getExtras();
+ if (extras != null) {
+
+ String chosenProjectId = extras.getString(GeneralSelectionActivity.CHOSEN_ID);
+ this.chosenProject = new ProjectDataSource(this.getApplicationContext()).getModel(chosenProjectId);
+ }
}
- @Override
- protected void setUI() {
- super.setUI();
+ protected void prepareListView(){
+
+ //getting instance of ExpandableListView
+ mListView = (ExpandableListView) findViewById(R.id.versions_list);
+// mListView.setOnItemClickListener(this);
+
+// ArrayList data = this.getData();
+
+ if (chosenProject == null) {
+ addProject();
+ }
+
+ adapter = new CollapsibleVersionAdapter(this, this.chosenProject);
+ mListView.setAdapter(adapter);
if(footerView == null) {
LayoutInflater inflater = getLayoutInflater();
@@ -75,71 +109,74 @@ protected void setUI() {
tView.setText(versionName);
mListView.addFooterView(footerView);
}
- }
-
- protected ArrayList getData(){
-
- if (chosenLanguage == null) {
- addLanguage();
- }
-
- String selectedLanguage = PreferenceManager.getDefaultSharedPreferences(this).getString(
- getResources().getString(R.string.selected_language), "English");
- if(!chosenLanguage.languageName.equalsIgnoreCase(selectedLanguage)){
- LanguageModel correctLanguage = null;
+ int selectedIndex = 0;
+ if(chosenProject.slug.equalsIgnoreCase(STORIES_SLUG)){
- ArrayList languages = chosenLanguage.getParent(getApplicationContext()).getChildModels(getApplicationContext());
-
- for(LanguageModel model : languages){
- if(selectedLanguage.equalsIgnoreCase(model.languageName)){
- correctLanguage = model;
- break;
- }
+ String selectedVersion = UWPreferenceManager.getSelectedStoryVersion(getApplicationContext());
+ if(Long.parseLong(selectedVersion) < 0){
+ selectedIndex = 0;
}
- if(correctLanguage != null){
- chosenLanguage = correctLanguage;
+ else {
+ VersionModel version = new VersionDataSource(getApplicationContext()).getModel(selectedVersion);
+
+ for(int i = 0; i < chosenProject.getChildModels(getApplicationContext()).size(); i++){
+ if(chosenProject.getChildModels(getApplicationContext()).get(i).slug.equalsIgnoreCase(version.getParent(getApplicationContext()).slug)){
+ selectedIndex = i;
+ break;
+ }
+ }
}
}
-
- ArrayList versions = this.chosenLanguage.getChildModels(getApplicationContext());
-
- ArrayList data = new ArrayList();
- for(VersionModel model : versions){
- data.add(model);
+ else{
+ String selectedVersion = UWPreferenceManager.getSelectedBibleVersion(getApplicationContext());
+ if(Long.parseLong(selectedVersion) < 0){
+ selectedIndex = 0;
+ }
+ else {
+ VersionModel version = new VersionDataSource(getApplicationContext()).getModel(selectedVersion);
+
+ for(int i = 0; i < chosenProject.getChildModels(getApplicationContext()).size(); i++){
+ if(chosenProject.getChildModels(getApplicationContext()).get(i).slug.equalsIgnoreCase(version.getParent(getApplicationContext()).slug)){
+ selectedIndex = i;
+ break;
+ }
+ }
+ }
}
- return data;
+ mListView.expandGroup(selectedIndex);
}
- private void addLanguage(){
-
- Bundle extras = getIntent().getExtras();
- if (extras != null) {
-
- String chosenVersion = extras.getString(CHOSEN_ID);
- this.chosenLanguage = new LanguageDataSource(this.getApplicationContext()).getModel(chosenVersion);
- }
+ @Override
+ public void onBackPressed() {
+ handleBack();
}
@Override
- protected void prepareListView(){
-
- //getting instance of ExpandableListView
- mListView = (ListView) findViewById(R.id.generalList);
- mListView.setOnItemClickListener(this);
+ protected void onResume() {
+ super.onResume();
+ prepareListView();
+ }
- ArrayList data = this.getData();
+ private void handleBack(){
+ adapter.willDestroy();
+ finish();
+ overridePendingTransition(R.anim.enter_center, R.anim.exit_on_bottom);
+ }
- if (data == null) {
- return;
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ handleBack();
}
-
- adapter = new VersionAdapter(this, data, actionbarTextView, this, this.getIndexStorageString());
- mListView.setAdapter(adapter);
-
- actionbarTextView.setText(getActionBarTitle());
+ return super.onOptionsItemSelected(item);
}
+ @Override
+ public void finish() {
+ adapter.willDestroy();
+ super.finish();
+ }
}
diff --git a/app/app/src/main/java/activity/reading/ReadingActivity.java b/app/app/src/main/java/activity/reading/ReadingActivity.java
index 99fa10b..ca4b9a9 100644
--- a/app/app/src/main/java/activity/reading/ReadingActivity.java
+++ b/app/app/src/main/java/activity/reading/ReadingActivity.java
@@ -2,76 +2,89 @@
import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.view.ViewPager;
+import android.support.v7.app.ActionBar;
+import android.support.v7.app.ActionBarActivity;
import android.view.Display;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
+import android.widget.LinearLayout;
+import android.widget.TextView;
import org.unfoldingword.mobile.R;
import java.util.ArrayList;
+import activity.bookSelection.BookSelectionActivity;
import activity.bookSelection.GeneralSelectionActivity;
+import activity.bookSelection.VersionSelectionActivity;
import adapters.ReadingPagerAdapter;
-import adapters.selectionAdapters.GeneralRowInterface;
import model.datasource.BibleChapterDataSource;
+import model.datasource.VersionDataSource;
import model.modelClasses.mainData.BibleChapterModel;
-import model.modelClasses.mainData.LanguageModel;
+import model.modelClasses.mainData.ProjectModel;
import model.modelClasses.mainData.VersionModel;
+import utils.UWPreferenceManager;
/**
* Created by Acts Media Inc on 5/12/14.
*/
-public class ReadingActivity extends GeneralSelectionActivity {
+public class ReadingActivity extends ActionBarActivity {
- static String BOOK_INDEX_STRING = "READING_INDEX_STRING";
+ static final public String BOOK_INDEX_STRING = "READING_INDEX_STRING";
- ViewPager readingViewPager = null;
+ private ViewPager readingViewPager = null;
+ private ActionBar mActionBar = null;
+ private LinearLayout versionsButton = null;
+ private LinearLayout chaptersButton = null;
+ private TextView versionsTextView = null;
+ private TextView chapterTextView = null;
- VersionModel versionModel = null;
- BibleChapterModel chapterModel = null;
+ private BibleChapterModel mChapter = null;
+ private ProjectModel selectedProject = null;
@Override
- protected int getContentView() {
- return R.layout.activity_reading;
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_reading);
+ setData();
+ if(mChapter == null || selectedProject == null){
+ goToVersionSelection();
+ }
}
+
@Override
- protected ArrayList getListOfLanguages() {
+ protected void onStart() {
+ super.onStart();
+ if(mChapter == null || selectedProject == null) {
+ setContentView(R.layout.activity_reading);
+ }
+ selectedProject = null;
+ mChapter = null;
+ setData();
+ setUI();
- if(versionModel == null){
- setVersion();
+ if(mChapter == null || selectedProject == null){
+ setContentView(R.layout.no_text_layout);
}
- return versionModel.getAvailableLanguages(getApplicationContext());
- }
- @Override
- protected ArrayList getData() {
- return null;
- }
- @Override
- protected String getIndexStorageString() {
- return BOOK_INDEX_STRING;
- }
- @Override
- protected Class getChildClass() {
- return null;
+ else {
+ setupPager();
+ }
+
}
- @Override
protected void updateListView() {
- setVersion();
+ setData();
this.setUIWithCurrentIndex();
}
- @Override
- protected String getActionBarTitle() {
- return chapterModel.getTitle();
- }
-
protected void setUIWithCurrentIndex() {
int index = readingViewPager.getCurrentItem();
@@ -81,83 +94,119 @@ protected void setUIWithCurrentIndex() {
/**
* Initializing the components
*/
- @Override
protected void setUI() {
+ setData();
+ setupActionBar();
+ }
- super.setUI();
+ private void setupActionBar(){
+ View view = getLayoutInflater().inflate(R.layout.actionbar_custom_view, null);
- readingViewPager = (ViewPager) findViewById(R.id.myViewPager);
+ mActionBar = getSupportActionBar();
+ chaptersButton = (LinearLayout) view.findViewById(R.id.middle_button);
+ mActionBar.setCustomView(view);
+ mActionBar.setDisplayShowCustomEnabled(true);
+ mActionBar.setDisplayShowHomeEnabled(true);
+ mActionBar.setHomeButtonEnabled(true);
+ mActionBar.setDisplayHomeAsUpEnabled(true);
- if(versionModel == null){
- this.setVersion();
- }
- actionbarTextView.setText(chapterModel.getTitle());
- ReadingPagerAdapter adapter = new ReadingPagerAdapter(this, versionModel.getBibleChildModels(getApplicationContext()),
- actionbarTextView, getIndexStorageString());
+ setupChapterButton(view);
+ setupVersionButton(view);
+ }
- readingViewPager.setAdapter(adapter);
- setupTouchListener(readingViewPager);
- int currentItem = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getInt(getIndexStorageString(), -1);
+ private void setupChapterButton(View view){
- if(currentItem < 0){
- currentItem = Integer.parseInt(chapterModel.number.replaceAll("[^0-9]", "")) - 1;
+ chaptersButton = (LinearLayout) view.findViewById(R.id.middle_button);
+ chapterTextView = (TextView) view.findViewById(R.id.middle_button_text);
+ if(this.mChapter != null) {
+ chapterTextView.setText(this.mChapter.getTitle(getApplicationContext()));
+ }
+ else{
+ chaptersButton.setVisibility(View.INVISIBLE);
+ chapterTextView.setText("");
}
- readingViewPager.setCurrentItem(currentItem);
}
- private void setVersion(){
-
- if(chapterModel == null) {
- Bundle extras = getIntent().getExtras();
- if (extras != null) {
+ public void updateChapter(String title){
+ this.chapterTextView.setText(title);
+ versionsButton.forceLayout();
+ }
- String chosenChapter = extras.getString(CHOSEN_ID);
- BibleChapterModel chapter = (new BibleChapterDataSource(this.getApplicationContext())).getModel(chosenChapter);
- chapterModel = chapter;
+ private void setupVersionButton(View view) {
- this.versionModel = chapter.getParent(getApplicationContext());
- checkForLanguageChange();
- }
+ versionsButton = (LinearLayout) view.findViewById(R.id.language_button);
+ versionsTextView = (TextView) view.findViewById(R.id.language_text);
+ if(this.mChapter != null) {
+ versionsTextView.setText(this.mChapter.getParent(getApplicationContext()).getParent(getApplicationContext()).slug);
}
else{
- checkForLanguageChange();
+ versionsTextView.setText("Select Version");
+ }
+ }
+
+ private void setupPager(){
+
+ readingViewPager = (ViewPager) findViewById(R.id.myViewPager);
+
+ ArrayList chapters = mChapter.getParent(getApplicationContext()).getBibleChildModels(getApplicationContext());
+ ReadingPagerAdapter adapter = new ReadingPagerAdapter(this, chapters, chapterTextView, BOOK_INDEX_STRING, getDoubleTapTouchListener());
+
+ readingViewPager.setAdapter(adapter);
+ readingViewPager.setOnTouchListener(getDoubleTapTouchListener());
+
+ int currentItem = Integer.parseInt(mChapter.number.replaceAll("[^0-9]", "")) - 1;
+ readingViewPager.setCurrentItem(currentItem);
+ }
+
+ private void goToVersionSelection(){
+
+ Bundle extras = getIntent().getExtras();
+ if (extras == null) {
+ return;
}
+ String projectId = extras.getString(GeneralSelectionActivity.CHOSEN_ID);
+ startActivity(new Intent(this, VersionSelectionActivity.class).putExtra(
+ GeneralSelectionActivity.CHOSEN_ID, projectId));
+ overridePendingTransition(R.anim.enter_from_bottom, R.anim.enter_center);
}
- private void checkForLanguageChange(){
+ private void goToChapterActivity(){
+
+ startActivity(new Intent(getApplicationContext(), BookSelectionActivity.class));
+ overridePendingTransition(R.anim.enter_from_bottom, R.anim.enter_center);
+ }
- String selectedLanguage = PreferenceManager.getDefaultSharedPreferences(this).getString(
- getResources().getString(R.string.selected_language), "English");
- Context context = getApplicationContext();
+ private void setData(){
- if(!chapterModel.getParent(context).getParent(context).languageName.equalsIgnoreCase(selectedLanguage)){
- LanguageModel correctLanguage = null;
+ if(mChapter == null || selectedProject == null) {
+ Bundle extras = getIntent().getExtras();
+ if (extras != null) {
+ Context context = getApplicationContext();
- ArrayList languages = chapterModel.getParent(context).
- getParent(getApplicationContext()).getParent(getApplicationContext()).
- getChildModels(getApplicationContext());
+ Long versionId = Long.parseLong(UWPreferenceManager.getSelectedBibleVersion(context));
- for(LanguageModel model : languages){
- if(selectedLanguage.equalsIgnoreCase(model.languageName)){
- correctLanguage = model;
- break;
+ if(versionId < 0){
+ return;
}
- }
- if(correctLanguage != null){
- ArrayList chapters = correctLanguage.getChildModels(context)
- .get(0).getBibleChildModels(context);
+ VersionModel currentVersion = new VersionDataSource(context).getModel(Long.toString(versionId));
- for(BibleChapterModel model : chapters){
- if(model.number.equalsIgnoreCase(chapterModel.number)){
- chapterModel = model;
- this.versionModel = chapterModel.getParent(context);
- break;
- }
+ this.selectedProject = currentVersion.getParent(context).getParent(context);
+
+ Long chapterId = Long.parseLong(UWPreferenceManager.getSelectedBibleChapter(context));
+
+ if(chapterId < 0){
+ this.mChapter = currentVersion.getChildModels(context).get(0).getBibleChapter(context, 1);
+ UWPreferenceManager.setSelectedBibleChapter(context, this.mChapter.uid);
+ }
+ else {
+ this.mChapter = new BibleChapterDataSource(getApplicationContext()).getModel(Long.toString(chapterId));
}
}
}
+ else{
+ }
}
private void handleActionBarHidden(boolean hide){
@@ -171,26 +220,34 @@ private void handleActionBarHidden(boolean hide){
}
- private void setupTouchListener(View view){
+ private View.OnTouchListener getDoubleTapTouchListener(){
- view.setOnTouchListener(new View.OnTouchListener() {
+ return new View.OnTouchListener() {
Handler handler = new Handler();
+
int numberOfTaps = 0;
long lastTapTimeMs = 0;
long touchDownMs = 0;
+ Resources res = getResources();
+ int tapTimeout = res.getInteger(R.integer.tap_timeout);
+ int doubleTapTimeout = res.getInteger(R.integer.double_tap_timeout);
+
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touchDownMs = System.currentTimeMillis();
+ if ((numberOfTaps > 0)
+ && (System.currentTimeMillis() - lastTapTimeMs) < doubleTapTimeout) {
+ return true;
+ }
break;
case MotionEvent.ACTION_UP:
handler.removeCallbacksAndMessages(null);
- int tapTimeout = ViewConfiguration.getTapTimeout();
if ((System.currentTimeMillis() - touchDownMs) > tapTimeout) {
//it was not a tap
@@ -199,8 +256,8 @@ public boolean onTouch(View v, MotionEvent event) {
break;
}
- if (numberOfTaps > 0
- && (System.currentTimeMillis() - lastTapTimeMs) < ViewConfiguration.getDoubleTapTimeout()) {
+ if ((numberOfTaps > 0)
+ && (System.currentTimeMillis() - lastTapTimeMs) < doubleTapTimeout) {
numberOfTaps += 1;
} else {
numberOfTaps = 1;
@@ -222,7 +279,7 @@ public boolean onTouch(View v, MotionEvent event) {
return false;
}
- });
+ };
}
private int getScreenOrientation()
@@ -242,10 +299,33 @@ private int getScreenOrientation()
private void checkShouldChangeNavBarHidden(){
// boolean shouldHide = (getScreenOrientation() == 1)? mActionBar.isShowing() : false;
-
boolean shouldHide = mActionBar.isShowing();
handleActionBarHidden(shouldHide);
}
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ handleBack();
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ private void handleBack(){
+
+ //reset Preference
+ PreferenceManager.getDefaultSharedPreferences(this).edit().putInt(BOOK_INDEX_STRING, -1).commit();
+ finish();
+ overridePendingTransition(R.anim.left_in, R.anim.right_out);
+
+ }
+
+ public void chapterButtonClicked(View view) {
+ goToChapterActivity();
+ }
+
+ public void versionButtonClicked(View view) {
+ goToVersionSelection();
+ }
}
diff --git a/app/app/src/main/java/activity/reading/StoryReadingActivity.java b/app/app/src/main/java/activity/reading/StoryReadingActivity.java
index a18d90b..ca9bcf5 100644
--- a/app/app/src/main/java/activity/reading/StoryReadingActivity.java
+++ b/app/app/src/main/java/activity/reading/StoryReadingActivity.java
@@ -2,92 +2,144 @@
import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v4.view.ViewPager;
+import android.support.v7.app.ActionBar;
+import android.support.v7.app.ActionBarActivity;
import android.view.Display;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import android.widget.TextView;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import org.unfoldingword.mobile.R;
-import java.util.ArrayList;
+import java.util.Locale;
import activity.bookSelection.GeneralSelectionActivity;
-import adapters.selectionAdapters.GeneralRowInterface;
+import activity.bookSelection.StoryChapterSelectionActivity;
+import activity.bookSelection.VersionSelectionActivity;
import adapters.StoryPagerAdapter;
import model.datasource.StoriesChapterDataSource;
-import model.modelClasses.mainData.LanguageModel;
+import model.datasource.VersionDataSource;
+import model.modelClasses.mainData.ProjectModel;
import model.modelClasses.mainData.StoriesChapterModel;
+import model.modelClasses.mainData.VersionModel;
+import utils.UWPreferenceManager;
/**
* Created by Acts Media Inc on 5/12/14.
*/
-public class StoryReadingActivity extends GeneralSelectionActivity {
+public class StoryReadingActivity extends ActionBarActivity {
- static String STORY_INDEX_STRING = "STORY_INDEX_STRING";
+ static final public String STORY_INDEX_STRING = "STORY_INDEX_STRING";
- ViewPager readingViewPager = null;
- ImageLoader mImageLoader;
+ private ViewPager readingViewPager = null;
+ private ActionBar mActionBar = null;
+ private LinearLayout versionsButton = null;
+ private LinearLayout chaptersButton = null;
+ private TextView versionsTextView = null;
+ private TextView chapterTextView = null;
- StoriesChapterModel storiesChapterModel = null;
+ ImageLoader mImageLoader = null;
+
+ private StoriesChapterModel mChapter = null;
+ private ProjectModel selectedProject = null;
@Override
- protected int getContentView() {
- return R.layout.activity_reading;
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_reading);
+
+ setData();
+ if(mChapter == null || selectedProject == null){
+ goToVersionSelection();
+ }
}
+
@Override
- protected ArrayList getListOfLanguages() {
+ protected void onStart() {
+ super.onStart();
+ if(mChapter == null || selectedProject == null) {
+ setContentView(R.layout.activity_reading);
+ }
+ selectedProject = null;
+ mChapter = null;
+ setData();
+ setUI();
- if(storiesChapterModel == null){
- setChapter();
+ if(mChapter == null || selectedProject == null){
+ setContentView(R.layout.no_text_layout);
+ }
+ else {
+ setupPager();
}
- return storiesChapterModel.getAvailableLanguages(getApplicationContext());
}
- @Override
- protected ArrayList getData() {
- return null;
- }
- @Override
- protected String getIndexStorageString() {
- return STORY_INDEX_STRING;
- }
- @Override
- protected Class getChildClass() {
- return null;
+
+ protected void setUI() {
+
+ setupActionBar();
+
+ if(mChapter == null || selectedProject == null){
+ return;
+ }
+
+ setupPager();
}
+ private void setupActionBar(){
+ View view = getLayoutInflater().inflate(R.layout.actionbar_custom_view, null);
- @Override
- protected String getActionBarTitle() {
- return this.storiesChapterModel.getTitle();
+ mActionBar = getSupportActionBar();
+ chaptersButton = (LinearLayout) view.findViewById(R.id.middle_button);
+ mActionBar.setCustomView(view);
+ mActionBar.setDisplayShowCustomEnabled(true);
+ mActionBar.setDisplayShowHomeEnabled(true);
+ mActionBar.setHomeButtonEnabled(true);
+ mActionBar.setDisplayHomeAsUpEnabled(true);
+
+ setupChapterButton(view);
+ setupVersionButton(view);
}
- @Override
- protected void updateListView() {
- setChapter();
- this.setUIWithCurrentIndex();
+ private void setupChapterButton(View view){
+
+ chaptersButton = (LinearLayout) view.findViewById(R.id.middle_button);
+ chapterTextView = (TextView) view.findViewById(R.id.middle_button_text);
+ if(this.mChapter != null) {
+ chapterTextView.setText(this.mChapter.title);
+ }
+ else{
+ chaptersButton.setVisibility(View.INVISIBLE);
+ chapterTextView.setText("");
+ }
}
- protected void setUIWithCurrentIndex() {
- int index =readingViewPager.getCurrentItem();
- setUI();
- readingViewPager.setCurrentItem(index);
+ private void setupVersionButton(View view) {
+
+ versionsButton = (LinearLayout) view.findViewById(R.id.language_button);
+ versionsTextView = (TextView) view.findViewById(R.id.language_text);
+ if(this.mChapter != null) {
+ Locale currentLocale = new Locale(this.mChapter.getParent(getApplicationContext()).getParent(getApplicationContext()).getParent(getApplicationContext()).languageAbbreviation);
+ versionsTextView.setText(currentLocale.getDisplayLanguage());
+ }
+ else{
+ versionsTextView.setText("Select Version");
+ }
}
- /**
- * Initializing the components
- */
- @Override
- protected void setUI() {
- super.setUI();
+ private void setupPager(){
readingViewPager = (ViewPager) findViewById(R.id.myViewPager);
mImageLoader = ImageLoader.getInstance();
@@ -96,93 +148,71 @@ protected void setUI() {
ImageLoader.getInstance().destroy();
}
+ int currentItem = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getInt(STORY_INDEX_STRING, -1);
mImageLoader.init(ImageLoaderConfiguration.createDefault(this));
- if(storiesChapterModel == null){
- this.setChapter();
- }
- actionbarTextView.setText(storiesChapterModel.getTitle());
- StoryPagerAdapter adapter = new StoryPagerAdapter(this, storiesChapterModel,
- mImageLoader,
- actionbarTextView, getIndexStorageString());
+ StoryPagerAdapter adapter = new StoryPagerAdapter(this, mChapter,
+ mImageLoader, chapterTextView, STORY_INDEX_STRING);
readingViewPager.setAdapter(adapter);
setupTouchListener(readingViewPager);
- int currentItem = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getInt(getIndexStorageString(), -1);
-
if(currentItem > 0){
readingViewPager.setCurrentItem(currentItem);
}
-
}
- private void setChapter(){
+ private void goToVersionSelection(){
Bundle extras = getIntent().getExtras();
- if (extras != null) {
-
- String chosenChapter = extras.getString(CHOSEN_ID);
- StoriesChapterModel chapter = (new StoriesChapterDataSource(this.getApplicationContext())).getModel(chosenChapter);
-
- this.storiesChapterModel = chapter;
- checkForLanguageChange();
+ if (extras == null) {
+ return;
}
+ String projectId = extras.getString(GeneralSelectionActivity.CHOSEN_ID);
+ startActivity(new Intent(this, VersionSelectionActivity.class).putExtra(
+ GeneralSelectionActivity.CHOSEN_ID, projectId));
+ overridePendingTransition(R.anim.enter_from_bottom, R.anim.enter_center);
}
- private void checkForLanguageChange(){
+ private void goToChapterActivity(){
- String selectedLanguage = PreferenceManager.getDefaultSharedPreferences(this).getString(
- getResources().getString(R.string.selected_language), "English");
+ startActivity(new Intent(getApplicationContext(), StoryChapterSelectionActivity.class));
+ overridePendingTransition(R.anim.enter_from_bottom, R.anim.enter_center);
+ }
- Context context = getApplicationContext();
+ private void setData(){
- if(!storiesChapterModel.getParent(context).getParent(context).getParent(context).languageName.equalsIgnoreCase(selectedLanguage)){
- LanguageModel correctLanguage = null;
+ if(mChapter == null || selectedProject == null) {
+ Bundle extras = getIntent().getExtras();
+ if (extras != null) {
+ Context context = getApplicationContext();
- ArrayList languages = storiesChapterModel.getParent(context).
- getParent(getApplicationContext()).getParent(getApplicationContext()).
- getParent(context).getChildModels(getApplicationContext());
+ Long versionId = Long.parseLong(UWPreferenceManager.getSelectedStoryVersion(context));
- for(LanguageModel model : languages){
- if(selectedLanguage.equalsIgnoreCase(model.languageName)){
- correctLanguage = model;
- break;
+ if(versionId < 0){
+ return;
}
- }
- if(correctLanguage != null){
+ VersionModel currentVersion = new VersionDataSource(context).getModel(Long.toString(versionId));
- ArrayList chapters = correctLanguage.getChildModels(context)
- .get(0).getStoriesChildModels(context).get(0).getChildModels(context);
+ this.selectedProject = currentVersion.getParent(context).getParent(context);
- for(StoriesChapterModel model : chapters){
+ Long chapterId = Long.parseLong(UWPreferenceManager.getSelectedStoryChapter(context));
- if(model.number.equalsIgnoreCase(storiesChapterModel.number)){
- storiesChapterModel = model;
- break;
- }
+ if(chapterId < 0){
+ this.mChapter = currentVersion.getChildModels(context).get(0).getStoryChapter(context, 1);
+ UWPreferenceManager.setSelectedStoryChapter(context, this.mChapter.uid);
+ }
+ else {
+ this.mChapter = new StoriesChapterDataSource(getApplicationContext()).getModel(Long.toString(chapterId));
}
}
}
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (item.getItemId() == android.R.id.home) {
- ImageLoader.getInstance().destroy();
+ else{
}
- return super.onOptionsItemSelected(item);
}
- @Override
- public void onBackPressed() {
- ImageLoader.getInstance().destroy();
- super.onBackPressed();
- }
-
-
private void handleActionBarHidden(boolean hide){
if( hide){
@@ -202,6 +232,10 @@ private void setupTouchListener(View view){
long lastTapTimeMs = 0;
long touchDownMs = 0;
+ Resources res = getResources();
+ int tapTimeout = res.getInteger(R.integer.tap_timeout);
+ int doubleTapTimeout = res.getInteger(R.integer.double_tap_timeout);
+
@Override
public boolean onTouch(View v, MotionEvent event) {
@@ -212,7 +246,6 @@ public boolean onTouch(View v, MotionEvent event) {
case MotionEvent.ACTION_UP:
handler.removeCallbacksAndMessages(null);
- int tapTimeout = ViewConfiguration.getTapTimeout();
if ((System.currentTimeMillis() - touchDownMs) > tapTimeout) {
//it was not a tap
@@ -221,8 +254,8 @@ public boolean onTouch(View v, MotionEvent event) {
break;
}
- if (numberOfTaps > 0
- && (System.currentTimeMillis() - lastTapTimeMs) < ViewConfiguration.getDoubleTapTimeout()) {
+ if ((numberOfTaps > 0)
+ && ((System.currentTimeMillis() - lastTapTimeMs) < doubleTapTimeout)) {
numberOfTaps += 1;
} else {
numberOfTaps = 1;
@@ -267,4 +300,38 @@ private void checkShouldChangeNavBarHidden(){
boolean shouldHide = mActionBar.isShowing();
handleActionBarHidden(shouldHide);
}
+
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ if(mImageLoader != null) {
+ ImageLoader.getInstance().destroy();
+ }
+ }
+ handleBack();
+ return true;
+ }
+
+ @Override
+ public void onBackPressed() {
+ ImageLoader.getInstance().destroy();
+ handleBack();
+ }
+
+ private void handleBack(){
+
+ //reset Preference
+ PreferenceManager.getDefaultSharedPreferences(this).edit().putInt(STORY_INDEX_STRING, -1).commit();
+ finish();
+ overridePendingTransition(R.anim.left_in, R.anim.right_out);
+ }
+
+ public void chapterButtonClicked(View view) {
+ goToChapterActivity();
+ }
+
+ public void versionButtonClicked(View view) {
+ goToVersionSelection();
+ }
}
diff --git a/app/app/src/main/java/adapters/ReadingPagerAdapter.java b/app/app/src/main/java/adapters/ReadingPagerAdapter.java
index bd85412..88204a0 100644
--- a/app/app/src/main/java/adapters/ReadingPagerAdapter.java
+++ b/app/app/src/main/java/adapters/ReadingPagerAdapter.java
@@ -2,65 +2,83 @@
import android.app.Activity;
import android.content.Context;
-import android.content.Intent;
-import android.preference.PreferenceManager;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
-import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
+import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;
-import com.nostra13.universalimageloader.core.DisplayImageOptions;
-
import org.unfoldingword.mobile.R;
import java.util.ArrayList;
import java.util.Collections;
-import activity.bookSelection.ChapterSelectionActivity;
+import activity.reading.ReadingActivity;
import model.database.DBManager;
import model.modelClasses.mainData.BibleChapterModel;
-import model.modelClasses.mainData.VersionModel;
+import model.modelClasses.mainData.BookModel;
+import utils.UWPreferenceManager;
/**
* Created by Acts Media Inc on 5/12/14.
*/
public class ReadingPagerAdapter extends PagerAdapter {
-
private static final String TAG = "ViewPagerAdapter";
-
protected String SELECTED_POS = "";
- DisplayImageOptions options;
- View view = null;
DBManager dbManager = null;
- private Intent intent;
- private Activity activity;
- private static Context context;
- private TextView actionbarTextView;
+ private Activity context;
+ private TextView chaptersText;
private ViewGroup container;
private ArrayList chapters;
- private VersionModel selectedVersion;
+ private View.OnTouchListener pagerOnTouchListener;
- public ReadingPagerAdapter(Object context, ArrayList models, TextView actionbarTextView, String positionHolder) {
- this.context = (Context) context;
+ private BookModel nextBook;
+
+ public ReadingPagerAdapter(Object context, ArrayList models, TextView chaptersText, String positionHolder, View.OnTouchListener pagerOnTouchListener) {
+ this.context = (Activity) context;
Collections.sort(models);
chapters = models;
getCount();
- this.actionbarTextView = actionbarTextView;
+ this.chaptersText = chaptersText;
dbManager = DBManager.getInstance(this.context);
- this.activity = (Activity) context;
SELECTED_POS = positionHolder;
+ this.pagerOnTouchListener = pagerOnTouchListener;
+ setNextBook();
+ }
+
+ public void setNextBook(){
+
+ ArrayList versionBooks = chapters.get(0).getParent(context).getParent(context).getChildModels(context);
+
+ long currentBookId = chapters.get(0).getParent(context).uid;
+ int currentIndex = -1;
+
+ for(int i = 0; i < versionBooks.size(); i++){
+
+ BookModel book = versionBooks.get(i);
+ if(book.uid == currentBookId){
+ currentIndex = i + 1;
+ break;
+ }
+ }
+
+ if(currentIndex < 0 || currentIndex >= versionBooks.size()){
+ currentIndex = 0;
+ }
+
+ BookModel newBook = versionBooks.get(currentIndex);
+ this.nextBook = newBook;
}
@Override
public int getCount() {
- return chapters.size();
+ return chapters.size() + 1;
}
@Override
@@ -68,40 +86,47 @@ public Object instantiateItem(final ViewGroup container, final int position) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.container = container;
+ View view = null;
- // getting last row values of data base
- int frameCount = chapters.size();
+ if (position == getCount() - 1) {
+ view = getNextBookView(inflater);
+ ((ViewPager) container).addView(view);
- view = inflater.inflate(R.layout.reading_pager_layout, container, false);
- view.setEnabled(false);
- WebView textWebView = (WebView) view.findViewById(R.id.chapterWebView);
- textWebView.getSettings().setJavaScriptEnabled(true);
+ } else {
- String pageText = getTextCss() + chapters.get(position).text;
- textWebView.loadDataWithBaseURL("", pageText, "text/html", "UTF-8", "");
+ view = inflater.inflate(R.layout.reading_pager_layout, container, false);
+ view.setEnabled(false);
+ WebView textWebView = (WebView) view.findViewById(R.id.chapterWebView);
+ textWebView.getSettings().setJavaScriptEnabled(true);
- ((ViewPager) container).addView(view);
+ String pageText = getTextCss() + chapters.get(position).text;
+ textWebView.loadDataWithBaseURL("", pageText, "text/html", "UTF-8", "");
+ textWebView.setOnTouchListener(this.pagerOnTouchListener);
- manageActionbarText();
+ ((ViewPager) container).addView(view);
+
+ manageActionbarText();
+ }
return view;
}
private void manageActionbarText(){
int index = ((ViewPager) container).getCurrentItem();
- actionbarTextView.setText(chapters.get(index).getTitle(context));
+ if(index < chapters.size()) {
+ String title = chapters.get(index).getTitle(context);
+ chaptersText.setText(title);
+ }
}
private String getTextCss(){
-
-
String css = "";
@@ -109,9 +134,10 @@ private String getTextCss(){
}
private String getTextDirection(){
- String direction = chapters.get(0).getParent(context).getParent(context).readingDirection;
- if(direction.equalsIgnoreCase("rtl")){
+ String language = chapters.get(0).getParent(context).getParent(context).getParent(context).languageAbbreviation;
+
+ if(isRTL()){
return "rtl";
}
else{
@@ -119,6 +145,25 @@ private String getTextDirection(){
}
}
+ private boolean isRTL() {
+ char desiredChar = ' ';
+
+ int spanIndex = chapters.get(0).text.indexOf("span>");
+ for(int i = spanIndex + 5; i < chapters.get(0).text.length(); i++){
+ desiredChar = chapters.get(0).text.charAt(i);
+
+ if(!Character.isDigit(desiredChar) && !Character.isWhitespace(desiredChar) && Character.isLetter(desiredChar)){
+ break;
+ }
+ }
+
+ final int directionality = Character.getDirectionality(desiredChar);
+ boolean direction = (directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT ||
+ directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC);
+
+ return direction;
+}
+
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((RelativeLayout) object);
@@ -132,8 +177,45 @@ public void destroyItem(ViewGroup container, int position, Object object) {
@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
super.setPrimaryItem(container, position, object);
- PreferenceManager.getDefaultSharedPreferences(context).edit().putInt(SELECTED_POS, position).commit();
- PreferenceManager.getDefaultSharedPreferences(context).edit().putInt(ChapterSelectionActivity.CHAPTERS_INDEX_STRING, position).commit();
+ if(position == (this.getCount() - 1)){
+ return;
+ }
+
+ BibleChapterModel model = chapters.get(position);
+ UWPreferenceManager.setSelectedBibleChapter(context, model.uid);
manageActionbarText();
}
+
+ private View getNextBookView(LayoutInflater inflater){
+
+ View nextChapterView = inflater.inflate(R.layout.next_chapter_screen_layout, container, false);
+ Button nextButton = (Button) nextChapterView.findViewById(R.id.next_chapter_screen_button);
+
+ String nextButtonString = context.getResources().getString(R.string.next_book);
+ nextButton.setText(nextButtonString + " " + nextBook.getTitle());
+ nextButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ moveToNextBook();
+ }
+ });
+
+ return nextChapterView;
+ }
+
+ private void moveToNextBook(){
+
+ this.chapters = nextBook.getBibleChildModels(context);
+ setNextBook();
+
+ UWPreferenceManager.setSelectedBibleChapter(context, chapters.get(0).uid);
+
+ String title = chapters.get(0).getTitle(context);
+ chaptersText.setText(title);
+
+ notifyDataSetChanged();
+
+ ((ViewPager) this.container).setCurrentItem(0);
+
+ }
}
diff --git a/app/app/src/main/java/adapters/StoryPagerAdapter.java b/app/app/src/main/java/adapters/StoryPagerAdapter.java
index 9a65b2e..8d77966 100644
--- a/app/app/src/main/java/adapters/StoryPagerAdapter.java
+++ b/app/app/src/main/java/adapters/StoryPagerAdapter.java
@@ -2,7 +2,6 @@
import android.app.Activity;
import android.content.Context;
-import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
@@ -26,11 +25,11 @@
import java.util.ArrayList;
-import activity.bookSelection.ChapterSelectionActivity;
+import activity.bookSelection.StoryChapterSelectionActivity;
import model.database.DBManager;
import model.modelClasses.mainData.StoriesChapterModel;
import utils.AsyncImageLoader;
-import utils.URLUtils;
+import utils.UWPreferenceManager;
/**
* Created by Acts Media Inc on 5/12/14.
@@ -43,12 +42,10 @@ public class StoryPagerAdapter extends PagerAdapter implements ImageLoadingListe
protected String SELECTED_POS = "";
DisplayImageOptions options;
- View view = null;
DBManager dbManager = null;
- private Intent intent;
private Activity activity;
private static Context context;
- private TextView actionbarTextView;
+ private TextView chapterTextView;
private ImageLoader mImageLoader;
private ViewGroup container;
private StoriesChapterModel currentChapter;
@@ -56,23 +53,21 @@ public class StoryPagerAdapter extends PagerAdapter implements ImageLoadingListe
private int lastChapterNumber = -1;
- public StoryPagerAdapter(Object context, StoriesChapterModel model, ImageLoader mImageLoader, TextView actionbarTextView, String positionHolder) {
+ public StoryPagerAdapter(Object context, StoriesChapterModel model, ImageLoader mImageLoader, TextView chapterTextView, String positionHolder) {
this.context = (Context) context;
currentChapter = model;
- getCount();
- currentChapter.AddBlankPageToEnd();
this.mImageLoader = mImageLoader;
- this.actionbarTextView = actionbarTextView;
+ this.chapterTextView = chapterTextView;
setImageOptions();
dbManager = DBManager.getInstance(this.context);
this.activity = (Activity) context;
- lastChapterNumber = currentChapter.getParent(this.context).getChildModels(this.context).size();
+ lastChapterNumber = currentChapter.getParent(this.context).getStoryChildModels(this.context).size();
SELECTED_POS = positionHolder;
}
@Override
public int getCount() {
- return currentChapter.getChildModels(context).size();
+ return currentChapter.getChildModels(context).size() + 1;
}
@Override
@@ -80,39 +75,15 @@ public Object instantiateItem(final ViewGroup container, final int position) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.container = container;
-
- // getting last row values of data base
- int frameCount = currentChapter.getChildModels(context).size() + 1;
+ View view = null;
if (position == getCount() - 1) {
-
- view = inflater.inflate(R.layout.next_chapter_screen_layout, container, false);
- Button nextButton = (Button) view.findViewById(R.id.nextChapterScreenbutton);
-
- if(Integer.parseInt(currentChapter.number) == lastChapterNumber){
- String nextButtonString = currentChapter.getParent(context).appWords.chapters;
- nextButton.setText(nextButtonString);
- nextButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- activity.finish();
- }
- });
- }
- else {
- String nextButtonString = currentChapter.getParent(context).appWords.nextChapter;
- nextButton.setText(nextButtonString);
- nextButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- moveToNextChapter();
- }
- });
- }
+ view = getNextChapterView(inflater);
} else {
+
view = inflater.inflate(R.layout.stories_pager_layout, container, false);
- ImageView chapterImageView = (ImageView) view.findViewById(R.id.chapterImageView);
- TextView storyTextView = (TextView) view.findViewById(R.id.storyTextView);
+ ImageView chapterImageView = (ImageView) view.findViewById(R.id.chapter_image_view);
+ TextView storyTextView = (TextView) view.findViewById(R.id.story_text_view);
storyTextView.setText(currentChapter.getChildModels(context).get(position).text);
String imgUrl = currentChapter.getChildModels(context).get(position).imageUrl;
String lastBitFromUrl = AsyncImageLoader.getLastBitFromUrl(imgUrl);
@@ -127,6 +98,34 @@ public void onClick(View view) {
return view;
}
+ private View getNextChapterView(LayoutInflater inflater){
+
+ View view = inflater.inflate(R.layout.next_chapter_screen_layout, container, false);
+ Button nextButton = (Button) view.findViewById(R.id.next_chapter_screen_button);
+
+ if(Integer.parseInt(currentChapter.number) == lastChapterNumber){
+ String nextButtonString = context.getResources().getString(R.string.chapters);
+ nextButton.setText(nextButtonString);
+ nextButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ activity.finish();
+ }
+ });
+ }
+ else {
+ String nextButtonString = context.getResources().getString(R.string.next_chapter);
+ nextButton.setText(nextButtonString);
+ nextButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ moveToNextChapter();
+ }
+ });
+ }
+ return view;
+ }
+
private void moveToNextChapter(){
int chapterNumber = Integer.parseInt(currentChapter.number);
@@ -136,7 +135,7 @@ private void moveToNextChapter(){
nextChapterNumber = "0" + nextChapterNumber;
}
- ArrayList chapters = currentChapter.getParent(context).getChildModels(context);
+ ArrayList chapters = currentChapter.getParent(context).getStoryChildModels(context);
StoriesChapterModel nextChapter = null;
int newChapterNumber = Integer.parseInt(this.currentChapter.number);
@@ -148,25 +147,18 @@ private void moveToNextChapter(){
}
this.currentChapter = nextChapter;
- PreferenceManager.getDefaultSharedPreferences(context).edit().putInt(ChapterSelectionActivity.CHAPTERS_INDEX_STRING, newChapterNumber).commit();
+ PreferenceManager.getDefaultSharedPreferences(context).edit().putInt(StoryChapterSelectionActivity.CHAPTERS_INDEX_STRING, newChapterNumber).commit();
getCount();
- currentChapter.AddBlankPageToEnd();
-// ArrayList newPages = nextChapter.getChildModels(context);
int current_value = Integer.parseInt(currentChapter.number);
- actionbarTextView.setText(nextChapter.title);
- // increment chapter selection
-// int prv_pos = PreferenceManager.getDefaultSharedPreferences(context).getInt(ChapterSelectionActivity.SELECTED_CHAPTER_POS, -1);
-// if (prv_pos != -1) {
-// PreferenceManager.getDefaultSharedPreferences(context).edit().putInt(ChapterSelectionActivity.SELECTED_CHAPTER_POS, prv_pos + 1).commit();
-// }
-//
-// intent.removeExtra(ChapterSelectionActivity.CHAPTERS_MODEL_INSTANCE);
-// AppVariable.MODELS = nextChapter;
+ chapterTextView.setText(nextChapter.title);
+ UWPreferenceManager.setSelectedStoryChapter(context, nextChapter.uid);
+
notifyDataSetChanged();
((ViewPager) this.container).setCurrentItem(0);
}
+
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((RelativeLayout) object);
@@ -193,7 +185,7 @@ public void onLoadingStarted(String s, View view) {
@Override
public void onLoadingFailed(String url, View view, FailReason failReason) {
- ImageView imageView = (ImageView) view.findViewById(R.id.chapterImageView);
+ ImageView imageView = (ImageView) view.findViewById(R.id.chapter_image_view);
if (url.contains("file")) {
String w = AsyncImageLoader.getLastBitFromUrl(url);
mImageLoader.displayImage("assets://images/" + w, imageView, options);
diff --git a/app/app/src/main/java/adapters/selectionAdapters/CollapsibleVersionAdapter.java b/app/app/src/main/java/adapters/selectionAdapters/CollapsibleVersionAdapter.java
new file mode 100644
index 0000000..8f21091
--- /dev/null
+++ b/app/app/src/main/java/adapters/selectionAdapters/CollapsibleVersionAdapter.java
@@ -0,0 +1,468 @@
+package adapters.selectionAdapters;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.graphics.Bitmap;
+import android.graphics.Typeface;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseExpandableListAdapter;
+import android.widget.FrameLayout;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.ProgressBar;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import org.unfoldingword.mobile.R;
+
+import java.util.Locale;
+
+import model.datasource.BibleChapterDataSource;
+import model.datasource.ProjectDataSource;
+import model.datasource.StoriesChapterDataSource;
+import model.datasource.VersionDataSource;
+import model.modelClasses.mainData.BibleChapterModel;
+import model.modelClasses.mainData.BookModel;
+import model.modelClasses.mainData.LanguageModel;
+import model.modelClasses.mainData.ProjectModel;
+import model.modelClasses.mainData.StoriesChapterModel;
+import model.modelClasses.mainData.VersionModel;
+import services.VersionDownloadService;
+import utils.CustomSlideAnimationRelativeLayout;
+import utils.NetWorkUtil;
+import utils.URLUtils;
+import utils.UWPreferenceManager;
+
+/**
+ * Created by Fechner on 3/23/15.
+ */
+public class CollapsibleVersionAdapter extends BaseExpandableListAdapter {
+
+ private final static String TAG = "CollapseVersionAdapter";
+ protected final static String SELECTED_POS = "VERSION_POSITION";
+
+ static final String STORIES_SLUG = "obs";
+ private Activity context;
+ ProjectModel currentProject = null;
+
+ public CollapsibleVersionAdapter(Activity context, ProjectModel currentProject) {
+ this.context = context;
+ this.currentProject = currentProject;
+
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(URLUtils.VERSION_BROADCAST_DOWN_COMP);
+ filter.addAction(URLUtils.VERSION_BROADCAST_DOWN_ERROR);
+ context.registerReceiver(receiver, filter);
+ }
+
+ private BroadcastReceiver receiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+
+ Bundle extra = intent.getExtras();
+ if (extra != null) {
+ String itemId = extra.getString(VersionDownloadService.VERSION_ID);
+ Log.d(TAG, itemId);
+ }
+
+ if (intent.getAction().equals(URLUtils.VERSION_BROADCAST_DOWN_COMP)) {
+ Toast.makeText(context, "Download complete", Toast.LENGTH_SHORT).show();
+ reload();
+ } else {
+ Toast.makeText(context, "Download error", Toast.LENGTH_SHORT).show();
+ }
+ }
+ };
+
+ private void reload(){
+
+ currentProject = new ProjectDataSource(context).getModel(Long.toString(currentProject.uid));
+ notifyDataSetChanged();
+ }
+
+ public VersionModel getChild(int groupPosition, int childPosition) {
+ return currentProject.getChildModels(context).get(groupPosition).getChildModels(context).get(childPosition);
+ }
+
+ public long getChildId(int groupPosition, int childPosition) {
+ return childPosition;
+ }
+
+ public View getChildView(final int groupPosition, final int childPosition,
+ boolean isLastChild, View convertView, ViewGroup parent) {
+
+ final VersionModel version = getChild(groupPosition, childPosition);
+ ViewHolderForGroup holder = null;
+ if (convertView == null) {
+ LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ convertView = inflater.inflate(R.layout.row_version_selector, parent, false);
+ holder = new ViewHolderForGroup();
+ holder.languageNameTextView = (TextView) convertView.findViewById(R.id.languageNameTextView);
+ holder.languageTypeImageView = (ImageView) convertView.findViewById(R.id.languageTypeImageView);
+ holder.visibleFrameLayout = (FrameLayout) convertView.findViewById(R.id.visibleLayout);
+ holder.checkingEntityTextView = (TextView) convertView.findViewById(R.id.checkingEntitytextView);
+ holder.checkingLevelTextView = (TextView) convertView.findViewById(R.id.checkingLevelTextView);
+ holder.versionTextView = (TextView) convertView.findViewById(R.id.versionTextView);
+ holder.publishDateTextView = (TextView) convertView.findViewById(R.id.publishDateTextView);
+ holder.checkingEntiityConstantTextView = (TextView) convertView.findViewById(R.id.checkingEntityConstanttextView);
+ holder.checkinglevelConstantTextView = (TextView) convertView.findViewById(R.id.checkingLevelConstanttextView);
+ holder.versionConstantTextView = (TextView) convertView.findViewById(R.id.versionConstanttextView);
+ holder.publishDateConstantTextView = (TextView) convertView.findViewById(R.id.publishDateConstanttextView);
+ holder.clickableLayout = (LinearLayout) convertView.findViewById(R.id.clickableRow);
+ holder.infoFrame = (FrameLayout) convertView.findViewById(R.id.info_image_frame);
+ holder.status = (ImageView) convertView.findViewById(R.id.status);
+
+ holder.downloadImageView = (ImageView) convertView.findViewById(R.id.download_status_image);
+ holder.downloadFrame = (FrameLayout) convertView.findViewById(R.id.download_status_frame);
+ holder.downloadProgressBar = (ProgressBar) convertView.findViewById(R.id.download_progress_bar);
+
+ final ViewHolderForGroup finalHolder = holder;
+ holder.infoFrame.setOnClickListener(getInfoClickListener(finalHolder));
+ convertView.setTag(holder);
+ } else {
+ holder = (ViewHolderForGroup) convertView.getTag();
+ }
+
+ boolean isSelected = ((version.uid == Long.parseLong(UWPreferenceManager.getSelectedBibleVersion(context)))
+ || (version.uid == Long.parseLong(UWPreferenceManager.getSelectedStoryVersion(context))));
+
+ int state = isSelected? 2 : 1;
+ holder.downloadProgressBar.setVisibility(View.INVISIBLE);
+ holder.downloadImageView.setVisibility(View.VISIBLE);
+
+ state = setRowState(holder, version, state);
+
+ holder.downloadFrame.setOnClickListener(getDownloadOnClickListener(version, holder));
+ setColorChange(holder, getColorForState(state));
+
+ if (version.status.checkingLevel.equals("1")) {
+ holder.languageTypeImageView.setImageResource(R.drawable.level_one_dark);
+ } else if (version.status.checkingLevel.equals("2")) {
+ holder.languageTypeImageView.setImageResource(R.drawable.level_two_dark);
+ } else if (version.status.checkingLevel.equals("3")) {
+ holder.languageTypeImageView.setImageResource(R.drawable.level_three_dark);
+ }
+
+
+// holder.languageTypeImageView.set
+ holder.languageNameTextView.setText(version.getTitle());
+ holder.checkingEntityTextView.setText(version.status.checkingEntity);
+ holder.checkingEntityTextView.setText(version.status.checkingEntity);
+ holder.checkingLevelTextView.setText(version.status.checkingLevel);
+ holder.versionTextView.setText(version.status.version);
+ holder.publishDateTextView.setText(version.status.publishDate);
+
+
+ Drawable statusImage = context.getResources().getDrawable(getColorForStatus(version.getVerificationStatus(context)));
+ Bitmap statusBitmap = ((BitmapDrawable)statusImage).getBitmap();
+ holder.status.setImageBitmap(statusBitmap);
+
+ return convertView;
+ }
+
+ private int setRowState(ViewHolderForGroup holder, VersionModel version, int selectionState){
+
+ switch (version.downloadState){
+
+ case DOWNLOAD_STATE_DOWNLOADED:{
+ holder.status.setVisibility(View.VISIBLE);
+ holder.downloadImageView.setVisibility(View.VISIBLE);
+ holder.downloadProgressBar.setVisibility(View.INVISIBLE);
+ holder.clickableLayout.setClickable(true);
+ holder.downloadFrame.setClickable(true);
+ holder.downloadImageView.setImageResource(R.drawable.x_button);
+ holder.clickableLayout.setOnClickListener(getSelectionOnClickListener(version));
+ return selectionState;
+ }
+ case DOWNLOAD_STATE_DOWNLOADING:{
+ holder.status.setVisibility(View.INVISIBLE);
+ holder.downloadImageView.setVisibility(View.INVISIBLE);
+ holder.downloadProgressBar.setVisibility(View.VISIBLE);
+ holder.clickableLayout.setClickable(false);
+ holder.downloadFrame.setClickable(true);
+ return 3;
+ }
+
+ default:{
+ holder.status.setVisibility(View.INVISIBLE);
+ holder.downloadImageView.setVisibility(View.VISIBLE);
+ holder.downloadProgressBar.setVisibility(View.INVISIBLE);
+ holder.clickableLayout.setClickable(false);
+ holder.downloadFrame.setClickable(true);
+ holder.downloadImageView.setImageResource(R.drawable.download_button);
+ return 3;
+ }
+
+ }
+ }
+
+ private View.OnClickListener getDownloadOnClickListener(final VersionModel version, final ViewHolderForGroup finalHolder) {
+
+ return new View.OnClickListener() {
+
+ @Override
+ public void onClick(View view) {
+ if (version instanceof VersionModel) {
+ finalHolder.clickableLayout.setClickable(false);
+ finalHolder.downloadProgressBar.setVisibility(View.VISIBLE);
+ finalHolder.downloadImageView.setVisibility(view.INVISIBLE);
+
+ if((version.downloadState == VersionModel.DOWNLOAD_STATE.DOWNLOAD_STATE_NONE)
+ || (version.downloadState == VersionModel.DOWNLOAD_STATE.DOWNLOAD_STATE_ERROR)) {
+
+ if (!NetWorkUtil.isConnected(context)) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ builder.setTitle("Alert");
+ builder.setMessage("Failed connecting to the internet.");
+ builder.setPositiveButton("OK", null);
+ builder.create().show();
+ } else {
+ // to handle new data from network
+ version.downloadState = VersionModel.DOWNLOAD_STATE.DOWNLOAD_STATE_DOWNLOADING;
+ version.save(context);
+ Intent downloadIntent = new Intent(context, VersionDownloadService.class);
+ downloadIntent.putExtra(VersionDownloadService.VERSION_ID, Long.toString(version.uid));
+ context.startService(downloadIntent);
+ }
+ }
+ else if(version.downloadState == VersionModel.DOWNLOAD_STATE.DOWNLOAD_STATE_DOWNLOADING){
+ context.stopService(new Intent(context, VersionDownloadService.class));
+ new DeleteVersionTask().execute(version);
+ }
+ else{
+ if(Long.parseLong(UWPreferenceManager.getSelectedBibleVersion(context)) == version.uid){
+ UWPreferenceManager.setSelectedBibleVersion(context, -1);
+ UWPreferenceManager.setSelectedBibleChapter(context, -1);
+ }
+ if(Long.parseLong(UWPreferenceManager.getSelectedStoryVersion(context)) == version.uid){
+ UWPreferenceManager.setSelectedStoryVersion(context, -1);
+ UWPreferenceManager.setSelectedStoryChapter(context, -1);
+ }
+ new DeleteVersionTask().execute(version);
+ }
+ }
+ }
+ };
+ }
+
+ private class DeleteVersionTask extends AsyncTask {
+
+ @Override
+ protected Object doInBackground(Object[] params) {
+ return new VersionDataSource(context).deleteDownloadedBookContent((VersionModel) params[0]);
+ }
+
+ @Override
+ protected void onPostExecute(Object o) {
+ super.onPostExecute(o);
+ reload();
+ }
+ }
+
+ private View.OnClickListener getSelectionOnClickListener(final VersionModel version) {
+
+ return new View.OnClickListener() {
+
+ @Override
+ public void onClick(View view) {
+ if (version instanceof VersionModel) {
+ boolean isStoryChapter = version.getParent(context).getParent(context).slug.equalsIgnoreCase(STORIES_SLUG);
+ refreshChapterSelection(version, isStoryChapter);
+ if(isStoryChapter){
+ UWPreferenceManager.setSelectedStoryVersion(context, version.uid);
+ }
+ else {
+ UWPreferenceManager.setSelectedBibleVersion(context, version.uid);
+ }
+ }
+ context.finish();
+ context.overridePendingTransition(R.anim.enter_center, R.anim.exit_on_bottom);
+ }
+ };
+ }
+
+
+ private void refreshChapterSelection(VersionModel version, boolean isStoryChapter){
+
+ if(isStoryChapter){
+
+ String chapterId = UWPreferenceManager.getSelectedStoryChapter(context);
+ if(Long.parseLong(chapterId) < 0){
+
+ StoriesChapterModel newChapter = version.getChildModels(context).get(0).getStoryChapter(context, 1);
+ UWPreferenceManager.setSelectedStoryChapter(context, newChapter.uid);
+ }
+ else {
+ StoriesChapterModel chapter = new StoriesChapterDataSource(context).getModel(chapterId);
+ if(chapter == null){
+ StoriesChapterModel newChapter = version.getChildModels(context).get(0).getStoryChapter(context, 1);
+ UWPreferenceManager.setSelectedStoryChapter(context, newChapter.uid);
+ return;
+ }
+ BookModel newBook = version.findBookForJsonSlug(context, chapter.getParent(context).slug.substring(0, 3));
+
+ StoriesChapterModel newChapter = (newBook == null)? version.getChildModels(context).get(0).getStoryChapter(context, 1) :
+ newBook.getStoryChapter(context, Integer.parseInt(chapter.number));
+
+ UWPreferenceManager.setSelectedStoryChapter(context, newChapter.uid);
+ }
+ }
+ else{
+ String chapterId = UWPreferenceManager.getSelectedBibleChapter(context);
+ if(Long.parseLong(chapterId) < 0){
+ BibleChapterModel newChapter = version.getChildModels(context).get(0).getBibleChapter(context, 1);
+ UWPreferenceManager.setSelectedBibleChapter(context, newChapter.uid);
+ }
+ else {
+ BibleChapterModel chapter = new BibleChapterDataSource(context).getModel(chapterId);
+ if(chapter == null){
+ BibleChapterModel newChapter = version.getChildModels(context).get(0).getBibleChapter(context, 1);
+ UWPreferenceManager.setSelectedBibleChapter(context, newChapter.uid);
+ return;
+ }
+ BookModel newBook = version.findBookForJsonSlug(context, chapter.getParent(context).slug.substring(0, 3));
+
+ BibleChapterModel newChapter = (newBook == null)? version.getChildModels(context).get(0).getBibleChapter(context, 1) :
+ newBook.getBibleChapter(context, Integer.parseInt(chapter.number.trim()));
+
+ UWPreferenceManager.setSelectedBibleChapter(context, newChapter.uid);
+ }
+ }
+
+ }
+
+ public int getChildrenCount(int groupPosition) {
+ return getGroup(groupPosition).getChildModels(context).size();
+ }
+
+ public LanguageModel getGroup(int groupPosition) {
+ return currentProject.getChildModels(context).get(groupPosition);
+ }
+
+ public int getGroupCount() {
+ return currentProject.getChildModels(context).size();
+ }
+
+ public long getGroupId(int groupPosition) {
+ return groupPosition;
+ }
+
+ public View getGroupView(int groupPosition, boolean isExpanded,
+ View convertView, ViewGroup parent) {
+ LanguageModel language = getGroup(groupPosition);
+ if (convertView == null) {
+
+ LayoutInflater inflater = (LayoutInflater) context
+ .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ convertView = inflater.inflate(R.layout.row_group,
+ null);
+ }
+
+ TextView item = (TextView) convertView.findViewById(R.id.group_title);
+ item.setTypeface(null, Typeface.BOLD);
+ Locale languageLocal = new Locale(language.getTitle());
+ item.setText(languageLocal.getDisplayLanguage());
+
+ return convertView;
+ }
+
+ public boolean hasStableIds() {
+ return true;
+ }
+
+ public boolean isChildSelectable(int groupPosition, int childPosition) {
+ return true;
+ }
+
+ public void setColorChange(ViewHolderForGroup holder, int color) {
+
+ holder.languageNameTextView.setTextColor(color);
+ }
+
+ private int getColorForStatus(int currentStatus){
+
+ switch (currentStatus){
+ case 0:
+ return R.drawable.status_verified_btn_radio_on_holo_light;
+ case 1:
+ return R.drawable.status_expired_btn_radio_on_holo_light;
+ case 3:
+ return R.drawable.status_failed_btn_radio_on_holo_light;
+ default:
+ return R.drawable.status_error_btn_radio_on_holo_light;
+ }
+ }
+
+ protected int getColorForState(int state){
+
+ switch (state){
+ case 1:
+ return context.getResources().getColor(R.color.black_light);
+ case 2:
+ return context.getResources().getColor(R.color.cyan);
+ default:
+ return context.getResources().getColor(R.color.lightgrey);
+ }
+ }
+
+
+ private View.OnClickListener getInfoClickListener(final ViewHolderForGroup finalHolder){
+ return new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (finalHolder.visibleFrameLayout.getVisibility() == View.GONE) {
+
+ CustomSlideAnimationRelativeLayout animationRelativeLayout = new CustomSlideAnimationRelativeLayout(finalHolder.visibleFrameLayout, 300, CustomSlideAnimationRelativeLayout.EXPAND);
+ finalHolder.visibleFrameLayout.startAnimation(animationRelativeLayout);
+// context.startActivity(new Intent(context, ChapterSelectionActivity.class).putExtra(LanguageChooserActivity.LANGUAGE_CODE, list.get(pos).language));
+ } else {
+ CustomSlideAnimationRelativeLayout animationRelativeLayout = new CustomSlideAnimationRelativeLayout(finalHolder.visibleFrameLayout, 300, CustomSlideAnimationRelativeLayout.COLLAPSE);
+ finalHolder.visibleFrameLayout.startAnimation(animationRelativeLayout);
+ }
+ }
+ };
+ }
+
+
+ public void willDestroy(){
+ if(receiver != null) {
+ context.unregisterReceiver(receiver);
+ }
+ receiver = null;
+ }
+
+
+ private static class ViewHolderForGroup {
+
+ TextView languageNameTextView;
+ ImageView languageTypeImageView;
+ FrameLayout visibleFrameLayout;
+ TextView checkingEntityTextView;
+ TextView checkingLevelTextView;
+ TextView versionTextView;
+ TextView publishDateTextView;
+ TextView checkingEntiityConstantTextView;
+ TextView checkinglevelConstantTextView;
+ TextView versionConstantTextView;
+ TextView publishDateConstantTextView;
+ LinearLayout clickableLayout;
+ FrameLayout infoFrame;
+ ImageView status;
+
+ ImageView downloadImageView;
+ FrameLayout downloadFrame;
+ ProgressBar downloadProgressBar;
+ }
+}
+
diff --git a/app/app/src/main/java/adapters/selectionAdapters/StoriesChapterAdapter.java b/app/app/src/main/java/adapters/selectionAdapters/StoriesChapterAdapter.java
index f20c14f..d4447da 100644
--- a/app/app/src/main/java/adapters/selectionAdapters/StoriesChapterAdapter.java
+++ b/app/app/src/main/java/adapters/selectionAdapters/StoriesChapterAdapter.java
@@ -23,7 +23,6 @@
import model.modelClasses.mainData.StoriesChapterModel;
import utils.AsyncImageLoader;
-import utils.URLUtils;
/**
* Created by Acts Media Inc on 4/12/14.
diff --git a/app/app/src/main/java/adapters/selectionAdapters/VersionAdapter.java b/app/app/src/main/java/adapters/selectionAdapters/VersionAdapter.java
deleted file mode 100644
index 430d6e4..0000000
--- a/app/app/src/main/java/adapters/selectionAdapters/VersionAdapter.java
+++ /dev/null
@@ -1,153 +0,0 @@
-package adapters.selectionAdapters;
-
-import android.content.Context;
-import android.content.Intent;
-import android.preference.PreferenceManager;
-import android.support.v7.app.ActionBarActivity;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.FrameLayout;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-
-import org.unfoldingword.mobile.R;
-
-import java.util.List;
-
-import activity.bookSelection.ChapterSelectionActivity;
-import activity.bookSelection.GeneralSelectionActivity;
-import model.modelClasses.mainData.VersionModel;
-import utils.CustomSlideAnimationRelativeLayout;
-
-/**
- * Created by Fechner on 3/6/15.
- */
-public class VersionAdapter extends GeneralAdapter {
-
-
- public VersionAdapter(Context context, List models, TextView actionbarTextView, ActionBarActivity activity, String storageString) {
- super(context, R.layout.row_version_selector, models, actionbarTextView, activity, storageString);
- }
-
- @Override
- public View getView(final int pos, View view, ViewGroup parent) {
-
- ViewHolderForGroup holder = null;
- if (view == null) {
- LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- view = inflater.inflate(R.layout.row_version_selector, parent, false);
- holder = new ViewHolderForGroup();
- holder.languageNameTextView = (TextView) view.findViewById(R.id.languageNameTextView);
- holder.languageTypeImageView = (ImageView) view.findViewById(R.id.languageTypeImageView);
- holder.clickLanguageImageView = (ImageView) view.findViewById(R.id.version_info_image);
- holder.visibleFrameLayout = (FrameLayout) view.findViewById(R.id.visibleLayout);
- holder.checkingEntityTextView = (TextView) view.findViewById(R.id.checkingEntitytextView);
- holder.checkingLevelTextView = (TextView) view.findViewById(R.id.checkingLevelTextView);
- holder.versionTextView = (TextView) view.findViewById(R.id.versionTextView);
- holder.publishDateTextView = (TextView) view.findViewById(R.id.publishDateTextView);
- holder.checkingEntiityConstantTextView = (TextView) view.findViewById(R.id.checkingEntityConstanttextView);
- holder.checkinglevelConstantTextView = (TextView) view.findViewById(R.id.checkingLevelConstanttextView);
- holder.versionConstantTextView = (TextView) view.findViewById(R.id.versionConstanttextView);
- holder.publishDateConstantTextView = (TextView) view.findViewById(R.id.publishDateConstanttextView);
- holder.clickableLayout = (LinearLayout) view.findViewById(R.id.clickableRow);
- holder.infoFrame = (FrameLayout) view.findViewById(R.id.info_image_frame);
-
- holder.clickableLayout.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- PreferenceManager.getDefaultSharedPreferences(context).edit().putInt(SELECTED_POS, pos).commit();
-// context.startActivity(new Intent(context, ChapterSelectionActivity.class).putExtra(LanguageChooserActivity.LANGUAGE_CODE, models.get(pos).language));
-
- Object itemAtPosition = models.get(pos);
- if (itemAtPosition instanceof GeneralRowInterface) {
- GeneralRowInterface model = (GeneralRowInterface) itemAtPosition;
-
- // put selected position to sharedprefences
- PreferenceManager.getDefaultSharedPreferences(context).edit().putInt(SELECTED_POS, pos).commit();
- context.startActivity(new Intent(context, ChapterSelectionActivity.class).putExtra(
- GeneralSelectionActivity.CHOSEN_ID, model.getChildIdentifier()));
- activity.overridePendingTransition(R.anim.enter_from_right, R.anim.exit_on_left);
- }
-
-
-// activity.overridePendingTransition(R.anim.abc_slide_in_bottom, R.anim.abc_slide_out_bottom);
-// activity.finish();
- }
- });
-
- final ViewHolderForGroup finalHolder = holder;
- holder.clickLanguageImageView.setOnClickListener(getInfoClickListener(finalHolder));
- holder.infoFrame.setOnClickListener(getInfoClickListener(finalHolder));
- view.setTag(holder);
- } else {
- holder = (ViewHolderForGroup) view.getTag();
- }
-
- int selectionPosition = PreferenceManager.getDefaultSharedPreferences(context).getInt(SELECTED_POS, -1);
- setColorChange(holder, getColorForState(selectionPosition, pos));
-
- if (((VersionModel) models.get(pos)).status.checkingLevel.equals("1")) {
- holder.languageTypeImageView.setImageResource(R.drawable.level_one_dark);
- } else if (((VersionModel) models.get(pos)).status.checkingLevel.equals("2")) {
- holder.languageTypeImageView.setImageResource(R.drawable.level_two_dark);
- } else if (((VersionModel) models.get(pos)).status.checkingLevel.equals("3")) {
- holder.languageTypeImageView.setImageResource(R.drawable.level_three_dark);
- }
-
-// holder.languageTypeImageView.set
- holder.languageNameTextView.setText(models.get(pos).getTitle());
- holder.checkingEntityTextView.setText(((VersionModel) models.get(pos)).status.checkingEntity);
- holder.checkingEntityTextView.setText(((VersionModel) models.get(pos)).status.checkingEntity);
- holder.checkingLevelTextView.setText(((VersionModel) models.get(pos)).status.checkingLevel);
- holder.versionTextView.setText(((VersionModel) models.get(pos)).status.version);
- holder.publishDateTextView.setText(((VersionModel) models.get(pos)).status.publishDate);
-
- return view;
- }
-
- private View.OnClickListener getInfoClickListener(final ViewHolderForGroup finalHolder){
- return new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (finalHolder.visibleFrameLayout.getVisibility() == View.GONE) {
-
- CustomSlideAnimationRelativeLayout animationRelativeLayout = new CustomSlideAnimationRelativeLayout(finalHolder.visibleFrameLayout, 300, CustomSlideAnimationRelativeLayout.EXPAND);
- finalHolder.visibleFrameLayout.startAnimation(animationRelativeLayout);
-// context.startActivity(new Intent(context, ChapterSelectionActivity.class).putExtra(LanguageChooserActivity.LANGUAGE_CODE, list.get(pos).language));
- } else {
- CustomSlideAnimationRelativeLayout animationRelativeLayout = new CustomSlideAnimationRelativeLayout(finalHolder.visibleFrameLayout, 300, CustomSlideAnimationRelativeLayout.COLLAPSE);
- finalHolder.visibleFrameLayout.startAnimation(animationRelativeLayout);
-
- }
-
- }
- };
- }
-
- public void setColorChange(ViewHolderForGroup holder, int color) {
-
- holder.languageNameTextView.setTextColor(color);
- }
-
- private static class ViewHolderForGroup {
-
- TextView languageNameTextView;
- ImageView languageTypeImageView;
- ImageView clickLanguageImageView;
- FrameLayout visibleFrameLayout;
- TextView checkingEntityTextView;
- TextView checkingLevelTextView;
- TextView versionTextView;
- TextView publishDateTextView;
- TextView checkingEntiityConstantTextView;
- TextView checkinglevelConstantTextView;
- TextView versionConstantTextView;
- TextView publishDateConstantTextView;
- LinearLayout clickableLayout;
- FrameLayout infoFrame;
- }
-
-
-}
diff --git a/app/app/src/main/java/model/datasource/AMDatabase/AMDatabaseIndex.java b/app/app/src/main/java/model/database/AMDatabaseIndex.java
similarity index 88%
rename from app/app/src/main/java/model/datasource/AMDatabase/AMDatabaseIndex.java
rename to app/app/src/main/java/model/database/AMDatabaseIndex.java
index 3f41a08..53c6e59 100644
--- a/app/app/src/main/java/model/datasource/AMDatabase/AMDatabaseIndex.java
+++ b/app/app/src/main/java/model/database/AMDatabaseIndex.java
@@ -1,4 +1,4 @@
-package model.datasource.AMDatabase;
+package model.database;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
@@ -16,9 +16,9 @@
*/
public class AMDatabaseIndex {
- public static String DB_NAME = "_un_folding_word";
- public static int DB_VERSION = 5;
-
+ public static final String DB_NAME = "_un_folding_word";
+ public static final int DB_VERSION = 6;
+ public static final int LAST_UPDATED = 20150310;
private static AMDatabaseIndex ourInstance = new AMDatabaseIndex();
public static AMDatabaseIndex getInstance() {
diff --git a/app/app/src/main/java/model/database/DBManager.java b/app/app/src/main/java/model/database/DBManager.java
index c9c8496..34983e2 100644
--- a/app/app/src/main/java/model/database/DBManager.java
+++ b/app/app/src/main/java/model/database/DBManager.java
@@ -13,9 +13,9 @@
import java.io.InputStream;
import java.util.ArrayList;
-import model.datasource.AMDatabase.AMDatabaseIndex;
-import model.datasource.LanguageDataSource;
+import model.database.AMDatabaseIndex;
import model.datasource.ProjectDataSource;
+import model.modelClasses.mainData.LanguageModel;
import model.modelClasses.mainData.ProjectModel;
/**
@@ -26,7 +26,7 @@ public class DBManager extends SQLiteOpenHelper {
/**
* This needs to match up with the most recently updated Language model
*/
- private static final int LAST_UPDATED = 20150310;
+
private static String TAG = "DBManager";
@@ -43,7 +43,7 @@ public class DBManager extends SQLiteOpenHelper {
* @param context
* @return instance of DBManager
*/
- public static DBManager getInstance(Context context) {
+ public synchronized static DBManager getInstance(Context context) {
if (dbManager == null) {
dbManager = new DBManager(context);
}
@@ -56,6 +56,30 @@ private DBManager(Context context) {
DB_PATH = "/data/data/" + context.getPackageName() + "/databases/";
}
+ private static int openingsCounter = 0;
+ private SQLiteDatabase database = null;
+ public synchronized SQLiteDatabase getDatabase(){
+
+ if(database == null){
+ openingsCounter = 0;
+ }
+
+ if(openingsCounter == 0){
+ database = this.getWritableDatabase();
+ }
+ openingsCounter++;
+
+ return database;
+ }
+
+ public synchronized void closeDatabase(){
+
+ openingsCounter--;
+ if(openingsCounter < 1){
+ this.close();
+ }
+ }
+
//region Overrides
@Override
@@ -80,10 +104,13 @@ public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i2) {
public void createDataBase(boolean forceCreate) throws IOException {
if(forceCreate || shouldLoadSavedDb()){
- copyDataBase();
+// copyDataBase();
getReadableDatabase();
}
+ else {
+ getReadableDatabase();
+ }
// backupDatabase();
}
@@ -173,9 +200,12 @@ private boolean dbIsUpdated(){
ArrayList models = new ProjectDataSource(this.context).getAllProjects();
for(ProjectModel model : models ){
- if(model.dateModified >= LAST_UPDATED){
- Log.i(TAG, "DB is up to date");
- return true;
+ ArrayList languageModels = model.getChildModels(context);
+ for(LanguageModel langMod : languageModels) {
+ if (langMod.dateModified >= AMDatabaseIndex.LAST_UPDATED) {
+ Log.i(TAG, "DB is up to date");
+ return true;
+ }
}
}
Log.i(TAG, "DB is not up to date");
diff --git a/app/app/src/main/java/model/database/UWDataParser.java b/app/app/src/main/java/model/database/UWDataParser.java
new file mode 100644
index 0000000..5cbab50
--- /dev/null
+++ b/app/app/src/main/java/model/database/UWDataParser.java
@@ -0,0 +1,254 @@
+package model.database;
+
+import android.content.Context;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Map;
+
+import model.datasource.AMDatabase.AMDatabaseDataSourceAbstract;
+import model.datasource.BibleChapterDataSource;
+import model.datasource.BookDataSource;
+import model.datasource.LanguageDataSource;
+import model.datasource.PageDataSource;
+import model.datasource.ProjectDataSource;
+import model.datasource.StoriesChapterDataSource;
+import model.datasource.VersionDataSource;
+import model.modelClasses.AMDatabase.AMDatabaseModelAbstractObject;
+import model.modelClasses.mainData.BibleChapterModel;
+import model.modelClasses.mainData.BookModel;
+import model.modelClasses.mainData.LanguageModel;
+import model.modelClasses.mainData.PageModel;
+import model.modelClasses.mainData.ProjectModel;
+import model.modelClasses.mainData.StoriesChapterModel;
+import model.modelClasses.mainData.VersionModel;
+import signing.Status;
+import signing.UWSigning;
+import utils.URLDownloadUtil;
+import utils.USFMParser;
+
+/**
+ * Created by Fechner on 3/15/15.
+ */
+public class UWDataParser {
+
+ private static final String PROJECTS_JSON_KEY = "cat";
+ private static final String LANGUAGES_JSON_KEY = "langs";
+ private static final String VERSIONS_JSON_KEY = "vers";
+ private static final String BOOKS_JSON_KEY = "toc";
+ private static final String CHAPTERS_JSON_KEY = "chapters";
+
+ private static UWDataParser ourInstance = null;
+
+ public static UWDataParser getInstance(Context context) {
+
+ if(ourInstance == null){
+ ourInstance = new UWDataParser(context);
+ }
+ return ourInstance;
+ }
+
+ private Context context;
+
+ private UWDataParser(Context context) {
+
+ this.context = context;
+ }
+
+ public String getSideLoadedDBAsJson(){
+
+ ArrayList projects = new ProjectDataSource(context).getAllProjects();
+ String json = "{\n[";
+
+ for(ProjectModel project : projects){
+
+ json += "\n" + project.getAsSideLoadedModel(context) + ",\n";
+ }
+
+ json = json.substring(0, json.length() - 1);
+ json += "\n]\n}";
+
+ return json;
+ }
+ public JSONArray downloadJsonArray(String url) throws JSONException, IOException{
+
+ String json = URLDownloadUtil.downloadString(url);
+
+ JSONArray jsonArray = new JSONArray(json);
+ return jsonArray;
+ }
+
+ public JSONObject downloadJsonObject(String url) throws JSONException, IOException{
+
+ String json = URLDownloadUtil.downloadString(url);
+
+ JSONObject jsonObject = new JSONObject(json);
+ return jsonObject;
+ }
+
+ public AMDatabaseModelAbstractObject updateModelFromJson(AMDatabaseDataSourceAbstract dataSource, JSONObject json, long parentId, boolean sideLoaded){
+
+ AMDatabaseModelAbstractObject model = dataSource.saveOrUpdateModel(json.toString(), parentId, sideLoaded);
+ return model;
+ }
+
+ public void updateProjects(String url, boolean sideLoaded) throws IOException, JSONException {
+
+ updateProjects(downloadJsonObject(url).getJSONArray(PROJECTS_JSON_KEY), sideLoaded);
+ }
+
+ public void updateProjects(JSONArray jsonArray, boolean sideLoaded) throws IOException, JSONException{
+
+ for(int i = 0; i < jsonArray.length(); i++){
+
+ JSONObject jsonObj = jsonArray.getJSONObject(i);
+ ProjectModel updatedModel = (ProjectModel) updateModelFromJson(new ProjectDataSource(context), jsonObj, -1, sideLoaded);
+
+ if(updatedModel == null){
+ continue;
+ }
+ else{
+ updateLanguages(jsonObj.getJSONArray(LANGUAGES_JSON_KEY), updatedModel.uid, sideLoaded);
+ }
+ }
+ }
+
+ public void updateLanguages(JSONArray jsonArray, long parentId, boolean sideLoaded) throws IOException, JSONException{
+
+
+ for(int i = 0; i < jsonArray.length(); i++){
+
+ JSONObject jsonObj = jsonArray.getJSONObject(i);
+ LanguageModel updatedModel = (LanguageModel) updateModelFromJson(new LanguageDataSource(context), jsonObj, parentId, sideLoaded);
+
+ if(updatedModel == null){
+ continue;
+ }
+ else{
+ updateVersions(jsonObj.getJSONArray(VERSIONS_JSON_KEY), updatedModel.uid, sideLoaded);
+ }
+ }
+ }
+
+ public void updateVersions(JSONArray jsonArray, long parentId, boolean sideLoaded) throws IOException, JSONException{
+
+ for(int i = 0; i < jsonArray.length(); i++){
+
+ JSONObject jsonObj = jsonArray.getJSONObject(i);
+ VersionModel updatedModel = (VersionModel) updateModelFromJson(new VersionDataSource(context), jsonObj, parentId, sideLoaded);
+
+ if(updatedModel == null){
+ continue;
+ }
+ updateBooks(jsonObj.getJSONArray(BOOKS_JSON_KEY), updatedModel.uid, sideLoaded);
+ }
+ }
+
+ public void updateBooks(JSONArray jsonArray, long parentId, boolean sideLoaded) throws IOException, JSONException{
+
+ for(int i = 0; i < jsonArray.length(); i++){
+
+ JSONObject jsonObj = jsonArray.getJSONObject(i);
+ updateModelFromJson(new BookDataSource(context), jsonObj, parentId, sideLoaded);
+ }
+ }
+
+ public void parseUSFMForBook(BookModel book) throws IOException, JSONException{
+
+ byte[] usfmText = URLDownloadUtil.downloadBytes(book.sourceUrl);
+
+ book = addSignatureToBook(book, usfmText);
+
+ Map usfmMap = USFMParser.parseUsfm(usfmText);
+
+ ArrayList chapters = book.getBibleChildModels(context);
+
+ for (Map.Entry entry : usfmMap.entrySet()){
+ BibleChapterModel chapter = new BibleChapterModel();
+ chapter.parentId = book.uid;
+ chapter.number = entry.getKey();
+ chapter.text = entry.getValue();
+
+ for(BibleChapterModel oldChapter : chapters){
+ if(Long.parseLong(oldChapter.number.replaceAll("[^0-9]", "")) == Long.parseLong(chapter.number.replaceAll("[^0-9]", ""))){
+ chapter.uid = oldChapter.uid;
+ }
+ }
+
+ new BibleChapterDataSource(context).saveModel(chapter);
+ }
+ }
+
+ public void updateStoryChapters(BookModel bookModel, boolean sideLoaded) throws IOException, JSONException{
+
+ byte[] jsonBytes = URLDownloadUtil.downloadBytes(bookModel.sourceUrl);
+
+ bookModel = addSignatureToBook(bookModel, jsonBytes);
+
+ String json = new String(jsonBytes);
+ JSONObject book = new JSONObject(json);
+ updateStoryChapters(book.getJSONArray(CHAPTERS_JSON_KEY), bookModel.uid, sideLoaded);
+ }
+
+ private BookModel addSignatureToBook(BookModel book, byte[] text) throws IOException{
+
+ Status signatureStatus = Status.ERROR;
+ try {
+ signatureStatus = UWSigning.getStatusForSigUrl(context, book.signatureUrl, text);
+ }
+ catch (JSONException e){
+ e.printStackTrace();
+ }
+
+ if(signatureStatus == Status.ERROR){
+ BookModel updatedBook = book.getDataSource(context).getModel(Long.toString(book.uid));
+ return updatedBook;
+ }
+
+ String sigJson = URLDownloadUtil.downloadString(book.signatureUrl);
+
+ try {
+ JSONArray sigArray = new JSONArray(sigJson);
+ JSONObject sigObj = sigArray.getJSONObject(0);
+ book.setEntityFromJson(sigObj.toString());
+ book.verificationStatus = signatureStatus.ordinal();
+
+ book.getDataSource(context).saveModel(book);
+
+ }
+ catch (JSONException e){
+ e.printStackTrace();
+ }
+ BookModel updatedBook = book.getDataSource(context).getModel(Long.toString(book.uid));
+ return updatedBook;
+ }
+
+ public void updateStoryChapters(JSONArray jsonArray, long parentId, boolean sideLoaded) throws IOException, JSONException{
+
+ for(int i = 0; i < jsonArray.length(); i++){
+
+ JSONObject jsonObj = jsonArray.getJSONObject(i);
+ StoriesChapterModel updatedModel = (StoriesChapterModel) updateModelFromJson(new StoriesChapterDataSource(context), jsonObj, parentId, sideLoaded);
+
+ if(updatedModel == null){
+ continue;
+ }
+ else{
+ updatePages(jsonObj.getJSONArray("frames"), updatedModel.uid, sideLoaded);
+ }
+ }
+ }
+
+ public void updatePages(JSONArray jsonArray, long parentId, boolean sideLoaded) throws IOException, JSONException{
+
+ for(int i = 0; i < jsonArray.length(); i++){
+
+ JSONObject jsonObj = jsonArray.getJSONObject(i);
+ PageModel updatedModel = (PageModel) updateModelFromJson(new PageDataSource(context), jsonObj, parentId, sideLoaded);
+ }
+ }
+}
diff --git a/app/app/src/main/java/model/datasource/AMDatabase/AMDatabaseDataSourceAbstract.java b/app/app/src/main/java/model/datasource/AMDatabase/AMDatabaseDataSourceAbstract.java
index d3539d1..fa5a7a1 100644
--- a/app/app/src/main/java/model/datasource/AMDatabase/AMDatabaseDataSourceAbstract.java
+++ b/app/app/src/main/java/model/datasource/AMDatabase/AMDatabaseDataSourceAbstract.java
@@ -9,7 +9,7 @@
import java.util.ArrayList;
import model.database.DBManager;
-import model.modelClasses.mainData.AMDatabase.AMDatabaseModelAbstractObject;
+import model.modelClasses.AMDatabase.AMDatabaseModelAbstractObject;
/**
* Created by Fechner on 2/23/15.
@@ -24,12 +24,14 @@ public AMDatabaseDataSourceAbstract(Context context){
this.context = context;
}
- private SQLiteDatabase getDatabase() {
+ private static synchronized DBManager getDBManager(Context context) {
- SQLiteDatabase database = DBManager.getInstance(this.context).getReadableDatabase();
- return database;
+ DBManager manager = DBManager.getInstance(context);
+ return manager;
}
+ abstract public AMDatabaseModelAbstractObject saveOrUpdateModel(String json, long parentId, boolean sideLoaded);
+
/**
* should return a sql table creation string
* @return
@@ -110,14 +112,32 @@ public void deleteModel(AMDatabaseModelAbstractObject model){
ArrayList children = this.loadChildrenModelsFromDatabase(model);
- for(AMDatabaseModelAbstractObject childModel : children){
- childModel.getDataSource(this.context).deleteModel(childModel);
+ if(children != null) {
+ for (AMDatabaseModelAbstractObject childModel : children) {
+ childModel.getDataSource(this.context).deleteModel(childModel);
+ }
}
- SQLiteDatabase database = getDatabase();
+ SQLiteDatabase database = getDBManager(context).getDatabase();
database.execSQL(this.getDeleteQuery(Long.toString(model.uid)));
- database.close();
+ getDBManager(context).closeDatabase();
+ }
+
+ public void deleteChildrenOfParent(AMDatabaseModelAbstractObject parent){
+
+ ArrayList children = this.loadChildrenModelsFromDatabase(parent);
+
+ if(children != null) {
+ for (AMDatabaseModelAbstractObject childModel : children) {
+ childModel.getDataSource(this.context).deleteChildrenOfParent(childModel);
+ }
+ }
+
+ SQLiteDatabase database = getDBManager(context).getDatabase();
+
+ database.execSQL(this.getDeleteChildrenQuery(Long.toString(parent.uid)));
+ getDBManager(context).closeDatabase();
}
public AMDatabaseModelAbstractObject getModelFromDatabaseForSlug(String slug){
@@ -134,7 +154,7 @@ public AMDatabaseModelAbstractObject getModelFromDatabaseForSlug(String slug){
protected ArrayList getModelFromDatabase(String desiredColumn, String key){
- SQLiteDatabase database = getDatabase();
+ SQLiteDatabase database = getDBManager(context).getDatabase();
ArrayList models = new ArrayList();
Cursor cursor = database.rawQuery(this.getQueryForColumn(desiredColumn), new String[]{key});
@@ -148,17 +168,17 @@ protected ArrayList getModelFromDatabase(String d
if (cursor != null) {
cursor.close();
}
- database.close();
+ getDBManager(context).closeDatabase();
return models;
}
public ArrayList getAllModels(){
+ ArrayList models = new ArrayList();
+ SQLiteDatabase database = getDBManager(context).getDatabase();
try {
- SQLiteDatabase database = getDatabase();
- ArrayList models = new ArrayList();
Cursor cursor = database.rawQuery(this.getAllQuery(), null);
if (cursor != null) {
int i = 0;
@@ -170,20 +190,23 @@ public ArrayList getAllModels(){
if (cursor != null) {
cursor.close();
}
- database.close();
- return models;
}
catch (SQLiteException e){
+ models = null;
e.printStackTrace();
- return null;
}
+
+ getDBManager(context).closeDatabase();
+
+ return models;
}
protected ArrayList getUniqueValuesForColumn(String column){
+ ArrayList values = new ArrayList();
+ SQLiteDatabase database = getDBManager(context).getDatabase();
try {
- ArrayList values = new ArrayList();
- SQLiteDatabase database = getDatabase();
+
Cursor cursor = database.query(true, this.getTableName(), new String[]{column}, null, null, null, null, null, null);
if (cursor != null) {
@@ -192,23 +215,26 @@ protected ArrayList getUniqueValuesForColumn(String column){
String value = cursor.getString(cursor.getColumnIndex(column));
values.add(value);
}
+ }
+ if (cursor != null) {
cursor.close();
}
- database.close();
- return values;
+
}
catch (SQLiteException e){
e.printStackTrace();
- return null;
+ values = null;
}
+
+ getDBManager(context).closeDatabase();
+ return values;
}
- public AMDatabaseModelAbstractObject getModelForKey(String key){
+ public synchronized AMDatabaseModelAbstractObject getModelForKey(String key){
- SQLiteDatabase database = getDatabase();
AMDatabaseModelAbstractObject model = null;
-
+ SQLiteDatabase database = getDBManager(context).getDatabase();
Cursor cursor = database.rawQuery(this.getSelectQuery(), new String[]{key});
if (cursor != null) {
@@ -216,38 +242,40 @@ public AMDatabaseModelAbstractObject getModelForKey(String key){
while (cursor.moveToNext()) {
model = getObjectFromCursor(cursor);
}
- cursor.close();
- }
- else{
+ if (cursor != null) {
+ cursor.close();
+ }
+ } else {
model = null;
}
-
- database.close();
-
+ getDBManager(context).closeDatabase();
return model;
}
public boolean createOrUpdateDatabaseModel(AMDatabaseModelAbstractObject model){
// Log.i(TAG, "Updating model: " + model.toString());
- SQLiteDatabase database = getDatabase();
-
- ContentValues values = this.getModelAsContentValues(model);
- int update = database.update(this.getTableName(), values,
- this.getCreateWhereClause(), new String[]{Long.toString(model.uid)});
- if (update > 0) {
- return true;
- }
- else{
- boolean didAdd = addModelToDatabase(database, values);
- return didAdd;
+ SQLiteDatabase database = getDBManager(context).getDatabase();
+ synchronized(database) {
+ ContentValues values = this.getModelAsContentValues(model);
+ int update = database.update(this.getTableName(), values,
+ this.getCreateWhereClause(), new String[]{Long.toString(model.uid)});
+ if (update > 0) {
+ getDBManager(context).closeDatabase();
+ return true;
+ } else {
+ boolean didAdd = addModelToDatabase(database, values);
+ getDBManager(context).closeDatabase();
+ return didAdd;
+ }
}
+
+
}
protected boolean addModelToDatabase(SQLiteDatabase database, ContentValues values) {
long insert = database.insert(this.getTableName(), null, values);
- database.close();
if (insert > 0) {
// Log.d("DB", "add: " + true);
return true;
@@ -258,12 +286,15 @@ protected boolean addModelToDatabase(SQLiteDatabase database, ContentValues valu
protected ArrayList loadChildrenModelsFromDatabase(AMDatabaseModelAbstractObject model){
- SQLiteDatabase database = getDatabase();
-
ArrayList models = new ArrayList();
AMDatabaseDataSourceAbstract childDataSource = this.getChildDataSource();
- Cursor cursor = database.rawQuery(getChildrenQuery(childDataSource),new String[]{Long.toString(model.uid)});
+ if(childDataSource == null){
+ return null;
+ }
+
+ SQLiteDatabase database = getDBManager(context).getDatabase();
+ Cursor cursor = database.rawQuery(getChildrenQuery(childDataSource), new String[]{Long.toString(model.uid)});
if (cursor != null) {
@@ -277,7 +308,7 @@ protected ArrayList loadChildrenModelsFromDatabas
if (cursor != null) {
cursor.close();
}
- database.close();
+ getDBManager(context).closeDatabase();
return models;
}
@@ -323,6 +354,12 @@ private String getDeleteQuery(String id){
return query;
}
+ private String getDeleteChildrenQuery(String parentId){
+
+ String query = "DELETE FROM " + this.getTableName() + " WHERE " + this.getParentIdColumnName() + " = " + parentId;
+ return query;
+ }
+
diff --git a/app/app/src/main/java/model/datasource/BibleChapterDataSource.java b/app/app/src/main/java/model/datasource/BibleChapterDataSource.java
index 8470e5a..da300fb 100644
--- a/app/app/src/main/java/model/datasource/BibleChapterDataSource.java
+++ b/app/app/src/main/java/model/datasource/BibleChapterDataSource.java
@@ -3,11 +3,12 @@
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
+import android.util.Log;
import java.util.ArrayList;
import model.datasource.AMDatabase.AMDatabaseDataSourceAbstract;
-import model.modelClasses.mainData.AMDatabase.AMDatabaseModelAbstractObject;
+import model.modelClasses.AMDatabase.AMDatabaseModelAbstractObject;
import model.modelClasses.mainData.BibleChapterModel;
import model.modelClasses.mainData.PageModel;
@@ -16,14 +17,16 @@
*/
public class BibleChapterDataSource extends AMDatabaseDataSourceAbstract {
- static String TABLE_CHAPTER = "_table_bible_chapter";
+ static final String TAG = "BibleChapterDataSource";
+
+ static final String TABLE_CHAPTER = "_table_bible_chapter";
// Table columns of TABLE_CHAPTER
- static String TABLE_CHAPTER_COLUMN_UID = "_column_bible_chapter_uid";
- static String TABLE_CHAPTER_COLUMN_PARENT_ID = "_column_parent_id";
- static String TABLE_CHAPTER_COLUMN_SLUG = "_column_slug";
- static String TABLE_CHAPTER_COLUMN_NUMBER = "_column_number";
- static String TABLE_CHAPTER_COLUMN_TEXT = "_column_text";
+ static final String TABLE_CHAPTER_COLUMN_UID = "_column_bible_chapter_uid";
+ static final String TABLE_CHAPTER_COLUMN_PARENT_ID = "_column_parent_id";
+ static final String TABLE_CHAPTER_COLUMN_SLUG = "_column_slug";
+ static final String TABLE_CHAPTER_COLUMN_NUMBER = "_column_number";
+ static final String TABLE_CHAPTER_COLUMN_TEXT = "_column_text";
public BibleChapterDataSource(Context context) {
super(context);
@@ -47,6 +50,25 @@ public ArrayList getChaptersForParentId(String parentId){
return chapters;
}
+ @Override
+ public AMDatabaseModelAbstractObject saveOrUpdateModel(String json, long parentId, boolean sideLoaded) {
+
+ if(!sideLoaded){
+ Log.e(TAG, "BibleChapterDataSource This shouldn't happen!");
+ return null;
+ }
+
+ BibleChapterModel newModel = new BibleChapterModel(json, parentId, sideLoaded);
+ BibleChapterModel currentModel = getModelForSlug(newModel.slug);
+
+ if(currentModel != null) {
+ newModel.uid = currentModel.uid;
+ }
+
+ saveModel(newModel);
+ return getModelForSlug(newModel.slug);
+ }
+
@Override
protected String getParentIdColumnName() {
return TABLE_CHAPTER_COLUMN_PARENT_ID;
@@ -64,7 +86,7 @@ public AMDatabaseDataSourceAbstract getChildDataSource() {
@Override
public AMDatabaseDataSourceAbstract getParentDataSource() {
- return new VersionDataSource(this.context);
+ return new BookDataSource(this.context);
}
@Override
diff --git a/app/app/src/main/java/model/datasource/BookDataSource.java b/app/app/src/main/java/model/datasource/BookDataSource.java
index 27d4c30..94e8d5f 100644
--- a/app/app/src/main/java/model/datasource/BookDataSource.java
+++ b/app/app/src/main/java/model/datasource/BookDataSource.java
@@ -7,7 +7,8 @@
import java.util.ArrayList;
import model.datasource.AMDatabase.AMDatabaseDataSourceAbstract;
-import model.modelClasses.mainData.AMDatabase.AMDatabaseModelAbstractObject;
+import model.modelClasses.AMDatabase.AMDatabaseModelAbstractObject;
+import model.modelClasses.mainData.BibleChapterModel;
import model.modelClasses.mainData.BookModel;
import model.modelClasses.mainData.StoriesChapterModel;
@@ -16,26 +17,22 @@
*/
public class BookDataSource extends AMDatabaseDataSourceAbstract {
- static String TABLE_BOOK = "_table_book_info";
+ static final String TABLE_BOOK = "_table_book";
// Table columns of TABLE_BOOK
- static String TABLE_BOOK_COLUMN_UID = "_column_book_uid";
- static String TABLE_BOOK_COLUMN_PARENT_ID = "_column_parent_id";
- static String TABLE_BOOK_COLUMN_DATE_MODIFIED = "_column_date_modified";
- static String TABLE_BOOK_COLUMN_DIRECTION = "_column_txt_direction";
- static String TABLE_BOOK_COLUMN_LANGUAGE = "_column_language_abbreviation";
- static String TABLE_BOOK_COLUMN_SLUG = "_column_slug";
-
- static String TABLE_BOOK_COLUMN_WORDS_CANCEL = "_column_words_cancel";
- static String TABLE_BOOK_COLUMN_WORDS_CHAPTERS = "_column_words_chapters";
- static String TABLE_BOOK_COLUMN_WORDS_LANGUAGES = "_column_words_languages";
- static String TABLE_BOOK_COLUMN_WORDS_NEXT_CHAPTER = "_column_words_next_chapter";
- static String TABLE_BOOK_COLUMN_WORDS_OK = "_column_words_ok";
- static String TABLE_BOOK_COLUMN_WORDS_REMOVE_LOCALLY = "_column_words_remove_locally";
- static String TABLE_BOOK_COLUMN_WORDS_REMOVE_THIS_STRING = "_column_words_remove_this_string";
- static String TABLE_BOOK_COLUMN_WORDS_SAVE_LOCALLY = "_column_words_save_locally";
- static String TABLE_BOOK_COLUMN_WORDS_SAVE_THIS_STRING = "_column_words_save_this_string";
- static String TABLE_BOOK_COLUMN_WORDS_SELECT_A_LANGUAGE = "_column_words_select_a_language";
+ static final String TABLE_BOOK_COLUMN_UID = "_column_book_uid";
+ static final String TABLE_BOOK_COLUMN_PARENT_ID = "_column_parent_id";
+ static final String TABLE_BOOK_COLUMN_DATE_MODIFIED = "_column_date_modified";
+ static final String TABLE_BOOK_COLUMN_TITLE= "_column_title";
+ static final String TABLE_BOOK_COLUMN_DESCRIPTION = "_column_description";
+ static final String TABLE_BOOK_COLUMN_SLUG = "_column_slug";
+ static final String TABLE_BOOK_COLUMN_SOURCE_URL = "_column_source_url";
+ static final String TABLE_BOOK_COLUMN_SIGNATURE_URL = "_column_signature_url";
+
+ static final String TABLE_BOOK_COLUMN_SIG_ENTITY = "_column_signature_entity";
+ static final String TABLE_BOOK_COLUMN_SIG = "_column_signature";
+ static final String TABLE_BOOK_COLUMN_VERIFY_STATUS = "_column_verification_status";
+
public BookDataSource(Context context) {
super(context);
@@ -54,6 +51,24 @@ public ArrayList getChildModels(BookModel parentModel) {
return modelList;
}
+ @Override
+ public AMDatabaseModelAbstractObject saveOrUpdateModel(String json, long parentId, boolean sideLoaded) {
+ BookModel newModel = new BookModel(json, parentId, sideLoaded);
+ BookModel currentModel = getModelForSlug(newModel.slug);
+
+ if(currentModel != null) {
+ newModel.uid = currentModel.uid;
+ }
+
+ if (currentModel == null || (currentModel.dateModified < newModel.dateModified)) {
+ saveModel(newModel);
+ return getModelForSlug(newModel.slug);
+ }
+ else{
+ return null;
+ }
+ }
+
@Override
protected String getParentIdColumnName() {
return TABLE_BOOK_COLUMN_PARENT_ID;
@@ -90,16 +105,12 @@ public BookModel getModelForSlug(String slug){
return (BookModel) this.getModelFromDatabaseForSlug(slug);
}
- public BookModel getModelForLanguage(String language){
+ public void deleteDownloadedBookContent(BookModel book){
- ArrayList models = this.getModelFromDatabase(TABLE_BOOK_COLUMN_LANGUAGE, language);
+ AMDatabaseDataSourceAbstract dataSource = (book.sourceUrl.contains("usfm"))?
+ new BibleChapterDataSource(context) : new StoriesChapterDataSource(context);
- if(models.size() != 1){
- return null;
- }
- else{
- return (BookModel) models.get(0);
- }
+ dataSource.deleteChildrenOfParent(book);
}
@Override
@@ -111,24 +122,19 @@ public ContentValues getModelAsContentValues(AMDatabaseModelAbstractObject model
if(versionModel.uid > 0) {
values.put(TABLE_BOOK_COLUMN_UID, versionModel.uid);
}
+
values.put(TABLE_BOOK_COLUMN_PARENT_ID, versionModel.parentId);
values.put(TABLE_BOOK_COLUMN_DATE_MODIFIED, versionModel.dateModified);
- values.put(TABLE_BOOK_COLUMN_DIRECTION, versionModel.direction);
- values.put(TABLE_BOOK_COLUMN_LANGUAGE, versionModel.language);
+ values.put(TABLE_BOOK_COLUMN_TITLE, versionModel.title);
+ values.put(TABLE_BOOK_COLUMN_DESCRIPTION, versionModel.description);
values.put(TABLE_BOOK_COLUMN_SLUG, versionModel.slug);
- values.put(TABLE_BOOK_COLUMN_WORDS_CANCEL, versionModel.appWords.cancel);
- values.put(TABLE_BOOK_COLUMN_WORDS_CHAPTERS, versionModel.appWords.chapters);
- values.put(TABLE_BOOK_COLUMN_WORDS_LANGUAGES, versionModel.appWords.languages);
- values.put(TABLE_BOOK_COLUMN_WORDS_NEXT_CHAPTER, versionModel.appWords.nextChapter);
- values.put(TABLE_BOOK_COLUMN_WORDS_OK, versionModel.appWords.ok);
-
- values.put(TABLE_BOOK_COLUMN_WORDS_REMOVE_LOCALLY, versionModel.appWords.removeLocally);
- values.put(TABLE_BOOK_COLUMN_WORDS_REMOVE_THIS_STRING, versionModel.appWords.removeThisString);
- values.put(TABLE_BOOK_COLUMN_WORDS_SAVE_LOCALLY, versionModel.appWords.saveLocally);
- values.put(TABLE_BOOK_COLUMN_WORDS_SAVE_THIS_STRING, versionModel.appWords.saveThisString);
- values.put(TABLE_BOOK_COLUMN_WORDS_SELECT_A_LANGUAGE, versionModel.appWords.selectALanguage);
+ values.put(TABLE_BOOK_COLUMN_SOURCE_URL, versionModel.sourceUrl);
+ values.put(TABLE_BOOK_COLUMN_SIGNATURE_URL, versionModel.signatureUrl);
+ values.put(TABLE_BOOK_COLUMN_SIG_ENTITY, versionModel.signingEntity);
+ values.put(TABLE_BOOK_COLUMN_SIG, versionModel.signature);
+ values.put(TABLE_BOOK_COLUMN_VERIFY_STATUS, versionModel.verificationStatus);
return values;
}
@@ -140,21 +146,16 @@ public AMDatabaseModelAbstractObject getObjectFromCursor(Cursor cursor) {
model.uid = cursor.getLong(cursor.getColumnIndex(TABLE_BOOK_COLUMN_UID));
model.parentId = cursor.getLong(cursor.getColumnIndex(TABLE_BOOK_COLUMN_PARENT_ID));
model.dateModified = cursor.getLong(cursor.getColumnIndex(TABLE_BOOK_COLUMN_DATE_MODIFIED));
- model.direction = cursor.getString(cursor.getColumnIndex(TABLE_BOOK_COLUMN_DIRECTION));
- model.language = cursor.getString(cursor.getColumnIndex(TABLE_BOOK_COLUMN_LANGUAGE));
+ model.title = cursor.getString(cursor.getColumnIndex(TABLE_BOOK_COLUMN_TITLE));
+ model.description = cursor.getString(cursor.getColumnIndex(TABLE_BOOK_COLUMN_DESCRIPTION));
model.slug = cursor.getString(cursor.getColumnIndex(TABLE_BOOK_COLUMN_SLUG));
- model.appWords.cancel = cursor.getString(cursor.getColumnIndex(TABLE_BOOK_COLUMN_WORDS_CANCEL));
- model.appWords.chapters = cursor.getString(cursor.getColumnIndex(TABLE_BOOK_COLUMN_WORDS_CHAPTERS));
- model.appWords.languages = cursor.getString(cursor.getColumnIndex(TABLE_BOOK_COLUMN_WORDS_LANGUAGES));
- model.appWords.nextChapter = cursor.getString(cursor.getColumnIndex(TABLE_BOOK_COLUMN_WORDS_NEXT_CHAPTER));
- model.appWords.ok = cursor.getString(cursor.getColumnIndex(TABLE_BOOK_COLUMN_WORDS_OK));
+ model.sourceUrl = cursor.getString(cursor.getColumnIndex(TABLE_BOOK_COLUMN_SOURCE_URL));
+ model.signatureUrl = cursor.getString(cursor.getColumnIndex(TABLE_BOOK_COLUMN_SIGNATURE_URL));
- model.appWords.removeLocally = cursor.getString(cursor.getColumnIndex(TABLE_BOOK_COLUMN_WORDS_REMOVE_LOCALLY));
- model.appWords.removeThisString = cursor.getString(cursor.getColumnIndex(TABLE_BOOK_COLUMN_WORDS_REMOVE_THIS_STRING));
- model.appWords.saveLocally = cursor.getString(cursor.getColumnIndex(TABLE_BOOK_COLUMN_WORDS_SAVE_LOCALLY));
- model.appWords.saveThisString = cursor.getString(cursor.getColumnIndex(TABLE_BOOK_COLUMN_WORDS_SAVE_THIS_STRING));
- model.appWords.selectALanguage = cursor.getString(cursor.getColumnIndex(TABLE_BOOK_COLUMN_WORDS_SELECT_A_LANGUAGE));
+ model.signingEntity = cursor.getString(cursor.getColumnIndex(TABLE_BOOK_COLUMN_SIG_ENTITY));
+ model.signature = cursor.getString(cursor.getColumnIndex(TABLE_BOOK_COLUMN_SIG));
+ model.verificationStatus = cursor.getInt(cursor.getColumnIndex(TABLE_BOOK_COLUMN_VERIFY_STATUS));
return model;
}
@@ -164,29 +165,27 @@ public String getTableCreationString() {
String creationString = "CREATE TABLE " + this.getTableName() + "(" +
BookDataSource.TABLE_BOOK_COLUMN_UID +" INTEGER PRIMARY KEY AUTOINCREMENT," +
+
BookDataSource.TABLE_BOOK_COLUMN_PARENT_ID + " INTEGER," +
BookDataSource.TABLE_BOOK_COLUMN_DATE_MODIFIED + " INTEGER," +
- BookDataSource.TABLE_BOOK_COLUMN_DIRECTION + " VARCHAR," +
- BookDataSource.TABLE_BOOK_COLUMN_LANGUAGE + " VARCHAR," +
+ BookDataSource.TABLE_BOOK_COLUMN_TITLE + " VARCHAR," +
+ BookDataSource.TABLE_BOOK_COLUMN_DESCRIPTION + " VARCHAR," +
BookDataSource.TABLE_BOOK_COLUMN_SLUG + " VARCHAR," +
- BookDataSource.TABLE_BOOK_COLUMN_WORDS_CANCEL + " VARCHAR," +
- BookDataSource.TABLE_BOOK_COLUMN_WORDS_CHAPTERS + " VARCHAR," +
- BookDataSource.TABLE_BOOK_COLUMN_WORDS_LANGUAGES + " VARCHAR," +
- BookDataSource.TABLE_BOOK_COLUMN_WORDS_NEXT_CHAPTER + " VARCHAR," +
- BookDataSource.TABLE_BOOK_COLUMN_WORDS_OK + " VARCHAR," +
- BookDataSource.TABLE_BOOK_COLUMN_WORDS_REMOVE_LOCALLY + " VARCHAR," +
- BookDataSource.TABLE_BOOK_COLUMN_WORDS_REMOVE_THIS_STRING + " VARCHAR," +
- BookDataSource.TABLE_BOOK_COLUMN_WORDS_SAVE_LOCALLY + " VARCHAR," +
- BookDataSource.TABLE_BOOK_COLUMN_WORDS_SAVE_THIS_STRING + " VARCHAR," +
- BookDataSource.TABLE_BOOK_COLUMN_WORDS_SELECT_A_LANGUAGE + " VARCHAR)";
+ BookDataSource.TABLE_BOOK_COLUMN_SIG_ENTITY + " VARCHAR," +
+ BookDataSource.TABLE_BOOK_COLUMN_SIG + " VARCHAR," +
+ BookDataSource.TABLE_BOOK_COLUMN_VERIFY_STATUS + " INTEGER," +
+
+ BookDataSource.TABLE_BOOK_COLUMN_SOURCE_URL + " VARCHAR," +
+ BookDataSource.TABLE_BOOK_COLUMN_SIGNATURE_URL + " VARCHAR)";
+
return creationString;
}
@Override
public BookModel getModel(String uid) {
BookModel model = new BookModel();
- this.getModelForKey(uid);
+ model = (BookModel) this.getModelForKey(uid);
return model;
}
}
diff --git a/app/app/src/main/java/model/datasource/LanguageDataSource.java b/app/app/src/main/java/model/datasource/LanguageDataSource.java
index f659e60..f4beec5 100644
--- a/app/app/src/main/java/model/datasource/LanguageDataSource.java
+++ b/app/app/src/main/java/model/datasource/LanguageDataSource.java
@@ -7,7 +7,7 @@
import java.util.ArrayList;
import model.datasource.AMDatabase.AMDatabaseDataSourceAbstract;
-import model.modelClasses.mainData.AMDatabase.AMDatabaseModelAbstractObject;
+import model.modelClasses.AMDatabase.AMDatabaseModelAbstractObject;
import model.modelClasses.mainData.LanguageModel;
import model.modelClasses.mainData.VersionModel;
@@ -17,24 +17,18 @@
public class LanguageDataSource extends AMDatabaseDataSourceAbstract {
- static String TABLE_LANGUAGE = "_table_language";
+ static final String TABLE_LANGUAGE = "_table_language";
//Table columns of TABLE_PROJECT
- static String TABLE_LANGUAGE_UID = "_column_language_uid";
- static String TABLE_LANGUAGE_PARENT_ID = "_column_parent_id";
- static String TABLE_LANGUAGE_DATE_MODIFIED = "_column_date_modified";
- static String TABLE_LANGUAGE_DIRECTION = "_column_direction";
- static String TABLE_LANGUAGE_NAME = "_column_name";
- static String TABLE_LANGUAGE_SLUG = "_column_slug";
- static String TABLE_LANGUAGE_RESOURCES_URL = "_column_resources_url";
- static String TABLE_LANGUAGE_PROJECT_DESCRIPTION = "_column_project_description";
- static String TABLE_LANGUAGE_PROJECT_META = "_column_project_meta";
- static String TABLE_LANGUAGE_PROJECT_NAME = "_column_project_name";
- static String TABLE_LANGUAGE_PROJECT_SORT = "_column_project_sort_order";
+ static final String TABLE_LANGUAGE_UID = "_column_language_uid";
+ static final String TABLE_LANGUAGE_PARENT_ID = "_column_parent_id";
+ static final String TABLE_LANGUAGE_DATE_MODIFIED = "_column_date_modified";
+ static final String TABLE_LANGUAGE_LANGUAGE_ABBREVIATION = "_column_lang_abbrev";
+ static final String TABLE_LANGUAGE_SLUG = "_column_slug";
public ArrayList getAvailableLanguages(){
- return this.getUniqueValuesForColumn(TABLE_LANGUAGE_NAME);
+ return this.getUniqueValuesForColumn(TABLE_LANGUAGE_LANGUAGE_ABBREVIATION);
}
public LanguageDataSource(Context context) {
@@ -55,6 +49,25 @@ public ArrayList getChildModels(LanguageModel parentModel) {
}
+ @Override
+ public AMDatabaseModelAbstractObject saveOrUpdateModel(String json, long parentId, boolean sideLoaded) {
+ LanguageModel newModel = new LanguageModel(json, parentId, sideLoaded);
+ LanguageModel currentModel = getModelForSlug(newModel.slug);
+
+ if(currentModel != null) {
+ newModel.uid = currentModel.uid;
+ }
+
+ if (currentModel == null || (currentModel.dateModified < newModel.dateModified)) {
+
+ saveModel(newModel);
+ return getModelForSlug(newModel.slug);
+ }
+ else{
+ return null;
+ }
+ }
+
@Override
protected String getParentIdColumnName() {
return TABLE_LANGUAGE_PARENT_ID;
@@ -96,7 +109,6 @@ public LanguageModel getModelForSlug(String slug){
return (LanguageModel) this.getModelFromDatabaseForSlug(slug);
}
-
@Override
public AMDatabaseModelAbstractObject getObjectFromCursor(Cursor cursor) {
@@ -104,17 +116,9 @@ public AMDatabaseModelAbstractObject getObjectFromCursor(Cursor cursor) {
model.uid = cursor.getLong(cursor.getColumnIndex(TABLE_LANGUAGE_UID));
model.parentId = cursor.getLong(cursor.getColumnIndex(TABLE_LANGUAGE_PARENT_ID));
model.dateModified = cursor.getLong(cursor.getColumnIndex(TABLE_LANGUAGE_DATE_MODIFIED));
- model.readingDirection = cursor.getString(cursor.getColumnIndex(TABLE_LANGUAGE_DIRECTION));
- model.languageName = cursor.getString(cursor.getColumnIndex(TABLE_LANGUAGE_NAME));
+ model.languageAbbreviation = cursor.getString(cursor.getColumnIndex(TABLE_LANGUAGE_LANGUAGE_ABBREVIATION));
model.slug = cursor.getString(cursor.getColumnIndex(TABLE_LANGUAGE_SLUG));
- model.resourceUrl = cursor.getString(cursor.getColumnIndex(TABLE_LANGUAGE_RESOURCES_URL));
- model.description = cursor.getString(cursor.getColumnIndex(TABLE_LANGUAGE_PROJECT_DESCRIPTION));
- model.meta = cursor.getString(cursor.getColumnIndex(TABLE_LANGUAGE_PROJECT_META));
- model.projectName = cursor.getString(cursor.getColumnIndex(TABLE_LANGUAGE_PROJECT_NAME));
- model.sortOrder = cursor.getInt(cursor.getColumnIndex(TABLE_LANGUAGE_PROJECT_SORT));
-
-
return model;
}
@@ -129,16 +133,9 @@ public ContentValues getModelAsContentValues(AMDatabaseModelAbstractObject model
}
values.put(TABLE_LANGUAGE_PARENT_ID, languageModel.parentId);
values.put(TABLE_LANGUAGE_DATE_MODIFIED, languageModel.dateModified);
- values.put(TABLE_LANGUAGE_DIRECTION, languageModel.readingDirection);
- values.put(TABLE_LANGUAGE_NAME, languageModel.languageName);
+ values.put(TABLE_LANGUAGE_LANGUAGE_ABBREVIATION, languageModel.languageAbbreviation);
values.put(TABLE_LANGUAGE_SLUG, languageModel.slug);
- values.put(TABLE_LANGUAGE_RESOURCES_URL, languageModel.resourceUrl);
- values.put(TABLE_LANGUAGE_PROJECT_DESCRIPTION, languageModel.description);
- values.put(TABLE_LANGUAGE_PROJECT_META, languageModel.meta);
- values.put(TABLE_LANGUAGE_PROJECT_NAME, languageModel.projectName);
- values.put(TABLE_LANGUAGE_PROJECT_SORT, languageModel.sortOrder);
-
return values;
}
@@ -149,14 +146,8 @@ public String getTableCreationString() {
LanguageDataSource.TABLE_LANGUAGE_UID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
LanguageDataSource.TABLE_LANGUAGE_PARENT_ID + " INTEGER," +
LanguageDataSource.TABLE_LANGUAGE_DATE_MODIFIED + " INTEGER," +
- LanguageDataSource.TABLE_LANGUAGE_DIRECTION + " VARCHAR," +
- LanguageDataSource.TABLE_LANGUAGE_NAME + " VARCHAR," +
- LanguageDataSource.TABLE_LANGUAGE_SLUG + " VARCHAR," +
- LanguageDataSource.TABLE_LANGUAGE_RESOURCES_URL + " VARCHAR," +
- LanguageDataSource.TABLE_LANGUAGE_PROJECT_DESCRIPTION + " VARCHAR," +
- LanguageDataSource.TABLE_LANGUAGE_PROJECT_META + " VARCHAR," +
- LanguageDataSource.TABLE_LANGUAGE_PROJECT_NAME + " VARCHAR," +
- LanguageDataSource.TABLE_LANGUAGE_PROJECT_SORT + " VARCHAR)";
+ LanguageDataSource.TABLE_LANGUAGE_LANGUAGE_ABBREVIATION + " VARCHAR," +
+ LanguageDataSource.TABLE_LANGUAGE_SLUG + " VARCHAR)";
return creationString;
}
diff --git a/app/app/src/main/java/model/datasource/PageDataSource.java b/app/app/src/main/java/model/datasource/PageDataSource.java
index ccbedc1..a8e00ab 100644
--- a/app/app/src/main/java/model/datasource/PageDataSource.java
+++ b/app/app/src/main/java/model/datasource/PageDataSource.java
@@ -5,7 +5,7 @@
import android.database.Cursor;
import model.datasource.AMDatabase.AMDatabaseDataSourceAbstract;
-import model.modelClasses.mainData.AMDatabase.AMDatabaseModelAbstractObject;
+import model.modelClasses.AMDatabase.AMDatabaseModelAbstractObject;
import model.modelClasses.mainData.PageModel;
/**
@@ -13,16 +13,16 @@
*/
public class PageDataSource extends AMDatabaseDataSourceAbstract {
- static String TABLE_PAGE = "_page_info";
+ static final String TABLE_PAGE = "_table_page";
// Table columns of TABLE_PAGE
- static String TABLE_PAGE_COLUMN_UID = "_column_page_uid";
- static String TABLE_PAGE_COLUMN_PARENT_ID = "_column_parent_id";
- static String TABLE_PAGE_COLUMN_PAGE_NUMBER = "_column_page_number";
- static String TABLE_PAGE_COLUMN_CHAPTER_NUMBER = "_column_chapter_number";
- static String TABLE_PAGE_COLUMN_IMAGE_URL = "_column_img_url";
- static String TABLE_PAGE_COLUMN_TEXT = "_column_text";
- static String TABLE_PAGE_COLUMN_SLUG = "_column_slug";
+ static final String TABLE_PAGE_COLUMN_UID = "_column_page_uid";
+ static final String TABLE_PAGE_COLUMN_PARENT_ID = "_column_parent_id";
+ static final String TABLE_PAGE_COLUMN_PAGE_NUMBER = "_column_page_number";
+ static final String TABLE_PAGE_COLUMN_CHAPTER_NUMBER = "_column_chapter_number";
+ static final String TABLE_PAGE_COLUMN_IMAGE_URL = "_column_img_url";
+ static final String TABLE_PAGE_COLUMN_TEXT = "_column_text";
+ static final String TABLE_PAGE_COLUMN_SLUG = "_column_slug";
public PageDataSource(Context context) {
super(context);
@@ -68,6 +68,18 @@ public PageModel getModelForSlug(String slug){
return (PageModel) this.getModelFromDatabaseForSlug(slug);
}
+ @Override
+ public AMDatabaseModelAbstractObject saveOrUpdateModel(String json, long parentID, boolean sideLoaded) {
+ PageModel newModel = new PageModel(json, parentID, sideLoaded);
+ PageModel currentModel = getModelForSlug(newModel.slug);
+
+ if(currentModel != null) {
+ newModel.uid = currentModel.uid;
+ }
+
+ saveModel(newModel);
+ return getModelForSlug(newModel.slug);
+ }
@Override
public ContentValues getModelAsContentValues(AMDatabaseModelAbstractObject model) {
diff --git a/app/app/src/main/java/model/datasource/ProjectDataSource.java b/app/app/src/main/java/model/datasource/ProjectDataSource.java
index 1e0d6dc..356cc57 100644
--- a/app/app/src/main/java/model/datasource/ProjectDataSource.java
+++ b/app/app/src/main/java/model/datasource/ProjectDataSource.java
@@ -7,7 +7,7 @@
import java.util.ArrayList;
import model.datasource.AMDatabase.AMDatabaseDataSourceAbstract;
-import model.modelClasses.mainData.AMDatabase.AMDatabaseModelAbstractObject;
+import model.modelClasses.AMDatabase.AMDatabaseModelAbstractObject;
import model.modelClasses.mainData.LanguageModel;
import model.modelClasses.mainData.ProjectModel;
@@ -19,12 +19,9 @@ public class ProjectDataSource extends AMDatabaseDataSourceAbstract {
static String TABLE_PROJECT = "_table_project";
//Table columns of TABLE_PROJECT
- static String TABLE_PROJECT_COLUMN_UID = "_column_project_uid";
- static String TABLE_PROJECT_COLUMN_DATE_MODIFIED_ = "_column_date_modified";
- static String TABLE_PROJECT_COLUMN_LANGUAGE_URL = "_column_language_url";
- static String TABLE_PROJECT_COLUMN_META = "_column_meta";
- static String TABLE_PROJECT_COLUMN_SLUG = "_column_slug";
- static String TABLE_PROJECT_COLUMN_SORT = "_column_sort";
+ static final String TABLE_PROJECT_COLUMN_UID = "_column_project_uid";
+ static final String TABLE_PROJECT_COLUMN_TITLE = "_column_title";
+ static final String TABLE_PROJECT_COLUMN_SLUG = "_column_slug";
public ProjectDataSource(Context context) {
super(context);
@@ -43,6 +40,24 @@ public ArrayList getChildModels(ProjectModel parentModel) {
return modelList;
}
+ @Override
+ public AMDatabaseModelAbstractObject saveOrUpdateModel(String json, long parentId, boolean sideLoaded) {
+ ProjectModel newModel = new ProjectModel(json, sideLoaded);
+ ProjectModel currentModel = getModelForSlug(newModel.slug);
+
+ if(currentModel != null) {
+ newModel.uid = currentModel.uid;
+ }
+
+ if (currentModel == null) {
+ saveModel(newModel);
+ return getModelForSlug(newModel.slug);
+ }
+ else{
+ return null;
+ }
+ }
+
@Override
protected String getParentIdColumnName() {
return null;
@@ -104,11 +119,8 @@ protected AMDatabaseModelAbstractObject getObjectFromCursor(Cursor cursor) {
ProjectModel model = new ProjectModel();
model.uid = cursor.getLong(cursor.getColumnIndex(TABLE_PROJECT_COLUMN_UID));
- model.dateModified = cursor.getLong(cursor.getColumnIndex(TABLE_PROJECT_COLUMN_DATE_MODIFIED_));
- model.languageUrl = cursor.getString(cursor.getColumnIndex(TABLE_PROJECT_COLUMN_LANGUAGE_URL));
- model.meta = cursor.getString(cursor.getColumnIndex(TABLE_PROJECT_COLUMN_META));
+ model.title = cursor.getString(cursor.getColumnIndex(TABLE_PROJECT_COLUMN_TITLE));
model.slug = cursor.getString(cursor.getColumnIndex(TABLE_PROJECT_COLUMN_SLUG));
- model.sort = cursor.getInt(cursor.getColumnIndex(TABLE_PROJECT_COLUMN_SORT));
return model;
}
@@ -122,11 +134,8 @@ protected ContentValues getModelAsContentValues(AMDatabaseModelAbstractObject mo
if(projectModel.uid > 0) {
values.put(TABLE_PROJECT_COLUMN_UID, projectModel.uid);
}
- values.put(TABLE_PROJECT_COLUMN_DATE_MODIFIED_, projectModel.dateModified);
- values.put(TABLE_PROJECT_COLUMN_LANGUAGE_URL, projectModel.languageUrl);
- values.put(TABLE_PROJECT_COLUMN_META, projectModel.meta);
+ values.put(TABLE_PROJECT_COLUMN_TITLE, projectModel.title);
values.put(TABLE_PROJECT_COLUMN_SLUG, projectModel.slug);
- values.put(TABLE_PROJECT_COLUMN_SORT, projectModel.sort);
return values;
}
@@ -136,11 +145,8 @@ public String getTableCreationString() {
String creationString = "CREATE TABLE " + this.getTableName() + "(" +
ProjectDataSource.TABLE_PROJECT_COLUMN_UID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
- ProjectDataSource.TABLE_PROJECT_COLUMN_DATE_MODIFIED_ + " INTEGER," +
- ProjectDataSource.TABLE_PROJECT_COLUMN_LANGUAGE_URL + " VARCHAR," +
- ProjectDataSource.TABLE_PROJECT_COLUMN_META + " VARCHAR," +
- ProjectDataSource.TABLE_PROJECT_COLUMN_SLUG + " VARCHAR," +
- ProjectDataSource.TABLE_PROJECT_COLUMN_SORT + " INTEGER)";
+ ProjectDataSource.TABLE_PROJECT_COLUMN_TITLE + " VARCHAR," +
+ ProjectDataSource.TABLE_PROJECT_COLUMN_SLUG + " VARCHAR)";
return creationString;
}
}
diff --git a/app/app/src/main/java/model/datasource/StoriesChapterDataSource.java b/app/app/src/main/java/model/datasource/StoriesChapterDataSource.java
index f42284b..18435fd 100644
--- a/app/app/src/main/java/model/datasource/StoriesChapterDataSource.java
+++ b/app/app/src/main/java/model/datasource/StoriesChapterDataSource.java
@@ -7,24 +7,24 @@
import java.util.ArrayList;
import model.datasource.AMDatabase.AMDatabaseDataSourceAbstract;
-import model.modelClasses.mainData.AMDatabase.AMDatabaseModelAbstractObject;
-import model.modelClasses.mainData.StoriesChapterModel;
+import model.modelClasses.AMDatabase.AMDatabaseModelAbstractObject;
import model.modelClasses.mainData.PageModel;
+import model.modelClasses.mainData.StoriesChapterModel;
/**
* Created by Fechner on 2/24/15.
*/
public class StoriesChapterDataSource extends AMDatabaseDataSourceAbstract {
- static String TABLE_CHAPTER = "_table_stories_chapter";
+ static final String TABLE_CHAPTER = "_table_stories_chapter";
// Table columns of TABLE_CHAPTER
- static String TABLE_CHAPTER_COLUMN_UID = "_column_stories_chapter_uid";
- static String TABLE_CHAPTER_COLUMN_PARENT_ID = "_column_parent_id";
- static String TABLE_CHAPTER_COLUMN_SLUG = "_column_slug";
- static String TABLE_CHAPTER_COLUMN_NUMBER = "_column_number";
- static String TABLE_CHAPTER_COLUMN_DESCRIPTION = "_column_description";
- static String TABLE_CHAPTER_COLUMN_TITLE = "_column_title";
+ static final String TABLE_CHAPTER_COLUMN_UID = "_column_stories_chapter_uid";
+ static final String TABLE_CHAPTER_COLUMN_PARENT_ID = "_column_parent_id";
+ static final String TABLE_CHAPTER_COLUMN_SLUG = "_column_slug";
+ static final String TABLE_CHAPTER_COLUMN_NUMBER = "_column_number";
+ static final String TABLE_CHAPTER_COLUMN_DESCRIPTION = "_column_description";
+ static final String TABLE_CHAPTER_COLUMN_TITLE = "_column_title";
public StoriesChapterDataSource(Context context) {
super(context);
@@ -56,6 +56,19 @@ public ArrayList getChaptersForParentId(String parentId){
return chapters;
}
+ @Override
+ public AMDatabaseModelAbstractObject saveOrUpdateModel(String json, long parentId, boolean sideLoaded) {
+ StoriesChapterModel newModel = new StoriesChapterModel(json, parentId, sideLoaded);
+ StoriesChapterModel currentModel = getModelForSlug(newModel.slug);
+
+ if(currentModel != null) {
+ newModel.uid = currentModel.uid;
+ }
+
+ saveModel(newModel);
+ return getModelForSlug(newModel.slug);
+ }
+
@Override
protected String getParentIdColumnName() {
return TABLE_CHAPTER_COLUMN_PARENT_ID;
diff --git a/app/app/src/main/java/model/datasource/VersionDataSource.java b/app/app/src/main/java/model/datasource/VersionDataSource.java
index b42907b..cfc977c 100644
--- a/app/app/src/main/java/model/datasource/VersionDataSource.java
+++ b/app/app/src/main/java/model/datasource/VersionDataSource.java
@@ -7,7 +7,7 @@
import java.util.ArrayList;
import model.datasource.AMDatabase.AMDatabaseDataSourceAbstract;
-import model.modelClasses.mainData.AMDatabase.AMDatabaseModelAbstractObject;
+import model.modelClasses.AMDatabase.AMDatabaseModelAbstractObject;
import model.modelClasses.mainData.BookModel;
import model.modelClasses.mainData.VersionModel;
@@ -16,29 +16,24 @@
*/
public class VersionDataSource extends AMDatabaseDataSourceAbstract {
- static String TABLE_VERSION = "_table_version";
+ static final String TABLE_VERSION = "_table_version";
//Table columns of TABLE_VERSION
- static String TABLE_VERSION_COLUMN_UID = "_column_version_uid";
- static String TABLE_VERSION_COLUMN_PARENT_ID = "_column_parent_id";
- static String TABLE_VERSION_COLUMN_DATE_MODIFIED = "_column_date_modified";
- static String TABLE_VERSION_COLUMN_NAME = "_column_name";
- static String TABLE_VERSION_COLUMN_SLUG = "_column_slug";
-
- static String TABLE_VERSION_COLUMN_SOURCE_URL = "_column_source_url";
- static String TABLE_VERSION_COLUMN_NOTES_URL = "_column_notes_url";
- static String TABLE_VERSION_COLUMN_TERMS_URL = "_column_terms_url";
- static String TABLE_VERSION_COLUMN_USFM_URL = "_column_usfm_url";
-
- static String TABLE_VERSION_COLUMN_CHECKING_ENTITY = "_column_checking_entity";
- static String TABLE_VERSION_COLUMN_CHECKING_LEVEL = "_column_checking_level";
- static String TABLE_VERSION_COLUMN_COMMENTS = "_column_comments";
- static String TABLE_VERSION_COLUMN_CONTRIBUTORS = "_column_contributors";
- static String TABLE_VERSION_COLUMN_PUBLISH_DATE = "_column_publish_date";
- static String TABLE_VERSION_COLUMN_SOURCE_TEXT = "_column_source_text";
- static String TABLE_VERSION_COLUMN_SOURCE_TEXT_VERSION = "_column_source_text_version";
- static String TABLE_VERSION_COLUMN_VERSION = "_column_version";
-
+ static final String TABLE_VERSION_COLUMN_UID = "_column_version_uid";
+ static final String TABLE_VERSION_COLUMN_PARENT_ID = "_column_parent_id";
+ static final String TABLE_VERSION_COLUMN_DATE_MODIFIED = "_column_date_modified";
+ static final String TABLE_VERSION_COLUMN_NAME = "_column_name";
+ static final String TABLE_VERSION_COLUMN_SLUG = "_column_slug";
+ static final String TABLE_VERSION_COLUMN_SOURCE_IS_DOWNLOADED = "_column_is_downloaded";
+
+ static final String TABLE_VERSION_COLUMN_CHECKING_ENTITY = "_column_checking_entity";
+ static final String TABLE_VERSION_COLUMN_CHECKING_LEVEL = "_column_checking_level";
+ static final String TABLE_VERSION_COLUMN_COMMENTS = "_column_comments";
+ static final String TABLE_VERSION_COLUMN_CONTRIBUTORS = "_column_contributors";
+ static final String TABLE_VERSION_COLUMN_PUBLISH_DATE = "_column_publish_date";
+ static final String TABLE_VERSION_COLUMN_SOURCE_TEXT = "_column_source_text";
+ static final String TABLE_VERSION_COLUMN_SOURCE_TEXT_VERSION = "_column_source_text_version";
+ static final String TABLE_VERSION_COLUMN_VERSION = "_column_version";
public VersionDataSource(Context context) {
super(context);
@@ -57,6 +52,26 @@ public ArrayList getChildModels(VersionModel parentModel) {
return modelList;
}
+ @Override
+ public AMDatabaseModelAbstractObject saveOrUpdateModel(String json, long parentId, boolean sideLoaded) {
+ VersionModel newModel = new VersionModel(json, parentId, sideLoaded);
+ VersionModel currentModel = getModelForSlug(newModel.slug);
+
+ if(currentModel != null) {
+ newModel.uid = currentModel.uid;
+ }
+
+ if (currentModel == null || (currentModel.dateModified < newModel.dateModified)) {
+
+ newModel.parentId = parentId;
+ saveModel(newModel);
+ return getModelForSlug(newModel.slug);
+ }
+ else{
+ return null;
+ }
+ }
+
@Override
protected String getParentIdColumnName() {
return TABLE_VERSION_COLUMN_PARENT_ID;
@@ -98,6 +113,19 @@ public VersionModel getModelForSlug(String slug){
return (VersionModel) this.getModelFromDatabaseForSlug(slug);
}
+ public VersionModel deleteDownloadedBookContent(VersionModel version){
+
+ ArrayList versionBooks = version.getChildModels(context);
+
+ BookDataSource bookSource = new BookDataSource(context);
+ for(BookModel book : versionBooks){
+ bookSource.deleteDownloadedBookContent(book);
+ }
+ version.downloadState = VersionModel.DOWNLOAD_STATE.DOWNLOAD_STATE_NONE;
+ createOrUpdateDatabaseModel(version);
+ return version;
+ }
+
@Override
public ContentValues getModelAsContentValues(AMDatabaseModelAbstractObject model) {
@@ -111,11 +139,7 @@ public ContentValues getModelAsContentValues(AMDatabaseModelAbstractObject model
values.put(TABLE_VERSION_COLUMN_DATE_MODIFIED, versionModel.dateModified);
values.put(TABLE_VERSION_COLUMN_NAME, versionModel.name);
values.put(TABLE_VERSION_COLUMN_SLUG, versionModel.slug);
-
- values.put(TABLE_VERSION_COLUMN_SOURCE_URL, versionModel.sourceUrl);
- values.put(TABLE_VERSION_COLUMN_NOTES_URL, versionModel.notesUrl);
- values.put(TABLE_VERSION_COLUMN_USFM_URL, versionModel.usfmUrl);
- values.put(TABLE_VERSION_COLUMN_TERMS_URL, versionModel.termsUrl);
+ values.put(TABLE_VERSION_COLUMN_SOURCE_IS_DOWNLOADED, versionModel.downloadState.ordinal());
values.put(TABLE_VERSION_COLUMN_CHECKING_ENTITY, versionModel.status.checkingEntity);
values.put(TABLE_VERSION_COLUMN_CHECKING_LEVEL, versionModel.status.checkingLevel);
@@ -139,11 +163,8 @@ public AMDatabaseModelAbstractObject getObjectFromCursor(Cursor cursor) {
model.dateModified = cursor.getLong(cursor.getColumnIndex(TABLE_VERSION_COLUMN_DATE_MODIFIED));
model.name = cursor.getString(cursor.getColumnIndex(TABLE_VERSION_COLUMN_NAME));
model.slug = cursor.getString(cursor.getColumnIndex(TABLE_VERSION_COLUMN_SLUG));
-
- model.sourceUrl = cursor.getString(cursor.getColumnIndex(TABLE_VERSION_COLUMN_SOURCE_URL));
- model.notesUrl = cursor.getString(cursor.getColumnIndex(TABLE_VERSION_COLUMN_NOTES_URL));
- model.usfmUrl = cursor.getString(cursor.getColumnIndex(TABLE_VERSION_COLUMN_USFM_URL));
- model.termsUrl = cursor.getString(cursor.getColumnIndex(TABLE_VERSION_COLUMN_TERMS_URL));
+ model.downloadState = VersionModel.DOWNLOAD_STATE.createState(
+ cursor.getInt(cursor.getColumnIndex(TABLE_VERSION_COLUMN_SOURCE_IS_DOWNLOADED)));
model.status.checkingEntity = cursor.getString(cursor.getColumnIndex(TABLE_VERSION_COLUMN_CHECKING_ENTITY));
model.status.checkingLevel = cursor.getString(cursor.getColumnIndex(TABLE_VERSION_COLUMN_CHECKING_LEVEL));
@@ -166,11 +187,7 @@ public String getTableCreationString() {
VersionDataSource.TABLE_VERSION_COLUMN_DATE_MODIFIED + " INTEGER," +
VersionDataSource.TABLE_VERSION_COLUMN_NAME + " VARCHAR," +
VersionDataSource.TABLE_VERSION_COLUMN_SLUG + " VARCHAR," +
-
- VersionDataSource.TABLE_VERSION_COLUMN_SOURCE_URL + " VARCHAR," +
- VersionDataSource.TABLE_VERSION_COLUMN_NOTES_URL + " VARCHAR," +
- VersionDataSource.TABLE_VERSION_COLUMN_USFM_URL + " VARCHAR," +
- VersionDataSource.TABLE_VERSION_COLUMN_TERMS_URL + " VARCHAR," +
+ VersionDataSource.TABLE_VERSION_COLUMN_SOURCE_IS_DOWNLOADED + " VARCHAR," +
VersionDataSource.TABLE_VERSION_COLUMN_CHECKING_ENTITY + " VARCHAR," +
VersionDataSource.TABLE_VERSION_COLUMN_CHECKING_LEVEL + " VARCHAR," +
diff --git a/app/app/src/main/java/model/modelClasses/mainData/AMDatabase/AMDatabaseModelAbstractObject.java b/app/app/src/main/java/model/modelClasses/AMDatabase/AMDatabaseModelAbstractObject.java
similarity index 68%
rename from app/app/src/main/java/model/modelClasses/mainData/AMDatabase/AMDatabaseModelAbstractObject.java
rename to app/app/src/main/java/model/modelClasses/AMDatabase/AMDatabaseModelAbstractObject.java
index cbdd990..cfa7f3f 100644
--- a/app/app/src/main/java/model/modelClasses/mainData/AMDatabase/AMDatabaseModelAbstractObject.java
+++ b/app/app/src/main/java/model/modelClasses/AMDatabase/AMDatabaseModelAbstractObject.java
@@ -1,8 +1,7 @@
-package model.modelClasses.mainData.AMDatabase;
+package model.modelClasses.AMDatabase;
import android.content.Context;
-
-import org.json.JSONObject;
+import android.util.Log;
import java.util.GregorianCalendar;
import java.util.TimeZone;
@@ -14,6 +13,7 @@
*/
public abstract class AMDatabaseModelAbstractObject {
+ public static final String ABSTRACT_TAG = "AMDBAbstractModel";
public long uid;
public long parentId;
public String slug;
@@ -22,14 +22,14 @@ public abstract class AMDatabaseModelAbstractObject {
* Should set all the Object's attributes that are necessary to load from JSON
* @return
*/
- abstract public void initModelFromJsonObject(JSONObject jsonObject);
+ abstract public void initModelFromJson(String json, boolean sideLoaded);
/**
* Should set all the Object's attributes that are necessary to load from JSON
- * @param jsonObject
- * @param parent
+ * @param json
+ * @param parentId
*/
- abstract public void initModelFromJsonObject(JSONObject jsonObject, AMDatabaseModelAbstractObject parent);
+ abstract public void initModelFromJson(String json, long parentId, boolean sideLoaded);
/**
*
@@ -42,13 +42,14 @@ public AMDatabaseModelAbstractObject(){
}
- public AMDatabaseModelAbstractObject(JSONObject jsonObject){
+ public AMDatabaseModelAbstractObject(String json, boolean sideLoaded){
this();
- this.initModelFromJsonObject(jsonObject);
+ this.initModelFromJson(json, sideLoaded);
}
- public AMDatabaseModelAbstractObject(JSONObject jsonObject, AMDatabaseModelAbstractObject parent) {
- this.initModelFromJsonObject(jsonObject, parent);
+ public AMDatabaseModelAbstractObject(String json, long parentId, boolean sideLoaded) {
+ this.initModelFromJson(json, parentId, sideLoaded);
+// Log.d(ABSTRACT_TAG, this.toString());
}
static public long getDateFromString(String date) {
diff --git a/app/app/src/main/java/model/modelClasses/AppWordsModel.java b/app/app/src/main/java/model/modelClasses/AppWordsModel.java
deleted file mode 100644
index 3f3ebc2..0000000
--- a/app/app/src/main/java/model/modelClasses/AppWordsModel.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package model.modelClasses;
-
-import android.content.ContentValues;
-import android.util.Log;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import model.modelClasses.mainData.BookModel;
-
-/**
- * Created by Fechner on 1/9/15.
- */
-public class AppWordsModel {
-
- private static final String TAG = "AppWordsModel";
-
- private static final String CANCEL = "cancel";
- private static final String CHAPTERS = "chapters";
- private static final String LANGUAGES = "languages";
- private static final String NEXT_CHAPTER = "next_chapter";
- private static final String OK = "ok";
- private static final String REMOVE_LOCALLY = "remove_locally";
- private static final String REMOVE_THIS_STRING = "remove_this_string";
- private static final String SAVE_LOCALLY = "save_locally";
- private static final String SAVE_THIS_STRING = "save_this_string";
- private static final String SELECT_A_LANGUAGE = "select_a_language";
-
- public String cancel = "";
- public String chapters = "";
- public String languages = "";
- public String nextChapter = "";
- public String ok = "";
- public String removeLocally = "";
- public String removeThisString = "";
- public String saveLocally = "";
- public String saveThisString = "";
- public String selectALanguage = "";
-
- //BookModel bookParent;
-
- public AppWordsModel(){
-
- }
- public AppWordsModel(BookModel parent){
- //this.bookParent = parent;
- }
-
-
-
- public static AppWordsModel getAppWordsModelFromJsonObject(JSONObject jsonObj, BookModel parent){
-
- AppWordsModel model = new AppWordsModel(parent);
-
- try{
- model.cancel = jsonObj.has(CANCEL) ? jsonObj.getString(CANCEL) : "";
- model.chapters = jsonObj.has(CHAPTERS) ? jsonObj.getString(CHAPTERS) : "";
- model.languages = jsonObj.has(LANGUAGES) ? jsonObj.getString(LANGUAGES) : "";
- model.nextChapter = jsonObj.has(NEXT_CHAPTER) ? jsonObj.getString(NEXT_CHAPTER) : "";
- model.removeLocally = jsonObj.has(REMOVE_LOCALLY) ? jsonObj.getString(REMOVE_LOCALLY) : "";
- model.removeThisString = jsonObj.has(REMOVE_THIS_STRING) ? jsonObj.getString(REMOVE_THIS_STRING) : "";
- model.saveLocally = jsonObj.has(SAVE_LOCALLY) ? jsonObj.getString(SAVE_LOCALLY) : "";
- model.saveThisString = jsonObj.has(SAVE_THIS_STRING) ? jsonObj.getString(SAVE_THIS_STRING) : "";
- model.selectALanguage = jsonObj.has(SELECT_A_LANGUAGE) ? jsonObj.getString(SELECT_A_LANGUAGE) : "";
- model.ok = jsonObj.has(OK)? jsonObj.getString(OK) : "";
- }
- catch (JSONException e){
- Log.e(TAG, "AppWordsModel JSON Exception: " + e.toString());
- return null;
- }
-
- return model;
- }
-
- @Override
- public String toString() {
- return "AppWordsModel{" +
- "cancel='" + cancel + '\'' +
- ", chapters='" + chapters + '\'' +
- ", languages='" + languages + '\'' +
- ", nextChapter='" + nextChapter + '\'' +
- ", ok='" + ok + '\'' +
- ", removeLocally='" + removeLocally + '\'' +
- ", removeThisString='" + removeThisString + '\'' +
- ", saveLocally='" + saveLocally + '\'' +
- ", saveThisString='" + saveThisString + '\'' +
- ", selectALanguage='" + selectALanguage + '\'' +
- '}';
- }
-}
diff --git a/app/app/src/main/java/model/modelClasses/StatusModel.java b/app/app/src/main/java/model/modelClasses/StatusModel.java
index a0913de..db1f344 100644
--- a/app/app/src/main/java/model/modelClasses/StatusModel.java
+++ b/app/app/src/main/java/model/modelClasses/StatusModel.java
@@ -1,6 +1,7 @@
package model.modelClasses;
import android.content.ContentValues;
+import android.content.Context;
import android.util.Log;
import org.json.JSONException;
@@ -13,15 +14,6 @@
*/
public class StatusModel {
- // Table columns of TABLE_RESOURCES
- static String RESOURCES_COLUMN_AUTO_GENERATED_ID = "_column_table_resources_auto_generated_id";
- static String RESOURCES_COLUMN_LANGUAGES_SLUG = "_column_table_resources_languages_slug";
- static String RESOURCES_COLUMN_SLUG = "_column_table_resources_slug";
- static String RESOURCES_COLUMN_NAME = "_column_table_resources_name";
- static String RESOURCES_COLUMN_MODIFIED_DATE = "_column_table_resources_modified_date";
- static String RESOURCES_COLUMN_SOURCE_URL = "_column_table_resources_source_url";
- static String RESOURCES_COLUMN_TERMS_URL = "_column_table_resources_terms_url";
- static String RESOURCES_COLUMN_NOTES_URL = "_column_table_resources_notes_url";
static String RESOURCES_COLUMN_STATUS_CHECKING_ENTITY = "_column_table_resources_checking_entity";
static String RESOURCES_COLUMN_STATUS_CHECKING_LEVEL = "_column_table_resources_checking_level";
static String RESOURCES_COLUMN_STATUS_COMMENTS = "_column_table_resources_comments";
@@ -114,4 +106,16 @@ public String toString() {
", version='" + version + '\'' +
'}';
}
+
+ public String getModelAsJson(Context context) {
+ String json = "checkingEntity: \"" + checkingEntity + "\",\n" +
+ "checkingLevel: \"" + checkingLevel + "\",\n" +
+ "comments: \"" + comments + "\",\n" +
+ "contributors: \"" + contributors + "\",\n" +
+ "publishDate: \"" + publishDate + "\",\n" +
+ "sourceText: \"" + sourceText + "\",\n" +
+ "sourceTextVersion: \"" + sourceTextVersion + "\",\n" +
+ "version: \"" + version + "\"";
+ return json;
+ }
}
diff --git a/app/app/src/main/java/model/modelClasses/mainData/BibleChapterModel.java b/app/app/src/main/java/model/modelClasses/mainData/BibleChapterModel.java
index 57543e0..6b295b7 100644
--- a/app/app/src/main/java/model/modelClasses/mainData/BibleChapterModel.java
+++ b/app/app/src/main/java/model/modelClasses/mainData/BibleChapterModel.java
@@ -1,14 +1,13 @@
package model.modelClasses.mainData;
import android.content.Context;
+import android.util.Log;
-import org.json.JSONObject;
-
-import java.util.ArrayList;
+import com.google.gson.Gson;
import adapters.selectionAdapters.GeneralRowInterface;
import model.datasource.BibleChapterDataSource;
-import model.modelClasses.mainData.AMDatabase.AMDatabaseModelAbstractObject;
+import model.modelClasses.AMDatabase.AMDatabaseModelAbstractObject;
/**
* Created by Acts Media Inc. on 3/12/14.
@@ -20,16 +19,16 @@ public class BibleChapterModel extends AMDatabaseModelAbstractObject implements
public String number;
public String text;
- private VersionModel parent = null;
- public VersionModel getParent(Context context){
+ private BookModel parent = null;
+ public BookModel getParent(Context context){
if(parent == null){
- parent = (VersionModel) this.getDataSource(context).loadParentModelFromDatabase(this);
+ parent = (BookModel) this.getDataSource(context).loadParentModelFromDatabase(this);
}
return parent;
}
- public void setParent(VersionModel parent){
+ public void setParent(BookModel parent){
this.parent = parent;
}
@@ -37,42 +36,38 @@ public BibleChapterModel() {
super();
}
- public BibleChapterModel(JSONObject jsonObject, AMDatabaseModelAbstractObject parent) {
- super(jsonObject, parent);
+ public BibleChapterModel(String json, long parentId, boolean sideLoaded) {
+ super(json, parentId, sideLoaded);
}
public BibleChapterDataSource getDataSource(Context context) {
return new BibleChapterDataSource(context);
}
- public void initModelFromJsonObject(JSONObject jsonObj) {
+ public void initModelFromJson(String json, boolean sideLoaded) {
return;
}
@Override
- public void initModelFromJsonObject(JSONObject jsonObject, AMDatabaseModelAbstractObject parent) {
-
- this.initModelFromJsonObject(jsonObject);
- this.parentId = parent.uid;
- this.slug = parent.slug + this.number;
- this.text = "";
- }
+ public void initModelFromJson(String json, long parentId, boolean sideLoaded) {
- public ArrayList getAvailableLanguages(Context context) {
-
- ArrayList languages = this.getParent(context).getAvailableLanguages(context);
- return languages;
+ if(sideLoaded){
+ initModelFromSideLoadedJson(json);
+ }
+ else{
+ Log.e(TAG, "BibleChapterModel. This should't happen!");
+ }
+ this.parentId = parentId;
}
-
@Override
public String getTitle() {
return "Chapter " + this.number;
}
public String getTitle(Context context) {
- return this.getParent(context).getParent(context).getTitle() + " " + this.number;
+ return this.getParent(context).getTitle() + " " + this.number;
}
@Override
@@ -96,4 +91,35 @@ public String toString() {
", number='" + number + '\'' +
"} " + super.toString();
}
+
+ protected class BibleChapterSideLoadedModel {
+
+ String number;
+ String slug;
+ String text;
+
+ PageModel.PageSideLoadedModel[] pages;
+
+ public BibleChapterSideLoadedModel(BibleChapterModel chapter) {
+ this.number = chapter.number;
+ this.text = chapter.text;
+ this.slug = chapter.slug;
+ }
+ }
+
+ protected BibleChapterSideLoadedModel getAsSideLoadedModel(){
+
+ return new BibleChapterSideLoadedModel(this);
+ }
+
+ public void initModelFromSideLoadedJson(String json){
+
+ BibleChapterSideLoadedModel model = new Gson().fromJson(json, BibleChapterSideLoadedModel.class);
+
+ this.number = model.number;
+ this.text = model.text;
+ this.slug = model.slug;
+ this.uid = -1;
+ }
+
}
\ No newline at end of file
diff --git a/app/app/src/main/java/model/modelClasses/mainData/BookModel.java b/app/app/src/main/java/model/modelClasses/mainData/BookModel.java
index 33317c6..204f31e 100644
--- a/app/app/src/main/java/model/modelClasses/mainData/BookModel.java
+++ b/app/app/src/main/java/model/modelClasses/mainData/BookModel.java
@@ -1,37 +1,59 @@
package model.modelClasses.mainData;
import android.content.Context;
-import android.util.Log;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.google.gson.Gson;
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.Collections;
+import adapters.selectionAdapters.GeneralRowInterface;
+import model.datasource.BibleChapterDataSource;
import model.datasource.BookDataSource;
-import model.modelClasses.AppWordsModel;
-import model.modelClasses.mainData.AMDatabase.AMDatabaseModelAbstractObject;
+import model.modelClasses.AMDatabase.AMDatabaseModelAbstractObject;
+import signing.Status;
/**
* Created by Fechner on 1/9/15.
*/
-public class BookModel extends AMDatabaseModelAbstractObject {
+public class BookModel extends AMDatabaseModelAbstractObject implements GeneralRowInterface {
- private static final String TAG = "BookModel";
+ private class BookJsonModel {
- static final String APP_WORDS = "app_words";
- static final String CHAPTERS = "chapters";
- static final String DATE_MODIFIED = "date_modified";
- static final String DIRECTION = "direction";
- static final String LANGUAGE = "language";
+ long mod;
+ String title;
+ String slug;
+ String src;
+ String src_sig;
+ String desc;
+ }
+
+ private class SignatureJsonModel {
+
+ String si;
+ String sig;
+ }
+
+ @Override
+ public String getTitle() {
+ return this.title;
+ }
+
+ @Override
+ public String getChildIdentifier() {
+ return Long.toString(this.uid);
+ }
public long dateModified;
- public String language;
- public String direction;
- public AppWordsModel appWords;
+ public String title;
+ public String description;
+ public String sourceUrl;
+ public String signatureUrl;
+
+ public String signingEntity;
+ public String signature;
+ public int verificationStatus;
private VersionModel parent = null;
public VersionModel getParent(Context context){
@@ -45,43 +67,68 @@ public void setParent(VersionModel parent){
this.parent = parent;
}
- private ArrayList chapters = null;
- public ArrayList getChildModels(Context context){
+ private ArrayList storyChapters = null;
+ public ArrayList getStoryChildModels(Context context){
- if(chapters == null){
- chapters = this.getDataSource(context).getChildModels(this);
+ if(storyChapters == null){
+ storyChapters = this.getDataSource(context).getChildModels(this);
+ Collections.sort(storyChapters);
}
- return chapters;
+ return storyChapters;
}
- public Map getPages(Context context){
+ public StoriesChapterModel getStoryChapter(Context context, int chapterNumber){
- ArrayList pages = new ArrayList();
+ this.getStoryChildModels(context);
+ Collections.sort(this.storyChapters);
- for(StoriesChapterModel chapter : this.getChildModels(context)){
- pages.addAll(chapter.getChildModels(context));
+ if(chapterNumber >= this.storyChapters.size()){
+ return null;
+ }
+ else{
+ return this.storyChapters.get(chapterNumber -1);
}
+ }
- Map pageMap = new HashMap();
+ private ArrayList bibleChapterModels = null;
+ public ArrayList getBibleChildModels(Context context){
- for(PageModel page : pages){
- pageMap.put(page.uid, page);
+ if(bibleChapterModels == null){
+ bibleChapterModels = new BibleChapterDataSource(context).getChaptersForParentId(Long.toString(this.uid));
+ Collections.sort(bibleChapterModels);
}
- return pageMap;
+ return bibleChapterModels;
+ }
+
+ public BibleChapterModel getBibleChapter(Context context, int chapterNumber){
+
+ this.getBibleChildModels(context);
+ Collections.sort(this.bibleChapterModels);
+
+ if(chapterNumber >= this.bibleChapterModels.size()){
+ return null;
+ }
+ else{
+ for(BibleChapterModel chapter : bibleChapterModels) {
+ if(Integer.parseInt(chapter.number.trim()) == chapterNumber){
+ return chapter;
+ }
+ }
+ }
+ return null;
}
public BookModel(){
super();
- this.appWords = new AppWordsModel();
}
- public BookModel(JSONObject jsonObject) {
- super(jsonObject);
+ public BookModel(String jsonObject, boolean sideLoaded) {
+ super(jsonObject, sideLoaded);
}
- public BookModel(JSONObject jsonObject, AMDatabaseModelAbstractObject parent) {
- super(jsonObject, parent);
+ public BookModel(String jsonObject, long parentId, boolean sideLoaded) {
+ super(jsonObject, parentId, sideLoaded);
}
@Override
@@ -89,65 +136,133 @@ public BookDataSource getDataSource(Context context) {
return new BookDataSource(context);
}
- public void initModelFromJsonObject(JSONObject jsonObj){
+ @Override
+ public void initModelFromJson(String json, boolean sideLoaded){
- try {
- long date = -1;
+ if(sideLoaded){
+ initModelFromSideLoadedJson(json);
+ return;
+ }
- if (jsonObj.has(DATE_MODIFIED)) {
- String dateString = jsonObj.getString(DATE_MODIFIED);
- date = Integer.parseInt(dateString);
- }
+ BookJsonModel model = new Gson().fromJson(json, BookJsonModel.class);
- this.dateModified = date > 0 ? date : -1;
- this.direction = jsonObj.has(DIRECTION) ? jsonObj.getString(DIRECTION) : "";
- this.language = jsonObj.has(LANGUAGE) ? jsonObj.getString(LANGUAGE) : "";
+ this.dateModified = model.mod;
+ this.title = model.title;
+ this.slug = model.slug + model.title;
+ this.sourceUrl = model.src;
+ this.signatureUrl = model.src_sig;
+ this.description = model.desc;
+ this.uid = -1;
+ }
+
+ @Override
+ public void initModelFromJson(String json, long parentId, boolean sideLoaded) {
- JSONObject wordsModelObj = jsonObj.getJSONObject(APP_WORDS);
- AppWordsModel wordsModel = AppWordsModel.getAppWordsModelFromJsonObject(wordsModelObj, this);
- if(wordsModel != null){
- this.appWords = wordsModel;
+ if(sideLoaded){
+ initModelFromSideLoadedJson(json);
+ }
+ else {
+ this.initModelFromJson(json, sideLoaded);
+ if(slug.length() < 3){
+ slug = sourceUrl;
}
else{
- this.appWords = new AppWordsModel();
+ slug += sourceUrl;
}
-
-// if (jsonObj.has(CHAPTERS)) {
-//
-// chapters = new ArrayList();
-// JSONArray jsonArray = jsonObj.getJSONArray(CHAPTERS);
-//
-// for (int i = 0; i < jsonArray.length(); i++) {
-// JSONObject pageJsonObj = jsonArray.getJSONObject(i);
-//
-// ChapterModel chapter = new ChapterModel();
-// chapter.initModelFromJsonObject(pageJsonObj);
-// chapters.add(chapter);
-// }
-// }
- }
- catch (JSONException e){
- Log.e(TAG, "BookModel JSON Exception: " + e.toString());
- e.printStackTrace();
}
+ this.parentId = parentId;
+ this.verificationStatus = Status.ERROR.ordinal();
}
- @Override
- public void initModelFromJsonObject(JSONObject jsonObject, AMDatabaseModelAbstractObject parent) {
+ public void setEntityFromJson(String json){
+
+ SignatureJsonModel model = new Gson().fromJson(json, SignatureJsonModel.class);
- this.initModelFromJsonObject(jsonObject);
- this.parentId = parent.uid;
- this.slug = parent.slug + this.language;
+ signingEntity = model.si;
+ signature = model.sig;
}
@Override
public String toString() {
return "BookModel{" +
- "appWords=" + appWords +
- ", dateModified=" + dateModified +
- ", language='" + language + '\'' +
- ", direction='" + direction + '\'' +
+ "dateModified=" + dateModified +
+ ", title='" + title + '\'' +
+ ", description='" + description + '\'' +
+ ", sourceUrl='" + sourceUrl + '\'' +
+ ", signatureUrl='" + signatureUrl + '\'' +
+ ", parent=" + parent +
"} " + super.toString();
}
+
+ protected class BookSideLoadedModel {
+
+ long date_modified;
+ String title;
+ String slug;
+ String description;
+ String source_url;
+ String signature_url;
+
+ String signing_entity;
+ String signature;
+ int verificationStatus;
+
+ StoriesChapterModel.StoriesChapterSideLoadedModel[] storiesChapters;
+ BibleChapterModel.BibleChapterSideLoadedModel[] bibleChapters;
+
+ public BookSideLoadedModel(BookModel book, Context context) {
+ this.date_modified = book.dateModified;
+ this.title = book.title;
+ this.slug = book.slug;
+ this.description = book.description;
+ this.source_url = book.sourceUrl;
+ this.signature_url = book.signatureUrl;
+ this.signing_entity = book.signingEntity;
+ this.signature = book.signature;
+ this.verificationStatus = book.verificationStatus;
+
+ if(book.sourceUrl.contains("usfm")){
+
+ ArrayList chapters = book.getBibleChildModels(context);
+ bibleChapters = new BibleChapterModel.BibleChapterSideLoadedModel[chapters.size()];
+
+ for(int i = 0; i < chapters.size(); i++){
+ bibleChapters[i] = chapters.get(i).getAsSideLoadedModel();
+ }
+ storiesChapters = new StoriesChapterModel.StoriesChapterSideLoadedModel[0];
+ }
+ else{
+ ArrayList chapters = book.getStoryChildModels(context);
+ storiesChapters = new StoriesChapterModel.StoriesChapterSideLoadedModel[chapters.size()];
+
+ for(int i = 0; i < chapters.size(); i++){
+ storiesChapters[i] = chapters.get(i).getAsSideLoadedModel(context);
+ }
+ bibleChapters = new BibleChapterModel.BibleChapterSideLoadedModel[0];
+ }
+ }
+ }
+
+ protected BookSideLoadedModel getAsSideLoadedModel(Context context){
+
+ return new BookSideLoadedModel(this, context);
+ }
+
+ public void initModelFromSideLoadedJson(String json){
+
+ BookSideLoadedModel model = new Gson().fromJson(json, BookSideLoadedModel.class);
+
+ this.dateModified = model.date_modified;
+ this.title = model.title;
+ this.slug = model.slug;
+ this.sourceUrl = model.source_url;
+ this.signatureUrl = model.signature_url;
+ this.signingEntity = model.signing_entity;
+ this.signature = model.signature;
+ this.verificationStatus = model.verificationStatus;
+ this.description = model.description;
+
+ this.uid = -1;
+ }
}
diff --git a/app/app/src/main/java/model/modelClasses/mainData/LanguageModel.java b/app/app/src/main/java/model/modelClasses/mainData/LanguageModel.java
index 00ed25c..d996fe4 100644
--- a/app/app/src/main/java/model/modelClasses/mainData/LanguageModel.java
+++ b/app/app/src/main/java/model/modelClasses/mainData/LanguageModel.java
@@ -1,49 +1,32 @@
package model.modelClasses.mainData;
import android.content.Context;
-import android.util.Log;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.google.gson.Gson;
import java.util.ArrayList;
import adapters.selectionAdapters.GeneralRowInterface;
-import model.database.ModelCaching;
import model.datasource.LanguageDataSource;
-import model.database.DBManager;
-import model.modelClasses.mainData.AMDatabase.AMDatabaseModelAbstractObject;
+import model.modelClasses.AMDatabase.AMDatabaseModelAbstractObject;
/**
* Created by Acts Media Inc. on 3/12/14.
*/
public class LanguageModel extends AMDatabaseModelAbstractObject implements GeneralRowInterface{
- private static final String TAG = "LanguageModel";
- private static final String LANGUAGE_JSON_KEY = "language";
- private static final String MODIFIED_DATE_JSON_KEY = "date_modified";
- private static final String READING_DIRECTION_JSON_KEY = "direction";
- private static final String LANGUAGE_NAME_JSON_KEY = "name";
- private static final String SLUG_JSON_KEY = "slug";
+ private class LanguageJsonModel{
- private static final String PROJECT_JSON_KEY = "project";
- private static final String DESCRIPTION_JSON_KEY = "desc";
- private static final String META_JSON_KEY = "meta";
- private static final String PROJECT_NAME_JSON_KEY = "name";
- private static final String SORT_JSON_KEY = "sort";
- private static final String RESOURCE_URL_JSON_KEY = "res_catalog";
+ long mod;
+ String slug;
+ String lc;
+ }
+ private static final String TAG = "LanguageModel";
public long dateModified;
- public String readingDirection;
- public String languageName;
- public String resourceUrl;
-
- public String description;
- public String meta;
- public String projectName;
- public int sortOrder;
+ public String languageAbbreviation;
private ProjectModel parent;
public ProjectModel getParent(Context context){
@@ -57,25 +40,25 @@ public void setParent(ProjectModel parent){
this.parent = parent;
}
- private ArrayList resources = null;
+ private ArrayList versions = null;
public ArrayList getChildModels(Context context){
- if(resources == null){
- resources = this.getDataSource(context).getChildModels(this);
+ if(versions == null){
+ versions = this.getDataSource(context).getChildModels(this);
}
- return resources;
+ return versions;
}
public LanguageModel() {
}
- public LanguageModel(JSONObject jsonObject) {
- super(jsonObject);
+ public LanguageModel(String jsonObject, boolean sideLoaded) {
+ super(jsonObject, sideLoaded);
}
- public LanguageModel(JSONObject jsonObject, AMDatabaseModelAbstractObject parent) {
- super(jsonObject, parent);
+ public LanguageModel(String jsonObject, long parentId, boolean sideLoaded) {
+ super(jsonObject, parentId, sideLoaded);
}
@Override
@@ -83,60 +66,38 @@ public LanguageDataSource getDataSource(Context context) {
return new LanguageDataSource(context);
}
- public void initModelFromJsonObject(JSONObject jsonObj){
-
- try {
- resourceUrl = jsonObj.has(RESOURCE_URL_JSON_KEY) ? jsonObj.getString(RESOURCE_URL_JSON_KEY) : "";
-
- JSONObject languageObject = jsonObj.getJSONObject(LANGUAGE_JSON_KEY);
-
- slug = languageObject.has(SLUG_JSON_KEY) ? languageObject.getString(SLUG_JSON_KEY) : "";
- languageName = languageObject.has(LANGUAGE_NAME_JSON_KEY) ? languageObject.getString(LANGUAGE_NAME_JSON_KEY) : "";
- readingDirection = languageObject.has(READING_DIRECTION_JSON_KEY) ? languageObject.getString(READING_DIRECTION_JSON_KEY) : "";
-
- if (languageObject.has(MODIFIED_DATE_JSON_KEY)) {
- dateModified = getDateFromString(languageObject.getString(MODIFIED_DATE_JSON_KEY));
- }
- else{
- dateModified = -1;
- }
-
- JSONObject projectObject = jsonObj.getJSONObject(PROJECT_JSON_KEY);
+ @Override
+ public void initModelFromJson(String json, boolean sideLoaded){
- projectName = projectObject.has(PROJECT_NAME_JSON_KEY) ? projectObject.getString(PROJECT_NAME_JSON_KEY) : "";
- description = projectObject.has(DESCRIPTION_JSON_KEY) ? projectObject.getString(DESCRIPTION_JSON_KEY) : "";
- meta = projectObject.has(META_JSON_KEY) ? projectObject.getString(META_JSON_KEY) : "";
- sortOrder = projectObject.has(SORT_JSON_KEY) ? Integer.parseInt(projectObject.getString(SORT_JSON_KEY)) : 0;
+ if(sideLoaded){
+ initModelFromSideLoadedJson(json);
+ return;
}
- catch (JSONException e){
- Log.e(TAG, "LanguageModel JSON Exception: " + e.toString());
- }
- }
- public ArrayList getAvailableLanguages(Context context) {
+ LanguageJsonModel model = new Gson().fromJson(json, LanguageJsonModel.class);
- ArrayList availLanguages = ModelCaching.getAvailableLanguages(context);
- ArrayList languages = new ArrayList();
-
- for(String language : availLanguages){
- if(getParent(context).containsLanguage(language, context) && !languages.contains(language)){
- languages.add(language.toLowerCase());
- }
- }
- return languages;
+ dateModified = model.mod;
+ languageAbbreviation = model.lc;
+ uid = -1;
}
@Override
- public void initModelFromJsonObject(JSONObject jsonObject, AMDatabaseModelAbstractObject parent) {
- this.initModelFromJsonObject(jsonObject);
+ public void initModelFromJson(String json, long parentId, boolean sideLoaded) {
+
+ if(sideLoaded){
+ initModelFromSideLoadedJson(json);
+ }
+ else {
+ this.initModelFromJson(json, sideLoaded);
+ this.parentId = parentId;
+ this.slug = this.languageAbbreviation + parentId;
+ }
- this.parentId = parent.uid;
- this.slug += ((ProjectModel) parent).slug;
}
@Override
public String getTitle() {
- return this.projectName;
+ return this.languageAbbreviation;
}
@Override
@@ -148,16 +109,45 @@ public String getChildIdentifier() {
public String toString() {
return "LanguageModel{" +
"dateModified=" + dateModified +
- ", readingDirection='" + readingDirection + '\'' +
- ", languageName='" + languageName + '\'' +
- ", slug='" + slug + '\'' +
- ", resourceUrl='" + resourceUrl + '\'' +
- ", description='" + description + '\'' +
- ", meta='" + meta + '\'' +
- ", projectName='" + projectName + '\'' +
- ", sortOrder=" + sortOrder +
+ ", languageAbbreviation='" + languageAbbreviation + '\'' +
", parent=" + parent +
- ", resources=" + resources +
"} " + super.toString();
}
+
+ protected class LanguageSideLoadedModel{
+
+ long date_modified;
+ String slug;
+ String lang_abbrev;
+ VersionModel.VersionSideLoadedModel[] versions;
+
+ private LanguageSideLoadedModel(LanguageModel model, Context context) {
+
+ this.date_modified = model.dateModified;
+ this.lang_abbrev = model.languageAbbreviation;
+ this.slug = model.slug;
+
+ ArrayList bookModels = model.getChildModels(context);
+ this.versions = new VersionModel.VersionSideLoadedModel[bookModels.size()];
+
+ for(int i = 0; i < bookModels.size(); i++){
+ this.versions[i] = bookModels.get(i).getAsSideLoadedModel(context);
+ }
+ }
+ }
+
+ protected LanguageSideLoadedModel getAsSideLoadedModel(Context context){
+
+ return new LanguageSideLoadedModel(this, context);
+ }
+
+ public void initModelFromSideLoadedJson(String json){
+
+ LanguageSideLoadedModel model = new Gson().fromJson(json, LanguageSideLoadedModel.class);
+
+ dateModified = model.date_modified;
+ languageAbbreviation = model.lang_abbrev;
+ slug = model.slug;
+ uid = -1;
+ }
}
diff --git a/app/app/src/main/java/model/modelClasses/mainData/PageModel.java b/app/app/src/main/java/model/modelClasses/mainData/PageModel.java
index 05685bf..6501d9e 100644
--- a/app/app/src/main/java/model/modelClasses/mainData/PageModel.java
+++ b/app/app/src/main/java/model/modelClasses/mainData/PageModel.java
@@ -3,22 +3,24 @@
import android.content.Context;
import android.util.Log;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.google.gson.Gson;
import model.datasource.PageDataSource;
-import model.modelClasses.mainData.AMDatabase.AMDatabaseModelAbstractObject;
+import model.modelClasses.AMDatabase.AMDatabaseModelAbstractObject;
/**
* Created by Fechner on 1/9/15.
*/
public class PageModel extends AMDatabaseModelAbstractObject {
- private static final String TAG = "PageModel";
+ private class PageJsonModel {
- private static final String ID = "id";
- private static final String IMAGE_URL = "img";
- private static final String TEXT = "text";
+ String id;
+ String img;
+ String text;
+ }
+
+ private static final String TAG = "PageModel";
public String pageNumber;
public String chapterNumber;
@@ -54,8 +56,12 @@ public PageModel() {
super();
}
- public PageModel(JSONObject jsonObject, AMDatabaseModelAbstractObject parent) {
- super(jsonObject, parent);
+ public PageModel(String jsonObject, boolean sideLoaded) {
+ super(jsonObject, sideLoaded);
+ }
+
+ public PageModel(String jsonObject, long parentId, boolean sideLoaded) {
+ super(jsonObject, parentId, sideLoaded);
}
@@ -63,31 +69,44 @@ public PageDataSource getDataSource(Context context) {
return new PageDataSource(context);
}
- public void initModelFromJsonObject(JSONObject jsonObj) {
-
- try {
- String idString = jsonObj.has(ID) ? jsonObj.getString(ID) : "";
- if (idString.length() > 1) {
- String[] splitString = idString.split("-");
- this.chapterNumber = splitString[0];
- this.pageNumber = splitString[1];
- }
- else{
- Log.e(TAG, "Error splitting PageModel id: " + idString);
- }
- this.imageUrl = jsonObj.has(IMAGE_URL) ? jsonObj.getString(IMAGE_URL) : "";
- this.text = jsonObj.has(TEXT) ? jsonObj.getString(TEXT) : "";
- } catch (JSONException e) {
- Log.e(TAG, "PageModel JSON Exception: " + e.toString());
+ @Override
+ public void initModelFromJson(String json, boolean sideLoaded) {
+
+ if(sideLoaded){
+ initModelFromSideLoadedJson(json);
+ return;
}
+
+ PageJsonModel model = new Gson().fromJson(json, PageJsonModel.class);
+
+ this.imageUrl = model.img;
+ this.text = model.text;
+
+ String idString = model.id;
+ if (idString.length() > 1) {
+ String[] splitString = idString.split("-");
+ this.chapterNumber = splitString[0];
+ this.pageNumber = splitString[1];
+ }
+ else{
+ Log.e(TAG, "Error splitting PageModel id: " + idString);
+ }
+
+ this.uid = -1;
}
@Override
- public void initModelFromJsonObject(JSONObject jsonObject, AMDatabaseModelAbstractObject parent) {
+ public void initModelFromJson(String json, long parentId, boolean sideLoaded) {
- this.initModelFromJsonObject(jsonObject);
- this.parentId = parent.uid;
- this.slug = parent.slug + pageNumber;
+ if(sideLoaded){
+ initModelFromSideLoadedJson(json);
+ }
+ else {
+ this.initModelFromJson(json, sideLoaded);
+ this.slug = chapterNumber + pageNumber + "parent" + parentId;
+ }
+
+ this.parentId = parentId;
}
@Override
@@ -100,4 +119,42 @@ public String toString() {
", parent=" + parent +
"} " + super.toString();
}
+
+ protected class PageSideLoadedModel {
+
+ String page_number;
+ String chapter_number;
+ String img;
+ String text;
+
+ public PageSideLoadedModel(PageModel page) {
+ this.page_number = page.pageNumber;
+ this.chapter_number = page.chapterNumber;
+ this.img = page.imageUrl;
+ this.text = page.text;
+ }
+ }
+
+ protected PageSideLoadedModel getAsSideLoadedModel(){
+
+ return new PageSideLoadedModel(this);
+ }
+
+ public void initModelFromSideLoadedJson(String json){
+
+ PageSideLoadedModel model = new Gson().fromJson(json, PageSideLoadedModel.class);
+
+ this.pageNumber = model.page_number;
+ this.chapterNumber = model.chapter_number;
+ this.imageUrl = model.img;
+ this.text = model.text;
+ }
}
+
+
+
+
+
+
+
+
diff --git a/app/app/src/main/java/model/modelClasses/mainData/ProjectModel.java b/app/app/src/main/java/model/modelClasses/mainData/ProjectModel.java
index c23808a..d514f93 100644
--- a/app/app/src/main/java/model/modelClasses/mainData/ProjectModel.java
+++ b/app/app/src/main/java/model/modelClasses/mainData/ProjectModel.java
@@ -1,35 +1,28 @@
package model.modelClasses.mainData;
import android.content.Context;
-import android.util.Log;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.google.gson.Gson;
import java.util.ArrayList;
import adapters.selectionAdapters.GeneralRowInterface;
import model.datasource.ProjectDataSource;
-import model.modelClasses.mainData.AMDatabase.AMDatabaseModelAbstractObject;
+import model.modelClasses.AMDatabase.AMDatabaseModelAbstractObject;
/**
* Created by Fechner on 1/22/15.
*/
public class ProjectModel extends AMDatabaseModelAbstractObject implements GeneralRowInterface, Comparable{
- private static final String TAG = "AMDBeModelAbstractObj";
-
- private static final String DATE_MODIFIED_JSON_KEY = "date_modified";
- private static final String LANGUAGES_URL_JSON_KEY = "lang_catalog";
- private static final String META_JSON_KEY = "meta";
- private static final String SLUG_JSON_KEY = "slug";
- private static final String SORT_JSON_KEY = "sort";
+ private static final String TAG = "AMDBModelAbstractObj";
+ private class ProjectJsonModel{
+ String title;
+ String slug;
+ }
- public long dateModified;
- public String languageUrl;
- public String meta;
- public int sort;
+ public String title;
private ArrayList languages = null;
public ArrayList getChildModels(Context context){
@@ -43,8 +36,8 @@ public ArrayList getChildModels(Context context){
public ProjectModel() {
}
- public ProjectModel(JSONObject jsonObject) {
- super(jsonObject);
+ public ProjectModel(String jsonObject, boolean sideLoaded) {
+ super(jsonObject, sideLoaded);
}
@Override
@@ -57,116 +50,90 @@ public boolean containsLanguage(String languageName, Context context){
ArrayList childLanguages = this.getChildModels(context);
for(LanguageModel model : childLanguages){
- if(model.languageName.equalsIgnoreCase(languageName)){
+ if(model.languageAbbreviation.equalsIgnoreCase(languageName)){
return true;
}
}
-
return false;
}
- public ArrayList getAvailableLanguageNames(Context context){
-
- ArrayList childLanguages = this.getChildModels(context);
- ArrayList languages = new ArrayList();
-
- for(LanguageModel model : childLanguages){
- languages.add(model.languageName);
+ @Override
+ public void initModelFromJson(String json, boolean sideLoaded){
+ if(sideLoaded){
+ initModelFromSideLoadedJson(json);
+ return;
}
- return languages;
+ ProjectJsonModel model = new Gson().fromJson(json, ProjectJsonModel.class);
+
+ title = model.title;
+ slug = model.slug;
+ uid = -1;
}
- public LanguageModel getLanguageModel(Context context, String languageName){
+ @Override
+ public void initModelFromJson(String json, long parentId, boolean sideLoaded) {
+ return;
+ }
- ArrayList childLanguages = this.getChildModels(context);
+ @Override
+ public int compareTo(ProjectModel another) {
+ return this.title.substring(0, 1).compareTo(another.title.substring(0, 1));
+ }
- for(LanguageModel model : childLanguages){
- if(model.languageName.equalsIgnoreCase(languageName)){
- return model;
- }
- }
- return null;
+ @Override
+ public String getTitle() {
+ return this.title;
}
- public String getLanguageProjectNameForLanguage(String languageName, Context context){
+ @Override
+ public String getChildIdentifier() {
+ return Long.toString(this.uid);
+ }
- ArrayList childLanguages = this.getChildModels(context);
- for(LanguageModel model : childLanguages){
- if(model.languageName.equalsIgnoreCase(languageName)){
- return model.projectName;
- }
- }
- return null;
+ @Override
+ public String toString() {
+ return "ProjectModel{" +
+ "title='" + title + '\'' +
+ "} " + super.toString();
}
- //region DatabaseInterface
+ protected class ProjectSideLoadedModel {
- public void initModelFromJsonObject(JSONObject jsonObj){
+ String title;
+ String slug;
+ long date_modified;
- try {
+ LanguageModel.LanguageSideLoadedModel[] languages;
- if (jsonObj.has(DATE_MODIFIED_JSON_KEY)) {
- dateModified = getDateFromString(jsonObj.getString(DATE_MODIFIED_JSON_KEY));
- }
- else{
- dateModified = -1;
- }
+ private ProjectSideLoadedModel(ProjectModel model, Context context) {
- slug = jsonObj.has(SLUG_JSON_KEY) ? jsonObj.getString(SLUG_JSON_KEY) : "";
- languageUrl = jsonObj.has(LANGUAGES_URL_JSON_KEY) ? jsonObj.getString(LANGUAGES_URL_JSON_KEY) : "";
- String metaString = jsonObj.has(META_JSON_KEY) ? jsonObj.getString(META_JSON_KEY) : "";
- metaString = metaString.replace("[\"", "");
- metaString = metaString.replace("\"]", "");
+ this.title = model.title;
+ this.slug = model.slug;
- this.meta = (metaString.length() > 2)? metaString : "Bible Stories";
- sort = Integer.parseInt(jsonObj.has(SORT_JSON_KEY) ? jsonObj.getString(SORT_JSON_KEY) : "");
- uid = 0;
+ ArrayList bookModels = model.getChildModels(context);
+ this.languages = new LanguageModel.LanguageSideLoadedModel[bookModels.size()];
- }
- catch (JSONException e){
- Log.e(TAG, "LanguageModel JSON Exception: " + e.toString());
+ for(int i = 0; i < bookModels.size(); i++){
+ this.languages[i] = bookModels.get(i).getAsSideLoadedModel(context);
+ }
}
}
- @Override
- public void initModelFromJsonObject(JSONObject jsonObject, AMDatabaseModelAbstractObject parent) {
- return;
- }
-
- //endregion
-
+ public ProjectSideLoadedModel getAsSideLoadedModel(Context context){
- @Override
- public int compareTo(ProjectModel another) {
- return this.sort - another.sort;
+ return new ProjectSideLoadedModel(this, context);
}
- @Override
- public String toString() {
- return "ProjectModel{" +
- "dateModified=" + dateModified +
- ", languageUrl='" + languageUrl + '\'' +
- ", meta='" + meta + '\'' +
- ", slug='" + slug + '\'' +
- ", sort=" + sort +
- ", languages=" + languages +
- "} " + super.toString();
- }
+ public void initModelFromSideLoadedJson(String json){
- //region GeneralRowInterface
+ ProjectSideLoadedModel model = new Gson().fromJson(json, ProjectSideLoadedModel.class);
- @Override
- public String getTitle() {
- return null;
- }
-
- @Override
- public String getChildIdentifier() {
- return null;
+ title = model.title;
+ slug = model.slug;
+ uid = -1;
}
- //endregion
}
diff --git a/app/app/src/main/java/model/modelClasses/mainData/StoriesChapterModel.java b/app/app/src/main/java/model/modelClasses/mainData/StoriesChapterModel.java
index 6a43883..7ae26b0 100644
--- a/app/app/src/main/java/model/modelClasses/mainData/StoriesChapterModel.java
+++ b/app/app/src/main/java/model/modelClasses/mainData/StoriesChapterModel.java
@@ -1,28 +1,26 @@
package model.modelClasses.mainData;
import android.content.Context;
-import android.util.Log;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.google.gson.Gson;
import java.util.ArrayList;
import adapters.selectionAdapters.GeneralRowInterface;
import model.datasource.StoriesChapterDataSource;
-import model.modelClasses.mainData.AMDatabase.AMDatabaseModelAbstractObject;
+import model.modelClasses.AMDatabase.AMDatabaseModelAbstractObject;
/**
* Created by Acts Media Inc. on 3/12/14.
*/
public class StoriesChapterModel extends AMDatabaseModelAbstractObject implements GeneralRowInterface, Comparable {
- private static final String TAG = "LanguageModel";
+ private class StoriesChapterJsonModel {
- private static final String NUMBER = "number";
- private static final String TITLE = "title";
- private static final String REF = "ref";
-// private static final String PAGES = "frames";
+ String number;
+ String title;
+ String ref;
+ }
public String number;
public String description;
@@ -55,43 +53,46 @@ public StoriesChapterModel() {
super();
}
- public StoriesChapterModel(JSONObject jsonObject, AMDatabaseModelAbstractObject parent) {
- super(jsonObject, parent);
+ public StoriesChapterModel(String jsonObject, boolean sideLoaded) {
+ super(jsonObject, sideLoaded);
+ }
+
+ public StoriesChapterModel(String jsonObject, long parentId, boolean sideLoaded) {
+ super(jsonObject, parentId, sideLoaded);
}
public StoriesChapterDataSource getDataSource(Context context) {
return new StoriesChapterDataSource(context);
}
- public void AddBlankPageToEnd(){
- PageModel pageModel = pages.get(0);
- pages.add(pageModel);
- }
+ @Override
+ public void initModelFromJson(String json, boolean sideLoaded) {
- public void initModelFromJsonObject(JSONObject jsonObj) {
+ if(sideLoaded){
+ initModelFromSideLoadedJson(json);
+ return;
+ }
+ StoriesChapterJsonModel model = new Gson().fromJson(json, StoriesChapterJsonModel.class);
- try {
- this.number = jsonObj.has(NUMBER) ? jsonObj.getString(NUMBER) : "";
- this.description = jsonObj.has(REF) ? jsonObj.getString(REF) : "";
- this.title = jsonObj.has(TITLE) ? jsonObj.getString(TITLE) : "";
+ number = model.number;
+ description = model.ref;
+ title = model.title;
- } catch (JSONException e) {
- Log.e(TAG, "ChapterModel JSON Exception: " + e.toString());
- }
+ uid = -1;
}
@Override
- public void initModelFromJsonObject(JSONObject jsonObject, AMDatabaseModelAbstractObject parent) {
+ public void initModelFromJson(String json, long parentId, boolean sideLoaded) {
- this.initModelFromJsonObject(jsonObject);
- this.parentId = parent.uid;
- this.slug = parent.slug + this.number;
- }
-
- public ArrayList getAvailableLanguages(Context context) {
+ if(sideLoaded){
+ initModelFromSideLoadedJson(json);
+ }
+ else {
+ this.initModelFromJson(json, sideLoaded);
+ this.slug = this.title + "parent" + parentId;
+ }
- ArrayList languages = this.getParent(context).getParent(context).getAvailableLanguages(context);
- return languages;
+ this.parentId = parentId;
}
@Override
@@ -116,10 +117,50 @@ public int compareTo(StoriesChapterModel another) {
@Override
public String toString() {
- return "ChapterModel{" +
+ return "StoriesChapterModel{" +
"title='" + title + '\'' +
", description='" + description + '\'' +
", number='" + number + '\'' +
"} " + super.toString();
}
+
+ protected class StoriesChapterSideLoadedModel {
+
+ String number;
+ String title;
+ String description;
+
+ PageModel.PageSideLoadedModel[] pages;
+
+
+ public StoriesChapterSideLoadedModel(StoriesChapterModel chapter, Context context) {
+ this.number = chapter.number;
+ this.title = chapter.title;
+ this.description = chapter.description;
+
+ ArrayList pageList = chapter.getChildModels(context);
+ pages = new PageModel.PageSideLoadedModel[pageList.size()];
+
+ for(int i = 0; i < pageList.size(); i++){
+ pages[i] = pageList.get(i).getAsSideLoadedModel();
+ }
+
+ }
+ }
+
+ protected StoriesChapterSideLoadedModel getAsSideLoadedModel(Context context){
+
+ return new StoriesChapterSideLoadedModel(this, context);
+ }
+
+ public void initModelFromSideLoadedJson(String json){
+
+ StoriesChapterSideLoadedModel model = new Gson().fromJson(json, StoriesChapterSideLoadedModel.class);
+
+ number = model.number;
+ description = model.description;
+ title = model.title;
+
+ uid = -1;
+ }
}
\ No newline at end of file
diff --git a/app/app/src/main/java/model/modelClasses/mainData/VersionModel.java b/app/app/src/main/java/model/modelClasses/mainData/VersionModel.java
index 9ad9fed..fbf9c5e 100644
--- a/app/app/src/main/java/model/modelClasses/mainData/VersionModel.java
+++ b/app/app/src/main/java/model/modelClasses/mainData/VersionModel.java
@@ -1,20 +1,16 @@
package model.modelClasses.mainData;
import android.content.Context;
-import android.util.Log;
-import org.json.JSONException;
-import org.json.JSONObject;
+import com.google.gson.Gson;
import java.util.ArrayList;
import adapters.selectionAdapters.GeneralRowInterface;
-import model.database.ModelCaching;
-import model.datasource.BibleChapterDataSource;
import model.datasource.VersionDataSource;
-import model.database.DBManager;
import model.modelClasses.StatusModel;
-import model.modelClasses.mainData.AMDatabase.AMDatabaseModelAbstractObject;
+import model.modelClasses.AMDatabase.AMDatabaseModelAbstractObject;
+import signing.Status;
/**
* Created by Fechner on 1/22/15.
@@ -23,23 +19,65 @@ public class VersionModel extends AMDatabaseModelAbstractObject implements Gener
private static final String TAG = "ResourceModel";
+ public enum DOWNLOAD_STATE{
+ DOWNLOAD_STATE_ERROR(0),
+ DOWNLOAD_STATE_NONE(1),
+ DOWNLOAD_STATE_DOWNLOADING(2),
+ DOWNLOAD_STATE_DOWNLOADED(3);
+
+ DOWNLOAD_STATE(int i) {
+ }
+
+ public static DOWNLOAD_STATE createState(int value) {
+
+ switch (value) {
+ case 1:{
+ return DOWNLOAD_STATE_NONE;
+ }
+ case 2:{
+ return DOWNLOAD_STATE_DOWNLOADING;
+ }
+ case 3:{
+ return DOWNLOAD_STATE_DOWNLOADED;
+ }
+ default:{
+ return DOWNLOAD_STATE_ERROR;
+ }
+
+ }
+ }
+
+ }
+
+ private class VersionJsonModel {
+
+ long mod;
+ String name;
+ String slug;
+ StatusJsonModel status;
+ }
+
+ private class StatusJsonModel {
+
+ String checking_entity;
+ String checking_level;
+ String comments;
+ String contributors;
+ String publish_date;
+ String source_text;
+ String source_text_version;
+ String version;
+ }
+
private static final String DATE_MODIFIED_JSON_KEY = "date_modified";
private static final String NAME_JSON_KEY = "name";
private static final String SLUG_JSON_KEY = "slug";
- private static final String SOURCE_URL_JSON_KEY = "source";
- private static final String TERMS_URL_JSON_KEY = "terms";
- private static final String NOTES_URL_JSON_KEY = "notes";
- private static final String USFM_URL_JSON_KEY = "usfm";
private static final String STATUS_JSON_KEY = "status";
public String name;
public long dateModified;
- public String sourceUrl;
- public String termsUrl;
- public String notesUrl;
- public String usfmUrl;
-
public StatusModel status;
+ public DOWNLOAD_STATE downloadState;
private LanguageModel parent;
public LanguageModel getParent(Context context){
@@ -54,22 +92,16 @@ public void setParent(LanguageModel parent){
}
private ArrayList books = null;
- public ArrayList getStoriesChildModels(Context context){
+ public ArrayList getChildModels(Context context){
if(books == null){
books = this.getDataSource(context).getChildModels(this);
}
- return books;
- }
-
- private ArrayList chapters = null;
- public ArrayList getBibleChildModels(Context context){
- if(chapters == null){
- chapters = new BibleChapterDataSource(context).getChaptersForParentId(Long.toString(this.uid));
+ if(books.size() == 0){
+ books = null;
}
-
- return chapters;
+ return books;
}
public VersionModel() {
@@ -77,66 +109,64 @@ public VersionModel() {
this.status = new StatusModel();
}
- public VersionModel(JSONObject jsonObject) {
- super(jsonObject);
+ public VersionModel(String jsonObject, boolean sideLoaded) {
+ super(jsonObject, sideLoaded);
}
- public VersionModel(JSONObject jsonObject, AMDatabaseModelAbstractObject parent) {
- super(jsonObject, parent);
- }
-
- @Override
- public VersionDataSource getDataSource(Context context) {
- return new VersionDataSource(context);
+ public VersionModel(String jsonObject, long parentId, boolean sideLoaded) {
+ super(jsonObject, parentId, sideLoaded);
}
- public void initModelFromJsonObject(JSONObject jsonObj){
+ public BookModel findBookForJsonSlug(Context context, String slug){
- try {
+ for(BookModel model : this.getChildModels(context)){
- if (jsonObj.has(DATE_MODIFIED_JSON_KEY)) {
- dateModified = getDateFromString(jsonObj.getString(DATE_MODIFIED_JSON_KEY));
- }
- else{
- dateModified = -1;
- }
-
- slug = jsonObj.has(SLUG_JSON_KEY) ? jsonObj.getString(SLUG_JSON_KEY) : "";
- name = jsonObj.has(NAME_JSON_KEY) ? jsonObj.getString(NAME_JSON_KEY) : "";
- sourceUrl = jsonObj.has(SOURCE_URL_JSON_KEY) ? jsonObj.getString(SOURCE_URL_JSON_KEY) : "";
- termsUrl = jsonObj.has(TERMS_URL_JSON_KEY) ? jsonObj.getString(TERMS_URL_JSON_KEY) : "";
- notesUrl = jsonObj.has(NOTES_URL_JSON_KEY) ? jsonObj.getString(NOTES_URL_JSON_KEY) : "";
- usfmUrl = jsonObj.has(USFM_URL_JSON_KEY) ? jsonObj.getString(USFM_URL_JSON_KEY) : "";
-
- JSONObject statusJsonObject = jsonObj.getJSONObject(STATUS_JSON_KEY);
- StatusModel statMod = StatusModel.getStatusModelFromJsonObject(statusJsonObject, this);
+ if(model.slug.substring(0, 3).equalsIgnoreCase(slug.substring(0, 3))){
- status = (statMod != null)? statMod : null;
- }
- catch (JSONException e){
- Log.e(TAG, "LanguageModel JSON Exception: " + e.toString());
+ return model;
+ }
}
+ return null;
+ }
+
+ @Override
+ public VersionDataSource getDataSource(Context context) {
+ return new VersionDataSource(context);
}
- public ArrayList getAvailableLanguages(Context context) {
-
- ArrayList availLanguages = ModelCaching.getAvailableLanguages(context);
- ArrayList languages = new ArrayList();
-
- for(String language : availLanguages){
- if(getParent(context).getParent(context).containsLanguage(language, context) && !languages.contains(language)){
- languages.add(language.toLowerCase());
- }
- }
- return languages;
+ @Override
+ public void initModelFromJson(String json, boolean preLoaded){
+
+ VersionJsonModel model = new Gson().fromJson(json, VersionJsonModel.class);
+
+ name = model.name;
+ dateModified = model.mod;
+ slug = model.slug;
+
+ status = new StatusModel();
+ status.checkingEntity = model.status.checking_entity;
+ status.checkingLevel = model.status.checking_level;
+ status.comments = model.status.comments;
+ status.contributors = model.status.contributors;
+ status.publishDate = model.status.publish_date;
+ status.sourceText = model.status.source_text;
+ status.sourceTextVersion = model.status.source_text_version;
+ status.version = model.status.version;
+ uid = -1;
}
@Override
- public void initModelFromJsonObject(JSONObject jsonObject, AMDatabaseModelAbstractObject parent) {
- this.initModelFromJsonObject(jsonObject);
+ public void initModelFromJson(String json, long parentId, boolean sideLoaded) {
+ if(sideLoaded){
+ this.initModelFromSideLoadedJson(json);
+ }
+ else {
+ this.initModelFromJson(json, sideLoaded);
+// this.slug += ((LanguageModel) parent).slug;
+ }
- this.parentId = parent.uid;
- this.slug += ((LanguageModel) parent).slug;
+ this.parentId = parentId;
+ downloadState = DOWNLOAD_STATE.DOWNLOAD_STATE_NONE;
}
@Override
@@ -149,19 +179,120 @@ public String getChildIdentifier() {
return Long.toString(this.uid);
}
- @Override
+ public VersionModel save(Context context){
+ this.getDataSource(context).createOrUpdateDatabaseModel(this);
+ return this.getDataSource(context).getModel(Long.toString(this.uid));
+ }
+
+ public int getVerificationStatus(Context context){
+
+ int verifyStatus = 0;
+
+ if(this.getChildModels(context) == null){
+ return -1;
+ }
+
+ for(BookModel book : this.getChildModels(context)){
+ switch (book.verificationStatus){
+ case 0:{
+ break;
+ }
+ case 1:{
+ if(verifyStatus < 1){
+ verifyStatus = 1;
+ }
+ break;
+ }
+ case 3:{
+ if(verifyStatus < 3){
+ verifyStatus = 3;
+ }
+ break;
+ }
+ default:{
+ verifyStatus = 2;
+ break;
+ }
+ }
+ }
+ return verifyStatus;
+ }
+
public String toString() {
return "VersionModel{" +
", slug='" + slug + '\'' +
", name='" + name + '\'' +
", dateModified=" + dateModified +
- ", sourceUrl='" + sourceUrl + '\'' +
- ", termsUrl='" + termsUrl + '\'' +
- ", notesUrl='" + notesUrl + '\'' +
- ", usfmUrl='" + usfmUrl + '\'' +
", status=" + status.toString() +
", parent=" + parent +
", books=" + books +
+ status.toString() +
"} " + super.toString();
}
+
+ protected class VersionSideLoadedModel {
+
+ long date_modified;
+ String name;
+ String slug;
+
+ String checking_entity;
+ String checking_level;
+ String comments;
+ String contributors;
+ String publish_date;
+ String source_text;
+ String source_text_version;
+ String version;
+
+ BookModel.BookSideLoadedModel[] books;
+
+ private VersionSideLoadedModel(VersionModel model, Context context) {
+
+ this.date_modified = model.dateModified;
+ this.name = model.name;
+ this.slug = model.slug;
+ this.checking_entity = model.status.checkingEntity;
+ this.checking_level = model.status.checkingLevel;
+ this.comments = model.status.comments;
+ this.contributors = model.status.contributors;
+ this.publish_date = model.status.publishDate;
+ this.source_text = model.status.sourceText;
+ this.source_text_version = model.status.sourceTextVersion;
+ this.version = model.status.version;
+
+ ArrayList bookModels = model.getChildModels(context);
+ this.books = new BookModel.BookSideLoadedModel[bookModels.size()];
+
+ for(int i = 0; i < bookModels.size(); i++){
+ this.books[i] = bookModels.get(i).getAsSideLoadedModel(context);
+ }
+ }
+ }
+
+
+ protected VersionSideLoadedModel getAsSideLoadedModel(Context context){
+
+ return new VersionSideLoadedModel(this, context);
+ }
+
+ public void initModelFromSideLoadedJson(String json){
+
+ VersionSideLoadedModel model = new Gson().fromJson(json, VersionSideLoadedModel.class);
+
+ name = model.name;
+ dateModified = model.date_modified;
+ slug = model.slug;
+
+ status = new StatusModel();
+ status.checkingEntity = model.checking_entity;
+ status.checkingLevel = model.checking_level;
+ status.comments = model.comments;
+ status.contributors = model.contributors;
+ status.publishDate = model.publish_date;
+ status.sourceText = model.source_text;
+ status.sourceTextVersion = model.source_text_version;
+ status.version = model.version;
+ uid = -1;
+ }
}
diff --git a/app/app/src/main/java/services/UWSideLoader.java b/app/app/src/main/java/services/UWSideLoader.java
new file mode 100644
index 0000000..670f96b
--- /dev/null
+++ b/app/app/src/main/java/services/UWSideLoader.java
@@ -0,0 +1,102 @@
+package services;
+
+import android.app.Service;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.IBinder;
+import android.os.Looper;
+import android.os.Message;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+
+import java.io.IOException;
+
+import model.database.UWDataParser;
+
+/**
+ * Created by Fechner on 3/14/15.
+ */
+public class UWSideLoader extends Service {
+
+ private Looper mServiceLooper;
+ private ServiceHandler mServiceHandler;
+
+ private String json;
+ @Override
+ public IBinder onBind(Intent intent) {
+ return null;
+ }
+
+
+ @Override
+ public void onCreate() {
+ HandlerThread thread = new HandlerThread("ServiceStartArguments", 2);
+ thread.start();
+
+ // Get the HandlerThread's Looper and use it for our Handler
+ mServiceLooper = thread.getLooper();
+ mServiceHandler = new ServiceHandler(mServiceLooper);
+
+ super.onCreate();
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ try {
+ Bundle extra = intent.getExtras();
+ if (extra != null) {
+ String json = extra.getString("json");
+ this.json = json;
+ }
+ Message msg = mServiceHandler.obtainMessage();
+ msg.arg1 = startId;
+ mServiceHandler.sendMessage(msg);
+ } catch (Exception e) {
+
+ }
+ return START_STICKY;
+ }
+
+ private final class ServiceHandler extends Handler {
+ public ServiceHandler(Looper looper) {
+ super(looper);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+
+ try {
+ JSONArray jsonArray = new JSONArray(json);
+
+ UWDataParser.getInstance(getApplicationContext()).updateProjects(jsonArray, true);
+
+ }
+ catch (JSONException e){
+ e.printStackTrace();
+ }
+ catch (IOException e){
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private void addContentToDatabase(String content){
+
+ try {
+ JSONArray jsonArray = new JSONArray(content);
+
+ UWDataParser.getInstance(getApplicationContext()).updateProjects(jsonArray, true);
+ }
+ catch (JSONException e){
+ e.printStackTrace();
+ }
+ catch (IOException e){
+ e.printStackTrace();
+ }
+ }
+
+
+}
diff --git a/app/app/src/main/java/services/UpdateService.java b/app/app/src/main/java/services/UpdateService.java
index a19b435..073ccf9 100644
--- a/app/app/src/main/java/services/UpdateService.java
+++ b/app/app/src/main/java/services/UpdateService.java
@@ -1,7 +1,6 @@
package services;
import android.app.Service;
-import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
@@ -11,37 +10,22 @@
import android.os.Looper;
import android.os.Message;
import android.preference.PreferenceManager;
-import android.util.Log;
-import org.json.JSONArray;
import org.json.JSONException;
-import org.json.JSONObject;
import org.unfoldingword.mobile.R;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;
-import model.datasource.BibleChapterDataSource;
-import model.datasource.BookDataSource;
-import model.datasource.StoriesChapterDataSource;
-import model.datasource.LanguageDataSource;
-import model.datasource.PageDataSource;
-import model.datasource.ProjectDataSource;
-import model.datasource.VersionDataSource;
import model.database.DBManager;
import model.database.ImageDatabaseHandler;
-import model.modelClasses.mainData.BibleChapterModel;
+import model.database.UWDataParser;
import model.modelClasses.mainData.BookModel;
-import model.modelClasses.mainData.StoriesChapterModel;
-import model.modelClasses.mainData.LanguageModel;
import model.modelClasses.mainData.PageModel;
-import model.modelClasses.mainData.ProjectModel;
-import model.modelClasses.mainData.VersionModel;
+import model.modelClasses.mainData.StoriesChapterModel;
import utils.AsyncImageLoader;
-import utils.URLDownloadUtil;
import utils.URLUtils;
-import utils.USFMParser;
/**
* Created by Acts Media Inc on 11/12/14.
@@ -71,7 +55,7 @@ public IBinder onBind(Intent intent) {
public void onCreate() {
dbManager = DBManager.getInstance(getApplicationContext());
serviceState = true;
- HandlerThread thread = new HandlerThread("ServiceStartArguments", 1);
+ HandlerThread thread = new HandlerThread("UpdateServiceThread", 1);
thread.start();
// Get the HandlerThread's Looper and use it for our Handler
@@ -116,7 +100,8 @@ public void handleMessage(Message msg) {
// Get current list of languages
try {
hasUpdatedImages = false;
- updateProjects(false);
+ String url = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("base_url", getResources().getString(R.string.pref_default_base_url));
+ UWDataParser.getInstance(getApplicationContext()).updateProjects(url, false);
} catch (IOException e) {
e.printStackTrace();
@@ -130,221 +115,218 @@ public void handleMessage(Message msg) {
}
}
- private void updateProjects(boolean forceUpdate) throws JSONException, IOException{
-
-// Log.i(TAG, " Updating Projects");
- String url = PreferenceManager.getDefaultSharedPreferences(this).getString("base_url", getResources().getString(R.string.pref_default_base_url));
- String json = URLDownloadUtil.downloadJson(url);
-
- JSONArray jsonArray = new JSONArray(json);
- ProjectDataSource dataSource = new ProjectDataSource(this.getApplicationContext());
-
- if(jsonArray.length() > 0) {
-
- // Iterate through the current Models
- for (int i = 0; i < jsonArray.length(); i++) {
-
- ProjectModel newModel = new ProjectModel(jsonArray.getJSONObject(i));
- ProjectModel currentModel = dataSource.getModelForSlug(newModel.slug);
-
- if(currentModel != null) {
- newModel.uid = currentModel.uid;
- }
-
- if (currentModel == null || (currentModel.dateModified < newModel.dateModified) || forceUpdate) {
- dataSource.saveModel(newModel);
- updateLanguages(dataSource.getModelForSlug(newModel.slug), forceUpdate);
- }
- }
- }
- }
-
- private void updateLanguages(ProjectModel parent, boolean forceUpdate) throws JSONException, IOException{
-
-// Log.i(TAG, " Updating Languages");
- String json = URLDownloadUtil.downloadJson(parent.languageUrl);
-
- JSONArray jsonArray = new JSONArray(json);
- LanguageDataSource dataSource = new LanguageDataSource(this.getApplicationContext());
-
- if(jsonArray.length() > 0) {
-
- // Iterate through the current Models
- for (int i = 0; i < jsonArray.length(); i++) {
-
- LanguageModel newModel = new LanguageModel(jsonArray.getJSONObject(i), parent);
- LanguageModel currentModel = dataSource.getModelForSlug(newModel.slug);
-
- if(currentModel != null) {
- newModel.uid = currentModel.uid;
- }
-
- if (currentModel == null || (currentModel.dateModified < newModel.dateModified) || forceUpdate) {
- dataSource.saveModel(newModel);
- updateVersions(dataSource.getModelForSlug(newModel.slug), forceUpdate);
- }
- }
- }
- }
-
- private void updateVersions(LanguageModel parent, boolean forceUpdate) throws JSONException, IOException{
-
-// Log.i(TAG, " Updating Versions");
- String json = URLDownloadUtil.downloadJson(parent.resourceUrl);
-
- JSONArray jsonArray = new JSONArray(json);
- VersionDataSource dataSource = new VersionDataSource(this.getApplicationContext());
-
- if(jsonArray.length() > 0) {
-
- // Iterate through the current Models
- for (int i = 0; i < jsonArray.length(); i++) {
-
- VersionModel newModel = new VersionModel(jsonArray.getJSONObject(i), parent);
- VersionModel currentModel = dataSource.getModelForSlug(newModel.slug);
-
- if(currentModel != null) {
- newModel.uid = currentModel.uid;
- }
-
- if (currentModel == null || (currentModel.dateModified < newModel.dateModified) || forceUpdate) {
-
- dataSource.saveModel(newModel);
-
- if(newModel.usfmUrl.length() > 1){
- this.parseUSFMForVersion(dataSource.getModelForSlug(newModel.slug));
- }
- else {
- updateBooks(dataSource.getModelForSlug(newModel.slug), forceUpdate);
- }
- }
- }
- }
- }
-
- private void parseUSFMForVersion(VersionModel version) throws IOException{
-
-// Log.i(TAG, " parsing usfm");
-
- byte[] usfmText = URLDownloadUtil.downloadUsfm(version.usfmUrl);
-
- Map usfmMap = USFMParser.parseUsfm(usfmText);
-
- ArrayList chapters = version.getBibleChildModels(getApplicationContext());
-
- Context context = getApplicationContext();
- for (Map.Entry entry : usfmMap.entrySet()){
- BibleChapterModel chapter = new BibleChapterModel();
- chapter.parentId = version.uid;
- chapter.number = entry.getKey();
- chapter.text = entry.getValue();
-
- for(BibleChapterModel oldChapter : chapters){
- if(Long.parseLong(oldChapter.number.replaceAll("[^0-9]", "")) == Long.parseLong(chapter.number.replaceAll("[^0-9]", ""))){
- chapter.uid = oldChapter.uid;
- }
- }
-
- new BibleChapterDataSource(context).saveModel(chapter);
- }
- }
-
-
- private void updateBooks(VersionModel parent, boolean forceUpdate) throws JSONException, IOException{
-
-// Log.i(TAG, " Updating Books");
-
- String json = URLDownloadUtil.downloadJson(parent.sourceUrl);
-
- JSONObject jsonObject = new JSONObject(json);
- BookDataSource dataSource = new BookDataSource(this.getApplicationContext());
-
- BookModel newModel = new BookModel(jsonObject, parent);
- BookModel currentModel = dataSource.getModelForLanguage(newModel.language);
-
- if(currentModel != null) {
- newModel.uid = currentModel.uid;
- }
-
- if (currentModel == null || (currentModel.dateModified < newModel.dateModified) || forceUpdate) {
-
-
-
- dataSource.saveModel(newModel);
- updateStoryChapters(dataSource.getModelForSlug(newModel.slug) , jsonObject.getJSONArray("chapters"));
-
- hasUpdatedImages = true;
- }
- }
-
- private void updateStoryChapters(BookModel parent, JSONArray jsonArray) throws JSONException, IOException{
-
-// Log.i(TAG, " Updating Chapters");
-
-
- StoriesChapterDataSource dataSource = new StoriesChapterDataSource(this.getApplicationContext());
-
-// // Iterate through the current Models
- for (int i = 0; i < jsonArray.length(); i++) {
-
- JSONObject jsonObject = jsonArray.getJSONObject(i);
-
- StoriesChapterModel newModel = new StoriesChapterModel(jsonObject, parent);
- StoriesChapterModel currentModel = dataSource.getModelForSlug(newModel.slug);
-
- if(currentModel != null) {
- newModel.uid = currentModel.uid;
- }
-
- dataSource.saveModel(newModel);
- updateStoryPage(dataSource.getModelForSlug(newModel.slug), jsonObject.getJSONArray("frames"));
- }
- }
-
- private void updateStoryPage(StoriesChapterModel parent, JSONArray jsonArray) throws JSONException, IOException{
-
-// Log.i(TAG, " Updating Page");
-
-
- PageDataSource dataSource = new PageDataSource(this.getApplicationContext());
-
-// // Iterate through the current Models
- for (int i = 0; i < jsonArray.length(); i++) {
-
- PageModel newModel = new PageModel(jsonArray.getJSONObject(i), parent);
- PageModel currentModel = dataSource.getModelForSlug(newModel.slug);
-
- if(currentModel != null) {
- newModel.uid = currentModel.uid;
- }
-
- if(!hasUpdatedImages){
- updateImageForPages(currentModel, newModel );
- }
-
-
- dataSource.saveModel(newModel);
- }
-}
-
- private void updateImages(BookModel currentBook, BookModel newBook){
+// private void updateProjects(boolean forceUpdate) throws JSONException, IOException{
+//
+//// Log.i(TAG, " Updating Projects");
+// String url = PreferenceManager.getDefaultSharedPreferences(this).getString("base_url", getResources().getString(R.string.pref_default_base_url));
+// String json = URLDownloadUtil.downloadJson(url);
+//
+// JSONArray jsonArray = new JSONArray(json);
+// ProjectDataSource dataSource = new ProjectDataSource(this.getApplicationContext());
+//
+// if(jsonArray.length() > 0) {
+//
+// // Iterate through the current Models
+// for (int i = 0; i < jsonArray.length(); i++) {
+//
+// ProjectModel newModel = new ProjectModel(jsonArray.getJSONObject(i));
+// ProjectModel currentModel = dataSource.getModelForSlug(newModel.slug);
+//
+// if(currentModel != null) {
+// newModel.uid = currentModel.uid;
+// }
+//
+// if (currentModel == null || (currentModel.dateModified < newModel.dateModified) || forceUpdate) {
+// dataSource.saveModel(newModel);
+// updateLanguages(dataSource.getModelForSlug(newModel.slug), forceUpdate);
+// }
+// }
+// }
+// }
+//
+// private void updateLanguages(ProjectModel parent, boolean forceUpdate) throws JSONException, IOException{
+//
+//// Log.i(TAG, " Updating Languages");
+// String json = URLDownloadUtil.downloadJson(parent.languageUrl);
+//
+// JSONArray jsonArray = new JSONArray(json);
+// LanguageDataSource dataSource = new LanguageDataSource(this.getApplicationContext());
+//
+// if(jsonArray.length() > 0) {
+//
+// // Iterate through the current Models
+// for (int i = 0; i < jsonArray.length(); i++) {
+//
+// LanguageModel newModel = new LanguageModel(jsonArray.getJSONObject(i), parent);
+// LanguageModel currentModel = dataSource.getModelForSlug(newModel.slug);
+//
+// if(currentModel != null) {
+// newModel.uid = currentModel.uid;
+// }
+//
+// if (currentModel == null || (currentModel.dateModified < newModel.dateModified) || forceUpdate) {
+// dataSource.saveModel(newModel);
+// updateVersions(dataSource.getModelForSlug(newModel.slug), forceUpdate);
+// }
+// }
+// }
+// }
+//
+// private void updateVersions(LanguageModel parent, boolean forceUpdate) throws JSONException, IOException{
+//
+//// Log.i(TAG, " Updating Versions");
+// String json = URLDownloadUtil.downloadJson(parent.resourceUrl);
+//
+// JSONArray jsonArray = new JSONArray(json);
+// VersionDataSource dataSource = new VersionDataSource(this.getApplicationContext());
+//
+// if(jsonArray.length() > 0) {
+//
+// // Iterate through the current Models
+// for (int i = 0; i < jsonArray.length(); i++) {
+//
+// VersionModel newModel = new VersionModel(jsonArray.getJSONObject(i), parent);
+// VersionModel currentModel = dataSource.getModelForSlug(newModel.slug);
+//
+// if(currentModel != null) {
+// newModel.uid = currentModel.uid;
+// }
+//
+// if (currentModel == null || (currentModel.dateModified < newModel.dateModified) || forceUpdate) {
+//
+// dataSource.saveModel(newModel);
+//
+// if(newModel.usfmUrl.length() > 1){
+// this.parseUSFMForVersion(dataSource.getModelForSlug(newModel.slug));
+// }
+// else {
+// updateBooks(dataSource.getModelForSlug(newModel.slug), forceUpdate);
+// }
+// }
+// }
+// }
+// }
+//
+// private void parseUSFMForVersion(VersionModel version) throws IOException{
+//
+//// Log.i(TAG, " parsing usfm");
+//
+// byte[] usfmText = URLDownloadUtil.downloadUsfm(version.usfmUrl);
+//
+// Map usfmMap = USFMParser.parseUsfm(usfmText);
+//
+// ArrayList chapters = version.getBibleChildModels(getApplicationContext());
+//
+// Context context = getApplicationContext();
+// for (Map.Entry entry : usfmMap.entrySet()){
+// BibleChapterModel chapter = new BibleChapterModel();
+// chapter.parentId = version.uid;
+// chapter.number = entry.getKey();
+// chapter.text = entry.getValue();
+//
+// for(BibleChapterModel oldChapter : chapters){
+// if(Long.parseLong(oldChapter.number.replaceAll("[^0-9]", "")) == Long.parseLong(chapter.number.replaceAll("[^0-9]", ""))){
+// chapter.uid = oldChapter.uid;
+// }
+// }
+//
+// new BibleChapterDataSource(context).saveModel(chapter);
+// }
+// }
+//
+//
+// private void updateBooks(VersionModel parent, boolean forceUpdate) throws JSONException, IOException{
+//
+//// Log.i(TAG, " Updating Books");
+//
+// String json = URLDownloadUtil.downloadJson(parent.sourceUrl);
+//
+// JSONObject jsonObject = new JSONObject(json);
+// BookDataSource dataSource = new BookDataSource(this.getApplicationContext());
+//
+// BookModel newModel = new BookModel(jsonObject, parent);
+// BookModel currentModel = dataSource.getModelForLanguage(newModel.language);
+//
+// if(currentModel != null) {
+// newModel.uid = currentModel.uid;
+// }
+//
+// if (currentModel == null || (currentModel.dateModified < newModel.dateModified) || forceUpdate) {
+//
+// dataSource.saveModel(newModel);
+// updateStoryChapters(dataSource.getModelForSlug(newModel.slug) , jsonObject.getJSONArray("chapters"));
+//
+// hasUpdatedImages = true;
+// }
+// }
+//
+// private void updateStoryChapters(BookModel parent, JSONArray jsonArray) throws JSONException, IOException{
+//
+//// Log.i(TAG, " Updating Chapters");
+//
+//
+// StoriesChapterDataSource dataSource = new StoriesChapterDataSource(this.getApplicationContext());
+//
+//// // Iterate through the current Models
+// for (int i = 0; i < jsonArray.length(); i++) {
+//
+// JSONObject jsonObject = jsonArray.getJSONObject(i);
+//
+// StoriesChapterModel newModel = new StoriesChapterModel(jsonObject, parent);
+// StoriesChapterModel currentModel = dataSource.getModelForSlug(newModel.slug);
+//
+// if(currentModel != null) {
+// newModel.uid = currentModel.uid;
+// }
+//
+// dataSource.saveModel(newModel);
+// updateStoryPage(dataSource.getModelForSlug(newModel.slug), jsonObject.getJSONArray("frames"));
+// }
+// }
+//
+// private void updateStoryPage(StoriesChapterModel parent, JSONArray jsonArray) throws JSONException, IOException{
+//
+//// Log.i(TAG, " Updating Page");
+//
+//
+// PageDataSource dataSource = new PageDataSource(this.getApplicationContext());
+//
+//// // Iterate through the current Models
+// for (int i = 0; i < jsonArray.length(); i++) {
+//
+// PageModel newModel = new PageModel(jsonArray.getJSONObject(i), parent);
+// PageModel currentModel = dataSource.getModelForSlug(newModel.slug);
+//
+// if(currentModel != null) {
+// newModel.uid = currentModel.uid;
+// }
+//
+// if(!hasUpdatedImages){
+// updateImageForPages(currentModel, newModel );
+// }
+//
+//
+// dataSource.saveModel(newModel);
+// }
+//}
+
+ private void updateImages(ArrayList currentChapters, ArrayList newChapters){
// Log.i(TAG, " Updating Images");
- if(currentBook == null || newBook == null){
+ if(currentChapters == null || newChapters == null){
return;
}
// Log.i(TAG, " Updating Images");
- Map currentPages = currentBook.getPages(this.getApplicationContext());
- Map newPages = newBook.getPages(this.getApplicationContext());
-
- for (Map.Entry entry : currentPages.entrySet()){
-
- updateImageForPages(entry.getValue(), newPages.get(entry.getKey()));
- }
+// Map currentPages = currentBook.getPages(this.getApplicationContext());
+// Map newPages = newBook.getPages(this.getApplicationContext());
+//
+// for (Map.Entry entry : currentPages.entrySet()){
+//
+// updateImageForPages(entry.getValue(), newPages.get(entry.getKey()));
+// }
}
-
/**
* Compares the page's image url to what currently exists in the DB and updates if necessary
* @param newModel
diff --git a/app/app/src/main/java/services/VersionDownloadService.java b/app/app/src/main/java/services/VersionDownloadService.java
new file mode 100644
index 0000000..a79783c
--- /dev/null
+++ b/app/app/src/main/java/services/VersionDownloadService.java
@@ -0,0 +1,119 @@
+package services;
+
+import android.app.Service;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.HandlerThread;
+import android.os.IBinder;
+import android.os.Looper;
+import android.os.Message;
+
+import org.json.JSONException;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+import model.database.UWDataParser;
+import model.datasource.VersionDataSource;
+import model.modelClasses.mainData.BookModel;
+import model.modelClasses.mainData.VersionModel;
+import signing.Status;
+import signing.UWSigning;
+import utils.URLUtils;
+
+/**
+ * Created by Acts Media Inc on 11/12/14.
+ */
+public class VersionDownloadService extends Service{
+
+ private static final String TAG = "UpdateService";
+
+ public static final String VERSION_ID = "VERSION_ID";
+
+ public static final int STATUS_RUNNING = 0;
+ public static final int STATUS_FINISHED = 1;
+ public static final int STATUS_ERROR = 2;
+ private Looper mServiceLooper;
+ private ServiceHandler mServiceHandler;
+
+ String versionId;
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return null;
+ }
+
+ @Override
+ public void onCreate() {
+ HandlerThread thread = new HandlerThread("VersionDownloadThread", 1);
+ thread.start();
+
+ // Get the HandlerThread's Looper and use it for our Handler
+ mServiceLooper = thread.getLooper();
+ mServiceHandler = new ServiceHandler(mServiceLooper);
+
+ super.onCreate();
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ try {
+ Bundle extra = intent.getExtras();
+ if (extra != null) {
+ String itemId = extra.getString(VERSION_ID);
+ this.versionId = itemId;
+ }
+ Message msg = mServiceHandler.obtainMessage();
+ msg.arg1 = startId;
+ mServiceHandler.sendMessage(msg);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return START_STICKY;
+ }
+
+ @Override
+ public void onDestroy() {
+
+ super.onDestroy();
+ }
+
+ private final class ServiceHandler extends Handler {
+ public ServiceHandler(Looper looper) {
+ super(looper);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+
+ // Get current list of languages
+ try {
+ VersionModel desiredVersion = new VersionDataSource(getApplicationContext()).getModel(versionId);
+
+ ArrayList books = desiredVersion.getChildModels(getApplicationContext());
+
+ for(BookModel book : books){
+
+ if(book.sourceUrl.contains("usfm")){
+ UWDataParser.getInstance(getApplicationContext()).parseUSFMForBook(book);
+ }
+ else{
+ UWDataParser.getInstance(getApplicationContext()).updateStoryChapters(book, false);
+ }
+ }
+ desiredVersion.downloadState = VersionModel.DOWNLOAD_STATE.DOWNLOAD_STATE_DOWNLOADED;
+ desiredVersion.getDataSource(getApplicationContext()).createOrUpdateDatabaseModel(desiredVersion);
+ }
+ catch (IOException e) {
+ e.printStackTrace();
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+
+// if (onComplete)
+ getApplicationContext().sendBroadcast(new Intent(URLUtils.VERSION_BROADCAST_DOWN_COMP).putExtra(VERSION_ID, versionId));
+
+ }
+ }
+}
diff --git a/app/app/src/main/java/signing/Organization.java b/app/app/src/main/java/signing/Organization.java
new file mode 100644
index 0000000..46beddc
--- /dev/null
+++ b/app/app/src/main/java/signing/Organization.java
@@ -0,0 +1,61 @@
+package signing;
+
+import org.json.JSONObject;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * Created by joel on 2/23/2015.
+ */
+public class Organization {
+
+ public final Date createdAt;
+ public final String email;
+ public final Date expiresAt;
+ public final Date modifiedAt;
+ public final String name;
+ public final String slug;
+ public final String url;
+
+ /**
+ * Creates a new organization instance
+ * @param createdAt
+ * @param email
+ * @param expiresAt
+ * @param modifiedAt
+ * @param name
+ * @param slug
+ * @param url
+ */
+ public Organization(Date createdAt, String email, Date expiresAt, Date modifiedAt, String name, String slug, String url) {
+ this.createdAt = createdAt;
+ this.email = email;
+ this.expiresAt = expiresAt;
+ this.modifiedAt = modifiedAt;
+ this.name = name;
+ this.slug = slug;
+ this.url = url;
+ }
+
+ @Override
+ public String toString() {
+ return name+" <"+slug+">\n"+"email: "+email+"\nurl: "+url+"\ncreated: "+createdAt+"\nmodified: "+modifiedAt+"\nexpires: "+expiresAt;
+ }
+
+ /**
+ * Generates a new organization instance from a json string
+ * @param orgJsonString the organization information
+ * @return
+ */
+ public static Organization generate(String orgJsonString) {
+ try {
+ JSONObject json = new JSONObject(orgJsonString);
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+ return new Organization(format.parse(json.getString("created")), json.getString("email"), format.parse(json.getString("expires")), format.parse(json.getString("modified")), json.getString("org"), json.getString("slug"), json.getString("web"));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+}
diff --git a/app/app/src/main/java/signing/SigningEntity.java b/app/app/src/main/java/signing/SigningEntity.java
new file mode 100644
index 0000000..65791a0
--- /dev/null
+++ b/app/app/src/main/java/signing/SigningEntity.java
@@ -0,0 +1,172 @@
+package signing;
+
+import android.util.Base64;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.security.PublicKey;
+import java.util.Date;
+
+/**
+ * A Signing Identity represents an organization that has been registered to sign content.
+ *
+ */
+public class SigningEntity {
+ private final PublicKey mCAPublicKey;
+ private final PublicKey mPublicKey;
+ public final Organization organization;
+ private final byte[] mData;
+ private final byte[] mSignature;
+ private Status mStatus;
+
+
+
+ /**
+ * Creates a new Signing Entity
+ * @param caPublicKey The Certificate Authority's public key
+ * @param publicKey The Signing Entity's public key
+ * @param organization The entity's organization info
+ * @param keyOrgData The concated public key and organization data
+ * @param keyOrgSig The signature of the entity's concated public key and organization
+ */
+ public SigningEntity(PublicKey caPublicKey, PublicKey publicKey, Organization organization, byte[] keyOrgData, byte[] keyOrgSig) {
+ mCAPublicKey = caPublicKey;
+ mPublicKey = publicKey;
+ mSignature = keyOrgSig;
+ // this techncially duplicates the key and org data, but we pass it along so we don't convert everything to bytes again
+ // and possibly introduce additional points of error
+ mData = keyOrgData;
+ this.organization = organization;
+ }
+
+ /**
+ * Checks the validation status of this Signing Entity
+ * @return
+ */
+ public Status status() {
+ if(mStatus == null) {
+ mStatus = Crypto.verifyECDSASignature(mCAPublicKey, mSignature, mData);
+ if(mStatus == Status.VERIFIED) {
+ // check if expired
+ if(new Date().after(organization.expiresAt)) {
+ mStatus = Status.EXPIRED;
+ }
+ }
+ }
+ return mStatus;
+ }
+
+ /**
+ * Checks the validation status of the signed content.
+ * @param signature The signature of hte data as signed by the Se
+ * @param data The data that will be validated against the signature (the source translation)
+ * @return
+ */
+ public Status verifyContent(String signature, byte[] data) {
+ byte[] sig = Base64.decode(signature, Base64.NO_WRAP);
+ Status contentStatus = verifyContent(sig, data);
+
+ // always return the most severe status
+ if(contentStatus.weight() > status().weight()) {
+ return contentStatus;
+ } else {
+ return status();
+ }
+ }
+
+ /**
+ * Checks the validation status of the signed content.
+ * @param signature The signature of the data as signed by the SE
+ * @param data The data that will be validated against the signature (the source translation)
+ * @return
+ */
+ public Status verifyContent(byte[] signature, byte[] data) {
+ Status contentStatus = Crypto.verifyECDSASignature(mPublicKey, signature, data);
+
+ // always return the most severe status
+ if(contentStatus.weight() > status().weight()) {
+ return contentStatus;
+ } else {
+ return status();
+ }
+ }
+
+ /**
+ * Generates a new signing entity from the signing identity
+ * @param caPublicKey The The Certificate Authority's public key
+ * @param signingIdentity An input stream to the Signing Identity
+ * @return
+ */
+ public static SigningEntity generateFromIdentity(PublicKey caPublicKey, InputStream signingIdentity) {
+ BufferedReader br = new BufferedReader(new InputStreamReader(signingIdentity));
+ StringBuilder pkBuilder = new StringBuilder();
+ StringBuilder orgBuilder = new StringBuilder();
+ StringBuilder sigBuilder = new StringBuilder();
+ StringBuilder dataBuilder = new StringBuilder();
+
+ // read Signing Identity
+ try {
+ String section = null;
+ String line;
+ while((line = br.readLine()) != null) {
+ if(line.startsWith("-----")) {
+ // start/end section
+ section = line;
+ } else if(!line.trim().isEmpty()){
+ // build sections
+ if(section.equals("-----BEGIN PUBLIC KEY-----")) {
+ pkBuilder.append(line.trim());
+ } else if(section.equals("-----BEGIN ORG INFO-----")) {
+ orgBuilder.append(line.trim());
+ } else if(section.equals("-----BEGIN SIG-----")) {
+ sigBuilder.append(line.trim());
+ }
+ }
+
+ // store everything but the signature for verification
+ if(!section.equals("-----BEGIN SIG-----") && !section.equals("-----END SIG-----")) {
+ // TRICKY: we intentionally close with a trailing new line
+ dataBuilder.append(line + "\n");
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ }
+
+ // Assemble Signing Entity
+ if(dataBuilder.length() > 0 && pkBuilder.length() > 0 && orgBuilder.length() > 0 && sigBuilder.length() > 0) {
+ byte[] keyOrgData;
+ try {
+ keyOrgData = dataBuilder.toString().getBytes("UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ return null;
+ }
+ byte[] keyBytes;
+ try {
+ keyBytes = Base64.decode(pkBuilder.toString().getBytes("UTF-8"), Base64.DEFAULT);
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ return null;
+ }
+ PublicKey key = Crypto.loadPublicECDSAKey(keyBytes);
+ byte[] signature = Base64.decode(sigBuilder.toString(), Base64.NO_WRAP);
+ String orgJsonString;
+ try {
+ orgJsonString = new String(Base64.decode(orgBuilder.toString(), Base64.NO_WRAP));
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ Organization org = Organization.generate(orgJsonString);
+ if(org != null) {
+ return new SigningEntity(caPublicKey, key, org, keyOrgData, signature);
+ }
+ }
+ return null;
+ }
+}
diff --git a/app/app/src/main/java/signing/UWSigning.java b/app/app/src/main/java/signing/UWSigning.java
new file mode 100644
index 0000000..e7091da
--- /dev/null
+++ b/app/app/src/main/java/signing/UWSigning.java
@@ -0,0 +1,51 @@
+package signing;
+
+import android.content.Context;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.PublicKey;
+
+import utils.URLDownloadUtil;
+
+/**
+ * Created by Fechner on 3/13/15.
+ */
+public class UWSigning {
+
+ private static final String signatureJsonKey = "sig";
+ private static final String signingEntityUrl = "https://pki.unfoldingword.org/uW-vk.pem";
+
+ public static Status getStatusForSigUrl(Context context, String url, byte[] signingData) throws IOException, JSONException{
+
+ InputStream uwKeyFile = context.getAssets().open("certs/ca.pub");
+ PublicKey uwPublicKey = Crypto.loadPublicECDSAKey(uwKeyFile);
+
+ byte[] keyData = URLDownloadUtil.downloadBytes(signingEntityUrl);
+ InputStream signingStream = new ByteArrayInputStream(keyData);
+ SigningEntity signingEntity = SigningEntity.generateFromIdentity(uwPublicKey, signingStream);
+
+ String sigData = URLDownloadUtil.downloadString(url);
+
+ try {
+
+ JSONArray sigArray = new JSONArray(sigData);
+ JSONObject sigObj = sigArray.getJSONObject(0);
+ String sig = sigObj.getString(signatureJsonKey);
+
+
+ Status sigStatus = signingEntity.verifyContent(sig, signingData);
+ return sigStatus;
+ }
+ catch (JSONException e){
+ e.printStackTrace();
+ return null;
+ }
+
+ }
+}
diff --git a/app/app/src/main/java/utils/AsyncImageLoader.java b/app/app/src/main/java/utils/AsyncImageLoader.java
index 7d11724..6526d34 100755
--- a/app/app/src/main/java/utils/AsyncImageLoader.java
+++ b/app/app/src/main/java/utils/AsyncImageLoader.java
@@ -1,6 +1,10 @@
package utils;
-import java.io.InputStream;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.os.AsyncTask;
+import android.os.SystemClock;
+
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
@@ -10,10 +14,7 @@
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.os.AsyncTask;
-import android.os.SystemClock;
+import java.io.InputStream;
public class AsyncImageLoader extends AsyncTask {
diff --git a/app/app/src/main/java/utils/SSLErrorPreventer.java b/app/app/src/main/java/utils/SSLErrorPreventer.java
index bb9673c..cbd3d78 100755
--- a/app/app/src/main/java/utils/SSLErrorPreventer.java
+++ b/app/app/src/main/java/utils/SSLErrorPreventer.java
@@ -1,6 +1,13 @@
package utils;
+import org.apache.http.client.HttpClient;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.impl.client.DefaultHttpClient;
+
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
@@ -16,13 +23,6 @@
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
-import org.apache.http.client.HttpClient;
-import org.apache.http.conn.ClientConnectionManager;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.ssl.SSLSocketFactory;
-import org.apache.http.impl.client.DefaultHttpClient;
-
/**
diff --git a/app/app/src/main/java/utils/URLDownloadUtil.java b/app/app/src/main/java/utils/URLDownloadUtil.java
index 5068884..4aa16bc 100644
--- a/app/app/src/main/java/utils/URLDownloadUtil.java
+++ b/app/app/src/main/java/utils/URLDownloadUtil.java
@@ -43,14 +43,14 @@ static public HttpResponse downloadUrl(String url) throws IOException {
* @param url
* @return
*/
- public static String downloadJson(String url) throws IOException {
+ public static String downloadString(String url) throws IOException {
HttpResponse response = downloadUrl(url);
return EntityUtils.toString(response.getEntity());
}
- public static byte[] downloadUsfm(String url) throws IOException {
+ public static byte[] downloadBytes(String url) throws IOException {
HttpResponse response = downloadUrl(url);
diff --git a/app/app/src/main/java/utils/URLUtils.java b/app/app/src/main/java/utils/URLUtils.java
index a6207e7..58f15f5 100644
--- a/app/app/src/main/java/utils/URLUtils.java
+++ b/app/app/src/main/java/utils/URLUtils.java
@@ -8,5 +8,8 @@ public class URLUtils {
public static final String BROAD_CAST_DOWN_COMP = "org.unfoldingword.mobile.DOWNLOAD_COMPLETED";
public static final String BROAD_CAST_DOWN_ERROR = "org.unfoldingword.mobile.DOWNLOAD_WHILE_ERROR";
+ public static final String VERSION_BROADCAST_DOWN_COMP = "org.unfoldingword.mobile.VERSION_DOWNLOAD_COMPLETED";
+ public static final String VERSION_BROADCAST_DOWN_ERROR = "org.unfoldingword.mobile.VERSION_DOWNLOAD_WHILE_ERROR";
+
}
diff --git a/app/app/src/main/java/utils/UWPreferenceManager.java b/app/app/src/main/java/utils/UWPreferenceManager.java
new file mode 100644
index 0000000..4f90f02
--- /dev/null
+++ b/app/app/src/main/java/utils/UWPreferenceManager.java
@@ -0,0 +1,46 @@
+package utils;
+
+import android.content.Context;
+
+/**
+ * Created by Fechner on 3/25/15.
+ */
+public class UWPreferenceManager {
+
+ private static final String STORY_VERSION_ID = "selected_story_version_id";
+ public static String getSelectedStoryVersion(Context context){
+ return Long.toString(android.preference.PreferenceManager.getDefaultSharedPreferences(context).getLong(STORY_VERSION_ID, -1));
+ }
+ public static void setSelectedStoryVersion(Context context, long newValue){
+
+ android.preference.PreferenceManager.getDefaultSharedPreferences(context).edit().putLong(STORY_VERSION_ID, newValue).commit();
+ }
+
+ private static final String BIBLE_VERSION_ID = "selected_bible_version_id";
+ public static String getSelectedBibleVersion(Context context){
+ return Long.toString(android.preference.PreferenceManager.getDefaultSharedPreferences(context).getLong(BIBLE_VERSION_ID, -1));
+ }
+ public static void setSelectedBibleVersion(Context context, long newValue){
+
+ android.preference.PreferenceManager.getDefaultSharedPreferences(context).edit().putLong(BIBLE_VERSION_ID, newValue).commit();
+ }
+
+ private static final String BIBLE_CHAPTER_ID = "selected_bible_chapter_id";
+ public static String getSelectedBibleChapter(Context context){
+ return Long.toString(android.preference.PreferenceManager.getDefaultSharedPreferences(context).getLong(BIBLE_CHAPTER_ID, -1));
+ }
+ public static void setSelectedBibleChapter(Context context, long newValue){
+
+ android.preference.PreferenceManager.getDefaultSharedPreferences(context).edit().putLong(BIBLE_CHAPTER_ID, newValue).commit();
+ }
+
+ private static final String STORY_CHAPTER_ID = "selected_story_chapter_id";
+ public static String getSelectedStoryChapter(Context context){
+ return Long.toString(android.preference.PreferenceManager.getDefaultSharedPreferences(context).getLong(STORY_CHAPTER_ID, -1));
+ }
+ public static void setSelectedStoryChapter(Context context, long newValue){
+
+ android.preference.PreferenceManager.getDefaultSharedPreferences(context).edit().putLong(STORY_CHAPTER_ID, newValue).commit();
+ }
+
+}
diff --git a/app/app/src/main/java/view/popover/ActionItem.java b/app/app/src/main/java/view/popover/ActionItem.java
index a22c15c..b02d66f 100755
--- a/app/app/src/main/java/view/popover/ActionItem.java
+++ b/app/app/src/main/java/view/popover/ActionItem.java
@@ -1,7 +1,7 @@
package view.popover;
-import android.graphics.drawable.Drawable;
import android.graphics.Bitmap;
+import android.graphics.drawable.Drawable;
/**
* Action item, displayed as menu with icon and text.
diff --git a/app/app/src/main/java/view/popover/PopupWindows.java b/app/app/src/main/java/view/popover/PopupWindows.java
index 91fdfec..a021b82 100755
--- a/app/app/src/main/java/view/popover/PopupWindows.java
+++ b/app/app/src/main/java/view/popover/PopupWindows.java
@@ -1,16 +1,14 @@
package view.popover;
+import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
-
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
-import android.view.WindowManager;
import android.view.View.OnTouchListener;
-
+import android.view.WindowManager;
import android.widget.PopupWindow;
-import android.content.Context;
/**
* Custom popup window.
diff --git a/app/app/src/main/java/view/popover/QuickAction.java b/app/app/src/main/java/view/popover/QuickAction.java
index 71907fa..5cbac99 100755
--- a/app/app/src/main/java/view/popover/QuickAction.java
+++ b/app/app/src/main/java/view/popover/QuickAction.java
@@ -1,27 +1,24 @@
package view.popover;
import android.content.Context;
-
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
-
-import android.widget.ImageView;
-import android.widget.TextView;
-import android.widget.ScrollView;
-import android.widget.RelativeLayout;
-import android.widget.PopupWindow.OnDismissListener;
-
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
-import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup;
+import android.view.ViewGroup.LayoutParams;
+import android.widget.ImageView;
+import android.widget.PopupWindow.OnDismissListener;
+import android.widget.RelativeLayout;
+import android.widget.ScrollView;
+import android.widget.TextView;
import org.unfoldingword.mobile.R;
-import java.util.List;
import java.util.ArrayList;
+import java.util.List;
/**
* QuickAction dialog, shows action list as icon and text like the one in Gallery3D app. Currently supports vertical
diff --git a/app/app/src/main/res/anim/enter_center.xml b/app/app/src/main/res/anim/enter_center.xml
new file mode 100644
index 0000000..5b17d4d
--- /dev/null
+++ b/app/app/src/main/res/anim/enter_center.xml
@@ -0,0 +1,10 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/app/src/main/res/anim/enter_from_bottom.xml b/app/app/src/main/res/anim/enter_from_bottom.xml
new file mode 100644
index 0000000..0d0e28b
--- /dev/null
+++ b/app/app/src/main/res/anim/enter_from_bottom.xml
@@ -0,0 +1,8 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/app/src/main/res/anim/enter_from_top.xml b/app/app/src/main/res/anim/enter_from_top.xml
new file mode 100644
index 0000000..e67d481
--- /dev/null
+++ b/app/app/src/main/res/anim/enter_from_top.xml
@@ -0,0 +1,8 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/app/src/main/res/anim/exit_on_bottom.xml b/app/app/src/main/res/anim/exit_on_bottom.xml
new file mode 100644
index 0000000..7f92a8d
--- /dev/null
+++ b/app/app/src/main/res/anim/exit_on_bottom.xml
@@ -0,0 +1,8 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/app/src/main/res/anim/exit_on_top.xml b/app/app/src/main/res/anim/exit_on_top.xml
new file mode 100644
index 0000000..be7a9ee
--- /dev/null
+++ b/app/app/src/main/res/anim/exit_on_top.xml
@@ -0,0 +1,8 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/app/src/main/res/anim/grow_from_bottom.xml b/app/app/src/main/res/anim/grow_from_bottom.xml
index d2a371d..062307e 100755
--- a/app/app/src/main/res/anim/grow_from_bottom.xml
+++ b/app/app/src/main/res/anim/grow_from_bottom.xml
@@ -4,11 +4,11 @@
android:fromXScale="0.3" android:toXScale="1.0"
android:fromYScale="0.3" android:toYScale="1.0"
android:pivotX="50%" android:pivotY="100%"
- android:duration="@android:integer/config_shortAnimTime"
+ android:duration="@integer/fast_animation"
/>
diff --git a/app/app/src/main/res/anim/grow_from_bottomleft_to_topright.xml b/app/app/src/main/res/anim/grow_from_bottomleft_to_topright.xml
index a4bf4ea..fbba872 100755
--- a/app/app/src/main/res/anim/grow_from_bottomleft_to_topright.xml
+++ b/app/app/src/main/res/anim/grow_from_bottomleft_to_topright.xml
@@ -4,11 +4,11 @@
android:fromXScale="0.3" android:toXScale="1.0"
android:fromYScale="0.3" android:toYScale="1.0"
android:pivotX="0%" android:pivotY="50%"
- android:duration="@android:integer/config_shortAnimTime"
+ android:duration="@integer/fast_animation"
/>
\ No newline at end of file
diff --git a/app/app/src/main/res/anim/grow_from_bottomright_to_topleft.xml b/app/app/src/main/res/anim/grow_from_bottomright_to_topleft.xml
index 3446623..f41e414 100755
--- a/app/app/src/main/res/anim/grow_from_bottomright_to_topleft.xml
+++ b/app/app/src/main/res/anim/grow_from_bottomright_to_topleft.xml
@@ -4,11 +4,11 @@
android:fromXScale="0.3" android:toXScale="1.0"
android:fromYScale="0.3" android:toYScale="1.0"
android:pivotX="100%" android:pivotY="50%"
- android:duration="@android:integer/config_shortAnimTime"
+ android:duration="@integer/fast_animation"
/>
\ No newline at end of file
diff --git a/app/app/src/main/res/anim/grow_from_top.xml b/app/app/src/main/res/anim/grow_from_top.xml
index ffd722c..dd0b37e 100755
--- a/app/app/src/main/res/anim/grow_from_top.xml
+++ b/app/app/src/main/res/anim/grow_from_top.xml
@@ -4,11 +4,11 @@
android:fromXScale="0.3" android:toXScale="1.0"
android:fromYScale="0.3" android:toYScale="1.0"
android:pivotX="50%" android:pivotY="0%"
- android:duration="@android:integer/config_shortAnimTime"
+ android:duration="@integer/fast_animation"
/>
diff --git a/app/app/src/main/res/anim/grow_from_topleft_to_bottomright.xml b/app/app/src/main/res/anim/grow_from_topleft_to_bottomright.xml
index b67ebe5..c660223 100755
--- a/app/app/src/main/res/anim/grow_from_topleft_to_bottomright.xml
+++ b/app/app/src/main/res/anim/grow_from_topleft_to_bottomright.xml
@@ -4,11 +4,11 @@
android:fromXScale="0.3" android:toXScale="1.0"
android:fromYScale="0.3" android:toYScale="1.0"
android:pivotX="0%" android:pivotY="0%"
- android:duration="@android:integer/config_shortAnimTime"
+ android:duration="@integer/fast_animation"
/>
diff --git a/app/app/src/main/res/anim/grow_from_topright_to_bottomleft.xml b/app/app/src/main/res/anim/grow_from_topright_to_bottomleft.xml
index d4744f6..0e735e6 100755
--- a/app/app/src/main/res/anim/grow_from_topright_to_bottomleft.xml
+++ b/app/app/src/main/res/anim/grow_from_topright_to_bottomleft.xml
@@ -4,11 +4,11 @@
android:fromXScale="0.3" android:toXScale="1.0"
android:fromYScale="0.3" android:toYScale="1.0"
android:pivotX="100%" android:pivotY="0%"
- android:duration="@android:integer/config_shortAnimTime"
+ android:duration="@integer/fast_animation"
/>
\ No newline at end of file
diff --git a/app/app/src/main/res/anim/pump_bottom.xml b/app/app/src/main/res/anim/pump_bottom.xml
index f681951..9b17ab8 100755
--- a/app/app/src/main/res/anim/pump_bottom.xml
+++ b/app/app/src/main/res/anim/pump_bottom.xml
@@ -4,11 +4,11 @@
android:fromXScale="1.1" android:toXScale="1.0"
android:fromYScale="1.1" android:toYScale="1.0"
android:pivotX="50%" android:pivotY="100%"
- android:duration="@android:integer/config_shortAnimTime"
+ android:duration="@integer/fast_animation"
/>
diff --git a/app/app/src/main/res/anim/pump_top.xml b/app/app/src/main/res/anim/pump_top.xml
index 65637b5..3edffbe 100755
--- a/app/app/src/main/res/anim/pump_top.xml
+++ b/app/app/src/main/res/anim/pump_top.xml
@@ -4,11 +4,11 @@
android:fromXScale="1.1" android:toXScale="1.0"
android:fromYScale="1.1" android:toYScale="1.0"
android:pivotX="50%" android:pivotY="0%"
- android:duration="@android:integer/config_shortAnimTime"
+ android:duration="@integer/fast_animation"
/>
diff --git a/app/app/src/main/res/anim/shrink_from_bottom.xml b/app/app/src/main/res/anim/shrink_from_bottom.xml
index a98d592..7ebc025 100755
--- a/app/app/src/main/res/anim/shrink_from_bottom.xml
+++ b/app/app/src/main/res/anim/shrink_from_bottom.xml
@@ -4,11 +4,11 @@
android:fromXScale="1.0" android:toXScale="0.3"
android:fromYScale="1.0" android:toYScale="0.3"
android:pivotX="50%" android:pivotY="0%"
- android:duration="@android:integer/config_shortAnimTime"
+ android:duration="@integer/fast_animation"
/>
diff --git a/app/app/src/main/res/anim/shrink_from_bottomleft_to_topright.xml b/app/app/src/main/res/anim/shrink_from_bottomleft_to_topright.xml
index 6e56c1e..79328cb 100755
--- a/app/app/src/main/res/anim/shrink_from_bottomleft_to_topright.xml
+++ b/app/app/src/main/res/anim/shrink_from_bottomleft_to_topright.xml
@@ -4,11 +4,11 @@
android:fromXScale="1.0" android:toXScale="0.3"
android:fromYScale="1.0" android:toYScale="0.3"
android:pivotX="100%" android:pivotY="0%"
- android:duration="@android:integer/config_shortAnimTime"
+ android:duration="@integer/fast_animation"
/>
\ No newline at end of file
diff --git a/app/app/src/main/res/anim/shrink_from_bottomright_to_topleft.xml b/app/app/src/main/res/anim/shrink_from_bottomright_to_topleft.xml
index d4ed513..3bc9bf2 100755
--- a/app/app/src/main/res/anim/shrink_from_bottomright_to_topleft.xml
+++ b/app/app/src/main/res/anim/shrink_from_bottomright_to_topleft.xml
@@ -4,11 +4,11 @@
android:fromXScale="1.0" android:toXScale="0.3"
android:fromYScale="1.0" android:toYScale="0.3"
android:pivotX="0%" android:pivotY="0%"
- android:duration="@android:integer/config_shortAnimTime"
+ android:duration="@integer/fast_animation"
/>
diff --git a/app/app/src/main/res/anim/shrink_from_top.xml b/app/app/src/main/res/anim/shrink_from_top.xml
index 89cd8f4..57f70d4 100755
--- a/app/app/src/main/res/anim/shrink_from_top.xml
+++ b/app/app/src/main/res/anim/shrink_from_top.xml
@@ -4,11 +4,11 @@
android:fromXScale="1.0" android:toXScale="0.3"
android:fromYScale="1.0" android:toYScale="0.3"
android:pivotX="50%" android:pivotY="100%"
- android:duration="@android:integer/config_shortAnimTime"
+ android:duration="@integer/fast_animation"
/>
diff --git a/app/app/src/main/res/anim/shrink_from_topleft_to_bottomright.xml b/app/app/src/main/res/anim/shrink_from_topleft_to_bottomright.xml
index 1341728..a41bdb9 100755
--- a/app/app/src/main/res/anim/shrink_from_topleft_to_bottomright.xml
+++ b/app/app/src/main/res/anim/shrink_from_topleft_to_bottomright.xml
@@ -4,11 +4,11 @@
android:fromXScale="1.0" android:toXScale="0.3"
android:fromYScale="1.0" android:toYScale="0.3"
android:pivotX="100%" android:pivotY="100%"
- android:duration="@android:integer/config_shortAnimTime"
+ android:duration="@integer/fast_animation"
/>
\ No newline at end of file
diff --git a/app/app/src/main/res/anim/shrink_from_topright_to_bottomleft.xml b/app/app/src/main/res/anim/shrink_from_topright_to_bottomleft.xml
index d4064fc..a973a54 100755
--- a/app/app/src/main/res/anim/shrink_from_topright_to_bottomleft.xml
+++ b/app/app/src/main/res/anim/shrink_from_topright_to_bottomleft.xml
@@ -4,11 +4,11 @@
android:fromXScale="1.0" android:toXScale="0.3"
android:fromYScale="1.0" android:toYScale="0.3"
android:pivotX="0%" android:pivotY="100%"
- android:duration="@android:integer/config_shortAnimTime"
+ android:duration="@integer/fast_animation"
/>
diff --git a/app/app/src/main/res/drawable-hdpi/download_button.png b/app/app/src/main/res/drawable-hdpi/download_button.png
new file mode 100644
index 0000000..c8c6e04
Binary files /dev/null and b/app/app/src/main/res/drawable-hdpi/download_button.png differ
diff --git a/app/app/src/main/res/drawable-hdpi/status_error_btn_radio_on_holo_light.png b/app/app/src/main/res/drawable-hdpi/status_error_btn_radio_on_holo_light.png
new file mode 100644
index 0000000..5c27a6a
Binary files /dev/null and b/app/app/src/main/res/drawable-hdpi/status_error_btn_radio_on_holo_light.png differ
diff --git a/app/app/src/main/res/drawable-hdpi/status_expired_btn_radio_on_holo_light.png b/app/app/src/main/res/drawable-hdpi/status_expired_btn_radio_on_holo_light.png
new file mode 100644
index 0000000..2f82561
Binary files /dev/null and b/app/app/src/main/res/drawable-hdpi/status_expired_btn_radio_on_holo_light.png differ
diff --git a/app/app/src/main/res/drawable-hdpi/status_failed_btn_radio_on_holo_light.png b/app/app/src/main/res/drawable-hdpi/status_failed_btn_radio_on_holo_light.png
new file mode 100644
index 0000000..535bc6e
Binary files /dev/null and b/app/app/src/main/res/drawable-hdpi/status_failed_btn_radio_on_holo_light.png differ
diff --git a/app/app/src/main/res/drawable-hdpi/status_verified_btn_radio_on_holo_light.png b/app/app/src/main/res/drawable-hdpi/status_verified_btn_radio_on_holo_light.png
new file mode 100644
index 0000000..fc4e7d6
Binary files /dev/null and b/app/app/src/main/res/drawable-hdpi/status_verified_btn_radio_on_holo_light.png differ
diff --git a/app/app/src/main/res/drawable-hdpi/x_button.png b/app/app/src/main/res/drawable-hdpi/x_button.png
new file mode 100644
index 0000000..0098e14
Binary files /dev/null and b/app/app/src/main/res/drawable-hdpi/x_button.png differ
diff --git a/app/app/src/main/res/drawable-mdpi/download_button.png b/app/app/src/main/res/drawable-mdpi/download_button.png
new file mode 100644
index 0000000..32bdd8e
Binary files /dev/null and b/app/app/src/main/res/drawable-mdpi/download_button.png differ
diff --git a/app/app/src/main/res/drawable-mdpi/status_error_btn_radio_on_holo_light.png b/app/app/src/main/res/drawable-mdpi/status_error_btn_radio_on_holo_light.png
new file mode 100644
index 0000000..c2cf8a0
Binary files /dev/null and b/app/app/src/main/res/drawable-mdpi/status_error_btn_radio_on_holo_light.png differ
diff --git a/app/app/src/main/res/drawable-mdpi/status_expired_btn_radio_on_holo_light.png b/app/app/src/main/res/drawable-mdpi/status_expired_btn_radio_on_holo_light.png
new file mode 100644
index 0000000..02c375c
Binary files /dev/null and b/app/app/src/main/res/drawable-mdpi/status_expired_btn_radio_on_holo_light.png differ
diff --git a/app/app/src/main/res/drawable-mdpi/status_failed_btn_radio_on_holo_light.png b/app/app/src/main/res/drawable-mdpi/status_failed_btn_radio_on_holo_light.png
new file mode 100644
index 0000000..9d5152e
Binary files /dev/null and b/app/app/src/main/res/drawable-mdpi/status_failed_btn_radio_on_holo_light.png differ
diff --git a/app/app/src/main/res/drawable-mdpi/status_verified_btn_radio_on_holo_light.png b/app/app/src/main/res/drawable-mdpi/status_verified_btn_radio_on_holo_light.png
new file mode 100644
index 0000000..effa6a3
Binary files /dev/null and b/app/app/src/main/res/drawable-mdpi/status_verified_btn_radio_on_holo_light.png differ
diff --git a/app/app/src/main/res/drawable-mdpi/x_button.png b/app/app/src/main/res/drawable-mdpi/x_button.png
new file mode 100644
index 0000000..9660b1e
Binary files /dev/null and b/app/app/src/main/res/drawable-mdpi/x_button.png differ
diff --git a/app/app/src/main/res/drawable-xhdpi/download_button.png b/app/app/src/main/res/drawable-xhdpi/download_button.png
new file mode 100644
index 0000000..60b6209
Binary files /dev/null and b/app/app/src/main/res/drawable-xhdpi/download_button.png differ
diff --git a/app/app/src/main/res/drawable-xhdpi/status_error_btn_radio_on_holo_light.png b/app/app/src/main/res/drawable-xhdpi/status_error_btn_radio_on_holo_light.png
new file mode 100644
index 0000000..3bacee1
Binary files /dev/null and b/app/app/src/main/res/drawable-xhdpi/status_error_btn_radio_on_holo_light.png differ
diff --git a/app/app/src/main/res/drawable-xhdpi/status_expired_btn_radio_on_holo_light.png b/app/app/src/main/res/drawable-xhdpi/status_expired_btn_radio_on_holo_light.png
new file mode 100644
index 0000000..86da73c
Binary files /dev/null and b/app/app/src/main/res/drawable-xhdpi/status_expired_btn_radio_on_holo_light.png differ
diff --git a/app/app/src/main/res/drawable-xhdpi/status_failed_btn_radio_on_holo_light.png b/app/app/src/main/res/drawable-xhdpi/status_failed_btn_radio_on_holo_light.png
new file mode 100644
index 0000000..7a23d93
Binary files /dev/null and b/app/app/src/main/res/drawable-xhdpi/status_failed_btn_radio_on_holo_light.png differ
diff --git a/app/app/src/main/res/drawable-xhdpi/status_verified_btn_radio_on_holo_light.png b/app/app/src/main/res/drawable-xhdpi/status_verified_btn_radio_on_holo_light.png
new file mode 100644
index 0000000..a0daf96
Binary files /dev/null and b/app/app/src/main/res/drawable-xhdpi/status_verified_btn_radio_on_holo_light.png differ
diff --git a/app/app/src/main/res/drawable-xhdpi/x_button.png b/app/app/src/main/res/drawable-xhdpi/x_button.png
new file mode 100644
index 0000000..5f2d0c9
Binary files /dev/null and b/app/app/src/main/res/drawable-xhdpi/x_button.png differ
diff --git a/app/app/src/main/res/drawable-xxhdpi/download_button.png b/app/app/src/main/res/drawable-xxhdpi/download_button.png
new file mode 100644
index 0000000..8e16459
Binary files /dev/null and b/app/app/src/main/res/drawable-xxhdpi/download_button.png differ
diff --git a/app/app/src/main/res/drawable-xxhdpi/status_error_btn_radio_on_holo_light.png b/app/app/src/main/res/drawable-xxhdpi/status_error_btn_radio_on_holo_light.png
new file mode 100644
index 0000000..7c5bbd5
Binary files /dev/null and b/app/app/src/main/res/drawable-xxhdpi/status_error_btn_radio_on_holo_light.png differ
diff --git a/app/app/src/main/res/drawable-xxhdpi/status_expired_btn_radio_on_holo_light.png b/app/app/src/main/res/drawable-xxhdpi/status_expired_btn_radio_on_holo_light.png
new file mode 100644
index 0000000..be2899f
Binary files /dev/null and b/app/app/src/main/res/drawable-xxhdpi/status_expired_btn_radio_on_holo_light.png differ
diff --git a/app/app/src/main/res/drawable-xxhdpi/status_failed_btn_radio_on_holo_light.png b/app/app/src/main/res/drawable-xxhdpi/status_failed_btn_radio_on_holo_light.png
new file mode 100644
index 0000000..ea3c5ec
Binary files /dev/null and b/app/app/src/main/res/drawable-xxhdpi/status_failed_btn_radio_on_holo_light.png differ
diff --git a/app/app/src/main/res/drawable-xxhdpi/status_verified_btn_radio_on_holo_light.png b/app/app/src/main/res/drawable-xxhdpi/status_verified_btn_radio_on_holo_light.png
new file mode 100644
index 0000000..a19be39
Binary files /dev/null and b/app/app/src/main/res/drawable-xxhdpi/status_verified_btn_radio_on_holo_light.png differ
diff --git a/app/app/src/main/res/drawable-xxhdpi/x_button.png b/app/app/src/main/res/drawable-xxhdpi/x_button.png
new file mode 100644
index 0000000..4497e3b
Binary files /dev/null and b/app/app/src/main/res/drawable-xxhdpi/x_button.png differ
diff --git a/app/app/src/main/res/drawable-xxxhdpi/download_button.png b/app/app/src/main/res/drawable-xxxhdpi/download_button.png
new file mode 100644
index 0000000..b367624
Binary files /dev/null and b/app/app/src/main/res/drawable-xxxhdpi/download_button.png differ
diff --git a/app/app/src/main/res/drawable-xxxhdpi/x_button.png b/app/app/src/main/res/drawable-xxxhdpi/x_button.png
new file mode 100644
index 0000000..1d273b8
Binary files /dev/null and b/app/app/src/main/res/drawable-xxxhdpi/x_button.png differ
diff --git a/app/app/src/main/res/drawable/status_error_btn_radio_holo_light.xml b/app/app/src/main/res/drawable/status_error_btn_radio_holo_light.xml
new file mode 100644
index 0000000..6037f38
--- /dev/null
+++ b/app/app/src/main/res/drawable/status_error_btn_radio_holo_light.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
diff --git a/app/app/src/main/res/drawable/status_expired_btn_radio_holo_light.xml b/app/app/src/main/res/drawable/status_expired_btn_radio_holo_light.xml
new file mode 100644
index 0000000..0a12914
--- /dev/null
+++ b/app/app/src/main/res/drawable/status_expired_btn_radio_holo_light.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
diff --git a/app/app/src/main/res/drawable/status_failed_btn_radio_holo_light.xml b/app/app/src/main/res/drawable/status_failed_btn_radio_holo_light.xml
new file mode 100644
index 0000000..0ba5799
--- /dev/null
+++ b/app/app/src/main/res/drawable/status_failed_btn_radio_holo_light.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
diff --git a/app/app/src/main/res/drawable/status_verified_btn_radio_holo_light.xml b/app/app/src/main/res/drawable/status_verified_btn_radio_holo_light.xml
new file mode 100644
index 0000000..54de584
--- /dev/null
+++ b/app/app/src/main/res/drawable/status_verified_btn_radio_holo_light.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
diff --git a/app/app/src/main/res/layout-land/stories_pager_layout.xml b/app/app/src/main/res/layout-land/stories_pager_layout.xml
index b787487..2865ae5 100644
--- a/app/app/src/main/res/layout-land/stories_pager_layout.xml
+++ b/app/app/src/main/res/layout-land/stories_pager_layout.xml
@@ -9,25 +9,26 @@
android:layout_height="match_parent">
+ android:scaleType="fitCenter"/>
\ No newline at end of file
diff --git a/app/app/src/main/res/layout/actionbar_base.xml b/app/app/src/main/res/layout/actionbar_base.xml
new file mode 100644
index 0000000..c9d1952
--- /dev/null
+++ b/app/app/src/main/res/layout/actionbar_base.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/app/src/main/res/layout/actionbar_custom_view.xml b/app/app/src/main/res/layout/actionbar_custom_view.xml
index 7404977..696eec0 100644
--- a/app/app/src/main/res/layout/actionbar_custom_view.xml
+++ b/app/app/src/main/res/layout/actionbar_custom_view.xml
@@ -1,40 +1,75 @@
+ android:layout_height="30dp">
-
+ android:layout_alignParentTop="true"
+ android:clickable="true"
+ android:background="@drawable/language_button_click"
+ android:layout_centerHorizontal="true"
+ android:onClick="chapterButtonClicked"
+ android:paddingLeft="10dp"
+ android:paddingRight="50dp">
+
+
+
+
+
-
+ android:layout_alignParentBottom="true"
+ android:layout_height="fill_parent"
+ >
+
+
+
+
+
\ No newline at end of file
diff --git a/app/app/src/main/res/layout/activity_version_selector.xml b/app/app/src/main/res/layout/activity_version_selector.xml
new file mode 100644
index 0000000..58f4f61
--- /dev/null
+++ b/app/app/src/main/res/layout/activity_version_selector.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/app/src/main/res/layout/footerview.xml b/app/app/src/main/res/layout/footerview.xml
index 296c3c6..fb9b907 100644
--- a/app/app/src/main/res/layout/footerview.xml
+++ b/app/app/src/main/res/layout/footerview.xml
@@ -4,6 +4,121 @@
android:layout_height="match_parent"
android:orientation="vertical">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/app/src/main/res/layout/next_chapter_screen_layout.xml b/app/app/src/main/res/layout/next_chapter_screen_layout.xml
index e13ea6e..eca1de8 100644
--- a/app/app/src/main/res/layout/next_chapter_screen_layout.xml
+++ b/app/app/src/main/res/layout/next_chapter_screen_layout.xml
@@ -6,7 +6,7 @@
android:padding="16dp">