|
|
|
|
@ -1,7 +1,9 @@ |
|
|
|
|
package net.pokeranalytics.android.ui.fragment.components.bottomsheet |
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint |
|
|
|
|
import android.app.Activity.RESULT_OK |
|
|
|
|
import android.app.Dialog |
|
|
|
|
import android.content.Intent |
|
|
|
|
import android.os.Bundle |
|
|
|
|
import android.view.LayoutInflater |
|
|
|
|
import android.view.View |
|
|
|
|
@ -9,11 +11,16 @@ import android.view.ViewGroup |
|
|
|
|
import android.view.WindowManager |
|
|
|
|
import androidx.fragment.app.FragmentManager |
|
|
|
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment |
|
|
|
|
import io.realm.RealmObject |
|
|
|
|
import kotlinx.android.synthetic.main.fragment_bottom_sheet.* |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.model.LiveData |
|
|
|
|
import net.pokeranalytics.android.ui.activity.EditableDataActivity |
|
|
|
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor |
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.SessionRow |
|
|
|
|
|
|
|
|
|
enum class BottomSheetType { |
|
|
|
|
NONE, |
|
|
|
|
@ -42,6 +49,9 @@ open class BottomSheetFragment : BottomSheetDialogFragment() { |
|
|
|
|
private var rowRepresentableEditDescriptors: ArrayList<RowRepresentableEditDescriptor> = ArrayList() |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
const val REQUEST_CODE_ADD_NEW_OBJECT = 100 |
|
|
|
|
|
|
|
|
|
fun create( |
|
|
|
|
fragmentManager: FragmentManager?, |
|
|
|
|
row: RowRepresentable, |
|
|
|
|
@ -78,6 +88,23 @@ open class BottomSheetFragment : BottomSheetDialogFragment() { |
|
|
|
|
initUI() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
|
|
|
|
super.onActivityResult(requestCode, resultCode, data) |
|
|
|
|
|
|
|
|
|
// If we come from a creation of an object an everything is okay, we call |
|
|
|
|
// the delegate onRowValueChanged with the newly created object |
|
|
|
|
if (requestCode == REQUEST_CODE_ADD_NEW_OBJECT && resultCode == RESULT_OK && data != null) { |
|
|
|
|
val dataType = data.getIntExtra(EditableDataActivity.IntentKey.DATA_TYPE.keyName, 0) |
|
|
|
|
val primaryKey = data.getStringExtra(EditableDataActivity.IntentKey.PRIMARY_KEY.keyName) |
|
|
|
|
val pokerAnalyticsActivity = activity as PokerAnalyticsActivity |
|
|
|
|
val liveDataType = LiveData.values()[dataType] |
|
|
|
|
val proxyItem: RealmObject? = liveDataType.getData(pokerAnalyticsActivity.getRealm(), primaryKey) |
|
|
|
|
this.delegate.onRowValueChanged(proxyItem, this.row) |
|
|
|
|
dismiss() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SuppressLint("RestrictedApi") |
|
|
|
|
override fun setupDialog(dialog: Dialog?, style: Int) { |
|
|
|
|
super.setupDialog(dialog, style) |
|
|
|
|
@ -103,7 +130,13 @@ open class BottomSheetFragment : BottomSheetDialogFragment() { |
|
|
|
|
true |
|
|
|
|
} |
|
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionAdd).setOnMenuItemClickListener { |
|
|
|
|
this.delegate.clickOnAdd(row) |
|
|
|
|
when (row) { |
|
|
|
|
SessionRow.GAME -> EditableDataActivity.newInstanceForResult(this, LiveData.GAME.ordinal, requestCode = REQUEST_CODE_ADD_NEW_OBJECT) |
|
|
|
|
SessionRow.BANKROLL -> EditableDataActivity.newInstanceForResult(this, LiveData.BANKROLL.ordinal, requestCode = REQUEST_CODE_ADD_NEW_OBJECT) |
|
|
|
|
SessionRow.LOCATION -> EditableDataActivity.newInstanceForResult(this, LiveData.LOCATION.ordinal, requestCode = REQUEST_CODE_ADD_NEW_OBJECT) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//this.delegate.clickOnAdd(row) |
|
|
|
|
true |
|
|
|
|
} |
|
|
|
|
bottomSheetToolbar.menu.findItem(R.id.actionCheck).setOnMenuItemClickListener { |
|
|
|
|
|