mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-03-12 14:40:07 +01:00
couple improvements to widgets and intent handling
This commit is contained in:
parent
a6b9cbba9b
commit
742fe5d842
@ -58,8 +58,7 @@ class MainActivity : SimpleActivity() {
|
||||
setContentView(R.layout.activity_main)
|
||||
appLaunched(BuildConfig.APPLICATION_ID)
|
||||
|
||||
initViewPager()
|
||||
|
||||
initViewPager(intent.getLongExtra(OPEN_NOTE_ID, -1L))
|
||||
pager_title_strip.setTextSize(TypedValue.COMPLEX_UNIT_PX, getTextSize())
|
||||
pager_title_strip.layoutParams.height = (pager_title_strip.height + resources.getDimension(R.dimen.activity_margin) * 2).toInt()
|
||||
checkWhatsNewDialog()
|
||||
@ -202,7 +201,8 @@ class MainActivity : SimpleActivity() {
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
super.onNewIntent(intent)
|
||||
view_pager.currentItem = getWantedNoteIndex(null)
|
||||
val wantedNoteId = intent.getLongExtra(OPEN_NOTE_ID, -1L)
|
||||
view_pager.currentItem = getWantedNoteIndex(wantedNoteId)
|
||||
}
|
||||
|
||||
private fun storeStateVariables() {
|
||||
@ -256,6 +256,7 @@ class MainActivity : SimpleActivity() {
|
||||
view_pager.apply {
|
||||
adapter = mAdapter
|
||||
currentItem = getWantedNoteIndex(wantedNoteId)
|
||||
config.currentNoteId = mCurrentNote.id!!
|
||||
|
||||
onPageChangeListener {
|
||||
mCurrentNote = mNotes[it]
|
||||
@ -269,12 +270,10 @@ class MainActivity : SimpleActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getWantedNoteIndex(secondaryWantedNoteId: Long?): Int {
|
||||
var wantedNoteId = intent.getLongExtra(OPEN_NOTE_ID, -1)
|
||||
if (wantedNoteId == -1L) {
|
||||
wantedNoteId = secondaryWantedNoteId ?: config.currentNoteId
|
||||
}
|
||||
return getNoteIndexWithId(wantedNoteId)
|
||||
private fun getWantedNoteIndex(wantedNoteId: Long?): Int {
|
||||
intent.removeExtra(OPEN_NOTE_ID)
|
||||
val noteIdToOpen = if (wantedNoteId == null || wantedNoteId == -1L) config.currentNoteId else wantedNoteId
|
||||
return getNoteIndexWithId(noteIdToOpen)
|
||||
}
|
||||
|
||||
private fun currentNotesView() = if (view_pager == null) {
|
||||
|
@ -8,7 +8,7 @@ class SplashActivity : BaseSplashActivity() {
|
||||
override fun initActivity() {
|
||||
if (intent.extras?.containsKey(OPEN_NOTE_ID) == true) {
|
||||
Intent(this, MainActivity::class.java).apply {
|
||||
putExtra(OPEN_NOTE_ID, intent.getIntExtra(OPEN_NOTE_ID, -1))
|
||||
putExtra(OPEN_NOTE_ID, intent.getLongExtra(OPEN_NOTE_ID, -1L))
|
||||
startActivity(this)
|
||||
}
|
||||
} else {
|
||||
|
@ -18,7 +18,7 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
|
||||
override fun getItem(position: Int): NoteFragment {
|
||||
val bundle = Bundle()
|
||||
val id = notes[position].id
|
||||
bundle.putInt(NOTE_ID, id!!.toInt())
|
||||
bundle.putLong(NOTE_ID, id!!)
|
||||
|
||||
if (fragments.containsKey(position)) {
|
||||
return fragments[position]!!
|
||||
|
@ -22,7 +22,7 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi
|
||||
private var widgetTextColor = context.config.widgetTextColor
|
||||
|
||||
override fun getViewAt(position: Int): RemoteViews {
|
||||
val noteId = intent.getIntExtra(NOTE_ID, 1)
|
||||
val noteId = intent.getLongExtra(NOTE_ID, 0L)
|
||||
val views = RemoteViews(context.packageName, R.layout.widget_text_layout).apply {
|
||||
val note = context.notesDB.getNoteWithId(noteId)
|
||||
if (note != null) {
|
||||
|
@ -38,14 +38,14 @@ class NoteFragment : androidx.fragment.app.Fragment() {
|
||||
private var textHistory = TextHistory()
|
||||
private var isUndoOrRedo = false
|
||||
private var skipTextUpdating = false
|
||||
private var noteId = 0
|
||||
private var noteId = 0L
|
||||
private var note: Note? = null
|
||||
|
||||
lateinit var view: ViewGroup
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
view = inflater.inflate(R.layout.fragment_note, container, false) as ViewGroup
|
||||
noteId = arguments!!.getInt(NOTE_ID)
|
||||
noteId = arguments!!.getLong(NOTE_ID)
|
||||
retainInstance = true
|
||||
|
||||
val layoutToInflate = if (config!!.enableLineWrap) R.layout.note_view_static else R.layout.note_view_horiz_scrollable
|
||||
@ -87,11 +87,11 @@ class NoteFragment : androidx.fragment.app.Fragment() {
|
||||
|
||||
override fun setMenuVisibility(menuVisible: Boolean) {
|
||||
super.setMenuVisibility(menuVisible)
|
||||
if (!menuVisible && noteId != 0 && config?.autosaveNotes == true) {
|
||||
if (!menuVisible && noteId != 0L && config?.autosaveNotes == true) {
|
||||
saveText(false)
|
||||
}
|
||||
|
||||
if (menuVisible && noteId != 0) {
|
||||
if (menuVisible && noteId != 0L) {
|
||||
val currentText = getCurrentNoteViewText()
|
||||
if (currentText != null) {
|
||||
(activity as MainActivity).currentNoteTextChanged(currentText, isUndoAvailable(), isRedoAvailable())
|
||||
|
@ -26,24 +26,26 @@ class MyWidgetProvider : AppWidgetProvider() {
|
||||
|
||||
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
|
||||
super.onUpdate(context, appWidgetManager, appWidgetIds)
|
||||
context.widgetsDB.getWidgets().forEach {
|
||||
val views = RemoteViews(context.packageName, R.layout.widget)
|
||||
views.setBackgroundColor(R.id.notes_widget_holder, context.config.widgetBgColor)
|
||||
setupAppOpenIntent(context, views, R.id.notes_widget_holder, it)
|
||||
Thread {
|
||||
context.widgetsDB.getWidgets().forEach {
|
||||
val views = RemoteViews(context.packageName, R.layout.widget)
|
||||
views.setBackgroundColor(R.id.notes_widget_holder, context.config.widgetBgColor)
|
||||
setupAppOpenIntent(context, views, R.id.notes_widget_holder, it)
|
||||
|
||||
Intent(context, WidgetService::class.java).apply {
|
||||
putExtra(NOTE_ID, it.noteId)
|
||||
data = Uri.parse(this.toUri(Intent.URI_INTENT_SCHEME))
|
||||
views.setRemoteAdapter(R.id.notes_widget_listview, this)
|
||||
Intent(context, WidgetService::class.java).apply {
|
||||
putExtra(NOTE_ID, it.noteId)
|
||||
data = Uri.parse(this.toUri(Intent.URI_INTENT_SCHEME))
|
||||
views.setRemoteAdapter(R.id.notes_widget_listview, this)
|
||||
}
|
||||
|
||||
val startActivityIntent = context.getLaunchIntent() ?: Intent(context, SplashActivity::class.java)
|
||||
startActivityIntent.putExtra(OPEN_NOTE_ID, it.noteId)
|
||||
val startActivityPendingIntent = PendingIntent.getActivity(context, it.widgetId, startActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
views.setPendingIntentTemplate(R.id.notes_widget_listview, startActivityPendingIntent)
|
||||
|
||||
appWidgetManager.updateAppWidget(it.widgetId, views)
|
||||
appWidgetManager.notifyAppWidgetViewDataChanged(it.widgetId, R.id.notes_widget_listview)
|
||||
}
|
||||
|
||||
val startActivityIntent = context.getLaunchIntent() ?: Intent(context, SplashActivity::class.java)
|
||||
startActivityIntent.putExtra(OPEN_NOTE_ID, it.noteId)
|
||||
val startActivityPendingIntent = PendingIntent.getActivity(context, it.widgetId, startActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
views.setPendingIntentTemplate(R.id.notes_widget_listview, startActivityPendingIntent)
|
||||
|
||||
appWidgetManager.updateAppWidget(it.widgetId, views)
|
||||
appWidgetManager.notifyAppWidgetViewDataChanged(it.widgetId, R.id.notes_widget_listview)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ class NotesHelper(val activity: Activity) {
|
||||
}.start()
|
||||
}
|
||||
|
||||
fun getNoteWithId(id: Int, callback: (note: Note?) -> Unit) {
|
||||
fun getNoteWithId(id: Long, callback: (note: Note?) -> Unit) {
|
||||
Thread {
|
||||
val note = activity.notesDB.getNoteWithId(id)
|
||||
activity.runOnUiThread {
|
||||
|
@ -9,7 +9,7 @@ interface NotesDao {
|
||||
fun getNotes(): List<Note>
|
||||
|
||||
@Query("SELECT * FROM notes WHERE id = :id")
|
||||
fun getNoteWithId(id: Int): Note?
|
||||
fun getNoteWithId(id: Long): Note?
|
||||
|
||||
@Query("SELECT id FROM notes WHERE path = :path")
|
||||
fun getNoteIdWithPath(path: String): Long?
|
||||
|
Loading…
x
Reference in New Issue
Block a user