diff --git a/android/android-base/src/main/java/org/isoron/androidbase/activities/BaseRootView.kt b/android/android-base/src/main/java/org/isoron/androidbase/activities/BaseRootView.kt deleted file mode 100644 index cc8fb3c7e..000000000 --- a/android/android-base/src/main/java/org/isoron/androidbase/activities/BaseRootView.kt +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2016 Álinson Santos Xavier - * - * 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 . - */ -package org.isoron.androidbase.activities - -import android.content.Context -import android.os.Build.VERSION -import android.os.Build.VERSION_CODES -import android.view.View -import android.widget.FrameLayout -import androidx.appcompat.widget.Toolbar -import org.isoron.androidbase.R -import org.isoron.androidbase.utils.InterfaceUtils.dpToPixels -import org.isoron.androidbase.utils.StyledResources - -/** - * Base class for all root views in the application. - * - * - * A root view is an Android view that is directly attached to an activity. This - * view usually includes a toolbar and a progress bar. This abstract class hides - * some of the complexity of setting these things up, for every version of - * Android. - */ -abstract class BaseRootView(context: Context) : FrameLayout(context) { - var displayHomeAsUp = false - var screen: BaseScreen? = null - private set - - open fun getToolbar(): Toolbar { - return findViewById(R.id.toolbar) - ?: throw RuntimeException("Your BaseRootView should have a toolbar with id R.id.toolbar") - } - - open fun getToolbarColor(): Int = StyledResources(context).getColor(R.attr.colorPrimary) - - protected open fun initToolbar() { - if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) { - getToolbar().elevation = dpToPixels(context, 2f) - findViewById(R.id.toolbarShadow)?.visibility = View.GONE - findViewById(R.id.headerShadow)?.visibility = View.GONE - } - } - - fun onAttachedToScreen(screen: BaseScreen?) { - this.screen = screen - } -} \ No newline at end of file diff --git a/android/android-base/src/main/java/org/isoron/androidbase/activities/BaseScreen.kt b/android/android-base/src/main/java/org/isoron/androidbase/activities/BaseScreen.kt index edd0f257b..4ef72cd91 100644 --- a/android/android-base/src/main/java/org/isoron/androidbase/activities/BaseScreen.kt +++ b/android/android-base/src/main/java/org/isoron/androidbase/activities/BaseScreen.kt @@ -43,31 +43,8 @@ import java.io.* */ open class BaseScreen(@JvmField protected var activity: BaseActivity) { - private var rootView: BaseRootView? = null private var snackbar: Snackbar? = null - /** - * Notifies the screen that its contents should be updated. - */ - fun invalidate() { - rootView?.invalidate() - } - - fun invalidateToolbar() { - rootView?.let { root -> - activity.runOnUiThread { - val toolbar = root.getToolbar() - activity.setSupportActionBar(toolbar) - activity.supportActionBar?.let { actionBar -> - actionBar.setDisplayHomeAsUpEnabled(root.displayHomeAsUp) - val color = root.getToolbarColor() - setActionBarColor(actionBar, color) - setStatusBarColor(color) - } - } - } - } - /** * Called when another Activity has finished, and has returned some result. * @@ -85,19 +62,6 @@ open class BaseScreen(@JvmField protected var activity: BaseActivity) { */ open fun reattachDialogs() {} - /** - * Sets the root view for this screen. - * - * @param rootView the root view for this screen. - */ - fun setRootView(rootView: BaseRootView?) { - this.rootView = rootView - activity.setContentView(rootView) - rootView?.let { - it.onAttachedToScreen(this) - invalidateToolbar() - } - } /** * Shows a message on the screen. @@ -118,10 +82,6 @@ open class BaseScreen(@JvmField protected var activity: BaseActivity) { snackbar.show() } - fun showMessage(@StringRes stringId: Int?) { - showMessage(stringId, this.rootView) - } - fun showSendEmailScreen(@StringRes toId: Int, @StringRes subjectId: Int, content: String?) { val to = activity.getString(toId) val subject = activity.getString(subjectId) @@ -144,14 +104,4 @@ open class BaseScreen(@JvmField protected var activity: BaseActivity) { flags = Intent.FLAG_GRANT_READ_URI_PERMISSION }) } - - private fun setActionBarColor(actionBar: ActionBar, color: Int) { - val drawable = ColorDrawable(color) - actionBar.setBackgroundDrawable(drawable) - } - - private fun setStatusBarColor(baseColor: Int) { - val darkerColor = mixColors(baseColor, Color.BLACK, 0.75f) - activity.window.statusBarColor = darkerColor - } } \ No newline at end of file diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsActivity.kt b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsActivity.kt index a4f91a864..90ad83c59 100644 --- a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsActivity.kt +++ b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsActivity.kt @@ -60,7 +60,7 @@ class ListHabitsActivity : HabitsActivity() { setScreen(screen) component.listHabitsBehavior.onStartup() - setTitle(R.string.main_activity_title) + setContentView(rootView) } override fun onPause() { diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsRootView.kt b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsRootView.kt index 268c1e06a..7f00d586c 100644 --- a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsRootView.kt +++ b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsRootView.kt @@ -49,7 +49,7 @@ class ListHabitsRootView @Inject constructor( runner: TaskRunner, private val listAdapter: HabitCardListAdapter, habitCardListViewFactory: HabitCardListViewFactory -) : BaseRootView(context), ModelObservable.Listener { +) : FrameLayout(context), ModelObservable.Listener { val listView: HabitCardListView = habitCardListViewFactory.create() val llEmpty = EmptyListView(context) @@ -63,7 +63,7 @@ class ListHabitsRootView @Inject constructor( val hintList = hintListFactory.create(hints) hintView = HintView(context, hintList) - addView(RelativeLayout(context).apply { + val rootView = RelativeLayout(context).apply { background = sres.getDrawable(R.attr.windowBackgroundColor) addAtTop(tbar) addBelow(header, tbar) @@ -73,18 +73,15 @@ class ListHabitsRootView @Inject constructor( it.topMargin = dp(-6.0f).toInt() } addAtBottom(hintView) - if (SDK_INT < LOLLIPOP) { - addBelow(ShadowView(context), tbar) - addBelow(ShadowView(context), header) - } - }, MATCH_PARENT, MATCH_PARENT) - + } + rootView.setupToolbar( + toolbar = tbar, + title = resources.getString(R.string.main_activity_title), + color = PaletteColor(17), + displayHomeAsUpEnabled = false, + ) + addView(rootView, MATCH_PARENT, MATCH_PARENT) listAdapter.setListView(listView) - initToolbar() - } - - override fun getToolbar(): Toolbar { - return tbar } override fun onModelChange() { diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.kt b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.kt index c2362641a..990365fb5 100644 --- a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.kt +++ b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/ListHabitsScreen.kt @@ -39,6 +39,7 @@ import org.isoron.uhabits.core.ui.screens.habits.list.* import org.isoron.uhabits.core.ui.screens.habits.list.ListHabitsBehavior.Message.* import org.isoron.uhabits.intents.* import org.isoron.uhabits.tasks.* +import org.isoron.uhabits.utils.* import java.io.* import javax.inject.* @@ -73,10 +74,6 @@ class ListHabitsScreen ListHabitsMenuBehavior.Screen, ListHabitsSelectionMenuBehavior.Screen { - init { - setRootView(rootView) - } - fun onAttached() { commandRunner.addListener(this) if(activity.intent.action == "android.intent.action.VIEW") { @@ -94,8 +91,11 @@ class ListHabitsScreen } override fun onCommandExecuted(command: Command?, refreshKey: Long?) { - if (command != null) - showMessage(getExecuteString(command)) + if (command != null) { + val stringId = getExecuteString(command) + if (stringId != null) + activity.showMessage(stringId) + } } override fun onResult(requestCode: Int, resultCode: Int, data: Intent?) { @@ -115,7 +115,7 @@ class ListHabitsScreen inStream.copyTo(tempFile) onImportData(tempFile) { tempFile.delete() } } catch (e: IOException) { - showMessage(R.string.could_not_import) + activity.showMessage(R.string.could_not_import) e.printStackTrace() } } @@ -175,7 +175,7 @@ class ListHabitsScreen } override fun showMessage(m: ListHabitsBehavior.Message) { - showMessage(when (m) { + activity.showMessage(when (m) { COULD_NOT_EXPORT -> R.string.could_not_export IMPORT_SUCCESSFUL -> R.string.habits_imported IMPORT_FAILED -> R.string.could_not_import @@ -232,11 +232,11 @@ class ListHabitsScreen taskRunner.execute(importTaskFactory.create(file) { result -> if (result == ImportDataTask.SUCCESS) { adapter.refresh() - showMessage(R.string.habits_imported) + activity.showMessage(R.string.habits_imported) } else if (result == ImportDataTask.NOT_RECOGNIZED) { - showMessage(R.string.file_not_recognized) + activity.showMessage(R.string.file_not_recognized) } else { - showMessage(R.string.could_not_import) + activity.showMessage(R.string.could_not_import) } onFinished() }) @@ -245,7 +245,7 @@ class ListHabitsScreen private fun onExportDB() { taskRunner.execute(exportDBFactory.create { filename -> if (filename != null) showSendFileScreen(filename) - else showMessage(R.string.could_not_export) + else activity.showMessage(R.string.could_not_export) }) } }