appending package name with .pro

This commit is contained in:
tibbi
2018-11-07 11:48:09 +01:00
parent 20338bbe90
commit 0635dac078
34 changed files with 128 additions and 128 deletions

View File

@ -0,0 +1,71 @@
package com.simplemobiletools.notes.pro.adapters
import android.app.Activity
import android.os.Bundle
import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import com.simplemobiletools.commons.extensions.showErrorToast
import com.simplemobiletools.notes.pro.fragments.NoteFragment
import com.simplemobiletools.notes.pro.helpers.NOTE_ID
import com.simplemobiletools.notes.pro.models.Note
class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity: Activity) : FragmentStatePagerAdapter(fm) {
private var fragments: HashMap<Int, NoteFragment> = LinkedHashMap()
override fun getCount() = notes.size
override fun getItem(position: Int): NoteFragment {
val bundle = Bundle()
val id = notes[position].id
bundle.putInt(NOTE_ID, id)
if (fragments.containsKey(position)) {
return fragments[position]!!
}
val fragment = NoteFragment()
fragment.arguments = bundle
fragments[position] = fragment
return fragment
}
override fun getPageTitle(position: Int) = notes[position].title
fun getCurrentNotesView(position: Int) = fragments[position]?.getNotesView()
fun getCurrentNoteViewText(position: Int) = fragments[position]?.getCurrentNoteViewText()
fun appendText(position: Int, text: String) = fragments[position]?.getNotesView()?.append(text)
fun saveCurrentNote(position: Int, force: Boolean) = fragments[position]?.saveText(force)
fun focusEditText(position: Int) = fragments[position]?.focusEditText()
fun anyHasUnsavedChanges() = fragments.values.any { it.hasUnsavedChanges() }
fun saveAllFragmentTexts() = fragments.values.forEach { it.saveText(false) }
fun undo(position: Int) = fragments[position]?.undo()
fun redo(position: Int) = fragments[position]?.redo()
override fun finishUpdate(container: ViewGroup) {
try {
super.finishUpdate(container)
} catch (e: Exception) {
activity.showErrorToast(e)
}
}
override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
super.destroyItem(container, position, `object`)
fragments.remove(position)
}
override fun instantiateItem(container: ViewGroup, position: Int): Any {
val fragment = super.instantiateItem(container, position) as NoteFragment
fragments[position] = fragment
return fragment
}
}

View File

@ -0,0 +1,72 @@
package com.simplemobiletools.notes.pro.adapters
import android.content.Context
import android.content.Intent
import android.view.View
import android.widget.RemoteViews
import android.widget.RemoteViewsService
import com.simplemobiletools.commons.extensions.setText
import com.simplemobiletools.commons.extensions.setTextSize
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.R.id.widget_text_holder
import com.simplemobiletools.notes.pro.extensions.config
import com.simplemobiletools.notes.pro.extensions.dbHelper
import com.simplemobiletools.notes.pro.extensions.getTextSize
import com.simplemobiletools.notes.pro.helpers.GRAVITY_CENTER
import com.simplemobiletools.notes.pro.helpers.GRAVITY_RIGHT
import com.simplemobiletools.notes.pro.helpers.NOTE_ID
import com.simplemobiletools.notes.pro.helpers.OPEN_NOTE_ID
class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsService.RemoteViewsFactory {
private val textIds = arrayOf(R.id.widget_text_left, R.id.widget_text_center, R.id.widget_text_right)
private var widgetTextColor = context.config.widgetTextColor
override fun getViewAt(position: Int): RemoteViews {
val noteId = intent.getIntExtra(NOTE_ID, 1)
val views = RemoteViews(context.packageName, R.layout.widget_text_layout).apply {
val note = context.dbHelper.getNoteWithId(noteId)
if (note != null) {
val noteText = note.getNoteStoredValue() ?: ""
val textSize = context.getTextSize() / context.resources.displayMetrics.density
for (id in textIds) {
setText(id, noteText)
setTextColor(id, widgetTextColor)
setTextSize(id, textSize)
setViewVisibility(id, View.GONE)
}
}
Intent().apply {
putExtra(OPEN_NOTE_ID, noteId)
setOnClickFillInIntent(widget_text_holder, this)
}
setViewVisibility(getProperTextView(context), View.VISIBLE)
}
return views
}
private fun getProperTextView(context: Context) = when (context.config.gravity) {
GRAVITY_CENTER -> R.id.widget_text_center
GRAVITY_RIGHT -> R.id.widget_text_right
else -> R.id.widget_text_left
}
override fun onCreate() {}
override fun getLoadingView() = null
override fun getItemId(position: Int) = position.toLong()
override fun onDataSetChanged() {
widgetTextColor = context.config.widgetTextColor
}
override fun hasStableIds() = true
override fun getCount() = 1
override fun getViewTypeCount() = 1
override fun onDestroy() {}
}