Refactor AboutActivity

pull/699/head
Alinson S. Xavier 5 years ago
parent 826ea17cdd
commit 638bc2816f

@ -93,12 +93,4 @@ abstract class BaseActivity : AppCompatActivity() {
super.onResume()
screen?.reattachDialogs()
}
override fun startActivity(intent: Intent?) {
try {
super.startActivity(intent)
} catch(e: ActivityNotFoundException) {
this.screen?.showMessage(R.string.activity_not_found)
}
}
}

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2016-2020 Á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/>.
-->
<resources>
<string name="activity_not_found">No app was found to support this action</string>
</resources>

@ -16,30 +16,25 @@
* 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.uhabits.activities.about
package org.isoron.uhabits.activities.about;
import android.os.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.activities.*;
import android.os.*
import androidx.appcompat.app.*
import org.isoron.uhabits.*
import org.isoron.uhabits.activities.*
/**
* Activity that allows the user to see information about the app itself.
* Display current version, link to Google Play and list of contributors.
*/
public class AboutActivity extends HabitsActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
HabitsApplication app = (HabitsApplication) getApplication();
AboutScreen screen = new AboutScreen(this,
app.getComponent().getIntentFactory(),
app.getComponent().getPreferences());
AboutRootView rootView = new AboutRootView(this, screen);
screen.setRootView(rootView);
setScreen(screen);
class AboutActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val app = application as HabitsApplication
val screen = AboutScreen(this,
app.component.intentFactory,
app.component.preferences)
AndroidThemeSwitcher(this, app.component.preferences).apply()
setContentView(AboutView(this, screen))
}
}
}

@ -1,118 +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.uhabits.activities.about;
import android.content.*;
import android.widget.*;
import androidx.annotation.*;
import org.isoron.androidbase.activities.*;
import org.isoron.androidbase.utils.*;
import org.isoron.uhabits.BuildConfig;
import org.isoron.uhabits.R;
import javax.inject.*;
import butterknife.*;
public class AboutRootView extends BaseRootView
{
@BindView(R.id.tvVersion)
TextView tvVersion;
@NonNull
private final AboutScreen screen;
@Inject
public AboutRootView(@NonNull @ActivityContext Context context,
@NonNull AboutScreen screen)
{
super(context);
this.screen = screen;
addView(inflate(getContext(), R.layout.about, null));
ButterKnife.bind(this);
String version = getResources().getString(R.string.version_n);
tvVersion.setText(String.format(version, BuildConfig.VERSION_NAME));
setDisplayHomeAsUp(true);
}
@Override
public int getToolbarColor()
{
StyledResources res = new StyledResources(getContext());
if (!res.getBoolean(R.attr.useHabitColorAsPrimary))
return super.getToolbarColor();
return res.getColor(R.attr.aboutScreenColor);
}
@OnClick(R.id.tvFeedback)
public void onClickFeedback()
{
screen.showSendFeedbackScreen();
}
@OnClick(R.id.tvVersion)
public void onClickIcon()
{
screen.onPressDeveloperCountdown();
}
@OnClick(R.id.tvRate)
public void onClickRate()
{
screen.showRateAppWebsite();
}
@OnClick(R.id.tvSource)
public void onClickSource()
{
screen.showSourceCodeWebsite();
}
@OnClick(R.id.tvTranslate)
public void onClickTranslate()
{
screen.showTranslationWebsite();
}
@OnClick(R.id.tvPrivacy)
public void onClickPrivacy()
{
screen.showPrivacyPolicyWebsite();
}
@OnClick(R.id.tvContributors)
public void onClickContributors()
{
screen.showCodeContributorsWebsite();
}
@Override
protected void initToolbar()
{
super.initToolbar();
getToolbar().setTitle(getResources().getString(R.string.about));
}
}

