remove DayActivity

This commit is contained in:
tibbi 2018-01-22 17:36:11 +01:00
parent d2a145faed
commit 438935c301
7 changed files with 13 additions and 178 deletions

View File

@ -96,14 +96,9 @@
android:label="@string/third_party_licences"
android:parentActivityName="com.simplemobiletools.commons.activities.AboutActivity"/>
<activity
android:name=".activities.DayActivity"
android:label="@string/details"
android:parentActivityName=".activities.MainActivity"/>
<activity
android:name=".activities.EventActivity"
android:parentActivityName=".activities.DayActivity">
android:parentActivityName=".activities.MainActivity">
<intent-filter>
<action android:name="android.intent.action.EDIT"/>

View File

@ -1,130 +0,0 @@
package com.simplemobiletools.calendar.activities
import android.content.Intent
import android.os.Bundle
import android.support.v4.view.ViewPager
import android.util.SparseIntArray
import android.view.Menu
import android.view.MenuItem
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.adapters.MyDayPagerAdapter
import com.simplemobiletools.calendar.dialogs.FilterEventTypesDialog
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.dbHelper
import com.simplemobiletools.calendar.extensions.getNewEventTimestampFromCode
import com.simplemobiletools.calendar.helpers.DAY_CODE
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.helpers.NEW_EVENT_START_TS
import com.simplemobiletools.calendar.interfaces.NavigationListener
import com.simplemobiletools.commons.extensions.isActivityDestroyed
import com.simplemobiletools.commons.extensions.updateTextColors
import kotlinx.android.synthetic.main.activity_day.*
import org.joda.time.DateTime
import java.util.*
class DayActivity : SimpleActivity(), NavigationListener, ViewPager.OnPageChangeListener {
private val PREFILLED_DAYS = 121
private var mDayCode = ""
private var mPagerDays: MutableList<String>? = null
private var mPagerPos = 0
private var eventTypeColors = SparseIntArray()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_day)
val intent = intent ?: return
mDayCode = intent.getStringExtra(DAY_CODE)
if (mDayCode.isEmpty()) {
return
}
fillViewPager(mDayCode)
day_fab.setOnClickListener { addNewEvent() }
updateTextColors(day_coordinator)
dbHelper.getEventTypes {
if (!isActivityDestroyed()) {
eventTypeColors.clear()
it.map { eventTypeColors.put(it.id, it.color) }
invalidateOptionsMenu()
}
}
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_day, menu)
menu.findItem(R.id.filter).isVisible = eventTypeColors.size() > 1 || config.displayEventTypes.isEmpty()
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.filter -> showFilterDialog()
else -> return super.onOptionsItemSelected(item)
}
return true
}
private fun fillViewPager(targetDay: String) {
getDays(targetDay)
val daysAdapter = MyDayPagerAdapter(supportFragmentManager, mPagerDays!!, this)
mPagerPos = mPagerDays!!.size / 2
view_pager.apply {
adapter = daysAdapter
currentItem = mPagerPos
addOnPageChangeListener(this@DayActivity)
}
}
private fun showFilterDialog() {
FilterEventTypesDialog(this) {
recheckEvents()
}
}
private fun addNewEvent() {
Intent(applicationContext, EventActivity::class.java).apply {
putExtra(NEW_EVENT_START_TS, getNewEventTimestampFromCode(mPagerDays?.get(view_pager.currentItem).toString()))
startActivity(this)
}
}
private fun getDays(code: String) {
mPagerDays = ArrayList(PREFILLED_DAYS)
val today = Formatter.getDateTimeFromCode(code)
for (i in -PREFILLED_DAYS / 2..PREFILLED_DAYS / 2) {
mPagerDays!!.add(Formatter.getDayCodeFromDateTime(today.plusDays(i)))
}
}
fun recheckEvents() {
(view_pager.adapter as MyDayPagerAdapter).checkDayEvents(mPagerPos)
}
override fun onPageScrollStateChanged(state: Int) {
}
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
}
override fun onPageSelected(position: Int) {
mPagerPos = position
(view_pager.adapter as MyDayPagerAdapter).destroyMultiselector(position)
}
override fun goLeft() {
view_pager.currentItem = view_pager.currentItem - 1
}
override fun goRight() {
view_pager.currentItem = view_pager.currentItem + 1
}
override fun goToDateTime(dateTime: DateTime) {
fillViewPager(Formatter.getDayCodeFromDateTime(dateTime))
}
}

