Skip to content

Commit

Permalink
Merge branch 'multi-list'
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephM101 committed Jul 26, 2022
2 parents a517a60 + b8e2954 commit e76809d
Show file tree
Hide file tree
Showing 28 changed files with 1,305 additions and 516 deletions.
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
minSdkVersion 26
targetSdkVersion 30
versionCode 2
versionName '2.4.4'
versionName '2.5.0'
android.defaultConfig.vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -19,6 +19,7 @@ android {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
applicationVariants.all { variant ->
variant.outputs.all {
// outputFileName = "PriceCalc_${variant.buildType.name}_v${defaultConfig.versionName}.apk"
Expand All @@ -43,6 +44,7 @@ dependencies {
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.preference:preference-ktx:1.1.1'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
implementation 'javax.json:javax.json-api:1.1.4'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.4-alpha06'
Expand All @@ -54,7 +56,7 @@ dependencies {
implementation 'com.opencsv:opencsv:5.5.2'
// https://mvnrepository.com/artifact/org.jsoup/jsoup
implementation 'org.jsoup:jsoup:1.14.3'

implementation 'com.google.code.gson:gson:2.9.0'
}
repositories {
mavenCentral()
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.PriceCalc">
<activity
android:name=".TextPromptDialog"
android:exported="false"
android:theme="@style/Theme.MaterialComponents.DayNight.Dialog"/>
<activity
android:name=".OpenList_Activity"
android:exported="true" />
android:exported="true"
android:theme="@style/Theme.MaterialComponents.DayNight.Dialog"></activity>
<activity android:name=".WelcomeScreen" />
<activity
android:name=".CheckForUpdates"
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/com/josephm101/pricecalc/About.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@ protected void onCreate(Bundle savedInstanceState) {
}
try {
PackageInfo pInfo = this.getPackageManager().getPackageInfo(this.getPackageName(), 0);
//Get info
// Get info
version = BuildConfig.VERSION_NAME;
buildType = BuildConfig.BUILD_TYPE;
fullPackageName = BuildConfig.APPLICATION_ID;
packageName = getString(R.string.app_name); //+ String.valueOf(BuildConfig.VERSION_CODE);
//Print info
// Print info
TextView packageName_textView = findViewById(R.id.packageName_textView);
TextView fullPackageName_textView = findViewById(R.id.fullPackageName_textView);
TextView appVersion_textView = findViewById(R.id.appVersion_textView);

packageName_textView.setText(packageName);
fullPackageName_textView.setText(fullPackageName);

//String appVersionString = version +
// "-" +
// buildType;
// String appVersionString = version +
// "-" +
// buildType;

String appVersionString = version;

Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/josephm101/pricecalc/ContextTattletale.java
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;
}
}
9 changes: 9 additions & 0 deletions app/src/main/java/com/josephm101/pricecalc/Defaults.java
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 app/src/main/java/com/josephm101/pricecalc/ExportToCsv.java
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 app/src/main/java/com/josephm101/pricecalc/FirstStart.java
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();
}
}
}
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;
}
}
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
}
}
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.
Loading

0 comments on commit e76809d

Please sign in to comment.