commit
661a0d56fc
@ -0,0 +1,58 @@ |
||||
package net.pokeranalytics.android.ui.view |
||||
|
||||
import android.widget.FrameLayout |
||||
import android.content.Context |
||||
import android.graphics.Color |
||||
import android.util.AttributeSet |
||||
import android.view.LayoutInflater |
||||
import androidx.constraintlayout.widget.ConstraintLayout |
||||
import kotlinx.android.synthetic.main.row_session.view.* |
||||
import net.pokeranalytics.android.R |
||||
import net.pokeranalytics.android.model.realm.Session |
||||
import timber.log.Timber |
||||
|
||||
|
||||
class SessionRowView : FrameLayout { |
||||
|
||||
private lateinit var rowHistorySession: ConstraintLayout |
||||
|
||||
/** |
||||
* Constructors |
||||
*/ |
||||
constructor(context: Context) : super(context) { |
||||
init() |
||||
} |
||||
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) { |
||||
init() |
||||
} |
||||
|
||||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { |
||||
init() |
||||
} |
||||
|
||||
/** |
||||
* Init |
||||
* |
||||
* @param attrs |
||||
*/ |
||||
private fun init() { |
||||
val layoutInflater = LayoutInflater.from(context) |
||||
rowHistorySession = layoutInflater.inflate(R.layout.row_session, this, false) as ConstraintLayout |
||||
val layoutParams = FrameLayout.LayoutParams( |
||||
FrameLayout.LayoutParams.MATCH_PARENT, |
||||
FrameLayout.LayoutParams.WRAP_CONTENT |
||||
) |
||||
|
||||
addView(rowHistorySession, layoutParams) |
||||
} |
||||
|
||||
/** |
||||
* Set the session data to the view |
||||
*/ |
||||
fun setData(session: Session) { |
||||
Timber.d("Set data: ${session.creationDate}") |
||||
rowHistorySession.date.text = session.creationDate.toString() |
||||
} |
||||
|
||||
} |
||||
@ -1,78 +0,0 @@ |
||||
package net.pokeranalytics.android.util.data |
||||
|
||||
import android.app.Application |
||||
import androidx.lifecycle.AndroidViewModel |
||||
import androidx.lifecycle.LiveData |
||||
import androidx.lifecycle.MutableLiveData |
||||
import io.realm.OrderedRealmCollectionChangeListener |
||||
import io.realm.Realm |
||||
import io.realm.RealmResults |
||||
import net.pokeranalytics.android.model.realm.Session |
||||
import net.pokeranalytics.android.util.data.sessionDao |
||||
|
||||
/** |
||||
* Session View Model |
||||
*/ |
||||
class SessionViewModel(application: Application) : AndroidViewModel(application) { |
||||
|
||||
private var realm = Realm.getDefaultInstance() |
||||
private var results: RealmResults<Session> |
||||
private val observablePlaces = MutableLiveData<List<Session>>() |
||||
|
||||
private var realmChangeListener = OrderedRealmCollectionChangeListener<RealmResults<Session>> { t, changeSet -> |
||||
observablePlaces.value = realm.copyFromRealm(t) |
||||
} |
||||
|
||||
init { |
||||
results = realm.sessionDao().findAllSessions() |
||||
} |
||||
|
||||
override fun onCleared() { |
||||
super.onCleared() |
||||
results.removeChangeListener(realmChangeListener) |
||||
realm.close() |
||||
} |
||||
|
||||
/** |
||||
* Get all sessions |
||||
*/ |
||||
fun getAllSessions(): LiveData<List<Session>> { |
||||
results.addChangeListener(realmChangeListener) |
||||
observablePlaces.value = realm.copyFromRealm(results) |
||||
return observablePlaces |
||||
} |
||||
|
||||
/** |
||||
* Get session by id |
||||
*/ |
||||
fun getSessionById(id: Int): Session? { |
||||
if (!realm.isClosed) { |
||||
val session = realm.sessionDao().findSessionById(id) |
||||
if (session != null) { |
||||
return realm.copyFromRealm(session) |
||||
} |
||||
} |
||||
return null |
||||
} |
||||
|
||||
/** |
||||
* Create or update a session |
||||
*/ |
||||
fun createOrUpdateSession(session: Session): Session? { |
||||
if (!realm.isClosed) { |
||||
return realm.sessionDao().createOrUpdateSession(session) |
||||
} |
||||
|
||||
return null |
||||
} |
||||
|
||||
/** |
||||
* Delete a session |
||||
*/ |
||||
fun deleteSession(sessionId: Int) { |
||||
if (!realm.isClosed) { |
||||
realm.sessionDao().deleteSession(sessionId) |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,31 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.constraintlayout.widget.ConstraintLayout |
||||
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
tools:context=".ui.activity.HomeActivity"> |
||||
|
||||
<FrameLayout |
||||
android:id="@+id/container" |
||||
android:layout_width="0dp" |
||||
android:layout_height="0dp" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintBottom_toTopOf="@+id/navigation" |
||||
app:layout_constraintTop_toTopOf="parent"/> |
||||
|
||||
<com.google.android.material.bottomnavigation.BottomNavigationView |
||||
android:id="@+id/navigation" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginEnd="0dp" |
||||
android:layout_marginStart="0dp" |
||||
android:background="?android:attr/windowBackground" |
||||
app:layout_constraintBottom_toBottomOf="parent" |
||||
app:layout_constraintLeft_toLeftOf="parent" |
||||
app:layout_constraintRight_toRightOf="parent" |
||||
app:menu="@menu/navigation"/> |
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
||||
@ -1,33 +0,0 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.constraintlayout.widget.ConstraintLayout |
||||
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:id="@+id/container" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
tools:context=".ui.activity.HomeActivity"> |
||||
|
||||
<TextView |
||||
android:id="@+id/message" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="@dimen/activity_horizontal_margin" |
||||
android:layout_marginLeft="@dimen/activity_horizontal_margin" |
||||
android:layout_marginTop="@dimen/activity_vertical_margin" |
||||
app:layout_constraintLeft_toLeftOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent"/> |
||||
|
||||
<com.google.android.material.bottomnavigation.BottomNavigationView |
||||
android:id="@+id/navigation" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginEnd="0dp" |
||||
android:layout_marginStart="0dp" |
||||
android:background="?android:attr/windowBackground" |
||||
app:layout_constraintBottom_toBottomOf="parent" |
||||
app:layout_constraintLeft_toLeftOf="parent" |
||||
app:layout_constraintRight_toRightOf="parent" |
||||
app:menu="@menu/navigation"/> |
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
||||
@ -1,23 +1,21 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.constraintlayout.widget.ConstraintLayout |
||||
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:id="@+id/container" |
||||
android:layout_width="match_parent" |
||||
android:background="#999999" |
||||
android:layout_height="match_parent" |
||||
tools:context=".ui.activity.HomeActivity"> |
||||
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:id="@+id/container" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
tools:context=".ui.activity.HomeActivity"> |
||||
|
||||
<TextView |
||||
android:id="@+id/title" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="@dimen/activity_horizontal_margin" |
||||
android:layout_marginLeft="@dimen/activity_horizontal_margin" |
||||
android:layout_marginTop="@dimen/activity_vertical_margin" |
||||
android:text="fragment" |
||||
app:layout_constraintLeft_toLeftOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent"/> |
||||
<androidx.recyclerview.widget.RecyclerView |
||||
android:id="@+id/recyclerView" |
||||
android:layout_width="0dp" |
||||
android:layout_height="0dp" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintBottom_toBottomOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent" |
||||
tools:listitem="@layout/row_history_session"/> |
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
||||
@ -1,23 +1,12 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.constraintlayout.widget.ConstraintLayout |
||||
<FrameLayout |
||||
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:padding="16dp"> |
||||
android:layout_height="wrap_content"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/date" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
android:layout_marginEnd="8dp" |
||||
android:layout_marginTop="8dp" |
||||
app:layout_constraintTop_toTopOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
android:layout_marginStart="8dp" |
||||
android:layout_marginBottom="8dp" |
||||
app:layout_constraintBottom_toBottomOf="parent"/> |
||||
<net.pokeranalytics.android.ui.view.SessionRowView |
||||
android:id="@+id/sessionRow" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" /> |
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
||||
</FrameLayout> |
||||
@ -0,0 +1,25 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.constraintlayout.widget.ConstraintLayout |
||||
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:padding="16dp"> |
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView |
||||
android:id="@+id/date" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
android:layout_marginEnd="8dp" |
||||
android:layout_marginTop="8dp" |
||||
android:textSize="16sp" |
||||
tools:text="This date" |
||||
app:layout_constraintTop_toTopOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
android:layout_marginStart="8dp" |
||||
android:layout_marginBottom="8dp" |
||||
app:layout_constraintBottom_toBottomOf="parent"/> |
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
||||
Loading…
Reference in new issue