Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supulkalhara ci workflow #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/android_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Android CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:
runs-on: macos-latest
strategy:
matrix:
api-level: [21, 23, 29]
steps:
- name: checkout
uses: actions/checkout@v3

- name: Gradle cache
uses: gradle/gradle-build-action@v2

- name: AVD cache
uses: actions/cache@v3
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ matrix.api-level }}

- name: create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
script: echo "Generated AVD snapshot for caching."

- name: run tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: ./gradlew connectedCheck
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,21 @@ The current implementation is non-persistent. Therefore all the account informat

Your task is to make the storage of account information and transactions persistent, using an embedded database such as SQLite as the persistent storage.

In order to achieve this you should implement the two interfaces, [`AccountDAO`](/app/src/main/java/lk/ac/mrt/cse/dbs/simpleexpensemanager/data/AccountDAO.java) and [`TransactionDAO`](/app/src/main/java/lk/ac/mrt/cse/dbs/simpleexpensemanager/data/TransactionDAO.java). These two interfaces follow the “Data Access Object” Design pattern [1](http://www.oracle.com/technetwork/java/dataaccessobject-138824.html) [2](http://www.tutorialspoint.com/design_pattern/data_access_object_pattern.htm). You can refer the current In-Memory implementation ([`InMemoryAccountDAO`](/app/src/main/java/lk/ac/mrt/cse/dbs/simpleexpensemanager/data/impl/InMemoryAccountDAO.java), [`InMemoryTransactionDAO`](/app/src/main/java/lk/ac/mrt/cse/dbs/simpleexpensemanager/data/impl/InMemoryTransactionDAO.java)) to get an idea of the current implementation.
In order to achieve this you should implement the two interfaces, [`AccountDAO`](/app/src/main/java/lk/ac/mrt/cse/dbs/simpleexpensemanager/data/AccountDAO.java)
and [`TransactionDAO`](/app/src/main/java/lk/ac/mrt/cse/dbs/simpleexpensemanager/data/TransactionDAO.java).
These two interfaces follow the “Data Access Object” Design pattern [1](http://www.oracle.com/technetwork/java/dataaccessobject-138824.html)
[2](http://www.tutorialspoint.com/design_pattern/data_access_object_pattern.htm).
You can refer the current In-Memory implementation ([`InMemoryAccountDAO`](/app/src/main/java/lk/ac/mrt/cse/dbs/simpleexpensemanager/data/impl/InMemoryAccountDAO.java),
[`InMemoryTransactionDAO`](/app/src/main/java/lk/ac/mrt/cse/dbs/simpleexpensemanager/data/impl/InMemoryTransactionDAO.java))
to get an idea of the current implementation.

After you have implemented the two interfaces, you can use these implementations to setup the application to use the persistent storage instead of the existing in-memory storage. In order to do that you should implement the `setup()` method of the abstract class [`ExpenseManager`](/app/src/main/java/lk/ac/mrt/cse/dbs/simpleexpensemanager/control/ExpenseManager.java). You can refer the current concrete implementation ([`InMemoryDemoExpenseManager`](/app/src/main/java/lk/ac/mrt/cse/dbs/simpleexpensemanager/control/InMemoryDemoExpenseManager.java)) of this class to get an idea.
After you have implemented the two interfaces, you can use these implementations to setup the application to use the persistent storage instead of the existing in-memory storage.
In order to do that you should implement the `setup()` method of the abstract class [`ExpenseManager`](/app/src/main/java/lk/ac/mrt/cse/dbs/simpleexpensemanager/control/ExpenseManager.java).
You can refer the current concrete implementation ([`InMemoryDemoExpenseManager`](/app/src/main/java/lk/ac/mrt/cse/dbs/simpleexpensemanager/control/InMemoryDemoExpenseManager.java)) of this class to get an idea.

After you have completed implementation of the [`ExpenseManager`](/app/src/main/java/lk/ac/mrt/cse/dbs/simpleexpensemanager/control/ExpenseManager.java) class, go to [`MainActivity`](/app/src/main/java/lk/ac/mrt/cse/dbs/simpleexpensemanager/ui/MainActivity.java) class in the ui package and change the existing implementation to your implementation.
After you have completed implementation of the [`ExpenseManager`](/app/src/main/java/lk/ac/mrt/cse/dbs/simpleexpensemanager/control/ExpenseManager.java) class,
go to [`MainActivity`](/app/src/main/java/lk/ac/mrt/cse/dbs/simpleexpensemanager/ui/MainActivity.java)
class in the ui package and change the existing implementation to your implementation.

eg:

Expand All @@ -32,7 +42,8 @@ expenseManager = new PersistentExpenseManager(context);
/*** END ***/
```

You can make improvements to the project as you require. However this project is designed to act as a skeleton and minimize involvement in other components such as the UI. Therefore your main effort should be focused on implementing the persistent storage using an embedded database.
You can make improvements to the project as you require. However this project is designed to act as a skeleton and minimize involvement in other components such as the UI.
Therefore your main effort should be focused on implementing the persistent storage using an embedded database.

## Instructions
1. Fork the GitHub project - https://github.com/GayashanNA/SimpleExpenseManager
Expand All @@ -45,15 +56,15 @@ You can make improvements to the project as you require. However this project is

Current implementation
```Java
/*** Begin generating dummy data for In-Memory implementation ***/
/*** Begin generating dummy data for In-Memory implementation
expenseManager = new InMemoryDemoExpenseManager();
/*** END ***/
END ***/
```
Your implementation
```Java
/*** Setup the persistent storage implementation ***/
/*** Setup the persistent storage implementation
expenseManager = new PersistentExpenseManager(context);
/*** END ***/
END ***/
```
6. Commit your code and push to your forked repository in GitHub.
7. Download your project as a Zip from GitHub and submit as the completed assignment.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2015 Department of Computer Science and Engineering, University of Moratuwa.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package lk.ac.mrt.cse.dbs.simpleexpensemanager.control;

import android.content.Context;

import lk.ac.mrt.cse.dbs.simpleexpensemanager.data.AccountDAO;
import lk.ac.mrt.cse.dbs.simpleexpensemanager.data.TransactionDAO;
import lk.ac.mrt.cse.dbs.simpleexpensemanager.data.impl.InMemoryAccountDAO;
import lk.ac.mrt.cse.dbs.simpleexpensemanager.data.impl.InMemoryTransactionDAO;
import lk.ac.mrt.cse.dbs.simpleexpensemanager.data.impl.PersistentAccountDAO;
import lk.ac.mrt.cse.dbs.simpleexpensemanager.data.impl.PersistentTransactionDAO;
import lk.ac.mrt.cse.dbs.simpleexpensemanager.data.model.Account;

/**
*
*/
public class PersistentDemoExpenseManager extends ExpenseManager {

public Context context;
public PersistentDemoExpenseManager(Context context) {
this.context = context;
setup();
}

@Override
public void setup() {
/*** Begin generating dummy data for In-Memory implementation ***/

// TransactionDAO inMemoryDAOTransactionDAO = new InMemoryTransactionDAO();
TransactionDAO persistentTransactionDAO = new PersistentTransactionDAO(context);
setTransactionsDAO(persistentTransactionDAO);

// AccountDAO inMemoryAccountDAO = new InMemoryAccountDAO();

AccountDAO persistentAccountDAO = new PersistentAccountDAO(context);
setAccountsDAO(persistentAccountDAO);

// dummy data
// Account dummyAcct1 = new Account("12345A", "Yoda Bank", "Anakin Skywalker", 10000.0);
// Account dummyAcct2 = new Account("78945Z", "Clone BC", "Obi-Wan Kenobi", 80000.0);
// getAccountsDAO().addAccount(dummyAcct1);
// getAccountsDAO().addAccount(dummyAcct2);

/*** End ***/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ public interface AccountDAO {
* Add an account to the accounts collection.
*
* @param account - the account to be added.
* @return
*/
public void addAccount(Account account);
public boolean addAccount(Account account);

/***
* Remove an account from the accounts collection.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package lk.ac.mrt.cse.dbs.simpleexpensemanager.data;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.annotation.Nullable;

public class DataBaseManager extends SQLiteOpenHelper {

public static final String ACCOUNT_TABLE = "ACCOUNT_TABLE";
public static final String ACCOUNT_NUMBER = "ACCOUNT_NUMBER";
public static final String BANK_NAME = "BANK_NAME";
public static final String ACCOUNT_HOLDER_NAME = "ACCOUNT_HOLDER_NAME";
public static final String BALANCE = "BALANCE";
public static final String TRANSACTION_TABLE = "TRANSACTION_TABLE";
public static final String ID = "ID";
public static final String TYPE = "TYPE";
public static final String DATE = "DATE";
public static final String AMOUNT = "AMOUNT";

public DataBaseManager(@Nullable Context context) {
super(context, "190482K.db", null, 1);
}

@Override
public void onCreate(SQLiteDatabase SqLiteDb) {
String tableStatementForAddAccount = "CREATE TABLE " +
ACCOUNT_TABLE + " (" +
ACCOUNT_NUMBER + " INTEGER PRIMARY KEY AUTOINCREMENT," +
BANK_NAME + " TEXT," +
ACCOUNT_HOLDER_NAME + " TEXT," +
BALANCE + " REAL" + ")";

SqLiteDb.execSQL(tableStatementForAddAccount);

String tableStatementForTransaction = "CREATE TABLE " +
TRANSACTION_TABLE + " (" +
ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
ACCOUNT_NUMBER + " INTEGER," +
TYPE + " INTEGER," +
DATE + " TEXT," +
AMOUNT + " REAL" + ")";

SqLiteDb.execSQL(tableStatementForTransaction);
}

@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int acc_no, int type) {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public interface TransactionDAO {

/***
* Log the transaction requested by the user.
*
* @param date - date of the transaction
* @param accountNo - account number involved
* @param expenseType - type of the expense
* @param amount - amount involved
* @return
*/
public void logTransaction(Date date, String accountNo, ExpenseType expenseType, double amount);
public boolean logTransaction(Date date, String accountNo, ExpenseType expenseType, double amount);

/***
* Return all the transactions logged.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* This is an In-Memory implementation of the AccountDAO interface. This is not a persistent storage. A HashMap is
* used to store the account details temporarily in the memory.
*/
public class InMemoryAccountDAO implements AccountDAO {
public class InMemoryAccountDAO implements AccountDAO {
private final Map<String, Account> accounts;

public InMemoryAccountDAO() {
Expand All @@ -57,8 +57,9 @@ public Account getAccount(String accountNo) throws InvalidAccountException {
}

@Override
public void addAccount(Account account) {
public boolean addAccount(Account account) {
accounts.put(account.getAccountNo(), account);
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@
* transaction logs are stored in a LinkedList in memory.
*/
public class InMemoryTransactionDAO implements TransactionDAO {

private final List<Transaction> transactions;

public InMemoryTransactionDAO() {
transactions = new LinkedList<>();
}

@Override
public void logTransaction(Date date, String accountNo, ExpenseType expenseType, double amount) {
public boolean logTransaction(Date date, String accountNo, ExpenseType expenseType, double amount) {
Transaction transaction = new Transaction(date, accountNo, expenseType, amount);
transactions.add(transaction);
return false;
}

@Override
Expand Down
Loading