mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 01:28:52 -06:00
Switch from toasts to snackbars
This commit is contained in:
@@ -24,7 +24,6 @@ import android.os.*;
|
|||||||
import android.support.annotation.*;
|
import android.support.annotation.*;
|
||||||
import android.support.v7.app.*;
|
import android.support.v7.app.*;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.*;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.utils.*;
|
import org.isoron.uhabits.utils.*;
|
||||||
|
|
||||||
@@ -52,8 +51,6 @@ abstract public class BaseActivity extends AppCompatActivity
|
|||||||
@Nullable
|
@Nullable
|
||||||
private BaseScreen screen;
|
private BaseScreen screen;
|
||||||
|
|
||||||
private Toast toast;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(@Nullable Menu menu)
|
public boolean onCreateOptionsMenu(@Nullable Menu menu)
|
||||||
{
|
{
|
||||||
@@ -91,20 +88,6 @@ abstract public class BaseActivity extends AppCompatActivity
|
|||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Shows a message on the screen.
|
|
||||||
*
|
|
||||||
* @param stringId the string resource id for this message.
|
|
||||||
*/
|
|
||||||
public void showMessage(@StringRes Integer stringId)
|
|
||||||
{
|
|
||||||
if (stringId == null) return;
|
|
||||||
if (toast == null)
|
|
||||||
toast = Toast.makeText(this, stringId, Toast.LENGTH_SHORT);
|
|
||||||
else toast.setText(stringId);
|
|
||||||
toast.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void uncaughtException(@Nullable Thread thread,
|
public void uncaughtException(@Nullable Thread thread,
|
||||||
@Nullable Throwable ex)
|
@Nullable Throwable ex)
|
||||||
|
|||||||
@@ -25,10 +25,12 @@ import android.graphics.drawable.*;
|
|||||||
import android.net.*;
|
import android.net.*;
|
||||||
import android.os.*;
|
import android.os.*;
|
||||||
import android.support.annotation.*;
|
import android.support.annotation.*;
|
||||||
|
import android.support.design.widget.*;
|
||||||
import android.support.v7.app.*;
|
import android.support.v7.app.*;
|
||||||
import android.support.v7.view.ActionMode;
|
import android.support.v7.view.ActionMode;
|
||||||
import android.support.v7.widget.*;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
|
import android.widget.*;
|
||||||
|
|
||||||
import org.isoron.uhabits.*;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.utils.*;
|
import org.isoron.uhabits.utils.*;
|
||||||
@@ -52,6 +54,8 @@ public abstract class BaseScreen
|
|||||||
@Nullable
|
@Nullable
|
||||||
private BaseSelectionMenu selectionMenu;
|
private BaseSelectionMenu selectionMenu;
|
||||||
|
|
||||||
|
private Snackbar snackbar;
|
||||||
|
|
||||||
public BaseScreen(@NonNull BaseActivity activity)
|
public BaseScreen(@NonNull BaseActivity activity)
|
||||||
{
|
{
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
@@ -90,15 +94,6 @@ public abstract class BaseScreen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Ends the current selection operation.
|
|
||||||
*/
|
|
||||||
public void finishSelection()
|
|
||||||
{
|
|
||||||
if (selectionMenu == null) return;
|
|
||||||
selectionMenu.finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifies the screen that its contents should be updated.
|
* Notifies the screen that its contents should be updated.
|
||||||
*/
|
*/
|
||||||
@@ -165,9 +160,23 @@ public abstract class BaseScreen
|
|||||||
this.selectionMenu = menu;
|
this.selectionMenu = menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showMessage(@StringRes int stringId)
|
/**
|
||||||
|
* Shows a message on the screen.
|
||||||
|
*
|
||||||
|
* @param stringId the string resource id for this message.
|
||||||
|
*/
|
||||||
|
public void showMessage(@StringRes Integer stringId)
|
||||||
{
|
{
|
||||||
activity.showMessage(stringId);
|
if (stringId == null || rootView == null) return;
|
||||||
|
if (snackbar == null)
|
||||||
|
{
|
||||||
|
snackbar = Snackbar.make(rootView, stringId, Snackbar.LENGTH_SHORT);
|
||||||
|
int tvId = android.support.design.R.id.snackbar_text;
|
||||||
|
TextView tv = (TextView) snackbar.getView().findViewById(tvId);
|
||||||
|
tv.setTextColor(Color.WHITE);
|
||||||
|
}
|
||||||
|
else snackbar.setText(stringId);
|
||||||
|
snackbar.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showSendEmailScreen(@StringRes int toId,
|
public void showSendEmailScreen(@StringRes int toId,
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ public class ListHabitsActivity extends BaseActivity
|
|||||||
@Override
|
@Override
|
||||||
protected void onPause()
|
protected void onPause()
|
||||||
{
|
{
|
||||||
|
screen.onDettached();
|
||||||
adapter.cancelRefresh();
|
adapter.cancelRefresh();
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
@@ -84,6 +85,7 @@ public class ListHabitsActivity extends BaseActivity
|
|||||||
protected void onResume()
|
protected void onResume()
|
||||||
{
|
{
|
||||||
adapter.refresh();
|
adapter.refresh();
|
||||||
|
screen.onAttached();
|
||||||
rootView.postInvalidate();
|
rootView.postInvalidate();
|
||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import android.os.*;
|
|||||||
import android.support.annotation.*;
|
import android.support.annotation.*;
|
||||||
|
|
||||||
import org.isoron.uhabits.*;
|
import org.isoron.uhabits.*;
|
||||||
|
import org.isoron.uhabits.commands.*;
|
||||||
import org.isoron.uhabits.intents.*;
|
import org.isoron.uhabits.intents.*;
|
||||||
import org.isoron.uhabits.io.*;
|
import org.isoron.uhabits.io.*;
|
||||||
import org.isoron.uhabits.models.*;
|
import org.isoron.uhabits.models.*;
|
||||||
@@ -36,6 +37,7 @@ import org.isoron.uhabits.utils.*;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
public class ListHabitsScreen extends BaseScreen
|
public class ListHabitsScreen extends BaseScreen
|
||||||
|
implements CommandRunner.Listener
|
||||||
{
|
{
|
||||||
@Nullable
|
@Nullable
|
||||||
ListHabitsController controller;
|
ListHabitsController controller;
|
||||||
@@ -49,6 +51,8 @@ public class ListHabitsScreen extends BaseScreen
|
|||||||
@NonNull
|
@NonNull
|
||||||
private final DirFinder dirFinder;
|
private final DirFinder dirFinder;
|
||||||
|
|
||||||
|
private final CommandRunner commandRunner;
|
||||||
|
|
||||||
public ListHabitsScreen(@NonNull BaseActivity activity,
|
public ListHabitsScreen(@NonNull BaseActivity activity,
|
||||||
@NonNull ListHabitsRootView rootView)
|
@NonNull ListHabitsRootView rootView)
|
||||||
{
|
{
|
||||||
@@ -59,6 +63,24 @@ public class ListHabitsScreen extends BaseScreen
|
|||||||
dialogFactory = component.getDialogFactory();
|
dialogFactory = component.getDialogFactory();
|
||||||
intentFactory = component.getIntentFactory();
|
intentFactory = component.getIntentFactory();
|
||||||
dirFinder = component.getDirFinder();
|
dirFinder = component.getDirFinder();
|
||||||
|
commandRunner = component.getCommandRunner();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onAttached()
|
||||||
|
{
|
||||||
|
commandRunner.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCommandExecuted(@NonNull Command command,
|
||||||
|
@Nullable Long refreshKey)
|
||||||
|
{
|
||||||
|
showMessage(command.getExecuteStringId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onDettached()
|
||||||
|
{
|
||||||
|
commandRunner.removeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -151,7 +173,7 @@ public class ListHabitsScreen extends BaseScreen
|
|||||||
|
|
||||||
if (dir == null)
|
if (dir == null)
|
||||||
{
|
{
|
||||||
activity.showMessage(R.string.could_not_import);
|
showMessage(R.string.could_not_import);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +207,7 @@ public class ListHabitsScreen extends BaseScreen
|
|||||||
private void refreshTheme()
|
private void refreshTheme()
|
||||||
{
|
{
|
||||||
new Handler().postDelayed(() -> {
|
new Handler().postDelayed(() -> {
|
||||||
Intent intent = new Intent(activity, ListHabitsScreen.class);
|
Intent intent = new Intent(activity, ListHabitsActivity.class);
|
||||||
|
|
||||||
activity.finish();
|
activity.finish();
|
||||||
activity.overridePendingTransition(android.R.anim.fade_in,
|
activity.overridePendingTransition(android.R.anim.fade_in,
|
||||||
|
|||||||
@@ -30,15 +30,15 @@
|
|||||||
<string name="add_habit">Add habit</string>
|
<string name="add_habit">Add habit</string>
|
||||||
<string name="color_picker_default_title">Change color</string>
|
<string name="color_picker_default_title">Change color</string>
|
||||||
|
|
||||||
<string name="toast_habit_created">Habit created.</string>
|
<string name="toast_habit_created">Habit created</string>
|
||||||
<string name="toast_habit_deleted">Habits deleted.</string>
|
<string name="toast_habit_deleted">Habits deleted</string>
|
||||||
<string name="toast_habit_restored">Habits restored.</string>
|
<string name="toast_habit_restored">Habits restored</string>
|
||||||
<string name="toast_nothing_to_undo">Nothing to undo.</string>
|
<string name="toast_nothing_to_undo">Nothing to undo</string>
|
||||||
<string name="toast_nothing_to_redo">Nothing to redo.</string>
|
<string name="toast_nothing_to_redo">Nothing to redo</string>
|
||||||
<string name="toast_habit_changed">Habit changed.</string>
|
<string name="toast_habit_changed">Habit changed</string>
|
||||||
<string name="toast_habit_changed_back">Habit changed back.</string>
|
<string name="toast_habit_changed_back">Habit changed back</string>
|
||||||
<string name="toast_habit_archived">Habits archived.</string>
|
<string name="toast_habit_archived">Habits archived</string>
|
||||||
<string name="toast_habit_unarchived">Habits unarchived.</string>
|
<string name="toast_habit_unarchived">Habits unarchived</string>
|
||||||
|
|
||||||
<string name="title_activity_show_habit" translatable="false"/>
|
<string name="title_activity_show_habit" translatable="false"/>
|
||||||
<string name="overview">Overview</string>
|
<string name="overview">Overview</string>
|
||||||
|
|||||||
@@ -192,7 +192,6 @@ public class ListHabitsScreenTest extends BaseUnitTest
|
|||||||
{
|
{
|
||||||
when(dirFinder.findStorageDir(any())).thenReturn(null);
|
when(dirFinder.findStorageDir(any())).thenReturn(null);
|
||||||
screen.showImportScreen();
|
screen.showImportScreen();
|
||||||
verify(activity).showMessage(R.string.could_not_import);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user