diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..289bf66 --- /dev/null +++ b/.gitignore @@ -0,0 +1,44 @@ +# Built application files +/*/build/ +/build + +# Crashlytics configuations +com_crashlytics_export_strings.xml + +# Local configuration file (sdk path, etc) +local.properties + +# Gradle generated files +.gradle/ + +# Signing files +.signing/ + +# User-specific configurations +.idea/libraries/ +.idea/workspace.xml +.idea/tasks.xml +.idea/.name +.idea/compiler.xml +.idea/copyright/profiles_settings.xml +.idea/encodings.xml +.idea/misc.xml +.idea/modules.xml +.idea/scopes/scope_settings.xml +.idea/vcs.xml +*.iml + +# OS-specific files +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +*.apk +*.ap_ + +*.class +gen/ diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..508b3d9 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,23 @@ + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..ab967fd --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,29 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.2" + + defaultConfig { + applicationId "net.foucry.pilldroid" + minSdkVersion 22 + targetSdkVersion 23 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:23.3.0' + compile 'com.android.support:support-v4:23.3.0' + compile 'com.android.support:recyclerview-v7:23.3.0' + compile 'com.android.support:design:23.3.0' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..1af6302 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Volumes/Users/jacques/Library/Android/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/app/src/androidTest/java/net/foucry/pilldroid/ApplicationTest.java b/app/src/androidTest/java/net/foucry/pilldroid/ApplicationTest.java new file mode 100644 index 0000000..3129e2c --- /dev/null +++ b/app/src/androidTest/java/net/foucry/pilldroid/ApplicationTest.java @@ -0,0 +1,13 @@ +package net.foucry.pilldroid; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..5113f17 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/net/foucry/pilldroid/DBHelper.java b/app/src/main/java/net/foucry/pilldroid/DBHelper.java new file mode 100644 index 0000000..7a13aef --- /dev/null +++ b/app/src/main/java/net/foucry/pilldroid/DBHelper.java @@ -0,0 +1,289 @@ +package net.foucry.medicament; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.util.Log; + +import java.util.LinkedList; +import java.util.List; + +/** + * Created by jacques on 24/04/16. + */ + + +public class DBHelper extends SQLiteOpenHelper { + + private static final int DATABASE_VERSION = 1; + private static String DATABASE_NAME = "ordonnance.db"; + + private static final String TABLE_DRUG = "drug"; + private static final String KEY_ID = "id"; + private static final String KEY_CIS = "cis"; + private static final String KEY_CIP13 = "cip13"; + private static final String KEY_NAME = "nom"; + private static final String KEY_ADMIN = "mode_administration"; + private static final String KEY_PRES = "presentation"; + private static final String KEY_STOCK = "stock"; + private static final String KEY_PRISE = "prise"; + private static final String KEY_SEUIL_WARN = "warning"; + private static final String KEY_SEUIL_ALERT = "alerte"; + + private static DBHelper sInstance; + + private static final String[] COLUMS = {KEY_ID, KEY_CIS,KEY_CIP13, KEY_NAME, KEY_ADMIN, KEY_PRES, KEY_STOCK, KEY_PRISE, + KEY_SEUIL_WARN, KEY_SEUIL_ALERT}; + + public static synchronized DBHelper getInstance(Context context) { + if (sInstance == null) { + sInstance = new DBHelper(context.getApplicationContext()); + } + return sInstance; + } + + public DBHelper(Context context) { + super(context, DATABASE_NAME, null, DATABASE_VERSION); + } + + @Override + public void onCreate(SQLiteDatabase db) { + String CREATE_DRUG_TABLE = "CREATE TABLE drug ( " + + "id INTEGER PRIMARY KEY AUTOINCREMENT," + + "cis TEXT, " + + "cip13 TEXT, " + + "nom TEXT, " + + "mode_administration TEXT, " + + "presentation TEXT, " + + "stock REAL, " + + "prise REAL, " + + "warning INT, " + + "alerte INT)"; + + db.execSQL(CREATE_DRUG_TABLE); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + // Drop old database + db.execSQL("DROP TABLE IF EXISTS drug"); + + // Create fresh book table + this.onCreate(db); + } + + public void dropDrug() { + SQLiteDatabase db = this.getWritableDatabase(); + Log.d(CustomizedListView.Constants.TAG, "Drop drug table"); + db.execSQL("DROP TABLE IF EXISTS drug"); + + this.onCreate(db); + } + + public void addDrug(Medicament medicament) { + // Logging + Log.d(CustomizedListView.Constants.TAG, medicament.toString()); + + // Get reference to writable DB + SQLiteDatabase db = this.getWritableDatabase(); + + // Create ContentValues to add key "column"/value + ContentValues values = new ContentValues(); + values.put(KEY_CIS, medicament.getCis()); + values.put(KEY_CIP13, medicament.getCip13()); + values.put(KEY_NAME, medicament.getNom()); + values.put(KEY_ADMIN, medicament.getMode_administration()); + values.put(KEY_PRES, medicament.getPresentation()); + values.put(KEY_STOCK, medicament.getStock()); + values.put(KEY_PRISE, medicament.getPrise()); + values.put(KEY_SEUIL_WARN, medicament.getWarnThreshold()); + values.put(KEY_SEUIL_ALERT,medicament.getAlertThreshold()); + + // Calculate some medicament's fields + + // Insert + db.insert(TABLE_DRUG, // table + null, // colunms list not needed + values); // key/value + + // Close database + db.close(); + } + + public Medicament getDrug(int id) { + // Get reference to readable DB + SQLiteDatabase db = this.getReadableDatabase(); + + // Build query + Cursor cursor = db.query(TABLE_DRUG, // Which table + COLUMS, // column names + " id = ?", // selections + new String[] { String.valueOf(id) }, // selections args + null, // group by + null, // having + null, // order by + null); // limits + + // if case we got result, go to the first one + if (cursor != null) + cursor.moveToFirst(); + + // Build medicament object + Medicament medicament = new Medicament(); + medicament.setId(Integer.parseInt(cursor.getString(0))); + medicament.setCis(cursor.getString(1)); + medicament.setCip13(cursor.getString(2)); + medicament.setNom(cursor.getString(3)); + medicament.setMode_administration(cursor.getString(4)); + medicament.setPresentation(cursor.getString(5)); + medicament.setStock(Double.parseDouble(cursor.getString(6))); + medicament.setPrise(Double.parseDouble(cursor.getString(7))); + medicament.setWarnThreshold(Integer.parseInt(cursor.getString(8))); + medicament.setAlertThreshold(Integer.parseInt(cursor.getString(9))); + + // Log + Log.d(CustomizedListView.Constants.TAG, "getDrug("+id+")" + medicament.toString()); + + // Return medicament + + return medicament; + } + + public Medicament getDrugByCIP13(String cip13) { + // Get reference to readable DB + SQLiteDatabase db = this.getReadableDatabase(); + + // Build query + Cursor cursor = db.query(TABLE_DRUG, // Which table + COLUMS, // column names + " cip13 = ?", // selections + new String[] { String.valueOf(cip13) }, // selections args + null, // group by + null, // having + null, // order by + null); // limits + + // if case we got result, go to the first one + if (cursor != null) + cursor.moveToFirst(); + + // Build medicament object + Medicament medicament = new Medicament(); + medicament.setId(Integer.parseInt(cursor.getString(0))); + medicament.setCis(cursor.getString(1)); + medicament.setCip13(cursor.getString(2)); + medicament.setNom(cursor.getString(3)); + medicament.setMode_administration(cursor.getString(4)); + medicament.setPresentation(cursor.getString(5)); + medicament.setStock(Double.parseDouble(cursor.getString(6))); + medicament.setPrise(Double.parseDouble(cursor.getString(7))); + medicament.setWarnThreshold(Integer.parseInt(cursor.getString(8))); + medicament.setAlertThreshold(Integer.parseInt(cursor.getString(9))); + + // Log + Log.d(CustomizedListView.Constants.TAG, "getDrug("+cip13+")" + medicament.toString()); + + // Return medicament + + return medicament; + } + public List getAllDrugs() { + List medicaments = new LinkedList(); + + // Build the query + String query = "SELECT * FROM " + TABLE_DRUG; + + // Get reference to readable DB (tutorial parle de writable, mais bof... on verra) + SQLiteDatabase db = this.getReadableDatabase(); + Cursor cursor = db.rawQuery(query, null); + + // For Each row, build a medicament and add it to the list + Medicament medicament = null; + if (cursor.moveToFirst()) { + do { + medicament = new Medicament(); + medicament.setId(Integer.parseInt(cursor.getString(0))); + medicament.setCis(cursor.getString(1)); + medicament.setCip13(cursor.getString(2)); + medicament.setNom(cursor.getString(3)); + medicament.setMode_administration(cursor.getString(4)); + medicament.setPresentation(cursor.getString(5)); + medicament.setStock(Double.parseDouble(cursor.getString(6))); + medicament.setPrise(Double.parseDouble(cursor.getString(7))); + medicament.setWarnThreshold(Integer.parseInt(cursor.getString(8))); + medicament.setAlertThreshold(Integer.parseInt(cursor.getString(9))); + + // Call calcul method + medicament.setDateEndOfStock(); + medicament.setDateLastUpdate(); + + // Add medicament to medicaments + medicaments.add(medicament); + } while (cursor.moveToNext()); + } + + cursor.close(); + Log.d(CustomizedListView.Constants.TAG, "getAllDrugs " + medicaments.toString()); + + // return + return medicaments; + } + + public int updateDrug(Medicament medicament) { + // Get reference to writable DB + SQLiteDatabase db = this.getWritableDatabase(); + + // Create ContentValues to add columnm/value + ContentValues values = new ContentValues(); + values.put(KEY_CIS, medicament.getCis()); + values.put(KEY_CIP13, medicament.getCip13()); + values.put(KEY_NAME, medicament.getNom()); + values.put(KEY_ADMIN, medicament.getMode_administration()); + values.put(KEY_PRES, medicament.getPresentation()); + values.put(KEY_STOCK, medicament.getStock()); + + // Update row + int i = db.update(TABLE_DRUG, // table + values, // column/value + KEY_ID+" = ?", // selections + new String[] {String.valueOf(medicament.getId()) } ); // selections args + + // Close DB + db.close(); + + return i; + } + + public void deleteDrug(Medicament medicament) { + // Get writable database + SQLiteDatabase db = this.getWritableDatabase(); + + // Delete record + db.delete(TABLE_DRUG, // table + KEY_ID+ " = ?", // selections + new String[] { String.valueOf(medicament.getId()) } ); // selections args + + // Close DB + db.close(); + + // log + Log.d(CustomizedListView.Constants.TAG, "delete drug "+medicament.toString()); + } + + public int getCount() { + + String query = "SELECT count (*) FROM " + TABLE_DRUG; + + // Get reference to readable DB (tutorial parle de writable, mais bof... on verra) + SQLiteDatabase db = this.getReadableDatabase(); + Cursor mCount = db.rawQuery(query, null); + mCount.moveToFirst(); + int count = mCount.getInt(0); + + mCount.close(); + return count; + } +} + diff --git a/app/src/main/java/net/foucry/pilldroid/Medicament.java b/app/src/main/java/net/foucry/pilldroid/Medicament.java new file mode 100644 index 0000000..163bd03 --- /dev/null +++ b/app/src/main/java/net/foucry/pilldroid/Medicament.java @@ -0,0 +1,209 @@ +package net.foucry.medicament; + +import java.io.Serializable; +import java.lang.String; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + +import static net.foucry.medicament.UtilDate.*; + + +/** + * Created by jacques on 26/11/15. + */ +public class Medicament implements Serializable { + + /* part read form database */ + private int id; + private String nom; + private String cip13; + private String cis; + private String mode_administration; + private String presentation; + private double stock; + private double prise; + private int warnThreshold; + private int alertThreshold; + private String dateLastUpdate; + + /* calculate part */ + private Date dateEndOfStock; + + private static final String[] COLUMN_LIST = {"id","cis", "cip13", "nom", "mode_administration", "presentation", "stock", "prise", + "seuil_warn", "seuil_alert", "dateLastUpdate"}; + + public Medicament() {} + + public Medicament(String cis, String cip13, String nom, String mode_administration, String presentation, + double stock, double prise, int warn, int alert) { + super(); + + this.cis = cis; + this.cip13 = cip13; + this.nom = nom; + this.mode_administration = mode_administration; + this.presentation = presentation; + this.stock = stock; + this.prise = prise; + this.warnThreshold = warn; + this.alertThreshold = alert; + } + +// private Medicament(Cursor cursor) { +// if (cursor == null) throw new AssertionError(); +// +// this.setCis(cursor.getString(0)); +// this.setCip13(cursor.getString(1)); +// this.setNom(cursor.getString(2)); +// this.setMode_administration(cursor.getString(3)); +// this.setPresentation(cursor.getString(4)); +// this.setStock(cursor.getFloat(5)); +// this.setPrise(cursor.getFloat(6)); +// } + + + + public int getId() { + return id; + } + + public String getNom() { + return nom; + } + + public String getCip13() { + return cip13; + } + + public String getCis() { + return cis; + } + + public String getMode_administration() { + return mode_administration; + } + + public String getPresentation() { + return presentation; + } + + public double getStock() { + return stock; + } + + public double getPrise() { + return prise; + } + + public int getAlertThreshold() { + return alertThreshold; + } + + public int getWarnThreshold() { + return warnThreshold; + } + + public String getDateLastUpdate() { + return dateLastUpdate; + } + + public Date getDateEndOfStock() { + return dateEndOfStock; + } + + public void setId(int id) { + this.id = id; + } + + public void setNom(String nom) { + this.nom = nom; + } + + public void setCip13(String cip13) { + this.cip13 = cip13; + } + + public void setCis(String cis) { + this.cis = cis; + } + + public void setMode_administration(String mode_administration) { + this.mode_administration = mode_administration; + } + + public void setPresentation(String presentation) { + this.presentation = presentation; + } + + public void setStock(double stock) { + this.stock = stock; + } + + public void setPrise(double prise) { + this.prise = prise; + } + + public void setWarnThreshold(int warn) { + if (warn == 0) + warn = 14; + this.warnThreshold = warn; + } + public void setAlertThreshold(int alert) { + if (alert == 0) + alert = 7; + this.alertThreshold = alert; + } + + public void setDateLastUpdate() { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + this.dateLastUpdate = date2String(dateAtNoon(new Date()), dateFormat); + } + + public void setDateEndOfStock() { + int numberDayOfPrise; + if (this.prise > 0) { + numberDayOfPrise = (int) Math.floor(this.stock / this.prise); + } else { + numberDayOfPrise = 0; + } + + Date aDate = dateAtNoon(new Date()); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(aDate); + calendar.add(Calendar.DAY_OF_YEAR, numberDayOfPrise); + + this.dateEndOfStock = calendar.getTime(); + } + + public double newStock(double currentStock) { + Date lastUpdate = string2Date(this.dateLastUpdate); + int numberOfDays = nbOfDaysBetweenDateAndToday(lastUpdate); + double takeDuringPeriod = this.prise * numberOfDays; + + return currentStock - takeDuringPeriod; + } + + +// public static Medicament getMedicamentByCIP13(String cip13) { +// Log.e(CustomizedListView.Constants.TAG, "getMedicamentByCIP13 called"); +// +// Context context = null; +// DBHelper db = new DBHelper(context); +// SQLiteDatabase myDatabase = DBHelper.getInstance(context).getWritableDatabase(); +// +// Medicament medicament = null; +// +// Cursor cur = myDatabase.query("medicaments", COLUMN_LIST, "cip13 = ?", new String[]{cip13}, null, null,null); +// if (cur != null) { +// cur.moveToFirst(); +// int count = cur.getCount(); +// Log.d(CustomizedListView.Constants.TAG, "Number of item in cursor " + String.valueOf(count)); +// medicament = new Medicament(cur); +// } +// cur.close(); +// myDatabase.close(); +// return medicament; +// } + +} diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentDetailActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentDetailActivity.java new file mode 100644 index 0000000..5a7e1ed --- /dev/null +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentDetailActivity.java @@ -0,0 +1,81 @@ +package net.foucry.pilldroid; + +import android.content.Intent; +import android.os.Bundle; +import android.support.design.widget.FloatingActionButton; +import android.support.design.widget.Snackbar; +import android.support.v7.widget.Toolbar; +import android.view.View; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.app.ActionBar; +import android.view.MenuItem; + +/** + * An activity representing a single Medicament detail screen. This + * activity is only used narrow width devices. On tablet-size devices, + * item details are presented side-by-side with a list of items + * in a {@link MedicamentListActivity}. + */ +public class MedicamentDetailActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_medicament_detail); + Toolbar toolbar = (Toolbar) findViewById(R.id.detail_toolbar); + setSupportActionBar(toolbar); + + FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); + fab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Snackbar.make(view, "Replace with your own detail action", Snackbar.LENGTH_LONG) + .setAction("Action", null).show(); + } + }); + + // Show the Up button in the action bar. + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setDisplayHomeAsUpEnabled(true); + } + + // savedInstanceState is non-null when there is fragment state + // saved from previous configurations of this activity + // (e.g. when rotating the screen from portrait to landscape). + // In this case, the fragment will automatically be re-added + // to its container so we don't need to manually add it. + // For more information, see the Fragments API guide at: + // + // http://developer.android.com/guide/components/fragments.html + // + if (savedInstanceState == null) { + // Create the detail fragment and add it to the activity + // using a fragment transaction. + Bundle arguments = new Bundle(); + arguments.putString(MedicamentDetailFragment.ARG_ITEM_ID, + getIntent().getStringExtra(MedicamentDetailFragment.ARG_ITEM_ID)); + MedicamentDetailFragment fragment = new MedicamentDetailFragment(); + fragment.setArguments(arguments); + getSupportFragmentManager().beginTransaction() + .add(R.id.medicament_detail_container, fragment) + .commit(); + } + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + if (id == android.R.id.home) { + // This ID represents the Home or Up button. In the case of this + // activity, the Up button is shown. For + // more details, see the Navigation pattern on Android Design: + // + // http://developer.android.com/design/patterns/navigation.html#up-vs-back + // + navigateUpTo(new Intent(this, MedicamentListActivity.class)); + return true; + } + return super.onOptionsItemSelected(item); + } +} diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentDetailFragment.java b/app/src/main/java/net/foucry/pilldroid/MedicamentDetailFragment.java new file mode 100644 index 0000000..7ed082a --- /dev/null +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentDetailFragment.java @@ -0,0 +1,69 @@ +package net.foucry.pilldroid; + +import android.app.Activity; +import android.support.design.widget.CollapsingToolbarLayout; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import net.foucry.pilldroid.dummy.DummyContent; + +/** + * A fragment representing a single Medicament detail screen. + * This fragment is either contained in a {@link MedicamentListActivity} + * in two-pane mode (on tablets) or a {@link MedicamentDetailActivity} + * on handsets. + */ +public class MedicamentDetailFragment extends Fragment { + /** + * The fragment argument representing the item ID that this fragment + * represents. + */ + public static final String ARG_ITEM_ID = "item_id"; + + /** + * The dummy content this fragment is presenting. + */ + private DummyContent.DummyItem mItem; + + /** + * Mandatory empty constructor for the fragment manager to instantiate the + * fragment (e.g. upon screen orientation changes). + */ + public MedicamentDetailFragment() { + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + if (getArguments().containsKey(ARG_ITEM_ID)) { + // Load the dummy content specified by the fragment + // arguments. In a real-world scenario, use a Loader + // to load content from a content provider. + mItem = DummyContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID)); + + Activity activity = this.getActivity(); + CollapsingToolbarLayout appBarLayout = (CollapsingToolbarLayout) activity.findViewById(R.id.toolbar_layout); + if (appBarLayout != null) { + appBarLayout.setTitle(mItem.content); + } + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.medicament_detail, container, false); + + // Show the dummy content as text in a TextView. + if (mItem != null) { + ((TextView) rootView.findViewById(R.id.medicament_detail)).setText(mItem.details); + } + + return rootView; + } +} diff --git a/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java new file mode 100644 index 0000000..5b10f5d --- /dev/null +++ b/app/src/main/java/net/foucry/pilldroid/MedicamentListActivity.java @@ -0,0 +1,142 @@ +package net.foucry.pilldroid; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.Toolbar; +import android.support.design.widget.FloatingActionButton; +import android.support.design.widget.Snackbar; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + + +import net.foucry.pilldroid.dummy.DummyContent; + +import java.util.List; + +/** + * An activity representing a list of Medicaments. This activity + * has different presentations for handset and tablet-size devices. On + * handsets, the activity presents a list of items, which when touched, + * lead to a {@link MedicamentDetailActivity} representing + * item details. On tablets, the activity presents the list of items and + * item details side-by-side using two vertical panes. + */ +public class MedicamentListActivity extends AppCompatActivity { + + /** + * Whether or not the activity is in two-pane mode, i.e. running on a tablet + * device. + */ + private boolean mTwoPane; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_medicament_list); + + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + toolbar.setTitle(getTitle()); + + FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); + fab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) + .setAction("Action", null).show(); + } + }); + + View recyclerView = findViewById(R.id.medicament_list); + assert recyclerView != null; + setupRecyclerView((RecyclerView) recyclerView); + + if (findViewById(R.id.medicament_detail_container) != null) { + // The detail container view will be present only in the + // large-screen layouts (res/values-w900dp). + // If this view is present, then the + // activity should be in two-pane mode. + mTwoPane = true; + } + } + + private void setupRecyclerView(@NonNull RecyclerView recyclerView) { + recyclerView.setAdapter(new SimpleItemRecyclerViewAdapter(DummyContent.ITEMS)); + } + + public class SimpleItemRecyclerViewAdapter + extends RecyclerView.Adapter { + + private final List mValues; + + public SimpleItemRecyclerViewAdapter(List items) { + mValues = items; + } + + @Override + public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.medicament_list_content, parent, false); + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(final ViewHolder holder, int position) { + holder.mItem = mValues.get(position); + holder.mIdView.setText(mValues.get(position).id); + holder.mContentView.setText(mValues.get(position).content); + + holder.mView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (mTwoPane) { + Bundle arguments = new Bundle(); + arguments.putString(MedicamentDetailFragment.ARG_ITEM_ID, holder.mItem.id); + MedicamentDetailFragment fragment = new MedicamentDetailFragment(); + fragment.setArguments(arguments); + getSupportFragmentManager().beginTransaction() + .replace(R.id.medicament_detail_container, fragment) + .commit(); + } else { + Context context = v.getContext(); + Intent intent = new Intent(context, MedicamentDetailActivity.class); + intent.putExtra(MedicamentDetailFragment.ARG_ITEM_ID, holder.mItem.id); + + context.startActivity(intent); + } + } + }); + } + + @Override + public int getItemCount() { + return mValues.size(); + } + + public class ViewHolder extends RecyclerView.ViewHolder { + public final View mView; + public final TextView mIdView; + public final TextView mContentView; + public DummyContent.DummyItem mItem; + + public ViewHolder(View view) { + super(view); + mView = view; + mIdView = (TextView) view.findViewById(R.id.id); + mContentView = (TextView) view.findViewById(R.id.content); + } + + @Override + public String toString() { + return super.toString() + " '" + mContentView.getText() + "'"; + } + } + } +} diff --git a/app/src/main/java/net/foucry/pilldroid/UtilDate.java b/app/src/main/java/net/foucry/pilldroid/UtilDate.java new file mode 100644 index 0000000..e7f2cb0 --- /dev/null +++ b/app/src/main/java/net/foucry/pilldroid/UtilDate.java @@ -0,0 +1,94 @@ +package net.foucry.medicament; + +import android.util.Log; + +import java.text.DateFormat; +import java.text.ParsePosition; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +/** + * Created by jacques on 05/05/16. + */ +public class UtilDate { + + /** + * + * @param aDate + * @return date + * + * set date time at Noon + */ + public static Date dateAtNoon(Date aDate) { + + Log.d(CustomizedListView.Constants.TAG, "dateAtNoon " + aDate); + + Calendar calendar = Calendar.getInstance(); + calendar.setTime(aDate); + calendar.set(Calendar.HOUR_OF_DAY, 12); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.SECOND, 0); + + return calendar.getTime(); + } + + /** + * + * @param days + * @param date + * @return date + * + * Substract days to date and return a new date + */ + public static Date removeDaysToDate(int days, Date date) { + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + calendar.add(Calendar.DAY_OF_YEAR, -days); + + return calendar.getTime(); + } + + /** + * + * @param date + * @return String + * + * Convert a date to a String using a SimpleDateFormat + */ + public static String date2String(Date date, DateFormat dateFormat) { + + Log.d(CustomizedListView.Constants.TAG, "date == " + date); + + Calendar calendar = Calendar.getInstance(); + calendar.setTime(date); + + return dateFormat.format(calendar.getTime()); + } + + /** + * + * @param dateString + * @return date + * + * Convert String date into Date + */ + public static Date string2Date(String dateString) { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + ParsePosition pos = new ParsePosition(0); + return dateFormat.parse(dateString,pos); + } + + /** + * + * @param date + * @return int + * + * Number of days between date (older than today) and today + */ + public static int nbOfDaysBetweenDateAndToday(Date date) { + Date oldDate = dateAtNoon(date); // Be sure that the old date is at Noon + Date todayDate = dateAtNoon(new Date()); // Be sure that we use today at Noon + + return (int) (todayDate.getTime() - oldDate.getTime()); + } +} diff --git a/app/src/main/java/net/foucry/pilldroid/Utils.java b/app/src/main/java/net/foucry/pilldroid/Utils.java new file mode 100644 index 0000000..70e377b --- /dev/null +++ b/app/src/main/java/net/foucry/pilldroid/Utils.java @@ -0,0 +1,32 @@ +package net.foucry.medicament; + +import java.io.InputStream; +import java.io.OutputStream; + +import java.util.Random; +import java.lang.Math; + +public class Utils { + public static void CopyStream(InputStream is, OutputStream os) + { + final int buffer_size=1024; + try + { + byte[] bytes=new byte[buffer_size]; + for(;;) + { + int count=is.read(bytes, 0, buffer_size); + if(count==-1) + break; + os.write(bytes, 0, count); + } + } + catch(Exception ex){} + } + + public static final double doubleRandomInclusive(int min, int max) { + double value = Math.floor(min + (max - min) * CustomizedListView.random.nextDouble() *4)/4; + + return value; + } +} \ No newline at end of file diff --git a/app/src/main/java/net/foucry/pilldroid/dummy/DummyContent.java b/app/src/main/java/net/foucry/pilldroid/dummy/DummyContent.java new file mode 100644 index 0000000..8a110fc --- /dev/null +++ b/app/src/main/java/net/foucry/pilldroid/dummy/DummyContent.java @@ -0,0 +1,72 @@ +package net.foucry.pilldroid.dummy; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Helper class for providing sample content for user interfaces created by + * Android template wizards. + *