@ -1,87 +0,0 @@
/*
* Copyright (C) 2017 Á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.uhabits.activities.about;
import android.widget.*;
import androidx.annotation.*;
import org.isoron.androidbase.activities.*;
import org.isoron.uhabits.core.preferences.*;
import org.isoron.uhabits.intents.*;
public class AboutScreen extends BaseScreen
{
@NonNull
private final Preferences prefs;
private int developerCountdown = 5;
@NonNull
private final IntentFactory intents;
public AboutScreen(@NonNull BaseActivity activity,
@NonNull IntentFactory intents,
@NonNull Preferences prefs)
{
super(activity);
this.intents = intents;
this.prefs = prefs;
}
public void showRateAppWebsite()
{
activity.startActivity(intents.rateApp(activity));
}
public void showSendFeedbackScreen()
{
activity.startActivity(intents.sendFeedback(activity));
}
public void showSourceCodeWebsite()
{
activity.startActivity(intents.viewSourceCode(activity));
}
public void showTranslationWebsite()
{
activity.startActivity(intents.helpTranslate(activity));
}
public void showPrivacyPolicyWebsite()
{
activity.startActivity(intents.privacyPolicy(activity));
}
public void showCodeContributorsWebsite()
{
activity.startActivity(intents.codeContributors(activity));
}
public void onPressDeveloperCountdown()
{
developerCountdown--;
if (developerCountdown == 0) {
prefs.setDeveloper(true);
Toast.makeText(activity, "You are now a developer", Toast.LENGTH_LONG).show();
}
}
}

@ -0,0 +1,59 @@
/*
* Copyright (C) 2017 Á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.uhabits.activities.about
import org.isoron.uhabits.*
import org.isoron.uhabits.core.preferences.*
import org.isoron.uhabits.intents.*
import org.isoron.uhabits.utils.*
class AboutScreen(
private val activity: AboutActivity,
private val intents: IntentFactory,
private val prefs: Preferences,
) {
private var developerCountdown = 5
fun showRateAppWebsite() =
activity.startActivitySafely(intents.rateApp(activity))
fun showSendFeedbackScreen() =
activity.startActivitySafely(intents.sendFeedback(activity))
fun showSourceCodeWebsite() =
activity.startActivitySafely(intents.viewSourceCode(activity))
fun showTranslationWebsite() =
activity.startActivitySafely(intents.helpTranslate(activity))
fun showPrivacyPolicyWebsite() =
activity.startActivitySafely(intents.privacyPolicy(activity))
fun showCodeContributorsWebsite() =
activity.startActivitySafely(intents.codeContributors(activity))
fun onPressDeveloperCountdown() {
developerCountdown--
if (developerCountdown == 0) {
prefs.isDeveloper = true
activity.showMessage(R.string.you_are_now_a_developer)
}
}
}

@ -0,0 +1,55 @@
/*
* 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.uhabits.activities.about
import android.annotation.*
import android.content.*
import android.view.*
import android.widget.*
import org.isoron.uhabits.*
import org.isoron.uhabits.core.models.*
import org.isoron.uhabits.databinding.*
import org.isoron.uhabits.utils.*
@SuppressLint("ViewConstructor")
class AboutView(
context: Context,
private val screen: AboutScreen,
) : FrameLayout(context) {
private var binding = AboutBinding.inflate(LayoutInflater.from(context))
init {
addView(binding.root)
setupToolbar(
toolbar = binding.toolbar,
color = PaletteColor(11),
title = resources.getString(R.string.about)
)
val version = resources.getString(R.string.version_n)
binding.tvContributors.setOnClickListener { screen.showCodeContributorsWebsite() }
binding.tvFeedback.setOnClickListener { screen.showSendFeedbackScreen() }
binding.tvPrivacy.setOnClickListener { screen.showPrivacyPolicyWebsite() }
binding.tvRate.setOnClickListener { screen.showRateAppWebsite() }
binding.tvSource.setOnClickListener { screen.showSourceCodeWebsite() }
binding.tvTranslate.setOnClickListener { screen.showTranslationWebsite() }
binding.tvVersion.setOnClickListener { screen.onPressDeveloperCountdown() }
binding.tvVersion.text = String.format(version, BuildConfig.VERSION_NAME)
}
}

@ -23,6 +23,7 @@ import android.app.*
import android.content.*
import android.graphics.*
import android.graphics.drawable.*
import android.util.*
import android.view.*
import android.view.ViewGroup.LayoutParams.*
import android.widget.*
@ -105,6 +106,14 @@ fun Activity.showSendFileScreen(archiveFilename: String) {
})
}
fun Activity.startActivitySafely(intent: Intent) {
try {
startActivity(intent)
} catch(e: ActivityNotFoundException) {
this.showMessage(R.string.activity_not_found)
}
}
fun View.setupToolbar(
toolbar: Toolbar,
title: String,

@ -217,4 +217,6 @@
<string name="sync_key_already_installed">Sync key already installed</string>
<string name="pref_unknown_title">Show question marks for missing data</string>
<string name="pref_unknown_description">Differentiate days without data from actual lapses. To enter a lapse, toggle twice.</string>
<string name="you_are_now_a_developer">You are now a developer</string>
<string name="activity_not_found">No app was found to support this action</string>
</resources>
Loading…
Cancel
Save