Skip to content

Commit

Permalink
Merge pull request #3 from philippluxi/release/v0.1
Browse files Browse the repository at this point in the history
Release/v0.1
  • Loading branch information
philippluxi authored Dec 31, 2020
2 parents 9054bc8 + c1397d8 commit 19f2b01
Show file tree
Hide file tree
Showing 20 changed files with 446 additions and 36 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Archaeological_Fieldwork
Repository for submission for the Android programming course at the OTH Regensburg in the winter semester 2020/2021.

### Purpose of the application
In the final version, places are to be stored, displayed and managed together with title, description and pictures.
In an extended version, the data storage takes place in Firebase and notes and ratings can be given for the places.
9 changes: 8 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
defaultConfig {
applicationId "com.archaeologicalfieldwork"
minSdkVersion 23
targetSdkVersion 30
targetSdkVersion 29
versionCode 1
versionName "1.0"

Expand All @@ -34,4 +34,11 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

//*************Own Implementations*************
//Anko Logger
implementation 'org.jetbrains.anko:anko-commons:0.10.8'

//Material Design
implementation 'com.google.android.material:material:1.2.0'

}
7 changes: 6 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@
package="com.archaeologicalfieldwork">

<application
android:name="com.archaeologicalfieldwork.main.MainApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">

<activity android:name=".activities.SpotActivity"></activity>

<activity android:name=".activities.SpotListActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

</manifest>
11 changes: 0 additions & 11 deletions app/src/main/java/com/archaeologicalfieldwork/MainActivity.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.archaeologicalfieldwork.activities

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import kotlinx.android.synthetic.main.activity_spot.*
import org.jetbrains.anko.info
import org.jetbrains.anko.toast
import org.jetbrains.anko.AnkoLogger
import com.archaeologicalfieldwork.R
import com.archaeologicalfieldwork.main.MainApp
import com.archaeologicalfieldwork.models.SpotModel

class SpotActivity : AppCompatActivity(), AnkoLogger {

var spot = SpotModel()
lateinit var app: MainApp
var edit = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_spot)
toolbarAdd.title = title
setSupportActionBar(toolbarAdd)
info("Add Spot Activity started...")

app = application as MainApp

// Retrieve passed Spot info via Parcelize
if (intent.hasExtra("spot_edit")) {
edit = true

spot = intent.extras?.getParcelable<SpotModel>("spot_edit")!!
spotTitle.setText(spot.title)
spotDescription.setText(spot.desription)

btnAddSpot.setText(R.string.button_save_spot)
}

// Handle Add Button Press
btnAddSpot.setOnClickListener() {
spot.title = spotTitle.text.toString()
spot.desription = spotDescription.text.toString()

if (spot.title.isEmpty()) {
toast(R.string.enter_spot_title)
} else {
if (edit) {
app.spots.update(spot.copy())
} else {
app.spots.create(spot.copy())
}
info("add Button pressed: ${spot}")
app.spots.logAll()
setResult(AppCompatActivity.RESULT_OK)
finish()
}
}
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu_new_spot, menu)
return super.onCreateOptionsMenu(menu)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.item_cancel -> {
finish()
}
}
return super.onOptionsItemSelected(item)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.archaeologicalfieldwork.activities

import android.view.View
import android.view.ViewGroup
import android.view.LayoutInflater
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.card_spot.view.*
import com.archaeologicalfieldwork.R
import com.archaeologicalfieldwork.models.SpotModel

interface SpotListener {
fun onSpotClick(spot: SpotModel)
}

class SpotAdapter constructor(
private var spots: List<SpotModel>,
private val listener: SpotListener
) : RecyclerView.Adapter<SpotAdapter.MainHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MainHolder {
return MainHolder(
LayoutInflater.from(parent?.context).inflate(
R.layout.card_spot,
parent,
false
)
)
}

override fun onBindViewHolder(holder: MainHolder, position: Int) {
val spot = spots[holder.adapterPosition]
holder.bind(spot, listener)
}

override fun getItemCount(): Int = spots.size

class MainHolder constructor(itemView: View) : RecyclerView.ViewHolder(itemView) {

fun bind(spot: SpotModel, listener: SpotListener) {
itemView.spotTitle_Card.text = spot.title
itemView.spotDescription_Card.text = spot.desription
itemView.setOnClickListener { listener.onSpotClick(spot) }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.archaeologicalfieldwork.activities

import android.content.Intent
import android.os.Bundle
import android.view.*
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.activity_spot_list.*
import org.jetbrains.anko.AnkoLogger
import org.jetbrains.anko.intentFor
import org.jetbrains.anko.startActivityForResult
import com.archaeologicalfieldwork.R
import com.archaeologicalfieldwork.main.MainApp
import com.archaeologicalfieldwork.models.SpotModel


class SpotListActivity : AppCompatActivity(), SpotListener, AnkoLogger {

lateinit var app: MainApp

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_spot_list)
app = application as MainApp

toolbar.title = title
setSupportActionBar(toolbar)

val layoutManager = LinearLayoutManager(this)
recyclerView.layoutManager = layoutManager
recyclerView.adapter = SpotAdapter(app.spots.findAll(), this)
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu_main, menu)
return super.onCreateOptionsMenu(menu)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.item_add -> startActivityForResult<SpotActivity>(0)
}
return super.onOptionsItemSelected(item)
}

override fun onSpotClick(spot: SpotModel) {
startActivityForResult(intentFor<SpotActivity>().putExtra("spot_edit", spot), 0)
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
recyclerView.adapter?.notifyDataSetChanged()
super.onActivityResult(requestCode, resultCode, data)
}
}
16 changes: 16 additions & 0 deletions app/src/main/java/com/archaeologicalfieldwork/main/MainApp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.archaeologicalfieldwork.main

import android.app.Application
import org.jetbrains.anko.info
import org.jetbrains.anko.AnkoLogger
import com.archaeologicalfieldwork.models.SpotMemStore

class MainApp : Application(), AnkoLogger {

val spots = SpotMemStore()

override fun onCreate() {
super.onCreate()
info("Archaelogical Fieldwork started")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.archaeologicalfieldwork.models

import java.util.ArrayList
import org.jetbrains.anko.info
import org.jetbrains.anko.AnkoLogger

var lastId = 0L

internal fun getId(): Long {
return lastId++
}

class SpotMemStore : SpotStore, AnkoLogger {

val spots = ArrayList<SpotModel>()

override fun findAll(): List<SpotModel> {
return spots
}

override fun create(spot: SpotModel) {
spot.id = getId()
spots.add(spot)
logAll()
}

override fun update(spot: SpotModel) {
var foundSpot: SpotModel? = spots.find { spot_iterator -> spot_iterator.id == spot.id }
if (foundSpot != null) {
foundSpot.title = spot.title
foundSpot.desription = spot.desription
}
}

fun logAll() {
spots.forEach { info("${it}") }
}
}
11 changes: 11 additions & 0 deletions app/src/main/java/com/archaeologicalfieldwork/models/SpotModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.archaeologicalfieldwork.models

import android.os.Parcelable
import kotlinx.android.parcel.Parcelize

@Parcelize
data class SpotModel(
var id: Long = 0,
var title: String = "",
var desription: String = ""
) : Parcelable
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.archaeologicalfieldwork.models

interface SpotStore {
fun findAll(): List<SpotModel>
fun create(spot: SpotModel)
fun update(spot: SpotModel)
}
18 changes: 0 additions & 18 deletions app/src/main/res/layout/activity_main.xml

This file was deleted.

Loading

0 comments on commit 19f2b01

Please sign in to comment.