Skip to content

Commit

Permalink
move updateWidget class to mainactivity, as its not used anywhere else
Browse files Browse the repository at this point in the history
  • Loading branch information
tibbi committed Nov 14, 2016
1 parent 66d75b9 commit afbf579
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
18 changes: 0 additions & 18 deletions app/src/main/kotlin/com/simplemobiletools/notes/Utils.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
package com.simplemobiletools.notes

import android.appwidget.AppWidgetManager
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.widget.Toast

object Utils {
fun showToast(context: Context, resId: Int) {
Toast.makeText(context, context.resources.getString(resId), Toast.LENGTH_SHORT).show()
}

fun getTextSize(context: Context): Float {
val fontSize = Config.newInstance(context).fontSize
val res = context.resources
Expand All @@ -21,14 +13,4 @@ object Utils {
else -> res.getDimension(R.dimen.medium_text_size)
}
}

fun updateWidget(context: Context) {
val widgetManager = AppWidgetManager.getInstance(context)
val ids = widgetManager.getAppWidgetIds(ComponentName(context, MyWidgetProvider::class.java))

val intent = Intent(context, MyWidgetProvider::class.java)
intent.action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids)
context.sendBroadcast(intent)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.simplemobiletools.notes.activities

import android.appwidget.AppWidgetManager
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.os.Bundle
Expand All @@ -11,6 +13,7 @@ import android.view.View
import android.view.WindowManager
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import com.simplemobiletools.notes.MyWidgetProvider
import com.simplemobiletools.notes.R
import com.simplemobiletools.notes.Utils
import com.simplemobiletools.notes.databases.DBHelper
Expand Down Expand Up @@ -113,7 +116,7 @@ class MainActivity : SimpleActivity(), OpenNoteDialog.OpenNoteListener {

current_note_label.visibility = if (mNotes.size <= 1) View.GONE else View.VISIBLE
current_note_title.visibility = if (mNotes.size <= 1) View.GONE else View.VISIBLE
Utils.updateWidget(applicationContext)
updateWidget(applicationContext)
}

fun displayNewNoteDialog() {
Expand Down Expand Up @@ -188,7 +191,7 @@ class MainActivity : SimpleActivity(), OpenNoteDialog.OpenNoteListener {
}

hideKeyboard()
Utils.updateWidget(applicationContext)
updateWidget(applicationContext)
}

private fun shareText() {
Expand All @@ -215,4 +218,14 @@ class MainActivity : SimpleActivity(), OpenNoteDialog.OpenNoteListener {
}

override fun noteSelected(id: Int) = updateSelectedNote(id)

fun updateWidget(context: Context) {
val widgetManager = AppWidgetManager.getInstance(context)
val ids = widgetManager.getAppWidgetIds(ComponentName(context, MyWidgetProvider::class.java))

val intent = Intent(context, MyWidgetProvider::class.java)
intent.action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids)
context.sendBroadcast(intent)
}
}

0 comments on commit afbf579

Please sign in to comment.