-
-
Notifications
You must be signed in to change notification settings - Fork 677
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a WidgetConfigureActivity base class (#2488)
- Loading branch information
Showing
12 changed files
with
126 additions
and
287 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
app/src/main/java/io/homeassistant/companion/android/widgets/BaseWidgetConfigureActivity.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,50 @@ | ||
package io.homeassistant.companion.android.widgets | ||
|
||
import android.appwidget.AppWidgetManager | ||
import android.content.Context | ||
import android.view.View | ||
import android.widget.Toast | ||
import androidx.lifecycle.lifecycleScope | ||
import io.homeassistant.companion.android.BaseActivity | ||
import io.homeassistant.companion.android.common.R | ||
import io.homeassistant.companion.android.database.widget.WidgetDao | ||
import kotlinx.coroutines.launch | ||
|
||
abstract class BaseWidgetConfigureActivity : BaseActivity() { | ||
|
||
protected var appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID | ||
|
||
abstract val dao: WidgetDao | ||
|
||
protected val onDeleteWidget = View.OnClickListener { deleteConfirmation(it.context) } | ||
|
||
private fun deleteConfirmation(context: Context) { | ||
val builder: android.app.AlertDialog.Builder = android.app.AlertDialog.Builder(context) | ||
|
||
builder.setTitle(R.string.confirm_delete_this_widget_title) | ||
builder.setMessage(R.string.confirm_delete_this_widget_message) | ||
|
||
builder.setPositiveButton( | ||
R.string.confirm_positive | ||
) { dialog, _ -> | ||
lifecycleScope.launch { | ||
dao.delete(appWidgetId) | ||
dialog.dismiss() | ||
finish() | ||
} | ||
} | ||
|
||
builder.setNegativeButton( | ||
R.string.confirm_negative | ||
) { dialog, _ -> // Do nothing | ||
dialog.dismiss() | ||
} | ||
|
||
val alert: android.app.AlertDialog? = builder.create() | ||
alert?.show() | ||
} | ||
|
||
protected fun showAddWidgetError() { | ||
Toast.makeText(applicationContext, R.string.widget_creation_error, Toast.LENGTH_LONG).show() | ||
} | ||
} |
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
Oops, something went wrong.