-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,305 additions
and
516 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/josephm101/pricecalc/ContextTattletale.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.josephm101.pricecalc; | ||
|
||
import android.content.Context; | ||
|
||
// This class gets context data, and then makes it available to all classes. | ||
public final class ContextTattletale { | ||
private static Context localContext; | ||
public static Context getLocalContext() { | ||
return localContext; | ||
} | ||
public static void setLocalContext(Context localContext) { | ||
ContextTattletale.localContext = localContext; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.josephm101.pricecalc; | ||
|
||
import android.content.Context; | ||
|
||
public class Defaults { | ||
public static String primarySavedListFileName = "/saved_list.txt"; | ||
|
||
public static String NameOfFirstList = "Default"; | ||
} |
69 changes: 69 additions & 0 deletions
69
app/src/main/java/com/josephm101/pricecalc/ExportToCsv.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.josephm101.pricecalc; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
|
||
import androidx.preference.PreferenceManager; | ||
|
||
import com.opencsv.CSVWriter; | ||
import com.opencsv.CSVWriterBuilder; | ||
import com.opencsv.ICSVWriter; | ||
|
||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ExportToCsv { | ||
// Gather all items, extract the data, and export everything to a .csv file. | ||
public static boolean ExportToCSV(Context context, ArrayList<DataModel> data, String DestinationFile) throws IOException { | ||
FileWriter fileWriter = new FileWriter(DestinationFile); | ||
ICSVWriter csvWriter = new CSVWriterBuilder(fileWriter).withSeparator(CSVWriter.DEFAULT_SEPARATOR).withEscapeChar(CSVWriter.DEFAULT_ESCAPE_CHARACTER).build(); | ||
String[] headerRecord = {"Item Name", "Item Price", "Quantity", "Tax Cost", "Total"}; | ||
String[] emptyLine = {"", "", "", "", ""}; | ||
String[] endHeader = {"", "", "", "Total:", ""}; | ||
|
||
csvWriter.writeNext(headerRecord); | ||
|
||
List<String[]> list = generateCsvData(data, context); | ||
for (String[] item : list) { | ||
csvWriter.writeNext(item); | ||
} | ||
|
||
// Add total to bottom of file if the setting "csvExport_AddTotalToFile_Preference" is set to true. | ||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()); | ||
if (sharedPreferences.getBoolean("csvExport_AddTotalToFile_Preference", false)) { | ||
// Empty line, followed by data | ||
csvWriter.writeNext(emptyLine); | ||
csvWriter.writeNext(endHeader); | ||
} | ||
|
||
csvWriter.close(); | ||
fileWriter.close(); | ||
return true; | ||
} | ||
|
||
public static ArrayList<String[]> generateCsvData(ArrayList<DataModel> data, Context context) { | ||
ArrayList<String[]> list = new ArrayList<String[]>(); | ||
for (DataModel dm : data) { | ||
String itemName = dm.getItemName(); | ||
double itemPrice = Double.parseDouble(dm.getItemPrice()); | ||
int itemQuantity = Integer.parseInt(dm.getItemQuantity()); | ||
//boolean isItemTaxable = dm.getIsTaxable(); | ||
|
||
double priceWithQuantity = (itemPrice * itemQuantity); | ||
double taxRate = PriceHandling.getDefaultTaxRatePercentage(context.getApplicationContext()); | ||
double priceTax = ((priceWithQuantity * taxRate) / 100); | ||
double totalCostOverall = priceWithQuantity + priceTax; | ||
|
||
// Convert values to strings | ||
String str_itemPrice = PriceHandling.PriceToString(itemPrice); | ||
String str_itemQuantity = String.valueOf(itemQuantity); | ||
String str_priceTax = PriceHandling.PriceToString(priceTax); | ||
String str_totalCost = PriceHandling.PriceToString(totalCostOverall); | ||
|
||
list.add(new String[]{itemName, str_itemPrice, str_itemQuantity, str_priceTax, str_totalCost}); | ||
} | ||
return list; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/josephm101/pricecalc/FirstStart.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.josephm101.pricecalc; | ||
|
||
import com.josephm101.pricecalc.ListFileHandler.Json.ListFileHandler; | ||
|
||
import java.io.IOException; | ||
|
||
public class FirstStart { | ||
public static void DoFirstStartSetup() { | ||
try { | ||
ListFileHandler.CreateNewList(Defaults.NameOfFirstList); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
app/src/main/java/com/josephm101/pricecalc/ListFileHandler/Common/ListInstance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.josephm101.pricecalc.ListFileHandler.Common; | ||
|
||
import com.josephm101.pricecalc.DataModel; | ||
|
||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.UUID; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.JsonElement; | ||
|
||
public class ListInstance implements Serializable { | ||
private UUID uuid; | ||
private String ListName; | ||
public ArrayList<DataModel> ListItems; | ||
|
||
public ListInstance (UUID uuid, String ListName, ArrayList<DataModel> ListItems) { | ||
this.uuid = uuid; | ||
this.ListName = ListName; | ||
this.ListItems = ListItems; | ||
} | ||
|
||
public boolean setListFriendlyName(String newListName) { | ||
if (newListName.isEmpty()) { | ||
return false; | ||
} else { | ||
this.ListName = newListName; | ||
return true; | ||
} | ||
} | ||
|
||
public String getListFriendlyName() { | ||
return this.ListName; | ||
} | ||
|
||
public UUID getUuid() { | ||
return this.uuid; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/com/josephm101/pricecalc/ListFileHandler/Common/ListInstanceArray.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.josephm101.pricecalc.ListFileHandler.Common | ||
|
||
import com.josephm101.pricecalc.ListFileHandler.Common.ListInstance | ||
import java.util.ArrayList | ||
|
||
// List collection data model (for JSON serialization) | ||
class ListInstanceArray { | ||
var lists: ArrayList<ListInstance> | ||
|
||
constructor() { | ||
lists = ArrayList() | ||
} | ||
|
||
constructor(lists: ArrayList<ListInstance>) { | ||
this.lists = lists | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
app/src/main/java/com/josephm101/pricecalc/ListFileHandler/Json/Class descriptions.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Here is an example of what the JSON file might look like: | ||
{ | ||
"lists": [ | ||
{ | ||
"uuid": "<uuid">, | ||
"friendlyName": "<User-set friendly name>", | ||
"data": <Serialized from DataModel> | ||
}, | ||
{ | ||
"uuid": "<different uuid">, | ||
"friendlyName": "<Other different user-friendly name>", | ||
"data": <Serialized from DataModel> | ||
} | ||
] | ||
} | ||
|
||
Theoretical benefits of using JSON format: | ||
- Items can be stored in a serialized format, simplifying saving/loading | ||
- The list instances can be easily iterated through, identified and updated by their UUIDs. | ||
|
||
NOTE: A non-unified approach may be taken if a unified approach ends up being clunky and problematic. | ||
What that would mean is, for example, instead of including all of the lists in a single file, they would be stored in individual files named by their UUIDs. | ||
If this ends up being the case, here's an example of what the contents would look like for each file. Assume filename = UUID. | ||
|
||
Here is an example of how individual JSON files might be formatted: | ||
{ | ||
"friendlyName": "<User-set friendly name>", | ||
"data": <Serialized from DataModel> | ||
} | ||
|
||
Class descriptions: | ||
|
||
-- ListFileHandler: The roots of the operation. This is the class that interfaces with the file(s) that contain the JSON data for each list. |
Oops, something went wrong.