Skip to content

Commit

Permalink
Move some UI functions to more common class
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanomiko committed Sep 11, 2021
1 parent cc4a276 commit 97a44a9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
10 changes: 0 additions & 10 deletions app/src/main/java/net/dcnnt/fragments/BasePluginFargment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,6 @@ abstract class BasePluginFargment: DCFragment() {

open fun onSelectedDeviceChanged() {}

fun toast(context: Context, text: String) {
activity?.runOnUiThread { Toast.makeText(context, text, Toast.LENGTH_SHORT).show() }
}

fun showError(context: Context, e: Exception) {
toast(context, "Error: $e")
APP.log("Error occurred: $e")
APP.logException(e)
}

fun createDeviceSelectView(context: Context,
availableOnly: Boolean = true,
addCommon: Boolean = false): DeviceSelectView {
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/net/dcnnt/ui/DCFragment.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package net.dcnnt.ui

import android.content.Context
import android.content.Intent
import android.widget.Toast
import androidx.appcompat.widget.Toolbar
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import net.dcnnt.MainActivity
import net.dcnnt.core.APP
import java.lang.Exception

/**
* Base class for all fragments in application
Expand Down Expand Up @@ -37,4 +41,20 @@ open class DCFragment: Fragment() {
}
return true
}

/**
* Just show toast with text
*/
fun toast(context: Context, text: String) {
activity?.runOnUiThread { Toast.makeText(context, text, Toast.LENGTH_SHORT).show() }
}

/**
* Show error message for user and add it to log
*/
fun showError(context: Context, e: Exception) {
toast(context, "Error: $e")
APP.log("Error occurred: $e")
APP.logException(e)
}
}

0 comments on commit 97a44a9

Please sign in to comment.