View File

@ -7,9 +7,9 @@ import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.SimpleActivity
import com.simplemobiletools.calendar.dialogs.DeleteEventDialog
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.dbHelper
import com.simplemobiletools.calendar.extensions.shareEvents
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.interfaces.DeleteEventsListener
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
import com.simplemobiletools.commons.extensions.applyColorFilter
@ -18,8 +18,8 @@ import com.simplemobiletools.commons.extensions.beInvisibleIf
import com.simplemobiletools.commons.views.MyRecyclerView
import kotlinx.android.synthetic.main.event_item_day_view.view.*
class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, val listener: DeleteEventsListener?, recyclerView: MyRecyclerView,
itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, recyclerView: MyRecyclerView, itemClick: (Any) -> Unit)
: MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) {
private var allDayString = resources.getString(R.string.all_day)
private var replaceDescriptionWithLocation = activity.config.replaceDescription
@ -112,9 +112,12 @@ class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList<Event>, v
events.removeAll(eventsToDelete)
if (it) {
listener?.deleteItems(eventIds)
val eventIDs = Array(eventIds.size, { i -> (eventIds[i].toString()) })
activity.dbHelper.deleteEvents(eventIDs, true)
} else {
listener?.addEventRepeatException(eventIds, timestamps)
eventIds.forEachIndexed { index, value ->
activity.dbHelper.addEventRepeatException(value, timestamps[index], true)
}
}
removeSelectedItems()
}

View File

@ -11,7 +11,6 @@ import android.view.ViewGroup
import android.widget.DatePicker
import android.widget.RelativeLayout
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.activities.DayActivity
import com.simplemobiletools.calendar.activities.EventActivity
import com.simplemobiletools.calendar.activities.SimpleActivity
import com.simplemobiletools.calendar.adapters.DayEventsAdapter
@ -22,7 +21,6 @@ import com.simplemobiletools.calendar.helpers.DAY_CODE
import com.simplemobiletools.calendar.helpers.EVENT_ID
import com.simplemobiletools.calendar.helpers.EVENT_OCCURRENCE_TS
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.interfaces.DeleteEventsListener
import com.simplemobiletools.calendar.interfaces.NavigationListener
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.commons.extensions.applyColorFilter
@ -33,7 +31,7 @@ import kotlinx.android.synthetic.main.top_navigation.view.*
import org.joda.time.DateTime
import java.util.*
class DayFragment : Fragment(), DeleteEventsListener {
class DayFragment : Fragment() {
var mListener: NavigationListener? = null
private var mTextColor = 0
private var mDayCode = ""
@ -140,7 +138,7 @@ class DayFragment : Fragment(), DeleteEventsListener {
if (activity == null)
return
DayEventsAdapter(activity as SimpleActivity, events, this, mHolder.day_events) {
DayEventsAdapter(activity as SimpleActivity, events, mHolder.day_events) {
editEvent(it as Event)
}.apply {
setupDragListener(true)
@ -156,16 +154,4 @@ class DayFragment : Fragment(), DeleteEventsListener {
startActivity(this)
}
}
override fun deleteItems(ids: ArrayList<Int>) {
val eventIDs = Array(ids.size, { i -> (ids[i].toString()) })
context!!.dbHelper.deleteEvents(eventIDs, true)
}
override fun addEventRepeatException(parentIds: ArrayList<Int>, timestamps: ArrayList<Int>) {
parentIds.forEachIndexed { index, value ->
context!!.dbHelper.addEventRepeatException(parentIds[index], timestamps[index], true)
}
(activity as DayActivity).recheckEvents()
}
}

View File

@ -1,9 +0,0 @@
package com.simplemobiletools.calendar.interfaces
import java.util.*
interface DeleteEventsListener {
fun deleteItems(ids: ArrayList<Int>)
fun addEventRepeatException(parentIds: ArrayList<Int>, timestamps: ArrayList<Int>)
}

View File

@ -5,17 +5,16 @@
android:id="@+id/day_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/medium_margin">
android:paddingTop="@dimen/medium_margin">
<include layout="@layout/top_navigation"/>
<com.simplemobiletools.commons.views.MyRecyclerView
android:id="@+id/day_events"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
android:layout_below="@+id/top_value"
android:clipToPadding="false"
android:overScrollMode="never"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
</RelativeLayout>

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/filter"
android:icon="@drawable/ic_filter"
android:title="@string/filter"
app:showAsAction="ifRoom"/>
</menu>