mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-15 07:52:02 +02:00
open the widget note after clicking on the widget
This commit is contained in:
parent
255a5ade89
commit
70550d022e
@ -24,6 +24,7 @@ import com.simplemobiletools.notes.dialogs.*
|
|||||||
import com.simplemobiletools.notes.extensions.config
|
import com.simplemobiletools.notes.extensions.config
|
||||||
import com.simplemobiletools.notes.extensions.getTextSize
|
import com.simplemobiletools.notes.extensions.getTextSize
|
||||||
import com.simplemobiletools.notes.helpers.DBHelper
|
import com.simplemobiletools.notes.helpers.DBHelper
|
||||||
|
import com.simplemobiletools.notes.helpers.OPEN_NOTE_ID
|
||||||
import com.simplemobiletools.notes.helpers.TYPE_NOTE
|
import com.simplemobiletools.notes.helpers.TYPE_NOTE
|
||||||
import com.simplemobiletools.notes.models.Note
|
import com.simplemobiletools.notes.models.Note
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
@ -55,7 +56,11 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
|||||||
private fun initViewPager() {
|
private fun initViewPager() {
|
||||||
mNotes = mDb.getNotes()
|
mNotes = mDb.getNotes()
|
||||||
mCurrentNote = mNotes[0]
|
mCurrentNote = mNotes[0]
|
||||||
val itemIndex = getNoteIndexWithId(config.currentNoteId)
|
var wantedNoteId = intent.getIntExtra(OPEN_NOTE_ID, -1)
|
||||||
|
if (wantedNoteId == -1)
|
||||||
|
wantedNoteId = config.currentNoteId
|
||||||
|
|
||||||
|
val itemIndex = getNoteIndexWithId(wantedNoteId)
|
||||||
|
|
||||||
mAdapter = NotesPagerAdapter(supportFragmentManager, mNotes)
|
mAdapter = NotesPagerAdapter(supportFragmentManager, mNotes)
|
||||||
view_pager.apply {
|
view_pager.apply {
|
||||||
|
@ -3,11 +3,20 @@ package com.simplemobiletools.notes.activities
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.app.AppCompatActivity
|
||||||
|
import com.simplemobiletools.notes.helpers.OPEN_NOTE_ID
|
||||||
|
|
||||||
class SplashActivity : AppCompatActivity() {
|
class SplashActivity : AppCompatActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
startActivity(Intent(this, MainActivity::class.java))
|
|
||||||
|
if (intent.extras?.containsKey(OPEN_NOTE_ID) == true) {
|
||||||
|
Intent(this, MainActivity::class.java).apply {
|
||||||
|
putExtra(OPEN_NOTE_ID, intent.getIntExtra(OPEN_NOTE_ID, -1))
|
||||||
|
startActivity(this)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
startActivity(Intent(this, MainActivity::class.java))
|
||||||
|
}
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.simplemobiletools.notes.helpers
|
package com.simplemobiletools.notes.helpers
|
||||||
|
|
||||||
val NOTE_ID = "note_id"
|
val NOTE_ID = "note_id"
|
||||||
|
val OPEN_NOTE_ID = "open_note_id"
|
||||||
|
|
||||||
// shared preferences
|
// shared preferences
|
||||||
val CURRENT_NOTE_ID = "current_note_id"
|
val CURRENT_NOTE_ID = "current_note_id"
|
||||||
|
@ -60,9 +60,12 @@ class MyWidgetProvider : AppWidgetProvider() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupAppOpenIntent(id: Int, context: Context) {
|
private fun setupAppOpenIntent(id: Int, context: Context) {
|
||||||
val intent = Intent(context, SplashActivity::class.java)
|
val widgetId = context.config.widgetNoteId
|
||||||
val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0)
|
Intent(context, SplashActivity::class.java).apply {
|
||||||
mRemoteViews.setOnClickPendingIntent(id, pendingIntent)
|
putExtra(OPEN_NOTE_ID, widgetId)
|
||||||
|
val pendingIntent = PendingIntent.getActivity(context, widgetId, this, 0)
|
||||||
|
mRemoteViews.setOnClickPendingIntent(id, pendingIntent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateWidget(widgetManager: AppWidgetManager, widgetId: Int, remoteViews: RemoteViews, context: Context) {
|
private fun updateWidget(widgetManager: AppWidgetManager, widgetId: Int, remoteViews: RemoteViews, context: Context) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user