-
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.
Merge pull request #3 from philippluxi/release/v0.1
Release/v0.1
- Loading branch information
Showing
20 changed files
with
446 additions
and
36 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
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. |
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
11 changes: 0 additions & 11 deletions
11
app/src/main/java/com/archaeologicalfieldwork/MainActivity.kt
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
app/src/main/java/com/archaeologicalfieldwork/activities/SpotActivity.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,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) | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
app/src/main/java/com/archaeologicalfieldwork/activities/SpotAdapter.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,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) } | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
app/src/main/java/com/archaeologicalfieldwork/activities/SpotListActivity.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,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
16
app/src/main/java/com/archaeologicalfieldwork/main/MainApp.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,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") | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
app/src/main/java/com/archaeologicalfieldwork/models/SpotMemStore.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,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
11
app/src/main/java/com/archaeologicalfieldwork/models/SpotModel.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,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 |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/archaeologicalfieldwork/models/SpotStore.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,7 @@ | ||
package com.archaeologicalfieldwork.models | ||
|
||
interface SpotStore { | ||
fun findAll(): List<SpotModel> | ||
fun create(spot: SpotModel) | ||
fun update(spot: SpotModel) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.