mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Remove BaseActivity and BaseScreen
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.isoron.androidbase.activities
|
||||
package org.isoron.androidbase
|
||||
|
||||
import javax.inject.*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||
* Copyright (C) 2016-2020 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.androidbase.activities;
|
||||
package org.isoron.androidbase;
|
||||
|
||||
import android.content.*;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.isoron.androidbase.activities
|
||||
package org.isoron.androidbase
|
||||
|
||||
import javax.inject.*
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
*/
|
||||
package org.isoron.androidbase
|
||||
|
||||
import org.isoron.androidbase.activities.BaseActivity
|
||||
import android.app.*
|
||||
|
||||
class BaseExceptionHandler(private val activity: BaseActivity) : Thread.UncaughtExceptionHandler {
|
||||
class BaseExceptionHandler(private val activity: Activity) : Thread.UncaughtExceptionHandler {
|
||||
|
||||
private val originalHandler: Thread.UncaughtExceptionHandler? =
|
||||
Thread.getDefaultUncaughtExceptionHandler()
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.isoron.androidbase.activities
|
||||
|
||||
import android.R.anim
|
||||
import android.content.*
|
||||
import android.os.*
|
||||
import android.view.*
|
||||
import androidx.appcompat.app.*
|
||||
import org.isoron.androidbase.*
|
||||
|
||||
/**
|
||||
* Base class for all activities in the application.
|
||||
*
|
||||
* This class delegates the responsibilities of an Android activity to other classes. For example,
|
||||
* callbacks related to menus are forwarded to a []BaseMenu], while callbacks related to activity
|
||||
* results are forwarded to a [BaseScreen].
|
||||
*
|
||||
*
|
||||
* A BaseActivity also installs an [java.lang.Thread.UncaughtExceptionHandler] to the main thread.
|
||||
* By default, this handler is an instance of BaseExceptionHandler, which logs the exception to the
|
||||
* disk before the application crashes. To the default handler, you should override the method
|
||||
* getExceptionHandler.
|
||||
*/
|
||||
abstract class BaseActivity : AppCompatActivity() {
|
||||
private var screen: BaseScreen? = null
|
||||
|
||||
fun restartWithFade(cls: Class<*>?) {
|
||||
Handler().postDelayed({
|
||||
finish()
|
||||
overridePendingTransition(anim.fade_in, anim.fade_out)
|
||||
startActivity(Intent(this, cls))
|
||||
}, 500) // HACK: Let the menu disappear first
|
||||
}
|
||||
|
||||
fun setScreen(screen: BaseScreen?) {
|
||||
this.screen = screen
|
||||
}
|
||||
|
||||
fun showDialog(dialog: AppCompatDialogFragment, tag: String?) {
|
||||
dialog.show(supportFragmentManager, tag)
|
||||
}
|
||||
|
||||
fun showDialog(dialog: AppCompatDialog) {
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
override fun onActivityResult(request: Int, result: Int, data: Intent?) {
|
||||
val screen = screen
|
||||
if(screen == null) super.onActivityResult(request, result, data)
|
||||
else screen.onResult(request, result, data)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
Thread.setDefaultUncaughtExceptionHandler(getExceptionHandler())
|
||||
}
|
||||
|
||||
private fun getExceptionHandler() = BaseExceptionHandler(this)
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
screen?.reattachDialogs()
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.androidbase.activities;
|
||||
|
||||
import dagger.*;
|
||||
|
||||
@Module
|
||||
public class BaseActivityModule
|
||||
{
|
||||
private BaseActivity activity;
|
||||
|
||||
public BaseActivityModule(BaseActivity activity)
|
||||
{
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
@Provides
|
||||
public BaseActivity getBaseActivity()
|
||||
{
|
||||
return activity;
|
||||
}
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.isoron.androidbase.activities
|
||||
|
||||
import android.content.*
|
||||
import android.graphics.*
|
||||
import android.graphics.drawable.*
|
||||
import android.view.*
|
||||
import android.widget.*
|
||||
import androidx.annotation.*
|
||||
import androidx.appcompat.app.*
|
||||
import androidx.appcompat.view.ActionMode
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import androidx.core.content.*
|
||||
import com.google.android.material.snackbar.*
|
||||
import org.isoron.androidbase.*
|
||||
import org.isoron.androidbase.utils.*
|
||||
import org.isoron.androidbase.utils.ColorUtils.mixColors
|
||||
import org.isoron.androidbase.utils.InterfaceUtils.dpToPixels
|
||||
import java.io.*
|
||||
|
||||
/**
|
||||
* Base class for all screens in the application.
|
||||
*
|
||||
* Screens are responsible for deciding what root views and what menus should be attached to the
|
||||
* main window. They are also responsible for showing other screens and for receiving their results.
|
||||
*/
|
||||
open class BaseScreen(@JvmField protected var activity: BaseActivity) {
|
||||
|
||||
private var snackbar: Snackbar? = null
|
||||
|
||||
/**
|
||||
* Called when another Activity has finished, and has returned some result.
|
||||
*
|
||||
* @param requestCode the request code originally supplied to startActivityForResult.
|
||||
* @param resultCode the result code sent by the other activity.
|
||||
* @param data an Intent containing extra data sent by the other
|
||||
* activity.
|
||||
* @see {@link android.app.Activity.onActivityResult
|
||||
*/
|
||||
open fun onResult(requestCode: Int, resultCode: Int, data: Intent?) {}
|
||||
|
||||
/**
|
||||
* Called after activity has been recreated, and the dialogs should be
|
||||
* reattached to their controllers.
|
||||
*/
|
||||
open fun reattachDialogs() {}
|
||||
|
||||
|
||||
/**
|
||||
* Shows a message on the screen.
|
||||
*
|
||||
* @param stringId the string resource id for this message.
|
||||
*/
|
||||
fun showMessage(@StringRes stringId: Int?, rootView: View?) {
|
||||
var snackbar = this.snackbar
|
||||
if (stringId == null || rootView == null) return
|
||||
if (snackbar == null) {
|
||||
snackbar = Snackbar.make(rootView, stringId, Snackbar.LENGTH_SHORT)
|
||||
val tvId = R.id.snackbar_text
|
||||
val tv = snackbar.view.findViewById<TextView>(tvId)
|
||||
tv.setTextColor(Color.WHITE)
|
||||
this.snackbar = snackbar
|
||||
}
|
||||
snackbar.setText(stringId)
|
||||
snackbar.show()
|
||||
}
|
||||
|
||||
fun showSendEmailScreen(@StringRes toId: Int, @StringRes subjectId: Int, content: String?) {
|
||||
val to = activity.getString(toId)
|
||||
val subject = activity.getString(subjectId)
|
||||
activity.startActivity(Intent().apply {
|
||||
action = Intent.ACTION_SEND
|
||||
type = "message/rfc822"
|
||||
putExtra(Intent.EXTRA_EMAIL, arrayOf(to))
|
||||
putExtra(Intent.EXTRA_SUBJECT, subject)
|
||||
putExtra(Intent.EXTRA_TEXT, content)
|
||||
})
|
||||
}
|
||||
|
||||
fun showSendFileScreen(archiveFilename: String) {
|
||||
val file = File(archiveFilename)
|
||||
val fileUri = FileProvider.getUriForFile(activity, "org.isoron.uhabits", file)
|
||||
activity.startActivity(Intent().apply {
|
||||
action = Intent.ACTION_SEND
|
||||
type = "application/zip"
|
||||
putExtra(Intent.EXTRA_STREAM, fileUri)
|
||||
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -33,9 +33,7 @@ import androidx.test.uiautomator.*;
|
||||
import junit.framework.*;
|
||||
|
||||
import org.isoron.androidbase.*;
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.androidbase.utils.*;
|
||||
import org.isoron.uhabits.core.database.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
import org.isoron.uhabits.core.tasks.*;
|
||||
|
||||
@@ -20,11 +20,10 @@
|
||||
package org.isoron.uhabits
|
||||
|
||||
import dagger.*
|
||||
import org.isoron.androidbase.activities.*
|
||||
import org.isoron.androidbase.*
|
||||
import org.isoron.uhabits.activities.*
|
||||
import org.isoron.uhabits.activities.habits.list.*
|
||||
import org.isoron.uhabits.activities.habits.list.views.*
|
||||
import org.isoron.uhabits.activities.habits.show.*
|
||||
import org.isoron.uhabits.core.ui.screens.habits.list.*
|
||||
import org.mockito.Mockito.*
|
||||
|
||||
|
||||
@@ -20,25 +20,25 @@
|
||||
package org.isoron.uhabits.activities
|
||||
|
||||
import android.app.*
|
||||
import android.content.*
|
||||
import android.content.res.Configuration.*
|
||||
import android.os.Build.VERSION.*
|
||||
import androidx.core.content.*
|
||||
import org.isoron.androidbase.activities.*
|
||||
import org.isoron.uhabits.*
|
||||
import org.isoron.androidbase.*
|
||||
import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.core.preferences.*
|
||||
import org.isoron.uhabits.core.ui.*
|
||||
import javax.inject.*
|
||||
|
||||
@ActivityScope
|
||||
class AndroidThemeSwitcher
|
||||
constructor(
|
||||
private val activity: Activity,
|
||||
@ActivityContext val context: Context,
|
||||
preferences: Preferences
|
||||
) : ThemeSwitcher(preferences) {
|
||||
|
||||
override fun getSystemTheme(): Int {
|
||||
if(SDK_INT < 29) return THEME_LIGHT;
|
||||
val uiMode = activity.resources.configuration.uiMode
|
||||
if (SDK_INT < 29) return THEME_LIGHT;
|
||||
val uiMode = context.resources.configuration.uiMode
|
||||
return if ((uiMode and UI_MODE_NIGHT_MASK) == UI_MODE_NIGHT_YES) {
|
||||
THEME_DARK;
|
||||
} else {
|
||||
@@ -47,25 +47,18 @@ constructor(
|
||||
}
|
||||
|
||||
override fun applyDarkTheme() {
|
||||
activity.setTheme(R.style.AppBaseThemeDark)
|
||||
activity.window.navigationBarColor =
|
||||
ContextCompat.getColor(activity, R.color.grey_900)
|
||||
context.setTheme(R.style.AppBaseThemeDark)
|
||||
(context as Activity).window.navigationBarColor =
|
||||
ContextCompat.getColor(context, R.color.grey_900)
|
||||
}
|
||||
|
||||
override fun applyLightTheme() {
|
||||
activity.setTheme(R.style.AppBaseTheme)
|
||||
context.setTheme(R.style.AppBaseTheme)
|
||||
}
|
||||
|
||||
override fun applyPureBlackTheme() {
|
||||
activity.setTheme(R.style.AppBaseThemeDark_PureBlack)
|
||||
activity.window.navigationBarColor =
|
||||
ContextCompat.getColor(activity, R.color.black)
|
||||
}
|
||||
|
||||
fun getDialogTheme(): Int {
|
||||
return when {
|
||||
isNightMode -> R.style.DarkDialogWithTitle
|
||||
else -> R.style.DialogWithTitle
|
||||
}
|
||||
context.setTheme(R.style.AppBaseThemeDark_PureBlack)
|
||||
(context as Activity).window.navigationBarColor =
|
||||
ContextCompat.getColor(context, R.color.black)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,12 @@ package org.isoron.uhabits.activities
|
||||
|
||||
import android.content.*
|
||||
import android.os.*
|
||||
import org.isoron.androidbase.activities.*
|
||||
import androidx.appcompat.app.*
|
||||
import org.isoron.androidbase.*
|
||||
import org.isoron.uhabits.*
|
||||
import org.isoron.uhabits.core.models.*
|
||||
|
||||
abstract class HabitsActivity : BaseActivity() {
|
||||
abstract class HabitsActivity : AppCompatActivity() {
|
||||
lateinit var component: HabitsActivityComponent
|
||||
lateinit var appComponent: HabitsApplicationComponent
|
||||
|
||||
@@ -43,8 +44,6 @@ abstract class HabitsActivity : BaseActivity() {
|
||||
component = DaggerHabitsActivityComponent
|
||||
.builder()
|
||||
.activityContextModule(ActivityContextModule(this))
|
||||
.baseActivityModule(BaseActivityModule(this))
|
||||
.habitModule(HabitModule(habit))
|
||||
.habitsApplicationComponent(appComponent)
|
||||
.build()
|
||||
|
||||
|
||||
@@ -20,20 +20,17 @@
|
||||
package org.isoron.uhabits.activities
|
||||
|
||||
import dagger.*
|
||||
import org.isoron.androidbase.activities.*
|
||||
import org.isoron.androidbase.*
|
||||
import org.isoron.uhabits.*
|
||||
import org.isoron.uhabits.activities.about.*
|
||||
import org.isoron.uhabits.activities.common.dialogs.*
|
||||
import org.isoron.uhabits.activities.habits.list.*
|
||||
import org.isoron.uhabits.activities.habits.list.views.*
|
||||
import org.isoron.uhabits.activities.habits.show.*
|
||||
import org.isoron.uhabits.core.ui.*
|
||||
import org.isoron.uhabits.core.ui.screens.habits.list.*
|
||||
|
||||
@ActivityScope
|
||||
@Component(modules = arrayOf(
|
||||
ActivityContextModule::class,
|
||||
BaseActivityModule::class,
|
||||
HabitsActivityModule::class,
|
||||
ListHabitsModule::class,
|
||||
HabitModule::class
|
||||
|
||||
@@ -19,8 +19,9 @@
|
||||
|
||||
package org.isoron.uhabits.activities
|
||||
|
||||
import android.content.*
|
||||
import dagger.*
|
||||
import org.isoron.androidbase.activities.*
|
||||
import org.isoron.androidbase.*
|
||||
import org.isoron.uhabits.core.preferences.*
|
||||
import org.isoron.uhabits.core.ui.*
|
||||
|
||||
@@ -29,9 +30,10 @@ class HabitsActivityModule {
|
||||
|
||||
@Provides
|
||||
@ActivityScope
|
||||
fun getThemeSwitcher(activity: BaseActivity,
|
||||
prefs: Preferences
|
||||
): ThemeSwitcher {
|
||||
return AndroidThemeSwitcher(activity, prefs)
|
||||
fun getThemeSwitcher(
|
||||
@ActivityContext context: Context,
|
||||
prefs: Preferences
|
||||
): ThemeSwitcher {
|
||||
return AndroidThemeSwitcher(context, prefs)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ package org.isoron.uhabits.activities.common.dialogs;
|
||||
|
||||
import android.content.*;
|
||||
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.androidbase.*;
|
||||
import org.isoron.androidbase.utils.*;
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
|
||||
@@ -27,9 +27,9 @@ import androidx.appcompat.app.*;
|
||||
|
||||
import com.google.auto.factory.*;
|
||||
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.androidbase.*;
|
||||
import org.isoron.uhabits.core.ui.callbacks.*;
|
||||
import org.isoron.uhabits.R;
|
||||
|
||||
/**
|
||||
* Dialog that asks the user confirmation before executing a delete operation.
|
||||
|
||||
@@ -27,9 +27,9 @@ import androidx.appcompat.app.*;
|
||||
|
||||
import com.google.auto.factory.*;
|
||||
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.androidbase.*;
|
||||
import org.isoron.uhabits.core.ui.callbacks.*;
|
||||
import org.isoron.uhabits.R;
|
||||
|
||||
@AutoFactory(allowSubclasses = true)
|
||||
public class ConfirmSyncKeyDialog extends AlertDialog
|
||||
|
||||
@@ -26,9 +26,9 @@ import android.view.*
|
||||
import android.view.WindowManager.LayoutParams.*
|
||||
import android.view.inputmethod.*
|
||||
import android.widget.*
|
||||
import org.isoron.androidbase.activities.*
|
||||
import org.isoron.androidbase.*
|
||||
import org.isoron.androidbase.utils.*
|
||||
import org.isoron.uhabits.*
|
||||
import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.core.ui.screens.habits.list.*
|
||||
import javax.inject.*
|
||||
|
||||
|
||||
@@ -19,10 +19,11 @@
|
||||
|
||||
package org.isoron.uhabits.activities.habits.list
|
||||
|
||||
import android.content.*
|
||||
import android.os.*
|
||||
import android.view.*
|
||||
import kotlinx.coroutines.*
|
||||
import org.isoron.uhabits.*
|
||||
import org.isoron.androidbase.*
|
||||
import org.isoron.uhabits.activities.*
|
||||
import org.isoron.uhabits.activities.habits.list.views.*
|
||||
import org.isoron.uhabits.core.preferences.*
|
||||
@@ -31,6 +32,7 @@ import org.isoron.uhabits.core.tasks.*
|
||||
import org.isoron.uhabits.core.ui.ThemeSwitcher.*
|
||||
import org.isoron.uhabits.core.utils.*
|
||||
import org.isoron.uhabits.database.*
|
||||
import org.isoron.uhabits.utils.*
|
||||
|
||||
class ListHabitsActivity : HabitsActivity() {
|
||||
|
||||
@@ -57,8 +59,7 @@ class ListHabitsActivity : HabitsActivity() {
|
||||
adapter = component.habitCardListAdapter
|
||||
taskRunner = appComponent.taskRunner
|
||||
menu = component.listHabitsMenu
|
||||
|
||||
setScreen(screen)
|
||||
Thread.setDefaultUncaughtExceptionHandler(BaseExceptionHandler(this))
|
||||
component.listHabitsBehavior.onStartup()
|
||||
setContentView(rootView)
|
||||
}
|
||||
@@ -98,4 +99,9 @@ class ListHabitsActivity : HabitsActivity() {
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return menu.onItemSelected(item)
|
||||
}
|
||||
|
||||
override fun onActivityResult(request: Int, result: Int, data: Intent?) {
|
||||
super.onActivityResult(request, result, data)
|
||||
screen.onResult(request, result, data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,9 +19,11 @@
|
||||
|
||||
package org.isoron.uhabits.activities.habits.list
|
||||
|
||||
import android.content.*
|
||||
import android.view.*
|
||||
import org.isoron.androidbase.activities.*
|
||||
import org.isoron.uhabits.*
|
||||
import androidx.appcompat.app.*
|
||||
import org.isoron.androidbase.*
|
||||
import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.core.preferences.*
|
||||
import org.isoron.uhabits.core.ui.*
|
||||
import org.isoron.uhabits.core.ui.screens.habits.list.*
|
||||
@@ -29,11 +31,12 @@ import javax.inject.*
|
||||
|
||||
@ActivityScope
|
||||
class ListHabitsMenu @Inject constructor(
|
||||
private val activity: BaseActivity,
|
||||
@ActivityContext context: Context,
|
||||
private val preferences: Preferences,
|
||||
private val themeSwitcher: ThemeSwitcher,
|
||||
private val behavior: ListHabitsMenuBehavior
|
||||
) {
|
||||
val activity = (context as AppCompatActivity)
|
||||
|
||||
fun onCreate(inflater: MenuInflater, menu: Menu) {
|
||||
menu.clear()
|
||||
|
||||
@@ -20,13 +20,10 @@
|
||||
package org.isoron.uhabits.activities.habits.list
|
||||
|
||||
import android.content.*
|
||||
import android.os.Build.VERSION.*
|
||||
import android.os.Build.VERSION_CODES.*
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
import android.view.ViewGroup.LayoutParams.*
|
||||
import android.widget.*
|
||||
import org.isoron.androidbase.activities.*
|
||||
import org.isoron.uhabits.*
|
||||
import org.isoron.androidbase.*
|
||||
import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.activities.common.views.*
|
||||
import org.isoron.uhabits.activities.habits.list.views.*
|
||||
import org.isoron.uhabits.core.models.*
|
||||
|
||||
@@ -23,10 +23,11 @@ import android.app.*
|
||||
import android.content.*
|
||||
import android.util.*
|
||||
import androidx.annotation.*
|
||||
import androidx.appcompat.app.*
|
||||
import dagger.*
|
||||
import org.isoron.androidbase.activities.*
|
||||
import org.isoron.androidbase.*
|
||||
import org.isoron.androidbase.utils.*
|
||||
import org.isoron.uhabits.*
|
||||
import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.activities.common.dialogs.*
|
||||
import org.isoron.uhabits.activities.habits.edit.*
|
||||
import org.isoron.uhabits.activities.habits.list.views.*
|
||||
@@ -54,8 +55,7 @@ const val REQUEST_SETTINGS = 107
|
||||
@ActivityScope
|
||||
class ListHabitsScreen
|
||||
@Inject constructor(
|
||||
activity: BaseActivity,
|
||||
rootView: ListHabitsRootView,
|
||||
@ActivityContext val context: Context,
|
||||
private val commandRunner: CommandRunner,
|
||||
private val intentFactory: IntentFactory,
|
||||
private val themeSwitcher: ThemeSwitcher,
|
||||
@@ -68,12 +68,13 @@ class ListHabitsScreen
|
||||
private val colorPickerFactory: ColorPickerDialogFactory,
|
||||
private val numberPickerFactory: NumberPickerFactory,
|
||||
private val behavior: Lazy<ListHabitsBehavior>
|
||||
) : BaseScreen(activity),
|
||||
CommandRunner.Listener,
|
||||
) : CommandRunner.Listener,
|
||||
ListHabitsBehavior.Screen,
|
||||
ListHabitsMenuBehavior.Screen,
|
||||
ListHabitsSelectionMenuBehavior.Screen {
|
||||
|
||||
val activity = (context as AppCompatActivity)
|
||||
|
||||
fun onAttached() {
|
||||
commandRunner.addListener(this)
|
||||
if(activity.intent.action == "android.intent.action.VIEW") {
|
||||
@@ -98,7 +99,7 @@ class ListHabitsScreen
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
fun onResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
when (requestCode) {
|
||||
REQUEST_OPEN_DOCUMENT -> onOpenDocumentResult(resultCode, data)
|
||||
REQUEST_SETTINGS -> onSettingsResult(resultCode)
|
||||
@@ -142,15 +143,15 @@ class ListHabitsScreen
|
||||
|
||||
override fun showSelectHabitTypeDialog() {
|
||||
val dialog = HabitTypeDialog()
|
||||
activity.showDialog(dialog, "habitType")
|
||||
dialog.show(activity.supportFragmentManager, "habitType")
|
||||
}
|
||||
|
||||
override fun showDeleteConfirmationScreen(callback: OnConfirmedCallback) {
|
||||
activity.showDialog(confirmDeleteDialogFactory.create(callback))
|
||||
confirmDeleteDialogFactory.create(callback).show()
|
||||
}
|
||||
|
||||
override fun showEditHabitsScreen(habits: List<Habit>) {
|
||||
val intent = intentFactory.startEditActivity(activity!!, habits[0])
|
||||
val intent = intentFactory.startEditActivity(activity, habits[0])
|
||||
activity.startActivity(intent)
|
||||
}
|
||||
|
||||
@@ -190,7 +191,11 @@ class ListHabitsScreen
|
||||
override fun showSendBugReportToDeveloperScreen(log: String) {
|
||||
val to = R.string.bugReportTo
|
||||
val subject = R.string.bugReportSubject
|
||||
showSendEmailScreen(to, subject, log)
|
||||
activity.showSendEmailScreen(to, subject, log)
|
||||
}
|
||||
|
||||
override fun showSendFileScreen(filename: String) {
|
||||
activity.showSendFileScreen(filename)
|
||||
}
|
||||
|
||||
override fun showSettingsScreen() {
|
||||
@@ -202,7 +207,7 @@ class ListHabitsScreen
|
||||
callback: OnColorPickedCallback) {
|
||||
val picker = colorPickerFactory.create(defaultColor)
|
||||
picker.setListener(callback)
|
||||
activity.showDialog(picker, "picker")
|
||||
picker.show(activity.supportFragmentManager, "picker")
|
||||
}
|
||||
|
||||
override fun showNumberPicker(value: Double,
|
||||
@@ -212,7 +217,7 @@ class ListHabitsScreen
|
||||
}
|
||||
|
||||
override fun showConfirmInstallSyncKey(callback: OnConfirmedCallback) {
|
||||
activity.showDialog(confirmSyncKeyDialogFactory.create(callback))
|
||||
confirmSyncKeyDialogFactory.create(callback).show()
|
||||
}
|
||||
|
||||
@StringRes
|
||||
@@ -244,7 +249,7 @@ class ListHabitsScreen
|
||||
|
||||
private fun onExportDB() {
|
||||
taskRunner.execute(exportDBFactory.create { filename ->
|
||||
if (filename != null) showSendFileScreen(filename)
|
||||
if (filename != null) activity.showSendFileScreen(filename)
|
||||
else activity.showMessage(R.string.could_not_export)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -19,11 +19,13 @@
|
||||
|
||||
package org.isoron.uhabits.activities.habits.list
|
||||
|
||||
import android.content.*
|
||||
import android.view.*
|
||||
import androidx.appcompat.app.*
|
||||
import androidx.appcompat.view.ActionMode
|
||||
import dagger.*
|
||||
import org.isoron.androidbase.activities.*
|
||||
import org.isoron.uhabits.*
|
||||
import org.isoron.androidbase.*
|
||||
import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.activities.habits.list.views.*
|
||||
import org.isoron.uhabits.core.commands.*
|
||||
import org.isoron.uhabits.core.preferences.*
|
||||
@@ -34,7 +36,7 @@ import javax.inject.*
|
||||
|
||||
@ActivityScope
|
||||
class ListHabitsSelectionMenu @Inject constructor(
|
||||
private val activity: BaseActivity,
|
||||
@ActivityContext context: Context,
|
||||
private val listAdapter: HabitCardListAdapter,
|
||||
var commandRunner: CommandRunner,
|
||||
private val prefs: Preferences,
|
||||
@@ -43,6 +45,8 @@ class ListHabitsSelectionMenu @Inject constructor(
|
||||
private val notificationTray: NotificationTray
|
||||
) : ActionMode.Callback {
|
||||
|
||||
val activity = (context as AppCompatActivity)
|
||||
|
||||
var activeActionMode: ActionMode? = null
|
||||
|
||||
fun onSelectionStart() {
|
||||
|
||||
@@ -25,8 +25,8 @@ import android.text.*
|
||||
import android.view.*
|
||||
import android.view.View.MeasureSpec.*
|
||||
import com.google.auto.factory.*
|
||||
import org.isoron.androidbase.activities.*
|
||||
import org.isoron.uhabits.*
|
||||
import org.isoron.androidbase.*
|
||||
import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.core.models.*
|
||||
import org.isoron.uhabits.core.models.Checkmark.*
|
||||
import org.isoron.uhabits.core.preferences.*
|
||||
|
||||
@@ -21,7 +21,7 @@ package org.isoron.uhabits.activities.habits.list.views
|
||||
|
||||
import android.content.*
|
||||
import com.google.auto.factory.*
|
||||
import org.isoron.androidbase.activities.*
|
||||
import org.isoron.androidbase.*
|
||||
import org.isoron.uhabits.core.models.*
|
||||
import org.isoron.uhabits.core.models.Checkmark.*
|
||||
import org.isoron.uhabits.core.preferences.*
|
||||
|
||||
@@ -26,7 +26,7 @@ import android.view.*;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.androidbase.*;
|
||||
import org.isoron.uhabits.activities.habits.list.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
package org.isoron.uhabits.activities.habits.list.views
|
||||
|
||||
import dagger.*
|
||||
import org.isoron.androidbase.activities.*
|
||||
import org.isoron.androidbase.*
|
||||
import org.isoron.uhabits.activities.habits.list.*
|
||||
import org.isoron.uhabits.core.models.*
|
||||
import org.isoron.uhabits.core.ui.screens.habits.list.*
|
||||
|
||||
@@ -21,13 +21,12 @@ package org.isoron.uhabits.activities.habits.list.views
|
||||
|
||||
import android.content.*
|
||||
import android.os.*
|
||||
import androidx.appcompat.widget.*
|
||||
import androidx.recyclerview.widget.*
|
||||
import androidx.recyclerview.widget.ItemTouchHelper.*
|
||||
import android.view.*
|
||||
import com.google.auto.factory.*
|
||||
import dagger.*
|
||||
import org.isoron.androidbase.activities.*
|
||||
import org.isoron.androidbase.*
|
||||
import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.activities.common.views.*
|
||||
import org.isoron.uhabits.core.models.*
|
||||
|
||||
@@ -28,8 +28,8 @@ import android.view.*
|
||||
import android.view.ViewGroup.LayoutParams.*
|
||||
import android.widget.*
|
||||
import com.google.auto.factory.*
|
||||
import org.isoron.androidbase.activities.*
|
||||
import org.isoron.uhabits.*
|
||||
import org.isoron.androidbase.*
|
||||
import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.activities.common.views.*
|
||||
import org.isoron.uhabits.core.models.*
|
||||
import org.isoron.uhabits.core.ui.screens.habits.list.*
|
||||
|
||||
@@ -25,10 +25,10 @@ import android.text.*
|
||||
import android.view.*
|
||||
import android.view.View.*
|
||||
import com.google.auto.factory.*
|
||||
import org.isoron.androidbase.activities.*
|
||||
import org.isoron.androidbase.*
|
||||
import org.isoron.androidbase.utils.*
|
||||
import org.isoron.androidbase.utils.InterfaceUtils.getDimension
|
||||
import org.isoron.uhabits.*
|
||||
import org.isoron.uhabits.R
|
||||
import org.isoron.uhabits.core.preferences.*
|
||||
import org.isoron.uhabits.utils.*
|
||||
import java.text.*
|
||||
|
||||
@@ -21,7 +21,7 @@ package org.isoron.uhabits.activities.habits.list.views
|
||||
|
||||
import android.content.*
|
||||
import com.google.auto.factory.*
|
||||
import org.isoron.androidbase.activities.*
|
||||
import org.isoron.androidbase.*
|
||||
import org.isoron.uhabits.core.models.*
|
||||
import org.isoron.uhabits.core.preferences.*
|
||||
import org.isoron.uhabits.core.utils.*
|
||||
|
||||
@@ -20,14 +20,14 @@ package org.isoron.uhabits.activities.settings
|
||||
|
||||
import android.os.*
|
||||
import android.view.*
|
||||
import org.isoron.androidbase.activities.*
|
||||
import androidx.appcompat.app.*
|
||||
import org.isoron.uhabits.*
|
||||
import org.isoron.uhabits.activities.*
|
||||
import org.isoron.uhabits.core.models.*
|
||||
import org.isoron.uhabits.databinding.*
|
||||
import org.isoron.uhabits.utils.*
|
||||
|
||||
class SettingsActivity : BaseActivity() {
|
||||
class SettingsActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val component = (application as HabitsApplication).component
|
||||
|
||||
@@ -23,7 +23,7 @@ import android.app.*
|
||||
import android.content.*
|
||||
import android.graphics.*
|
||||
import android.graphics.drawable.*
|
||||
import android.util.*
|
||||
import android.os.*
|
||||
import android.view.*
|
||||
import android.view.ViewGroup.LayoutParams.*
|
||||
import android.widget.*
|
||||
@@ -109,11 +109,35 @@ fun Activity.showSendFileScreen(archiveFilename: String) {
|
||||
fun Activity.startActivitySafely(intent: Intent) {
|
||||
try {
|
||||
startActivity(intent)
|
||||
} catch(e: ActivityNotFoundException) {
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
this.showMessage(R.string.activity_not_found)
|
||||
}
|
||||
}
|
||||
|
||||
fun Activity.showSendEmailScreen(@StringRes toId: Int, @StringRes subjectId: Int, content: String?) {
|
||||
val to = this.getString(toId)
|
||||
val subject = this.getString(subjectId)
|
||||
this.startActivity(Intent().apply {
|
||||
action = Intent.ACTION_SEND
|
||||
type = "message/rfc822"
|
||||
putExtra(Intent.EXTRA_EMAIL, arrayOf(to))
|
||||
putExtra(Intent.EXTRA_SUBJECT, subject)
|
||||
putExtra(Intent.EXTRA_TEXT, content)
|
||||
})
|
||||
}
|
||||
|
||||
fun Activity.restartWithFade(cls: Class<*>?) {
|
||||
Handler().postDelayed(
|
||||
{
|
||||
finish()
|
||||
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out)
|
||||
startActivity(Intent(this, cls))
|
||||
},
|
||||
500,
|
||||
) // HACK: Let the menu disappear first
|
||||
}
|
||||
|
||||
|
||||
fun View.setupToolbar(
|
||||
toolbar: Toolbar,
|
||||
title: String,
|
||||
|
||||
Reference in New Issue
Block a user