diff --git a/android/android-base/src/main/java/org/isoron/androidbase/activities/BaseRootView.java b/android/android-base/src/main/java/org/isoron/androidbase/activities/BaseRootView.java deleted file mode 100644 index 3ff339387..000000000 --- a/android/android-base/src/main/java/org/isoron/androidbase/activities/BaseRootView.java +++ /dev/null @@ -1,110 +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.*; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.widget.Toolbar; -import android.view.*; -import android.widget.*; - -import org.isoron.androidbase.*; -import org.isoron.androidbase.utils.*; - -import static android.os.Build.VERSION.SDK_INT; -import static android.os.Build.VERSION_CODES.LOLLIPOP; - -/** - * 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. - */ -public abstract class BaseRootView extends FrameLayout -{ - @NonNull - private final Context context; - - protected boolean shouldDisplayHomeAsUp = false; - - @Nullable - private BaseScreen screen; - - public BaseRootView(@NonNull Context context) - { - super(context); - this.context = context; - } - - public boolean getDisplayHomeAsUp() - { - return shouldDisplayHomeAsUp; - } - - public void setDisplayHomeAsUp(boolean b) - { - shouldDisplayHomeAsUp = b; - } - - @NonNull - public Toolbar getToolbar() - { - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - if (toolbar == null) throw new RuntimeException( - "Your BaseRootView should have a " + - "toolbar with id R.id.toolbar"); - return toolbar; - } - - public int getToolbarColor() - { - StyledResources res = new StyledResources(context); - return res.getColor(R.attr.colorPrimary); - } - - protected void initToolbar() - { - if (SDK_INT >= LOLLIPOP) - { - getToolbar().setElevation(InterfaceUtils.dpToPixels(context, 2)); - - View view = findViewById(R.id.toolbarShadow); - if (view != null) view.setVisibility(GONE); - - view = findViewById(R.id.headerShadow); - if (view != null) view.setVisibility(GONE); - } - } - - public void onAttachedToScreen(BaseScreen screen) - { - this.screen = screen; - } - - @Nullable - public BaseScreen getScreen() - { - return screen; - } -} 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 new file mode 100644 index 000000000..cc8fb3c7e --- /dev/null +++ b/android/android-base/src/main/java/org/isoron/androidbase/activities/BaseRootView.kt @@ -0,0 +1,63 @@ +/* + * 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/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/TaskProgressBar.kt b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/TaskProgressBar.kt index 13a23fc07..452c60369 100644 --- a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/TaskProgressBar.kt +++ b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/TaskProgressBar.kt @@ -20,8 +20,8 @@ package org.isoron.uhabits.activities.common.views import android.content.* +import android.view.* import android.widget.* -import org.isoron.androidbase.activities.* import org.isoron.uhabits.core.tasks.* class TaskProgressBar( @@ -34,7 +34,7 @@ class TaskProgressBar( ), TaskRunner.Listener { init { - visibility = BaseRootView.GONE + visibility = View.GONE isIndeterminate = true } diff --git a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/EmptyListView.kt b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/EmptyListView.kt index 3d4ddafb1..c92eb341f 100644 --- a/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/EmptyListView.kt +++ b/android/uhabits-android/src/main/java/org/isoron/uhabits/activities/habits/list/views/EmptyListView.kt @@ -24,15 +24,14 @@ import android.view.* import android.view.Gravity.* import android.view.ViewGroup.LayoutParams.* import android.widget.* -import org.isoron.androidbase.activities.* import org.isoron.uhabits.* import org.isoron.uhabits.utils.* class EmptyListView(context: Context) : LinearLayout(context) { init { orientation = VERTICAL - gravity = Gravity.CENTER - visibility = BaseRootView.GONE + gravity = CENTER + visibility = View.GONE addView(TextView(context).apply { text = str(R.string.fa_star_half_o)