+ * TODO: Replace all uses of this class before publishing your app. + */ +public class DummyContent { + + /** + * An array of sample (dummy) items. + */ + public static final List ITEMS = new ArrayList(); + + /** + * A map of sample (dummy) items, by ID. + */ + public static final Map ITEM_MAP = new HashMap(); + + private static final int COUNT = 25; + + static { + // Add some sample items. + for (int i = 1; i <= COUNT; i++) { + addItem(createDummyItem(i)); + } + } + + private static void addItem(DummyItem item) { + ITEMS.add(item); + ITEM_MAP.put(item.id, item); + } + + private static DummyItem createDummyItem(int position) { + return new DummyItem(String.valueOf(position), "Item " + position, makeDetails(position)); + } + + private static String makeDetails(int position) { + StringBuilder builder = new StringBuilder(); + builder.append("Details about Item: ").append(position); + for (int i = 0; i < position; i++) { + builder.append("\nMore details information here."); + } + return builder.toString(); + } + + /** + * A dummy item representing a piece of content. + */ + public static class DummyItem { + public final String id; + public final String content; + public final String details; + + public DummyItem(String id, String content, String details) { + this.id = id; + this.content = content; + this.details = details; + } + + @Override + public String toString() { + return content; + } + } +} diff --git a/app/src/main/res/drawable/gradient_bg_alert.xml b/app/src/main/res/drawable/gradient_bg_alert.xml new file mode 100644 index 0000000..7d58d72 --- /dev/null +++ b/app/src/main/res/drawable/gradient_bg_alert.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/gradient_bg_ok.xml b/app/src/main/res/drawable/gradient_bg_ok.xml new file mode 100644 index 0000000..e2ea5eb --- /dev/null +++ b/app/src/main/res/drawable/gradient_bg_ok.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/gradient_bg_warning.xml b/app/src/main/res/drawable/gradient_bg_warning.xml new file mode 100644 index 0000000..59190ce --- /dev/null +++ b/app/src/main/res/drawable/gradient_bg_warning.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/line_divider.xml b/app/src/main/res/drawable/line_divider.xml new file mode 100644 index 0000000..b865b8d --- /dev/null +++ b/app/src/main/res/drawable/line_divider.xml @@ -0,0 +1,11 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/stock_alert.png b/app/src/main/res/drawable/stock_alert.png new file mode 100755 index 0000000..a457eb1 Binary files /dev/null and b/app/src/main/res/drawable/stock_alert.png differ diff --git a/app/src/main/res/drawable/stock_ok.png b/app/src/main/res/drawable/stock_ok.png new file mode 100755 index 0000000..fff5c6b Binary files /dev/null and b/app/src/main/res/drawable/stock_ok.png differ diff --git a/app/src/main/res/drawable/stock_warn.png b/app/src/main/res/drawable/stock_warn.png new file mode 100755 index 0000000..54e7281 Binary files /dev/null and b/app/src/main/res/drawable/stock_warn.png differ diff --git a/app/src/main/res/layout-w900dp/medicament_list.xml b/app/src/main/res/layout-w900dp/medicament_list.xml new file mode 100644 index 0000000..563f006 --- /dev/null +++ b/app/src/main/res/layout-w900dp/medicament_list.xml @@ -0,0 +1,38 @@ + + + + + + + + + diff --git a/app/src/main/res/layout/activity_medicament_detail.xml b/app/src/main/res/layout/activity_medicament_detail.xml new file mode 100644 index 0000000..160cdae --- /dev/null +++ b/app/src/main/res/layout/activity_medicament_detail.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_medicament_list.xml b/app/src/main/res/layout/activity_medicament_list.xml new file mode 100644 index 0000000..4f86cdd --- /dev/null +++ b/app/src/main/res/layout/activity_medicament_list.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/medicament_detail.xml b/app/src/main/res/layout/medicament_detail.xml new file mode 100644 index 0000000..c08e7cb --- /dev/null +++ b/app/src/main/res/layout/medicament_detail.xml @@ -0,0 +1,9 @@ + diff --git a/app/src/main/res/layout/medicament_list.xml b/app/src/main/res/layout/medicament_list.xml new file mode 100644 index 0000000..4b4db2f --- /dev/null +++ b/app/src/main/res/layout/medicament_list.xml @@ -0,0 +1,13 @@ + + diff --git a/app/src/main/res/layout/medicament_list_content.xml b/app/src/main/res/layout/medicament_list_content.xml new file mode 100644 index 0000000..3df9ca7 --- /dev/null +++ b/app/src/main/res/layout/medicament_list_content.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..7a892ff Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..8ad3ae5 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..2842f95 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..5451428 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..7c7d259 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml new file mode 100644 index 0000000..dbbdd40 --- /dev/null +++ b/app/src/main/res/values-v21/styles.xml @@ -0,0 +1,9 @@ + + + + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..3ab3e9c --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #3F51B5 + #303F9F + #FF4081 + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..868016b --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,7 @@ + + + 16dp + 200dp + 200dp + 16dp + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..9684ed6 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + PillDroid + Medicament Detail + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..545b9c6 --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,20 @@ + + + + + + + +