Refactor AboutActivity

pull/183/head
Alinson S. Xavier 9 years ago
parent 4e952dd87a
commit df1751b21a

@ -44,7 +44,7 @@ import java.io.*;
* attached to the main window. They are also responsible for showing other
* screens and for receiving their results.
*/
public abstract class BaseScreen
public class BaseScreen
{
protected BaseActivity activity;
@ -76,6 +76,7 @@ public abstract class BaseScreen
actionBar.setDisplayHomeAsUpEnabled(true);
ColorDrawable drawable = new ColorDrawable(color);
actionBar.setBackgroundDrawable(drawable);
@ -150,6 +151,20 @@ public abstract class BaseScreen
activity.setBaseMenu(menu);
}
/**
* Sets the root view for this screen.
*
* @param rootView the root view for this screen.
*/
public void setRootView(@Nullable BaseRootView rootView)
{
this.rootView = rootView;
activity.setContentView(rootView);
if (rootView == null) return;
invalidateToolbar();
}
/**
* Sets the menu to be shown when a selection is active on the screen.
*
@ -216,20 +231,6 @@ public abstract class BaseScreen
activity.startSupportActionMode(new ActionModeWrapper());
}
/**
* Sets the root view for this screen.
*
* @param rootView the root view for this screen.
*/
protected void setRootView(@Nullable BaseRootView rootView)
{
this.rootView = rootView;
activity.setContentView(rootView);
if (rootView == null) return;
invalidateToolbar();
}
private void setActionBarColor(@NonNull ActionBar actionBar, int color)
{
ColorDrawable drawable = new ColorDrawable(color);

@ -19,78 +19,24 @@
package org.isoron.uhabits.activities.about;
import android.content.*;
import android.net.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.activities.*;
import org.isoron.uhabits.utils.*;
import org.isoron.uhabits.intents.*;
/**
* 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 BaseActivity implements View.OnClickListener
public class AboutActivity extends BaseActivity
{
@Override
public void onClick(View v)
{
switch (v.getId())
{
case R.id.tvRate:
{
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(getString(R.string.playStoreURL)));
startActivity(intent);
break;
}
case R.id.tvFeedback:
{
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SENDTO);
intent.setData(Uri.parse(getString(R.string.feedbackURL)));
startActivity(intent);
break;
}
case R.id.tvSource:
{
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(getString(R.string.sourceCodeURL)));
startActivity(intent);
break;
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
StyledResources res = new StyledResources(this);
int color = res.getColor(R.attr.aboutScreenColor);
BaseScreen.setupActionBarColor(this, color);
TextView tvVersion = (TextView) findViewById(R.id.tvVersion);
TextView tvRate = (TextView) findViewById(R.id.tvRate);
TextView tvFeedback = (TextView) findViewById(R.id.tvFeedback);
TextView tvSource = (TextView) findViewById(R.id.tvSource);
tvVersion.setText(
String.format(getResources().getString(R.string.version_n),
BuildConfig.VERSION_NAME));
tvRate.setOnClickListener(this);
tvFeedback.setOnClickListener(this);
tvSource.setOnClickListener(this);
AboutRootView rootView = new AboutRootView(this, new IntentFactory());
BaseScreen screen = new BaseScreen(this);
screen.setRootView(rootView);
setScreen(screen);
}
}

@ -0,0 +1,117 @@
/*
* 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.support.annotation.*;
import android.support.v7.widget.Toolbar;
import android.widget.*;
import org.isoron.uhabits.BuildConfig;
import org.isoron.uhabits.*;
import org.isoron.uhabits.activities.*;
import org.isoron.uhabits.intents.*;
import org.isoron.uhabits.utils.*;
import butterknife.*;
public class AboutRootView extends BaseRootView
{
@BindView(R.id.tvVersion)
TextView tvVersion;
@BindView(R.id.tvRate)
TextView tvRate;
@BindView(R.id.tvFeedback)
TextView tvFeedback;
@BindView(R.id.tvSource)
TextView tvSource;
@BindView(R.id.toolbar)
Toolbar toolbar;
private final IntentFactory intents;
public AboutRootView(Context context, IntentFactory intents)
{
super(context);
this.intents = intents;
addView(inflate(getContext(), R.layout.about, null));
ButterKnife.bind(this);
tvVersion.setText(
String.format(getResources().getString(R.string.version_n),
BuildConfig.VERSION_NAME));
}
@Override
public boolean getDisplayHomeAsUp()
{
return true;
}
@NonNull
@Override
public Toolbar getToolbar()
{
return toolbar;
}
@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()
{
Intent intent = intents.sendFeedback(getContext());
getContext().startActivity(intent);
}
@OnClick(R.id.tvRate)
public void onClickRate()
{
Intent intent = intents.rateApp(getContext());
getContext().startActivity(intent);
}
@OnClick(R.id.tvSource)
public void onClickSource()
{
Intent intent = intents.viewSourceCode(getContext());
getContext().startActivity(intent);
}
@Override
protected void initToolbar()
{
super.initToolbar();
toolbar.setTitle(getResources().getString(R.string.about));
}
}

@ -21,13 +21,14 @@ package org.isoron.uhabits.intents;
import android.content.*;
import android.net.*;
import android.support.annotation.*;
import org.isoron.uhabits.*;
import org.isoron.uhabits.models.*;
import org.isoron.uhabits.activities.about.*;
import org.isoron.uhabits.activities.habits.show.*;
import org.isoron.uhabits.activities.intro.*;
import org.isoron.uhabits.activities.settings.*;
import org.isoron.uhabits.models.*;
import javax.inject.*;
@ -36,7 +37,18 @@ public class IntentFactory
@Inject
public IntentFactory()
{
}
public Intent rateApp(Context context)
{
String url = context.getString(R.string.playStoreURL);
return buildViewIntent(url);
}
public Intent sendFeedback(Context context)
{
String url = context.getString(R.string.feedbackURL);
return buildSendToIntent(url);
}
public Intent startAboutActivity(Context context)
@ -62,10 +74,32 @@ public class IntentFactory
}
public Intent viewFAQ(Context context)
{
String url = context.getString(R.string.helpURL);
return buildViewIntent(url);
}
public Intent viewSourceCode(Context context)
{
String url = context.getString(R.string.sourceCodeURL);
return buildViewIntent(url);
}
@NonNull
private Intent buildSendToIntent(String url)
{
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SENDTO);
intent.setData(Uri.parse(url));
return intent;
}
@NonNull
private Intent buildViewIntent(String url)
{
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(context.getString(R.string.helpURL)));
intent.setData(Uri.parse(url));
return intent;
}
}

Loading…
Cancel
Save