From 438935c301ebd47e88b4238d413f35e1b0436cb1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 22 Jan 2018 17:36:11 +0100 Subject: [PATCH] remove DayActivity --- app/src/main/AndroidManifest.xml | 7 +- .../calendar/activities/DayActivity.kt | 130 ------------------ .../calendar/adapters/DayEventsAdapter.kt | 13 +- .../calendar/fragments/DayFragment.kt | 18 +-- .../interfaces/DeleteEventsListener.kt | 9 -- app/src/main/res/layout/fragment_day.xml | 5 +- app/src/main/res/menu/menu_day.xml | 9 -- 7 files changed, 13 insertions(+), 178 deletions(-) delete mode 100644 app/src/main/kotlin/com/simplemobiletools/calendar/activities/DayActivity.kt delete mode 100644 app/src/main/kotlin/com/simplemobiletools/calendar/interfaces/DeleteEventsListener.kt delete mode 100644 app/src/main/res/menu/menu_day.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d4eb7662e..7bdfe96d0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -96,14 +96,9 @@ android:label="@string/third_party_licences" android:parentActivityName="com.simplemobiletools.commons.activities.AboutActivity"/> - - + android:parentActivityName=".activities.MainActivity"> diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/DayActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/activities/DayActivity.kt deleted file mode 100644 index 26449e3ea..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/activities/DayActivity.kt +++ /dev/null @@ -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? = 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)) - } -} diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/DayEventsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/DayEventsAdapter.kt index d577949e3..625697409 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/DayEventsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/adapters/DayEventsAdapter.kt @@ -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, val listener: DeleteEventsListener?, recyclerView: MyRecyclerView, - itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, null, itemClick) { +class DayEventsAdapter(activity: SimpleActivity, val events: ArrayList, 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, 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() } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/DayFragment.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/DayFragment.kt index a8ac92d3b..33b348d02 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/DayFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/fragments/DayFragment.kt @@ -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) { - val eventIDs = Array(ids.size, { i -> (ids[i].toString()) }) - context!!.dbHelper.deleteEvents(eventIDs, true) - } - - override fun addEventRepeatException(parentIds: ArrayList, timestamps: ArrayList) { - parentIds.forEachIndexed { index, value -> - context!!.dbHelper.addEventRepeatException(parentIds[index], timestamps[index], true) - } - (activity as DayActivity).recheckEvents() - } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/interfaces/DeleteEventsListener.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/interfaces/DeleteEventsListener.kt deleted file mode 100644 index 0fdebdec1..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/interfaces/DeleteEventsListener.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.simplemobiletools.calendar.interfaces - -import java.util.* - -interface DeleteEventsListener { - fun deleteItems(ids: ArrayList) - - fun addEventRepeatException(parentIds: ArrayList, timestamps: ArrayList) -} diff --git a/app/src/main/res/layout/fragment_day.xml b/app/src/main/res/layout/fragment_day.xml index 4ea4e4a0b..392a5b1c9 100644 --- a/app/src/main/res/layout/fragment_day.xml +++ b/app/src/main/res/layout/fragment_day.xml @@ -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"> diff --git a/app/src/main/res/menu/menu_day.xml b/app/src/main/res/menu/menu_day.xml deleted file mode 100644 index 9940db810..000000000 --- a/app/src/main/res/menu/menu_day.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - -